Allow relative WebSocket URLs
This can be very useful if you have multiple instances of noVNC, and you want to redirect them to different VNC servers. The new default settings will have the same behaviour as before for systems where noVNC is deployed in the root web folder.
This commit is contained in:
parent
074fa1a40f
commit
96c76f7709
37
app/ui.js
37
app/ui.js
|
@ -158,20 +158,7 @@ const UI = {
|
||||||
UI.initSetting('logging', 'warn');
|
UI.initSetting('logging', 'warn');
|
||||||
UI.updateLogging();
|
UI.updateLogging();
|
||||||
|
|
||||||
// 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 */
|
/* 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('encrypt', (window.location.protocol === "https:"));
|
||||||
UI.initSetting('view_clip', false);
|
UI.initSetting('view_clip', false);
|
||||||
UI.initSetting('resize', 'off');
|
UI.initSetting('resize', 'off');
|
||||||
|
@ -1021,25 +1008,27 @@ const UI = {
|
||||||
|
|
||||||
UI.hideStatus();
|
UI.hideStatus();
|
||||||
|
|
||||||
if (!host) {
|
|
||||||
Log.Error("Can't connect when host is: " + host);
|
|
||||||
UI.showStatus(_("Must set host"), 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UI.closeConnectPanel();
|
UI.closeConnectPanel();
|
||||||
|
|
||||||
UI.updateVisualState('connecting');
|
UI.updateVisualState('connecting');
|
||||||
|
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
url = new URL("https://" + host);
|
if (host) {
|
||||||
|
url = new URL("https://" + host);
|
||||||
|
|
||||||
url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:';
|
url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:';
|
||||||
if (port) {
|
if (port) {
|
||||||
url.port = 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.pathname = '/' + path;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UI.rfb = new RFB(document.getElementById('noVNC_container'),
|
UI.rfb = new RFB(document.getElementById('noVNC_container'),
|
||||||
|
|
Loading…
Reference in New Issue