Skip to content

Commit

Permalink
websocket: fix heartbeat reconnect (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav authored Oct 26, 2023
2 parents 70f0400 + a3fc429 commit 19993d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-sheep-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solid-primitives/websocket": minor
---

bugfix: setup heartbeat after reconnect
5 changes: 3 additions & 2 deletions packages/websocket/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ export const makeHeartbeatWS = (
clearTimers();
pongtimer = setTimeout(ws.reconnect, options.wait || 1500);
};
ws.addEventListener("close", clearTimers);
const receiveMessage = () => {
clearTimers();
pingtimer = setTimeout(() => ws.send(options.message || "ping"), options.interval || 1000);
};
ws.addEventListener("close", clearTimers);
ws.addEventListener("message", receiveMessage);
setTimeout(receiveMessage, options.interval || 1000);
ws.addEventListener("open", () => setTimeout(receiveMessage, options.interval || 1000));
return ws;
};

0 comments on commit 19993d2

Please sign in to comment.