Skip to content

Commit

Permalink
fix: bug when joining room after re-using peer for host (not recommen…
Browse files Browse the repository at this point in the history
…ded)
  • Loading branch information
therealPaulPlay committed Feb 10, 2025
1 parent 21e12d2 commit 4945495
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playpeerjs",
"version": "1.3.0",
"version": "1.3.1",
"description": "WebRTC-based wrapper for creating robust peer-2-peer multiplayer systems with ease.",
"type": "module",
"main": "dist/playpeer.js",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ export default class PlayPeer {
reject(new Error("Peer not initialized."));
}
try {
if (this.#outgoingConnection) this.#outgoingConnection.close(); // Close previous connection (if exists)
this.#outgoingConnection = this.#peer.connect(hostId, { reliable: true }); // Connect to host
this.#triggerEvent("status", "Connecting to host...");

Expand Down Expand Up @@ -347,8 +346,9 @@ export default class PlayPeer {

// Regularly check if host responds to heartbeat
this.#heartbeatReceived = true;
clearInterval(this.#heartbeatSendInterval); // Prevent multiple ones stacking up in case function fires twice or more
clearInterval(this.#heartbeatSendInterval); // Prevent multiple ones stacking up
this.#heartbeatSendInterval = setInterval(() => {
if (this.#isHost) return clearInterval(this.#heartbeatSendInterval);
if (!this.#heartbeatReceived) {
failedHeartbeatAttempts++;
if (failedHeartbeatAttempts >= 2) {
Expand Down

0 comments on commit 4945495

Please sign in to comment.