playsocketjs 1.1.12 → 1.1.13

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.
@@ -2061,7 +2061,7 @@ class PlaySocket {
2061
2061
 
2062
2062
  // Room properties
2063
2063
  #roomHost;
2064
- #roomId; // ID of the host (client only)
2064
+ #inRoom; // If the client is currently in a room or not
2065
2065
  #connectionCount = 0;
2066
2066
  #crdtManager;
2067
2067
  #roomVersion = 0; // Update version (used to compare local vs. remote state to detect package loss)
@@ -2202,6 +2202,7 @@ class PlaySocket {
2202
2202
  // Connected to room
2203
2203
  if (this.#pendingJoin) {
2204
2204
  if (this.#debug) console.log(LOG_PREFIX + "State received for join:", message.state);
2205
+ this.#inRoom = true;
2205
2206
  this.#crdtManager.importState(message.state);
2206
2207
  this.#connectionCount = message.participantCount - 1; // Counted without the user themselves
2207
2208
  this.#roomHost = message.host;
@@ -2232,7 +2233,7 @@ class PlaySocket {
2232
2233
  this.#connectionCount = message.roomData.participantCount - 1; // Counted without the user themselves
2233
2234
  this.#setHost(message.roomData.host); // Set host before in case there are .isHost checks in the storageUpdate fallback
2234
2235
  this.#triggerEvent("storageUpdated", this.getStorage);
2235
- } else if (this.#roomId) {
2236
+ } else if (this.#inRoom) {
2236
2237
  // If no room data received, but client thinks they were in a room...
2237
2238
  this.#triggerEvent("error", "Reconnected, but room no longer exists.");
2238
2239
  return this.destroy();
@@ -2248,8 +2249,9 @@ class PlaySocket {
2248
2249
 
2249
2250
  case 'room_created':
2250
2251
  if (this.#pendingCreate) {
2252
+ this.#inRoom = true;
2251
2253
  this.#triggerEvent("status", `Room created${this.#pendingCreate.maxSize ? ` with max size ${this.#pendingCreate.maxSize}.` : '.'}`);
2252
- this.#pendingCreate.resolve(this.#roomId);
2254
+ this.#pendingCreate.resolve(this.#pendingCreate.id);
2253
2255
  }
2254
2256
  break;
2255
2257
 
@@ -2408,9 +2410,8 @@ class PlaySocket {
2408
2410
  Object.entries(initialStorage)?.forEach(([key, value]) => {
2409
2411
  this.#crdtManager.updateProperty(key, "set", value);
2410
2412
  });
2411
- this.#roomId = this.#id; // Create room with your own ID as the room ID to mimic p2p
2412
2413
  this.#roomHost = this.#id;
2413
- this.#pendingCreate = { maxSize, resolve, reject };
2414
+ this.#pendingCreate = { maxSize, id: this.#id, resolve, reject };
2414
2415
  this.#sendToServer({
2415
2416
  type: 'create_room',
2416
2417
  state: this.#crdtManager.getState,
@@ -2437,7 +2438,6 @@ class PlaySocket {
2437
2438
 
2438
2439
  return Promise.race([
2439
2440
  new Promise((resolve, reject) => {
2440
- this.#roomId = roomId;
2441
2441
  this.#pendingJoin = { resolve, reject };
2442
2442
 
2443
2443
  // Send connection request
@@ -2508,7 +2508,7 @@ class PlaySocket {
2508
2508
  // Reset state
2509
2509
  clearTimeout(this.#reconnectTimeout);
2510
2510
  this.#roomHost = null;
2511
- this.#roomId = null;
2511
+ this.#inRoom = false;
2512
2512
  this.#connectionCount = 0;
2513
2513
  this.#isReconnecting = false;
2514
2514
  this.#reconnectCount = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsocketjs",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "WebSocket wrapper for creating simple multiplayer systems with ease.",
5
5
  "module": "dist/playsocket-client.js",
6
6
  "exports": {