From 26af8c66ac09e07eec2be103af6afb5fc1dbe8f3 Mon Sep 17 00:00:00 2001 From: Tag Date: Wed, 22 Feb 2023 16:51:31 -0800 Subject: [PATCH] Better close of websocket handling --- package.nw/lib/gt.js | 11 +++++------ package.nw/lib/gtws.js | 25 +++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index 8c81dd3..ee1b8b9 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -2719,6 +2719,7 @@ function onRightClickGridSquare(feature) new_win.on("loaded", function () { GT.popupWindowHandle.show(); + GT.popupWindowHandle.focus(); renderTooltipWindow(feature); }); new_win.on("close", function () @@ -7727,9 +7728,9 @@ function resetSearch() GT.lastSearchSelection = null; } -function showWorkedByCall(callsign, evt) +function showWorkedByCall(callsign, event) { - evt.preventDefault(); + event.preventDefault(); resetSearch(); GT.searchWB = callsign; @@ -7830,10 +7831,7 @@ function showWorkedBox(sortIndex, nextPage, redraw) bands[list[key].band] = list[key].band; modes[list[key].mode] = list[key].mode; var unconfirmedCallsKey = new UnconfirmedCallsKey(list[key].dxcc, list[key].band); - if ( - GT.unconfirmedCalls.has(unconfirmedCallsKey.key) && - list[key].confirmed - ) + if (GT.unconfirmedCalls.has(unconfirmedCallsKey.key) && list[key].confirmed) { GT.unconfirmedCalls.set(unconfirmedCallsKey.key, GT.unconfirmedCallsSentinel); } @@ -8447,6 +8445,7 @@ function showDXCCsBox() new_win.on("loaded", function () { GT.popupWindowHandle.show(); + GT.popupWindowHandle.focus(); renderTooltipWindowLogbook(GT.unconfirmedCalls.get(unconfirmedCallsKey.key)); }); new_win.on("close", function () diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index 7e9405e..398bfb5 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -120,11 +120,14 @@ function gtConnectChat() GT.gtChatSocket.onerror = function () { + this.close(); + GT.gtChatSocket = null; GT.gtState = ChatState.error; }; GT.gtChatSocket.onclose = function () { + GT.gtChatSocket = null; GT.gtState = ChatState.closed; }; } @@ -151,20 +154,20 @@ function closeGtSocket() { gtChatSendClose(); - if (GT.gtChatSocket.readyState != WebSocket.CLOSED) GT.gtChatSocket.close(); - - if (GT.gtChatSocket.readyState === WebSocket.CLOSED) - { - GT.gtChatSocket = null; - GT.gtState = ChatState.none; - } + GT.gtChatSocket.close(); + GT.gtChatSocket = null; + GT.gtState = ChatState.none; } else GT.gtState = ChatState.none; } function gtClosedSocket() { - GT.gtChatSocket = null; + if (GT.gtChatSocket != null) + { + GT.gtChatSocket.close(); + GT.gtChatSocket = null; + } GT.gtState = ChatState.none; } @@ -320,12 +323,6 @@ function gtChatRemoveCall(jsmesg) { delete GT.gtFlagPins[cid].ids[id]; } - else - { - console.log("drop: No such id in GT.gtFlagPins.ids:"); - console.log(jsmesg); - console.log(GT.gtFlagPins[cid].ids); - } if (Object.keys(GT.gtFlagPins[cid].ids).length == 0) {