Handle immediate connection errors

The browser might throw an exception right away if there is something it
doesn't like with our connect attempt. E.g. using a non-TLS WebSocket
from a TLS web page.
This commit is contained in:
Pierre Ossman 2023-12-05 11:30:30 +01:00
parent 7d2dad0f9e
commit 9ac632deee
1 changed files with 12 additions and 4 deletions

View File

@ -1041,10 +1041,18 @@ const UI = {
} }
url += '/' + path; url += '/' + path;
UI.rfb = new RFB(document.getElementById('noVNC_container'), url, try {
{ shared: UI.getSetting('shared'), UI.rfb = new RFB(document.getElementById('noVNC_container'), url,
repeaterID: UI.getSetting('repeaterID'), { shared: UI.getSetting('shared'),
credentials: { password: password } }); 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("connect", UI.connectFinished);
UI.rfb.addEventListener("disconnect", UI.disconnectFinished); UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("serververification", UI.serverVerify); UI.rfb.addEventListener("serververification", UI.serverVerify);