Skip to content

Commit

Permalink
disconnect session on bad ping
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtsukino committed Nov 6, 2024
1 parent 10ebede commit 190777f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/entries/Background/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const connectSession = async () => {
// Check if connection is open
socket.send(bufferify({ method: 'ping' }));
} else {
disconnectSession();
clearInterval(heartbeatInterval); // Stop heartbeat if connection is closed
}
}, 55000);
Expand Down Expand Up @@ -352,7 +353,7 @@ async function handleRemoveIncomingProofRequest(message: {

export const disconnectSession = async () => {
if (!state.socket) return;
await state.socket.close();
const socket = state.socket;
state.socket = null;
state.clientId = '';
state.pairing = '';
Expand All @@ -368,6 +369,7 @@ export const disconnectSession = async () => {
pushToRedux(setOutgoingPairingRequest([]));
pushToRedux(setIncomingProofRequest([]));
pushToRedux(setOutgoingProofRequest([]));
await socket.close();
};

function sendMessage(target: string, method: string, params?: any) {
Expand Down

0 comments on commit 190777f

Please sign in to comment.