blob: 224e5d240bf6658f659bba7a96a58ee14bc2b241 [file] [log] [blame]
Yoshie Muranaka198ce1f2019-09-20 10:33:04 -07001/**
2 * Directive for KVM (Kernel-based Virtual Machine)
3 *
4 * @module app/serverControl
5 * @exports kvmConsole
6 * @name kvmConsole
7 */
8
9import RFB from '@novnc/novnc/core/rfb.js';
10
11window.angular && (function(angular) {
12 'use strict';
13
14 angular.module('app.serverControl').directive('kvmConsole', [
15 '$log', '$location',
16 function($log, $location) {
17 return {
18 restrict: 'E', template: require('./kvm-console.html'),
19 link: function(scope, element) {
20 var rfb;
21
22 element.on('$destroy', function() {
23 if (rfb) {
24 rfb.disconnect();
25 }
26 });
27
28 function sendCtrlAltDel() {
29 rfb.sendCtrlAltDel();
30 return false;
31 };
32
33 function connected(e) {
34 $log.debug('RFB Connected');
35 }
36 function disconnected(e) {
37 $log.debug('RFB disconnected');
38 }
39
40 var host = $location.host();
41 var port = $location.port();
42 var target = element[0].firstElementChild;
43 try {
44 rfb = new RFB(
45 target, 'wss://' + host + ':' + port + '/kvm/0', {});
46
47 rfb.addEventListener('connect', connected);
48 rfb.addEventListener('disconnect', disconnected);
49 } catch (exc) {
50 $log.error(exc);
51 updateState(
52 null, 'fatal', null,
53 'Unable to create RFB client -- ' + exc);
54 return; // don't continue trying to connect
55 };
56 }
57 }
58 }
59 ]);
60})(window.angular);