From aa7fd0e88907a5bb6c724ec4307edae844fe3428 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Mon, 3 Feb 2020 16:42:27 +0100 Subject: [PATCH] B #4020: Fix status of NoVNC server (#4151) --- src/sunstone/public/app/console/vnc.js | 49 ++++++++++++++++--- .../app/tabs/vms-tab/dialogs/vnc/html.hbs | 1 - src/sunstone/public/app/utils/vnc.js | 31 +++++++++--- src/sunstone/views/vnc.erb | 2 +- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/sunstone/public/app/console/vnc.js b/src/sunstone/public/app/console/vnc.js index 710dab0ce7..cc05c4449c 100644 --- a/src/sunstone/public/app/console/vnc.js +++ b/src/sunstone/public/app/console/vnc.js @@ -17,7 +17,35 @@ define(function(require) { var RFB = require("vnc-rfb").default; var Config = require("sunstone-config"); - var rfb; + var _rfb; + var _is_encrypted = ""; + + function setStatus(message="", status=""){ + $(".NOVNC_message").text(message); + $("#noVNC_status").text(status); + } + + function connected(){ + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + _rfb._fb_name); + } + + function disconnectedFromServer(e){ + if (e.detail.clean) { + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + _rfb._fb_name); + } else { + setStatus("Something went wrong, connection is closed", "Failed"); + } + } + + function desktopNameChange(e) { + if (e.detail.name) { + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + e.detail.name); + } + } + + function credentialsRequired(e) { + setStatus("Something went wrong, more credentials must be given to continue", "Failed"); + } function passwordRequired(rfb) { var msg; @@ -31,24 +59,24 @@ define(function(require) { document.querySelector("#setPasswordForm").addEventListener("submit", setPassword); } function setPassword(event) { - rfb.sendPassword(document.querySelector("#password_input").value); + _rfb.sendPassword(document.querySelector("#password_input").value); event.preventDefault(); return false; } function sendCtrlAltDel() { - rfb.sendCtrlAltDel(); + _rfb.sendCtrlAltDel(); return false; } function xvpShutdown() { - rfb.xvpShutdown(); + _rfb.xvpShutdown(); return false; } function xvpReboot() { - rfb.xvpReboot(); + _rfb.xvpReboot(); return false; } function xvpReset() { - rfb.xvpReset(); + _rfb.xvpReset(); return false; } function updateState(rfb, state, oldstate, msg) { @@ -109,8 +137,10 @@ define(function(require) { if (window.location.protocol === "https:") { URL = "wss"; + _is_encrypted = "encrypted"; } else { URL = "ws"; + _is_encrypted = "unencrypted"; } URL += "://" + window.location.hostname; URL += ":" + proxy_port; @@ -133,8 +163,13 @@ define(function(require) { return; } try{ - rfb = new RFB(document.querySelector("#VNC_canvas"), URL, rfbConfig); + _rfb = new RFB(document.querySelector("#VNC_canvas"), URL, rfbConfig); + _rfb.addEventListener("connect", connected); + _rfb.addEventListener("disconnect", disconnectedFromServer); + _rfb.addEventListener("desktopname", desktopNameChange); + _rfb.addEventListener("credentialsrequired", credentialsRequired); }catch(err){ + setStatus("Something went wrong, connection is closed", "Failed"); console.log("error start NOVNC ", err); } }); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/vnc/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/vnc/html.hbs index d14f4313fa..916b9b9bb2 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/vnc/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/vnc/html.hbs @@ -18,7 +18,6 @@
- {{tr "VNC"}} diff --git a/src/sunstone/public/app/utils/vnc.js b/src/sunstone/public/app/utils/vnc.js index 34e880c44a..6e7d286d91 100644 --- a/src/sunstone/public/app/utils/vnc.js +++ b/src/sunstone/public/app/utils/vnc.js @@ -21,6 +21,7 @@ define(function(require) { var _rfb; var _message = ""; var _status = "Loading"; + var _is_encrypted = ""; return { "lockStatus": lockStatus, @@ -43,25 +44,35 @@ define(function(require) { _lock = false; } - function connected(){ - status("","Loaded"); - } - - function status(message="", status=""){ + function setStatus(message="", status=""){ _message = message; _status = status; $(".NOVNC_message").text(_message); $("#VNC_status").text(_status); } + function connected(){ + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + _rfb._fb_name); + } + function disconnectedFromServer(e){ if (e.detail.clean) { - status("", "Loaded"); + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + _rfb._fb_name); } else { - status("Something went wrong, connection is closed", "Failed"); + setStatus("Something went wrong, connection is closed", "Failed"); } } + function desktopNameChange(e) { + if (e.detail.name) { + setStatus(null, "VNC " + _rfb._rfb_connection_state + " (" + _is_encrypted + ") to: " + e.detail.name); + } + } + + function credentialsRequired(e) { + setStatus("Something went wrong, more credentials must be given to continue", "Failed"); + } + function vncCallback(response) { var URL = ""; var proxy_host = window.location.hostname; @@ -76,8 +87,10 @@ define(function(require) { if (protocol === "https:") { URL = "wss"; + _is_encrypted ="encrypted"; } else { URL = "ws"; + _is_encrypted ="unencrypted"; } URL += "://" + hostname; URL += ":" + proxy_port; @@ -97,8 +110,10 @@ define(function(require) { _rfb = new RFB(document.querySelector("#VNC_canvas"), URL, rfbConfig); _rfb.addEventListener("connect", connected); _rfb.addEventListener("disconnect", disconnectedFromServer); + _rfb.addEventListener("desktopname", desktopNameChange); + _rfb.addEventListener("credentialsrequired", credentialsRequired); }catch(err){ - status("Something went wrong, connection is closed", "Failed"); + setStatus("Something went wrong, connection is closed", "Failed"); console.log("error start NOVNC ", err); } diff --git a/src/sunstone/views/vnc.erb b/src/sunstone/views/vnc.erb index f96a1a3f79..59d511a689 100644 --- a/src/sunstone/views/vnc.erb +++ b/src/sunstone/views/vnc.erb @@ -70,7 +70,7 @@ -
Loading
+
Loading