Fixed WS reconnection logic onError and onClose (#2591)
Removes duplicated reconnection request when error is reached on Object Browser websocket, also removed the use of the connect call back as it will contain references to the initial request and it is not necessary as we already have information available. Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
@@ -121,7 +121,7 @@ const initWSConnection = (
|
|||||||
|
|
||||||
const reconnectFn = () => {
|
const reconnectFn = () => {
|
||||||
if (errorCounter <= 5) {
|
if (errorCounter <= 5) {
|
||||||
initWSConnection(openCallback, onMessageCallback);
|
initWSConnection(() => {}, onMessageCallback);
|
||||||
errorCounter += 1;
|
errorCounter += 1;
|
||||||
} else {
|
} else {
|
||||||
console.error("Websocket not available.");
|
console.error("Websocket not available.");
|
||||||
@@ -139,9 +139,7 @@ const initWSConnection = (
|
|||||||
objectsWS.onerror = () => {
|
objectsWS.onerror = () => {
|
||||||
wsInFlight = false;
|
wsInFlight = false;
|
||||||
console.error("Error in websocket connection. Attempting reconnection...");
|
console.error("Error in websocket connection. Attempting reconnection...");
|
||||||
|
// Onclose will be triggered by specification, reconnect function will be executed there to avoid duplicated requests
|
||||||
// We reconnect after 3 seconds
|
|
||||||
setTimeout(reconnectFn, 3000);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user