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