@pluv/client 0.29.0 → 0.30.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 +7 -7
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +24 -20
- package/dist/index.d.ts +24 -20
- package/dist/index.js +18 -10
- package/dist/index.mjs +18 -10
- package/package.json +5 -5
- package/src/PluvClient.ts +12 -8
- package/src/PluvRoom.ts +26 -20
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@0.
|
|
2
|
+
> @pluv/client@0.30.0 build /home/runner/work/pluv/pluv/packages/client
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[32mESM[39m ⚡️ Build success in 106ms
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m47.76 KB[39m
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m48.17 KB[39m
|
|
14
12
|
[32mCJS[39m ⚡️ Build success in 106ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m46.91 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 111ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m22.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m22.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3475ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m22.35 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m22.35 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -184,6 +184,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
184
184
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
185
185
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
186
186
|
onAuthorizationFail?: (error: Error) => void;
|
|
187
|
+
publicKey?: string;
|
|
187
188
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
188
189
|
} & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
|
|
189
190
|
metadata?: undefined;
|
|
@@ -192,23 +193,24 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
192
193
|
})>;
|
|
193
194
|
declare class PluvRoom<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
194
195
|
readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
|
|
195
|
-
private _crdtManager;
|
|
196
|
-
private _crdtNotifier;
|
|
197
|
-
private _debug;
|
|
198
|
-
private _eventNotifier;
|
|
199
|
-
private _intervals;
|
|
200
|
-
private _listeners;
|
|
201
|
-
private _metadata;
|
|
202
|
-
private _otherNotifier;
|
|
203
|
-
private
|
|
196
|
+
private readonly _crdtManager;
|
|
197
|
+
private readonly _crdtNotifier;
|
|
198
|
+
private readonly _debug;
|
|
199
|
+
private readonly _eventNotifier;
|
|
200
|
+
private readonly _intervals;
|
|
201
|
+
private readonly _listeners;
|
|
202
|
+
private readonly _metadata;
|
|
203
|
+
private readonly _otherNotifier;
|
|
204
|
+
private readonly _publicKey;
|
|
205
|
+
private readonly _router;
|
|
206
|
+
private readonly _stateNotifier;
|
|
207
|
+
private readonly _storageStore;
|
|
208
|
+
private readonly _subscriptions;
|
|
209
|
+
private readonly _timeouts;
|
|
210
|
+
private readonly _usersManager;
|
|
204
211
|
private _state;
|
|
205
|
-
private _stateNotifier;
|
|
206
|
-
private _storageStore;
|
|
207
|
-
private _subscriptions;
|
|
208
|
-
private _timeouts;
|
|
209
212
|
private _windowListeners;
|
|
210
213
|
private _wsListeners;
|
|
211
|
-
private _usersManager;
|
|
212
214
|
constructor(room: string, options: RoomConfig<TIO, TMetadata, TPresence, TStorage, TEvents>);
|
|
213
215
|
get storageLoaded(): boolean;
|
|
214
216
|
get webSocket(): WebSocket | null;
|
|
@@ -297,6 +299,7 @@ type PluvClientOptions<TIO extends IOLike, TPresence extends JsonObject, TStorag
|
|
|
297
299
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
298
300
|
metadata?: InputZodLike<TMetadata>;
|
|
299
301
|
presence?: InputZodLike<TPresence>;
|
|
302
|
+
publicKey?: string;
|
|
300
303
|
};
|
|
301
304
|
type CreateRoomOptions<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
302
305
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
@@ -311,12 +314,13 @@ type CreateRoomOptions<TIO extends IOLike, TPresence extends JsonObject, TStorag
|
|
|
311
314
|
metadata: TMetadata;
|
|
312
315
|
});
|
|
313
316
|
declare class PluvClient<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TMetadata extends JsonObject = {}> {
|
|
314
|
-
private _authEndpoint;
|
|
315
|
-
private _debug;
|
|
316
|
-
private _initialStorage?;
|
|
317
|
-
private _presence?;
|
|
318
|
-
private
|
|
319
|
-
private _rooms;
|
|
317
|
+
private readonly _authEndpoint;
|
|
318
|
+
private readonly _debug;
|
|
319
|
+
private readonly _initialStorage?;
|
|
320
|
+
private readonly _presence?;
|
|
321
|
+
private readonly _publicKey;
|
|
322
|
+
private readonly _rooms;
|
|
323
|
+
private readonly _wsEndpoint;
|
|
320
324
|
get _defs(): {
|
|
321
325
|
initialStorage: AbstractCrdtDocFactory<TStorage> | undefined;
|
|
322
326
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -184,6 +184,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
184
184
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
185
185
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
186
186
|
onAuthorizationFail?: (error: Error) => void;
|
|
187
|
+
publicKey?: string;
|
|
187
188
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
188
189
|
} & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
|
|
189
190
|
metadata?: undefined;
|
|
@@ -192,23 +193,24 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
|
|
|
192
193
|
})>;
|
|
193
194
|
declare class PluvRoom<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
194
195
|
readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
|
|
195
|
-
private _crdtManager;
|
|
196
|
-
private _crdtNotifier;
|
|
197
|
-
private _debug;
|
|
198
|
-
private _eventNotifier;
|
|
199
|
-
private _intervals;
|
|
200
|
-
private _listeners;
|
|
201
|
-
private _metadata;
|
|
202
|
-
private _otherNotifier;
|
|
203
|
-
private
|
|
196
|
+
private readonly _crdtManager;
|
|
197
|
+
private readonly _crdtNotifier;
|
|
198
|
+
private readonly _debug;
|
|
199
|
+
private readonly _eventNotifier;
|
|
200
|
+
private readonly _intervals;
|
|
201
|
+
private readonly _listeners;
|
|
202
|
+
private readonly _metadata;
|
|
203
|
+
private readonly _otherNotifier;
|
|
204
|
+
private readonly _publicKey;
|
|
205
|
+
private readonly _router;
|
|
206
|
+
private readonly _stateNotifier;
|
|
207
|
+
private readonly _storageStore;
|
|
208
|
+
private readonly _subscriptions;
|
|
209
|
+
private readonly _timeouts;
|
|
210
|
+
private readonly _usersManager;
|
|
204
211
|
private _state;
|
|
205
|
-
private _stateNotifier;
|
|
206
|
-
private _storageStore;
|
|
207
|
-
private _subscriptions;
|
|
208
|
-
private _timeouts;
|
|
209
212
|
private _windowListeners;
|
|
210
213
|
private _wsListeners;
|
|
211
|
-
private _usersManager;
|
|
212
214
|
constructor(room: string, options: RoomConfig<TIO, TMetadata, TPresence, TStorage, TEvents>);
|
|
213
215
|
get storageLoaded(): boolean;
|
|
214
216
|
get webSocket(): WebSocket | null;
|
|
@@ -297,6 +299,7 @@ type PluvClientOptions<TIO extends IOLike, TPresence extends JsonObject, TStorag
|
|
|
297
299
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
298
300
|
metadata?: InputZodLike<TMetadata>;
|
|
299
301
|
presence?: InputZodLike<TPresence>;
|
|
302
|
+
publicKey?: string;
|
|
300
303
|
};
|
|
301
304
|
type CreateRoomOptions<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
302
305
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
@@ -311,12 +314,13 @@ type CreateRoomOptions<TIO extends IOLike, TPresence extends JsonObject, TStorag
|
|
|
311
314
|
metadata: TMetadata;
|
|
312
315
|
});
|
|
313
316
|
declare class PluvClient<TIO extends IOLike = IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TMetadata extends JsonObject = {}> {
|
|
314
|
-
private _authEndpoint;
|
|
315
|
-
private _debug;
|
|
316
|
-
private _initialStorage?;
|
|
317
|
-
private _presence?;
|
|
318
|
-
private
|
|
319
|
-
private _rooms;
|
|
317
|
+
private readonly _authEndpoint;
|
|
318
|
+
private readonly _debug;
|
|
319
|
+
private readonly _initialStorage?;
|
|
320
|
+
private readonly _presence?;
|
|
321
|
+
private readonly _publicKey;
|
|
322
|
+
private readonly _rooms;
|
|
323
|
+
private readonly _wsEndpoint;
|
|
320
324
|
get _defs(): {
|
|
321
325
|
initialStorage: AbstractCrdtDocFactory<TStorage> | undefined;
|
|
322
326
|
};
|
package/dist/index.js
CHANGED
|
@@ -446,6 +446,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
446
446
|
metadata,
|
|
447
447
|
onAuthorizationFail,
|
|
448
448
|
presence,
|
|
449
|
+
publicKey,
|
|
449
450
|
router,
|
|
450
451
|
wsEndpoint
|
|
451
452
|
} = options;
|
|
@@ -457,6 +458,15 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
457
458
|
};
|
|
458
459
|
this._metadata = {};
|
|
459
460
|
this._otherNotifier = new OtherNotifier();
|
|
461
|
+
this._publicKey = null;
|
|
462
|
+
this._stateNotifier = new StateNotifier();
|
|
463
|
+
this._subscriptions = {
|
|
464
|
+
observeCrdt: null
|
|
465
|
+
};
|
|
466
|
+
this._timeouts = {
|
|
467
|
+
pong: null,
|
|
468
|
+
reconnect: null
|
|
469
|
+
};
|
|
460
470
|
this._state = {
|
|
461
471
|
authorization: {
|
|
462
472
|
token: null,
|
|
@@ -469,14 +479,6 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
469
479
|
},
|
|
470
480
|
webSocket: null
|
|
471
481
|
};
|
|
472
|
-
this._stateNotifier = new StateNotifier();
|
|
473
|
-
this._subscriptions = {
|
|
474
|
-
observeCrdt: null
|
|
475
|
-
};
|
|
476
|
-
this._timeouts = {
|
|
477
|
-
pong: null,
|
|
478
|
-
reconnect: null
|
|
479
|
-
};
|
|
480
482
|
this._windowListeners = null;
|
|
481
483
|
this._wsListeners = null;
|
|
482
484
|
this.broadcast = new Proxy(
|
|
@@ -612,7 +614,8 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
612
614
|
this._debug = debug;
|
|
613
615
|
this._endpoints = { authEndpoint, wsEndpoint };
|
|
614
616
|
this._storageStore = storage;
|
|
615
|
-
if (
|
|
617
|
+
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
618
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
616
619
|
this._listeners = {
|
|
617
620
|
onAuthorizationFail: (error) => {
|
|
618
621
|
this._clearTimeout(this._timeouts.reconnect);
|
|
@@ -652,6 +655,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
652
655
|
try {
|
|
653
656
|
authToken = yield this._getAuthorization(this.id);
|
|
654
657
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
658
|
+
this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
|
|
655
659
|
webSocket = new WebSocket(url.toString());
|
|
656
660
|
} catch (err) {
|
|
657
661
|
yield this._storageStore.destroy();
|
|
@@ -1180,8 +1184,10 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
1180
1184
|
// src/PluvClient.ts
|
|
1181
1185
|
var PluvClient = class {
|
|
1182
1186
|
constructor(options) {
|
|
1187
|
+
this._publicKey = null;
|
|
1183
1188
|
this._rooms = /* @__PURE__ */ new Map();
|
|
1184
1189
|
this.createRoom = (room, options) => {
|
|
1190
|
+
var _a;
|
|
1185
1191
|
const oldRoom = this.getRoom(room);
|
|
1186
1192
|
if (oldRoom) return oldRoom;
|
|
1187
1193
|
const newRoom = new PluvRoom(room, {
|
|
@@ -1193,6 +1199,7 @@ var PluvClient = class {
|
|
|
1193
1199
|
metadata: options.metadata,
|
|
1194
1200
|
onAuthorizationFail: options.onAuthorizationFail,
|
|
1195
1201
|
presence: this._presence,
|
|
1202
|
+
publicKey: (_a = this._publicKey) != null ? _a : void 0,
|
|
1196
1203
|
router: options.router,
|
|
1197
1204
|
wsEndpoint: this._wsEndpoint
|
|
1198
1205
|
});
|
|
@@ -1222,12 +1229,13 @@ var PluvClient = class {
|
|
|
1222
1229
|
this._rooms.delete(toLeave.id);
|
|
1223
1230
|
this._logDebug(`Left and deleted room: ${room}`);
|
|
1224
1231
|
});
|
|
1225
|
-
const { authEndpoint, debug = false, initialStorage, presence, wsEndpoint } = options;
|
|
1232
|
+
const { authEndpoint, debug = false, initialStorage, presence, publicKey, wsEndpoint } = options;
|
|
1226
1233
|
this._authEndpoint = authEndpoint;
|
|
1227
1234
|
this._debug = debug;
|
|
1228
1235
|
this._initialStorage = initialStorage;
|
|
1229
1236
|
this._presence = presence;
|
|
1230
1237
|
this._wsEndpoint = wsEndpoint;
|
|
1238
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
1231
1239
|
}
|
|
1232
1240
|
get _defs() {
|
|
1233
1241
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -417,6 +417,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
417
417
|
metadata,
|
|
418
418
|
onAuthorizationFail,
|
|
419
419
|
presence,
|
|
420
|
+
publicKey,
|
|
420
421
|
router,
|
|
421
422
|
wsEndpoint
|
|
422
423
|
} = options;
|
|
@@ -428,6 +429,15 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
428
429
|
};
|
|
429
430
|
this._metadata = {};
|
|
430
431
|
this._otherNotifier = new OtherNotifier();
|
|
432
|
+
this._publicKey = null;
|
|
433
|
+
this._stateNotifier = new StateNotifier();
|
|
434
|
+
this._subscriptions = {
|
|
435
|
+
observeCrdt: null
|
|
436
|
+
};
|
|
437
|
+
this._timeouts = {
|
|
438
|
+
pong: null,
|
|
439
|
+
reconnect: null
|
|
440
|
+
};
|
|
431
441
|
this._state = {
|
|
432
442
|
authorization: {
|
|
433
443
|
token: null,
|
|
@@ -440,14 +450,6 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
440
450
|
},
|
|
441
451
|
webSocket: null
|
|
442
452
|
};
|
|
443
|
-
this._stateNotifier = new StateNotifier();
|
|
444
|
-
this._subscriptions = {
|
|
445
|
-
observeCrdt: null
|
|
446
|
-
};
|
|
447
|
-
this._timeouts = {
|
|
448
|
-
pong: null,
|
|
449
|
-
reconnect: null
|
|
450
|
-
};
|
|
451
453
|
this._windowListeners = null;
|
|
452
454
|
this._wsListeners = null;
|
|
453
455
|
this.broadcast = new Proxy(
|
|
@@ -583,7 +585,8 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
583
585
|
this._debug = debug;
|
|
584
586
|
this._endpoints = { authEndpoint, wsEndpoint };
|
|
585
587
|
this._storageStore = storage;
|
|
586
|
-
if (
|
|
588
|
+
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
589
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
587
590
|
this._listeners = {
|
|
588
591
|
onAuthorizationFail: (error) => {
|
|
589
592
|
this._clearTimeout(this._timeouts.reconnect);
|
|
@@ -623,6 +626,7 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
623
626
|
try {
|
|
624
627
|
authToken = yield this._getAuthorization(this.id);
|
|
625
628
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
629
|
+
this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
|
|
626
630
|
webSocket = new WebSocket(url.toString());
|
|
627
631
|
} catch (err) {
|
|
628
632
|
yield this._storageStore.destroy();
|
|
@@ -1151,8 +1155,10 @@ var PluvRoom = class extends AbstractRoom {
|
|
|
1151
1155
|
// src/PluvClient.ts
|
|
1152
1156
|
var PluvClient = class {
|
|
1153
1157
|
constructor(options) {
|
|
1158
|
+
this._publicKey = null;
|
|
1154
1159
|
this._rooms = /* @__PURE__ */ new Map();
|
|
1155
1160
|
this.createRoom = (room, options) => {
|
|
1161
|
+
var _a;
|
|
1156
1162
|
const oldRoom = this.getRoom(room);
|
|
1157
1163
|
if (oldRoom) return oldRoom;
|
|
1158
1164
|
const newRoom = new PluvRoom(room, {
|
|
@@ -1164,6 +1170,7 @@ var PluvClient = class {
|
|
|
1164
1170
|
metadata: options.metadata,
|
|
1165
1171
|
onAuthorizationFail: options.onAuthorizationFail,
|
|
1166
1172
|
presence: this._presence,
|
|
1173
|
+
publicKey: (_a = this._publicKey) != null ? _a : void 0,
|
|
1167
1174
|
router: options.router,
|
|
1168
1175
|
wsEndpoint: this._wsEndpoint
|
|
1169
1176
|
});
|
|
@@ -1193,12 +1200,13 @@ var PluvClient = class {
|
|
|
1193
1200
|
this._rooms.delete(toLeave.id);
|
|
1194
1201
|
this._logDebug(`Left and deleted room: ${room}`);
|
|
1195
1202
|
});
|
|
1196
|
-
const { authEndpoint, debug = false, initialStorage, presence, wsEndpoint } = options;
|
|
1203
|
+
const { authEndpoint, debug = false, initialStorage, presence, publicKey, wsEndpoint } = options;
|
|
1197
1204
|
this._authEndpoint = authEndpoint;
|
|
1198
1205
|
this._debug = debug;
|
|
1199
1206
|
this._initialStorage = initialStorage;
|
|
1200
1207
|
this._presence = presence;
|
|
1201
1208
|
this._wsEndpoint = wsEndpoint;
|
|
1209
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
1202
1210
|
}
|
|
1203
1211
|
get _defs() {
|
|
1204
1212
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "@pluv/io frontend client",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"wonka": "^6.3.4",
|
|
21
|
-
"@pluv/crdt": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/crdt": "^0.30.0",
|
|
22
|
+
"@pluv/types": "^0.30.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"eslint": "^8.57.0",
|
|
26
26
|
"tsup": "^8.3.0",
|
|
27
27
|
"typescript": "^5.6.2",
|
|
28
|
-
"@pluv/tsconfig": "^0.
|
|
29
|
-
"eslint-config-pluv": "^0.
|
|
28
|
+
"@pluv/tsconfig": "^0.30.0",
|
|
29
|
+
"eslint-config-pluv": "^0.30.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/PluvClient.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type PluvClientOptions<
|
|
|
22
22
|
initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
23
23
|
metadata?: InputZodLike<TMetadata>;
|
|
24
24
|
presence?: InputZodLike<TPresence>;
|
|
25
|
+
publicKey?: string;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export type CreateRoomOptions<
|
|
@@ -45,13 +46,13 @@ export class PluvClient<
|
|
|
45
46
|
TStorage extends Record<string, CrdtType<any, any>> = {},
|
|
46
47
|
TMetadata extends JsonObject = {},
|
|
47
48
|
> {
|
|
48
|
-
private _authEndpoint: AuthEndpoint<TMetadata> | undefined;
|
|
49
|
-
private _debug: boolean;
|
|
50
|
-
private _initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
51
|
-
private _presence?: InputZodLike<TPresence>;
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
private
|
|
49
|
+
private readonly _authEndpoint: AuthEndpoint<TMetadata> | undefined;
|
|
50
|
+
private readonly _debug: boolean;
|
|
51
|
+
private readonly _initialStorage?: AbstractCrdtDocFactory<TStorage>;
|
|
52
|
+
private readonly _presence?: InputZodLike<TPresence>;
|
|
53
|
+
private readonly _publicKey: string | null = null;
|
|
54
|
+
private readonly _rooms = new Map<string, PluvRoom<TIO, TMetadata, TPresence, TStorage, any>>();
|
|
55
|
+
private readonly _wsEndpoint: WsEndpoint<TMetadata> | undefined;
|
|
55
56
|
|
|
56
57
|
public get _defs() {
|
|
57
58
|
return {
|
|
@@ -64,13 +65,15 @@ export class PluvClient<
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
constructor(options: PluvClientOptions<TIO, TPresence, TStorage, TMetadata>) {
|
|
67
|
-
const { authEndpoint, debug = false, initialStorage, presence, wsEndpoint } = options;
|
|
68
|
+
const { authEndpoint, debug = false, initialStorage, presence, publicKey, wsEndpoint } = options;
|
|
68
69
|
|
|
69
70
|
this._authEndpoint = authEndpoint as AuthEndpoint<TMetadata>;
|
|
70
71
|
this._debug = debug;
|
|
71
72
|
this._initialStorage = initialStorage;
|
|
72
73
|
this._presence = presence;
|
|
73
74
|
this._wsEndpoint = wsEndpoint;
|
|
75
|
+
|
|
76
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
public createRoom = <TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}>(
|
|
@@ -90,6 +93,7 @@ export class PluvClient<
|
|
|
90
93
|
metadata: options.metadata,
|
|
91
94
|
onAuthorizationFail: options.onAuthorizationFail,
|
|
92
95
|
presence: this._presence,
|
|
96
|
+
publicKey: this._publicKey ?? undefined,
|
|
93
97
|
router: options.router,
|
|
94
98
|
wsEndpoint: this._wsEndpoint,
|
|
95
99
|
} as RoomConfig<TIO, TMetadata, TPresence, TStorage, TEvents>);
|
package/src/PluvRoom.ts
CHANGED
|
@@ -147,6 +147,7 @@ export type RoomConfig<
|
|
|
147
147
|
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
148
148
|
debug?: boolean | PluvRoomDebug<TIO>;
|
|
149
149
|
onAuthorizationFail?: (error: Error) => void;
|
|
150
|
+
publicKey?: string;
|
|
150
151
|
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
151
152
|
} & RoomEndpoints<TIO, TMetadata> &
|
|
152
153
|
Pick<CrdtManagerOptions<TStorage>, "initialStorage"> &
|
|
@@ -163,17 +164,29 @@ export class PluvRoom<
|
|
|
163
164
|
> extends AbstractRoom<TIO, TPresence, TStorage> {
|
|
164
165
|
readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
|
|
165
166
|
|
|
166
|
-
private _crdtManager: CrdtManager<TStorage>;
|
|
167
|
-
private _crdtNotifier = new CrdtNotifier<TStorage>();
|
|
168
|
-
private _debug: boolean | PluvRoomDebug<TIO>;
|
|
169
|
-
private _eventNotifier = new EventNotifier<MergeEvents<TEvents, TIO>>();
|
|
170
|
-
private _intervals: IntervalIds = {
|
|
167
|
+
private readonly _crdtManager: CrdtManager<TStorage>;
|
|
168
|
+
private readonly _crdtNotifier = new CrdtNotifier<TStorage>();
|
|
169
|
+
private readonly _debug: boolean | PluvRoomDebug<TIO>;
|
|
170
|
+
private readonly _eventNotifier = new EventNotifier<MergeEvents<TEvents, TIO>>();
|
|
171
|
+
private readonly _intervals: IntervalIds = {
|
|
171
172
|
heartbeat: null,
|
|
172
173
|
};
|
|
173
|
-
private _listeners: InternalListeners;
|
|
174
|
-
private _metadata: TMetadata = {} as TMetadata;
|
|
175
|
-
private _otherNotifier = new OtherNotifier<TIO>();
|
|
176
|
-
private
|
|
174
|
+
private readonly _listeners: InternalListeners;
|
|
175
|
+
private readonly _metadata: TMetadata = {} as TMetadata;
|
|
176
|
+
private readonly _otherNotifier = new OtherNotifier<TIO>();
|
|
177
|
+
private readonly _publicKey: string | null = null;
|
|
178
|
+
private readonly _router: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
179
|
+
private readonly _stateNotifier = new StateNotifier<TIO, TPresence>();
|
|
180
|
+
private readonly _storageStore: AbstractStorageStore;
|
|
181
|
+
private readonly _subscriptions: InternalSubscriptions = {
|
|
182
|
+
observeCrdt: null,
|
|
183
|
+
};
|
|
184
|
+
private readonly _timeouts: TimeoutIds = {
|
|
185
|
+
pong: null,
|
|
186
|
+
reconnect: null,
|
|
187
|
+
};
|
|
188
|
+
private readonly _usersManager: UsersManager<TIO, TPresence>;
|
|
189
|
+
|
|
177
190
|
private _state: WebSocketState<TIO> = {
|
|
178
191
|
authorization: {
|
|
179
192
|
token: null,
|
|
@@ -186,18 +199,8 @@ export class PluvRoom<
|
|
|
186
199
|
},
|
|
187
200
|
webSocket: null,
|
|
188
201
|
};
|
|
189
|
-
private _stateNotifier = new StateNotifier<TIO, TPresence>();
|
|
190
|
-
private _storageStore: AbstractStorageStore;
|
|
191
|
-
private _subscriptions: InternalSubscriptions = {
|
|
192
|
-
observeCrdt: null,
|
|
193
|
-
};
|
|
194
|
-
private _timeouts: TimeoutIds = {
|
|
195
|
-
pong: null,
|
|
196
|
-
reconnect: null,
|
|
197
|
-
};
|
|
198
202
|
private _windowListeners: WindowListeners | null = null;
|
|
199
203
|
private _wsListeners: WebSocketListeners | null = null;
|
|
200
|
-
private _usersManager: UsersManager<TIO, TPresence>;
|
|
201
204
|
|
|
202
205
|
constructor(room: string, options: RoomConfig<TIO, TMetadata, TPresence, TStorage, TEvents>) {
|
|
203
206
|
const {
|
|
@@ -209,6 +212,7 @@ export class PluvRoom<
|
|
|
209
212
|
metadata,
|
|
210
213
|
onAuthorizationFail,
|
|
211
214
|
presence,
|
|
215
|
+
publicKey,
|
|
212
216
|
router,
|
|
213
217
|
wsEndpoint,
|
|
214
218
|
} = options;
|
|
@@ -226,7 +230,8 @@ export class PluvRoom<
|
|
|
226
230
|
this._endpoints = { authEndpoint, wsEndpoint } as RoomEndpoints<TIO, TMetadata>;
|
|
227
231
|
this._storageStore = storage;
|
|
228
232
|
|
|
229
|
-
if (
|
|
233
|
+
if (typeof metadata !== "undefined") this._metadata = metadata;
|
|
234
|
+
if (typeof publicKey === "string") this._publicKey = publicKey;
|
|
230
235
|
|
|
231
236
|
this._listeners = {
|
|
232
237
|
onAuthorizationFail: (error) => {
|
|
@@ -348,6 +353,7 @@ export class PluvRoom<
|
|
|
348
353
|
authToken = await this._getAuthorization(this.id);
|
|
349
354
|
|
|
350
355
|
authToken && url.searchParams.set("token", encodeURIComponent(authToken));
|
|
356
|
+
this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
|
|
351
357
|
|
|
352
358
|
webSocket = new WebSocket(url.toString());
|
|
353
359
|
} catch (err) {
|