@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,67 @@
|
|
|
1
|
+
import { Middleware } from "@tsed/common";
|
|
2
|
+
import { Store } from "@tsed/core";
|
|
3
|
+
import { SocketProviderTypes } from "../interfaces/SocketProviderTypes";
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new SocketMiddlewareError.
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
10
|
+
*
|
|
11
|
+
* Here an example of a middleware:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import {SocketMiddlewareError, SocketErr, Socket, Args} from "@tsed/socketio";
|
|
15
|
+
*
|
|
16
|
+
* @SocketMiddlewareError()
|
|
17
|
+
* export class ErrorHandlerSocketMiddleware {
|
|
18
|
+
* async use(@SocketEventName, @SocketErr err: any, @Socket socket: SocketIO.Socket) {
|
|
19
|
+
* console.error(err);
|
|
20
|
+
* socket.emit("error", {message: "An error has occured"})
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Then:
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
29
|
+
* import {ErrorHandlerSocketMiddleware} from "../middlewares";
|
|
30
|
+
* import {User} from "../models/User";
|
|
31
|
+
*
|
|
32
|
+
* @SocketService("/my-namespace")
|
|
33
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware) // global version
|
|
34
|
+
* export class MySocketService {
|
|
35
|
+
*
|
|
36
|
+
* @Input("eventName")
|
|
37
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
38
|
+
* @SocketUseAfter(ErrorHandlerSocketMiddleware)
|
|
39
|
+
* async myMethod(@Args(0) userName: User) {
|
|
40
|
+
*
|
|
41
|
+
* console.log(user);
|
|
42
|
+
* throw new Error("Error");
|
|
43
|
+
*
|
|
44
|
+
* return user;
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @returns {Function}
|
|
50
|
+
* @decorator
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
export function SocketMiddlewareError() {
|
|
54
|
+
return (target) => {
|
|
55
|
+
Store.from(target).merge("socketIO", {
|
|
56
|
+
type: SocketProviderTypes.MIDDLEWARE,
|
|
57
|
+
error: true,
|
|
58
|
+
handlers: {
|
|
59
|
+
use: {
|
|
60
|
+
methodClassName: "use"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return Middleware()(target);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=socketMiddlewareError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketMiddlewareError.js","sourceRoot":"","sources":["../../../src/decorators/socketMiddlewareError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,CAAC,MAAiB,EAAE,EAAE;QAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,IAAI,EAAE,mBAAmB,CAAC,UAAU;YACpC,KAAK,EAAE,IAAI;YAEX,QAAQ,EAAE;gBACR,GAAG,EAAE;oBACH,eAAe,EAAE,KAAK;iBACvB;aACF;SACF,CAAC,CAAC;QAEH,OAAO,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Middleware} from \"@tsed/common\";\nimport {Store, Type} from \"@tsed/core\";\nimport {SocketProviderTypes} from \"../interfaces/SocketProviderTypes\";\n\n/**\n * Declare a new SocketMiddlewareError.\n *\n * ### Example\n *\n * A middleware can be also used on a `SocketService` either on a class or on a method.\n *\n * Here an example of a middleware:\n *\n * ```typescript\n * import {SocketMiddlewareError, SocketErr, Socket, Args} from \"@tsed/socketio\";\n *\n * @SocketMiddlewareError()\n * export class ErrorHandlerSocketMiddleware {\n * async use(@SocketEventName, @SocketErr err: any, @Socket socket: SocketIO.Socket) {\n * console.error(err);\n * socket.emit(\"error\", {message: \"An error has occured\"})\n * }\n * }\n * ```\n *\n * Then:\n *\n * ```typescript\n * import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from \"@tsed/socketio\";\n * import {ErrorHandlerSocketMiddleware} from \"../middlewares\";\n * import {User} from \"../models/User\";\n *\n * @SocketService(\"/my-namespace\")\n * @SocketUseAfter(ErrorHandlerSocketMiddleware) // global version\n * export class MySocketService {\n *\n * @Input(\"eventName\")\n * @Emit(\"responseEventName\") // or Broadcast or BroadcastOthers\n * @SocketUseAfter(ErrorHandlerSocketMiddleware)\n * async myMethod(@Args(0) userName: User) {\n *\n * console.log(user);\n * throw new Error(\"Error\");\n *\n * return user;\n * }\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n * @experimental\n */\nexport function SocketMiddlewareError(): Function {\n return (target: Type<any>) => {\n Store.from(target).merge(\"socketIO\", {\n type: SocketProviderTypes.MIDDLEWARE,\n error: true,\n\n handlers: {\n use: {\n methodClassName: \"use\"\n }\n }\n });\n\n return Middleware()(target);\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} eventName
|
|
5
|
+
* @param {SocketReturnsTypes} type
|
|
6
|
+
* @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => void}
|
|
7
|
+
* @decorator
|
|
8
|
+
*/
|
|
9
|
+
export function SocketReturns(eventName, type) {
|
|
10
|
+
return (target, propertyKey, descriptor) => {
|
|
11
|
+
Store.from(target).merge("socketIO", {
|
|
12
|
+
handlers: {
|
|
13
|
+
[propertyKey]: {
|
|
14
|
+
returns: {
|
|
15
|
+
eventName,
|
|
16
|
+
type
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=socketReturns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketReturns.js","sourceRoot":"","sources":["../../../src/decorators/socketReturns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAGjC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,IAAwB;IACvE,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,QAAQ,EAAE;gBACR,CAAC,WAAW,CAAC,EAAE;oBACb,OAAO,EAAE;wBACP,SAAS;wBACT,IAAI;qBACL;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {SocketReturnsTypes} from \"../interfaces/SocketReturnsTypes\";\n\n/**\n *\n * @param {string} eventName\n * @param {SocketReturnsTypes} type\n * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => void}\n * @decorator\n */\nexport function SocketReturns(eventName: string, type: SocketReturnsTypes) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Store.from(target).merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n returns: {\n eventName,\n type\n }\n }\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StoreMerge, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Injectable } from "@tsed/di";
|
|
3
|
+
import { SocketProviderTypes } from "../interfaces/SocketProviderTypes";
|
|
4
|
+
import { PROVIDER_TYPE_SOCKET_SERVICE } from "../constants";
|
|
5
|
+
/**
|
|
6
|
+
* The decorators `@SocketService()` declare a new socket service (and service) can be injected in other service or controller on there `constructor`.
|
|
7
|
+
* All services annotated with `@SocketService()` are constructed one time.
|
|
8
|
+
*
|
|
9
|
+
* > `@SocketService()` use the `reflect-metadata` to collect and inject service on controllers or other services.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} namespace
|
|
12
|
+
* @returns {Function}
|
|
13
|
+
* @decorator
|
|
14
|
+
*/
|
|
15
|
+
export function SocketService(namespace = "/") {
|
|
16
|
+
return useDecorators(StoreMerge("socketIO", { namespace, type: SocketProviderTypes.SERVICE }), Injectable({
|
|
17
|
+
type: PROVIDER_TYPE_SOCKET_SERVICE
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=socketService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketService.js","sourceRoot":"","sources":["../../../src/decorators/socketService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,4BAA4B,EAAC,MAAM,cAAc,CAAC;AAE1D;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,SAAS,GAAG,GAAG;IAC3C,OAAO,aAAa,CAClB,UAAU,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,mBAAmB,CAAC,OAAO,EAAC,CAAC,EACtE,UAAU,CAAC;QACT,IAAI,EAAE,4BAA4B;KACnC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {SocketProviderTypes} from \"../interfaces/SocketProviderTypes\";\nimport {PROVIDER_TYPE_SOCKET_SERVICE} from \"../constants\";\n\n/**\n * The decorators `@SocketService()` declare a new socket service (and service) can be injected in other service or controller on there `constructor`.\n * All services annotated with `@SocketService()` are constructed one time.\n *\n * > `@SocketService()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @param {string} namespace\n * @returns {Function}\n * @decorator\n */\nexport function SocketService(namespace = \"/\") {\n return useDecorators(\n StoreMerge(\"socketIO\", {namespace, type: SocketProviderTypes.SERVICE}),\n Injectable({\n type: PROVIDER_TYPE_SOCKET_SERVICE\n })\n );\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
2
|
+
import { SocketFilter } from "./socketFilter";
|
|
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(@SocketSession session: Map) {
|
|
14
|
+
* console.log(session);
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param target
|
|
20
|
+
* @param {string} propertyKey
|
|
21
|
+
* @param {number} index
|
|
22
|
+
* @decorator
|
|
23
|
+
*/
|
|
24
|
+
export function SocketSession(target, propertyKey, index) {
|
|
25
|
+
return SocketFilter(SocketFilters.SESSION)(target, propertyKey, index);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=socketSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketSession.js","sourceRoot":"","sources":["../../../src/decorators/socketSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa;IAC3E,OAAO,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import {SocketFilters} from \"../interfaces/SocketFilters\";\nimport {SocketFilter} from \"./socketFilter\";\n\nexport type SocketSession = Map<string, any>;\n\n/**\n * Inject the Socket instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * myMethod(@SocketSession session: Map) {\n * console.log(session);\n * }\n * }\n * ```\n *\n * @param target\n * @param {string} propertyKey\n * @param {number} index\n * @decorator\n */\nexport function SocketSession(target: any, propertyKey: string, index: number): any {\n return SocketFilter(SocketFilters.SESSION)(target, propertyKey, index);\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Store } 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 function SocketUseAfter(...middlewares) {
|
|
53
|
+
return (target, propertyKey, descriptor) => {
|
|
54
|
+
if (propertyKey) {
|
|
55
|
+
Store.from(target).merge("socketIO", {
|
|
56
|
+
handlers: {
|
|
57
|
+
[propertyKey]: {
|
|
58
|
+
useAfter: middlewares
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
Store.from(target).merge("socketIO", {
|
|
65
|
+
useAfter: middlewares
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=socketUseAfter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketUseAfter.js","sourceRoot":"","sources":["../../../src/decorators/socketUseAfter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,cAAc,CAAC,GAAG,WAAwB;IACxD,OAAO,CAAC,MAAW,EAAE,WAAoB,EAAE,UAA+B,EAAE,EAAE;QAC5E,IAAI,WAAW,EAAE;YACf,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,QAAQ,EAAE;oBACR,CAAC,WAAW,CAAC,EAAE;wBACb,QAAQ,EAAE,WAAW;qBACtB;iBACF;aACF,CAAC,CAAC;SACJ;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,QAAQ,EAAE,WAAW;aACtB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\n\n/**\n * Attach a Socket Middleware to a method or a class.\n *\n * ### Example\n *\n * A middleware can be also used on a `SocketService` either on a class or on a method.\n *\n * Here an example of a middleware:\n *\n * ```typescript\n * import {SocketMiddlewareError, SocketErr, Socket, Args} from \"@tsed/socketio\";\n *\n * @SocketMiddlewareError()\n * export class ErrorHandlerSocketMiddleware {\n * async use(@SocketErr() err: any, @Socket socket: SocketIO.Socket) {\n * console.error(err);\n * socket.emit(\"error\", {message: \"An error has occured\"})\n * }\n * }\n * ```\n *\n * Then:\n *\n * ```typescript\n * import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from \"@tsed/socketio\";\n * import {ErrorHandlerSocketMiddleware} from \"../middlewares\";\n * import {User} from \"../models/User\";\n *\n * @SocketService(\"/my-namespace\")\n * @SocketUseAfter(ErrorHandlerSocketMiddleware) // global version\n * export class MySocketService {\n *\n * @Input(\"eventName\")\n * @Emit(\"responseEventName\") // or Broadcast or BroadcastOthers\n * @SocketUseAfter(ErrorHandlerSocketMiddleware)\n * async myMethod(@Args(0) userName: User) {\n *\n * console.log(user);\n * throw new Error(\"Error\");\n *\n * return user;\n * }\n * }\n * ```\n *\n * @returns {(target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void}\n * @decorator\n * @experimental\n * @param middlewares\n */\nexport function SocketUseAfter(...middlewares: Type<any>[]) {\n return (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => {\n if (propertyKey) {\n Store.from(target).merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n useAfter: middlewares\n }\n }\n });\n } else {\n Store.from(target).merge(\"socketIO\", {\n useAfter: middlewares\n });\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Store } 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 function SocketUseBefore(...middlewares) {
|
|
57
|
+
return (target, propertyKey, descriptor) => {
|
|
58
|
+
if (propertyKey) {
|
|
59
|
+
Store.from(target).merge("socketIO", {
|
|
60
|
+
handlers: {
|
|
61
|
+
[propertyKey]: {
|
|
62
|
+
useBefore: middlewares
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
Store.from(target).merge("socketIO", {
|
|
69
|
+
useBefore: middlewares
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=socketUseBefore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketUseBefore.js","sourceRoot":"","sources":["../../../src/decorators/socketUseBefore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,eAAe,CAAC,GAAG,WAAwB;IACzD,OAAO,CAAC,MAAW,EAAE,WAAoB,EAAE,UAA+B,EAAE,EAAE;QAC5E,IAAI,WAAW,EAAE;YACf,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,QAAQ,EAAE;oBACR,CAAC,WAAW,CAAC,EAAE;wBACb,SAAS,EAAE,WAAW;qBACvB;iBACF;aACF,CAAC,CAAC;SACJ;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,SAAS,EAAE,WAAW;aACvB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\n\n/**\n * Attach a Socket Middleware to a method or a class.\n *\n * ### Example\n *\n * A middleware can be also used on a `SocketService` either on a class or on a method.\n *\n * Here an example of a middleware:\n *\n * ```typescript\n * @SocketMiddleware()\n * export class UserConverterSocketMiddleware {\n * constructor(private converterService: ConverterService) {\n * }\n * async use(@Args() args: any[]) {\n *\n * let [user] = args;\n * // update Arguments\n * user = ConverterService.deserialize(user, User);\n *\n * return [user];\n * }\n * }\n * ```\n * > The user instance will be forwarded to the next middleware and to your decorated method.\n *\n * Then:\n *\n * ```typescript\n * import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from \"@tsed/socketio\";\n * import {UserConverterSocketMiddleware} from \"../middlewares\";\n * import {User} from \"../models/User\";\n *\n * @SocketService(\"/my-namespace\")\n * @SocketUseBefore(UserConverterSocketMiddleware) // global version\n * export class MySocketService {\n *\n * @Input(\"eventName\")\n * @Emit(\"responseEventName\") // or Broadcast or BroadcastOthers\n * @SocketUseBefore(UserConverterSocketMiddleware)\n * async myMethod(@Args(0) user: User) {\n *\n * console.log(user);\n *\n * return user;\n * }\n * }\n * ```\n *\n * @returns {(target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void}\n * @decorator\n * @experimental\n * @param middlewares\n */\nexport function SocketUseBefore(...middlewares: Type<any>[]) {\n return (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => {\n if (propertyKey) {\n Store.from(target).merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n useBefore: middlewares\n }\n }\n });\n } else {\n Store.from(target).merge(\"socketIO\", {\n useBefore: middlewares\n });\n }\n };\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from "./SocketIOModule";
|
|
2
|
+
// interfaces
|
|
3
|
+
export * from "./interfaces";
|
|
4
|
+
export * from "./class/SocketProviderMetadata";
|
|
5
|
+
// decorators
|
|
6
|
+
export * from "./decorators/input";
|
|
7
|
+
export * from "./decorators/args";
|
|
8
|
+
export * from "./decorators/io";
|
|
9
|
+
export * from "./decorators/nsp";
|
|
10
|
+
export * from "./decorators/emit";
|
|
11
|
+
export * from "./decorators/broadcast";
|
|
12
|
+
export * from "./decorators/broadcastOthers";
|
|
13
|
+
export * from "./decorators/inputAndEmit";
|
|
14
|
+
export * from "./decorators/inputAndBroadcast";
|
|
15
|
+
export * from "./decorators/inputAndBroadcastOthers";
|
|
16
|
+
export * from "./decorators/socket";
|
|
17
|
+
export * from "./decorators/socketErr";
|
|
18
|
+
export * from "./decorators/socketFilter";
|
|
19
|
+
export * from "./decorators/socketMiddleware";
|
|
20
|
+
export * from "./decorators/socketMiddlewareError";
|
|
21
|
+
export * from "./decorators/socketService";
|
|
22
|
+
export * from "./decorators/socketSession";
|
|
23
|
+
export * from "./decorators/socketUseAfter";
|
|
24
|
+
export * from "./decorators/socketUseBefore";
|
|
25
|
+
export * from "./decorators/socketEventName";
|
|
26
|
+
// service
|
|
27
|
+
export * from "./services/SocketIOServer";
|
|
28
|
+
export * from "./services/SocketIOService";
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,aAAa;AACb,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAE/C,aAAa;AACb,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAE7C,UAAU;AACV,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./SocketIOModule\";\n\n// interfaces\nexport * from \"./interfaces\";\nexport * from \"./class/SocketProviderMetadata\";\n\n// decorators\nexport * from \"./decorators/input\";\nexport * from \"./decorators/args\";\nexport * from \"./decorators/io\";\nexport * from \"./decorators/nsp\";\nexport * from \"./decorators/emit\";\nexport * from \"./decorators/broadcast\";\nexport * from \"./decorators/broadcastOthers\";\nexport * from \"./decorators/inputAndEmit\";\nexport * from \"./decorators/inputAndBroadcast\";\nexport * from \"./decorators/inputAndBroadcastOthers\";\nexport * from \"./decorators/socket\";\nexport * from \"./decorators/socketErr\";\nexport * from \"./decorators/socketFilter\";\nexport * from \"./decorators/socketMiddleware\";\nexport * from \"./decorators/socketMiddlewareError\";\nexport * from \"./decorators/socketService\";\nexport * from \"./decorators/socketSession\";\nexport * from \"./decorators/socketUseAfter\";\nexport * from \"./decorators/socketUseBefore\";\nexport * from \"./decorators/socketEventName\";\n\n// service\nexport * from \"./services/SocketIOServer\";\nexport * from \"./services/SocketIOService\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnNamespaceInit.js","sourceRoot":"","sources":["../../../src/interfaces/OnNamespaceInit.ts"],"names":[],"mappings":"","sourcesContent":["import {Namespace} from \"socket.io\";\n\n/**\n *\n */\nexport interface OnNamespaceInit {\n $onNamespaceInit(nsp: Namespace): void;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
export var SocketFilters;
|
|
5
|
+
(function (SocketFilters) {
|
|
6
|
+
SocketFilters["ARGS"] = "args";
|
|
7
|
+
SocketFilters["SOCKET"] = "socket";
|
|
8
|
+
SocketFilters["EVENT_NAME"] = "eventName";
|
|
9
|
+
SocketFilters["NSP"] = "nsp";
|
|
10
|
+
SocketFilters["SESSION"] = "session";
|
|
11
|
+
SocketFilters["ERR"] = "error";
|
|
12
|
+
})(SocketFilters || (SocketFilters = {}));
|
|
13
|
+
//# sourceMappingURL=SocketFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketFilters.js","sourceRoot":"","sources":["../../../src/interfaces/SocketFilters.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,yCAAwB,CAAA;IACxB,4BAAW,CAAA;IACX,oCAAmB,CAAA;IACnB,8BAAa,CAAA;AACf,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB","sourcesContent":["/**\n * @ignore\n */\nexport enum SocketFilters {\n ARGS = \"args\",\n SOCKET = \"socket\",\n EVENT_NAME = \"eventName\",\n NSP = \"nsp\",\n SESSION = \"session\",\n ERR = \"error\"\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketHandlerMetadata.js","sourceRoot":"","sources":["../../../src/interfaces/SocketHandlerMetadata.ts"],"names":[],"mappings":"","sourcesContent":["import {SocketParamMetadata} from \"./SocketParamMetadata\";\nimport {SocketReturnsTypes} from \"./SocketReturnsTypes\";\n\n/**\n *\n */\nexport interface SocketHandlerMetadata {\n eventName?: string;\n methodClassName: string;\n useBefore?: any[];\n useAfter?: any[];\n parameters?: {[key: number]: SocketParamMetadata};\n returns?: {\n type: SocketReturnsTypes;\n eventName: string;\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketInjectableNsp.js","sourceRoot":"","sources":["../../../src/interfaces/SocketInjectableNsp.ts"],"names":[],"mappings":"","sourcesContent":["export interface SocketInjectableNsp {\n propertyKey: string;\n nsp?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketParamMetadata.js","sourceRoot":"","sources":["../../../src/interfaces/SocketParamMetadata.ts"],"names":[],"mappings":"","sourcesContent":["import {MetadataTypes} from \"@tsed/core\";\nimport {SocketFilters} from \"./SocketFilters\";\n\nexport interface SocketParamMetadata extends Partial<MetadataTypes> {\n filter: SocketFilters;\n mapIndex?: number;\n useConverter?: boolean;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
export var SocketProviderTypes;
|
|
5
|
+
(function (SocketProviderTypes) {
|
|
6
|
+
SocketProviderTypes["SERVICE"] = "service";
|
|
7
|
+
SocketProviderTypes["MIDDLEWARE"] = "middleware";
|
|
8
|
+
})(SocketProviderTypes || (SocketProviderTypes = {}));
|
|
9
|
+
//# sourceMappingURL=SocketProviderTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketProviderTypes.js","sourceRoot":"","sources":["../../../src/interfaces/SocketProviderTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,gDAAyB,CAAA;AAC3B,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B","sourcesContent":["/**\n *\n */\nexport enum SocketProviderTypes {\n SERVICE = \"service\",\n MIDDLEWARE = \"middleware\"\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
export var SocketReturnsTypes;
|
|
5
|
+
(function (SocketReturnsTypes) {
|
|
6
|
+
SocketReturnsTypes["BROADCAST"] = "broadcast";
|
|
7
|
+
SocketReturnsTypes["BROADCAST_OTHERS"] = "broadcastOthers";
|
|
8
|
+
SocketReturnsTypes["EMIT"] = "emit";
|
|
9
|
+
})(SocketReturnsTypes || (SocketReturnsTypes = {}));
|
|
10
|
+
//# sourceMappingURL=SocketReturnsTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketReturnsTypes.js","sourceRoot":"","sources":["../../../src/interfaces/SocketReturnsTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,6CAAuB,CAAA;IACvB,0DAAoC,CAAA;IACpC,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B","sourcesContent":["/**\n * @ignore\n */\nexport enum SocketReturnsTypes {\n BROADCAST = \"broadcast\",\n BROADCAST_OTHERS = \"broadcastOthers\",\n EMIT = \"emit\"\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./SocketHandlerMetadata";
|
|
2
|
+
export * from "./SocketParamMetadata";
|
|
3
|
+
export * from "./SocketProviderTypes";
|
|
4
|
+
export * from "./OnNamespaceInit";
|
|
5
|
+
export * from "./SocketFilters";
|
|
6
|
+
export * from "./SocketReturnsTypes";
|
|
7
|
+
export * from "./SocketInjectableNsp";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAUA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC","sourcesContent":["import SocketIO from \"socket.io\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n socketIO: Partial<SocketIO.ServerOptions>;\n }\n }\n}\n\nexport * from \"./SocketHandlerMetadata\";\nexport * from \"./SocketParamMetadata\";\nexport * from \"./SocketProviderTypes\";\nexport * from \"./OnNamespaceInit\";\nexport * from \"./SocketFilters\";\nexport * from \"./SocketReturnsTypes\";\nexport * from \"./SocketInjectableNsp\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @type {Map<any, any>}
|
|
4
|
+
*/
|
|
5
|
+
const SESSIONS = new Map();
|
|
6
|
+
export function getNspSession(namespace = "/") {
|
|
7
|
+
if (!SESSIONS.has(namespace)) {
|
|
8
|
+
SESSIONS.set(namespace, new Map());
|
|
9
|
+
}
|
|
10
|
+
return SESSIONS.get(namespace);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=NspSessionRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NspSessionRegistry.js","sourceRoot":"","sources":["../../../src/registries/NspSessionRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,QAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;AAE1D,MAAM,UAAU,aAAa,CAAC,YAAoB,GAAG;IACnD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QAC5B,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;KACpC;IAED,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["/**\n *\n * @type {Map<any, any>}\n */\nconst SESSIONS: Map<string, Map<string, any>> = new Map();\n\nexport function getNspSession(namespace: string = \"/\") {\n if (!SESSIONS.has(namespace)) {\n SESSIONS.set(namespace, new Map());\n }\n\n return SESSIONS.get(namespace);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { registerProvider } from "@tsed/common";
|
|
2
|
+
import { Server } from "socket.io";
|
|
3
|
+
// tslint:disable-next-line: variable-name
|
|
4
|
+
export const SocketIOServer = Server;
|
|
5
|
+
export { Server };
|
|
6
|
+
registerProvider({
|
|
7
|
+
provide: Server,
|
|
8
|
+
useFactory() {
|
|
9
|
+
return new Server();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=SocketIOServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketIOServer.js","sourceRoot":"","sources":["../../../src/services/SocketIOServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AAIjC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAErC,OAAO,EAAC,MAAM,EAAC,CAAC;AAEhB,gBAAgB,CAAC;IACf,OAAO,EAAE,MAAM;IACf,UAAU;QACR,OAAO,IAAI,MAAM,EAAE,CAAC;IACtB,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {registerProvider} from \"@tsed/common\";\nimport {Server} from \"socket.io\";\n\nexport type SocketIOServer = Server;\n\n// tslint:disable-next-line: variable-name\nexport const SocketIOServer = Server;\n\nexport {Server};\n\nregisterProvider({\n provide: Server,\n useFactory() {\n return new Server();\n }\n});\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { ConverterService, InjectorService, Service } from "@tsed/common";
|
|
3
|
+
import SocketIO from "socket.io"; // tslint:disable-line: no-unused-variable
|
|
4
|
+
import { SocketHandlersBuilder } from "../class/SocketHandlersBuilder";
|
|
5
|
+
import { SocketProviderMetadata } from "../class/SocketProviderMetadata";
|
|
6
|
+
import { IO } from "../decorators/io";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
let SocketIOService = class SocketIOService {
|
|
11
|
+
constructor(injector, io, converterService) {
|
|
12
|
+
this.injector = injector;
|
|
13
|
+
this.io = io;
|
|
14
|
+
this.converterService = converterService;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @type {Map<any, any>}
|
|
18
|
+
*/
|
|
19
|
+
this.namespaces = new Map();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {string} namespace
|
|
24
|
+
* @returns {SocketIO.Namespace}
|
|
25
|
+
*/
|
|
26
|
+
getNsp(namespace = "/") {
|
|
27
|
+
if (!this.namespaces.has(namespace)) {
|
|
28
|
+
const conf = { nsp: this.io.of(namespace), instances: [] };
|
|
29
|
+
this.namespaces.set(namespace, conf);
|
|
30
|
+
conf.nsp.on("connection", (socket) => {
|
|
31
|
+
conf.instances.forEach((builder) => {
|
|
32
|
+
builder.onConnection(socket, conf.nsp);
|
|
33
|
+
});
|
|
34
|
+
socket.on("disconnect", () => {
|
|
35
|
+
conf.instances.forEach((builder) => {
|
|
36
|
+
builder.onDisconnect(socket, conf.nsp);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return this.namespaces.get(namespace);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {Provider<any>} provider
|
|
46
|
+
*/
|
|
47
|
+
addSocketProvider(provider) {
|
|
48
|
+
const wsConfig = new SocketProviderMetadata(provider.store.get("socketIO"));
|
|
49
|
+
const nspConfig = this.getNsp(wsConfig.namespace);
|
|
50
|
+
const nsps = new Map();
|
|
51
|
+
this.namespaces.forEach((value, nsp) => {
|
|
52
|
+
nsps.set(nsp, value.nsp);
|
|
53
|
+
});
|
|
54
|
+
const builder = new SocketHandlersBuilder(provider, this.converterService, this.injector).build(nsps);
|
|
55
|
+
nspConfig.instances.push(builder);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
SocketIOService = __decorate([
|
|
59
|
+
Service(),
|
|
60
|
+
__param(1, IO),
|
|
61
|
+
__metadata("design:paramtypes", [InjectorService, SocketIO.Server, ConverterService])
|
|
62
|
+
], SocketIOService);
|
|
63
|
+
export { SocketIOService };
|
|
64
|
+
//# sourceMappingURL=SocketIOService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketIOService.js","sourceRoot":"","sources":["../../../src/services/SocketIOService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAY,OAAO,EAAC,MAAM,cAAc,CAAC;AAClF,OAAO,QAAQ,MAAM,WAAW,CAAC,CAAC,0CAA0C;AAC5E,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAC,EAAE,EAAC,MAAM,kBAAkB,CAAC;AAEpC;;GAEG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAO1B,YAAoB,QAAyB,EAAc,EAAmB,EAAU,gBAAkC;QAAtG,aAAQ,GAAR,QAAQ,CAAiB;QAAc,OAAE,GAAF,EAAE,CAAiB;QAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;QAN1H;;;WAGG;QACK,eAAU,GAA2D,IAAI,GAAG,EAAE,CAAC;IAEsC,CAAC;IAE9H;;;;OAIG;IACI,MAAM,CAAC,YAAoB,GAAG;QACnC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YACnC,MAAM,IAAI,GAAG,EAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE,EAAC,CAAC;YAEzD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE;gBACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAA8B,EAAE,EAAE;oBACxD,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;gBAEH,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;oBAC3B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAA8B,EAAE,EAAE;wBACxD,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;oBACzC,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,QAAuB;QAC9C,MAAM,QAAQ,GAA2B,IAAI,sBAAsB,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;QAEpG,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QAEvB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACrC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEtG,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAtDY,eAAe;IAD3B,OAAO,EAAE;IAQwC,WAAA,EAAE,CAAA;qCAApB,eAAe,EAAkB,QAAQ,CAAC,MAAM,EAA4B,gBAAgB;GAP/G,eAAe,CAsD3B;SAtDY,eAAe","sourcesContent":["import {ConverterService, InjectorService, Provider, Service} from \"@tsed/common\";\nimport SocketIO from \"socket.io\"; // tslint:disable-line: no-unused-variable\nimport {SocketHandlersBuilder} from \"../class/SocketHandlersBuilder\";\nimport {SocketProviderMetadata} from \"../class/SocketProviderMetadata\";\nimport {IO} from \"../decorators/io\";\n\n/**\n *\n */\n@Service()\nexport class SocketIOService {\n /**\n *\n * @type {Map<any, any>}\n */\n private namespaces: Map<string, {nsp: SocketIO.Namespace; instances: any}> = new Map();\n\n constructor(private injector: InjectorService, @IO private io: SocketIO.Server, private converterService: ConverterService) {}\n\n /**\n *\n * @param {string} namespace\n * @returns {SocketIO.Namespace}\n */\n public getNsp(namespace: string = \"/\"): {nsp: SocketIO.Namespace; instances: any[]} {\n if (!this.namespaces.has(namespace)) {\n const conf = {nsp: this.io.of(namespace), instances: []};\n\n this.namespaces.set(namespace, conf);\n\n conf.nsp.on(\"connection\", (socket) => {\n conf.instances.forEach((builder: SocketHandlersBuilder) => {\n builder.onConnection(socket, conf.nsp);\n });\n\n socket.on(\"disconnect\", () => {\n conf.instances.forEach((builder: SocketHandlersBuilder) => {\n builder.onDisconnect(socket, conf.nsp);\n });\n });\n });\n }\n\n return this.namespaces.get(namespace)!;\n }\n\n /**\n *\n * @param {Provider<any>} provider\n */\n public addSocketProvider(provider: Provider<any>) {\n const wsConfig: SocketProviderMetadata = new SocketProviderMetadata(provider.store.get(\"socketIO\"));\n\n const nspConfig = this.getNsp(wsConfig.namespace);\n const nsps = new Map();\n\n this.namespaces.forEach((value, nsp) => {\n nsps.set(nsp, value.nsp);\n });\n\n const builder = new SocketHandlersBuilder(provider, this.converterService, this.injector).build(nsps);\n\n nspConfig.instances.push(builder);\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AfterListen, HttpServer, HttpsServer, InjectorService, OnDestroy, Provider } from "@tsed/common";
|
|
2
|
+
import { Server, ServerOptions } from "socket.io";
|
|
3
|
+
import { SocketIOService } from "./services/SocketIOService";
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare class SocketIOModule implements AfterListen, OnDestroy {
|
|
8
|
+
private injector;
|
|
9
|
+
private httpServer;
|
|
10
|
+
private httpsServer;
|
|
11
|
+
private io;
|
|
12
|
+
private socketIOService;
|
|
13
|
+
disableRoutesSummary: boolean;
|
|
14
|
+
settings: Partial<ServerOptions>;
|
|
15
|
+
httpPort: string | number;
|
|
16
|
+
httpsPort: string | number;
|
|
17
|
+
constructor(injector: InjectorService, httpServer: HttpServer, httpsServer: HttpsServer, io: Server, socketIOService: SocketIOService);
|
|
18
|
+
$afterListen(): Promise<void>;
|
|
19
|
+
$onDestroy(): void;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @returns {Provider<any>[]}
|
|
23
|
+
*/
|
|
24
|
+
protected getWebsocketServices(): Provider<any>[];
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
protected printSocketEvents(): void;
|
|
29
|
+
}
|