playsocketjs 1.1.11 → 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.
- package/dist/playsocket-client.js +10 -7
- package/package.json +1 -1
|
@@ -2061,7 +2061,7 @@ class PlaySocket {
|
|
|
2061
2061
|
|
|
2062
2062
|
// Room properties
|
|
2063
2063
|
#roomHost;
|
|
2064
|
-
#
|
|
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.#
|
|
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.#
|
|
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
|
|
@@ -2495,6 +2495,9 @@ class PlaySocket {
|
|
|
2495
2495
|
// Signal to the server that it can immediately remove this user
|
|
2496
2496
|
if (this.#socket.readyState === WebSocket.OPEN) this.#sendToServer({ type: 'disconnect' });
|
|
2497
2497
|
this.#socket.close();
|
|
2498
|
+
this.#socket.onmessage = null;
|
|
2499
|
+
this.#socket.onerror = null;
|
|
2500
|
+
this.#socket.onclose = null;
|
|
2498
2501
|
this.#socket = null;
|
|
2499
2502
|
|
|
2500
2503
|
// Trigger events
|
|
@@ -2505,7 +2508,7 @@ class PlaySocket {
|
|
|
2505
2508
|
// Reset state
|
|
2506
2509
|
clearTimeout(this.#reconnectTimeout);
|
|
2507
2510
|
this.#roomHost = null;
|
|
2508
|
-
this.#
|
|
2511
|
+
this.#inRoom = false;
|
|
2509
2512
|
this.#connectionCount = 0;
|
|
2510
2513
|
this.#isReconnecting = false;
|
|
2511
2514
|
this.#reconnectCount = 0;
|