Skip to content

Commit

Permalink
BREAKING CHANGE: Semantic event name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
therealPaulPlay committed Feb 3, 2025
1 parent 55b8115 commit 6e48d01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
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.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",
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class PlayPeer {
"status",
"error",
"instanceDestroyed",
"storageUpdate",
"hostMigration",
"storageUpdated",
"hostMigrated",
"incomingPeerConnected",
"incomingPeerDisconnected",
"incomingPeerError",
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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 });
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6e48d01

Please sign in to comment.