@pluv/io 0.32.5 → 0.32.6
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 +10 -10
- package/CHANGELOG.md +27 -0
- package/dist/index.d.mts +23 -11
- package/dist/index.d.ts +23 -11
- package/dist/index.js +63 -8
- package/dist/index.mjs +63 -8
- package/package.json +6 -6
- package/src/IORoom.ts +58 -7
- package/src/PluvIO.ts +1 -1
- package/src/PluvServer.ts +12 -2
- package/src/index.ts +2 -0
- package/src/types.ts +27 -16
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.32.
|
|
2
|
+
> @pluv/io@0.32.6 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> pnpm run version && tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @pluv/io@0.32.
|
|
6
|
+
> @pluv/io@0.32.6 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts
|
|
10
10
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
11
|
-
[34mCLI[39m tsup v8.3.
|
|
11
|
+
[34mCLI[39m tsup v8.3.5
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m42.67 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 62ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m44.85 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 71ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2294ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m27.20 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m27.20 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.32.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c0956e7: Add `onUserConnected` and `onUserDisconnected` events on `PluvServer`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createIO } from "@pluv/io";
|
|
11
|
+
|
|
12
|
+
const io = createIO({
|
|
13
|
+
/* ... */
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const ioServer = io.server({
|
|
17
|
+
// ...
|
|
18
|
+
onUserConnected: (event) => {
|
|
19
|
+
// ...
|
|
20
|
+
},
|
|
21
|
+
onUserDisconnected: (event) => {
|
|
22
|
+
// ...
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- @pluv/crdt@0.32.6
|
|
28
|
+
- @pluv/types@0.32.6
|
|
29
|
+
|
|
3
30
|
## 0.32.5
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -175,29 +175,38 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
175
175
|
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
176
176
|
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
177
177
|
}> : Id<TRoot>;
|
|
178
|
-
type GetInitialStorageEvent
|
|
178
|
+
type GetInitialStorageEvent = {
|
|
179
179
|
room: string;
|
|
180
180
|
};
|
|
181
|
-
type GetInitialStorageFn
|
|
181
|
+
type GetInitialStorageFn = (event: GetInitialStorageEvent) => MaybePromise<Maybe<string>>;
|
|
182
182
|
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
183
|
-
onRoomDeleted: (event: IORoomListenerEvent<
|
|
183
|
+
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
184
184
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
185
|
-
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext
|
|
185
|
+
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
186
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
187
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
186
188
|
}
|
|
187
|
-
type IORoomListenerEvent<
|
|
189
|
+
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
188
190
|
context: TContext;
|
|
189
191
|
encodedState: string | null;
|
|
190
192
|
room: string;
|
|
191
193
|
};
|
|
192
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<
|
|
194
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TContext> & {
|
|
193
195
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
194
196
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
195
197
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
196
198
|
};
|
|
197
|
-
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any
|
|
199
|
+
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
198
200
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
199
201
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
200
202
|
};
|
|
203
|
+
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
204
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
205
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
206
|
+
};
|
|
207
|
+
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
208
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
209
|
+
};
|
|
201
210
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
202
211
|
|
|
203
212
|
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
|
|
@@ -267,8 +276,10 @@ declare const authorize: (params: AuthorizeParams) => {
|
|
|
267
276
|
};
|
|
268
277
|
|
|
269
278
|
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
270
|
-
onDestroy: (event: IORoomListenerEvent<
|
|
279
|
+
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
271
280
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
281
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
282
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
272
283
|
}
|
|
273
284
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
274
285
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
@@ -334,6 +345,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
334
345
|
private _emitQuitters;
|
|
335
346
|
private _emitRegistered;
|
|
336
347
|
private _ensureDetached;
|
|
348
|
+
private _exitWebsocket;
|
|
337
349
|
private _getAbstractWs;
|
|
338
350
|
private _getAuthorizedUser;
|
|
339
351
|
private _getInitialDoc;
|
|
@@ -361,7 +373,7 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
361
373
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
362
374
|
};
|
|
363
375
|
debug?: boolean;
|
|
364
|
-
getInitialStorage?: GetInitialStorageFn
|
|
376
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
365
377
|
platform: TPlatform;
|
|
366
378
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
367
379
|
};
|
|
@@ -406,7 +418,7 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IO
|
|
|
406
418
|
platform: TPlatform;
|
|
407
419
|
};
|
|
408
420
|
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
409
|
-
getInitialStorage?: GetInitialStorageFn
|
|
421
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
410
422
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
411
423
|
};
|
|
412
424
|
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
@@ -433,4 +445,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
433
445
|
};
|
|
434
446
|
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
|
|
435
447
|
|
|
436
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
448
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
package/dist/index.d.ts
CHANGED
|
@@ -175,29 +175,38 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
175
175
|
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
176
176
|
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
177
177
|
}> : Id<TRoot>;
|
|
178
|
-
type GetInitialStorageEvent
|
|
178
|
+
type GetInitialStorageEvent = {
|
|
179
179
|
room: string;
|
|
180
180
|
};
|
|
181
|
-
type GetInitialStorageFn
|
|
181
|
+
type GetInitialStorageFn = (event: GetInitialStorageEvent) => MaybePromise<Maybe<string>>;
|
|
182
182
|
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
183
|
-
onRoomDeleted: (event: IORoomListenerEvent<
|
|
183
|
+
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
184
184
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
185
|
-
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext
|
|
185
|
+
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
186
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
187
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
186
188
|
}
|
|
187
|
-
type IORoomListenerEvent<
|
|
189
|
+
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
188
190
|
context: TContext;
|
|
189
191
|
encodedState: string | null;
|
|
190
192
|
room: string;
|
|
191
193
|
};
|
|
192
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<
|
|
194
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TContext> & {
|
|
193
195
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
194
196
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
195
197
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
196
198
|
};
|
|
197
|
-
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any
|
|
199
|
+
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
198
200
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
199
201
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
200
202
|
};
|
|
203
|
+
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
204
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
205
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
206
|
+
};
|
|
207
|
+
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
208
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
209
|
+
};
|
|
201
210
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
202
211
|
|
|
203
212
|
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
|
|
@@ -267,8 +276,10 @@ declare const authorize: (params: AuthorizeParams) => {
|
|
|
267
276
|
};
|
|
268
277
|
|
|
269
278
|
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
270
|
-
onDestroy: (event: IORoomListenerEvent<
|
|
279
|
+
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
271
280
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
281
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
282
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
272
283
|
}
|
|
273
284
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
274
285
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
@@ -334,6 +345,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
334
345
|
private _emitQuitters;
|
|
335
346
|
private _emitRegistered;
|
|
336
347
|
private _ensureDetached;
|
|
348
|
+
private _exitWebsocket;
|
|
337
349
|
private _getAbstractWs;
|
|
338
350
|
private _getAuthorizedUser;
|
|
339
351
|
private _getInitialDoc;
|
|
@@ -361,7 +373,7 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
361
373
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
362
374
|
};
|
|
363
375
|
debug?: boolean;
|
|
364
|
-
getInitialStorage?: GetInitialStorageFn
|
|
376
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
365
377
|
platform: TPlatform;
|
|
366
378
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
367
379
|
};
|
|
@@ -406,7 +418,7 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IO
|
|
|
406
418
|
platform: TPlatform;
|
|
407
419
|
};
|
|
408
420
|
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
409
|
-
getInitialStorage?: GetInitialStorageFn
|
|
421
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
410
422
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
411
423
|
};
|
|
412
424
|
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
@@ -433,4 +445,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
433
445
|
};
|
|
434
446
|
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
|
|
435
447
|
|
|
436
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
448
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
package/dist/index.js
CHANGED
|
@@ -406,6 +406,8 @@ var IORoom = class {
|
|
|
406
406
|
debug,
|
|
407
407
|
onDestroy,
|
|
408
408
|
onMessage,
|
|
409
|
+
onUserConnected,
|
|
410
|
+
onUserDisconnected,
|
|
409
411
|
platform,
|
|
410
412
|
roomContext,
|
|
411
413
|
router
|
|
@@ -418,7 +420,9 @@ var IORoom = class {
|
|
|
418
420
|
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
|
|
419
421
|
this._listeners = {
|
|
420
422
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
|
|
421
|
-
onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
|
|
423
|
+
onMessage: (event) => onMessage == null ? void 0 : onMessage(event),
|
|
424
|
+
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
425
|
+
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
422
426
|
};
|
|
423
427
|
if (authorize2) this._authorize = authorize2;
|
|
424
428
|
const webSockets = this._platform.getWebSockets();
|
|
@@ -603,12 +607,51 @@ var IORoom = class {
|
|
|
603
607
|
const sessionId = session.id;
|
|
604
608
|
const user = session.user;
|
|
605
609
|
yield this._sendSelfMessage({ type: "$REGISTERED", data: { sessionId } }, { sessionId, user });
|
|
610
|
+
try {
|
|
611
|
+
const doc = yield this._doc;
|
|
612
|
+
const encodedState = doc.getEncodedState();
|
|
613
|
+
yield Promise.resolve(
|
|
614
|
+
this._listeners.onUserConnected({
|
|
615
|
+
context: this._context,
|
|
616
|
+
encodedState,
|
|
617
|
+
room: this.id,
|
|
618
|
+
user,
|
|
619
|
+
webSocket: pluvWs.webSocket
|
|
620
|
+
})
|
|
621
|
+
);
|
|
622
|
+
} catch (e) {
|
|
623
|
+
}
|
|
606
624
|
});
|
|
607
625
|
}
|
|
608
626
|
_ensureDetached() {
|
|
609
627
|
if (this._platform._registrationMode === "detached") return;
|
|
610
628
|
throw new Error("Platform must use detached mode");
|
|
611
629
|
}
|
|
630
|
+
_exitWebsocket(webSocket) {
|
|
631
|
+
return __async(this, null, function* () {
|
|
632
|
+
const session = yield webSocket.getSession();
|
|
633
|
+
yield this._broadcast({
|
|
634
|
+
message: {
|
|
635
|
+
type: "$EXIT",
|
|
636
|
+
data: { sessionId: session.id }
|
|
637
|
+
},
|
|
638
|
+
senderId: session.id
|
|
639
|
+
});
|
|
640
|
+
try {
|
|
641
|
+
const doc = yield this._doc;
|
|
642
|
+
const encodedState = doc.getEncodedState();
|
|
643
|
+
yield Promise.resolve(
|
|
644
|
+
this._listeners.onUserDisconnected({
|
|
645
|
+
context: this._context,
|
|
646
|
+
encodedState,
|
|
647
|
+
room: this.id,
|
|
648
|
+
user: session.user
|
|
649
|
+
})
|
|
650
|
+
);
|
|
651
|
+
} catch (e) {
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
}
|
|
612
655
|
_getAbstractWs(webSocket) {
|
|
613
656
|
var _a, _b;
|
|
614
657
|
if (webSocket instanceof AbstractWebSocket) return webSocket;
|
|
@@ -727,11 +770,13 @@ var IORoom = class {
|
|
|
727
770
|
const encodedState = doc2.getEncodedState();
|
|
728
771
|
doc2.destroy();
|
|
729
772
|
this._doc = Promise.resolve(this._docFactory.getEmpty());
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
773
|
+
yield Promise.resolve(
|
|
774
|
+
this._listeners.onDestroy(__spreadProps(__spreadValues({}, "_meta" in this._platform && !!this._platform._meta ? { _meta: this._platform._meta } : {}), {
|
|
775
|
+
context: this._context,
|
|
776
|
+
encodedState,
|
|
777
|
+
room: this.id
|
|
778
|
+
}))
|
|
779
|
+
);
|
|
735
780
|
this._uninitialize = null;
|
|
736
781
|
});
|
|
737
782
|
return { doc, uninitialize };
|
|
@@ -957,7 +1002,7 @@ var IORoom = class {
|
|
|
957
1002
|
};
|
|
958
1003
|
|
|
959
1004
|
// src/version.generated.ts
|
|
960
|
-
var version = "0.32.
|
|
1005
|
+
var version = "0.32.6";
|
|
961
1006
|
|
|
962
1007
|
// src/PluvServer.ts
|
|
963
1008
|
var PluvServer = class {
|
|
@@ -1064,6 +1109,8 @@ var PluvServer = class {
|
|
|
1064
1109
|
onRoomDeleted,
|
|
1065
1110
|
onRoomMessage,
|
|
1066
1111
|
onStorageUpdated,
|
|
1112
|
+
onUserConnected,
|
|
1113
|
+
onUserDisconnected,
|
|
1067
1114
|
platform,
|
|
1068
1115
|
router = new PluvRouter({})
|
|
1069
1116
|
} = options;
|
|
@@ -1077,7 +1124,9 @@ var PluvServer = class {
|
|
|
1077
1124
|
this._listeners = {
|
|
1078
1125
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
1079
1126
|
onRoomMessage: (event) => onRoomMessage == null ? void 0 : onRoomMessage(event),
|
|
1080
|
-
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
1127
|
+
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event),
|
|
1128
|
+
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
1129
|
+
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
1081
1130
|
};
|
|
1082
1131
|
}
|
|
1083
1132
|
/**
|
|
@@ -1118,6 +1167,12 @@ var PluvServer = class {
|
|
|
1118
1167
|
yield Promise.resolve(onMessage == null ? void 0 : onMessage(event));
|
|
1119
1168
|
yield Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
1120
1169
|
}),
|
|
1170
|
+
onUserConnected: (event) => __async(this, null, function* () {
|
|
1171
|
+
yield Promise.resolve(this._getListeners().onUserConnected(event));
|
|
1172
|
+
}),
|
|
1173
|
+
onUserDisconnected: (event) => __async(this, null, function* () {
|
|
1174
|
+
yield Promise.resolve(this._getListeners().onUserDisconnected(event));
|
|
1175
|
+
}),
|
|
1121
1176
|
platform: this._platform,
|
|
1122
1177
|
roomContext,
|
|
1123
1178
|
router: this._router
|
package/dist/index.mjs
CHANGED
|
@@ -364,6 +364,8 @@ var IORoom = class {
|
|
|
364
364
|
debug,
|
|
365
365
|
onDestroy,
|
|
366
366
|
onMessage,
|
|
367
|
+
onUserConnected,
|
|
368
|
+
onUserDisconnected,
|
|
367
369
|
platform,
|
|
368
370
|
roomContext,
|
|
369
371
|
router
|
|
@@ -376,7 +378,9 @@ var IORoom = class {
|
|
|
376
378
|
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
|
|
377
379
|
this._listeners = {
|
|
378
380
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
|
|
379
|
-
onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
|
|
381
|
+
onMessage: (event) => onMessage == null ? void 0 : onMessage(event),
|
|
382
|
+
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
383
|
+
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
380
384
|
};
|
|
381
385
|
if (authorize2) this._authorize = authorize2;
|
|
382
386
|
const webSockets = this._platform.getWebSockets();
|
|
@@ -561,12 +565,51 @@ var IORoom = class {
|
|
|
561
565
|
const sessionId = session.id;
|
|
562
566
|
const user = session.user;
|
|
563
567
|
yield this._sendSelfMessage({ type: "$REGISTERED", data: { sessionId } }, { sessionId, user });
|
|
568
|
+
try {
|
|
569
|
+
const doc = yield this._doc;
|
|
570
|
+
const encodedState = doc.getEncodedState();
|
|
571
|
+
yield Promise.resolve(
|
|
572
|
+
this._listeners.onUserConnected({
|
|
573
|
+
context: this._context,
|
|
574
|
+
encodedState,
|
|
575
|
+
room: this.id,
|
|
576
|
+
user,
|
|
577
|
+
webSocket: pluvWs.webSocket
|
|
578
|
+
})
|
|
579
|
+
);
|
|
580
|
+
} catch (e) {
|
|
581
|
+
}
|
|
564
582
|
});
|
|
565
583
|
}
|
|
566
584
|
_ensureDetached() {
|
|
567
585
|
if (this._platform._registrationMode === "detached") return;
|
|
568
586
|
throw new Error("Platform must use detached mode");
|
|
569
587
|
}
|
|
588
|
+
_exitWebsocket(webSocket) {
|
|
589
|
+
return __async(this, null, function* () {
|
|
590
|
+
const session = yield webSocket.getSession();
|
|
591
|
+
yield this._broadcast({
|
|
592
|
+
message: {
|
|
593
|
+
type: "$EXIT",
|
|
594
|
+
data: { sessionId: session.id }
|
|
595
|
+
},
|
|
596
|
+
senderId: session.id
|
|
597
|
+
});
|
|
598
|
+
try {
|
|
599
|
+
const doc = yield this._doc;
|
|
600
|
+
const encodedState = doc.getEncodedState();
|
|
601
|
+
yield Promise.resolve(
|
|
602
|
+
this._listeners.onUserDisconnected({
|
|
603
|
+
context: this._context,
|
|
604
|
+
encodedState,
|
|
605
|
+
room: this.id,
|
|
606
|
+
user: session.user
|
|
607
|
+
})
|
|
608
|
+
);
|
|
609
|
+
} catch (e) {
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
570
613
|
_getAbstractWs(webSocket) {
|
|
571
614
|
var _a, _b;
|
|
572
615
|
if (webSocket instanceof AbstractWebSocket) return webSocket;
|
|
@@ -685,11 +728,13 @@ var IORoom = class {
|
|
|
685
728
|
const encodedState = doc2.getEncodedState();
|
|
686
729
|
doc2.destroy();
|
|
687
730
|
this._doc = Promise.resolve(this._docFactory.getEmpty());
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
731
|
+
yield Promise.resolve(
|
|
732
|
+
this._listeners.onDestroy(__spreadProps(__spreadValues({}, "_meta" in this._platform && !!this._platform._meta ? { _meta: this._platform._meta } : {}), {
|
|
733
|
+
context: this._context,
|
|
734
|
+
encodedState,
|
|
735
|
+
room: this.id
|
|
736
|
+
}))
|
|
737
|
+
);
|
|
693
738
|
this._uninitialize = null;
|
|
694
739
|
});
|
|
695
740
|
return { doc, uninitialize };
|
|
@@ -915,7 +960,7 @@ var IORoom = class {
|
|
|
915
960
|
};
|
|
916
961
|
|
|
917
962
|
// src/version.generated.ts
|
|
918
|
-
var version = "0.32.
|
|
963
|
+
var version = "0.32.6";
|
|
919
964
|
|
|
920
965
|
// src/PluvServer.ts
|
|
921
966
|
var PluvServer = class {
|
|
@@ -1022,6 +1067,8 @@ var PluvServer = class {
|
|
|
1022
1067
|
onRoomDeleted,
|
|
1023
1068
|
onRoomMessage,
|
|
1024
1069
|
onStorageUpdated,
|
|
1070
|
+
onUserConnected,
|
|
1071
|
+
onUserDisconnected,
|
|
1025
1072
|
platform,
|
|
1026
1073
|
router = new PluvRouter({})
|
|
1027
1074
|
} = options;
|
|
@@ -1035,7 +1082,9 @@ var PluvServer = class {
|
|
|
1035
1082
|
this._listeners = {
|
|
1036
1083
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
1037
1084
|
onRoomMessage: (event) => onRoomMessage == null ? void 0 : onRoomMessage(event),
|
|
1038
|
-
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
1085
|
+
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event),
|
|
1086
|
+
onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
|
|
1087
|
+
onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
|
|
1039
1088
|
};
|
|
1040
1089
|
}
|
|
1041
1090
|
/**
|
|
@@ -1076,6 +1125,12 @@ var PluvServer = class {
|
|
|
1076
1125
|
yield Promise.resolve(onMessage == null ? void 0 : onMessage(event));
|
|
1077
1126
|
yield Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
1078
1127
|
}),
|
|
1128
|
+
onUserConnected: (event) => __async(this, null, function* () {
|
|
1129
|
+
yield Promise.resolve(this._getListeners().onUserConnected(event));
|
|
1130
|
+
}),
|
|
1131
|
+
onUserDisconnected: (event) => __async(this, null, function* () {
|
|
1132
|
+
yield Promise.resolve(this._getListeners().onUserDisconnected(event));
|
|
1133
|
+
}),
|
|
1079
1134
|
platform: this._platform,
|
|
1080
1135
|
roomContext,
|
|
1081
1136
|
router: this._router
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.6",
|
|
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.9.6",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.4",
|
|
24
|
-
"@pluv/crdt": "^0.32.
|
|
25
|
-
"@pluv/types": "^0.32.
|
|
24
|
+
"@pluv/crdt": "^0.32.6",
|
|
25
|
+
"@pluv/types": "^0.32.6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
|
-
"tsup": "^8.3.
|
|
30
|
+
"tsup": "^8.3.5",
|
|
31
31
|
"typescript": "^5.6.3",
|
|
32
|
-
"@pluv/tsconfig": "^0.32.
|
|
33
|
-
"eslint-config-pluv": "^0.32.
|
|
32
|
+
"@pluv/tsconfig": "^0.32.6",
|
|
33
|
+
"eslint-config-pluv": "^0.32.6"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -32,6 +32,8 @@ import type {
|
|
|
32
32
|
EventResolverContext,
|
|
33
33
|
IORoomListenerEvent,
|
|
34
34
|
IORoomMessageEvent,
|
|
35
|
+
IOUserConnectedEvent,
|
|
36
|
+
IOUserDisconnectedEvent,
|
|
35
37
|
WebSocketSession,
|
|
36
38
|
WebSocketType,
|
|
37
39
|
} from "./types";
|
|
@@ -51,8 +53,10 @@ export interface IORoomListeners<
|
|
|
51
53
|
TContext extends Record<string, any>,
|
|
52
54
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
53
55
|
> {
|
|
54
|
-
onDestroy: (event: IORoomListenerEvent<
|
|
56
|
+
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
55
57
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
58
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
59
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
export type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(
|
|
@@ -151,6 +155,8 @@ export class IORoom<
|
|
|
151
155
|
debug,
|
|
152
156
|
onDestroy,
|
|
153
157
|
onMessage,
|
|
158
|
+
onUserConnected,
|
|
159
|
+
onUserDisconnected,
|
|
154
160
|
platform,
|
|
155
161
|
roomContext,
|
|
156
162
|
router,
|
|
@@ -167,6 +173,8 @@ export class IORoom<
|
|
|
167
173
|
this._listeners = {
|
|
168
174
|
onDestroy: (event) => onDestroy?.(event),
|
|
169
175
|
onMessage: (event) => onMessage?.(event),
|
|
176
|
+
onUserConnected: (event) => onUserConnected?.(event),
|
|
177
|
+
onUserDisconnected: (event) => onUserDisconnected?.(event),
|
|
170
178
|
};
|
|
171
179
|
|
|
172
180
|
if (authorize) this._authorize = authorize;
|
|
@@ -374,6 +382,21 @@ export class IORoom<
|
|
|
374
382
|
const user = session.user;
|
|
375
383
|
|
|
376
384
|
await this._sendSelfMessage({ type: "$REGISTERED", data: { sessionId } }, { sessionId, user });
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
const doc = await this._doc;
|
|
388
|
+
const encodedState = doc.getEncodedState();
|
|
389
|
+
|
|
390
|
+
await Promise.resolve(
|
|
391
|
+
this._listeners.onUserConnected({
|
|
392
|
+
context: this._context,
|
|
393
|
+
encodedState,
|
|
394
|
+
room: this.id,
|
|
395
|
+
user,
|
|
396
|
+
webSocket: pluvWs.webSocket,
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
} catch {}
|
|
377
400
|
}
|
|
378
401
|
|
|
379
402
|
private _ensureDetached(): void {
|
|
@@ -382,6 +405,32 @@ export class IORoom<
|
|
|
382
405
|
throw new Error("Platform must use detached mode");
|
|
383
406
|
}
|
|
384
407
|
|
|
408
|
+
private async _exitWebsocket(webSocket: AbstractWebSocket<any>): Promise<void> {
|
|
409
|
+
const session = await webSocket.getSession();
|
|
410
|
+
|
|
411
|
+
await this._broadcast({
|
|
412
|
+
message: {
|
|
413
|
+
type: "$EXIT",
|
|
414
|
+
data: { sessionId: session.id },
|
|
415
|
+
},
|
|
416
|
+
senderId: session.id,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
try {
|
|
420
|
+
const doc = await this._doc;
|
|
421
|
+
const encodedState = doc.getEncodedState();
|
|
422
|
+
|
|
423
|
+
await Promise.resolve(
|
|
424
|
+
this._listeners.onUserDisconnected({
|
|
425
|
+
context: this._context,
|
|
426
|
+
encodedState,
|
|
427
|
+
room: this.id,
|
|
428
|
+
user: session.user,
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
} catch {}
|
|
432
|
+
}
|
|
433
|
+
|
|
385
434
|
private _getAbstractWs(webSocket: WebSocketType<TPlatform>): AbstractWebSocket | null {
|
|
386
435
|
if ((webSocket as unknown as any) instanceof AbstractWebSocket) return webSocket;
|
|
387
436
|
|
|
@@ -535,12 +584,14 @@ export class IORoom<
|
|
|
535
584
|
doc.destroy();
|
|
536
585
|
this._doc = Promise.resolve(this._docFactory.getEmpty());
|
|
537
586
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
587
|
+
await Promise.resolve(
|
|
588
|
+
this._listeners.onDestroy({
|
|
589
|
+
...("_meta" in this._platform && !!this._platform._meta ? { _meta: this._platform._meta } : {}),
|
|
590
|
+
context: this._context,
|
|
591
|
+
encodedState,
|
|
592
|
+
room: this.id,
|
|
593
|
+
}),
|
|
594
|
+
);
|
|
544
595
|
|
|
545
596
|
this._uninitialize = null;
|
|
546
597
|
};
|
package/src/PluvIO.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type ServerConfig<
|
|
|
29
29
|
TContext extends Record<string, any> = {},
|
|
30
30
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
31
31
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
32
|
-
getInitialStorage?: GetInitialStorageFn
|
|
32
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
33
33
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
34
34
|
};
|
|
35
35
|
|
package/src/PluvServer.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type PluvServerConfig<
|
|
|
38
38
|
context?: PluvContext<TPlatform, TContext>;
|
|
39
39
|
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
40
40
|
debug?: boolean;
|
|
41
|
-
getInitialStorage?: GetInitialStorageFn
|
|
41
|
+
getInitialStorage?: GetInitialStorageFn;
|
|
42
42
|
platform: TPlatform;
|
|
43
43
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
44
44
|
};
|
|
@@ -197,7 +197,7 @@ export class PluvServer<
|
|
|
197
197
|
private readonly _context: PluvContext<TPlatform, TContext> = {} as PluvContext<TPlatform, TContext>;
|
|
198
198
|
private readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
199
199
|
private readonly _debug: boolean;
|
|
200
|
-
private readonly _getInitialStorage: GetInitialStorageFn
|
|
200
|
+
private readonly _getInitialStorage: GetInitialStorageFn | null = null;
|
|
201
201
|
private readonly _platform: TPlatform;
|
|
202
202
|
private readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
203
203
|
|
|
@@ -229,6 +229,8 @@ export class PluvServer<
|
|
|
229
229
|
onRoomDeleted,
|
|
230
230
|
onRoomMessage,
|
|
231
231
|
onStorageUpdated,
|
|
232
|
+
onUserConnected,
|
|
233
|
+
onUserDisconnected,
|
|
232
234
|
platform,
|
|
233
235
|
router = new PluvRouter<TPlatform, TAuthorize, TContext, TEvents>({} as TEvents),
|
|
234
236
|
} = options;
|
|
@@ -251,6 +253,8 @@ export class PluvServer<
|
|
|
251
253
|
onRoomDeleted: (event) => onRoomDeleted?.(event),
|
|
252
254
|
onRoomMessage: (event) => onRoomMessage?.(event),
|
|
253
255
|
onStorageUpdated: (event) => onStorageUpdated?.(event),
|
|
256
|
+
onUserConnected: (event) => onUserConnected?.(event),
|
|
257
|
+
onUserDisconnected: (event) => onUserDisconnected?.(event),
|
|
254
258
|
} as PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>;
|
|
255
259
|
}
|
|
256
260
|
|
|
@@ -289,6 +293,12 @@ export class PluvServer<
|
|
|
289
293
|
await Promise.resolve(onMessage?.(event));
|
|
290
294
|
await Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
291
295
|
},
|
|
296
|
+
onUserConnected: async (event) => {
|
|
297
|
+
await Promise.resolve(this._getListeners().onUserConnected(event));
|
|
298
|
+
},
|
|
299
|
+
onUserDisconnected: async (event) => {
|
|
300
|
+
await Promise.resolve(this._getListeners().onUserDisconnected(event));
|
|
301
|
+
},
|
|
292
302
|
platform: this._platform,
|
|
293
303
|
roomContext,
|
|
294
304
|
router: this._router,
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
InferPlatformWebSocketType,
|
|
19
19
|
InferRoomContextType,
|
|
20
20
|
} from "./AbstractPlatform";
|
|
21
|
-
import type { AbstractWebSocket
|
|
21
|
+
import type { AbstractWebSocket } from "./AbstractWebSocket";
|
|
22
22
|
import type { PluvRouterEventConfig } from "./PluvRouter";
|
|
23
23
|
|
|
24
24
|
declare global {
|
|
@@ -106,13 +106,11 @@ export type MergeEventRecords<
|
|
|
106
106
|
>
|
|
107
107
|
: Id<TRoot>;
|
|
108
108
|
|
|
109
|
-
type GetInitialStorageEvent
|
|
109
|
+
export type GetInitialStorageEvent = {
|
|
110
110
|
room: string;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
export type GetInitialStorageFn
|
|
114
|
-
event: GetInitialStorageEvent<TPlatform>,
|
|
115
|
-
) => MaybePromise<Maybe<string>>;
|
|
113
|
+
export type GetInitialStorageFn = (event: GetInitialStorageEvent) => MaybePromise<Maybe<string>>;
|
|
116
114
|
|
|
117
115
|
export interface PluvIOListeners<
|
|
118
116
|
TPlatform extends AbstractPlatform<any>,
|
|
@@ -120,17 +118,14 @@ export interface PluvIOListeners<
|
|
|
120
118
|
TContext extends Record<string, any>,
|
|
121
119
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
122
120
|
> {
|
|
123
|
-
onRoomDeleted: (event: IORoomListenerEvent<
|
|
121
|
+
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
124
122
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
125
|
-
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext
|
|
123
|
+
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
124
|
+
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
125
|
+
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
export type IORoomListenerEvent<
|
|
129
|
-
TPlatform extends AbstractPlatform<any>,
|
|
130
|
-
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
131
|
-
TContext extends Record<string, any>,
|
|
132
|
-
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
133
|
-
> = {
|
|
128
|
+
export type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
134
129
|
context: TContext;
|
|
135
130
|
encodedState: string | null;
|
|
136
131
|
room: string;
|
|
@@ -141,7 +136,7 @@ export type IORoomMessageEvent<
|
|
|
141
136
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
142
137
|
TContext extends Record<string, any>,
|
|
143
138
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
144
|
-
> = IORoomListenerEvent<
|
|
139
|
+
> = IORoomListenerEvent<TContext> & {
|
|
145
140
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
146
141
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
147
142
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -151,12 +146,28 @@ export type IOStorageUpdatedEvent<
|
|
|
151
146
|
TPlatform extends AbstractPlatform<any>,
|
|
152
147
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
153
148
|
TContext extends Record<string, any>,
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
> = IORoomListenerEvent<TContext> & {
|
|
150
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
151
|
+
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type IOUserConnectedEvent<
|
|
155
|
+
TPlatform extends AbstractPlatform<any>,
|
|
156
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
157
|
+
TContext extends Record<string, any>,
|
|
158
|
+
> = IORoomListenerEvent<TContext> & {
|
|
156
159
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
157
160
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
158
161
|
};
|
|
159
162
|
|
|
163
|
+
export type IOUserDisconnectedEvent<
|
|
164
|
+
TPlatform extends AbstractPlatform<any>,
|
|
165
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
166
|
+
TContext extends Record<string, any>,
|
|
167
|
+
> = IORoomListenerEvent<TContext> & {
|
|
168
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
169
|
+
};
|
|
170
|
+
|
|
160
171
|
export type WebSocketType<TPlatform extends AbstractPlatform> =
|
|
161
172
|
| InferPlatformWebSocketType<TPlatform>
|
|
162
173
|
| InferPlatformWebSocketSource<TPlatform>;
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.32.
|
|
2
|
+
export const version = '0.32.6'
|