Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 1 | <template> |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 2 | <div :class="isFullWindow ? 'full-window-container' : 'terminal-container'"> |
Sukanya Pandey | d9dc6fb | 2020-11-03 11:13:23 +0530 | [diff] [blame] | 3 | <b-row class="d-flex"> |
Nikhil Ashoka | 1d9257e | 2022-01-31 14:06:37 +0530 | [diff] [blame] | 4 | <b-col sm="4" md="6"> |
| 5 | <alert |
glukhov.mikhail | 83ca596 | 2022-11-25 11:52:45 +0300 | [diff] [blame] | 6 | v-if="connection ? false : true" |
Nikhil Ashoka | 1d9257e | 2022-01-31 14:06:37 +0530 | [diff] [blame] | 7 | variant="warning" |
| 8 | :small="true" |
| 9 | class="mt-4" |
| 10 | > |
| 11 | <p class="col-form-label"> |
| 12 | {{ $t('pageSerialOverLan.alert.disconnectedAlertMessage') }} |
| 13 | </p> |
| 14 | </alert> |
| 15 | </b-col> |
| 16 | </b-row> |
| 17 | <b-row class="d-flex"> |
Sukanya Pandey | d9dc6fb | 2020-11-03 11:13:23 +0530 | [diff] [blame] | 18 | <b-col class="d-flex flex-column justify-content-end"> |
| 19 | <dl class="mb-2" sm="6" md="6"> |
| 20 | <dt class="d-inline font-weight-bold mr-1"> |
| 21 | {{ $t('pageSerialOverLan.status') }}: |
| 22 | </dt> |
| 23 | <dd class="d-inline"> |
glukhov.mikhail | 83ca596 | 2022-11-25 11:52:45 +0300 | [diff] [blame] | 24 | <status-icon :status="serverStatusIcon" /> |
| 25 | {{ |
| 26 | connection |
| 27 | ? $t('pageSerialOverLan.connected') |
| 28 | : $t('pageSerialOverLan.disconnected') |
| 29 | }} |
Sukanya Pandey | d9dc6fb | 2020-11-03 11:13:23 +0530 | [diff] [blame] | 30 | </dd> |
| 31 | </dl> |
| 32 | </b-col> |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 33 | |
Sukanya Pandey | d9dc6fb | 2020-11-03 11:13:23 +0530 | [diff] [blame] | 34 | <b-col v-if="!isFullWindow" class="d-flex justify-content-end"> |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 35 | <b-button variant="link" type="button" @click="openConsoleWindow()"> |
| 36 | <icon-launch /> |
Sukanya Pandey | d9dc6fb | 2020-11-03 11:13:23 +0530 | [diff] [blame] | 37 | {{ $t('pageSerialOverLan.openNewTab') }} |
| 38 | </b-button> |
| 39 | </b-col> |
| 40 | </b-row> |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 41 | <div id="terminal" ref="panel"></div> |
| 42 | </div> |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 43 | </template> |
| 44 | |
| 45 | <script> |
Nikhil Ashoka | 1d9257e | 2022-01-31 14:06:37 +0530 | [diff] [blame] | 46 | import Alert from '@/components/Global/Alert'; |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 47 | import { AttachAddon } from 'xterm-addon-attach'; |
| 48 | import { FitAddon } from 'xterm-addon-fit'; |
| 49 | import { Terminal } from 'xterm'; |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 50 | import { throttle } from 'lodash'; |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 51 | import IconLaunch from '@carbon/icons-vue/es/launch/20'; |
| 52 | import StatusIcon from '@/components/Global/StatusIcon'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 53 | import { useI18n } from 'vue-i18n'; |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 54 | |
| 55 | export default { |
| 56 | name: 'SerialOverLanConsole', |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 57 | components: { |
Nikhil Ashoka | 1d9257e | 2022-01-31 14:06:37 +0530 | [diff] [blame] | 58 | Alert, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 59 | IconLaunch, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 60 | StatusIcon, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 61 | }, |
| 62 | props: { |
| 63 | isFullWindow: { |
| 64 | type: Boolean, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 65 | default: true, |
| 66 | }, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 67 | }, |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 68 | data() { |
| 69 | return { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 70 | $t: useI18n().t, |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 71 | resizeConsoleWindow: null, |
| 72 | }; |
| 73 | }, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 74 | computed: { |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 75 | serverStatus() { |
| 76 | return this.$store.getters['global/serverStatus']; |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 77 | }, |
glukhov.mikhail | 83ca596 | 2022-11-25 11:52:45 +0300 | [diff] [blame] | 78 | connection() { |
| 79 | return this.serverStatus === 'off' ? false : true; |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 80 | }, |
glukhov.mikhail | 83ca596 | 2022-11-25 11:52:45 +0300 | [diff] [blame] | 81 | serverStatusIcon() { |
| 82 | return this.connection ? 'success' : 'danger'; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 83 | }, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 84 | }, |
| 85 | created() { |
kirankumarb07 | b63e9d9 | 2023-02-07 13:08:52 +0530 | [diff] [blame] | 86 | this.$store.dispatch('global/getSystemInfo'); |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 87 | }, |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 88 | mounted() { |
| 89 | this.openTerminal(); |
| 90 | }, |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 91 | beforeUnmount() { |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 92 | window.removeEventListener('resize', this.resizeConsoleWindow); |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 93 | this.closeTerminal(); |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 94 | }, |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 95 | methods: { |
| 96 | openTerminal() { |
| 97 | const token = this.$store.getters['authentication/token']; |
Nikhil Ashoka | 37b22a1 | 2023-05-12 12:54:27 +0530 | [diff] [blame] | 98 | this.ws = new WebSocket(`wss://${window.location.host}/console/default`, [ |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 99 | token, |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 100 | ]); |
| 101 | |
| 102 | // Refer https://github.com/xtermjs/xterm.js/ for xterm implementation and addons. |
| 103 | |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 104 | this.term = new Terminal({ |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 105 | fontSize: 15, |
| 106 | fontFamily: |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 107 | 'SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 108 | }); |
| 109 | |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 110 | const attachAddon = new AttachAddon(this.ws); |
| 111 | this.term.loadAddon(attachAddon); |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 112 | |
| 113 | const fitAddon = new FitAddon(); |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 114 | this.term.loadAddon(fitAddon); |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 115 | |
| 116 | const SOL_THEME = { |
| 117 | background: '#19273c', |
| 118 | cursor: 'rgba(83, 146, 255, .5)', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 119 | scrollbar: 'rgba(83, 146, 255, .5)', |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 120 | }; |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 121 | this.term.setOption('theme', SOL_THEME); |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 122 | |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 123 | this.term.open(this.$refs.panel); |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 124 | fitAddon.fit(); |
| 125 | |
Konstantin Aladyshev | 64f260c | 2021-02-17 17:23:22 +0300 | [diff] [blame] | 126 | this.resizeConsoleWindow = throttle(() => { |
| 127 | fitAddon.fit(); |
| 128 | }, 1000); |
| 129 | window.addEventListener('resize', this.resizeConsoleWindow); |
| 130 | |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 131 | try { |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 132 | this.ws.onopen = function () { |
Nikhil Ashoka | 37b22a1 | 2023-05-12 12:54:27 +0530 | [diff] [blame] | 133 | console.log('websocket console/default opened'); |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 134 | }; |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 135 | this.ws.onclose = function (event) { |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 136 | console.log( |
Nikhil Ashoka | 37b22a1 | 2023-05-12 12:54:27 +0530 | [diff] [blame] | 137 | 'websocket console/default closed. code: ' + |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 138 | event.code + |
| 139 | ' reason: ' + |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 140 | event.reason, |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 141 | ); |
| 142 | }; |
| 143 | } catch (error) { |
| 144 | console.log(error); |
| 145 | } |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 146 | }, |
Xiaochao Ma | 78372d6 | 2022-03-08 20:13:00 +0800 | [diff] [blame] | 147 | closeTerminal() { |
| 148 | console.log('closeTerminal'); |
| 149 | this.term.dispose(); |
| 150 | this.term = null; |
| 151 | this.ws.close(); |
| 152 | this.ws = null; |
| 153 | }, |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 154 | openConsoleWindow() { |
| 155 | window.open( |
| 156 | '#/console/serial-over-lan-console', |
| 157 | '_blank', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 158 | 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=550', |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 159 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 160 | }, |
| 161 | }, |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 162 | }; |
| 163 | </script> |
| 164 | |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 165 | <style lang="scss" scoped> |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 166 | @import '@/assets/styles/bmc/helpers/_index.scss'; |
| 167 | @import '@/assets/styles/bootstrap/_helpers.scss'; |
| 168 | |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 169 | @import '~xterm/css/xterm.css'; |
| 170 | |
Sukanya Pandey | b0fadef | 2021-03-12 14:58:31 +0530 | [diff] [blame] | 171 | #terminal { |
| 172 | overflow: auto; |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | .full-window-container { |
| 176 | width: 97%; |
Sukanya Pandey | 615b315 | 2020-08-19 19:13:49 +0530 | [diff] [blame] | 177 | margin: 1.5%; |
Sukanya Pandey | 96f69ca | 2020-05-20 15:32:57 +0530 | [diff] [blame] | 178 | } |
| 179 | </style> |