Mateusz Gapski | 632de22 | 2020-07-09 09:21:33 +0200 | [diff] [blame^] | 1 | <template> |
| 2 | <div> |
| 3 | <span class="kvm-status">{{ $t('pageKvm.status') }}: {{ status }}</span> |
| 4 | <b-button |
| 5 | v-if="isConnected" |
| 6 | variant="link" |
| 7 | type="button" |
| 8 | class="button-launch button-ctrl-alt-delete" |
| 9 | @click="sendCtrlAltDel" |
| 10 | > |
| 11 | {{ $t('pageKvm.buttonCtrlAltDelete') }} |
| 12 | </b-button> |
| 13 | <div v-show="isConnected" id="terminal" ref="panel"></div> |
| 14 | </div> |
| 15 | </template> |
| 16 | |
| 17 | <script> |
| 18 | import RFB from '@novnc/novnc/core/rfb'; |
| 19 | |
| 20 | export default { |
| 21 | name: 'KvmConsole', |
| 22 | data() { |
| 23 | return { |
| 24 | rfb: null, |
| 25 | isConnected: false, |
| 26 | status: this.$t('pageKvm.connecting') |
| 27 | }; |
| 28 | }, |
| 29 | mounted() { |
| 30 | this.openTerminal(); |
| 31 | }, |
| 32 | methods: { |
| 33 | sendCtrlAltDel() { |
| 34 | this.rfb.sendCtrlAltDel(); |
| 35 | }, |
| 36 | openTerminal() { |
| 37 | const token = this.$store.getters['authentication/token']; |
| 38 | this.rfb = new RFB( |
| 39 | this.$refs.panel, |
| 40 | `wss://${window.location.host}/kvm/0`, |
| 41 | { wsProtocols: [token] } |
| 42 | ); |
| 43 | |
| 44 | this.rfb.scaleViewport = true; |
| 45 | const that = this; |
| 46 | this.rfb.addEventListener('connect', () => { |
| 47 | that.isConnected = true; |
| 48 | that.status = this.$t('pageKvm.connected'); |
| 49 | }); |
| 50 | |
| 51 | this.rfb.addEventListener('disconnect', () => { |
| 52 | that.status = this.$t('pageKvm.disconnected'); |
| 53 | }); |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | </script> |
| 58 | |
| 59 | <style scoped lang="scss"> |
| 60 | @import 'src/assets/styles/helpers'; |
| 61 | #terminal { |
| 62 | height: calc(100vh - 42px); |
| 63 | } |
| 64 | |
| 65 | .button-ctrl-alt-delete { |
| 66 | float: right; |
| 67 | } |
| 68 | |
| 69 | .kvm-status { |
| 70 | padding-top: $spacer / 2; |
| 71 | padding-left: $spacer / 4; |
| 72 | display: inline-block; |
| 73 | } |
| 74 | </style> |