@signe/room 2.6.0 → 2.7.1

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/index.d.ts CHANGED
@@ -706,6 +706,11 @@ interface RoomOnLeave {
706
706
  interface RoomMethods {
707
707
  $send: (conn: Connection, obj: any) => void;
708
708
  $broadcast: (obj: any) => void;
709
+ $applySync: () => void;
710
+ $sessionTransfer: (conn: Connection, targetRoomId: string) => Promise<string | null>;
711
+ $pendingSync: Map<string, any>;
712
+ $memoryAll: Map<string, any>;
713
+ $autoSync: boolean;
709
714
  }
710
715
 
711
716
  declare class ServerResponse {
package/dist/index.js CHANGED
@@ -614,12 +614,30 @@ var Server = class {
614
614
  load(instance, tmpObject, true);
615
615
  }, "loadMemory");
616
616
  instance.$memoryAll = {};
617
+ instance.$autoSync = instance["autoSync"] !== false;
618
+ instance.$pendingSync = /* @__PURE__ */ new Map();
617
619
  instance.$send = (conn, obj) => {
618
620
  return this.send(conn, obj, instance);
619
621
  };
620
622
  instance.$broadcast = (obj) => {
621
623
  return this.broadcast(obj, instance);
622
624
  };
625
+ instance.$applySync = () => {
626
+ let packet;
627
+ if (instance.$pendingSync.size > 0) {
628
+ if (options.getMemoryAll) {
629
+ buildObject(instance.$pendingSync, instance.$memoryAll);
630
+ }
631
+ packet = buildObject(instance.$pendingSync, instance.$memoryAll);
632
+ instance.$pendingSync.clear();
633
+ } else {
634
+ packet = instance.$memoryAll;
635
+ }
636
+ this.broadcast({
637
+ type: "sync",
638
+ value: packet
639
+ }, instance);
640
+ };
623
641
  instance.$sessionTransfer = async (conn, targetRoomId) => {
624
642
  let user;
625
643
  const signal2 = this.getUsersProperty(instance);
@@ -686,6 +704,13 @@ var Server = class {
686
704
  init = false;
687
705
  return;
688
706
  }
707
+ if (!instance.$autoSync) {
708
+ for (const [path, value] of values) {
709
+ instance.$pendingSync.set(path, value);
710
+ }
711
+ values.clear();
712
+ return;
713
+ }
689
714
  const packet = buildObject(values, instance.$memoryAll);
690
715
  this.broadcast({
691
716
  type: "sync",
@@ -710,11 +735,12 @@ var Server = class {
710
735
  values.clear();
711
736
  }, "persistCb");
712
737
  syncClass(instance, {
713
- onSync: throttle(syncCb, instance["throttleSync"] ?? 500),
714
- onPersist: throttle(persistCb, instance["throttleStorage"] ?? 2e3)
738
+ onSync: instance["throttleSync"] ? throttle(syncCb, instance["throttleSync"]) : syncCb,
739
+ onPersist: instance["throttleStorage"] ? throttle(persistCb, instance["throttleStorage"]) : persistCb
715
740
  });
716
741
  await loadMemory();
717
742
  initPersist = false;
743
+ init = false;
718
744
  return instance;
719
745
  }
720
746
  /**