blob: 080f72e890f83b8a72c2a0211ff43a22f37b763a [file] [log] [blame]
Mateusz Gapski632de222020-07-09 09:21:33 +02001<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>
18import RFB from '@novnc/novnc/core/rfb';
19
20export 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>