From 872330f7f7c2a5c009b576dee60c400c3d258ea4 Mon Sep 17 00:00:00 2001 From: marco-nh <47418876+marco-nh@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:42:28 +0100 Subject: [PATCH 1/4] Fix: Dependencies --- src/common/install/kasm_vnc/www/package.json | 72 ++++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/common/install/kasm_vnc/www/package.json b/src/common/install/kasm_vnc/www/package.json index 4b317ef..0c79fc3 100644 --- a/src/common/install/kasm_vnc/www/package.json +++ b/src/common/install/kasm_vnc/www/package.json @@ -38,56 +38,56 @@ "homepage": "https://github.com/kasmtech/noVNC", "devDependencies": { "@babel/cli": "*", - "@babel/core": "*", - "@babel/plugin-syntax-dynamic-import": "*", - "@babel/plugin-transform-modules-commonjs": "*", - "@babel/preset-env": "*", - "@chiragrupani/karma-chromium-edge-launcher": "*", - "babel-loader": "^8.2.2", + "@babel/core": "*", + "@babel/plugin-syntax-dynamic-import": "*", + "@babel/plugin-transform-modules-commonjs": "*", + "@babel/preset-env": "*", + "@chiragrupani/karma-chromium-edge-launcher": "*", + "@rollup/plugin-node-resolve": "15.3.0", + "babel-loader": "^8.2.2", "babel-plugin-import-redirect": "*", - "babelify": "*", - "browserify": "*", - "chai": "*", - "clean-webpack-plugin": "^3.0.0", - "commander": "*", - "core-js": "^3.18.3", + "babelify": "*", + "browserify": "*", + "chai": "^5.1.1", + "clean-webpack-plugin": "4.0.0", + "commander": "^2.20.3", + "core-js": "^3.18.3", "cross-env": "^7.0.3", "css-loader": "^5.0.1", "css-minimizer-webpack-plugin": "^1.1.5", - "es-module-loader": "*", - "eslint": "*", + "es-module-loader": "2.3.0", + "eslint": "^8.57.1", "file-loader": "^6.2.0", - "fs-extra": "*", + "fs-extra": "11.2.0", "html-loader": "^1.3.2", "html-webpack-inline-svg-plugin": "^2.3.0", "html-webpack-plugin": "^5.5.0", - "jsdom": "*", - "karma": "*", - "karma-chrome-launcher": "*", - "karma-firefox-launcher": "*", - "karma-ie-launcher": "*", - "karma-mocha": "*", - "karma-mocha-reporter": "*", - "karma-safari-launcher": "*", - "karma-script-launcher": "*", - "karma-sinon-chai": "*", + "jsdom": "^25.0.1", + "karma": "^6.4.4", + "karma-chrome-launcher": "3.2.0", + "karma-firefox-launcher": "2.1.3", + "karma-ie-launcher": "1.0.0", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-safari-launcher": "1.0.0", + "karma-script-launcher": "1.0.0", + "karma-sinon-chai": "2.0.2", "mini-css-extract-plugin": "^1.3.3", - "mocha": "*", - "node-getopt": "*", - "po2json": "*", + "mocha": "^10.7.3", + "node-getopt": "0.3.2", + "po2json": "0.4.5", "postcss-loader": "^4.1.0", "preload-webpack-plugin": "^3.0.0-beta.4", "regenerator-runtime": "^0.13.9", - "requirejs": "*", - "rollup": "*", - "rollup-plugin-node-resolve": "*", + "requirejs": "2.3.7", + "rollup": "4.23.0", "sass": "^1.30.0", "sass-loader": "^10.1.0", - "sinon": "*", - "sinon-chai": "^2.8.0", - "svg-sprite-html-webpack": "^2.3.0", - "webpack": "^5.20.0", - "webpack-cli": "^5.1.4" + "sinon": "19.0.2", + "sinon-chai": "^4.0.0", + "svg-sprite-html-webpack": "2.4.1", + "webpack": "^5.0.0-alpha.12", + "webpack-cli": "^4.0.0-alpha-4" }, "keywords": [ "vnc", From f4eb8f1b32625b7bd1f77f0c484975d9bfe9b0b0 Mon Sep 17 00:00:00 2001 From: marco-nh <47418876+marco-nh@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:21:44 +0000 Subject: [PATCH 2/4] Relative path fix --- src/Dockerfile | 3 +- src/common/install/kasm_vnc/www/app/ui.js | 105 +++++++++------------- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index e4b7cad..d3edefd 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -159,7 +159,8 @@ RUN rm -rf package-lock.json \ && npm run build \ && rm -rf /usr/share/kasmvnc/www/dist \ && mv dist /usr/share/kasmvnc/www/ \ - && mv -f index.html /usr/share/kasmvnc/www/index.html + && mv -f index.html /usr/share/kasmvnc/www/index.html \ + && mv -f $HOME/noVNC/app/ui.js /usr/share/kasmvnc/www/app/ui.js WORKDIR $HOME RUN rm -rf noVNC diff --git a/src/common/install/kasm_vnc/www/app/ui.js b/src/common/install/kasm_vnc/www/app/ui.js index 49ec804..6ea621b 100644 --- a/src/common/install/kasm_vnc/www/app/ui.js +++ b/src/common/install/kasm_vnc/www/app/ui.js @@ -13,14 +13,13 @@ window.addEventListener("load", function() { loader.src = "vendor/browser-es-module-loader/dist/browser-es-module-loader.js"; document.head.appendChild(loader); }); -// window.addEventListener("load", function() { -// var connect_btn_el = document.getElementById("noVNC_connect_button"); -// if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) -// { -// connect_btn_el.click(); -// UI.connect(); -// } -// }); +window.addEventListener("load", function() { + var connect_btn_el = document.getElementById("noVNC_connect_button"); + if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) + { + connect_btn_el.click(); + } +}); window.updateSetting = (name, value) => { WebUtil.writeSetting(name, value); @@ -142,15 +141,13 @@ const UI = { document.documentElement.classList.remove("noVNC_loading"); - // let autoconnect = WebUtil.getConfigVar('autoconnect', false); - // if (autoconnect === 'true' || autoconnect == '1') { - // autoconnect = true; - // UI.connect(); - // } else { - // autoconnect = false; - // } - - UI.connect(); + let autoconnect = WebUtil.getConfigVar('autoconnect', false); + if (autoconnect === 'true' || autoconnect == '1') { + autoconnect = true; + UI.connect(); + } else { + autoconnect = false; + } window.parent.postMessage({ action: "noVNC_initialized", @@ -215,20 +212,6 @@ const UI = { } qualityDropdown.appendChild(Object.assign(document.createElement("option"),{value:10,label:"Custom"})) - // if port == 80 (or 443) then it won't be present and should be - // set manually - let port = window.location.port; - if (!port) { - if (window.location.protocol.substring(0, 5) == 'https') { - port = 443; - } else if (window.location.protocol.substring(0, 4) == 'http') { - port = 80; - } - } - - /* Populate the controls if defaults are provided in the URL */ - UI.initSetting('host', window.location.hostname); - UI.initSetting('port', port); UI.initSetting('encrypt', (window.location.protocol === "https:")); UI.initSetting('view_clip', false); /* UI.initSetting('resize', 'off'); */ @@ -478,11 +461,11 @@ const UI = { addConnectionControlHandlers() { UI.addClickHandle('noVNC_disconnect_button', UI.disconnect); - // var connect_btn_el = document.getElementById("noVNC_connect_button"); - // if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) - // { - // connect_btn_el.addEventListener('click', UI.connect); - // } + var connect_btn_el = document.getElementById("noVNC_connect_button"); + if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) + { + connect_btn_el.addEventListener('click', UI.connect); + } document.getElementById("noVNC_cancel_reconnect_button") .addEventListener('click', UI.cancelReconnect); @@ -1363,23 +1346,26 @@ const UI = { UI.hideStatus(); - if (!host) { - Log.Error("Can't connect when host is: " + host); - UI.showStatus(_("Must set host"), 'error'); - return; - } - UI.updateVisualState('connecting'); let url; url = UI.getSetting('encrypt') ? 'wss' : 'ws'; - url += '://' + host; - if (port) { - url += ':' + port; + if (host) { + url = new URL("https://" + host); + url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:'; + if (port) { + url.port = port; + } + url.pathname = '/' + path; + } else { + // Current (May 2024) browsers support relative WebSocket + // URLs natively, but we need to support older browsers for + // some time. + url = new URL(path, location.href); + url.protocol = (window.location.protocol === "https:") ? 'wss:' : 'ws:'; } - url += '/' + path; UI.rfb = new RFB(document.getElementById('noVNC_container'), document.getElementById('noVNC_keyboardinput'), @@ -1913,20 +1899,17 @@ const UI = { updatePointerLockButton() { // Only show the button if the pointer lock API is properly supported // AND in fullscreen. - // if ( - // UI.connected && - // (document.pointerLockElement !== undefined || - // document.mozPointerLockElement !== undefined) - // ) { - // UI.showControlInput("noVNC_setting_pointer_lock"); - // UI.showControlInput("noVNC_game_mode_button"); - // } else { - // UI.hideControlInput("noVNC_setting_pointer_lock"); - // UI.hideControlInput("noVNC_game_mode_button"); - // } - - UI.hideControlInput("noVNC_setting_pointer_lock"); - UI.hideControlInput("noVNC_game_mode_button"); + if ( + UI.connected && + (document.pointerLockElement !== undefined || + document.mozPointerLockElement !== undefined) + ) { + UI.showControlInput("noVNC_setting_pointer_lock"); + UI.showControlInput("noVNC_game_mode_button"); + } else { + UI.hideControlInput("noVNC_setting_pointer_lock"); + UI.hideControlInput("noVNC_game_mode_button"); + } }, togglePointerLock() { @@ -2553,4 +2536,4 @@ if (l10n.language === "en" || l10n.dictionary !== undefined) { .then(UI.prime); } -export default UI; \ No newline at end of file +export default UI; From 35114ec8d6c909668c595e91f8ef64d9772f2615 Mon Sep 17 00:00:00 2001 From: marco-nh <47418876+marco-nh@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:12:31 +0000 Subject: [PATCH 3/4] Revert "Relative path fix" This reverts commit f4eb8f1b32625b7bd1f77f0c484975d9bfe9b0b0. --- src/Dockerfile | 3 +- src/common/install/kasm_vnc/www/app/ui.js | 105 +++++++++++++--------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index d3edefd..e4b7cad 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -159,8 +159,7 @@ RUN rm -rf package-lock.json \ && npm run build \ && rm -rf /usr/share/kasmvnc/www/dist \ && mv dist /usr/share/kasmvnc/www/ \ - && mv -f index.html /usr/share/kasmvnc/www/index.html \ - && mv -f $HOME/noVNC/app/ui.js /usr/share/kasmvnc/www/app/ui.js + && mv -f index.html /usr/share/kasmvnc/www/index.html WORKDIR $HOME RUN rm -rf noVNC diff --git a/src/common/install/kasm_vnc/www/app/ui.js b/src/common/install/kasm_vnc/www/app/ui.js index 6ea621b..49ec804 100644 --- a/src/common/install/kasm_vnc/www/app/ui.js +++ b/src/common/install/kasm_vnc/www/app/ui.js @@ -13,13 +13,14 @@ window.addEventListener("load", function() { loader.src = "vendor/browser-es-module-loader/dist/browser-es-module-loader.js"; document.head.appendChild(loader); }); -window.addEventListener("load", function() { - var connect_btn_el = document.getElementById("noVNC_connect_button"); - if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) - { - connect_btn_el.click(); - } -}); +// window.addEventListener("load", function() { +// var connect_btn_el = document.getElementById("noVNC_connect_button"); +// if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) +// { +// connect_btn_el.click(); +// UI.connect(); +// } +// }); window.updateSetting = (name, value) => { WebUtil.writeSetting(name, value); @@ -141,13 +142,15 @@ const UI = { document.documentElement.classList.remove("noVNC_loading"); - let autoconnect = WebUtil.getConfigVar('autoconnect', false); - if (autoconnect === 'true' || autoconnect == '1') { - autoconnect = true; - UI.connect(); - } else { - autoconnect = false; - } + // let autoconnect = WebUtil.getConfigVar('autoconnect', false); + // if (autoconnect === 'true' || autoconnect == '1') { + // autoconnect = true; + // UI.connect(); + // } else { + // autoconnect = false; + // } + + UI.connect(); window.parent.postMessage({ action: "noVNC_initialized", @@ -212,6 +215,20 @@ const UI = { } qualityDropdown.appendChild(Object.assign(document.createElement("option"),{value:10,label:"Custom"})) + // if port == 80 (or 443) then it won't be present and should be + // set manually + let port = window.location.port; + if (!port) { + if (window.location.protocol.substring(0, 5) == 'https') { + port = 443; + } else if (window.location.protocol.substring(0, 4) == 'http') { + port = 80; + } + } + + /* Populate the controls if defaults are provided in the URL */ + UI.initSetting('host', window.location.hostname); + UI.initSetting('port', port); UI.initSetting('encrypt', (window.location.protocol === "https:")); UI.initSetting('view_clip', false); /* UI.initSetting('resize', 'off'); */ @@ -461,11 +478,11 @@ const UI = { addConnectionControlHandlers() { UI.addClickHandle('noVNC_disconnect_button', UI.disconnect); - var connect_btn_el = document.getElementById("noVNC_connect_button"); - if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) - { - connect_btn_el.addEventListener('click', UI.connect); - } + // var connect_btn_el = document.getElementById("noVNC_connect_button"); + // if (typeof(connect_btn_el) != 'undefined' && connect_btn_el != null) + // { + // connect_btn_el.addEventListener('click', UI.connect); + // } document.getElementById("noVNC_cancel_reconnect_button") .addEventListener('click', UI.cancelReconnect); @@ -1346,26 +1363,23 @@ const UI = { UI.hideStatus(); + if (!host) { + Log.Error("Can't connect when host is: " + host); + UI.showStatus(_("Must set host"), 'error'); + return; + } + UI.updateVisualState('connecting'); let url; url = UI.getSetting('encrypt') ? 'wss' : 'ws'; - if (host) { - url = new URL("https://" + host); - url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:'; - if (port) { - url.port = port; - } - url.pathname = '/' + path; - } else { - // Current (May 2024) browsers support relative WebSocket - // URLs natively, but we need to support older browsers for - // some time. - url = new URL(path, location.href); - url.protocol = (window.location.protocol === "https:") ? 'wss:' : 'ws:'; + url += '://' + host; + if (port) { + url += ':' + port; } + url += '/' + path; UI.rfb = new RFB(document.getElementById('noVNC_container'), document.getElementById('noVNC_keyboardinput'), @@ -1899,17 +1913,20 @@ const UI = { updatePointerLockButton() { // Only show the button if the pointer lock API is properly supported // AND in fullscreen. - if ( - UI.connected && - (document.pointerLockElement !== undefined || - document.mozPointerLockElement !== undefined) - ) { - UI.showControlInput("noVNC_setting_pointer_lock"); - UI.showControlInput("noVNC_game_mode_button"); - } else { - UI.hideControlInput("noVNC_setting_pointer_lock"); - UI.hideControlInput("noVNC_game_mode_button"); - } + // if ( + // UI.connected && + // (document.pointerLockElement !== undefined || + // document.mozPointerLockElement !== undefined) + // ) { + // UI.showControlInput("noVNC_setting_pointer_lock"); + // UI.showControlInput("noVNC_game_mode_button"); + // } else { + // UI.hideControlInput("noVNC_setting_pointer_lock"); + // UI.hideControlInput("noVNC_game_mode_button"); + // } + + UI.hideControlInput("noVNC_setting_pointer_lock"); + UI.hideControlInput("noVNC_game_mode_button"); }, togglePointerLock() { @@ -2536,4 +2553,4 @@ if (l10n.language === "en" || l10n.dictionary !== undefined) { .then(UI.prime); } -export default UI; +export default UI; \ No newline at end of file From 293669e67b3a07866795be47b4c46994010eab3e Mon Sep 17 00:00:00 2001 From: marco-nh <47418876+marco-nh@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:28:10 +0000 Subject: [PATCH 4/4] Allow relative WebSocket URLs --- src/common/install/kasm_vnc/www/app/ui.js | 60 +++++++++++------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/common/install/kasm_vnc/www/app/ui.js b/src/common/install/kasm_vnc/www/app/ui.js index 49ec804..d4179aa 100644 --- a/src/common/install/kasm_vnc/www/app/ui.js +++ b/src/common/install/kasm_vnc/www/app/ui.js @@ -215,20 +215,8 @@ const UI = { } qualityDropdown.appendChild(Object.assign(document.createElement("option"),{value:10,label:"Custom"})) - // if port == 80 (or 443) then it won't be present and should be - // set manually - let port = window.location.port; - if (!port) { - if (window.location.protocol.substring(0, 5) == 'https') { - port = 443; - } else if (window.location.protocol.substring(0, 4) == 'http') { - port = 80; - } - } /* Populate the controls if defaults are provided in the URL */ - UI.initSetting('host', window.location.hostname); - UI.initSetting('port', port); UI.initSetting('encrypt', (window.location.protocol === "https:")); UI.initSetting('view_clip', false); /* UI.initSetting('resize', 'off'); */ @@ -474,7 +462,6 @@ const UI = { document.getElementById("noVNC_reset_button") .addEventListener('click', () => UI.rfb.machineReset()); }, - addConnectionControlHandlers() { UI.addClickHandle('noVNC_disconnect_button', UI.disconnect); @@ -1363,30 +1350,39 @@ const UI = { UI.hideStatus(); - if (!host) { - Log.Error("Can't connect when host is: " + host); - UI.showStatus(_("Must set host"), 'error'); - return; - } - UI.updateVisualState('connecting'); let url; - url = UI.getSetting('encrypt') ? 'wss' : 'ws'; + if (host) { + url = new URL("https://" + host); - url += '://' + host; - if (port) { - url += ':' + port; - } - url += '/' + path; - - UI.rfb = new RFB(document.getElementById('noVNC_container'), - document.getElementById('noVNC_keyboardinput'), - url, - { shared: UI.getSetting('shared'), - repeaterID: UI.getSetting('repeaterID'), - credentials: { password: password } }); + url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:'; + if (port) { + url.port = port; + } + url.pathname = '/' + path; + } else { + // Current (May 2024) browsers support relative WebSocket + // URLs natively, but we need to support older browsers for + // some time. + url = new URL(path, location.href); + url.protocol = (window.location.protocol === "https:") ? 'wss:' : 'ws:'; + } + + try { + UI.rfb = new RFB(document.getElementById('noVNC_container'), + document.getElementById('noVNC_keyboardinput'), + url.href, + { shared: UI.getSetting('shared'), + repeaterID: UI.getSetting('repeaterID'), + credentials: { password: password } }); + } catch (exc) { + Log.Error("Failed to connect to server: " + exc); + UI.updateVisualState('disconnected'); + UI.showStatus(_("Failed to connect to server: ") + exc, 'error'); + return; + } UI.rfb.addEventListener("connect", UI.connectFinished); UI.rfb.addEventListener("disconnect", UI.disconnectFinished); UI.rfb.addEventListener("credentialsrequired", UI.credentials);