From aac4d3f56226689d119c784a617c0c6e1e82655b Mon Sep 17 00:00:00 2001 From: sweiland-openrails <118388365+sweiland-openrails@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:51:00 +0200 Subject: [PATCH 1/2] When switch panel gets disconnected because off ending open rails add dark overlay to the webpage. And try to reconnect. --- .../WebServices/Web/SwitchPanel/index2.css | 14 +++++++++++ .../WebServices/Web/SwitchPanel/index2.html | 1 + .../WebServices/Web/SwitchPanel/index2.js | 25 ++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.css b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.css index 9e5c8f6675..2d9e9abf4a 100644 --- a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.css +++ b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.css @@ -69,3 +69,17 @@ label { min-width: 1px; } +#overlay { + position: fixed; /* Sit on top of the page content */ + display: none; /* Hidden by default */ + width: 100%; /* Full width (cover the whole page) */ + height: 100%; /* Full height (cover the whole page) */ + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(0,0,0,0.6); /* Black background with opacity */ + z-index: 2; /* Specify a stack order in case you're using a different order for other elements */ + cursor: pointer; /* Add a pointer on hover */ +} + diff --git a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.html b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.html index ffd093e013..8a533c2002 100644 --- a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.html +++ b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.html @@ -25,6 +25,7 @@ +
diff --git a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js index 2763af1b26..b0dcc876b5 100644 --- a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js +++ b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js @@ -30,12 +30,14 @@ function createSocket() { const connection = new WebSocket(uri, "json"); connection.onopen = function (evt) { - console.log("websocket opened: " + evt.type); + console.log("Websocket opened: " + evt.type); + // connected, turn off the dark overlay + document.getElementById("overlay").style.display = "none"; }; connection.onmessage = function (evt) { const json = JSON.parse(evt.data); - console.log("websocket message received: ", json); + console.log("Websocket message received: ", json); if (initStillToBeDone) { if (json.type == "init") { initReceived(json.data); @@ -48,13 +50,28 @@ function createSocket() { } connection.onerror = function (evt) { - console.error("websocket error: ", evt.type); + console.error("Websocket error: ", evt.type); + // this will also fire the onclose after this } connection.onclose = function (evt) { - console.log("WebSocket is closed now: " + evt.type); + console.log("WebSocket is closed: ", evt.type); + // dark overlay displayed so that it's clear the connection has gone + document.getElementById("overlay").style.display = "block"; + // try to reconnect after 1 second + setTimeout(function () { + websocket = createSocket(); + }, 1000); }; + setTimeout(function () { + // close the socket if no connection established after 1 second + // otherwise it will wait with the reconnect after a timeout of 2 minutes + if (websocket.readyState != 1) { + websocket.close(); + } + }, 1000); + return connection; } From edcc2dd59637524f4c1094be8e223ad351711b25 Mon Sep 17 00:00:00 2001 From: sweiland-openrails <118388365+sweiland-openrails@users.noreply.github.com> Date: Sun, 29 Oct 2023 20:51:31 +0100 Subject: [PATCH 2/2] Socket reconnect timeout changed from1 to 3 seconds Looks like 1 second is to short to make a websocket connection when connecting from a different machine --- .../Viewer3D/WebServices/Web/SwitchPanel/index2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js index b0dcc876b5..eda3f022d1 100644 --- a/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js +++ b/Source/RunActivity/Viewer3D/WebServices/Web/SwitchPanel/index2.js @@ -65,12 +65,12 @@ function createSocket() { }; setTimeout(function () { - // close the socket if no connection established after 1 second + // close the socket if no connection established after 3 seconds // otherwise it will wait with the reconnect after a timeout of 2 minutes if (websocket.readyState != 1) { websocket.close(); } - }, 1000); + }, 3000); return connection; }