@pluv/io 2.1.0 → 2.2.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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +19 -16
- package/dist/index.d.ts +19 -16
- package/dist/index.js +124 -91
- package/dist/index.mjs +124 -91
- package/package.json +5 -5
- package/src/IORoom.ts +11 -5
- package/src/PluvIO.ts +7 -5
- package/src/PluvServer.ts +238 -214
- package/src/createIO.ts +1 -1
- package/src/types.ts +13 -8
- package/src/version.generated.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -613,6 +613,7 @@ var IORoom = class {
|
|
|
613
613
|
this._listeners.onUserDisconnected({
|
|
614
614
|
context: this._context,
|
|
615
615
|
encodedState,
|
|
616
|
+
platform: this._platform,
|
|
616
617
|
room: this.id,
|
|
617
618
|
user
|
|
618
619
|
})
|
|
@@ -670,6 +671,7 @@ var IORoom = class {
|
|
|
670
671
|
this._listeners.onUserConnected({
|
|
671
672
|
context: this._context,
|
|
672
673
|
encodedState,
|
|
674
|
+
platform: this._platform,
|
|
673
675
|
room: this.id,
|
|
674
676
|
user,
|
|
675
677
|
webSocket: pluvWs.webSocket
|
|
@@ -833,6 +835,7 @@ var IORoom = class {
|
|
|
833
835
|
this._listeners.onDestroy(__spreadProps(__spreadValues({}, "_meta" in this._platform && !!this._platform._meta ? { _meta: this._platform._meta } : {}), {
|
|
834
836
|
context: this._context,
|
|
835
837
|
encodedState,
|
|
838
|
+
platform: this._platform,
|
|
836
839
|
room: this.id
|
|
837
840
|
}))
|
|
838
841
|
);
|
|
@@ -871,6 +874,7 @@ var IORoom = class {
|
|
|
871
874
|
garbageCollect: () => __async(this, null, function* () {
|
|
872
875
|
yield this.garbageCollect();
|
|
873
876
|
}),
|
|
877
|
+
platform: this._platform,
|
|
874
878
|
get presence() {
|
|
875
879
|
return session.presence;
|
|
876
880
|
},
|
|
@@ -897,6 +901,7 @@ var IORoom = class {
|
|
|
897
901
|
context: this._context,
|
|
898
902
|
encodedState: doc.getEncodedState(),
|
|
899
903
|
message,
|
|
904
|
+
platform: this._platform,
|
|
900
905
|
room: this.id,
|
|
901
906
|
user: session.user,
|
|
902
907
|
webSocket: session.webSocket.webSocket
|
|
@@ -1063,6 +1068,7 @@ var IORoom = class {
|
|
|
1063
1068
|
garbageCollect: () => __async(this, null, function* () {
|
|
1064
1069
|
yield this.garbageCollect();
|
|
1065
1070
|
}),
|
|
1071
|
+
platform: this._platform,
|
|
1066
1072
|
get presence() {
|
|
1067
1073
|
return null;
|
|
1068
1074
|
},
|
|
@@ -1114,14 +1120,74 @@ var pickBy = (obj, by) => {
|
|
|
1114
1120
|
};
|
|
1115
1121
|
|
|
1116
1122
|
// src/version.generated.ts
|
|
1117
|
-
var version = "2.
|
|
1123
|
+
var version = "2.2.0";
|
|
1118
1124
|
|
|
1119
1125
|
// src/PluvServer.ts
|
|
1120
1126
|
var PluvServer = class {
|
|
1121
1127
|
constructor(options) {
|
|
1122
1128
|
this.version = version;
|
|
1123
1129
|
this._authorize = null;
|
|
1124
|
-
this.
|
|
1130
|
+
this._context = {};
|
|
1131
|
+
this._getInitialStorage = null;
|
|
1132
|
+
const {
|
|
1133
|
+
authorize: authorize2,
|
|
1134
|
+
context,
|
|
1135
|
+
crdt = noop2,
|
|
1136
|
+
debug = false,
|
|
1137
|
+
getInitialStorage,
|
|
1138
|
+
io,
|
|
1139
|
+
limits,
|
|
1140
|
+
platform,
|
|
1141
|
+
router = new PluvRouter({})
|
|
1142
|
+
} = options;
|
|
1143
|
+
const {
|
|
1144
|
+
onRoomDeleted,
|
|
1145
|
+
onRoomMessage,
|
|
1146
|
+
onStorageUpdated,
|
|
1147
|
+
onUserConnected,
|
|
1148
|
+
onUserDisconnected
|
|
1149
|
+
} = options;
|
|
1150
|
+
platform().validateConfig(options);
|
|
1151
|
+
this._crdt = crdt;
|
|
1152
|
+
this._debug = debug;
|
|
1153
|
+
this._inputRouter = router;
|
|
1154
|
+
this._io = io;
|
|
1155
|
+
this._limits = limits;
|
|
1156
|
+
this._platform = platform;
|
|
1157
|
+
if (authorize2) this._authorize = authorize2;
|
|
1158
|
+
if (context) this._context = context;
|
|
1159
|
+
if (getInitialStorage) this._getInitialStorage = getInitialStorage;
|
|
1160
|
+
this._listeners = {
|
|
1161
|
+
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
1162
|
+
onRoomMessage: (event) => onRoomMessage == null ? void 0 : onRoomMessage(event),
|
|
1163
|
+
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event),
|
|
1164
|
+
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
1165
|
+
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
get fetch() {
|
|
1169
|
+
const platform = this._platform();
|
|
1170
|
+
return (...args) => {
|
|
1171
|
+
if (!platform._fetch)
|
|
1172
|
+
throw new Error(`\`${platform._name}\` does not support \`fetch\``);
|
|
1173
|
+
return platform._fetch(...args);
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* @ignore
|
|
1178
|
+
* @readonly
|
|
1179
|
+
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
1180
|
+
*/
|
|
1181
|
+
get _defs() {
|
|
1182
|
+
return {
|
|
1183
|
+
authorize: this._authorize,
|
|
1184
|
+
context: this._context,
|
|
1185
|
+
events: this._router._defs.events,
|
|
1186
|
+
platform: this._platform()
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
get _baseRouter() {
|
|
1190
|
+
return new PluvRouter({
|
|
1125
1191
|
$getOthers: this._procedure.sync((data, { room, session, sessions }) => {
|
|
1126
1192
|
const currentTime = Date.now();
|
|
1127
1193
|
const others = sessions.filter((wsSession) => {
|
|
@@ -1156,9 +1222,9 @@ var PluvServer = class {
|
|
|
1156
1222
|
timers: { presence: timers.presence }
|
|
1157
1223
|
}
|
|
1158
1224
|
};
|
|
1159
|
-
}).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, room, session }) {
|
|
1225
|
+
}).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, platform, room, session }) {
|
|
1160
1226
|
var _a;
|
|
1161
|
-
const oldState = yield
|
|
1227
|
+
const oldState = yield platform.persistence.getStorageState(room);
|
|
1162
1228
|
const update = data == null ? void 0 : data.update;
|
|
1163
1229
|
if (!oldState) {
|
|
1164
1230
|
const loadedState = yield (_a = this._getInitialStorage) == null ? void 0 : _a.call(this, { context, room });
|
|
@@ -1168,7 +1234,9 @@ var PluvServer = class {
|
|
|
1168
1234
|
}
|
|
1169
1235
|
if (!doc.isEmpty()) {
|
|
1170
1236
|
const encodedState2 = doc.getEncodedState();
|
|
1171
|
-
return {
|
|
1237
|
+
return {
|
|
1238
|
+
$storageReceived: { changeKind: "unchanged", state: encodedState2 }
|
|
1239
|
+
};
|
|
1172
1240
|
}
|
|
1173
1241
|
if (!!update) {
|
|
1174
1242
|
const encodedState2 = doc.applyEncodedState({ update }).getEncodedState();
|
|
@@ -1176,26 +1244,29 @@ var PluvServer = class {
|
|
|
1176
1244
|
if (!!this._limits.storageMaxSize && storageSize > this._limits.storageMaxSize) {
|
|
1177
1245
|
throw new Error("Storage has exceeded the size limit");
|
|
1178
1246
|
}
|
|
1179
|
-
yield
|
|
1247
|
+
yield platform.persistence.setStorageState(room, encodedState2).catch((error) => {
|
|
1180
1248
|
this._logDebug(error);
|
|
1181
1249
|
});
|
|
1182
1250
|
this._getListeners().onStorageUpdated({
|
|
1183
1251
|
context,
|
|
1184
1252
|
encodedState: encodedState2,
|
|
1253
|
+
platform,
|
|
1185
1254
|
room,
|
|
1186
1255
|
user: session == null ? void 0 : session.user,
|
|
1187
1256
|
webSocket: session == null ? void 0 : session.webSocket.webSocket
|
|
1188
1257
|
});
|
|
1189
|
-
return {
|
|
1258
|
+
return {
|
|
1259
|
+
$storageReceived: { changeKind: "initialized", state: encodedState2 }
|
|
1260
|
+
};
|
|
1190
1261
|
}
|
|
1191
1262
|
const encodedState = doc.getEncodedState();
|
|
1192
1263
|
return { $storageReceived: { changeKind: "empty", state: encodedState } };
|
|
1193
1264
|
})),
|
|
1194
|
-
$ping: this._procedure.self((data, { session }) => {
|
|
1265
|
+
$ping: this._procedure.self((data, { platform, session }) => {
|
|
1195
1266
|
if (!session) return {};
|
|
1196
1267
|
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1197
1268
|
const prevState = session.webSocket.state;
|
|
1198
|
-
|
|
1269
|
+
platform.setSerializedState(session.webSocket, __spreadProps(__spreadValues({}, prevState), {
|
|
1199
1270
|
timers: __spreadProps(__spreadValues({}, prevState.timers), {
|
|
1200
1271
|
ping: currentTime
|
|
1201
1272
|
})
|
|
@@ -1206,7 +1277,10 @@ var PluvServer = class {
|
|
|
1206
1277
|
const presence = data == null ? void 0 : data.presence;
|
|
1207
1278
|
const { session } = context;
|
|
1208
1279
|
if (!session) return {};
|
|
1209
|
-
const cleanedPatch = pickBy(
|
|
1280
|
+
const cleanedPatch = pickBy(
|
|
1281
|
+
presence != null ? presence : {},
|
|
1282
|
+
(value) => typeof value !== "undefined"
|
|
1283
|
+
);
|
|
1210
1284
|
const updated = Object.assign(/* @__PURE__ */ Object.create(null), session.presence, cleanedPatch);
|
|
1211
1285
|
const bytes = new TextEncoder().encode(JSON.stringify(updated)).length;
|
|
1212
1286
|
if (!!this._limits.presenceMaxSize && bytes > this._limits.presenceMaxSize) {
|
|
@@ -1222,7 +1296,7 @@ var PluvServer = class {
|
|
|
1222
1296
|
}
|
|
1223
1297
|
};
|
|
1224
1298
|
}),
|
|
1225
|
-
$updateStorage: this._procedure.broadcast((data, { context, doc, room }) => {
|
|
1299
|
+
$updateStorage: this._procedure.broadcast((data, { context, doc, platform, room }) => {
|
|
1226
1300
|
var _a;
|
|
1227
1301
|
const origin = data == null ? void 0 : data.origin;
|
|
1228
1302
|
const update = (_a = data == null ? void 0 : data.update) != null ? _a : null;
|
|
@@ -1233,110 +1307,68 @@ var PluvServer = class {
|
|
|
1233
1307
|
if (!!this._limits.storageMaxSize && storageSize > this._limits.storageMaxSize) {
|
|
1234
1308
|
throw new Error("Storage has exceeded the size limit");
|
|
1235
1309
|
}
|
|
1236
|
-
|
|
1310
|
+
platform.persistence.setStorageState(room, encodedState).then(() => {
|
|
1237
1311
|
this._getListeners().onStorageUpdated({
|
|
1238
1312
|
context,
|
|
1239
1313
|
encodedState,
|
|
1314
|
+
platform,
|
|
1240
1315
|
room
|
|
1241
1316
|
});
|
|
1242
1317
|
});
|
|
1243
1318
|
return { $storageUpdated: { state: encodedState } };
|
|
1244
1319
|
})
|
|
1245
1320
|
});
|
|
1246
|
-
this._context = {};
|
|
1247
|
-
this._getInitialStorage = null;
|
|
1248
|
-
const {
|
|
1249
|
-
authorize: authorize2,
|
|
1250
|
-
context,
|
|
1251
|
-
crdt = noop2,
|
|
1252
|
-
debug = false,
|
|
1253
|
-
getInitialStorage,
|
|
1254
|
-
io,
|
|
1255
|
-
limits,
|
|
1256
|
-
platform,
|
|
1257
|
-
router = new PluvRouter({})
|
|
1258
|
-
} = options;
|
|
1259
|
-
const {
|
|
1260
|
-
onRoomDeleted,
|
|
1261
|
-
onRoomMessage,
|
|
1262
|
-
onStorageUpdated,
|
|
1263
|
-
onUserConnected,
|
|
1264
|
-
onUserDisconnected
|
|
1265
|
-
} = options;
|
|
1266
|
-
platform.validateConfig(options);
|
|
1267
|
-
this._crdt = crdt;
|
|
1268
|
-
this._debug = debug;
|
|
1269
|
-
this._io = io;
|
|
1270
|
-
this._limits = limits;
|
|
1271
|
-
this._platform = platform;
|
|
1272
|
-
this._router = router ? PluvRouter.merge(this._baseRouter, router) : this._baseRouter;
|
|
1273
|
-
if (authorize2) this._authorize = authorize2;
|
|
1274
|
-
if (context) this._context = context;
|
|
1275
|
-
if (getInitialStorage) this._getInitialStorage = getInitialStorage;
|
|
1276
|
-
this._listeners = {
|
|
1277
|
-
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
1278
|
-
onRoomMessage: (event) => onRoomMessage == null ? void 0 : onRoomMessage(event),
|
|
1279
|
-
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event),
|
|
1280
|
-
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
1281
|
-
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
get fetch() {
|
|
1285
|
-
return (...args) => {
|
|
1286
|
-
if (!this._platform._fetch)
|
|
1287
|
-
throw new Error(`\`${this._platform._name}\` does not support \`fetch\``);
|
|
1288
|
-
return this._platform._fetch(...args);
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* @ignore
|
|
1293
|
-
* @readonly
|
|
1294
|
-
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
1295
|
-
*/
|
|
1296
|
-
get _defs() {
|
|
1297
|
-
return {
|
|
1298
|
-
authorize: this._authorize,
|
|
1299
|
-
context: this._context,
|
|
1300
|
-
events: this._router._defs.events,
|
|
1301
|
-
platform: this._platform
|
|
1302
|
-
};
|
|
1303
1321
|
}
|
|
1304
1322
|
get _procedure() {
|
|
1305
1323
|
return new PluvProcedure();
|
|
1306
1324
|
}
|
|
1325
|
+
get _router() {
|
|
1326
|
+
return this._inputRouter ? PluvRouter.merge(this._baseRouter, this._inputRouter) : this._baseRouter;
|
|
1327
|
+
}
|
|
1307
1328
|
createRoom(room, ...options) {
|
|
1308
1329
|
var _a, _c;
|
|
1309
1330
|
const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
|
|
1310
|
-
|
|
1311
|
-
|
|
1331
|
+
const platform = this._platform();
|
|
1332
|
+
if (platform._config.handleMode !== "io") {
|
|
1333
|
+
throw new Error(`\`createRoom\` is unsupported for \`${platform._name}\``);
|
|
1312
1334
|
}
|
|
1313
1335
|
if (!/^[a-z0-9](?:[a-z0-9-_]*[a-z0-9])?$/i.test(room))
|
|
1314
1336
|
throw new Error("Unsupported room name");
|
|
1315
1337
|
const roomContext = platformRoomContext;
|
|
1316
1338
|
const context = typeof this._context === "function" ? this._context(roomContext) : this._context;
|
|
1339
|
+
const listeners = this._getListeners();
|
|
1340
|
+
const logDebug = this._logDebug.bind(this);
|
|
1317
1341
|
const newRoom = new IORoom(room, __spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), {
|
|
1318
1342
|
authorize: (_c = this._authorize) != null ? _c : void 0,
|
|
1319
1343
|
context,
|
|
1320
1344
|
crdt: this._crdt,
|
|
1321
1345
|
debug: debug != null ? debug : this._debug,
|
|
1322
|
-
onDestroy
|
|
1323
|
-
this
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1346
|
+
onDestroy(event) {
|
|
1347
|
+
return __async(this, null, function* () {
|
|
1348
|
+
logDebug(`${colors2.blue("Deleting empty room:")} ${room}`);
|
|
1349
|
+
yield Promise.resolve(onDestroy == null ? void 0 : onDestroy(event));
|
|
1350
|
+
yield Promise.resolve(listeners.onRoomDeleted(event));
|
|
1351
|
+
yield event.platform.persistence.deleteStorageState(room);
|
|
1352
|
+
logDebug(`${colors2.blue("Deleted room:")} ${room}`);
|
|
1353
|
+
});
|
|
1354
|
+
},
|
|
1355
|
+
onMessage(event) {
|
|
1356
|
+
return __async(this, null, function* () {
|
|
1357
|
+
yield Promise.resolve(onMessage == null ? void 0 : onMessage(event));
|
|
1358
|
+
yield Promise.resolve(listeners.onRoomMessage(event));
|
|
1359
|
+
});
|
|
1360
|
+
},
|
|
1361
|
+
onUserConnected(event) {
|
|
1362
|
+
return __async(this, null, function* () {
|
|
1363
|
+
yield Promise.resolve(listeners.onUserConnected(event));
|
|
1364
|
+
});
|
|
1365
|
+
},
|
|
1366
|
+
onUserDisconnected(event) {
|
|
1367
|
+
return __async(this, null, function* () {
|
|
1368
|
+
yield Promise.resolve(listeners.onUserDisconnected(event));
|
|
1369
|
+
});
|
|
1370
|
+
},
|
|
1371
|
+
platform,
|
|
1340
1372
|
roomContext,
|
|
1341
1373
|
router: this._router
|
|
1342
1374
|
}));
|
|
@@ -1397,10 +1429,11 @@ var PluvIO = class {
|
|
|
1397
1429
|
`createToken called with large payload. User must be at most 512 bytes. Current size: ${bytes.toLocaleString()}`
|
|
1398
1430
|
);
|
|
1399
1431
|
}
|
|
1400
|
-
|
|
1432
|
+
const platform = this._platform();
|
|
1433
|
+
if (platform._createToken) return yield platform._createToken(params);
|
|
1401
1434
|
const secret = (_a = ioAuthorize == null ? void 0 : ioAuthorize.secret) != null ? _a : null;
|
|
1402
1435
|
if (!secret) throw new Error("`authorize` was specified without a valid secret");
|
|
1403
|
-
return yield authorize({ platform
|
|
1436
|
+
return yield authorize({ platform, secret }).encode(
|
|
1404
1437
|
params
|
|
1405
1438
|
);
|
|
1406
1439
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"jose": "^5.10.0",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.5",
|
|
24
|
-
"@pluv/crdt": "^2.
|
|
25
|
-
"@pluv/types": "^2.
|
|
24
|
+
"@pluv/crdt": "^2.2.0",
|
|
25
|
+
"@pluv/types": "^2.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^9.26.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.4.0",
|
|
31
31
|
"typescript": "^5.8.3",
|
|
32
|
-
"@pluv/tsconfig": "^2.
|
|
33
|
-
"eslint-config-pluv": "^2.
|
|
32
|
+
"@pluv/tsconfig": "^2.2.0",
|
|
33
|
+
"eslint-config-pluv": "^2.2.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface IORoomListeners<
|
|
|
60
60
|
TContext extends Record<string, any>,
|
|
61
61
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
62
62
|
> {
|
|
63
|
-
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
63
|
+
onDestroy: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
64
64
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
65
65
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
66
66
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -87,7 +87,7 @@ export type IORoomConfig<
|
|
|
87
87
|
> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
88
88
|
authorize?: TAuthorize;
|
|
89
89
|
context: TContext;
|
|
90
|
-
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
90
|
+
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any, any> };
|
|
91
91
|
debug: boolean;
|
|
92
92
|
platform: TPlatform;
|
|
93
93
|
roomContext: InferRoomContextType<TPlatform>;
|
|
@@ -124,14 +124,14 @@ export class IORoom<
|
|
|
124
124
|
{
|
|
125
125
|
public readonly id: string;
|
|
126
126
|
|
|
127
|
-
private _doc: Promise<CrdtDocLike<any>>;
|
|
127
|
+
private _doc: Promise<CrdtDocLike<any, any>>;
|
|
128
128
|
private _lastGarbageCollectMs: number = -1 * (GARBAGE_COLLECT_INTERVAL_MS + 1);
|
|
129
129
|
private _uninitialize: Promise<() => Promise<void>> | null = null;
|
|
130
130
|
|
|
131
131
|
private readonly _authorize: TAuthorize = null as TAuthorize;
|
|
132
132
|
private readonly _context: TContext;
|
|
133
133
|
private readonly _debug: boolean;
|
|
134
|
-
private readonly _docFactory: AbstractCrdtDocFactory<any>;
|
|
134
|
+
private readonly _docFactory: AbstractCrdtDocFactory<any, any>;
|
|
135
135
|
private readonly _listeners: IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>;
|
|
136
136
|
private readonly _platform: TPlatform;
|
|
137
137
|
private readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
@@ -472,6 +472,7 @@ export class IORoom<
|
|
|
472
472
|
this._listeners.onUserDisconnected({
|
|
473
473
|
context: this._context,
|
|
474
474
|
encodedState,
|
|
475
|
+
platform: this._platform,
|
|
475
476
|
room: this.id,
|
|
476
477
|
user,
|
|
477
478
|
}),
|
|
@@ -538,6 +539,7 @@ export class IORoom<
|
|
|
538
539
|
this._listeners.onUserConnected({
|
|
539
540
|
context: this._context,
|
|
540
541
|
encodedState,
|
|
542
|
+
platform: this._platform,
|
|
541
543
|
room: this.id,
|
|
542
544
|
user,
|
|
543
545
|
webSocket: pluvWs.webSocket,
|
|
@@ -626,7 +628,7 @@ export class IORoom<
|
|
|
626
628
|
}
|
|
627
629
|
}
|
|
628
630
|
|
|
629
|
-
private async _getInitialDoc(): Promise<CrdtDocLike<any>> {
|
|
631
|
+
private async _getInitialDoc(): Promise<CrdtDocLike<any, any>> {
|
|
630
632
|
const doc = this._docFactory.getEmpty();
|
|
631
633
|
const encodedState = await this._platform.persistence.getStorageState(this.id);
|
|
632
634
|
|
|
@@ -769,6 +771,7 @@ export class IORoom<
|
|
|
769
771
|
: {}),
|
|
770
772
|
context: this._context,
|
|
771
773
|
encodedState,
|
|
774
|
+
platform: this._platform,
|
|
772
775
|
room: this.id,
|
|
773
776
|
}),
|
|
774
777
|
);
|
|
@@ -825,6 +828,7 @@ export class IORoom<
|
|
|
825
828
|
garbageCollect: async () => {
|
|
826
829
|
await this.garbageCollect();
|
|
827
830
|
},
|
|
831
|
+
platform: this._platform,
|
|
828
832
|
get presence() {
|
|
829
833
|
return session.presence as JsonObject | null;
|
|
830
834
|
},
|
|
@@ -864,6 +868,7 @@ export class IORoom<
|
|
|
864
868
|
InferEventsOutput<TEvents>,
|
|
865
869
|
keyof InferEventsOutput<TEvents>
|
|
866
870
|
>,
|
|
871
|
+
platform: this._platform,
|
|
867
872
|
room: this.id,
|
|
868
873
|
user: session.user,
|
|
869
874
|
webSocket: session.webSocket.webSocket,
|
|
@@ -1105,6 +1110,7 @@ export class IORoom<
|
|
|
1105
1110
|
garbageCollect: async () => {
|
|
1106
1111
|
await this.garbageCollect();
|
|
1107
1112
|
},
|
|
1113
|
+
platform: this._platform,
|
|
1108
1114
|
get presence() {
|
|
1109
1115
|
return null;
|
|
1110
1116
|
},
|
package/src/PluvIO.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type PluvIOConfig<
|
|
|
37
37
|
crdt?: CrdtLibraryType;
|
|
38
38
|
debug?: boolean;
|
|
39
39
|
limits?: PluvIOLimits;
|
|
40
|
-
platform: TPlatform;
|
|
40
|
+
platform: () => TPlatform;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
type ResolvedServerConfig<
|
|
@@ -90,10 +90,10 @@ export class PluvIO<
|
|
|
90
90
|
TPlatform,
|
|
91
91
|
TContext
|
|
92
92
|
>;
|
|
93
|
-
private readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
93
|
+
private readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any, any> };
|
|
94
94
|
private readonly _debug: boolean;
|
|
95
95
|
private readonly _limits: PluvIOLimits;
|
|
96
|
-
private readonly _platform: TPlatform;
|
|
96
|
+
private readonly _platform: () => TPlatform;
|
|
97
97
|
|
|
98
98
|
public get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}> {
|
|
99
99
|
return new PluvProcedure();
|
|
@@ -141,19 +141,21 @@ export class PluvIO<
|
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
const platform = this._platform();
|
|
145
|
+
|
|
144
146
|
/**
|
|
145
147
|
* !HACK
|
|
146
148
|
* @description Allow the platform to overwrite this behavior as needed. This is introduced
|
|
147
149
|
* to support platformPluv
|
|
148
150
|
* @date December 15, 2024
|
|
149
151
|
*/
|
|
150
|
-
if (
|
|
152
|
+
if (platform._createToken) return await platform._createToken(params as any);
|
|
151
153
|
|
|
152
154
|
const secret = ioAuthorize?.secret ?? null;
|
|
153
155
|
|
|
154
156
|
if (!secret) throw new Error("`authorize` was specified without a valid secret");
|
|
155
157
|
|
|
156
|
-
return await authorize({ platform
|
|
158
|
+
return await authorize({ platform, secret }).encode(
|
|
157
159
|
params as JWTEncodeParams<any, TPlatform>,
|
|
158
160
|
);
|
|
159
161
|
}
|