Ed Tanous | 904063f | 2017-03-02 16:48:24 -0800 | [diff] [blame] | 1 | angular.module('bmcApp').controller('KvmController', function($scope, $location) { |
| 2 | |
| 3 | |
| 4 | /*jslint white: false */ |
| 5 | /*global window, $, Util, RFB, */ |
| 6 | "use strict"; |
| 7 | var INCLUDE_URI = "noVNC/" |
| 8 | // Load supporting scripts |
| 9 | Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js", |
| 10 | "keysymdef.js", "xtscancodes.js", "keyboard.js", |
| 11 | "input.js", "display.js", "inflator.js", "rfb.js", |
| 12 | "keysym.js"]); |
| 13 | |
| 14 | var rfb; |
| 15 | var resizeTimeout; |
| 16 | |
| 17 | |
| 18 | function UIresize() { |
| 19 | if (WebUtil.getConfigVar('resize', false)) { |
| 20 | var innerW = window.innerWidth; |
| 21 | var innerH = window.innerHeight; |
| 22 | var controlbarH = $D('noVNC_status_bar').offsetHeight; |
| 23 | var padding = 5; |
| 24 | if (innerW !== undefined && innerH !== undefined) |
| 25 | rfb.requestDesktopSize(innerW, innerH - controlbarH - padding); |
| 26 | } |
| 27 | } |
| 28 | function FBUComplete(rfb, fbu) { |
| 29 | UIresize(); |
| 30 | rfb.set_onFBUComplete(function() { }); |
| 31 | } |
| 32 | function sendCtrlAltDel() { |
| 33 | rfb.sendCtrlAltDel(); |
| 34 | return false; |
| 35 | } |
| 36 | function xvpShutdown() { |
| 37 | rfb.xvpShutdown(); |
| 38 | return false; |
| 39 | } |
| 40 | function xvpReboot() { |
| 41 | rfb.xvpReboot(); |
| 42 | return false; |
| 43 | } |
| 44 | function xvpReset() { |
| 45 | rfb.xvpReset(); |
| 46 | return false; |
| 47 | } |
| 48 | function updateState(rfb, state, oldstate, msg) { |
| 49 | var s, sb, cad, level; |
| 50 | s = $D('noVNC_status'); |
| 51 | sb = $D('noVNC_status_bar'); |
| 52 | cad = $D('sendCtrlAltDelButton'); |
| 53 | switch (state) { |
| 54 | case 'failed': level = "error"; break; |
| 55 | case 'fatal': level = "error"; break; |
| 56 | case 'normal': level = "normal"; break; |
| 57 | case 'disconnected': level = "normal"; break; |
| 58 | case 'loaded': level = "normal"; break; |
| 59 | default: level = "warn"; break; |
| 60 | } |
| 61 | |
| 62 | if (state === "normal") { |
| 63 | cad.disabled = false; |
| 64 | } else { |
| 65 | cad.disabled = true; |
| 66 | xvpInit(0); |
| 67 | } |
| 68 | |
| 69 | if (typeof(msg) !== 'undefined') { |
| 70 | sb.setAttribute("class", "noVNC_status_" + level); |
| 71 | s.innerHTML = msg; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | window.onresize = function () { |
| 76 | // When the window has been resized, wait until the size remains |
| 77 | // the same for 0.5 seconds before sending the request for changing |
| 78 | // the resolution of the session |
| 79 | clearTimeout(resizeTimeout); |
| 80 | resizeTimeout = setTimeout(function(){ |
| 81 | UIresize(); |
| 82 | }, 500); |
| 83 | }; |
| 84 | |
| 85 | function xvpInit(ver) { |
| 86 | var xvpbuttons; |
| 87 | xvpbuttons = $D('noVNC_xvp_buttons'); |
| 88 | if (ver >= 1) { |
| 89 | xvpbuttons.style.display = 'inline'; |
| 90 | } else { |
| 91 | xvpbuttons.style.display = 'none'; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | window.onscriptsload = function () { |
| 96 | var host, port, password, path, token; |
| 97 | |
| 98 | $D('sendCtrlAltDelButton').style.display = "inline"; |
| 99 | $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel; |
| 100 | $D('xvpShutdownButton').onclick = xvpShutdown; |
| 101 | $D('xvpRebootButton').onclick = xvpReboot; |
| 102 | $D('xvpResetButton').onclick = xvpReset; |
| 103 | |
| 104 | host = $location.host(); |
| 105 | port = 9000; |
| 106 | password = ""; |
| 107 | token = "1234"; |
| 108 | path = "/"; |
| 109 | |
| 110 | try { |
| 111 | rfb = new RFB({'target': $D('noVNC_canvas'), |
| 112 | 'encrypt': true, |
| 113 | 'local_cursor': true, |
| 114 | 'onUpdateState': updateState, |
| 115 | 'onXvpInit': xvpInit, |
| 116 | 'onFBUComplete': FBUComplete}); |
| 117 | } catch (exc) { |
| 118 | updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc); |
| 119 | return; // don't continue trying to connect |
| 120 | } |
| 121 | |
| 122 | rfb.connect(host, port, password, path); |
| 123 | }; |
| 124 | }); |