@signe/room 2.7.2 → 2.8.0
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.js +37 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +68 -1
- package/src/server.ts +49 -12
package/dist/index.js
CHANGED
|
@@ -100,7 +100,7 @@ var Storage = class {
|
|
|
100
100
|
// src/server.ts
|
|
101
101
|
import { dset as dset2 } from "dset";
|
|
102
102
|
import z from "zod";
|
|
103
|
-
import { createStatesSnapshot, getByPath, load, syncClass, DELETE_TOKEN, generateShortUUID as generateShortUUID2 } from "@signe/sync";
|
|
103
|
+
import { createStatesSnapshot, getByPath, load, syncClass, DELETE_TOKEN, generateShortUUID as generateShortUUID2, createStatesSnapshotDeep } from "@signe/sync";
|
|
104
104
|
|
|
105
105
|
// src/utils.ts
|
|
106
106
|
import { dset } from "dset";
|
|
@@ -616,6 +616,7 @@ var Server = class {
|
|
|
616
616
|
instance.$memoryAll = {};
|
|
617
617
|
instance.$autoSync = instance["autoSync"] !== false;
|
|
618
618
|
instance.$pendingSync = /* @__PURE__ */ new Map();
|
|
619
|
+
instance.$pendingInitialSync = /* @__PURE__ */ new Map();
|
|
619
620
|
instance.$send = (conn, obj) => {
|
|
620
621
|
return this.send(conn, obj, instance);
|
|
621
622
|
};
|
|
@@ -633,10 +634,25 @@ var Server = class {
|
|
|
633
634
|
} else {
|
|
634
635
|
packet = instance.$memoryAll;
|
|
635
636
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
637
|
+
const pendingConnections = new Set(instance.$pendingInitialSync.keys());
|
|
638
|
+
for (const [conn, publicId] of instance.$pendingInitialSync) {
|
|
639
|
+
this.send(conn, {
|
|
640
|
+
type: "sync",
|
|
641
|
+
value: {
|
|
642
|
+
pId: publicId,
|
|
643
|
+
...packet
|
|
644
|
+
}
|
|
645
|
+
}, instance);
|
|
646
|
+
}
|
|
647
|
+
instance.$pendingInitialSync.clear();
|
|
648
|
+
for (const conn of this.room.getConnections()) {
|
|
649
|
+
if (!pendingConnections.has(conn)) {
|
|
650
|
+
this.send(conn, {
|
|
651
|
+
type: "sync",
|
|
652
|
+
value: packet
|
|
653
|
+
}, instance);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
640
656
|
};
|
|
641
657
|
instance.$sessionTransfer = async (conn, targetRoomId) => {
|
|
642
658
|
let user;
|
|
@@ -670,7 +686,7 @@ var Server = class {
|
|
|
670
686
|
console.error("[sessionTransfer] `users` property not defined in the room.");
|
|
671
687
|
return null;
|
|
672
688
|
}
|
|
673
|
-
const userSnapshot =
|
|
689
|
+
const userSnapshot = createStatesSnapshotDeep(user);
|
|
674
690
|
const transferData = {
|
|
675
691
|
privateId,
|
|
676
692
|
userSnapshot,
|
|
@@ -925,7 +941,7 @@ var Server = class {
|
|
|
925
941
|
} else {
|
|
926
942
|
user = isClass(classType) ? new classType() : classType(conn, ctx);
|
|
927
943
|
signal2()[publicId] = user;
|
|
928
|
-
const snapshot =
|
|
944
|
+
const snapshot = createStatesSnapshotDeep(user);
|
|
929
945
|
this.room.storage.put(`${usersPropName}.${publicId}`, snapshot);
|
|
930
946
|
}
|
|
931
947
|
} else {
|
|
@@ -954,6 +970,8 @@ var Server = class {
|
|
|
954
970
|
...subRoom.$memoryAll
|
|
955
971
|
}
|
|
956
972
|
}, subRoom);
|
|
973
|
+
} else {
|
|
974
|
+
subRoom.$pendingInitialSync.set(conn, publicId);
|
|
957
975
|
}
|
|
958
976
|
}
|
|
959
977
|
/**
|
|
@@ -1239,6 +1257,9 @@ var Server = class {
|
|
|
1239
1257
|
if (!subRoom) {
|
|
1240
1258
|
return;
|
|
1241
1259
|
}
|
|
1260
|
+
if (subRoom.$pendingInitialSync) {
|
|
1261
|
+
subRoom.$pendingInitialSync.delete(conn);
|
|
1262
|
+
}
|
|
1242
1263
|
const signal2 = this.getUsersProperty(subRoom);
|
|
1243
1264
|
if (!conn.state) {
|
|
1244
1265
|
return;
|
|
@@ -1321,9 +1342,16 @@ var Server = class {
|
|
|
1321
1342
|
if (signal2 && usersPropName) {
|
|
1322
1343
|
const { classType } = signal2.options;
|
|
1323
1344
|
const user = isClass(classType) ? new classType() : classType();
|
|
1324
|
-
|
|
1345
|
+
const hydratedSnapshot = await awaitReturn(subRoom["onSessionRestore"]?.({
|
|
1346
|
+
userSnapshot,
|
|
1347
|
+
publicId,
|
|
1348
|
+
privateId,
|
|
1349
|
+
sessionState,
|
|
1350
|
+
room: this.room
|
|
1351
|
+
})) ?? userSnapshot;
|
|
1352
|
+
load(user, hydratedSnapshot, true);
|
|
1325
1353
|
signal2()[publicId] = user;
|
|
1326
|
-
await this.room.storage.put(`${usersPropName}.${publicId}`,
|
|
1354
|
+
await this.room.storage.put(`${usersPropName}.${publicId}`, hydratedSnapshot);
|
|
1327
1355
|
}
|
|
1328
1356
|
}
|
|
1329
1357
|
const transferToken = generateShortUUID2();
|