@tsed/socketio 6.91.0 → 6.92.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/cjs/SocketIOModule.d.ts +10 -11
- package/lib/cjs/SocketIOModule.js +22 -19
- package/lib/cjs/SocketIOModule.js.map +1 -1
- package/lib/cjs/decorators/io.d.ts +1 -0
- package/lib/cjs/decorators/io.js +4 -18
- package/lib/cjs/decorators/io.js.map +1 -1
- package/lib/esm/SocketIOModule.js +24 -21
- package/lib/esm/SocketIOModule.js.map +1 -1
- package/lib/esm/decorators/io.js +4 -18
- package/lib/esm/decorators/io.js.map +1 -1
- package/lib/types/SocketIOModule.d.ts +10 -11
- package/lib/types/decorators/io.d.ts +1 -0
- package/package.json +13 -13
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AfterListen, InjectorService, OnDestroy, Provider } from "@tsed/common";
|
|
3
|
+
import { ServerOptions } from "socket.io";
|
|
4
|
+
import Http from "http";
|
|
5
|
+
import Https from "https";
|
|
4
6
|
/**
|
|
5
7
|
* @ignore
|
|
6
8
|
*/
|
|
7
9
|
export declare class SocketIOModule implements AfterListen, OnDestroy {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
protected disableRoutesSummary: boolean;
|
|
11
|
+
protected settings: Partial<ServerOptions>;
|
|
12
|
+
protected injector: InjectorService;
|
|
13
|
+
protected httpServer: Http.Server | null;
|
|
14
|
+
protected httpsServer: Https.Server | null;
|
|
11
15
|
private io;
|
|
12
16
|
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
17
|
$afterListen(): Promise<void>;
|
|
19
18
|
$onDestroy(): void;
|
|
20
19
|
/**
|
|
@@ -9,22 +9,18 @@ const SocketProviderMetadata_1 = require("./class/SocketProviderMetadata"); // t
|
|
|
9
9
|
const constants_1 = require("./constants");
|
|
10
10
|
const io_1 = require("./decorators/io");
|
|
11
11
|
const SocketIOService_1 = require("./services/SocketIOService");
|
|
12
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
13
|
+
const https_1 = (0, tslib_1.__importDefault)(require("https"));
|
|
14
|
+
const di_1 = require("@tsed/di");
|
|
12
15
|
/**
|
|
13
16
|
* @ignore
|
|
14
17
|
*/
|
|
15
18
|
let SocketIOModule = class SocketIOModule {
|
|
16
|
-
constructor(injector, httpServer, httpsServer, io, socketIOService) {
|
|
17
|
-
this.injector = injector;
|
|
18
|
-
this.httpServer = httpServer;
|
|
19
|
-
this.httpsServer = httpsServer;
|
|
20
|
-
this.io = io;
|
|
21
|
-
this.socketIOService = socketIOService;
|
|
22
|
-
}
|
|
23
19
|
$afterListen() {
|
|
24
|
-
if (this.
|
|
20
|
+
if (this.httpServer) {
|
|
25
21
|
this.io.attach(this.httpServer, { ...this.settings });
|
|
26
22
|
}
|
|
27
|
-
if (this.
|
|
23
|
+
if (this.httpsServer) {
|
|
28
24
|
this.io.attach(this.httpsServer, { ...this.settings });
|
|
29
25
|
}
|
|
30
26
|
if (this.settings.adapter) {
|
|
@@ -89,20 +85,27 @@ let SocketIOModule = class SocketIOModule {
|
|
|
89
85
|
(0, tslib_1.__metadata)("design:type", Object)
|
|
90
86
|
], SocketIOModule.prototype, "settings", void 0);
|
|
91
87
|
(0, tslib_1.__decorate)([
|
|
92
|
-
(0,
|
|
88
|
+
(0, di_1.Inject)(),
|
|
89
|
+
(0, tslib_1.__metadata)("design:type", common_1.InjectorService)
|
|
90
|
+
], SocketIOModule.prototype, "injector", void 0);
|
|
91
|
+
(0, tslib_1.__decorate)([
|
|
92
|
+
(0, di_1.Inject)(http_1.default.Server),
|
|
93
93
|
(0, tslib_1.__metadata)("design:type", Object)
|
|
94
|
-
], SocketIOModule.prototype, "
|
|
94
|
+
], SocketIOModule.prototype, "httpServer", void 0);
|
|
95
95
|
(0, tslib_1.__decorate)([
|
|
96
|
-
(0,
|
|
96
|
+
(0, di_1.Inject)(https_1.default.Server),
|
|
97
97
|
(0, tslib_1.__metadata)("design:type", Object)
|
|
98
|
-
], SocketIOModule.prototype, "
|
|
98
|
+
], SocketIOModule.prototype, "httpsServer", void 0);
|
|
99
|
+
(0, tslib_1.__decorate)([
|
|
100
|
+
(0, io_1.IO)(),
|
|
101
|
+
(0, tslib_1.__metadata)("design:type", socket_io_1.Server)
|
|
102
|
+
], SocketIOModule.prototype, "io", void 0);
|
|
103
|
+
(0, tslib_1.__decorate)([
|
|
104
|
+
(0, di_1.Inject)(),
|
|
105
|
+
(0, tslib_1.__metadata)("design:type", SocketIOService_1.SocketIOService)
|
|
106
|
+
], SocketIOModule.prototype, "socketIOService", void 0);
|
|
99
107
|
SocketIOModule = (0, tslib_1.__decorate)([
|
|
100
|
-
(0, common_1.Module)()
|
|
101
|
-
(0, tslib_1.__param)(1, (0, common_1.Inject)(common_1.HttpServer)),
|
|
102
|
-
(0, tslib_1.__param)(2, (0, common_1.Inject)(common_1.HttpsServer)),
|
|
103
|
-
(0, tslib_1.__param)(3, io_1.IO),
|
|
104
|
-
(0, tslib_1.__metadata)("design:paramtypes", [common_1.InjectorService, Object, Object, socket_io_1.Server,
|
|
105
|
-
SocketIOService_1.SocketIOService])
|
|
108
|
+
(0, common_1.Module)()
|
|
106
109
|
], SocketIOModule);
|
|
107
110
|
exports.SocketIOModule = SocketIOModule;
|
|
108
111
|
//# sourceMappingURL=SocketIOModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocketIOModule.js","sourceRoot":"","sources":["../../src/SocketIOModule.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"SocketIOModule.js","s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c;aACrB;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAE7C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AA7FC;IADC,IAAA,iBAAQ,EAAC,6BAA6B,EAAE,KAAK,CAAC;;4DACP;AAGxC;IADC,IAAA,iBAAQ,EAAC,UAAU,EAAE,EAAE,CAAC;;gDACkB;AAG3C;IADC,IAAA,WAAM,GAAE;2CACW,wBAAe;gDAAC;AAGpC;IADC,IAAA,WAAM,EAAC,cAAI,CAAC,MAAM,CAAC;;kDACqB;AAGzC;IADC,IAAA,WAAM,EAAC,eAAK,CAAC,MAAM,CAAC;;mDACsB;AAG3C;IADC,IAAA,OAAE,GAAE;2CACO,kBAAM;0CAAC;AAGnB;IADC,IAAA,WAAM,GAAE;2CACgB,iCAAe;uDAAC;AApB9B,cAAc;IAD1B,IAAA,eAAM,GAAE;GACI,cAAc,CA+F1B;AA/FY,wCAAc","sourcesContent":["import {$log, AfterListen, Constant, InjectorService, Module, OnDestroy, Provider} from \"@tsed/common\";\nimport {catchError, nameOf} from \"@tsed/core\";\nimport {Server, ServerOptions} from \"socket.io\";\nimport {SocketProviderMetadata} from \"./class/SocketProviderMetadata\"; // tslint:disable-line: no-unused-variable\nimport {PROVIDER_TYPE_SOCKET_SERVICE} from \"./constants\";\nimport {IO} from \"./decorators/io\";\nimport {SocketIOService} from \"./services/SocketIOService\";\nimport Http from \"http\";\nimport Https from \"https\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @ignore\n */\n@Module()\nexport class SocketIOModule implements AfterListen, OnDestroy {\n @Constant(\"logger.disableRoutesSummary\", false)\n protected disableRoutesSummary: boolean;\n\n @Constant(\"socketIO\", {})\n protected settings: Partial<ServerOptions>;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject(Http.Server)\n protected httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n protected httpsServer: Https.Server | null;\n\n @IO()\n private io: Server;\n\n @Inject()\n private socketIOService: SocketIOService;\n\n $afterListen() {\n if (this.httpServer) {\n this.io.attach(this.httpServer, {...this.settings});\n }\n\n if (this.httpsServer) {\n this.io.attach(this.httpsServer, {...this.settings});\n }\n\n if (this.settings.adapter) {\n this.io.adapter(this.settings.adapter);\n }\n\n this.getWebsocketServices().forEach((provider) => this.socketIOService.addSocketProvider(provider));\n\n if (!this.disableRoutesSummary) {\n this.printSocketEvents();\n }\n\n return this.injector.emit(\"$afterSocketListen\");\n }\n\n $onDestroy() {\n catchError(() => this.io.close());\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getWebsocketServices(): Provider<any>[] {\n return Array.from(this.injector.getProviders(PROVIDER_TYPE_SOCKET_SERVICE));\n }\n\n /**\n *\n */\n protected printSocketEvents() {\n const list = this.getWebsocketServices().reduce((acc: any[], provider) => {\n const socketProvider = new SocketProviderMetadata(provider.store.get(\"socketIO\"));\n\n if (socketProvider.namespace) {\n socketProvider.getHandlers().forEach((handler) => {\n acc.push({\n namespace: socketProvider.namespace,\n inputEvent: handler.eventName,\n outputEvent: (handler.returns && handler.returns.eventName) || \"\",\n outputType: (handler.returns && handler.returns.type) || \"\",\n name: `${nameOf(provider.useClass)}.${handler.methodClassName}`\n });\n });\n }\n\n return acc;\n }, []);\n\n this.injector.logger.info(\"Socket events mounted:\");\n\n const str = $log.drawTable(list, {\n padding: 1,\n header: {\n namespace: \"Namespace\",\n inputEvent: \"Input event\",\n outputEvent: \"Output event\",\n outputType: \"Output type\",\n name: \"Class method\"\n }\n });\n\n this.injector.logger.info(\"\\n\" + str.trim());\n\n this.injector.logger.info(\"Socket server started...\");\n }\n}\n"]}
|
package/lib/cjs/decorators/io.js
CHANGED
|
@@ -3,25 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IO = void 0;
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
5
|
const SocketIOServer_1 = require("../services/SocketIOServer");
|
|
6
|
-
/**
|
|
7
|
-
* Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.
|
|
8
|
-
*
|
|
9
|
-
* ### Example
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* @SocketService("/nsp")
|
|
13
|
-
* export class MyWS {
|
|
14
|
-
* constructor(@IO private io: Server) {}
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param target
|
|
19
|
-
* @param targetKey
|
|
20
|
-
* @param descriptor
|
|
21
|
-
* @decorator
|
|
22
|
-
*/
|
|
23
6
|
function IO(target, targetKey, descriptor) {
|
|
24
|
-
|
|
7
|
+
if (target) {
|
|
8
|
+
return (0, common_1.Inject)(SocketIOServer_1.Server)(target, targetKey, descriptor);
|
|
9
|
+
}
|
|
10
|
+
return (0, common_1.Inject)(SocketIOServer_1.Server);
|
|
25
11
|
}
|
|
26
12
|
exports.IO = IO;
|
|
27
13
|
//# sourceMappingURL=io.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/decorators/io.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,+DAAkD;
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/decorators/io.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,+DAAkD;AAqBlD,SAAgB,EAAE,CAAC,MAAkB,EAAE,SAAkB,EAAE,UAAuD;IAChH,IAAI,MAAM,EAAE;QACV,OAAO,IAAA,eAAM,EAAC,uBAAM,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;KACtD;IACD,OAAO,IAAA,eAAM,EAAC,uBAAM,CAAC,CAAC;AACxB,CAAC;AALD,gBAKC","sourcesContent":["import {Inject} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport {Server} from \"../services/SocketIOServer\";\n\n/**\n * Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n * constructor(@IO private io: Server) {}\n * }\n * ```\n *\n * @param target\n * @param targetKey\n * @param descriptor\n * @decorator\n */\nexport function IO(): (...args: any[]) => any;\nexport function IO(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any;\nexport function IO(target?: Type<any>, targetKey?: string, descriptor?: TypedPropertyDescriptor<Function> | number): any {\n if (target) {\n return Inject(Server)(target, targetKey, descriptor);\n }\n return Inject(Server);\n}\n"]}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { __decorate, __metadata
|
|
2
|
-
import { $log, Constant,
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { $log, Constant, InjectorService, Module } from "@tsed/common";
|
|
3
3
|
import { catchError, nameOf } from "@tsed/core";
|
|
4
4
|
import { Server } from "socket.io";
|
|
5
5
|
import { SocketProviderMetadata } from "./class/SocketProviderMetadata"; // tslint:disable-line: no-unused-variable
|
|
6
6
|
import { PROVIDER_TYPE_SOCKET_SERVICE } from "./constants";
|
|
7
7
|
import { IO } from "./decorators/io";
|
|
8
8
|
import { SocketIOService } from "./services/SocketIOService";
|
|
9
|
+
import Http from "http";
|
|
10
|
+
import Https from "https";
|
|
11
|
+
import { Inject } from "@tsed/di";
|
|
9
12
|
/**
|
|
10
13
|
* @ignore
|
|
11
14
|
*/
|
|
12
15
|
let SocketIOModule = class SocketIOModule {
|
|
13
|
-
constructor(injector, httpServer, httpsServer, io, socketIOService) {
|
|
14
|
-
this.injector = injector;
|
|
15
|
-
this.httpServer = httpServer;
|
|
16
|
-
this.httpsServer = httpsServer;
|
|
17
|
-
this.io = io;
|
|
18
|
-
this.socketIOService = socketIOService;
|
|
19
|
-
}
|
|
20
16
|
$afterListen() {
|
|
21
|
-
if (this.
|
|
17
|
+
if (this.httpServer) {
|
|
22
18
|
this.io.attach(this.httpServer, { ...this.settings });
|
|
23
19
|
}
|
|
24
|
-
if (this.
|
|
20
|
+
if (this.httpsServer) {
|
|
25
21
|
this.io.attach(this.httpsServer, { ...this.settings });
|
|
26
22
|
}
|
|
27
23
|
if (this.settings.adapter) {
|
|
@@ -86,20 +82,27 @@ __decorate([
|
|
|
86
82
|
__metadata("design:type", Object)
|
|
87
83
|
], SocketIOModule.prototype, "settings", void 0);
|
|
88
84
|
__decorate([
|
|
89
|
-
|
|
85
|
+
Inject(),
|
|
86
|
+
__metadata("design:type", InjectorService)
|
|
87
|
+
], SocketIOModule.prototype, "injector", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
Inject(Http.Server),
|
|
90
90
|
__metadata("design:type", Object)
|
|
91
|
-
], SocketIOModule.prototype, "
|
|
91
|
+
], SocketIOModule.prototype, "httpServer", void 0);
|
|
92
92
|
__decorate([
|
|
93
|
-
|
|
93
|
+
Inject(Https.Server),
|
|
94
94
|
__metadata("design:type", Object)
|
|
95
|
-
], SocketIOModule.prototype, "
|
|
95
|
+
], SocketIOModule.prototype, "httpsServer", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
IO(),
|
|
98
|
+
__metadata("design:type", Server)
|
|
99
|
+
], SocketIOModule.prototype, "io", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
Inject(),
|
|
102
|
+
__metadata("design:type", SocketIOService)
|
|
103
|
+
], SocketIOModule.prototype, "socketIOService", void 0);
|
|
96
104
|
SocketIOModule = __decorate([
|
|
97
|
-
Module()
|
|
98
|
-
__param(1, Inject(HttpServer)),
|
|
99
|
-
__param(2, Inject(HttpsServer)),
|
|
100
|
-
__param(3, IO),
|
|
101
|
-
__metadata("design:paramtypes", [InjectorService, Object, Object, Server,
|
|
102
|
-
SocketIOService])
|
|
105
|
+
Module()
|
|
103
106
|
], SocketIOModule);
|
|
104
107
|
export { SocketIOModule };
|
|
105
108
|
//# sourceMappingURL=SocketIOModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocketIOModule.js","sourceRoot":"","sources":["../../src/SocketIOModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,IAAI,EAAe,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"SocketIOModule.js","sourceRoot":"","sources":["../../src/SocketIOModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,IAAI,EAAe,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAsB,MAAM,cAAc,CAAC;AACvG,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAC,MAAM,EAAgB,MAAM,WAAW,CAAC;AAChD,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC,CAAC,0CAA0C;AACjH,OAAO,EAAC,4BAA4B,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EAAC,EAAE,EAAC,MAAM,iBAAiB,CAAC;AACnC,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC;;GAEG;AAEH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAsBzB,YAAY;QACV,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAC,GAAG,IAAI,CAAC,QAAQ,EAAC,CAAC,CAAC;SACrD;QAED,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAC,GAAG,IAAI,CAAC,QAAQ,EAAC,CAAC,CAAC;SACtD;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC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;SA/FY,cAAc","sourcesContent":["import {$log, AfterListen, Constant, InjectorService, Module, OnDestroy, Provider} from \"@tsed/common\";\nimport {catchError, nameOf} from \"@tsed/core\";\nimport {Server, ServerOptions} from \"socket.io\";\nimport {SocketProviderMetadata} from \"./class/SocketProviderMetadata\"; // tslint:disable-line: no-unused-variable\nimport {PROVIDER_TYPE_SOCKET_SERVICE} from \"./constants\";\nimport {IO} from \"./decorators/io\";\nimport {SocketIOService} from \"./services/SocketIOService\";\nimport Http from \"http\";\nimport Https from \"https\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @ignore\n */\n@Module()\nexport class SocketIOModule implements AfterListen, OnDestroy {\n @Constant(\"logger.disableRoutesSummary\", false)\n protected disableRoutesSummary: boolean;\n\n @Constant(\"socketIO\", {})\n protected settings: Partial<ServerOptions>;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject(Http.Server)\n protected httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n protected httpsServer: Https.Server | null;\n\n @IO()\n private io: Server;\n\n @Inject()\n private socketIOService: SocketIOService;\n\n $afterListen() {\n if (this.httpServer) {\n this.io.attach(this.httpServer, {...this.settings});\n }\n\n if (this.httpsServer) {\n this.io.attach(this.httpsServer, {...this.settings});\n }\n\n if (this.settings.adapter) {\n this.io.adapter(this.settings.adapter);\n }\n\n this.getWebsocketServices().forEach((provider) => this.socketIOService.addSocketProvider(provider));\n\n if (!this.disableRoutesSummary) {\n this.printSocketEvents();\n }\n\n return this.injector.emit(\"$afterSocketListen\");\n }\n\n $onDestroy() {\n catchError(() => this.io.close());\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getWebsocketServices(): Provider<any>[] {\n return Array.from(this.injector.getProviders(PROVIDER_TYPE_SOCKET_SERVICE));\n }\n\n /**\n *\n */\n protected printSocketEvents() {\n const list = this.getWebsocketServices().reduce((acc: any[], provider) => {\n const socketProvider = new SocketProviderMetadata(provider.store.get(\"socketIO\"));\n\n if (socketProvider.namespace) {\n socketProvider.getHandlers().forEach((handler) => {\n acc.push({\n namespace: socketProvider.namespace,\n inputEvent: handler.eventName,\n outputEvent: (handler.returns && handler.returns.eventName) || \"\",\n outputType: (handler.returns && handler.returns.type) || \"\",\n name: `${nameOf(provider.useClass)}.${handler.methodClassName}`\n });\n });\n }\n\n return acc;\n }, []);\n\n this.injector.logger.info(\"Socket events mounted:\");\n\n const str = $log.drawTable(list, {\n padding: 1,\n header: {\n namespace: \"Namespace\",\n inputEvent: \"Input event\",\n outputEvent: \"Output event\",\n outputType: \"Output type\",\n name: \"Class method\"\n }\n });\n\n this.injector.logger.info(\"\\n\" + str.trim());\n\n this.injector.logger.info(\"Socket server started...\");\n }\n}\n"]}
|
package/lib/esm/decorators/io.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { Inject } from "@tsed/common";
|
|
2
2
|
import { Server } from "../services/SocketIOServer";
|
|
3
|
-
/**
|
|
4
|
-
* Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.
|
|
5
|
-
*
|
|
6
|
-
* ### Example
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @SocketService("/nsp")
|
|
10
|
-
* export class MyWS {
|
|
11
|
-
* constructor(@IO private io: Server) {}
|
|
12
|
-
* }
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param target
|
|
16
|
-
* @param targetKey
|
|
17
|
-
* @param descriptor
|
|
18
|
-
* @decorator
|
|
19
|
-
*/
|
|
20
3
|
export function IO(target, targetKey, descriptor) {
|
|
21
|
-
|
|
4
|
+
if (target) {
|
|
5
|
+
return Inject(Server)(target, targetKey, descriptor);
|
|
6
|
+
}
|
|
7
|
+
return Inject(Server);
|
|
22
8
|
}
|
|
23
9
|
//# sourceMappingURL=io.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/decorators/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/decorators/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAqBlD,MAAM,UAAU,EAAE,CAAC,MAAkB,EAAE,SAAkB,EAAE,UAAuD;IAChH,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;KACtD;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import {Inject} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport {Server} from \"../services/SocketIOServer\";\n\n/**\n * Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n * constructor(@IO private io: Server) {}\n * }\n * ```\n *\n * @param target\n * @param targetKey\n * @param descriptor\n * @decorator\n */\nexport function IO(): (...args: any[]) => any;\nexport function IO(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any;\nexport function IO(target?: Type<any>, targetKey?: string, descriptor?: TypedPropertyDescriptor<Function> | number): any {\n if (target) {\n return Inject(Server)(target, targetKey, descriptor);\n }\n return Inject(Server);\n}\n"]}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AfterListen, InjectorService, OnDestroy, Provider } from "@tsed/common";
|
|
3
|
+
import { ServerOptions } from "socket.io";
|
|
4
|
+
import Http from "http";
|
|
5
|
+
import Https from "https";
|
|
4
6
|
/**
|
|
5
7
|
* @ignore
|
|
6
8
|
*/
|
|
7
9
|
export declare class SocketIOModule implements AfterListen, OnDestroy {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
protected disableRoutesSummary: boolean;
|
|
11
|
+
protected settings: Partial<ServerOptions>;
|
|
12
|
+
protected injector: InjectorService;
|
|
13
|
+
protected httpServer: Http.Server | null;
|
|
14
|
+
protected httpsServer: Https.Server | null;
|
|
11
15
|
private io;
|
|
12
16
|
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
17
|
$afterListen(): Promise<void>;
|
|
19
18
|
$onDestroy(): void;
|
|
20
19
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/socketio",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.92.0",
|
|
4
4
|
"description": "Socket.io package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -30,24 +30,24 @@
|
|
|
30
30
|
"tslib": "2.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tsed/common": "6.
|
|
34
|
-
"@tsed/core": "6.
|
|
35
|
-
"@tsed/di": "6.
|
|
36
|
-
"@tsed/json-mapper": "6.
|
|
37
|
-
"@tsed/openspec": "6.
|
|
38
|
-
"@tsed/schema": "6.
|
|
33
|
+
"@tsed/common": "6.92.0",
|
|
34
|
+
"@tsed/core": "6.92.0",
|
|
35
|
+
"@tsed/di": "6.92.0",
|
|
36
|
+
"@tsed/json-mapper": "6.92.0",
|
|
37
|
+
"@tsed/openspec": "6.92.0",
|
|
38
|
+
"@tsed/schema": "6.92.0",
|
|
39
39
|
"express": "^4.17.1",
|
|
40
40
|
"socket.io": "4.1.2",
|
|
41
41
|
"socket.io-client": "^4.1.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@tsed/common": "^6.
|
|
45
|
-
"@tsed/core": "^6.
|
|
46
|
-
"@tsed/di": "^6.
|
|
47
|
-
"@tsed/json-mapper": "^6.
|
|
44
|
+
"@tsed/common": "^6.92.0",
|
|
45
|
+
"@tsed/core": "^6.92.0",
|
|
46
|
+
"@tsed/di": "^6.92.0",
|
|
47
|
+
"@tsed/json-mapper": "^6.92.0",
|
|
48
48
|
"@tsed/logger": ">=6.0.0",
|
|
49
|
-
"@tsed/openspec": "^6.
|
|
50
|
-
"@tsed/schema": "^6.
|
|
49
|
+
"@tsed/openspec": "^6.92.0",
|
|
50
|
+
"@tsed/schema": "^6.92.0",
|
|
51
51
|
"socket.io": ">=4.0.0"
|
|
52
52
|
},
|
|
53
53
|
"repository": "https://github.com/tsedio/tsed",
|