@tsed/socketio 6.88.1 → 6.89.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/lib/{SocketIOModule.d.ts → cjs/SocketIOModule.d.ts} +0 -0
- package/lib/{SocketIOModule.js → cjs/SocketIOModule.js} +20 -20
- package/lib/cjs/SocketIOModule.js.map +1 -0
- package/lib/{class → cjs/class}/SocketHandlersBuilder.d.ts +0 -0
- package/lib/{class → cjs/class}/SocketHandlersBuilder.js +1 -1
- package/lib/cjs/class/SocketHandlersBuilder.js.map +1 -0
- package/lib/{class → cjs/class}/SocketProviderMetadata.d.ts +0 -0
- package/lib/{class → cjs/class}/SocketProviderMetadata.js +0 -0
- package/lib/cjs/class/SocketProviderMetadata.js.map +1 -0
- package/lib/{constants → cjs/constants}/index.d.ts +0 -0
- package/lib/{constants → cjs/constants}/index.js +0 -0
- package/lib/cjs/constants/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/args.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/args.js +1 -1
- package/lib/cjs/decorators/args.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/broadcast.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/broadcast.js +1 -1
- package/lib/cjs/decorators/broadcast.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/broadcastOthers.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/broadcastOthers.js +1 -1
- package/lib/cjs/decorators/broadcastOthers.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/emit.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/emit.js +1 -1
- package/lib/cjs/decorators/emit.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/input.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/input.js +0 -0
- package/lib/cjs/decorators/input.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcast.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcast.js +2 -2
- package/lib/cjs/decorators/inputAndBroadcast.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcastOthers.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcastOthers.js +2 -2
- package/lib/cjs/decorators/inputAndBroadcastOthers.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndEmit.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndEmit.js +2 -2
- package/lib/cjs/decorators/inputAndEmit.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/io.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/io.js +1 -1
- package/lib/cjs/decorators/io.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/nsp.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/nsp.js +2 -2
- package/lib/cjs/decorators/nsp.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socket.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socket.js +1 -1
- package/lib/cjs/decorators/socket.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketErr.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketErr.js +1 -1
- package/lib/cjs/decorators/socketErr.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketEventName.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketEventName.js +1 -1
- package/lib/cjs/decorators/socketEventName.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketFilter.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketFilter.js +0 -0
- package/lib/cjs/decorators/socketFilter.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketMiddleware.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketMiddleware.js +1 -1
- package/lib/cjs/decorators/socketMiddleware.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketMiddlewareError.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketMiddlewareError.js +1 -1
- package/lib/cjs/decorators/socketMiddlewareError.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketReturns.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketReturns.js +0 -0
- package/lib/cjs/decorators/socketReturns.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketService.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketService.js +1 -1
- package/lib/cjs/decorators/socketService.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketSession.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketSession.js +1 -1
- package/lib/cjs/decorators/socketSession.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketUseAfter.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketUseAfter.js +0 -0
- package/lib/cjs/decorators/socketUseAfter.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketUseBefore.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketUseBefore.js +0 -0
- package/lib/cjs/decorators/socketUseBefore.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +32 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/OnNamespaceInit.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/OnNamespaceInit.js +0 -0
- package/lib/cjs/interfaces/OnNamespaceInit.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketFilters.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketFilters.js +0 -0
- package/lib/cjs/interfaces/SocketFilters.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketHandlerMetadata.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketHandlerMetadata.js +0 -0
- package/lib/cjs/interfaces/SocketHandlerMetadata.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketInjectableNsp.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketInjectableNsp.js +0 -0
- package/lib/cjs/interfaces/SocketInjectableNsp.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketParamMetadata.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketParamMetadata.js +0 -0
- package/lib/cjs/interfaces/SocketParamMetadata.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketProviderTypes.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketProviderTypes.js +0 -0
- package/lib/cjs/interfaces/SocketProviderTypes.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketReturnsTypes.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketReturnsTypes.js +0 -0
- package/lib/cjs/interfaces/SocketReturnsTypes.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/cjs/interfaces/index.js +11 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/{registries → cjs/registries}/NspSessionRegistry.d.ts +0 -0
- package/lib/{registries → cjs/registries}/NspSessionRegistry.js +0 -0
- package/lib/cjs/registries/NspSessionRegistry.js.map +1 -0
- package/lib/{services → cjs/services}/SocketIOServer.d.ts +0 -0
- package/lib/{services → cjs/services}/SocketIOServer.js +1 -1
- package/lib/cjs/services/SocketIOServer.js.map +1 -0
- package/lib/{services → cjs/services}/SocketIOService.d.ts +0 -0
- package/lib/{services → cjs/services}/SocketIOService.js +5 -5
- package/lib/cjs/services/SocketIOService.js.map +1 -0
- package/lib/esm/SocketIOModule.js +105 -0
- package/lib/esm/SocketIOModule.js.map +1 -0
- package/lib/esm/class/SocketHandlersBuilder.js +202 -0
- package/lib/esm/class/SocketHandlersBuilder.js.map +1 -0
- package/lib/esm/class/SocketProviderMetadata.js +44 -0
- package/lib/esm/class/SocketProviderMetadata.js.map +1 -0
- package/lib/esm/constants/index.js +2 -0
- package/lib/esm/constants/index.js.map +1 -0
- package/lib/esm/decorators/args.js +57 -0
- package/lib/esm/decorators/args.js.map +1 -0
- package/lib/esm/decorators/broadcast.js +28 -0
- package/lib/esm/decorators/broadcast.js.map +1 -0
- package/lib/esm/decorators/broadcastOthers.js +28 -0
- package/lib/esm/decorators/broadcastOthers.js.map +1 -0
- package/lib/esm/decorators/emit.js +28 -0
- package/lib/esm/decorators/emit.js.map +1 -0
- package/lib/esm/decorators/input.js +33 -0
- package/lib/esm/decorators/input.js.map +1 -0
- package/lib/esm/decorators/inputAndBroadcast.js +28 -0
- package/lib/esm/decorators/inputAndBroadcast.js.map +1 -0
- package/lib/esm/decorators/inputAndBroadcastOthers.js +28 -0
- package/lib/esm/decorators/inputAndBroadcastOthers.js.map +1 -0
- package/lib/esm/decorators/inputAndEmit.js +28 -0
- package/lib/esm/decorators/inputAndEmit.js.map +1 -0
- package/lib/esm/decorators/io.js +23 -0
- package/lib/esm/decorators/io.js.map +1 -0
- package/lib/esm/decorators/nsp.js +83 -0
- package/lib/esm/decorators/nsp.js.map +1 -0
- package/lib/esm/decorators/socket.js +28 -0
- package/lib/esm/decorators/socket.js.map +1 -0
- package/lib/esm/decorators/socketErr.js +26 -0
- package/lib/esm/decorators/socketErr.js.map +1 -0
- package/lib/esm/decorators/socketEventName.js +26 -0
- package/lib/esm/decorators/socketEventName.js.map +1 -0
- package/lib/esm/decorators/socketFilter.js +25 -0
- package/lib/esm/decorators/socketFilter.js.map +1 -0
- package/lib/esm/decorators/socketMiddleware.js +70 -0
- package/lib/esm/decorators/socketMiddleware.js.map +1 -0
- package/lib/esm/decorators/socketMiddlewareError.js +67 -0
- package/lib/esm/decorators/socketMiddlewareError.js.map +1 -0
- package/lib/esm/decorators/socketReturns.js +23 -0
- package/lib/esm/decorators/socketReturns.js.map +1 -0
- package/lib/esm/decorators/socketService.js +20 -0
- package/lib/esm/decorators/socketService.js.map +1 -0
- package/lib/esm/decorators/socketSession.js +27 -0
- package/lib/esm/decorators/socketSession.js.map +1 -0
- package/lib/esm/decorators/socketUseAfter.js +70 -0
- package/lib/esm/decorators/socketUseAfter.js.map +1 -0
- package/lib/esm/decorators/socketUseBefore.js +74 -0
- package/lib/esm/decorators/socketUseBefore.js.map +1 -0
- package/lib/esm/index.js +29 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/OnNamespaceInit.js +2 -0
- package/lib/esm/interfaces/OnNamespaceInit.js.map +1 -0
- package/lib/esm/interfaces/SocketFilters.js +13 -0
- package/lib/esm/interfaces/SocketFilters.js.map +1 -0
- package/lib/esm/interfaces/SocketHandlerMetadata.js +2 -0
- package/lib/esm/interfaces/SocketHandlerMetadata.js.map +1 -0
- package/lib/esm/interfaces/SocketInjectableNsp.js +2 -0
- package/lib/esm/interfaces/SocketInjectableNsp.js.map +1 -0
- package/lib/esm/interfaces/SocketParamMetadata.js +2 -0
- package/lib/esm/interfaces/SocketParamMetadata.js.map +1 -0
- package/lib/esm/interfaces/SocketProviderTypes.js +9 -0
- package/lib/esm/interfaces/SocketProviderTypes.js.map +1 -0
- package/lib/esm/interfaces/SocketReturnsTypes.js +10 -0
- package/lib/esm/interfaces/SocketReturnsTypes.js.map +1 -0
- package/lib/esm/interfaces/index.js +8 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/registries/NspSessionRegistry.js +12 -0
- package/lib/esm/registries/NspSessionRegistry.js.map +1 -0
- package/lib/esm/services/SocketIOServer.js +12 -0
- package/lib/esm/services/SocketIOServer.js.map +1 -0
- package/lib/esm/services/SocketIOService.js +64 -0
- package/lib/esm/services/SocketIOService.js.map +1 -0
- package/lib/types/SocketIOModule.d.ts +29 -0
- package/lib/types/class/SocketHandlersBuilder.d.ts +47 -0
- package/lib/types/class/SocketProviderMetadata.d.ts +19 -0
- package/lib/types/constants/index.d.ts +1 -0
- package/lib/types/decorators/args.d.ts +28 -0
- package/lib/types/decorators/broadcast.d.ts +23 -0
- package/lib/types/decorators/broadcastOthers.d.ts +23 -0
- package/lib/types/decorators/emit.d.ts +23 -0
- package/lib/types/decorators/input.d.ts +20 -0
- package/lib/types/decorators/inputAndBroadcast.d.ts +20 -0
- package/lib/types/decorators/inputAndBroadcastOthers.d.ts +20 -0
- package/lib/types/decorators/inputAndEmit.d.ts +20 -0
- package/lib/types/decorators/io.d.ts +19 -0
- package/lib/types/decorators/nsp.d.ts +64 -0
- package/lib/types/decorators/socket.d.ts +25 -0
- package/lib/types/decorators/socketErr.d.ts +21 -0
- package/lib/types/decorators/socketEventName.d.ts +21 -0
- package/lib/types/decorators/socketFilter.d.ts +9 -0
- package/lib/types/decorators/socketMiddleware.d.ts +54 -0
- package/lib/types/decorators/socketMiddlewareError.d.ts +50 -0
- package/lib/types/decorators/socketReturns.d.ts +9 -0
- package/lib/types/decorators/socketService.d.ts +11 -0
- package/lib/types/decorators/socketSession.d.ts +23 -0
- package/lib/types/decorators/socketUseAfter.d.ts +52 -0
- package/lib/types/decorators/socketUseBefore.d.ts +56 -0
- package/lib/types/index.d.ts +25 -0
- package/lib/types/interfaces/OnNamespaceInit.d.ts +7 -0
- package/lib/types/interfaces/SocketFilters.d.ts +11 -0
- package/lib/types/interfaces/SocketHandlerMetadata.d.ts +18 -0
- package/lib/types/interfaces/SocketInjectableNsp.d.ts +4 -0
- package/lib/types/interfaces/SocketParamMetadata.d.ts +7 -0
- package/lib/types/interfaces/SocketProviderTypes.d.ts +7 -0
- package/lib/types/interfaces/SocketReturnsTypes.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +15 -0
- package/lib/types/registries/NspSessionRegistry.d.ts +1 -0
- package/lib/types/services/SocketIOServer.d.ts +4 -0
- package/lib/types/services/SocketIOService.d.ts +30 -0
- package/package.json +25 -17
- package/tsconfig.compile.esm.json +23 -0
- package/lib/SocketIOModule.js.map +0 -1
- package/lib/class/SocketHandlersBuilder.js.map +0 -1
- package/lib/class/SocketProviderMetadata.js.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/decorators/args.js.map +0 -1
- package/lib/decorators/broadcast.js.map +0 -1
- package/lib/decorators/broadcastOthers.js.map +0 -1
- package/lib/decorators/emit.js.map +0 -1
- package/lib/decorators/input.js.map +0 -1
- package/lib/decorators/inputAndBroadcast.js.map +0 -1
- package/lib/decorators/inputAndBroadcastOthers.js.map +0 -1
- package/lib/decorators/inputAndEmit.js.map +0 -1
- package/lib/decorators/io.js.map +0 -1
- package/lib/decorators/nsp.js.map +0 -1
- package/lib/decorators/socket.js.map +0 -1
- package/lib/decorators/socketErr.js.map +0 -1
- package/lib/decorators/socketEventName.js.map +0 -1
- package/lib/decorators/socketFilter.js.map +0 -1
- package/lib/decorators/socketMiddleware.js.map +0 -1
- package/lib/decorators/socketMiddlewareError.js.map +0 -1
- package/lib/decorators/socketReturns.js.map +0 -1
- package/lib/decorators/socketService.js.map +0 -1
- package/lib/decorators/socketSession.js.map +0 -1
- package/lib/decorators/socketUseAfter.js.map +0 -1
- package/lib/decorators/socketUseBefore.js.map +0 -1
- package/lib/index.js +0 -32
- package/lib/index.js.map +0 -1
- package/lib/interfaces/OnNamespaceInit.js.map +0 -1
- package/lib/interfaces/SocketFilters.js.map +0 -1
- package/lib/interfaces/SocketHandlerMetadata.js.map +0 -1
- package/lib/interfaces/SocketInjectableNsp.js.map +0 -1
- package/lib/interfaces/SocketParamMetadata.js.map +0 -1
- package/lib/interfaces/SocketProviderTypes.js.map +0 -1
- package/lib/interfaces/SocketReturnsTypes.js.map +0 -1
- package/lib/interfaces/index.js +0 -11
- package/lib/interfaces/index.js.map +0 -1
- package/lib/registries/NspSessionRegistry.js.map +0 -1
- package/lib/services/SocketIOServer.js.map +0 -1
- package/lib/services/SocketIOService.js.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ConverterService, InjectorService, Provider } from "@tsed/common";
|
|
2
|
+
import { Namespace, Socket } from "socket.io";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare class SocketHandlersBuilder {
|
|
7
|
+
private provider;
|
|
8
|
+
private converterService;
|
|
9
|
+
private injector;
|
|
10
|
+
private socketProviderMetadata;
|
|
11
|
+
constructor(provider: Provider<any>, converterService: ConverterService, injector: InjectorService);
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {SocketHandlerMetadata} handlerMetadata
|
|
15
|
+
* @param scope
|
|
16
|
+
* @returns {(data) => void}
|
|
17
|
+
*/
|
|
18
|
+
private static bindResponseMiddleware;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @returns {any}
|
|
22
|
+
*/
|
|
23
|
+
build(nsps: Map<string, Namespace>): this;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {Socket} socket
|
|
27
|
+
* @param {Namespace} nsp
|
|
28
|
+
*/
|
|
29
|
+
onConnection(socket: Socket, nsp: Namespace): void;
|
|
30
|
+
onDisconnect(socket: Socket, nsp: Namespace): void;
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {Socket} socket
|
|
34
|
+
*/
|
|
35
|
+
private createSession;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {Socket} socket
|
|
39
|
+
*/
|
|
40
|
+
private destroySession;
|
|
41
|
+
private buildHandlers;
|
|
42
|
+
private runQueue;
|
|
43
|
+
private deserialize;
|
|
44
|
+
private bindMiddleware;
|
|
45
|
+
private invoke;
|
|
46
|
+
private buildParameters;
|
|
47
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SocketHandlerMetadata, SocketInjectableNsp } from "../interfaces";
|
|
2
|
+
import { SocketProviderTypes } from "../interfaces/SocketProviderTypes";
|
|
3
|
+
export declare class SocketProviderMetadata {
|
|
4
|
+
type: SocketProviderTypes;
|
|
5
|
+
namespace: string;
|
|
6
|
+
error: boolean;
|
|
7
|
+
injectNamespaces: SocketInjectableNsp[];
|
|
8
|
+
useBefore: any[];
|
|
9
|
+
useAfter: any[];
|
|
10
|
+
handlers: Record<string, SocketHandlerMetadata>;
|
|
11
|
+
constructor(options?: Partial<SocketProviderMetadata>);
|
|
12
|
+
get useHandler(): SocketHandlerMetadata;
|
|
13
|
+
get $onConnection(): SocketHandlerMetadata;
|
|
14
|
+
get $onDisconnect(): SocketHandlerMetadata;
|
|
15
|
+
get(key: string): SocketHandlerMetadata;
|
|
16
|
+
set(key: string, metadata: SocketHandlerMetadata): void;
|
|
17
|
+
getHandlers(): SocketHandlerMetadata[];
|
|
18
|
+
createHook(hook: string, eventName: string): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PROVIDER_TYPE_SOCKET_SERVICE = "socketService";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject the list of arguments in the decorated parameter.
|
|
3
|
+
*
|
|
4
|
+
* `@Args` accept an index parameter to pick up directly the item in the arguments list.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* myMethod(@Args() arguments: any[]) {
|
|
14
|
+
*
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @Input("event2")
|
|
18
|
+
* myMethod2(@Args(0) data: any) {
|
|
19
|
+
*
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @decorator
|
|
25
|
+
* @param mapIndex
|
|
26
|
+
* @param useType
|
|
27
|
+
*/
|
|
28
|
+
export declare function Args(mapIndex?: number, useType?: any): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast the response for all client registered in the same namespace.
|
|
3
|
+
*
|
|
4
|
+
* With the `@Broadcast` decorator, the method will accept a return type (Promise or not).
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* @Broadcast("returnEvent")
|
|
14
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
15
|
+
* return Promise.resolve({data})
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @decorator
|
|
21
|
+
* @param eventName
|
|
22
|
+
*/
|
|
23
|
+
export declare function Broadcast(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast the response for all client registered in the same namespace except to the current client.
|
|
3
|
+
*
|
|
4
|
+
* With the `@BroadcastOthers` decorator, the method will accept a return type (Promise or not).
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* @BroadcastOthers("returnEvent")
|
|
14
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
15
|
+
* return Promise.resolve({data})
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @decorator
|
|
21
|
+
* @param eventName
|
|
22
|
+
*/
|
|
23
|
+
export declare function BroadcastOthers(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit the response to the client.
|
|
3
|
+
*
|
|
4
|
+
* With the `@Emit` decorator, the method will accept a return type (Promise or not).
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* @Emit("returnEvent")
|
|
14
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
15
|
+
* return Promise.resolve({data})
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @decorator
|
|
21
|
+
* @param eventName
|
|
22
|
+
*/
|
|
23
|
+
export declare function Emit(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach the decorated method to the socket event.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketService("/nsp")
|
|
8
|
+
* export class MyWS {
|
|
9
|
+
*
|
|
10
|
+
* @Input("event")
|
|
11
|
+
* myMethod(@Args(0) data: any, @Nsp socket) {
|
|
12
|
+
*
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @decorator
|
|
18
|
+
* @param eventName
|
|
19
|
+
*/
|
|
20
|
+
export declare function Input(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach the decorated method to the socket event and broadcast the response to all clients.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketService("/nsp")
|
|
8
|
+
* export class MyWS {
|
|
9
|
+
*
|
|
10
|
+
* @InputAndBroadcast("event")
|
|
11
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
12
|
+
* return {data: "data"};
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @decorator
|
|
18
|
+
* @param eventName
|
|
19
|
+
*/
|
|
20
|
+
export declare function InputAndBroadcast(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach the decorated method to the socket event and broadcast the response to all clients with the exception of the connected customer.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketService("/nsp")
|
|
8
|
+
* export class MyWS {
|
|
9
|
+
*
|
|
10
|
+
* @InputAndBroadcastOthers("event")
|
|
11
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
12
|
+
* return {data: "data"};
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @decorator
|
|
18
|
+
* @param eventName
|
|
19
|
+
*/
|
|
20
|
+
export declare function InputAndBroadcastOthers(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach the decorated method to the socket event and emit the response to the client.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketService("/nsp")
|
|
8
|
+
* export class MyWS {
|
|
9
|
+
*
|
|
10
|
+
* @InputAndEmit("event")
|
|
11
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
12
|
+
* return {data: "data"};
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @decorator
|
|
18
|
+
* @param eventName
|
|
19
|
+
*/
|
|
20
|
+
export declare function InputAndEmit(eventName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @SocketService("/nsp")
|
|
9
|
+
* export class MyWS {
|
|
10
|
+
* constructor(@IO private io: Server) {}
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param target
|
|
15
|
+
* @param targetKey
|
|
16
|
+
* @param descriptor
|
|
17
|
+
* @decorator
|
|
18
|
+
*/
|
|
19
|
+
export declare function IO(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Namespace as NamespaceType } from "socket.io";
|
|
2
|
+
export declare type Namespace = NamespaceType;
|
|
3
|
+
export declare type Nsp = NamespaceType;
|
|
4
|
+
/**
|
|
5
|
+
* Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Nsp, SocketService, Input} from "@tsed/socketio";
|
|
11
|
+
*
|
|
12
|
+
* @SocketService("/nsp")
|
|
13
|
+
* export class MyWS {
|
|
14
|
+
*
|
|
15
|
+
* @Nsp
|
|
16
|
+
* nsp: SocketIO.Namespace; // will inject SocketIO.Namespace (not available on constructor)
|
|
17
|
+
*
|
|
18
|
+
* @Nsp("/my-other-namespace")
|
|
19
|
+
* nspOther: SocketIO.Namespace; // communication between two namespace
|
|
20
|
+
*
|
|
21
|
+
* @Input("event")
|
|
22
|
+
* myMethod(@Nsp namespace: SocketIO.Namespace) {
|
|
23
|
+
*
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param target
|
|
29
|
+
* @param {string} propertyKey
|
|
30
|
+
* @param {number} index
|
|
31
|
+
* @decorator
|
|
32
|
+
*/
|
|
33
|
+
export declare function Nsp(target: any, propertyKey?: string, index?: number): any;
|
|
34
|
+
/**
|
|
35
|
+
* Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
|
|
36
|
+
*
|
|
37
|
+
* ### Example
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import {Namespace, SocketService, Input} from "@tsed/socketio";
|
|
41
|
+
*
|
|
42
|
+
* @SocketService("/nsp")
|
|
43
|
+
* export class MyWS {
|
|
44
|
+
*
|
|
45
|
+
* @Nsp
|
|
46
|
+
* nsp: Namespace; // will inject SocketIO.Namespace (not available on constructor)
|
|
47
|
+
*
|
|
48
|
+
* @Nsp("/my-other-namespace")
|
|
49
|
+
* nspOther: Namespace; // communication between two namespace
|
|
50
|
+
*
|
|
51
|
+
* @Input("event")
|
|
52
|
+
* myMethod(@Namespace namespace: Namespace) {
|
|
53
|
+
*
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param target
|
|
59
|
+
* @param {string} propertyKey
|
|
60
|
+
* @param {number} index
|
|
61
|
+
* @alias {Nsp}
|
|
62
|
+
* @decorator
|
|
63
|
+
*/
|
|
64
|
+
export declare function Namespace(target: any, propertyKey?: string, index?: number): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Socket as SocketType } from "socket.io";
|
|
2
|
+
export declare type Socket = SocketType;
|
|
3
|
+
/**
|
|
4
|
+
* Inject the Socket instance in the decorated parameter.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* myMethod(@Socket socket) {
|
|
14
|
+
*
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
* @param target
|
|
21
|
+
* @param {string} propertyKey
|
|
22
|
+
* @param {number} index
|
|
23
|
+
* @decorator
|
|
24
|
+
*/
|
|
25
|
+
export declare function Socket(target: any, propertyKey: string, index: number): any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject the error in the parameters
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketMiddlewareError()
|
|
8
|
+
* export class MyMiddleware {
|
|
9
|
+
*
|
|
10
|
+
* myMethod(@SocketErr err: any, @Args() arguments: any[]) {
|
|
11
|
+
*
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @decorator
|
|
17
|
+
* @param target
|
|
18
|
+
* @param propertyKey
|
|
19
|
+
* @param index
|
|
20
|
+
*/
|
|
21
|
+
export declare function SocketErr(target: any, propertyKey: string, index: number): any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject the Socket instance in the decorated parameter.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @SocketMiddleware("/nsp")
|
|
8
|
+
* export class MyMiddleware {
|
|
9
|
+
* use(@SocketEventName eventName: string) {
|
|
10
|
+
*
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
* @param target
|
|
17
|
+
* @param {string} propertyKey
|
|
18
|
+
* @param {number} index
|
|
19
|
+
* @decorator
|
|
20
|
+
*/
|
|
21
|
+
export declare function SocketEventName(target: any, propertyKey: string, index: number): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {SocketFilters} filter
|
|
5
|
+
* @param {number} mapIndex
|
|
6
|
+
* @returns {(target: any, propertyKey: string, index: number) => Store}
|
|
7
|
+
* @decorator
|
|
8
|
+
*/
|
|
9
|
+
export declare function SocketFilter(filter: SocketFilters, mapIndex?: number): (target: any, propertyKey: string, index: number) => void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare a new SocketMiddleware.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
7
|
+
*
|
|
8
|
+
* Here an example of a middleware:
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @SocketMiddleware()
|
|
12
|
+
* export class UserConverterSocketMiddleware {
|
|
13
|
+
* constructor(private converterService: ConverterService) {
|
|
14
|
+
* }
|
|
15
|
+
* async use(@Args() args: any[]) {
|
|
16
|
+
*
|
|
17
|
+
* let [user] = args;
|
|
18
|
+
* // update Arguments
|
|
19
|
+
* user = this.converterService.deserialize(user, User);
|
|
20
|
+
*
|
|
21
|
+
* return [user];
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
* > The user instance will be forwarded to the next middleware and to your decorated method.
|
|
26
|
+
*
|
|
27
|
+
* Then:
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
31
|
+
* import {UserConverterSocketMiddleware} from "../middlewares";
|
|
32
|
+
* import {User} from "../models/User";
|
|
33
|
+
*
|
|
34
|
+
* @SocketService("/my-namespace")
|
|
35
|
+
* @SocketUseBefore(UserConverterSocketMiddleware) // global version
|
|
36
|
+
* export class MySocketService {
|
|
37
|
+
*
|
|
38
|
+
* @Input("eventName")
|
|
39
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
40
|
+
* @SocketUseBefore(UserConverterSocketMiddleware)
|
|
41
|
+
* async myMethod(@Args(0) user: User) {
|
|
42
|
+
*
|
|
43
|
+
* console.log(user);
|
|
44
|
+
*
|
|
45
|
+
* return user;
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @returns {Function}
|
|
51
|
+
* @decorator
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
54
|
+
export declare function SocketMiddleware(): Function;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare a new SocketMiddlewareError.
|
|
3
|
+
*
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
7
|
+
*
|
|
8
|
+
* Here an example of a middleware:
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {SocketMiddlewareError, SocketErr, Socket, Args} from "@tsed/socketio";
|
|
12
|
+
*
|
|
13
|
+
* @SocketMiddlewareError()
|
|
14
|
+
* export class ErrorHandlerSocketMiddleware {
|
|
15
|
+
* async use(@SocketEventName, @SocketErr err: any, @Socket socket: SocketIO.Socket) {
|
|
16
|
+
* console.error(err);
|
|
17
|
+
* socket.emit("error", {message: "An error has occured"})
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Then:
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
26
|
+
* import {ErrorHandlerSocketMiddleware} from "../middlewares";
|
|
27
|
+
* import {User} from "../models/User";
|
|
28
|
+
*
|
|
29
|
+
* @SocketService("/my-namespace")
|
|
30
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware) // global version
|
|
31
|
+
* export class MySocketService {
|
|
32
|
+
*
|
|
33
|
+
* @Input("eventName")
|
|
34
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
35
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware)
|
|
36
|
+
* async myMethod(@Args(0) userName: User) {
|
|
37
|
+
*
|
|
38
|
+
* console.log(user);
|
|
39
|
+
* throw new Error("Error");
|
|
40
|
+
*
|
|
41
|
+
* return user;
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @returns {Function}
|
|
47
|
+
* @decorator
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
50
|
+
export declare function SocketMiddlewareError(): Function;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SocketReturnsTypes } from "../interfaces/SocketReturnsTypes";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} eventName
|
|
5
|
+
* @param {SocketReturnsTypes} type
|
|
6
|
+
* @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => void}
|
|
7
|
+
* @decorator
|
|
8
|
+
*/
|
|
9
|
+
export declare function SocketReturns(eventName: string, type: SocketReturnsTypes): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decorators `@SocketService()` declare a new socket service (and service) can be injected in other service or controller on there `constructor`.
|
|
3
|
+
* All services annotated with `@SocketService()` are constructed one time.
|
|
4
|
+
*
|
|
5
|
+
* > `@SocketService()` use the `reflect-metadata` to collect and inject service on controllers or other services.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} namespace
|
|
8
|
+
* @returns {Function}
|
|
9
|
+
* @decorator
|
|
10
|
+
*/
|
|
11
|
+
export declare function SocketService(namespace?: string): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare type SocketSession = Map<string, any>;
|
|
2
|
+
/**
|
|
3
|
+
* Inject the Socket instance in the decorated parameter.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @SocketService("/nsp")
|
|
9
|
+
* export class MyWS {
|
|
10
|
+
*
|
|
11
|
+
* @Input("event")
|
|
12
|
+
* myMethod(@SocketSession session: Map) {
|
|
13
|
+
* console.log(session);
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param target
|
|
19
|
+
* @param {string} propertyKey
|
|
20
|
+
* @param {number} index
|
|
21
|
+
* @decorator
|
|
22
|
+
*/
|
|
23
|
+
export declare function SocketSession(target: any, propertyKey: string, index: number): any;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Attach a Socket Middleware to a method or a class.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
8
|
+
*
|
|
9
|
+
* Here an example of a middleware:
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {SocketMiddlewareError, SocketErr, Socket, Args} from "@tsed/socketio";
|
|
13
|
+
*
|
|
14
|
+
* @SocketMiddlewareError()
|
|
15
|
+
* export class ErrorHandlerSocketMiddleware {
|
|
16
|
+
* async use(@SocketErr() err: any, @Socket socket: SocketIO.Socket) {
|
|
17
|
+
* console.error(err);
|
|
18
|
+
* socket.emit("error", {message: "An error has occured"})
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Then:
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
27
|
+
* import {ErrorHandlerSocketMiddleware} from "../middlewares";
|
|
28
|
+
* import {User} from "../models/User";
|
|
29
|
+
*
|
|
30
|
+
* @SocketService("/my-namespace")
|
|
31
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware) // global version
|
|
32
|
+
* export class MySocketService {
|
|
33
|
+
*
|
|
34
|
+
* @Input("eventName")
|
|
35
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
36
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware)
|
|
37
|
+
* async myMethod(@Args(0) userName: User) {
|
|
38
|
+
*
|
|
39
|
+
* console.log(user);
|
|
40
|
+
* throw new Error("Error");
|
|
41
|
+
*
|
|
42
|
+
* return user;
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @returns {(target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void}
|
|
48
|
+
* @decorator
|
|
49
|
+
* @experimental
|
|
50
|
+
* @param middlewares
|
|
51
|
+
*/
|
|
52
|
+
export declare function SocketUseAfter(...middlewares: Type<any>[]): (target: any, propertyKey?: string | undefined, descriptor?: PropertyDescriptor | undefined) => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Attach a Socket Middleware to a method or a class.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
8
|
+
*
|
|
9
|
+
* Here an example of a middleware:
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* @SocketMiddleware()
|
|
13
|
+
* export class UserConverterSocketMiddleware {
|
|
14
|
+
* constructor(private converterService: ConverterService) {
|
|
15
|
+
* }
|
|
16
|
+
* async use(@Args() args: any[]) {
|
|
17
|
+
*
|
|
18
|
+
* let [user] = args;
|
|
19
|
+
* // update Arguments
|
|
20
|
+
* user = ConverterService.deserialize(user, User);
|
|
21
|
+
*
|
|
22
|
+
* return [user];
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
* > The user instance will be forwarded to the next middleware and to your decorated method.
|
|
27
|
+
*
|
|
28
|
+
* Then:
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
32
|
+
* import {UserConverterSocketMiddleware} from "../middlewares";
|
|
33
|
+
* import {User} from "../models/User";
|
|
34
|
+
*
|
|
35
|
+
* @SocketService("/my-namespace")
|
|
36
|
+
* @SocketUseBefore(UserConverterSocketMiddleware) // global version
|
|
37
|
+
* export class MySocketService {
|
|
38
|
+
*
|
|
39
|
+
* @Input("eventName")
|
|
40
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
41
|
+
* @SocketUseBefore(UserConverterSocketMiddleware)
|
|
42
|
+
* async myMethod(@Args(0) user: User) {
|
|
43
|
+
*
|
|
44
|
+
* console.log(user);
|
|
45
|
+
*
|
|
46
|
+
* return user;
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @returns {(target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void}
|
|
52
|
+
* @decorator
|
|
53
|
+
* @experimental
|
|
54
|
+
* @param middlewares
|
|
55
|
+
*/
|
|
56
|
+
export declare function SocketUseBefore(...middlewares: Type<any>[]): (target: any, propertyKey?: string | undefined, descriptor?: PropertyDescriptor | undefined) => void;
|