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
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BrokerController = void 0;
10
+ const ControllerBase_1 = require("../../Controller/ControllerBase");
11
+ const CanInvoke_1 = require("../../Decorators/CanInvoke");
12
+ const ControllerProperties_1 = require("../../Decorators/ControllerProperties");
13
+ const StringUtils_1 = require("../../Utils/StringUtils");
14
+ const PeerConnection_1 = require("./Models/PeerConnection");
15
+ /**
16
+ *
17
+ *
18
+ * @export
19
+ * @class BrokerController
20
+ * @extends {ControllerBase}
21
+ */
22
+ let BrokerController = class BrokerController extends ControllerBase_1.ControllerBase {
23
+ /**
24
+ * Creates an instance of BrokerController.
25
+ *
26
+ * @param {Connection} connection
27
+ *
28
+ * @memberOf BrokerController
29
+ */
30
+ constructor(connection) {
31
+ super(connection);
32
+ /**
33
+ *
34
+ *
35
+ * @type {string}
36
+ * @memberOf BrokerController
37
+ */
38
+ this.localPeerId = "";
39
+ this.Connections = [];
40
+ this.Peer = new PeerConnection_1.PeerConnection(StringUtils_1.StringUtils.newGuid(), connection.id);
41
+ }
42
+ /**
43
+ *
44
+ *
45
+ *
46
+ * @memberOf BrokerController
47
+ */
48
+ onopen() {
49
+ this.invoke(this.Peer, "contextCreated", this.alias);
50
+ }
51
+ /**
52
+ *
53
+ *
54
+ * @param {*} data
55
+ * @param {string} topic
56
+ * @param {string} controller
57
+ *
58
+ * @memberOf BrokerController
59
+ */
60
+ instantMessage(data, topic, controller) {
61
+ /**
62
+ *
63
+ *
64
+ * @param {ControllerBase} pre
65
+ * @returns
66
+ */
67
+ var expression = (pre) => {
68
+ return pre.Peer.context >= this.Peer.context;
69
+ };
70
+ this.invokeTo(expression, data, "instantMessage", this.alias);
71
+ }
72
+ /**
73
+ *
74
+ *
75
+ * @param {PeerConnection} change
76
+ *
77
+ * @memberOf BrokerCControllerPropertiesontroller
78
+ */
79
+ changeContext(change) {
80
+ this.Peer.context = change.context;
81
+ this.invoke(this.Peer, "contextChanged", this.alias);
82
+ }
83
+ /**
84
+ *
85
+ *
86
+ * @param {Signal} signal
87
+ *
88
+ * @memberOf BrokerController
89
+ */
90
+ contextSignal(signal) {
91
+ /**
92
+ *
93
+ *
94
+ * @param {BrokerController} pre
95
+ * @returns
96
+ */
97
+ let expression = (pre) => {
98
+ return pre.connection.id === signal.recipient;
99
+ };
100
+ this.invokeTo(expression, signal, "contextSignal", this.alias);
101
+ }
102
+ /**
103
+ *
104
+ *
105
+ *
106
+ * @memberOf BrokerController
107
+ */
108
+ connectContext() {
109
+ let connections = this.getPeerConnections(this.Peer)
110
+ .map((p) => {
111
+ return p.Peer;
112
+ });
113
+ this.invoke(connections, "connectTo", this.alias);
114
+ }
115
+ /**
116
+ *
117
+ *
118
+ * @param {PeerConnection} peerConnetion
119
+ * @returns {Array<BrokerController>}
120
+ *
121
+ * @memberOf BrokerController
122
+ */
123
+ getPeerConnections(peerConnetion) {
124
+ let match = this.findOn(this.alias, (pre) => {
125
+ return pre.Peer.context === this.Peer.context && pre.Peer.peerId !== peerConnetion.peerId;
126
+ });
127
+ return match ? match : new Array;
128
+ }
129
+ };
130
+ __decorate([
131
+ CanInvoke_1.CanInvoke(true)
132
+ ], BrokerController.prototype, "instantMessage", null);
133
+ __decorate([
134
+ CanInvoke_1.CanInvoke(true)
135
+ ], BrokerController.prototype, "changeContext", null);
136
+ __decorate([
137
+ CanInvoke_1.CanInvoke(true)
138
+ ], BrokerController.prototype, "contextSignal", null);
139
+ __decorate([
140
+ CanInvoke_1.CanInvoke(true)
141
+ ], BrokerController.prototype, "connectContext", null);
142
+ BrokerController = __decorate([
143
+ ControllerProperties_1.ControllerProperties("contextBroker", false, 7500)
144
+ ], BrokerController);
145
+ exports.BrokerController = BrokerController;
@@ -0,0 +1,61 @@
1
+ import { Connection } from '../../Connection/Connection';
2
+ import { ControllerBase } from '../../Controller/ControllerBase';
3
+ import { PeerConnection } from './Models/PeerConnection';
4
+ import { Signal } from './Models/Signal';
5
+ /**
6
+ * BrokerController class for managing peer connections and signals.
7
+ */
8
+ export declare class BrokerController extends ControllerBase {
9
+ /**
10
+ * An array of peer connections.
11
+ */
12
+ Connections: Array<PeerConnection>;
13
+ /**
14
+ * The current peer connection.
15
+ */
16
+ Peer: PeerConnection;
17
+ /**
18
+ * The local peer ID.
19
+ */
20
+ localPeerId: string;
21
+ /**
22
+ * Creates an instance of BrokerController.
23
+ * @param {Connection} connection The connection instance.
24
+ */
25
+ constructor(connection: Connection);
26
+ [key: string]: any;
27
+ /**
28
+ * Called when the connection is opened.
29
+ */
30
+ onopen(): void;
31
+ transcribe(data: {
32
+ phrase: string;
33
+ sourceLanguage: string;
34
+ }): void;
35
+ private generateSubtitles;
36
+ /**
37
+ * Sends an instant message to peers.
38
+ * @param {any} data The message data.
39
+ */
40
+ instantMessage(data: any): void;
41
+ /**
42
+ * Changes the context of the current peer.
43
+ * @param {PeerConnection} change The new peer connection context.
44
+ */
45
+ changeContext(change: PeerConnection): void;
46
+ /**
47
+ * Sends a signal to a specific peer.
48
+ * @param {Signal} signal The signal data.
49
+ */
50
+ contextSignal(signal: Signal): void;
51
+ /**
52
+ * Connects to peers in the same context.
53
+ */
54
+ connectContext(): void;
55
+ /**
56
+ * Gets peer connections in the same context.
57
+ * @param {PeerConnection} peerConnection The current peer connection.
58
+ * @returns {Array<BrokerController>} An array of matching peer controllers.
59
+ */
60
+ getPeerConnections(peerConnection: PeerConnection): Array<BrokerController>;
61
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BrokerController = void 0;
10
+ const ControllerBase_1 = require("../../Controller/ControllerBase");
11
+ const CanInvoke_1 = require("../../Decorators/CanInvoke");
12
+ const ControllerProperties_1 = require("../../Decorators/ControllerProperties");
13
+ const StringUtils_1 = require("../../Utils/StringUtils");
14
+ const PeerConnection_1 = require("./Models/PeerConnection");
15
+ /**
16
+ * BrokerController class for managing peer connections and signals.
17
+ */
18
+ let BrokerController = class BrokerController extends ControllerBase_1.ControllerBase {
19
+ /**
20
+ * Creates an instance of BrokerController.
21
+ * @param {Connection} connection The connection instance.
22
+ */
23
+ constructor(connection) {
24
+ super(connection);
25
+ /**
26
+ * The local peer ID.
27
+ */
28
+ this.localPeerId = "";
29
+ this.Connections = [];
30
+ this.Peer = new PeerConnection_1.PeerConnection(StringUtils_1.StringUtils.newGuid(), connection.id);
31
+ }
32
+ /**
33
+ * Called when the connection is opened.
34
+ */
35
+ onopen() {
36
+ this.invoke(this.Peer, "contextCreated", this.alias);
37
+ }
38
+ transcribe(data) {
39
+ if (!this.generateSubtitles()) {
40
+ return;
41
+ }
42
+ console.log(`Transcribing ${data.phrase} from ${data.sourceLanguage} to ${this.Peer.language}`);
43
+ }
44
+ generateSubtitles() {
45
+ return this.Peer.language != undefined;
46
+ }
47
+ /**
48
+ * Sends an instant message to peers.
49
+ * @param {any} data The message data.
50
+ */
51
+ instantMessage(data) {
52
+ const expression = (pre) => {
53
+ return pre.Peer.context >= this.Peer.context;
54
+ };
55
+ this.invokeTo(expression, data, "instantMessage", this.alias);
56
+ }
57
+ /**
58
+ * Changes the context of the current peer.
59
+ * @param {PeerConnection} change The new peer connection context.
60
+ */
61
+ changeContext(change) {
62
+ this.Peer.context = change.context;
63
+ this.invoke(this.Peer, "contextChanged", this.alias);
64
+ }
65
+ /**
66
+ * Sends a signal to a specific peer.
67
+ * @param {Signal} signal The signal data.
68
+ */
69
+ contextSignal(signal) {
70
+ const expression = (pre) => {
71
+ return pre.connection.id === signal.recipient;
72
+ };
73
+ this.invokeTo(expression, signal, "contextSignal", this.alias);
74
+ }
75
+ /**
76
+ * Connects to peers in the same context.
77
+ */
78
+ connectContext() {
79
+ const connections = this.getPeerConnections(this.Peer)
80
+ .map((p) => {
81
+ return p.Peer;
82
+ });
83
+ this.invoke(connections, "connectTo", this.alias);
84
+ }
85
+ /**
86
+ * Gets peer connections in the same context.
87
+ * @param {PeerConnection} peerConnection The current peer connection.
88
+ * @returns {Array<BrokerController>} An array of matching peer controllers.
89
+ */
90
+ getPeerConnections(peerConnection) {
91
+ const match = this.findOn(this.alias, (pre) => {
92
+ return (pre.Peer.context === this.Peer.context && pre.Peer.peerId !== peerConnection.peerId);
93
+ });
94
+ return match ? match : new Array();
95
+ }
96
+ };
97
+ exports.BrokerController = BrokerController;
98
+ __decorate([
99
+ (0, CanInvoke_1.CanInvoke)(true)
100
+ ], BrokerController.prototype, "transcribe", null);
101
+ __decorate([
102
+ (0, CanInvoke_1.CanInvoke)(true)
103
+ ], BrokerController.prototype, "instantMessage", null);
104
+ __decorate([
105
+ (0, CanInvoke_1.CanInvoke)(true)
106
+ ], BrokerController.prototype, "changeContext", null);
107
+ __decorate([
108
+ (0, CanInvoke_1.CanInvoke)(true)
109
+ ], BrokerController.prototype, "contextSignal", null);
110
+ __decorate([
111
+ (0, CanInvoke_1.CanInvoke)(true)
112
+ ], BrokerController.prototype, "connectContext", null);
113
+ exports.BrokerController = BrokerController = __decorate([
114
+ (0, ControllerProperties_1.ControllerProperties)("contextBroker", 7500)
115
+ ], BrokerController);
@@ -1,85 +1,74 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const CanInvoke_1 = require("../../Decorators/CanInvoke");
13
- const Connection_1 = require("../../Connection");
14
- const ControllerProperties_1 = require("../../Decorators/ControllerProperties");
15
- const PeerConnection_1 = require("./Models/PeerConnection");
16
- const Signal_1 = require("./Models/Signal");
17
- const StringUtils_1 = require("../../Utils/StringUtils");
18
- const ControllerBase_1 = require("../../Controller/ControllerBase");
19
- let BrokerController = class BrokerController extends ControllerBase_1.ControllerBase {
20
- constructor(connection) {
21
- super(connection);
22
- this.Connections = [];
23
- }
24
- onopen() {
25
- this.Peer = new PeerConnection_1.PeerConnection(StringUtils_1.StringUtils.newGuid(), this.connection.id);
26
- this.invoke(this.Peer, "contextCreated", this.alias);
27
- }
28
- instantMessage(data, topic, controller) {
29
- var expression = (pre) => {
30
- return pre.Peer.context >= this.Peer.context;
31
- };
32
- this.invokeTo(expression, data, "instantMessage", this.alias);
33
- }
34
- changeContext(change) {
35
- this.Peer.context = change.context;
36
- this.invoke(this.Peer, "contextChanged", this.alias);
37
- }
38
- contextSignal(signal) {
39
- let expression = (pre) => {
40
- return pre.connection.id === signal.recipient;
41
- };
42
- this.invokeTo(expression, signal, "contextSignal", this.alias);
43
- }
44
- connectContext() {
45
- let connections = this.getPeerConnections(this.Peer).map((p) => {
46
- return p.Peer;
47
- });
48
- this.invoke(connections, "connectTo", this.alias);
49
- }
50
- getPeerConnections(peerConnetion) {
51
- let match = this.findOn(this.alias, (pre) => {
52
- return pre.Peer.context === this.Peer.context && pre.Peer.peerId !== peerConnetion.peerId;
53
- });
54
- return match;
55
- }
56
- };
57
- __decorate([
58
- CanInvoke_1.CanInvoke(true),
59
- __metadata("design:type", Function),
60
- __metadata("design:paramtypes", [Object, String, String]),
61
- __metadata("design:returntype", void 0)
62
- ], BrokerController.prototype, "instantMessage", null);
63
- __decorate([
64
- CanInvoke_1.CanInvoke(true),
65
- __metadata("design:type", Function),
66
- __metadata("design:paramtypes", [PeerConnection_1.PeerConnection]),
67
- __metadata("design:returntype", void 0)
68
- ], BrokerController.prototype, "changeContext", null);
69
- __decorate([
70
- CanInvoke_1.CanInvoke(true),
71
- __metadata("design:type", Function),
72
- __metadata("design:paramtypes", [Signal_1.Signal]),
73
- __metadata("design:returntype", void 0)
74
- ], BrokerController.prototype, "contextSignal", null);
75
- __decorate([
76
- CanInvoke_1.CanInvoke(true),
77
- __metadata("design:type", Function),
78
- __metadata("design:paramtypes", []),
79
- __metadata("design:returntype", void 0)
80
- ], BrokerController.prototype, "connectContext", null);
81
- BrokerController = __decorate([
82
- ControllerProperties_1.ControllerProperties("contextBroker", false, 7500),
83
- __metadata("design:paramtypes", [Connection_1.Connection])
84
- ], BrokerController);
85
- exports.BrokerController = BrokerController;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var BrokerController_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BrokerController = void 0;
11
+ const ControllerBase_1 = require("../../Controller/ControllerBase");
12
+ const CanInvoke_1 = require("../../Decorators/CanInvoke");
13
+ const ControllerProperties_1 = require("../../Decorators/ControllerProperties");
14
+ const StringUtils_1 = require("../../Utils/StringUtils");
15
+ const PeerConnection_1 = require("./Models/PeerConnection");
16
+ let BrokerController = BrokerController_1 = class BrokerController extends ControllerBase_1.ControllerBase {
17
+ constructor(connection) {
18
+ super(connection);
19
+ this.localPeerId = "";
20
+ this.Connections = [];
21
+ this.Peer = new PeerConnection_1.PeerConnection(StringUtils_1.StringUtils.newGuid(), connection.id);
22
+ }
23
+ onopen() {
24
+ this.invoke(this.Peer, "contextCreated", this.alias);
25
+ }
26
+ instantMessage(data, topic, controller) {
27
+ var expression = (pre) => {
28
+ return pre.Peer.context >= this.Peer.context;
29
+ };
30
+ this.invokeTo(expression, data, "instantMessage", this.alias);
31
+ }
32
+ changeContext(change) {
33
+ this.Peer.context = change.context;
34
+ this.invoke(this.Peer, "contextChanged", this.alias);
35
+ }
36
+ contextSignal(signal) {
37
+ let expression = (pre) => {
38
+ return pre.connection.id === signal.recipient;
39
+ };
40
+ this.invokeTo(expression, signal, "contextSignal", this.alias);
41
+ }
42
+ connectContext() {
43
+ let connections = this.getPeerConnections(this.Peer)
44
+ .map((p) => {
45
+ return p.Peer;
46
+ });
47
+ this.invoke(connections, "connectTo", this.alias);
48
+ }
49
+ getPeerConnections(peerConnetion) {
50
+ let match = this.findOn(this.alias, (pre) => {
51
+ return (pre.Peer.context === this.Peer.context && pre.Peer.peerId !== peerConnetion.peerId);
52
+ });
53
+ return match ? match : new Array();
54
+ }
55
+ new(connection) {
56
+ return new BrokerController_1(connection);
57
+ }
58
+ };
59
+ __decorate([
60
+ CanInvoke_1.CanInvoke(true)
61
+ ], BrokerController.prototype, "instantMessage", null);
62
+ __decorate([
63
+ CanInvoke_1.CanInvoke(true)
64
+ ], BrokerController.prototype, "changeContext", null);
65
+ __decorate([
66
+ CanInvoke_1.CanInvoke(true)
67
+ ], BrokerController.prototype, "contextSignal", null);
68
+ __decorate([
69
+ CanInvoke_1.CanInvoke(true)
70
+ ], BrokerController.prototype, "connectContext", null);
71
+ BrokerController = BrokerController_1 = __decorate([
72
+ ControllerProperties_1.ControllerProperties("contextBroker", 7500)
73
+ ], BrokerController);
74
+ exports.BrokerController = BrokerController;
@@ -0,0 +1,7 @@
1
+ export declare class PeerConnection {
2
+ context: string;
3
+ peerId: string;
4
+ language: string | undefined;
5
+ constructor(context: string, peerId: string);
6
+ setLanguage(language: string): void;
7
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PeerConnection = void 0;
4
+ class PeerConnection {
5
+ constructor(context, peerId) {
6
+ this.peerId = ""; // The unique identifier for the peer. Defaults to an empty string.
7
+ this.context = context; // Initializes the context of the connection.
8
+ this.peerId = peerId; // Initializes the peer's unique identifier.
9
+ }
10
+ setLanguage(language) {
11
+ this.language = language;
12
+ }
13
+ }
14
+ exports.PeerConnection = PeerConnection;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Signal = void 0;
4
+ class Signal {
5
+ constructor(recipient, sender, message) {
6
+ this.recipient = recipient; // Initializes the recipient
7
+ this.sender = sender; // Initializes the sender
8
+ this.message = message; // Initializes the message
9
+ }
10
+ }
11
+ exports.Signal = Signal;
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ /**
3
+ * A decorator to define whether a method can be invoked, with optional alias support.
4
+ *
5
+ * @param state Boolean indicating whether the method can be invoked.
6
+ * @param alias Optional alias for the method.
7
+ *
8
+ * @returns A function that adds metadata to the method.
9
+ */
10
+ export declare function CanInvoke(state: boolean, alias?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CanInvoke = CanInvoke;
4
+ require("reflect-metadata");
5
+ /**
6
+ * A decorator to define whether a method can be invoked, with optional alias support.
7
+ *
8
+ * @param state Boolean indicating whether the method can be invoked.
9
+ * @param alias Optional alias for the method.
10
+ *
11
+ * @returns A function that adds metadata to the method.
12
+ */
13
+ function CanInvoke(state, alias) {
14
+ return (target, propertyKey, descriptor) => {
15
+ // Define metadata for whether the method can be invoked
16
+ Reflect.defineMetadata("canInvoke", state, target, propertyKey);
17
+ // Optionally add an alias if provided
18
+ if (alias) {
19
+ Reflect.defineMetadata("alias", alias, target, propertyKey);
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ /**
3
+ * A decorator that attaches metadata to a property indicating whether it can be set or get.
4
+ *
5
+ * @param canSet Boolean indicating if the property can be set.
6
+ * @param canGet Optional boolean indicating if the property can be gotten (defaults to `canSet` if not provided).
7
+ *
8
+ * @returns A function that adds metadata to the property.
9
+ */
10
+ export declare function CanSetGet(canSet: boolean, canGet?: boolean): (target: Object, propertyKey: string) => void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CanSetGet = CanSetGet;
4
+ require("reflect-metadata");
5
+ /**
6
+ * A decorator that attaches metadata to a property indicating whether it can be set or get.
7
+ *
8
+ * @param canSet Boolean indicating if the property can be set.
9
+ * @param canGet Optional boolean indicating if the property can be gotten (defaults to `canSet` if not provided).
10
+ *
11
+ * @returns A function that adds metadata to the property.
12
+ */
13
+ function CanSetGet(canSet, canGet) {
14
+ return function (target, propertyKey) {
15
+ // Attach 'canSet' metadata
16
+ Reflect.defineMetadata("canSet", canSet, target, propertyKey);
17
+ // Attach 'canGet' metadata, defaulting to 'canSet' if not provided
18
+ Reflect.defineMetadata("canGet", canGet !== null && canGet !== void 0 ? canGet : canSet, target, propertyKey);
19
+ };
20
+ }
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ /**
3
+ * A decorator to attach custom metadata to a controller class.
4
+ *
5
+ * @param alias The alias for the controller (used for routing or identification).
6
+ * @param heartbeatInterval Optional interval in milliseconds for the heartbeat. Defaults to -1.
7
+ *
8
+ * @returns A function that adds metadata to the target class.
9
+ */
10
+ export declare function ControllerProperties(alias: string, heartbeatInterval?: number): (target: Function) => void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ControllerProperties = ControllerProperties;
4
+ require("reflect-metadata");
5
+ /**
6
+ * A decorator to attach custom metadata to a controller class.
7
+ *
8
+ * @param alias The alias for the controller (used for routing or identification).
9
+ * @param heartbeatInterval Optional interval in milliseconds for the heartbeat. Defaults to -1.
10
+ *
11
+ * @returns A function that adds metadata to the target class.
12
+ */
13
+ function ControllerProperties(alias, heartbeatInterval) {
14
+ return function (target) {
15
+ // Attach alias to the class
16
+ Reflect.defineMetadata("alias", alias, target);
17
+ // Attach heartbeat interval to the class (default to -1 if not provided)
18
+ Reflect.defineMetadata("heartbeatInterval", heartbeatInterval !== null && heartbeatInterval !== void 0 ? heartbeatInterval : -1, target);
19
+ };
20
+ }
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class InstantMessage {
4
- }
5
- exports.InstantMessage = InstantMessage;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });