playsocketjs 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/playsocket-server.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,9 +257,10 @@ The callback signature is `callback(verified, code?, message?)` where `code` and
|
|
|
257
257
|
|-------|-------------------|-------------|--------------|
|
|
258
258
|
| `clientRegistered` | `clientId: string, customData: object` | Client registered with the server | - |
|
|
259
259
|
| `clientRegistrationRequested` | `clientId: string, customData: object` | Client requests to register | Return `false` or rejection reason `string` to block |
|
|
260
|
-
| `
|
|
261
|
-
| `clientJoinedRoom` | `clientId: string, roomId: string` | Client joined a room
|
|
260
|
+
| `clientDisconnected` | `clientId: string` | Client disconnected from the server | - |
|
|
261
|
+
| `clientJoinedRoom` | `clientId: string, roomId: string` | Client joined a room | - |
|
|
262
262
|
| `clientJoinRequested` | `clientId: string, roomId: string` | Client requests to join a room | Return `false` or rejection reason `string` to block |
|
|
263
|
+
| `clientLeftRoom` | `clientId: string, roomId: string` | Client left a room | - |
|
|
263
264
|
| `roomCreated` | `roomId: string` | Client created a room | - |
|
|
264
265
|
| `roomDestroyed` | `roomId: string` | Room was destroyed (happens when all participants leave, unless room host is "server") | - |
|
|
265
266
|
| `roomCreationRequested` | `{clientId: string, initialStorage: object}` | Room creation requested by client | Return `object` to override initial storage, `false` to deny |
|
|
@@ -2538,7 +2538,7 @@ class PlaySocketServer {
|
|
|
2538
2538
|
this.#clientTokens.delete(ws.clientId);
|
|
2539
2539
|
const roomId = this.#clientRooms.get(ws.clientId);
|
|
2540
2540
|
if (roomId && this.#rooms[roomId]) this.#leaveRoom(ws.clientId, roomId);
|
|
2541
|
-
this.#triggerEvent("clientDisconnected", ws.clientId
|
|
2541
|
+
this.#triggerEvent("clientDisconnected", ws.clientId);
|
|
2542
2542
|
}
|
|
2543
2543
|
|
|
2544
2544
|
/**
|
|
@@ -2547,7 +2547,7 @@ class PlaySocketServer {
|
|
|
2547
2547
|
* @param {Function} callback - Callback function
|
|
2548
2548
|
*/
|
|
2549
2549
|
onEvent(event, callback) {
|
|
2550
|
-
const validEvents = ["clientRegistered", "clientRegistrationRequested", "clientDisconnected", "clientJoinedRoom", "clientJoinRequested", "roomCreated", "roomCreationRequested", "requestReceived", "storageUpdated", "storageUpdateRequested", "roomDestroyed"];
|
|
2550
|
+
const validEvents = ["clientRegistered", "clientRegistrationRequested", "clientDisconnected", "clientJoinedRoom", "clientLeftRoom", "clientJoinRequested", "roomCreated", "roomCreationRequested", "requestReceived", "storageUpdated", "storageUpdateRequested", "roomDestroyed"];
|
|
2551
2551
|
if (!validEvents.includes(event)) {
|
|
2552
2552
|
console.warn(`Invalid PlaySocket event type "${event}"`);
|
|
2553
2553
|
return;
|
|
@@ -2748,6 +2748,7 @@ class PlaySocketServer {
|
|
|
2748
2748
|
|
|
2749
2749
|
room.participants = room.participants.filter(p => p !== clientId); // Remove client from room
|
|
2750
2750
|
this.#clientRooms.delete(clientId);
|
|
2751
|
+
this.#triggerEvent("clientLeftRoom", clientId, roomId); // Before potential room destruction to allow for accessing its data in callback
|
|
2751
2752
|
|
|
2752
2753
|
if (room.participants.length === 0 && room.host !== "server") {
|
|
2753
2754
|
this.destroyRoom(roomId); // Destroy room if now empty & not by server
|