playsocketjs 4.3.2 → 5.0.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
CHANGED
|
@@ -305,7 +305,7 @@ The callback signature is `callback(verified, code?, message?)` where `code` ref
|
|
|
305
305
|
#### Methods
|
|
306
306
|
|
|
307
307
|
> [!IMPORTANT]
|
|
308
|
-
> Rooms created by the server
|
|
308
|
+
> Rooms created by the server are always owned by the host ID "server". Such rooms are not auto-deleted when all participants have left, so you need to take care of their lifecycle.
|
|
309
309
|
|
|
310
310
|
| Name | Parameters | Return type | Description |
|
|
311
311
|
|--------|------------|-------------|-------------|
|
|
@@ -316,7 +316,7 @@ The callback signature is `callback(verified, code?, message?)` where `code` ref
|
|
|
316
316
|
| `getRoomStorage()` | `roomId: string` | `object` | Get a snapshot of the current room storage. |
|
|
317
317
|
| `getUpdateDetails()` | `update: object` | `object` | Get the details (`key`, `type`, `value` and `secondValue`) of a storage update for building validation logic. |
|
|
318
318
|
| `updateRoomStorage()` | `roomId: string, key: string, type: string, value: any, secondValue?: any` | `void` | Update a key in the shared storage of a room. |
|
|
319
|
-
| `createRoom()` | `initialStorage?: object, size?: number
|
|
319
|
+
| `createRoom()` | `initialStorage?: object, size?: number` | `object` | Create a server-owned room (returns object containing room ID and state).|
|
|
320
320
|
| `destroyRoom()` | `roomId: string` | `void` | Destroy a room & kick all participants. |
|
|
321
321
|
|
|
322
322
|
#### Events
|
package/package.json
CHANGED
package/src/server/server.js
CHANGED
|
@@ -258,7 +258,7 @@ export default class PlaySocketServer {
|
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
const newRoom = this
|
|
261
|
+
const newRoom = this.#createRoom(ws.clientId, data.initialStorage, data.size); // Create room
|
|
262
262
|
|
|
263
263
|
this.#rooms[newRoom.id].participants.push(ws.clientId) // Add client to the room
|
|
264
264
|
this.#clientRooms.set(ws.clientId, newRoom.id); // Add client to the client-room map
|
|
@@ -604,14 +604,24 @@ export default class PlaySocketServer {
|
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Create a server-owned room
|
|
609
|
+
* @param {object} [initialStorage] - Optional initial storage object
|
|
610
|
+
* @param {number} [size] - Max. room size, up to 500
|
|
611
|
+
* @returns {{ state: CRDTState, id: string }} Object containing room state and room ID
|
|
612
|
+
*/
|
|
613
|
+
createRoom(initialStorage, size) {
|
|
614
|
+
return this.#createRoom("server", initialStorage, size);
|
|
615
|
+
}
|
|
616
|
+
|
|
607
617
|
/**
|
|
608
618
|
* Create a room
|
|
619
|
+
* @param {string} host - Host ID (when set to "server", room will not be deleted if all clients leave)
|
|
609
620
|
* @param {object} [initialStorage] - Optional initial storage object
|
|
610
621
|
* @param {number} [size] - Max. room size, up to 500
|
|
611
|
-
* @param {string} [host] - Host ID, defaults to "server" (when set to "server", room will not be deleted if all clients leave)
|
|
612
622
|
* @returns {{ state: CRDTState, id: string }} Object containing room state and room ID
|
|
613
623
|
*/
|
|
614
|
-
createRoom(initialStorage, size
|
|
624
|
+
#createRoom(host, initialStorage, size) {
|
|
615
625
|
let newRoomId;
|
|
616
626
|
|
|
617
627
|
for (let i = 0; i < 100; i++) {
|
package/types/server/server.d.ts
CHANGED
|
@@ -120,13 +120,12 @@ export default class PlaySocketServer {
|
|
|
120
120
|
*/
|
|
121
121
|
updateRoomStorage(roomId: string, key: string, type: PropertyUpdateType, value: any, secondValue?: any): void;
|
|
122
122
|
/**
|
|
123
|
-
* Create a room
|
|
123
|
+
* Create a server-owned room
|
|
124
124
|
* @param {object} [initialStorage] - Optional initial storage object
|
|
125
125
|
* @param {number} [size] - Max. room size, up to 500
|
|
126
|
-
* @param {string} [host] - Host ID, defaults to "server" (when set to "server", room will not be deleted if all clients leave)
|
|
127
126
|
* @returns {{ state: CRDTState, id: string }} Object containing room state and room ID
|
|
128
127
|
*/
|
|
129
|
-
createRoom(initialStorage?: object, size?: number
|
|
128
|
+
createRoom(initialStorage?: object, size?: number): {
|
|
130
129
|
state: CRDTState;
|
|
131
130
|
id: string;
|
|
132
131
|
};
|