thor-io.vnext 2.0.5-beta.3 → 3.1.0-beta.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 (185) hide show
  1. package/.gitattributes +17 -17
  2. package/build/index.d.ts +24 -0
  3. package/build/index.js +47 -0
  4. package/build/src/Connection/ClientInfo.d.ts +27 -0
  5. package/{src/Client → build/src/Connection}/ClientInfo.js +7 -0
  6. package/build/src/Connection/Connection.d.ts +117 -0
  7. package/build/src/Connection/Connection.js +202 -0
  8. package/build/src/Connection/IClientInfo.d.ts +20 -0
  9. package/build/src/Controller/ControllerBase.d.ts +134 -0
  10. package/build/src/Controller/ControllerBase.js +543 -0
  11. package/build/src/Controller/Subscription.d.ts +27 -0
  12. package/build/src/Controller/Subscription.js +22 -0
  13. package/build/src/Controllers/BrokerController/Broker.js +145 -0
  14. package/build/src/Controllers/BrokerController/BrokerController.d.ts +61 -0
  15. package/build/src/Controllers/BrokerController/BrokerController.js +115 -0
  16. package/{src/Controllers/BrokerController/Broker.js → build/src/Controllers/BrokerController/BrokerrController.js} +74 -85
  17. package/build/src/Controllers/BrokerController/Models/PeerConnection.d.ts +7 -0
  18. package/build/src/Controllers/BrokerController/Models/PeerConnection.js +14 -0
  19. package/build/src/Controllers/BrokerController/Models/Signal.js +11 -0
  20. package/build/src/Decorators/CanInvoke.d.ts +10 -0
  21. package/build/src/Decorators/CanInvoke.js +22 -0
  22. package/build/src/Decorators/CanSet.d.ts +10 -0
  23. package/build/src/Decorators/CanSet.js +20 -0
  24. package/build/src/Decorators/ControllerProperties.d.ts +10 -0
  25. package/build/src/Decorators/ControllerProperties.js +20 -0
  26. package/{src/Controllers/BrokerController/Models/InstantMessage.js → build/src/Interfaces/IInterceptor.js} +2 -5
  27. package/build/src/Interfaces/ITransport.d.ts +94 -0
  28. package/build/src/Interfaces/ITransportMessage.d.ts +41 -0
  29. package/build/src/Messages/BufferMessage.d.ts +38 -0
  30. package/{src → build/src}/Messages/BufferMessage.js +32 -2
  31. package/build/src/Messages/ErrorMessage.d.ts +29 -0
  32. package/build/src/Messages/ErrorMessage.js +22 -0
  33. package/build/src/Messages/PipeMessage.d.ts +46 -0
  34. package/build/src/Messages/PipeMessage.js +41 -0
  35. package/build/src/Messages/TextMessage.d.ts +88 -0
  36. package/build/src/Messages/TextMessage.js +94 -0
  37. package/build/src/Messages/WebSocketMessage.d.ts +34 -0
  38. package/build/src/Messages/WebSocketMessage.js +41 -0
  39. package/build/src/Plugin.js +32 -0
  40. package/build/src/Server/Plugin.d.ts +37 -0
  41. package/build/src/Server/Plugin.js +32 -0
  42. package/build/src/Server/ThorIOServer.d.ts +68 -0
  43. package/build/src/Server/ThorIOServer.js +131 -0
  44. package/build/src/Subscription.js +22 -0
  45. package/build/src/ThorIO.js +142 -0
  46. package/build/src/ThorIOServer.d.ts +64 -0
  47. package/build/src/ThorIOServer.js +131 -0
  48. package/build/src/Transports/BufferMessageTransport.d.ts +78 -0
  49. package/build/src/Transports/BufferMessageTransport.js +85 -0
  50. package/build/src/Transports/PipeMessageTransport.d.ts +79 -0
  51. package/build/src/Transports/PipeMessageTransport.js +90 -0
  52. package/build/src/Transports/WebSocketMessageTransport.d.ts +87 -0
  53. package/build/src/Transports/WebSocketMessageTransport.js +93 -0
  54. package/build/src/Utils/BufferUtils.d.ts +32 -0
  55. package/build/src/Utils/BufferUtils.js +57 -0
  56. package/build/src/Utils/StringUtils.d.ts +15 -0
  57. package/build/src/Utils/StringUtils.js +31 -0
  58. package/build/src/test.js +5 -0
  59. package/docs/.nojekyll +1 -0
  60. package/docs/assets/hierarchy.js +1 -0
  61. package/docs/assets/highlight.css +43 -0
  62. package/docs/assets/icons.js +18 -0
  63. package/docs/assets/icons.svg +1 -0
  64. package/docs/assets/main.js +60 -0
  65. package/docs/assets/navigation.js +1 -0
  66. package/docs/assets/search.js +1 -0
  67. package/docs/assets/style.css +1610 -0
  68. package/docs/classes/BrokerController.html +164 -0
  69. package/docs/classes/BufferMessage.html +11 -0
  70. package/docs/classes/BufferMessageTransport.html +31 -0
  71. package/docs/classes/BufferUtils.html +16 -0
  72. package/docs/classes/ClientInfo.html +11 -0
  73. package/docs/classes/Connection.html +42 -0
  74. package/docs/classes/ControllerBase.html +144 -0
  75. package/docs/classes/ErrorMessage.html +13 -0
  76. package/docs/classes/PeerConnection.html +4 -0
  77. package/docs/classes/PipeMessage.html +17 -0
  78. package/docs/classes/PipeMessageTransport.html +33 -0
  79. package/docs/classes/Plugin.html +13 -0
  80. package/docs/classes/Signal.html +5 -0
  81. package/docs/classes/StringUtils.html +9 -0
  82. package/docs/classes/Subscription.html +11 -0
  83. package/docs/classes/TextMessage.html +37 -0
  84. package/docs/classes/ThorIOServer.html +25 -0
  85. package/docs/classes/WebSocketMessage.html +18 -0
  86. package/docs/classes/WebSocketMessageTransport.html +35 -0
  87. package/docs/functions/CanInvoke.html +5 -0
  88. package/docs/functions/CanSet.html +5 -0
  89. package/docs/functions/ControllerProperties.html +5 -0
  90. package/docs/hierarchy.html +1 -0
  91. package/docs/index.html +24 -0
  92. package/docs/interfaces/ITransport.html +46 -0
  93. package/docs/interfaces/ITransportMessage.html +21 -0
  94. package/docs/modules.html +1 -0
  95. package/index.ts +32 -37
  96. package/licence +21 -21
  97. package/package.json +48 -50
  98. package/readme.md +32 -1
  99. package/src/{Client → Connection}/ClientInfo.ts +34 -43
  100. package/src/Connection/Connection.ts +229 -0
  101. package/src/Connection/IClientInfo.ts +22 -0
  102. package/src/Controller/ControllerBase.ts +561 -457
  103. package/src/{Subscription.ts → Controller/Subscription.ts} +32 -34
  104. package/src/Controllers/BrokerController/BrokerController.ts +121 -0
  105. package/src/Controllers/BrokerController/Models/PeerConnection.ts +12 -34
  106. package/src/Controllers/BrokerController/Models/Signal.ts +11 -43
  107. package/src/Decorators/CanInvoke.ts +21 -13
  108. package/src/Decorators/CanSet.ts +19 -12
  109. package/src/Decorators/ControllerProperties.ts +19 -16
  110. package/src/Interfaces/ITransport.ts +107 -23
  111. package/src/Interfaces/ITransportMessage.ts +45 -41
  112. package/src/Messages/BufferMessage.ts +70 -69
  113. package/src/Messages/ErrorMessage.ts +34 -6
  114. package/src/Messages/PipeMessage.ts +56 -62
  115. package/src/Messages/TextMessage.ts +139 -93
  116. package/src/Messages/WebSocketMessage.ts +39 -41
  117. package/src/Server/Plugin.ts +56 -0
  118. package/src/Server/ThorIOServer.ts +121 -0
  119. package/src/ThorIOServer.ts +117 -0
  120. package/src/Transports/BufferMessageTransport.ts +109 -100
  121. package/src/Transports/PipeMessageTransport.ts +112 -104
  122. package/src/Transports/WebSocketMessageTransport.ts +122 -110
  123. package/src/Utils/BufferUtils.ts +55 -61
  124. package/src/Utils/StringUtils.ts +28 -17
  125. package/tsconfig.json +109 -19
  126. package/typedoc.json +6 -0
  127. package/index.d.ts +0 -24
  128. package/index.js +0 -46
  129. package/src/Client/ClientInfo.d.ts +0 -6
  130. package/src/Connection.d.ts +0 -24
  131. package/src/Connection.js +0 -121
  132. package/src/Connection.ts +0 -263
  133. package/src/Controller/ControllerBase.d.ts +0 -43
  134. package/src/Controller/ControllerBase.js +0 -331
  135. package/src/Controllers/BrokerController/Broker.d.ts +0 -21
  136. package/src/Controllers/BrokerController/Broker.ts +0 -153
  137. package/src/Controllers/BrokerController/Models/InstantMessage.d.ts +0 -3
  138. package/src/Controllers/BrokerController/Models/InstantMessage.ts +0 -15
  139. package/src/Controllers/BrokerController/Models/PeerConnection.d.ts +0 -5
  140. package/src/Controllers/BrokerController/Models/PeerConnection.js +0 -9
  141. package/src/Controllers/BrokerController/Models/Signal.js +0 -10
  142. package/src/Decorators/CanInvoke.d.ts +0 -2
  143. package/src/Decorators/CanInvoke.js +0 -9
  144. package/src/Decorators/CanSet.d.ts +0 -1
  145. package/src/Decorators/CanSet.js +0 -8
  146. package/src/Decorators/ControllerProperties.d.ts +0 -1
  147. package/src/Decorators/ControllerProperties.js +0 -10
  148. package/src/Interfaces/IInterceptor.d.ts +0 -2
  149. package/src/Interfaces/IInterceptor.ts +0 -2
  150. package/src/Interfaces/ITransport.d.ts +0 -18
  151. package/src/Interfaces/ITransportMessage.d.ts +0 -8
  152. package/src/Listener.d.ts +0 -5
  153. package/src/Listener.js +0 -9
  154. package/src/Listener.ts +0 -34
  155. package/src/Messages/BufferMessage.d.ts +0 -10
  156. package/src/Messages/ErrorMessage.d.ts +0 -4
  157. package/src/Messages/ErrorMessage.js +0 -8
  158. package/src/Messages/PipeMessage.d.ts +0 -12
  159. package/src/Messages/PipeMessage.js +0 -20
  160. package/src/Messages/TextMessage.d.ts +0 -15
  161. package/src/Messages/TextMessage.js +0 -50
  162. package/src/Messages/WebSocketMessage.d.ts +0 -10
  163. package/src/Messages/WebSocketMessage.js +0 -15
  164. package/src/Plugin.d.ts +0 -6
  165. package/src/Plugin.js +0 -11
  166. package/src/Plugin.ts +0 -37
  167. package/src/Subscription.d.ts +0 -5
  168. package/src/Subscription.js +0 -9
  169. package/src/ThorIO.d.ts +0 -18
  170. package/src/ThorIO.js +0 -65
  171. package/src/ThorIO.ts +0 -148
  172. package/src/Transports/BufferMessageTransport.d.ts +0 -21
  173. package/src/Transports/BufferMessageTransport.js +0 -31
  174. package/src/Transports/PipeMessageTransport.d.ts +0 -20
  175. package/src/Transports/PipeMessageTransport.js +0 -33
  176. package/src/Transports/WebSocketMessageTransport.d.ts +0 -20
  177. package/src/Transports/WebSocketMessageTransport.js +0 -31
  178. package/src/Utils/BufferUtils.d.ts +0 -5
  179. package/src/Utils/BufferUtils.js +0 -29
  180. package/src/Utils/StringUtils.d.ts +0 -4
  181. package/src/Utils/StringUtils.js +0 -13
  182. /package/{src/Interfaces/IInterceptor.js → build/src/Connection/IClientInfo.js} +0 -0
  183. /package/{src → build/src}/Controllers/BrokerController/Models/Signal.d.ts +0 -0
  184. /package/{src → build/src}/Interfaces/ITransport.js +0 -0
  185. /package/{src → build/src}/Interfaces/ITransportMessage.js +0 -0
@@ -1,34 +1,32 @@
1
- /**
2
- *
3
- *
4
- * @export
5
- * @class Subscription
6
- */
7
- export class Subscription {
8
- /**
9
- *
10
- *
11
- * @type {string}
12
- * @memberOf Subscription
13
- */
14
- public topic: string;
15
- /**
16
- *
17
- *
18
- * @type {string}
19
- * @memberOf Subscription
20
- */
21
- public controller: string;
22
- /**
23
- * Creates an instance of Subscription.
24
- *
25
- * @param {string} topic
26
- * @param {string} controller
27
- *
28
- * @memberOf Subscription
29
- */
30
- constructor(topic: string, controller: string) {
31
- this.topic = topic;
32
- this.controller = controller;
33
- }
34
- }
1
+ /**
2
+ * Represents a subscription to a specific topic with an associated controller.
3
+ *
4
+ * @export
5
+ * @class Subscription
6
+ */
7
+ export class Subscription {
8
+ /**
9
+ * The topic of the subscription.
10
+ *
11
+ * @type {string}
12
+ */
13
+ public topic: string;
14
+
15
+ /**
16
+ * The controller associated with the subscription.
17
+ *
18
+ * @type {string}
19
+ */
20
+ public controller: string;
21
+
22
+ /**
23
+ * Creates an instance of Subscription.
24
+ *
25
+ * @param {string} topic - The topic of the subscription.
26
+ * @param {string} controller - The controller associated with the subscription.
27
+ */
28
+ constructor(topic: string, controller: string) {
29
+ this.topic = topic;
30
+ this.controller = controller;
31
+ }
32
+ }
@@ -0,0 +1,121 @@
1
+ import { Connection } from '../../Connection/Connection';
2
+ import { ControllerBase } from '../../Controller/ControllerBase';
3
+ import { CanInvoke } from '../../Decorators/CanInvoke';
4
+ import { ControllerProperties } from '../../Decorators/ControllerProperties';
5
+ import { StringUtils } from '../../Utils/StringUtils';
6
+ import { PeerConnection } from './Models/PeerConnection';
7
+ import { Signal } from './Models/Signal';
8
+
9
+ /**
10
+ * BrokerController class for managing peer connections and signals.
11
+ */
12
+ @ControllerProperties("contextBroker", 7500)
13
+ export class BrokerController extends ControllerBase {
14
+ /**
15
+ * An array of peer connections.
16
+ */
17
+ public Connections: Array<PeerConnection>;
18
+
19
+ /**
20
+ * The current peer connection.
21
+ */
22
+ public Peer: PeerConnection;
23
+
24
+ /**
25
+ * The local peer ID.
26
+ */
27
+ public localPeerId: string = "";
28
+
29
+ /**
30
+ * Creates an instance of BrokerController.
31
+ * @param {Connection} connection The connection instance.
32
+ */
33
+ constructor(connection: Connection) {
34
+ super(connection);
35
+ this.Connections = [];
36
+ this.Peer = new PeerConnection(StringUtils.newGuid(), connection.id);
37
+ }
38
+
39
+ [key: string]: any;
40
+
41
+ /**
42
+ * Called when the connection is opened.
43
+ */
44
+ onopen() {
45
+ this.invoke(this.Peer, "contextCreated", this.alias);
46
+ }
47
+
48
+
49
+ @CanInvoke(true)
50
+ transcribe(data: {phrase: string,sourceLanguage:string}) {
51
+ if(!this.generateSubtitles()) {
52
+ return;
53
+ }
54
+ console.log(`Transcribing ${data.phrase} from ${data.sourceLanguage} to ${this.Peer.language}`);
55
+ }
56
+
57
+ private generateSubtitles(): boolean{
58
+ return this.Peer.language != undefined
59
+ }
60
+
61
+ /**
62
+ * Sends an instant message to peers.
63
+ * @param {any} data The message data.
64
+ */
65
+ @CanInvoke(true)
66
+ instantMessage(data: any) {
67
+ const expression = (pre: BrokerController) => {
68
+ return pre.Peer!.context >= this.Peer!.context;
69
+ };
70
+ this.invokeTo<BrokerController>(expression, data, "instantMessage", this.alias);
71
+ }
72
+
73
+ /**
74
+ * Changes the context of the current peer.
75
+ * @param {PeerConnection} change The new peer connection context.
76
+ */
77
+ @CanInvoke(true)
78
+ changeContext(change: PeerConnection) {
79
+ this.Peer!.context = change.context;
80
+ this.invoke(this.Peer, "contextChanged", this.alias);
81
+ }
82
+
83
+ /**
84
+ * Sends a signal to a specific peer.
85
+ * @param {Signal} signal The signal data.
86
+ */
87
+ @CanInvoke(true)
88
+ contextSignal(signal: Signal) {
89
+ const expression = (pre: BrokerController) => {
90
+ return pre.connection.id === signal.recipient;
91
+ };
92
+ this.invokeTo(expression, signal, "contextSignal", this.alias);
93
+ }
94
+
95
+ /**
96
+ * Connects to peers in the same context.
97
+ */
98
+ @CanInvoke(true)
99
+ connectContext() {
100
+ const connections = this.getPeerConnections(this.Peer!)
101
+ .map((p: BrokerController) => {
102
+ return p.Peer;
103
+ });
104
+
105
+ this.invoke(connections, "connectTo", this.alias);
106
+ }
107
+
108
+ /**
109
+ * Gets peer connections in the same context.
110
+ * @param {PeerConnection} peerConnection The current peer connection.
111
+ * @returns {Array<BrokerController>} An array of matching peer controllers.
112
+ */
113
+ getPeerConnections(peerConnection: PeerConnection): Array<BrokerController> {
114
+ const match = this.findOn<BrokerController>(this.alias, (pre: BrokerController) => {
115
+ return (pre.Peer!.context === this.Peer!.context && pre.Peer!.peerId !== peerConnection.peerId);
116
+ }) as Array<BrokerController>;
117
+ return match ? match : new Array<BrokerController>();
118
+ }
119
+
120
+
121
+ }
@@ -1,34 +1,12 @@
1
- /**
2
- *
3
- *
4
- * @export
5
- * @class PeerConnection
6
- */
7
- export class PeerConnection {
8
- /**
9
- *
10
- *
11
- * @type {string}
12
- * @memberOf PeerConnection
13
- */
14
- context: string;
15
- /**
16
- *
17
- *
18
- * @type {string}
19
- * @memberOf PeerConnection
20
- */
21
- peerId: string;
22
- /**
23
- * Creates an instance of PeerConnection.
24
- *
25
- * @param {string} [context]
26
- * @param {string} [peerId]
27
- *
28
- * @memberOf PeerConnection
29
- */
30
- constructor(context?: string, peerId?: string) {
31
- this.context = context;
32
- this.peerId = peerId;
33
- }
34
- }
1
+ export class PeerConnection {
2
+ context: string; // The context for the peer connection (e.g., a session or room).
3
+ peerId: string = ""; // The unique identifier for the peer. Defaults to an empty string.
4
+ language: string | undefined;
5
+ constructor(context: string, peerId: string) {
6
+ this.context = context; // Initializes the context of the connection.
7
+ this.peerId = peerId; // Initializes the peer's unique identifier.
8
+ }
9
+ setLanguage(language: string) {
10
+ this.language = language;
11
+ }
12
+ }
@@ -1,43 +1,11 @@
1
- /**
2
- *
3
- *
4
- * @export
5
- * @class Signal
6
- */
7
- export class Signal {
8
- /**
9
- *
10
- *
11
- * @type {string}
12
- * @memberOf Signal
13
- */
14
- recipient: string;
15
- /**
16
- *
17
- *
18
- * @type {string}
19
- * @memberOf Signal
20
- */
21
- sender: string;
22
- /**
23
- *
24
- *
25
- * @type {string}
26
- * @memberOf Signal
27
- */
28
- message: string;
29
- /**
30
- * Creates an instance of Signal.
31
- *
32
- * @param {string} recipient
33
- * @param {string} sender
34
- * @param {string} message
35
- *
36
- * @memberOf Signal
37
- */
38
- constructor(recipient: string, sender: string, message: string) {
39
- this.recipient = recipient;
40
- this.sender = sender;
41
- this.message = message;
42
- }
43
- }
1
+ export class Signal {
2
+ recipient: string; // The recipient of the signal
3
+ sender: string; // The sender of the signal
4
+ message: string; // The content of the signal/message
5
+
6
+ constructor(recipient: string, sender: string, message: string) {
7
+ this.recipient = recipient; // Initializes the recipient
8
+ this.sender = sender; // Initializes the sender
9
+ this.message = message; // Initializes the message
10
+ }
11
+ }
@@ -1,13 +1,21 @@
1
- import 'reflect-metadata';
2
- /**
3
- *
4
- *
5
- * @export
6
- * @param {boolean} state
7
- * @returns
8
- */
9
- export function CanInvoke(state: boolean, alias?: string) {
10
- return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
11
- Reflect.defineMetadata("canInvokeOrSet", state, target, propertyKey);
12
- };
13
- }
1
+ import 'reflect-metadata';
2
+
3
+ /**
4
+ * A decorator to define whether a method can be invoked, with optional alias support.
5
+ *
6
+ * @param state Boolean indicating whether the method can be invoked.
7
+ * @param alias Optional alias for the method.
8
+ *
9
+ * @returns A function that adds metadata to the method.
10
+ */
11
+ export function CanInvoke(state: boolean, alias?: string) {
12
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
13
+ // Define metadata for whether the method can be invoked
14
+ Reflect.defineMetadata("canInvoke", state, target, propertyKey);
15
+
16
+ // Optionally add an alias if provided
17
+ if (alias) {
18
+ Reflect.defineMetadata("alias", alias, target, propertyKey);
19
+ }
20
+ };
21
+ }
@@ -1,12 +1,19 @@
1
- /**
2
- *
3
- *
4
- * @export
5
- * @param {boolean} state
6
- * @returns
7
- */
8
- export function CanSet(state: boolean) {
9
- return function (target: Object, propertyKey: string) {
10
- Reflect.defineMetadata("canInvokeOrSet", state, target, propertyKey);
11
- };
12
- }
1
+ import 'reflect-metadata';
2
+
3
+ /**
4
+ * A decorator that attaches metadata to a property indicating whether it can be set or get.
5
+ *
6
+ * @param canSet Boolean indicating if the property can be set.
7
+ * @param canGet Optional boolean indicating if the property can be gotten (defaults to `canSet` if not provided).
8
+ *
9
+ * @returns A function that adds metadata to the property.
10
+ */
11
+ export function CanSetGet(canSet: boolean, canGet?: boolean) {
12
+ return function (target: Object, propertyKey: string) {
13
+ // Attach 'canSet' metadata
14
+ Reflect.defineMetadata("canSet", canSet, target, propertyKey);
15
+
16
+ // Attach 'canGet' metadata, defaulting to 'canSet' if not provided
17
+ Reflect.defineMetadata("canGet", canGet ?? canSet, target, propertyKey);
18
+ };
19
+ }
@@ -1,16 +1,19 @@
1
- /**
2
- *
3
- *
4
- * @export
5
- * @param {string} alias
6
- * @param {boolean} [seald]
7
- * @param {number} [heartbeatInterval]
8
- * @returns
9
- */
10
- export function ControllerProperties(alias: string, seald?: boolean, heartbeatInterval?: number) {
11
- return function (target: Function) {
12
- Reflect.defineMetadata("seald", seald || false, target);
13
- Reflect.defineMetadata("alias", alias, target);
14
- Reflect.defineMetadata("heartbeatInterval", heartbeatInterval || -1, target);
15
- };
16
- }
1
+ import 'reflect-metadata';
2
+
3
+ /**
4
+ * A decorator to attach custom metadata to a controller class.
5
+ *
6
+ * @param alias The alias for the controller (used for routing or identification).
7
+ * @param heartbeatInterval Optional interval in milliseconds for the heartbeat. Defaults to -1.
8
+ *
9
+ * @returns A function that adds metadata to the target class.
10
+ */
11
+ export function ControllerProperties(alias: string, heartbeatInterval?: number) {
12
+ return function (target: Function) {
13
+ // Attach alias to the class
14
+ Reflect.defineMetadata("alias", alias, target);
15
+
16
+ // Attach heartbeat interval to the class (default to -1 if not provided)
17
+ Reflect.defineMetadata("heartbeatInterval", heartbeatInterval ?? -1, target);
18
+ };
19
+ }
@@ -1,23 +1,107 @@
1
- import { ITransportMessage } from "./ITransportMessage";
2
- import { IInterceptor } from "./IInterceptor";
3
- import { IncomingMessage } from 'http';
4
- /**
5
- *
6
- *
7
- * @export
8
- * @interface ITransport
9
- */
10
- export interface ITransport {
11
- id: string;
12
- socket: any;
13
- readyState: number;
14
- send(data: any):void;
15
- close(reason: number, message: any):void;
16
- addEventListener(topic: string, fn: Function):void;
17
- ping():void;
18
- onMessage: (message: ITransportMessage) => void;
19
- onClose: (e: any) => void;
20
- onOpen: (e: any) => void;
21
- interceptors: Map<string,IInterceptor>;
22
- request:IncomingMessage | any ;
23
- }
1
+ import { IncomingMessage } from 'http';
2
+
3
+ import { ITransportMessage } from './ITransportMessage';
4
+
5
+ /**
6
+ * Represents a transport interface for handling communication over various protocols.
7
+ * This could be used for WebSocket, HTTP, or any other transport mechanism.
8
+ *
9
+ * @export
10
+ * @interface ITransport
11
+ */
12
+ export interface ITransport {
13
+ /**
14
+ * A unique identifier for the transport instance.
15
+ *
16
+ * @type {string}
17
+ * @memberOf ITransport
18
+ */
19
+ id: string;
20
+
21
+ /**
22
+ * The underlying socket or connection object used for communication.
23
+ *
24
+ * @type {*}
25
+ * @memberOf ITransport
26
+ */
27
+ socket: any;
28
+
29
+ /**
30
+ * The current state of the connection (e.g., open, closed, etc.).
31
+ * This is commonly used in WebSockets but can be adapted for other transport mechanisms.
32
+ *
33
+ * @readonly
34
+ * @type {number}
35
+ * @memberOf ITransport
36
+ */
37
+ readyState: number;
38
+
39
+ /**
40
+ * Sends data over the transport connection.
41
+ *
42
+ * @param {any} data The data to send. It can be any type, depending on the transport.
43
+ * @memberOf ITransport
44
+ */
45
+ send(data: any): void;
46
+
47
+ /**
48
+ * Closes the connection with a specified reason and optional message.
49
+ *
50
+ * @param {number} reason The reason code for closing the connection.
51
+ * @param {any} message An optional message to include with the close operation.
52
+ * @memberOf ITransport
53
+ */
54
+ close(reason: number, message: any): void;
55
+
56
+ /**
57
+ * Adds an event listener to the transport, e.g., for handling incoming messages or state changes.
58
+ *
59
+ * @param {string} topic The event name or topic to listen for.
60
+ * @param {Function} fn The callback function to invoke when the event occurs.
61
+ * @memberOf ITransport
62
+ */
63
+ addEventListener(topic: string, fn: Function): void;
64
+
65
+ /**
66
+ * Sends a ping message to keep the connection alive or check its status.
67
+ *
68
+ * @memberOf ITransport
69
+ */
70
+ ping(): void;
71
+
72
+ /**
73
+ * Callback function that is invoked when a message is received.
74
+ * This function is optional and can be defined by the implementing class.
75
+ *
76
+ * @type {(message: ITransportMessage) => void}
77
+ * @memberOf ITransport
78
+ */
79
+ onMessage?: (message: ITransportMessage) => void;
80
+
81
+ /**
82
+ * Callback function that is invoked when the connection is closed.
83
+ * This function is optional and can be defined by the implementing class.
84
+ *
85
+ * @type {(e: any) => void}
86
+ * @memberOf ITransport
87
+ */
88
+ onClose?: (e: any) => void;
89
+
90
+ /**
91
+ * Callback function that is invoked when the connection is established or opened.
92
+ * This function is optional and can be defined by the implementing class.
93
+ *
94
+ * @type {(e: any) => void}
95
+ * @memberOf ITransport
96
+ */
97
+ onOpen?: (e: any) => void;
98
+
99
+
100
+ /**
101
+ * The initial HTTP request (if applicable) associated with the transport connection.
102
+ *
103
+ * @type {IncomingMessage | any}
104
+ * @memberOf ITransport
105
+ */
106
+ request: IncomingMessage | any;
107
+ }
@@ -1,41 +1,45 @@
1
- import { TextMessage } from "../Messages/TextMessage";
2
-
3
- /**
4
- *
5
- *
6
- * @export
7
- * @interface ITransportMessage
8
- */
9
- export interface ITransportMessage {
10
- /**
11
- *
12
- *
13
- * @returns {TextMessage}
14
- *
15
- * @memberOf ITransportMessage
16
- */
17
- toMessage(): TextMessage;
18
- /**
19
- *
20
- *
21
- * @param {TextMessage} [message]
22
- * @returns {Buffer}
23
- *
24
- * @memberOf ITransportMessage
25
- */
26
- toBuffer(message?: TextMessage): Buffer;
27
- /**
28
- *
29
- *
30
- * @type {boolean}
31
- * @memberOf ITransportMessage
32
- */
33
- binary: boolean;
34
- /**
35
- *
36
- *
37
- * @type {*}
38
- * @memberOf ITransportMessage
39
- */
40
- data: any;
41
- }
1
+ import { TextMessage } from '../Messages/TextMessage';
2
+
3
+ /**
4
+ * Represents a message that can be transported and converted to/from different formats.
5
+ *
6
+ * @export
7
+ * @interface ITransportMessage
8
+ */
9
+ export interface ITransportMessage {
10
+ /**
11
+ * Converts the transport message into a `TextMessage` instance.
12
+ *
13
+ * @returns {TextMessage} The corresponding `TextMessage` object.
14
+ * @memberOf ITransportMessage
15
+ */
16
+ toMessage(): TextMessage;
17
+
18
+ /**
19
+ * Serializes the message into a `Buffer` format. Optionally accepts a `TextMessage`
20
+ * if the conversion needs to be done on a different message.
21
+ *
22
+ * @param {TextMessage} [message] The `TextMessage` to convert into a `Buffer`.
23
+ * If not provided, defaults to the current `data`.
24
+ * @returns {Buffer} A `Buffer` containing the serialized message data.
25
+ * @memberOf ITransportMessage
26
+ */
27
+ toBuffer(message?: TextMessage): Buffer;
28
+
29
+ /**
30
+ * A flag indicating whether the message contains binary data.
31
+ *
32
+ * @type {boolean}
33
+ * @memberOf ITransportMessage
34
+ */
35
+ isBinary: boolean;
36
+
37
+ /**
38
+ * The raw data associated with the transport message. This can be in various formats
39
+ * such as strings, buffers, etc.
40
+ *
41
+ * @type {*}
42
+ * @memberOf ITransportMessage
43
+ */
44
+ data: any;
45
+ }