playsocketjs 2.6.2 → 2.6.3
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 -1
- package/dist/playsocket-server.js +8 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -226,7 +226,7 @@ new PlaySocket(options: PlaySocketServerOptions)
|
|
|
226
226
|
| `onEvent()` | `event: string, callback: Function` | `void` | Register a server-side event callback |
|
|
227
227
|
| `getRoomStorage()` | `roomId: string` | `object` | Get a snapshot of the current room storage |
|
|
228
228
|
| `updateRoomStorage()` | `roomId: string, key: string, type: 'set' \| 'array-add' \| 'array-add-unique' \| 'array-remove-matching' \| 'array-update-matching', value: any, updateValue?: any` | `void` | Update a key in the shared room storage from the server |
|
|
229
|
-
| `createRoom()` | `initialStorage?: object, size?: number, host?: string` | `
|
|
229
|
+
| `createRoom()` | `initialStorage?: object, size?: number, host?: string` | `object` | Create a room (returns object containing room ID and state) – Rooms created with a non-player host like "server" (default) will not be deleted when the last participant leaves |
|
|
230
230
|
| `destroyRoom()` | `roomId: string` | `void` | Destroy a room & kick all participants |
|
|
231
231
|
|
|
232
232
|
### Event types
|
|
@@ -2285,7 +2285,12 @@ class PlaySocketServer {
|
|
|
2285
2285
|
}
|
|
2286
2286
|
|
|
2287
2287
|
try {
|
|
2288
|
-
|
|
2288
|
+
// Event callback with potential initial storage modifications
|
|
2289
|
+
const reviewedStorage = await this.#triggerEvent("roomCreationRequested", { clientId: ws.clientId, initialStorage: structuredClone({ ...data.initialStorage }) });
|
|
2290
|
+
if (typeof reviewedStorage === 'object') data.initialStorage = reviewedStorage;
|
|
2291
|
+
if (reviewedStorage === false) throw new Error("Room creation request denied.");
|
|
2292
|
+
|
|
2293
|
+
const newRoom = this.createRoom(data.initialStorage, data.size, ws.clientId); // Create room
|
|
2289
2294
|
|
|
2290
2295
|
// Check if client/creator is still connected - abort if not
|
|
2291
2296
|
if (!this.#clients.has(ws.clientId)) {
|
|
@@ -2631,18 +2636,12 @@ class PlaySocketServer {
|
|
|
2631
2636
|
|
|
2632
2637
|
/**
|
|
2633
2638
|
* Create a room from the server
|
|
2634
|
-
* @async
|
|
2635
2639
|
* @param {object} [initialStorage] - Optional initial storage object
|
|
2636
2640
|
* @param {number} [size] - Max. room size, up to 500
|
|
2637
2641
|
* @param {string} [host] - Host ID, defaults to "server" (when set to "server", room will not be deleted if all clients leave)
|
|
2638
|
-
* @returns {
|
|
2642
|
+
* @returns {object} Object containing room state and room ID
|
|
2639
2643
|
*/
|
|
2640
|
-
|
|
2641
|
-
// Event callback with potential initial storage modifications
|
|
2642
|
-
const reviewedStorage = await this.#triggerEvent("roomCreationRequested", { clientId: host, initialStorage: structuredClone({ ...initialStorage }) });
|
|
2643
|
-
if (typeof reviewedStorage === 'object') initialStorage = reviewedStorage;
|
|
2644
|
-
if (reviewedStorage === false) throw new Error("Room creation denied.");
|
|
2645
|
-
|
|
2644
|
+
createRoom(initialStorage, size, host = "server") {
|
|
2646
2645
|
let newRoomId;
|
|
2647
2646
|
|
|
2648
2647
|
for (let i = 0; i < 100; i++) {
|