@tsed/socketio 7.32.0 → 7.33.1

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.
Files changed (34) hide show
  1. package/jest.config.js +3 -3
  2. package/lib/cjs/class/SocketHandlersBuilder.js +7 -6
  3. package/lib/cjs/class/SocketHandlersBuilder.js.map +1 -1
  4. package/lib/cjs/decorators/reason.js +34 -0
  5. package/lib/cjs/decorators/reason.js.map +1 -0
  6. package/lib/cjs/index.js +1 -0
  7. package/lib/cjs/index.js.map +1 -1
  8. package/lib/cjs/interfaces/SocketFilters.js +1 -0
  9. package/lib/cjs/interfaces/SocketFilters.js.map +1 -1
  10. package/lib/cjs/services/SocketIOServer.js +3 -2
  11. package/lib/cjs/services/SocketIOServer.js.map +1 -1
  12. package/lib/cjs/services/SocketIOService.js +2 -2
  13. package/lib/cjs/services/SocketIOService.js.map +1 -1
  14. package/lib/esm/class/SocketHandlersBuilder.js +7 -6
  15. package/lib/esm/class/SocketHandlersBuilder.js.map +1 -1
  16. package/lib/esm/decorators/reason.js +30 -0
  17. package/lib/esm/decorators/reason.js.map +1 -0
  18. package/lib/esm/index.js +1 -0
  19. package/lib/esm/index.js.map +1 -1
  20. package/lib/esm/interfaces/SocketFilters.js +1 -0
  21. package/lib/esm/interfaces/SocketFilters.js.map +1 -1
  22. package/lib/esm/services/SocketIOServer.js +4 -3
  23. package/lib/esm/services/SocketIOServer.js.map +1 -1
  24. package/lib/esm/services/SocketIOService.js +2 -2
  25. package/lib/esm/services/SocketIOService.js.map +1 -1
  26. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  27. package/lib/tsconfig.tsbuildinfo +1 -1
  28. package/lib/types/SocketIOModule.d.ts +1 -1
  29. package/lib/types/class/SocketHandlersBuilder.d.ts +2 -2
  30. package/lib/types/decorators/reason.d.ts +25 -0
  31. package/lib/types/index.d.ts +1 -0
  32. package/lib/types/interfaces/SocketFilters.d.ts +2 -1
  33. package/package.json +17 -17
  34. package/readme.md +2 -2
@@ -16,7 +16,7 @@ export declare class SocketIOModule implements AfterListen, OnDestroy {
16
16
  private io;
17
17
  private socketIOService;
18
18
  $afterListen(): Promise<void>;
19
- $onDestroy(): any;
19
+ $onDestroy(): Promise<unknown>;
20
20
  /**
21
21
  *
22
22
  * @returns {Provider<any>[]}
@@ -25,8 +25,8 @@ export declare class SocketHandlersBuilder {
25
25
  * @param {Socket} socket
26
26
  * @param {Namespace} nsp
27
27
  */
28
- onConnection(socket: Socket, nsp: Namespace): void;
29
- onDisconnect(socket: Socket, nsp: Namespace): void;
28
+ onConnection(socket: Socket, nsp: Namespace): Promise<void>;
29
+ onDisconnect(socket: Socket, nsp: Namespace, reason?: string): Promise<void>;
30
30
  /**
31
31
  *
32
32
  * @param {Socket} socket
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Inject the disconnection reason into the decorated parameter.
3
+ *
4
+ * This decorator is used in conjunction with the `$onDisconnect` event handler to handle disconnection reasons in SocketIO services.
5
+ * It allows you to access the reason for the disconnection in your method implementation. For details please refer to the [Socket.io documentation](https://socket.io/docs/v4/server-api/#event-disconnect).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * @SocketService("/nsp")
10
+ * export class MyWS {
11
+ * public async $onDisconnect(
12
+ * @Reason reason: string = ''
13
+ * ) {
14
+ * // your implementation
15
+ * }
16
+ * }
17
+ * ```
18
+ *
19
+ * @experimental This decorator is experimental and may change or be removed in future versions.
20
+ * @param target
21
+ * @param {string} propertyKey
22
+ * @param {number} index
23
+ * @decorator
24
+ */
25
+ export declare function Reason(target: unknown, propertyKey: string, index: number): void;
@@ -15,6 +15,7 @@ export * from "./decorators/inputAndBroadcastOthers";
15
15
  export * from "./decorators/inputAndEmit";
16
16
  export * from "./decorators/io";
17
17
  export * from "./decorators/nsp";
18
+ export * from "./decorators/reason";
18
19
  export * from "./decorators/socket";
19
20
  export * from "./decorators/socketErr";
20
21
  export * from "./decorators/socketEventName";
@@ -8,5 +8,6 @@ export declare enum SocketFilters {
8
8
  NSP = "nsp",
9
9
  SESSION = "session",
10
10
  ERR = "error",
11
- SOCKET_NSP = "socket_nsp"
11
+ SOCKET_NSP = "socket_nsp",
12
+ REASON = "reason"
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/socketio",
3
- "version": "7.32.0",
3
+ "version": "7.33.1",
4
4
  "description": "Socket.io package for Ts.ED framework",
5
5
  "private": false,
6
6
  "keywords": [
@@ -33,27 +33,27 @@
33
33
  "tslib": "2.5.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@tsed/common": "7.32.0",
37
- "@tsed/core": "7.32.0",
38
- "@tsed/di": "7.32.0",
39
- "@tsed/eslint": "7.32.0",
40
- "@tsed/json-mapper": "7.32.0",
41
- "@tsed/openspec": "7.32.0",
42
- "@tsed/platform-middlewares": "7.32.0",
43
- "@tsed/schema": "7.32.0",
44
- "@tsed/socketio-testing": "7.32.0",
45
- "@tsed/typescript": "7.32.0",
36
+ "@tsed/common": "7.33.1",
37
+ "@tsed/core": "7.33.1",
38
+ "@tsed/di": "7.33.1",
39
+ "@tsed/eslint": "7.33.1",
40
+ "@tsed/json-mapper": "7.33.1",
41
+ "@tsed/openspec": "7.33.1",
42
+ "@tsed/platform-middlewares": "7.33.1",
43
+ "@tsed/schema": "7.33.1",
44
+ "@tsed/socketio-testing": "7.33.1",
45
+ "@tsed/typescript": "7.33.1",
46
46
  "eslint": "^8.12.0",
47
47
  "express": "^4.17.1",
48
- "socket.io": "4.4.1",
49
- "socket.io-client": "^4.1.2"
48
+ "socket.io": "4.7.1",
49
+ "socket.io-client": "^4.7.1"
50
50
  },
51
51
  "peerDependencies": {
52
- "@tsed/di": "^7.32.0",
53
- "@tsed/json-mapper": "^7.32.0",
52
+ "@tsed/di": "^7.33.1",
53
+ "@tsed/json-mapper": "^7.33.1",
54
54
  "@tsed/logger": ">=6.2.2",
55
- "@tsed/platform-middlewares": "^7.32.0",
56
- "@tsed/schema": "^7.32.0",
55
+ "@tsed/platform-middlewares": "^7.33.1",
56
+ "@tsed/schema": "^7.33.1",
57
57
  "socket.io": ">=4.0.0"
58
58
  },
59
59
  "peerDependenciesMeta": {
package/readme.md CHANGED
@@ -67,7 +67,7 @@ Example:
67
67
 
68
68
  ```typescript
69
69
  import * as SocketIO from "socket.io";
70
- import {SocketService, IO, Nsp, Socket, SocketSession} from "@tsed/socketio";
70
+ import {SocketService, IO, Nsp, Socket, SocketSession, Reason} from "@tsed/socketio";
71
71
 
72
72
  @SocketService("/my-namespace")
73
73
  export class MySocketService {
@@ -88,7 +88,7 @@ export class MySocketService {
88
88
  /**
89
89
  * Triggered when a client disconnects from the Namespace.
90
90
  */
91
- $onDisconnect(@Socket socket: SocketIO.Socket) {}
91
+ $onDisconnect(@Socket socket: SocketIO.Socket, @Reason reason: string) {}
92
92
  }
93
93
  ```
94
94