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) {