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