From 49454959b9629e6599f6a163a7c0fc116d552127 Mon Sep 17 00:00:00 2001 From: PaulPlay <80539587+therealPaulPlay@users.noreply.github.com> Date: Mon, 10 Feb 2025 01:13:08 +0100 Subject: [PATCH] fix: bug when joining room after re-using peer for host (not recommended) --- package.json | 2 +- src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 141701e..f79d8fb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 8f16506..38ef816 100644 --- a/src/index.js +++ b/src/index.js @@ -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..."); @@ -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) {