playsocketjs 2.5.3 → 2.5.5
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 -3
- package/dist/playsocket-server.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ new PlaySocket(id?: string, options: PlaySocketOptions)
|
|
|
99
99
|
- `createRoom(initialStorage?: object, maxSize?: number)`: Create a new room and become host – Returns Promise (async) which resolves with the room ID. The room participant maximum is 100
|
|
100
100
|
- `joinRoom(hostId: string)`: Join an existing room – Returns Promise (async)
|
|
101
101
|
- `destroy()`: Use this to leave a room and close the connection
|
|
102
|
-
- `updateStorage(key: string, type: 'set' | 'array-add' | 'array-add-unique' | 'array-remove-matching' | 'array-update-matching', value: any, updateValue?: any)`: Update the shared storage (max. 100 keys).
|
|
102
|
+
- `updateStorage(key: string, type: 'set' | 'array-add' | 'array-add-unique' | 'array-remove-matching' | 'array-update-matching', value: any, updateValue?: any)`: Update a key in the shared storage (max. 100 keys). Array operation types allow for conflict-free simultaneous array updates. For '-matching' operations, value becomes the value to match, and updateValue the replacement.
|
|
103
103
|
- `sendRequest(name: string, data?: any)`: Send requests to the server with optional custom data (handle these in the `requestReceived` server event)
|
|
104
104
|
- `onEvent(event: string, callback: Function)`: Register an event callback
|
|
105
105
|
|
|
@@ -212,7 +212,7 @@ Creates a new PlaySocket Server instance with configuration options.
|
|
|
212
212
|
- `kick(clientId: string, reason?: string)`: Kick a client by their clientID – this will close their connection and set an error message
|
|
213
213
|
- `onEvent(event: string, callback: Function)`: Register a server-side event callback
|
|
214
214
|
- `getRoomStorage(roomId: string)`: Get a snapshot of the current room storage (returns storage `object`)
|
|
215
|
-
- `updateRoomStorage(roomId: string, key: string, type: 'set' | 'array-add' | 'array-add-unique' | 'array-remove-matching' | 'array-update-matching', value: any, updateValue?: any)`: Update the shared room storage from the server.
|
|
215
|
+
- `updateRoomStorage(roomId: string, key: string, type: 'set' | 'array-add' | 'array-add-unique' | 'array-remove-matching' | 'array-update-matching', value: any, updateValue?: any)`: Update a key in the shared room storage from the server.
|
|
216
216
|
|
|
217
217
|
#### Event types
|
|
218
218
|
|
|
@@ -225,7 +225,7 @@ Creates a new PlaySocket Server instance with configuration options.
|
|
|
225
225
|
- `roomDestroyed`: Room was destroyed, this happens when all participants leave (returns room ID `string`)
|
|
226
226
|
- `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
|
|
227
227
|
- `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`)
|
|
228
|
-
- `storageUpdateRequested`: Room storage property update requested by client (returns `object` containing the client's ID `string`, room ID `string` and the
|
|
228
|
+
- `storageUpdateRequested`: Room storage property update requested by client (returns `object` containing the client's ID `string`, room ID `string`, the update `object`, and the current storage `object` that hasn't been updated yet) – if you return `false` in the callback, the update will be blocked
|
|
229
229
|
- `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`)
|
|
230
230
|
|
|
231
231
|
### Properties (Read-only)
|
|
@@ -2393,7 +2393,7 @@ class PlaySocketServer {
|
|
|
2393
2393
|
|
|
2394
2394
|
if (room && data.update) {
|
|
2395
2395
|
// Check if update is allowed via event callback (provide clone to ensure update integrity)
|
|
2396
|
-
const updateAllowed = await this.#triggerEvent("storageUpdateRequested", { roomId, clientId: ws.clientId, update: structuredClone(data.update) });
|
|
2396
|
+
const updateAllowed = await this.#triggerEvent("storageUpdateRequested", { roomId, clientId: ws.clientId, update: structuredClone(data.update), storage: this.getRoomStorage(roomId) });
|
|
2397
2397
|
if (updateAllowed === false) {
|
|
2398
2398
|
ws.send(encode({
|
|
2399
2399
|
type: 'property_update_rejected',
|