playsocketjs 1.1.5 → 1.1.7
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.
|
@@ -1735,7 +1735,7 @@ function requireCrdtManager () {
|
|
|
1735
1735
|
this.#vectorClock = new Map(vectorClock); // Rebuild the vector clock map
|
|
1736
1736
|
if (!this.#vectorClock.has(this.#replicaId)) this.#vectorClock.set(this.#replicaId, 0); // Add own vector clock if it wasn't present in the imported state
|
|
1737
1737
|
|
|
1738
|
-
// Map operation uuids to timestamp
|
|
1738
|
+
// Map all operation uuids to current timestamp
|
|
1739
1739
|
this.#keyOperations.forEach((value, key) => {
|
|
1740
1740
|
value?.forEach((operation) => {
|
|
1741
1741
|
this.#opUuidTimestamp.set(operation?.uuid, Date.now());
|
|
@@ -2279,7 +2279,7 @@ class PlaySocket {
|
|
|
2279
2279
|
}
|
|
2280
2280
|
break;
|
|
2281
2281
|
|
|
2282
|
-
case '
|
|
2282
|
+
case 'property_updated':
|
|
2283
2283
|
this.#roomVersion++; // Increment room version
|
|
2284
2284
|
if (this.#debug) console.log(LOG_PREFIX + "Property update received:", message.update);
|
|
2285
2285
|
this.#crdtManager.importPropertyUpdate(message.update);
|
|
@@ -2456,8 +2456,7 @@ class PlaySocket {
|
|
|
2456
2456
|
if (this.#debug) console.log(LOG_PREFIX + "Property set update for key '" + key + "':", value);
|
|
2457
2457
|
const propUpdate = this.#crdtManager.updateProperty(key, "set", value);
|
|
2458
2458
|
this.#sendToServer({
|
|
2459
|
-
type: '
|
|
2460
|
-
key,
|
|
2459
|
+
type: 'update_property',
|
|
2461
2460
|
update: propUpdate
|
|
2462
2461
|
});
|
|
2463
2462
|
if (this.#crdtManager.didPropertiesChange) this.#triggerEvent("storageUpdated", this.getStorage); // Always trigger callback after send in case msgs are sent in the callback (which would break the order)
|
|
@@ -2474,8 +2473,7 @@ class PlaySocket {
|
|
|
2474
2473
|
if (this.#debug) console.log(LOG_PREFIX + `Property array update for key '${key}', operation '${operation}', value '${value}' and updateValue '${updateValue}'.`);
|
|
2475
2474
|
const propUpdate = this.#crdtManager.updateProperty(key, "array-" + operation, value, updateValue);
|
|
2476
2475
|
this.#sendToServer({
|
|
2477
|
-
type: '
|
|
2478
|
-
key,
|
|
2476
|
+
type: 'update_property',
|
|
2479
2477
|
update: propUpdate
|
|
2480
2478
|
});
|
|
2481
2479
|
if (this.#crdtManager.didPropertiesChange) this.#triggerEvent("storageUpdated", this.getStorage);
|
|
@@ -1861,7 +1861,7 @@ function requireCrdtManager () {
|
|
|
1861
1861
|
this.#vectorClock = new Map(vectorClock); // Rebuild the vector clock map
|
|
1862
1862
|
if (!this.#vectorClock.has(this.#replicaId)) this.#vectorClock.set(this.#replicaId, 0); // Add own vector clock if it wasn't present in the imported state
|
|
1863
1863
|
|
|
1864
|
-
// Map operation uuids to timestamp
|
|
1864
|
+
// Map all operation uuids to current timestamp
|
|
1865
1865
|
this.#keyOperations.forEach((value, key) => {
|
|
1866
1866
|
value?.forEach((operation) => {
|
|
1867
1867
|
this.#opUuidTimestamp.set(operation?.uuid, Date.now());
|
|
@@ -2230,6 +2230,14 @@ function requireServer () {
|
|
|
2230
2230
|
ws.on('pong', () => { ws.isAlive = true; });
|
|
2231
2231
|
ws.on('message', msg => this.#handleMessage(ws, msg));
|
|
2232
2232
|
ws.on('close', () => this.#handleDisconnection(ws));
|
|
2233
|
+
ws.on('error', (error) => {
|
|
2234
|
+
console.error(`PlaySocket WebSocket connection error for client ${ws.clientId || 'unknown'}:`, error); // Catch conn errors
|
|
2235
|
+
});
|
|
2236
|
+
});
|
|
2237
|
+
|
|
2238
|
+
// Log & catch server-level errors
|
|
2239
|
+
this.#wss.on('error', (error) => {
|
|
2240
|
+
console.error('PlaySocket WebSocket server error:', error);
|
|
2233
2241
|
});
|
|
2234
2242
|
|
|
2235
2243
|
// Start heartbeat
|
|
@@ -2384,11 +2392,11 @@ function requireServer () {
|
|
|
2384
2392
|
this.#triggerEvent("roomJoined", ws.clientId, roomId);
|
|
2385
2393
|
break;
|
|
2386
2394
|
|
|
2387
|
-
case '
|
|
2395
|
+
case 'update_property':
|
|
2388
2396
|
const updateRoomId = this.#clientRooms.get(ws.clientId);
|
|
2389
2397
|
const updateRoom = updateRoomId ? this.#rooms[updateRoomId] : null;
|
|
2390
2398
|
|
|
2391
|
-
if (updateRoom && data.
|
|
2399
|
+
if (updateRoom && data.update) {
|
|
2392
2400
|
updateRoom.crdtManager.importPropertyUpdate(data.update);
|
|
2393
2401
|
|
|
2394
2402
|
// Increment version for this room
|
|
@@ -2400,7 +2408,7 @@ function requireServer () {
|
|
|
2400
2408
|
const client = this.#clients.get(p);
|
|
2401
2409
|
if (client) {
|
|
2402
2410
|
client.send(encode({
|
|
2403
|
-
type: '
|
|
2411
|
+
type: 'property_updated',
|
|
2404
2412
|
update: data.update,
|
|
2405
2413
|
version: currentVersion
|
|
2406
2414
|
}), { binary: true });
|