From 6e48d01e85c57482b7661e87750ed72d347d71ec Mon Sep 17 00:00:00 2001 From: PaulPlay <80539587+therealPaulPlay@users.noreply.github.com> Date: Mon, 3 Feb 2025 20:29:01 +0100 Subject: [PATCH] BREAKING CHANGE: Semantic event name changes --- README.md | 4 ++-- package.json | 2 +- src/index.js | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index df765e2..4a9d325 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ Creates a new PlayPeer instance with a specified peer ID and [PeerJS options](ht - `status`: Connection status updates (returns status `string`) - `error`: Error events (returns error `string`) - `instanceDestroyed`: Peer destruction event -- `storageUpdate`: Storage state changes (returns storage `object`) -- `hostMigration`: Host changes (returns host id / room code `string`) +- `storageUpdated`: Storage state changes (returns storage `object`) +- `hostMigrated`: Host changes (returns host id / room code `string`) - `incomingPeerConnected`: New peer connected (returns peer-id `string`) - `incomingPeerDisconnected`: Peer disconnected (returns peer-id `string`) - `incomingPeerError`: Peer connection error (returns peer-id `string`) diff --git a/package.json b/package.json index ae393c3..8ee0725 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "playpeerjs", - "version": "1.2.4", + "version": "1.2.5", "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 13ae677..eb1759b 100644 --- a/src/index.js +++ b/src/index.js @@ -50,8 +50,8 @@ export default class PlayPeer { "status", "error", "instanceDestroyed", - "storageUpdate", - "hostMigration", + "storageUpdated", + "hostMigrated", "incomingPeerConnected", "incomingPeerDisconnected", "incomingPeerError", @@ -278,7 +278,7 @@ export default class PlayPeer { this.#isHost = true; this.#storage = initialStorage; this.#maxSize = maxSize; // Store the maxSize value - this.#triggerEvent("storageUpdate", { ...this.#storage }); + this.#triggerEvent("storageUpdated", { ...this.#storage }); this.#triggerEvent("status", `Room created${maxSize ? ` with size ${maxSize}` : ''}.`); resolve(this.#id); }); @@ -360,7 +360,7 @@ export default class PlayPeer { // Update storage with host sync only if local save isn't identical if (JSON.stringify(this.#storage) !== JSON.stringify(data.storage)) { this.#storage = data.storage; - this.#triggerEvent("storageUpdate", { ...this.#storage }); + this.#triggerEvent("storageUpdated", { ...this.#storage }); } break; case 'peer_list': @@ -427,7 +427,7 @@ export default class PlayPeer { */ #setStorageLocally(key, value) { this.#storage[key] = value; - this.#triggerEvent("storageUpdate", { ...this.#storage }); + this.#triggerEvent("storageUpdated", { ...this.#storage }); } /** @@ -561,13 +561,13 @@ export default class PlayPeer { this.#isHost = true; this.#outgoingConnection = null; this.#triggerEvent("status", `This peer (index ${index}) is now the host.`); - this.#triggerEvent("hostMigration", this.#id); + this.#triggerEvent("hostMigrated", this.#id); } else { this.#triggerEvent("status", `Attempting to connect to new host (index ${index}) in 1s...`); try { await new Promise(resolve => setTimeout(resolve, 1250)); // Wait to give new host time to detect disconnection & open room await this.joinRoom(connectedPeerIds[index]); - this.#triggerEvent("hostMigration", connectedPeerIds[index]); + this.#triggerEvent("hostMigrated", connectedPeerIds[index]); } catch (error) { this.#triggerEvent("error", "Error migrating host while connecting to new room: " + error); console.warn(WARNING_PREFIX + `Error migrating host (index ${index}) while connecting to new room:`, error);