playsocketjs 2.2.2 → 2.3.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 +1 -0
- package/dist/playsocket-server.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -222,6 +222,7 @@ Creates a new PlaySocket Server instance with configuration options.
|
|
|
222
222
|
- `roomCreated`: Client created a room (returns room ID `string`)
|
|
223
223
|
- `roomDestroyed`: Room was destroyed, this happens when all participants leave (returns room ID `string`)
|
|
224
224
|
- `roomCreationRequested`: Room creation requested by client (returns `object` containing the client's ID `string`, room ID `string` and the initialStorage `object`) – if you return an `object` in the callback, it will take that as the initial storage instead. If you return `false`, the creation will be denied
|
|
225
|
+
- `storageUpdated`: Room storage property updated (returns `object` containing the ID of the client who requested the update `string`, room ID `string`, the update `object`, and the storage `object`)
|
|
225
226
|
- `storageUpdateRequested`: Room storage property update requested by client (returns `object` containing the client's ID `string`, room ID `string` and the update `object`) – if you return `false` in the callback, the update will be blocked
|
|
226
227
|
- `requestReceived`: Request from client was received by the server (returns `object` containing client's ID `string`, if in room – room ID `string`, request name `string` and optional passed data of type `any`)
|
|
227
228
|
|
|
@@ -2500,7 +2500,6 @@ function requireServer () {
|
|
|
2500
2500
|
// Increment version for this room
|
|
2501
2501
|
const currentVersion = this.#roomVersions.get(updateRoomId) + 1;
|
|
2502
2502
|
this.#roomVersions.set(updateRoomId, currentVersion);
|
|
2503
|
-
if (this.#debug) console.log("Property update received and imported:", data.update);
|
|
2504
2503
|
|
|
2505
2504
|
updateRoom.participants?.forEach(p => {
|
|
2506
2505
|
const client = this.#clients.get(p);
|
|
@@ -2512,6 +2511,9 @@ function requireServer () {
|
|
|
2512
2511
|
}), { binary: true });
|
|
2513
2512
|
}
|
|
2514
2513
|
});
|
|
2514
|
+
|
|
2515
|
+
this.#triggerEvent("storageUpdated", { roomId: updateRoomId, clientId: ws.clientId, update: structuredClone(data.update), storage: this.getRoomStorage(updateRoomId) });
|
|
2516
|
+
if (this.#debug) console.log("Property update received and imported:", data.update);
|
|
2515
2517
|
}
|
|
2516
2518
|
break;
|
|
2517
2519
|
|
|
@@ -2660,7 +2662,7 @@ function requireServer () {
|
|
|
2660
2662
|
* @param {Function} callback - Callback function
|
|
2661
2663
|
*/
|
|
2662
2664
|
onEvent(event, callback) {
|
|
2663
|
-
const validEvents = ["clientRegistered", "clientRegistrationRequested", "clientDisconnected", "clientJoinedRoom", "roomCreationRequested", "requestReceived", "
|
|
2665
|
+
const validEvents = ["clientRegistered", "clientRegistrationRequested", "clientDisconnected", "clientJoinedRoom", "roomCreated", "roomCreationRequested", "requestReceived", "storageUpdated", "storageUpdateRequested", "roomDestroyed"];
|
|
2664
2666
|
if (!validEvents.includes(event)) return console.warn(`Invalid PlaySocket event type "${event}"`);
|
|
2665
2667
|
if (!this.#callbacks.has(event)) this.#callbacks.set(event, []);
|
|
2666
2668
|
this.#callbacks.get(event).push(callback);
|