@tsed/socketio-testing 7.0.0-beta.2 → 7.0.0-beta.20

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./services/SocketClientService"), exports);
4
+ tslib_1.__exportStar(require("./services/SocketClientService"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,8EAA+C","sourcesContent":["export * from \"./services/SocketClientService\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+C","sourcesContent":["export * from \"./services/SocketClientService\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -6,9 +6,9 @@ const common_1 = require("@tsed/common");
6
6
  const di_1 = require("@tsed/di");
7
7
  const socket_io_client_1 = require("socket.io-client");
8
8
  let SocketClientService = class SocketClientService {
9
- constructor() {
10
- this.clients = new Map();
11
- }
9
+ settings;
10
+ logger;
11
+ clients = new Map();
12
12
  async get(namespace = "/", path) {
13
13
  if (this.clients.has(namespace)) {
14
14
  return this.clients.get(namespace);
@@ -29,15 +29,15 @@ let SocketClientService = class SocketClientService {
29
29
  this.logger.debug("Socket.io clients closed...");
30
30
  }
31
31
  };
32
- (0, tslib_1.__decorate)([
32
+ tslib_1.__decorate([
33
33
  (0, di_1.Configuration)(),
34
- (0, tslib_1.__metadata)("design:type", Object)
34
+ tslib_1.__metadata("design:type", Object)
35
35
  ], SocketClientService.prototype, "settings", void 0);
36
- (0, tslib_1.__decorate)([
36
+ tslib_1.__decorate([
37
37
  (0, common_1.Inject)(),
38
- (0, tslib_1.__metadata)("design:type", common_1.Logger)
38
+ tslib_1.__metadata("design:type", common_1.Logger)
39
39
  ], SocketClientService.prototype, "logger", void 0);
40
- SocketClientService = (0, tslib_1.__decorate)([
40
+ SocketClientService = tslib_1.__decorate([
41
41
  (0, di_1.Injectable)()
42
42
  ], SocketClientService);
43
43
  exports.SocketClientService = SocketClientService;
@@ -1 +1 @@
1
- {"version":3,"file":"SocketClientService.js","sourceRoot":"","sources":["../../../src/services/SocketClientService.ts"],"names":[],"mappings":";;;;AAAA,yCAAuD;AACvD,iCAAmD;AACnD,uDAA4C;AAG5C,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAAhC;QAOU,YAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IA4BnD,CAAC;IA1BC,KAAK,CAAC,GAAG,CAAC,YAAoB,GAAG,EAAE,IAAa;QAC9C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;SACrC;QAED,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,UAAU,OAAO,IAAI,IAAI,GAAG,SAAS,EAAE,CAAC;QAEpD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,IAAA,qBAAE,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAEpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,OAAc,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAEnD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,UAAU;QACR,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AAjCC;IADC,IAAA,kBAAa,GAAE;;qDACgB;AAGhC;IADC,IAAA,eAAM,GAAE;2CACO,eAAM;mDAAC;AALZ,mBAAmB;IAD/B,IAAA,eAAU,GAAE;GACA,mBAAmB,CAmC/B;AAnCY,kDAAmB","sourcesContent":["import {Inject, Logger, OnDestroy} from \"@tsed/common\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {io, Socket} from \"socket.io-client\";\n\n@Injectable()\nexport class SocketClientService implements OnDestroy {\n @Configuration()\n private settings: Configuration;\n\n @Inject()\n private logger: Logger;\n\n private clients: Map<string, Socket> = new Map();\n\n async get(namespace: string = \"/\", path?: string): Promise<Socket> {\n if (this.clients.has(namespace)) {\n return this.clients.get(namespace)!;\n }\n\n const {address, port} = this.settings.getHttpPort();\n const uri = `http://${address}:${port}${namespace}`;\n\n this.logger.info(\"Bind Socket.io client on:\", uri);\n const client = io(uri, path ? {path} : undefined);\n\n this.clients.set(namespace, client);\n\n await new Promise((resolve) => {\n client.on(\"connect\", resolve as any);\n });\n\n this.logger.debug(\"Socket.io client connected...\");\n\n return client;\n }\n\n $onDestroy() {\n this.clients.forEach((client) => client.close());\n this.logger.debug(\"Socket.io clients closed...\");\n }\n}\n"]}
1
+ {"version":3,"file":"SocketClientService.js","sourceRoot":"","sources":["../../../src/services/SocketClientService.ts"],"names":[],"mappings":";;;;AAAA,yCAAuD;AACvD,iCAAmD;AACnD,uDAA4C;AAG5C,IAAa,mBAAmB,GAAhC,MAAa,mBA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eAAM,GAAE;sCACO,eAAM;mDAAC;AALZ,mBAAmB;IAD/B,IAAA,eAAU,GAAE;GACA,mBAAmB,CAmC/B;AAnCY,kDAAmB","sourcesContent":["import {Inject, Logger, OnDestroy} from \"@tsed/common\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {io, Socket} from \"socket.io-client\";\n\n@Injectable()\nexport class SocketClientService implements OnDestroy {\n @Configuration()\n private settings: Configuration;\n\n @Inject()\n private logger: Logger;\n\n private clients: Map<string, Socket> = new Map();\n\n async get(namespace: string = \"/\", path?: string): Promise<Socket> {\n if (this.clients.has(namespace)) {\n return this.clients.get(namespace)!;\n }\n\n const {address, port} = this.settings.getHttpPort();\n const uri = `http://${address}:${port}${namespace}`;\n\n this.logger.info(\"Bind Socket.io client on:\", uri);\n const client = io(uri, path ? {path} : undefined);\n\n this.clients.set(namespace, client);\n\n await new Promise((resolve) => {\n client.on(\"connect\", resolve as any);\n });\n\n this.logger.debug(\"Socket.io client connected...\");\n\n return client;\n }\n\n $onDestroy() {\n this.clients.forEach((client) => client.close());\n this.logger.debug(\"Socket.io clients closed...\");\n }\n}\n"]}
package/lib/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./services/SocketClientService";
1
+ export * from "./services/SocketClientService.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -3,9 +3,9 @@ import { Inject, Logger } from "@tsed/common";
3
3
  import { Configuration, Injectable } from "@tsed/di";
4
4
  import { io } from "socket.io-client";
5
5
  let SocketClientService = class SocketClientService {
6
- constructor() {
7
- this.clients = new Map();
8
- }
6
+ settings;
7
+ logger;
8
+ clients = new Map();
9
9
  async get(namespace = "/", path) {
10
10
  if (this.clients.has(namespace)) {
11
11
  return this.clients.get(namespace);
@@ -1 +1 @@
1
- {"version":3,"file":"SocketClientService.js","sourceRoot":"","sources":["../../../src/services/SocketClientService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,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AK,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AAjCC;IADC,aAAa,EAAE;;qDACgB;AAGhC;IADC,MAAM,EAAE;8BACO,MAAM;mDAAC;AALZ,mBAAmB;IAD/B,UAAU,EAAE;GACA,mBAAmB,CAmC/B;SAnCY,mBAAmB","sourcesContent":["import {Inject, Logger, OnDestroy} from \"@tsed/common\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {io, Socket} from \"socket.io-client\";\n\n@Injectable()\nexport class SocketClientService implements OnDestroy {\n @Configuration()\n private settings: Configuration;\n\n @Inject()\n private logger: Logger;\n\n private clients: Map<string, Socket> = new Map();\n\n async get(namespace: string = \"/\", path?: string): Promise<Socket> {\n if (this.clients.has(namespace)) {\n return this.clients.get(namespace)!;\n }\n\n const {address, port} = this.settings.getHttpPort();\n const uri = `http://${address}:${port}${namespace}`;\n\n this.logger.info(\"Bind Socket.io client on:\", uri);\n const client = io(uri, path ? {path} : undefined);\n\n this.clients.set(namespace, client);\n\n await new Promise((resolve) => {\n client.on(\"connect\", resolve as any);\n });\n\n this.logger.debug(\"Socket.io client connected...\");\n\n return client;\n }\n\n $onDestroy() {\n this.clients.forEach((client) => client.close());\n this.logger.debug(\"Socket.io clients closed...\");\n }\n}\n"]}
1
+ {"version":3,"file":"SocketClientService.js","sourceRoot":"","sources":["../../../src/services/SocketClientService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAY,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,EAAE,EAAS,MAAM,kBAAkB,CAAC;AAG5C,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAEtB,QAAQ,CAAgB;IAGxB,MAAM,CAAS;IAEf,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEjD,K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, Logger, OnDestroy} from \"@tsed/common\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {io, Socket} from \"socket.io-client\";\n\n@Injectable()\nexport class SocketClientService implements OnDestroy {\n @Configuration()\n private settings: Configuration;\n\n @Inject()\n private logger: Logger;\n\n private clients: Map<string, Socket> = new Map();\n\n async get(namespace: string = \"/\", path?: string): Promise<Socket> {\n if (this.clients.has(namespace)) {\n return this.clients.get(namespace)!;\n }\n\n const {address, port} = this.settings.getHttpPort();\n const uri = `http://${address}:${port}${namespace}`;\n\n this.logger.info(\"Bind Socket.io client on:\", uri);\n const client = io(uri, path ? {path} : undefined);\n\n this.clients.set(namespace, client);\n\n await new Promise((resolve) => {\n client.on(\"connect\", resolve as any);\n });\n\n this.logger.debug(\"Socket.io client connected...\");\n\n return client;\n }\n\n $onDestroy() {\n this.clients.forEach((client) => client.close());\n this.logger.debug(\"Socket.io clients closed...\");\n }\n}\n"]}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tsed/socketio-testing",
3
- "version": "7.0.0-beta.2",
3
+ "version": "7.0.0-beta.20",
4
4
  "description": "Socket.io testing package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/cjs/index.js",
8
+ "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
11
  "types": "./lib/types/index.d.ts",
@@ -19,25 +20,28 @@
19
20
  "start": "ts-node -r tsconfig-paths/register test/app/index.ts"
20
21
  },
21
22
  "dependencies": {
22
- "tslib": "2.2.0"
23
+ "tslib": "2.4.0"
23
24
  },
24
25
  "devDependencies": {
25
- "@tsed/common": "7.0.0-beta.2",
26
- "@tsed/di": "7.0.0-beta.2",
26
+ "@tsed/common": "7.0.0-beta.20",
27
+ "@tsed/di": "7.0.0-beta.20",
27
28
  "socket.io-client": "^4.1.2"
28
29
  },
29
30
  "peerDependencies": {
30
- "@tsed/common": "^7.0.0-beta.2",
31
- "@tsed/core": "^7.0.0-beta.2",
32
- "@tsed/di": "^7.0.0-beta.2",
33
- "@tsed/socketio": "^7.0.0-beta.2",
31
+ "@tsed/common": "^7.0.0-beta.20",
32
+ "@tsed/core": "^7.0.0-beta.20",
33
+ "@tsed/di": "^7.0.0-beta.20",
34
+ "@tsed/socketio": "^7.0.0-beta.20",
34
35
  "socket.io-client": "^4.0.1"
35
36
  },
36
37
  "repository": "https://github.com/tsedio/tsed",
37
38
  "bugs": {
38
39
  "url": "https://github.com/tsedio/tsed/issues"
39
40
  },
40
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/third-parties/socketio-testing",
41
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/socketio-testing",
41
42
  "author": "Romain Lenzotti",
42
- "license": "MIT"
43
+ "license": "MIT",
44
+ "publishConfig": {
45
+ "tag": "beta"
46
+ }
43
47
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18
 
@@ -44,24 +45,20 @@ Then add the following configuration in your Server:
44
45
  import {Configuration} from "@tsed/common";
45
46
  import "@tsed/socketio"; // import socketio Ts.ED module
46
47
  import {resolve} from "path";
47
- const rootDir = resolve(__dirname)
48
48
 
49
49
  @Configuration({
50
- rootDir,
51
- socketIO: {
52
- // ... see configuration
53
- }
50
+ socketIO: {
51
+ // ... see configuration
52
+ }
54
53
  })
55
- export class Server {
56
-
57
- }
54
+ export class Server {}
58
55
  ```
59
56
 
60
57
  ## Socket Service
61
58
 
62
59
  > Socket.IO allows you to “namespace” your sockets, which essentially means assigning different endpoints or paths.
63
- This is a useful feature to minimize the number of resources (TCP connections) and at the same time separate concerns within your application
64
- by introducing separation between communication channels. See [namespace documentation](https://socket.io/docs/rooms-and-namespaces/#).
60
+ > This is a useful feature to minimize the number of resources (TCP connections) and at the same time separate concerns within your application
61
+ > by introducing separation between communication channels. See [namespace documentation](https://socket.io/docs/rooms-and-namespaces/#).
65
62
 
66
63
  All Socket service work under a namespace and you can create one Socket service per namespace.
67
64
 
@@ -73,31 +70,24 @@ import {SocketService, IO, Nsp, Socket, SocketSession} from "@tsed/socketio";
73
70
 
74
71
  @SocketService("/my-namespace")
75
72
  export class MySocketService {
76
-
77
- @Nsp nsp: SocketIO.Namespace;
78
-
79
- @Nsp("/my-other-namespace")
80
- nspOther: SocketIO.Namespace; // communication between two namespace
81
-
82
- constructor(@IO private io: SocketIO.Server) {}
83
- /**
84
- * Triggered the namespace is created
85
- */
86
- $onNamespaceInit(nsp: SocketIO.Namespace) {
87
-
88
- }
89
- /**
90
- * Triggered when a new client connects to the Namespace.
91
- */
92
- $onConnection(@Socket socket: SocketIO.Socket, @SocketSession session: SocketSession) {
93
-
94
- }
95
- /**
96
- * Triggered when a client disconnects from the Namespace.
97
- */
98
- $onDisconnect(@Socket socket: SocketIO.Socket) {
99
-
100
- }
73
+ @Nsp nsp: SocketIO.Namespace;
74
+
75
+ @Nsp("/my-other-namespace")
76
+ nspOther: SocketIO.Namespace; // communication between two namespace
77
+
78
+ constructor(@IO private io: SocketIO.Server) {}
79
+ /**
80
+ * Triggered the namespace is created
81
+ */
82
+ $onNamespaceInit(nsp: SocketIO.Namespace) {}
83
+ /**
84
+ * Triggered when a new client connects to the Namespace.
85
+ */
86
+ $onConnection(@Socket socket: SocketIO.Socket, @SocketSession session: SocketSession) {}
87
+ /**
88
+ * Triggered when a client disconnects from the Namespace.
89
+ */
90
+ $onDisconnect(@Socket socket: SocketIO.Socket) {}
101
91
  }
102
92
  ```
103
93
 
@@ -111,13 +101,14 @@ import {SocketService, Nsp} from "@tsed/socketio";
111
101
 
112
102
  @SocketService()
113
103
  export class MySocketService {
114
- @Nsp nsp: SocketIO.Namespace;
104
+ @Nsp nsp: SocketIO.Namespace;
115
105
 
116
- helloAll() {
117
- this.nsp.emit('hi', 'everyone!');
118
- }
106
+ helloAll() {
107
+ this.nsp.emit("hi", "everyone!");
108
+ }
119
109
  }
120
110
  ```
111
+
121
112
  Then, you can inject your socket service into another Service, Controller, etc... as following:
122
113
 
123
114
  ```typescript
@@ -126,16 +117,13 @@ import {MySocketService} from "../services/MySocketService";
126
117
 
127
118
  @Controller("/")
128
119
  export class MyCtrl {
129
-
130
- constructor(private mySocketService: MySocketService) {
131
-
132
- }
133
-
134
- @Get("/allo")
135
- allo() {
136
- this.mySocketService.helloAll();
137
- return "is sent";
138
- }
120
+ constructor(private mySocketService: MySocketService) {}
121
+
122
+ @Get("/allo")
123
+ allo() {
124
+ this.mySocketService.helloAll();
125
+ return "is sent";
126
+ }
139
127
  }
140
128
  ```
141
129
 
@@ -148,10 +136,10 @@ import {SocketService, Input, Emit, Args, Socket, Nsp} from "@tsed/socketio";
148
136
 
149
137
  @SocketService("/my-namespace")
150
138
  export class MySocketService {
151
- @Input("eventName")
152
- myMethod(@Args(0) userName: string, @Socket socket: SocketIO.Socket, @Nsp nsp: SocketIO.Namespace) {
153
- console.log(userName);
154
- }
139
+ @Input("eventName")
140
+ myMethod(@Args(0) userName: string, @Socket socket: SocketIO.Socket, @Nsp nsp: SocketIO.Namespace) {
141
+ console.log(userName);
142
+ }
155
143
  }
156
144
  ```
157
145
 
@@ -172,13 +160,14 @@ import {SocketService, Input, Emit, Args, Socket, Nsp} from "@tsed/socketio";
172
160
 
173
161
  @SocketService("/my-namespace")
174
162
  export class MySocketService {
175
- @Input("eventName")
176
- @Emit("responseEventName") // or Broadcast or BroadcastOthers
177
- async myMethod(@Args(0) userName: string, @Socket socket: SocketIO.Socket) {
178
- return "Message " + userName;
179
- }
163
+ @Input("eventName")
164
+ @Emit("responseEventName") // or Broadcast or BroadcastOthers
165
+ async myMethod(@Args(0) userName: string, @Socket socket: SocketIO.Socket) {
166
+ return "Message " + userName;
167
+ }
180
168
  }
181
169
  ```
170
+
182
171
  > The method accept a promise as returned value.
183
172
 
184
173
  ::: warning
@@ -194,17 +183,16 @@ import {SocketService, Input, Emit, Args, SocketSession} from "@tsed/socketio";
194
183
 
195
184
  @SocketService("/my-namespace")
196
185
  export class MySocketService {
197
- @Input("eventName")
198
- @Emit("responseEventName") // or Broadcast or BroadcastOthers
199
- async myMethod(@Args(0) userName: string, @SocketSession session: SocketSession) {
186
+ @Input("eventName")
187
+ @Emit("responseEventName") // or Broadcast or BroadcastOthers
188
+ async myMethod(@Args(0) userName: string, @SocketSession session: SocketSession) {
189
+ const user = session.get("user") || {};
190
+ user.name = userName;
200
191
 
201
- const user = session.get("user") || {}
202
- user.name = userName;
192
+ session.set("user", user);
203
193
 
204
- session.set("user", user);
205
-
206
- return user;
207
- }
194
+ return user;
195
+ }
208
196
  }
209
197
  ```
210
198
 
@@ -221,16 +209,16 @@ import {User} from "../models/User";
221
209
 
222
210
  @SocketMiddleware()
223
211
  export class UserConverterSocketMiddleware {
224
- async use(@Args() args: any[]) {
225
-
226
- let [user] = args;
227
- // update Arguments
228
- user = deserialize(user, {type: User});
229
-
230
- return [user];
231
- }
212
+ async use(@Args() args: any[]) {
213
+ let [user] = args;
214
+ // update Arguments
215
+ user = deserialize(user, {type: User});
216
+
217
+ return [user];
218
+ }
232
219
  }
233
220
  ```
221
+
234
222
  > The user instance will be forwarded to the next middleware and to your decorated method.
235
223
 
236
224
  You can also declare a middleware to handle an error with `@SocketMiddlewareError`.
@@ -241,10 +229,10 @@ import {SocketMiddlewareError, SocketErr, Socket} from "@tsed/socketio";
241
229
 
242
230
  @SocketMiddlewareError()
243
231
  export class ErrorHandlerSocketMiddleware {
244
- async use(@SocketErr err: any, @Socket socket: SocketIO.Socket) {
245
- console.error(err);
246
- socket.emit("error", {message: "An error has occured"})
247
- }
232
+ async use(@SocketErr err: any, @Socket socket: SocketIO.Socket) {
233
+ console.error(err);
234
+ socket.emit("error", {message: "An error has occured"});
235
+ }
248
236
  }
249
237
  ```
250
238
 
@@ -260,7 +248,7 @@ The call sequences is the following for each event request:
260
248
  - Middlewares attached with `@SocketUseBefore` on method,
261
249
  - The method,
262
250
  - Send response if the method is decorated with `@Emit`, `@Broadcast` or `@BroadcastOther`,
263
- - Middlewares attached with `@SocketUseAfter` on method,
251
+ - Middlewares attached with `@SocketUseAfter` on method,
264
252
  - Middlewares attached with `@SocketUseAfter` on class.
265
253
 
266
254
  Middlewares chain use the `Promise` to run it. If one of this middlewares/method emit an error, the first middleware error will be called.
@@ -274,20 +262,18 @@ import {User} from "../models/User";
274
262
  @SocketUseBefore(UserConverterSocketMiddleware) // global version
275
263
  @SocketUseAfter(ErrorHandlerSocketMiddleware)
276
264
  export class MySocketService {
277
-
278
- @Input("eventName")
279
- @Emit("responseEventName") // or Broadcast or BroadcastOthers
280
- @SocketUseBefore(UserConverterSocketMiddleware)
281
- @SocketUseAfter(ErrorHandlerSocketMiddleware)
282
- async myMethod(@Args(0) userName: User) {
283
-
284
- const user = session.get("user") || {}
285
- user.name = userName;
286
-
287
- session.set("user", user);
288
-
289
- return user;
290
- }
265
+ @Input("eventName")
266
+ @Emit("responseEventName") // or Broadcast or BroadcastOthers
267
+ @SocketUseBefore(UserConverterSocketMiddleware)
268
+ @SocketUseAfter(ErrorHandlerSocketMiddleware)
269
+ async myMethod(@Args(0) userName: User) {
270
+ const user = session.get("user") || {};
271
+ user.name = userName;
272
+
273
+ session.set("user", user);
274
+
275
+ return user;
276
+ }
291
277
  }
292
278
  ```
293
279
 
@@ -296,18 +282,17 @@ export class MySocketService {
296
282
  See our documentation https://tsed.io/#/api/index
297
283
 
298
284
  ## Contributors
285
+
299
286
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
300
287
 
301
288
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
302
289
 
303
-
304
290
  ## Backers
305
291
 
306
292
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
307
293
 
308
294
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
309
295
 
310
-
311
296
  ## Sponsors
312
297
 
313
298
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -316,7 +301,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
316
301
 
317
302
  The MIT License (MIT)
318
303
 
319
- Copyright (c) 2016 - 2018 Romain Lenzotti
304
+ Copyright (c) 2016 - 2022 Romain Lenzotti
320
305
 
321
306
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
322
307
 
@@ -8,16 +8,5 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
10
  },
11
- "exclude": [
12
- "node_modules",
13
- "test",
14
- "lib",
15
- "benchmark",
16
- "coverage",
17
- "spec",
18
- "**/*.benchmark.ts",
19
- "**/*.spec.ts",
20
- "keys",
21
- "jest.config.js"
22
- ]
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
23
12
  }