Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 1 | <template> |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 2 | <div :class="marginClass"> |
| 3 | <div ref="toolbar" class="kvm-toolbar"> |
| 4 | <b-row class="d-flex"> |
| 5 | <b-col class="d-flex flex-column justify-content-end" cols="4"> |
| 6 | <dl class="mb-2" sm="2" md="2"> |
| 7 | <dt class="d-inline font-weight-bold mr-1"> |
| 8 | {{ $t('pageKvm.status') }}: |
| 9 | </dt> |
| 10 | <dd class="d-inline"> |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 11 | <status-icon :status="serverStatusIcon" /> |
| 12 | <span class="d-none d-md-inline"> {{ serverStatus }}</span> |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 13 | </dd> |
| 14 | </dl> |
| 15 | </b-col> |
| 16 | |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 17 | <b-col class="d-flex justify-content-end pr-1"> |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 18 | <b-button |
| 19 | v-if="isConnected" |
| 20 | variant="link" |
| 21 | type="button" |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 22 | @click="sendCtrlAltDel" |
| 23 | > |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 24 | <icon-arrow-down /> |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 25 | {{ $t('pageKvm.buttonCtrlAltDelete') }} |
| 26 | </b-button> |
| 27 | <b-button |
| 28 | v-if="!isFullWindow" |
| 29 | variant="link" |
| 30 | type="button" |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 31 | @click="openConsoleWindow()" |
| 32 | > |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 33 | <icon-launch /> |
| 34 | {{ $t('pageKvm.openNewTab') }} |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 35 | </b-button> |
| 36 | </b-col> |
| 37 | </b-row> |
| 38 | </div> |
| 39 | <div id="terminal-kvm" ref="panel" :class="terminalClass"></div> |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 40 | </div> |
| 41 | </template> |
| 42 | |
| 43 | <script> |
| 44 | import RFB from '@novnc/novnc/core/rfb'; |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 45 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 46 | import IconLaunch from '@carbon/icons-vue/es/launch/20'; |
| 47 | import IconArrowDown from '@carbon/icons-vue/es/arrow--down/16'; |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 48 | import { throttle } from 'lodash'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 49 | import { useI18n } from 'vue-i18n'; |
| 50 | import i18n from '@/i18n'; |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 51 | |
| 52 | const Connecting = 0; |
| 53 | const Connected = 1; |
| 54 | const Disconnected = 2; |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 55 | |
| 56 | export default { |
| 57 | name: 'KvmConsole', |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 58 | components: { StatusIcon, IconLaunch, IconArrowDown }, |
| 59 | props: { |
| 60 | isFullWindow: { |
| 61 | type: Boolean, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 62 | default: true, |
| 63 | }, |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 64 | }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 65 | data() { |
| 66 | return { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 67 | $t: useI18n().t, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 68 | rfb: null, |
| 69 | isConnected: false, |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 70 | terminalClass: this.isFullWindow ? 'full-window' : '', |
| 71 | marginClass: this.isFullWindow ? 'margin-left-full-window' : '', |
| 72 | status: Connecting, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 73 | convasRef: null, |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 74 | resizeKvmWindow: null, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 75 | }; |
| 76 | }, |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 77 | computed: { |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 78 | serverStatusIcon() { |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 79 | if (this.status === Connected) { |
| 80 | return 'success'; |
| 81 | } else if (this.status === Disconnected) { |
| 82 | return 'danger'; |
| 83 | } |
| 84 | return 'secondary'; |
| 85 | }, |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 86 | serverStatus() { |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 87 | if (this.status === Connected) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 88 | return i18n.global.t('pageKvm.connected'); |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 89 | } else if (this.status === Disconnected) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 90 | return i18n.global.t('pageKvm.disconnected'); |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 91 | } |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 92 | return i18n.global.t('pageKvm.connecting'); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 93 | }, |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 94 | }, |
kirankumarb07 | e78d10b | 2023-03-03 12:10:29 +0530 | [diff] [blame] | 95 | created() { |
| 96 | this.$store.dispatch('global/getSystemInfo'); |
| 97 | }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 98 | mounted() { |
| 99 | this.openTerminal(); |
| 100 | }, |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 101 | beforeUnmount() { |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 102 | window.removeEventListener('resize', this.resizeKvmWindow); |
Lei YU | 6641cc4 | 2021-06-18 19:22:57 +0800 | [diff] [blame] | 103 | this.closeTerminal(); |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 104 | }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 105 | methods: { |
| 106 | sendCtrlAltDel() { |
| 107 | this.rfb.sendCtrlAltDel(); |
| 108 | }, |
Lei YU | 6641cc4 | 2021-06-18 19:22:57 +0800 | [diff] [blame] | 109 | closeTerminal() { |
| 110 | this.rfb.disconnect(); |
| 111 | this.rfb = null; |
| 112 | }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 113 | openTerminal() { |
| 114 | const token = this.$store.getters['authentication/token']; |
| 115 | this.rfb = new RFB( |
| 116 | this.$refs.panel, |
| 117 | `wss://${window.location.host}/kvm/0`, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 118 | { wsProtocols: [token] }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 119 | ); |
| 120 | |
| 121 | this.rfb.scaleViewport = true; |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 122 | this.rfb.clipViewport = true; |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 123 | const that = this; |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 124 | |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 125 | this.resizeKvmWindow = throttle(() => { |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 126 | setTimeout(that.setWidthToolbar, 0); |
Konstantin Aladyshev | 69e8ec5 | 2021-02-22 14:07:57 +0300 | [diff] [blame] | 127 | }, 1000); |
| 128 | window.addEventListener('resize', this.resizeKvmWindow); |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 129 | |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 130 | this.rfb.addEventListener('connect', () => { |
| 131 | that.isConnected = true; |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 132 | that.status = Connected; |
| 133 | that.setWidthToolbar(); |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 134 | }); |
| 135 | |
| 136 | this.rfb.addEventListener('disconnect', () => { |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 137 | this.isConnected = false; |
| 138 | that.status = Disconnected; |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 139 | }); |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 140 | }, |
| 141 | setWidthToolbar() { |
| 142 | if ( |
| 143 | this.$refs.panel.children && |
| 144 | this.$refs.panel.children.length > 0 && |
| 145 | this.$refs.panel.children[0].children.length > 0 |
| 146 | ) { |
| 147 | this.$refs.toolbar.style.width = |
| 148 | this.$refs.panel.children[0].children[0].clientWidth - 10 + 'px'; |
| 149 | } |
| 150 | }, |
| 151 | openConsoleWindow() { |
Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 152 | // If consoleWindow is not null |
kirankumarb07 | b89eed2 | 2023-01-12 15:50:30 +0530 | [diff] [blame] | 153 | // Check the newly opened window is closed or not |
Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 154 | if (this.$eventBus.$consoleWindow) { |
kirankumarb07 | b89eed2 | 2023-01-12 15:50:30 +0530 | [diff] [blame] | 155 | // If window is not closed set focus to new window |
| 156 | // If window is closed, do open new window |
Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 157 | if (!this.$eventBus.$consoleWindow.closed) { |
| 158 | this.$eventBus.$consoleWindow.focus(); |
kirankumarb07 | b89eed2 | 2023-01-12 15:50:30 +0530 | [diff] [blame] | 159 | return; |
| 160 | } else { |
| 161 | this.openNewWindow(); |
| 162 | } |
| 163 | } else { |
Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 164 | // If consoleWindow is null, open new window |
kirankumarb07 | b89eed2 | 2023-01-12 15:50:30 +0530 | [diff] [blame] | 165 | this.openNewWindow(); |
| 166 | } |
| 167 | }, |
| 168 | openNewWindow() { |
Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 169 | this.$eventBus.$consoleWindow = window.open( |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 170 | '#/console/kvm', |
kirankumarb07 | b89eed2 | 2023-01-12 15:50:30 +0530 | [diff] [blame] | 171 | 'kvmConsoleWindow', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 172 | 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=700,height=550', |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 173 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 174 | }, |
| 175 | }, |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 176 | }; |
| 177 | </script> |
| 178 | |
HuyLe | b449867 | 2024-11-17 11:01:35 +0700 | [diff] [blame^] | 179 | <style lang="scss"> |
| 180 | @import '@/assets/styles/bmc/custom/_kvm.scss'; |
| 181 | </style> |
| 182 | |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 183 | <style lang="scss" scoped> |
| 184 | @import '@/assets/styles/bmc/helpers/_index.scss'; |
| 185 | @import '@/assets/styles/bootstrap/_helpers.scss'; |
| 186 | |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 187 | .button-ctrl-alt-delete { |
| 188 | float: right; |
| 189 | } |
| 190 | |
| 191 | .kvm-status { |
| 192 | padding-top: $spacer / 2; |
| 193 | padding-left: $spacer / 4; |
| 194 | display: inline-block; |
| 195 | } |
Mateusz Gapski | 96b37af | 2020-09-04 14:11:55 +0200 | [diff] [blame] | 196 | |
| 197 | .margin-left-full-window { |
| 198 | margin-left: 5px; |
| 199 | } |
Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame] | 200 | </style> |