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.
- package/.gitattributes +17 -17
- package/build/index.d.ts +24 -0
- package/build/index.js +47 -0
- package/build/src/Connection/ClientInfo.d.ts +27 -0
- package/{src/Client → build/src/Connection}/ClientInfo.js +7 -0
- package/build/src/Connection/Connection.d.ts +117 -0
- package/build/src/Connection/Connection.js +202 -0
- package/build/src/Connection/IClientInfo.d.ts +20 -0
- package/build/src/Controller/ControllerBase.d.ts +134 -0
- package/build/src/Controller/ControllerBase.js +543 -0
- package/build/src/Controller/Subscription.d.ts +27 -0
- package/build/src/Controller/Subscription.js +22 -0
- package/build/src/Controllers/BrokerController/Broker.js +145 -0
- package/build/src/Controllers/BrokerController/BrokerController.d.ts +61 -0
- package/build/src/Controllers/BrokerController/BrokerController.js +115 -0
- package/{src/Controllers/BrokerController/Broker.js → build/src/Controllers/BrokerController/BrokerrController.js} +74 -85
- package/build/src/Controllers/BrokerController/Models/PeerConnection.d.ts +7 -0
- package/build/src/Controllers/BrokerController/Models/PeerConnection.js +14 -0
- package/build/src/Controllers/BrokerController/Models/Signal.js +11 -0
- package/build/src/Decorators/CanInvoke.d.ts +10 -0
- package/build/src/Decorators/CanInvoke.js +22 -0
- package/build/src/Decorators/CanSet.d.ts +10 -0
- package/build/src/Decorators/CanSet.js +20 -0
- package/build/src/Decorators/ControllerProperties.d.ts +10 -0
- package/build/src/Decorators/ControllerProperties.js +20 -0
- package/{src/Controllers/BrokerController/Models/InstantMessage.js → build/src/Interfaces/IInterceptor.js} +2 -5
- package/build/src/Interfaces/ITransport.d.ts +94 -0
- package/build/src/Interfaces/ITransportMessage.d.ts +41 -0
- package/build/src/Messages/BufferMessage.d.ts +38 -0
- package/{src → build/src}/Messages/BufferMessage.js +32 -2
- package/build/src/Messages/ErrorMessage.d.ts +29 -0
- package/build/src/Messages/ErrorMessage.js +22 -0
- package/build/src/Messages/PipeMessage.d.ts +46 -0
- package/build/src/Messages/PipeMessage.js +41 -0
- package/build/src/Messages/TextMessage.d.ts +88 -0
- package/build/src/Messages/TextMessage.js +94 -0
- package/build/src/Messages/WebSocketMessage.d.ts +34 -0
- package/build/src/Messages/WebSocketMessage.js +41 -0
- package/build/src/Plugin.js +32 -0
- package/build/src/Server/Plugin.d.ts +37 -0
- package/build/src/Server/Plugin.js +32 -0
- package/build/src/Server/ThorIOServer.d.ts +68 -0
- package/build/src/Server/ThorIOServer.js +131 -0
- package/build/src/Subscription.js +22 -0
- package/build/src/ThorIO.js +142 -0
- package/build/src/ThorIOServer.d.ts +64 -0
- package/build/src/ThorIOServer.js +131 -0
- package/build/src/Transports/BufferMessageTransport.d.ts +78 -0
- package/build/src/Transports/BufferMessageTransport.js +85 -0
- package/build/src/Transports/PipeMessageTransport.d.ts +79 -0
- package/build/src/Transports/PipeMessageTransport.js +90 -0
- package/build/src/Transports/WebSocketMessageTransport.d.ts +87 -0
- package/build/src/Transports/WebSocketMessageTransport.js +93 -0
- package/build/src/Utils/BufferUtils.d.ts +32 -0
- package/build/src/Utils/BufferUtils.js +57 -0
- package/build/src/Utils/StringUtils.d.ts +15 -0
- package/build/src/Utils/StringUtils.js +31 -0
- package/build/src/test.js +5 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +43 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1610 -0
- package/docs/classes/BrokerController.html +164 -0
- package/docs/classes/BufferMessage.html +11 -0
- package/docs/classes/BufferMessageTransport.html +31 -0
- package/docs/classes/BufferUtils.html +16 -0
- package/docs/classes/ClientInfo.html +11 -0
- package/docs/classes/Connection.html +42 -0
- package/docs/classes/ControllerBase.html +144 -0
- package/docs/classes/ErrorMessage.html +13 -0
- package/docs/classes/PeerConnection.html +4 -0
- package/docs/classes/PipeMessage.html +17 -0
- package/docs/classes/PipeMessageTransport.html +33 -0
- package/docs/classes/Plugin.html +13 -0
- package/docs/classes/Signal.html +5 -0
- package/docs/classes/StringUtils.html +9 -0
- package/docs/classes/Subscription.html +11 -0
- package/docs/classes/TextMessage.html +37 -0
- package/docs/classes/ThorIOServer.html +25 -0
- package/docs/classes/WebSocketMessage.html +18 -0
- package/docs/classes/WebSocketMessageTransport.html +35 -0
- package/docs/functions/CanInvoke.html +5 -0
- package/docs/functions/CanSet.html +5 -0
- package/docs/functions/ControllerProperties.html +5 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +24 -0
- package/docs/interfaces/ITransport.html +46 -0
- package/docs/interfaces/ITransportMessage.html +21 -0
- package/docs/modules.html +1 -0
- package/index.ts +32 -37
- package/licence +21 -21
- package/package.json +48 -50
- package/readme.md +32 -1
- package/src/{Client → Connection}/ClientInfo.ts +34 -43
- package/src/Connection/Connection.ts +229 -0
- package/src/Connection/IClientInfo.ts +22 -0
- package/src/Controller/ControllerBase.ts +561 -457
- package/src/{Subscription.ts → Controller/Subscription.ts} +32 -34
- package/src/Controllers/BrokerController/BrokerController.ts +121 -0
- package/src/Controllers/BrokerController/Models/PeerConnection.ts +12 -34
- package/src/Controllers/BrokerController/Models/Signal.ts +11 -43
- package/src/Decorators/CanInvoke.ts +21 -13
- package/src/Decorators/CanSet.ts +19 -12
- package/src/Decorators/ControllerProperties.ts +19 -16
- package/src/Interfaces/ITransport.ts +107 -23
- package/src/Interfaces/ITransportMessage.ts +45 -41
- package/src/Messages/BufferMessage.ts +70 -69
- package/src/Messages/ErrorMessage.ts +34 -6
- package/src/Messages/PipeMessage.ts +56 -62
- package/src/Messages/TextMessage.ts +139 -93
- package/src/Messages/WebSocketMessage.ts +39 -41
- package/src/Server/Plugin.ts +56 -0
- package/src/Server/ThorIOServer.ts +121 -0
- package/src/ThorIOServer.ts +117 -0
- package/src/Transports/BufferMessageTransport.ts +109 -100
- package/src/Transports/PipeMessageTransport.ts +112 -104
- package/src/Transports/WebSocketMessageTransport.ts +122 -110
- package/src/Utils/BufferUtils.ts +55 -61
- package/src/Utils/StringUtils.ts +28 -17
- package/tsconfig.json +109 -19
- package/typedoc.json +6 -0
- package/index.d.ts +0 -24
- package/index.js +0 -46
- package/src/Client/ClientInfo.d.ts +0 -6
- package/src/Connection.d.ts +0 -24
- package/src/Connection.js +0 -121
- package/src/Connection.ts +0 -263
- package/src/Controller/ControllerBase.d.ts +0 -43
- package/src/Controller/ControllerBase.js +0 -331
- package/src/Controllers/BrokerController/Broker.d.ts +0 -21
- package/src/Controllers/BrokerController/Broker.ts +0 -153
- package/src/Controllers/BrokerController/Models/InstantMessage.d.ts +0 -3
- package/src/Controllers/BrokerController/Models/InstantMessage.ts +0 -15
- package/src/Controllers/BrokerController/Models/PeerConnection.d.ts +0 -5
- package/src/Controllers/BrokerController/Models/PeerConnection.js +0 -9
- package/src/Controllers/BrokerController/Models/Signal.js +0 -10
- package/src/Decorators/CanInvoke.d.ts +0 -2
- package/src/Decorators/CanInvoke.js +0 -9
- package/src/Decorators/CanSet.d.ts +0 -1
- package/src/Decorators/CanSet.js +0 -8
- package/src/Decorators/ControllerProperties.d.ts +0 -1
- package/src/Decorators/ControllerProperties.js +0 -10
- package/src/Interfaces/IInterceptor.d.ts +0 -2
- package/src/Interfaces/IInterceptor.ts +0 -2
- package/src/Interfaces/ITransport.d.ts +0 -18
- package/src/Interfaces/ITransportMessage.d.ts +0 -8
- package/src/Listener.d.ts +0 -5
- package/src/Listener.js +0 -9
- package/src/Listener.ts +0 -34
- package/src/Messages/BufferMessage.d.ts +0 -10
- package/src/Messages/ErrorMessage.d.ts +0 -4
- package/src/Messages/ErrorMessage.js +0 -8
- package/src/Messages/PipeMessage.d.ts +0 -12
- package/src/Messages/PipeMessage.js +0 -20
- package/src/Messages/TextMessage.d.ts +0 -15
- package/src/Messages/TextMessage.js +0 -50
- package/src/Messages/WebSocketMessage.d.ts +0 -10
- package/src/Messages/WebSocketMessage.js +0 -15
- package/src/Plugin.d.ts +0 -6
- package/src/Plugin.js +0 -11
- package/src/Plugin.ts +0 -37
- package/src/Subscription.d.ts +0 -5
- package/src/Subscription.js +0 -9
- package/src/ThorIO.d.ts +0 -18
- package/src/ThorIO.js +0 -65
- package/src/ThorIO.ts +0 -148
- package/src/Transports/BufferMessageTransport.d.ts +0 -21
- package/src/Transports/BufferMessageTransport.js +0 -31
- package/src/Transports/PipeMessageTransport.d.ts +0 -20
- package/src/Transports/PipeMessageTransport.js +0 -33
- package/src/Transports/WebSocketMessageTransport.d.ts +0 -20
- package/src/Transports/WebSocketMessageTransport.js +0 -31
- package/src/Utils/BufferUtils.d.ts +0 -5
- package/src/Utils/BufferUtils.js +0 -29
- package/src/Utils/StringUtils.d.ts +0 -4
- package/src/Utils/StringUtils.js +0 -13
- /package/{src/Interfaces/IInterceptor.js → build/src/Connection/IClientInfo.js} +0 -0
- /package/{src → build/src}/Controllers/BrokerController/Models/Signal.d.ts +0 -0
- /package/{src → build/src}/Interfaces/ITransport.js +0 -0
- /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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @type {string}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of Subscription.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} topic
|
|
26
|
-
* @param {string} controller
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
}
|
package/src/Decorators/CanSet.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Reflect.defineMetadata("
|
|
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 {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @interface ITransportMessage
|
|
8
|
-
*/
|
|
9
|
-
export interface ITransportMessage {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @returns {TextMessage}
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
}
|