thor-io.vnext 2.0.6 → 3.1.0-beta.2
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/{index.d.ts → build/index.d.ts} +11 -8
- package/build/index.js +47 -0
- package/build/src/Connection/ClientInfo.d.ts +27 -0
- package/{src → 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/build/src/Interfaces/IInterceptor.js +2 -0
- 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 -35
- package/licence +21 -21
- package/package.json +48 -49
- package/readme.md +32 -71
- package/src/Connection/ClientInfo.ts +34 -37
- package/src/Connection/Connection.ts +229 -278
- package/src/Connection/IClientInfo.ts +22 -0
- package/src/Controller/ControllerBase.ts +561 -458
- 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 -18
- package/typedoc.json +6 -0
- package/index.js +0 -40
- package/src/Connection/ClientInfo.d.ts +0 -6
- package/src/Connection/Connection.d.ts +0 -24
- package/src/Connection/Connection.js +0 -129
- 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/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/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 -19
- package/src/ThorIO.js +0 -67
- package/src/ThorIO.ts +0 -153
- 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
|
@@ -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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const CanInvoke_1 = require("../../Decorators/CanInvoke");
|
|
13
|
-
const ControllerProperties_1 = require("../../Decorators/ControllerProperties");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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,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
|
+
}
|