playsocketjs 1.0.3 → 1.0.4

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.
@@ -333,13 +333,14 @@ class PlaySocket {
333
333
  */
334
334
  updateStorage(key, value) {
335
335
  if (JSON.stringify(this.#storage[key]) === JSON.stringify(value)) return;
336
- this.#storage[key] = value;
337
- this.#triggerEvent("storageUpdated", { ...this.#storage });
338
336
  this.#sendToServer({
339
337
  type: 'room_storage_update',
340
338
  key,
341
339
  value
342
340
  });
341
+ // Optimistic update AFTER sendToServer to preserve order if messages are being sent in the event callback
342
+ this.#storage[key] = value;
343
+ this.#triggerEvent("storageUpdated", { ...this.#storage });
343
344
  }
344
345
 
345
346
  /**
@@ -350,7 +351,6 @@ class PlaySocket {
350
351
  * @param {*} updateValue - New value for update-matching
351
352
  */
352
353
  updateStorageArray(key, operation, value, updateValue) {
353
- this.#handleArrayUpdate(key, operation, value, updateValue);
354
354
  this.#sendToServer({
355
355
  type: 'room_storage_array_update',
356
356
  key,
@@ -358,6 +358,8 @@ class PlaySocket {
358
358
  value,
359
359
  updateValue
360
360
  });
361
+ // Optimistic update AFTER sendToServer to preserve order if messages are being sent in the event callback
362
+ this.#handleArrayUpdate(key, operation, value, updateValue);
361
363
  }
362
364
 
363
365
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsocketjs",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "WebSocket wrapper for creating simple multiplayer systems with ease.",
5
5
  "module": "dist/playsocket-client.js",
6
6
  "exports": {