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
package/src/Connection.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Plugin } from './Plugin';
|
|
2
|
-
import { ClientInfo } from './Client/ClientInfo';
|
|
3
|
-
import { ITransport } from './Interfaces/ITransport';
|
|
4
|
-
import { ControllerBase } from './Controller/ControllerBase';
|
|
5
|
-
export declare class Connection {
|
|
6
|
-
transport: ITransport;
|
|
7
|
-
connections: Map<string, Connection>;
|
|
8
|
-
private controllers;
|
|
9
|
-
errors: Array<any>;
|
|
10
|
-
pingPongInterval: number;
|
|
11
|
-
controllerInstances: Map<string, ControllerBase>;
|
|
12
|
-
clientInfo: ClientInfo;
|
|
13
|
-
private methodInvoker;
|
|
14
|
-
get id(): string;
|
|
15
|
-
constructor(transport: ITransport, connections: Map<string, Connection>, controllers: Array<Plugin<ControllerBase>>);
|
|
16
|
-
private addError;
|
|
17
|
-
hasController(alias: string): boolean;
|
|
18
|
-
removeController(alias: string): boolean;
|
|
19
|
-
getController(alias: string): ControllerBase;
|
|
20
|
-
private addControllerInstance;
|
|
21
|
-
private registerSealdController;
|
|
22
|
-
resolveController(alias: string): Plugin<ControllerBase>;
|
|
23
|
-
locateController(alias: string): ControllerBase;
|
|
24
|
-
}
|
package/src/Connection.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const TextMessage_1 = require("./Messages/TextMessage");
|
|
4
|
-
const ClientInfo_1 = require("./Client/ClientInfo");
|
|
5
|
-
class Connection {
|
|
6
|
-
constructor(transport, connections, controllers) {
|
|
7
|
-
this.transport = transport;
|
|
8
|
-
this.connections = connections;
|
|
9
|
-
this.controllers = controllers;
|
|
10
|
-
this.connections = connections;
|
|
11
|
-
this.controllerInstances = new Map();
|
|
12
|
-
this.errors = [];
|
|
13
|
-
if (transport) {
|
|
14
|
-
this.transport.onMessage = (event) => {
|
|
15
|
-
try {
|
|
16
|
-
if (!event.binary) {
|
|
17
|
-
let message = event.toMessage();
|
|
18
|
-
let controller = this.locateController(message.C);
|
|
19
|
-
if (controller)
|
|
20
|
-
this.methodInvoker(controller, message.T, message.D);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
let message = TextMessage_1.TextMessage.fromArrayBuffer(event.data);
|
|
24
|
-
let controller = this.locateController(message.C);
|
|
25
|
-
if (controller)
|
|
26
|
-
this.methodInvoker(controller, message.T, message.D, message.B);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
this.addError(error);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
methodInvoker(controller, method, data, buffer) {
|
|
36
|
-
try {
|
|
37
|
-
if (!controller.canInvokeMethod(method))
|
|
38
|
-
throw "method '" + method + "' cant be invoked.";
|
|
39
|
-
if (typeof (controller[method]) === "function") {
|
|
40
|
-
controller[method].apply(controller, [JSON.parse(data), method,
|
|
41
|
-
controller.alias, buffer]);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
let prop = method;
|
|
45
|
-
let propValue = JSON.parse(data);
|
|
46
|
-
if (typeof (controller[prop]) === typeof (propValue))
|
|
47
|
-
controller[prop] = propValue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (ex) {
|
|
51
|
-
controller.invokeError(ex);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
get id() {
|
|
55
|
-
return this.transport.id;
|
|
56
|
-
}
|
|
57
|
-
addError(error) {
|
|
58
|
-
this.errors.push(error);
|
|
59
|
-
}
|
|
60
|
-
hasController(alias) {
|
|
61
|
-
return this.controllerInstances.has(alias);
|
|
62
|
-
}
|
|
63
|
-
removeController(alias) {
|
|
64
|
-
return this.controllerInstances.delete(alias);
|
|
65
|
-
}
|
|
66
|
-
getController(alias) {
|
|
67
|
-
try {
|
|
68
|
-
let match = this.controllerInstances.get(alias);
|
|
69
|
-
if (!match)
|
|
70
|
-
throw `cannot locate the requested controller ${alias}`;
|
|
71
|
-
return match;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
addControllerInstance(controller) {
|
|
78
|
-
this.controllerInstances.set(controller.alias, controller);
|
|
79
|
-
return controller;
|
|
80
|
-
}
|
|
81
|
-
registerSealdController() {
|
|
82
|
-
throw "not yet implemented";
|
|
83
|
-
}
|
|
84
|
-
resolveController(alias) {
|
|
85
|
-
try {
|
|
86
|
-
let resolvedController = this.controllers.find((resolve) => {
|
|
87
|
-
return resolve.alias === alias && Reflect.getMetadata("seald", resolve.instance) === false;
|
|
88
|
-
});
|
|
89
|
-
return resolvedController;
|
|
90
|
-
}
|
|
91
|
-
catch (_a) {
|
|
92
|
-
throw `Cannot resolve ${alias},controller unknown.`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
locateController(alias) {
|
|
96
|
-
try {
|
|
97
|
-
let match = this.getController(alias);
|
|
98
|
-
if (match) {
|
|
99
|
-
return match;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
let resolved = this.resolveController(alias);
|
|
103
|
-
let controllerInstance = new resolved.instance(this);
|
|
104
|
-
this.addControllerInstance(controllerInstance);
|
|
105
|
-
controllerInstance.invoke(new ClientInfo_1.ClientInfo(this.id, controllerInstance.alias), "___open", controllerInstance.alias);
|
|
106
|
-
if (controllerInstance.onopen)
|
|
107
|
-
controllerInstance.onopen();
|
|
108
|
-
this.transport.onClose = (e) => {
|
|
109
|
-
if (controllerInstance.onclose)
|
|
110
|
-
controllerInstance.onclose();
|
|
111
|
-
};
|
|
112
|
-
return controllerInstance;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
this.transport.close(1011, "Cannot locate the specified controller,it may be seald or the the alias in unknown '" + alias + "'. connection closed");
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.Connection = Connection;
|
package/src/Connection.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { Plugin } from './Plugin';
|
|
2
|
-
import { TextMessage } from './Messages/TextMessage';
|
|
3
|
-
import { ClientInfo } from './Client/ClientInfo';
|
|
4
|
-
import { ITransport } from './Interfaces/ITransport';
|
|
5
|
-
import { ITransportMessage } from './Interfaces/ITransportMessage';
|
|
6
|
-
import { ControllerBase } from './Controller/ControllerBase';
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @export
|
|
11
|
-
* @class Connection
|
|
12
|
-
*/
|
|
13
|
-
export class Connection {
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @type {Array<any>}
|
|
18
|
-
* @memberOf Connection
|
|
19
|
-
*/
|
|
20
|
-
public errors: Array<any>;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @type {number}
|
|
25
|
-
* @memberOf Connection
|
|
26
|
-
*/
|
|
27
|
-
public pingPongInterval: number;
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @type {Array<Controller>}
|
|
32
|
-
* @memberOf Connection
|
|
33
|
-
*/
|
|
34
|
-
//public controllerInstances: Array<ControllerBase>;
|
|
35
|
-
public controllerInstances: Map<string, ControllerBase>;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @type {ClientInfo}
|
|
40
|
-
* @memberOf Connection
|
|
41
|
-
*/
|
|
42
|
-
public clientInfo: ClientInfo;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
|
-
* @param {ControllerBase} controller
|
|
48
|
-
* @param {string} method
|
|
49
|
-
* @param {string} data
|
|
50
|
-
* @param {*} [buffer]
|
|
51
|
-
*
|
|
52
|
-
* @memberOf Connection
|
|
53
|
-
*/
|
|
54
|
-
private methodInvoker(controller: ControllerBase, method: string, data: string, buffer?: any) {
|
|
55
|
-
try {
|
|
56
|
-
if (!controller.canInvokeMethod(method))
|
|
57
|
-
throw "method '" + method + "' cant be invoked.";
|
|
58
|
-
if (typeof (controller[method]) === "function") {
|
|
59
|
-
controller[method].apply(controller, [JSON.parse(data), method,
|
|
60
|
-
controller.alias, buffer]);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
let prop = method;
|
|
64
|
-
let propValue = JSON.parse(data);
|
|
65
|
-
if (typeof (controller[prop]) === typeof (propValue))
|
|
66
|
-
controller[prop] = propValue;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (ex) {
|
|
70
|
-
controller.invokeError(ex);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
-
* @type {string}
|
|
78
|
-
* @memberOf Connection
|
|
79
|
-
*/
|
|
80
|
-
get id(): string {
|
|
81
|
-
return this.transport.id;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates an instance of Connection.
|
|
85
|
-
*
|
|
86
|
-
* @param {ITransport} transport
|
|
87
|
-
* @param {Array<Connection>} connections
|
|
88
|
-
* @param {Array<Plugin<ControllerBase>>} controllers
|
|
89
|
-
*
|
|
90
|
-
* @memberOf Connection
|
|
91
|
-
*/
|
|
92
|
-
constructor(public transport: ITransport, public connections: Map<string,Connection>,
|
|
93
|
-
private controllers: Array<Plugin<ControllerBase>>) {
|
|
94
|
-
this.connections = connections;
|
|
95
|
-
//this.controllerInstances = new Array<ControllerBase>();
|
|
96
|
-
this.controllerInstances = new Map<string, ControllerBase>();
|
|
97
|
-
|
|
98
|
-
this.errors = [];
|
|
99
|
-
if (transport) {
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @param {ITransportMessage} event
|
|
104
|
-
*/
|
|
105
|
-
this.transport.onMessage = (event: ITransportMessage) => {
|
|
106
|
-
try {
|
|
107
|
-
if (!event.binary) {
|
|
108
|
-
let message = event.toMessage();
|
|
109
|
-
let controller = this.locateController(message.C);
|
|
110
|
-
if (controller)
|
|
111
|
-
this.methodInvoker(controller, message.T, message.D);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
let message = TextMessage.fromArrayBuffer(event.data);
|
|
115
|
-
let controller = this.locateController(message.C);
|
|
116
|
-
if (controller)
|
|
117
|
-
this.methodInvoker(controller, message.T, message.D, message.B);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
this.addError(error);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @private
|
|
130
|
-
* @param {*} error
|
|
131
|
-
*
|
|
132
|
-
* @memberOf Connection
|
|
133
|
-
*/
|
|
134
|
-
private addError(error: any) {
|
|
135
|
-
this.errors.push(error);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @param {string} alias
|
|
141
|
-
* @returns {boolean}
|
|
142
|
-
*
|
|
143
|
-
* @memberOf Connection
|
|
144
|
-
*/
|
|
145
|
-
hasController(alias: string): boolean {
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @param {ControllerBase} pre
|
|
150
|
-
* @returns
|
|
151
|
-
*/
|
|
152
|
-
// let match = this.controllerInstances.filter((pre: ControllerBase) => {
|
|
153
|
-
// return pre.alias == alias;
|
|
154
|
-
// });
|
|
155
|
-
// return match.length >= 0;
|
|
156
|
-
return this.controllerInstances.has(alias);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @param {string} alias
|
|
162
|
-
*
|
|
163
|
-
* @memberOf Connection
|
|
164
|
-
*/
|
|
165
|
-
removeController(alias: string): boolean {
|
|
166
|
-
// let index = this.controllerInstances.indexOf(this.getController(alias));
|
|
167
|
-
// if (index > -1)
|
|
168
|
-
// this.controllerInstances.splice(index, 1);
|
|
169
|
-
return this.controllerInstances.delete(alias);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* @param {string} alias
|
|
175
|
-
* @returns {ControllerBase}
|
|
176
|
-
*
|
|
177
|
-
* @memberOf Connection
|
|
178
|
-
*/
|
|
179
|
-
getController(alias: string): ControllerBase {
|
|
180
|
-
try {
|
|
181
|
-
let match = this.controllerInstances.get(alias);
|
|
182
|
-
if (!match) throw `cannot locate the requested controller ${alias}`
|
|
183
|
-
return match;
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @private
|
|
193
|
-
* @param {ControllerBase} controller
|
|
194
|
-
* @returns {ControllerBase}
|
|
195
|
-
*
|
|
196
|
-
* @memberOf Connection
|
|
197
|
-
*/
|
|
198
|
-
private addControllerInstance(controller: ControllerBase): ControllerBase {
|
|
199
|
-
this.controllerInstances.set(controller.alias, controller);
|
|
200
|
-
return controller;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @private
|
|
206
|
-
*
|
|
207
|
-
* @memberOf Connection
|
|
208
|
-
*/
|
|
209
|
-
private registerSealdController() {
|
|
210
|
-
throw "not yet implemented";
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public resolveController(alias: string): Plugin<ControllerBase> {
|
|
214
|
-
try {
|
|
215
|
-
|
|
216
|
-
let resolvedController = this.controllers.find((resolve: Plugin<ControllerBase>) => {
|
|
217
|
-
return resolve.alias === alias && Reflect.getMetadata("seald", resolve.instance) === false;
|
|
218
|
-
});
|
|
219
|
-
return resolvedController;
|
|
220
|
-
} catch{
|
|
221
|
-
throw `Cannot resolve ${alias},controller unknown.`
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @param {string} alias
|
|
228
|
-
* @returns {ControllerBase}
|
|
229
|
-
*
|
|
230
|
-
* @memberOf Connection
|
|
231
|
-
*/
|
|
232
|
-
locateController(alias: string): ControllerBase {
|
|
233
|
-
try {
|
|
234
|
-
|
|
235
|
-
let match = this.getController(alias);
|
|
236
|
-
if (match) {
|
|
237
|
-
return match;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// let resolvedController = this.controllers.find((resolve: Plugin<ControllerBase>) => {
|
|
241
|
-
// return resolve.alias === alias && Reflect.getMetadata("seald", resolve.instance) === false;
|
|
242
|
-
// }).instance;
|
|
243
|
-
let resolved = this.resolveController(alias);
|
|
244
|
-
let controllerInstance = new resolved.instance(this)
|
|
245
|
-
this.addControllerInstance(controllerInstance);
|
|
246
|
-
controllerInstance.invoke(new ClientInfo(this.id, controllerInstance.alias), "___open", controllerInstance.alias);
|
|
247
|
-
if(controllerInstance.onopen)
|
|
248
|
-
controllerInstance.onopen();
|
|
249
|
-
this.transport.onClose = (e:any) => {
|
|
250
|
-
if(controllerInstance.onclose)
|
|
251
|
-
controllerInstance.onclose();
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return controllerInstance;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
this.transport.close(1011, "Cannot locate the specified controller,it may be seald or the the alias in unknown '" + alias + "'. connection closed");
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Connection } from '../Connection';
|
|
3
|
-
import { Subscription } from '../Subscription';
|
|
4
|
-
import { URLSearchParams } from 'url';
|
|
5
|
-
export interface ControllerBase {
|
|
6
|
-
new (connection: Connection): ControllerBase;
|
|
7
|
-
}
|
|
8
|
-
export declare class ControllerBase {
|
|
9
|
-
alias: string;
|
|
10
|
-
subscriptions: Array<Subscription>;
|
|
11
|
-
connection: Connection;
|
|
12
|
-
private lastPong;
|
|
13
|
-
private lastPing;
|
|
14
|
-
private heartbeatInterval;
|
|
15
|
-
private interval;
|
|
16
|
-
constructor(connection: Connection);
|
|
17
|
-
private enableHeartbeat;
|
|
18
|
-
disbaleHeartbeat(): void;
|
|
19
|
-
canInvokeMethod(method: string): boolean;
|
|
20
|
-
findOn<T>(alias: string, predicate: (item: any) => boolean): Array<ControllerBase>;
|
|
21
|
-
getConnections(alias?: string): Array<Connection>;
|
|
22
|
-
onopen(): void;
|
|
23
|
-
onclose(): void;
|
|
24
|
-
find<T, U>(array: T[], predicate: (item: any) => boolean, selector?: (item: T) => U): U[];
|
|
25
|
-
invokeError(ex: any): void;
|
|
26
|
-
invokeToOthers(data: any, topic: string, controller?: string, buffer?: any): void;
|
|
27
|
-
invokeToAll(data: any, topic: string, controller?: string, buffer?: any): void;
|
|
28
|
-
invokeTo(predicate: (item: ControllerBase) => boolean, data: any, topic: string, controller?: string, buffer?: any): void;
|
|
29
|
-
invoke(data: any, topic: string, controller?: string, buffer?: any): ControllerBase;
|
|
30
|
-
publish(data: any, topic: string, controller?: string): ControllerBase;
|
|
31
|
-
publishToAll(data: any, topic: string, controller?: string): void;
|
|
32
|
-
hasSubscription(topic: string): boolean;
|
|
33
|
-
addSubscription(topic: string): Subscription;
|
|
34
|
-
removeSubscription(topic: string): boolean;
|
|
35
|
-
getSubscription(topic: string): Subscription;
|
|
36
|
-
___connect(): void;
|
|
37
|
-
___close(): void;
|
|
38
|
-
___subscribe(subscription: Subscription, topic: string, controller: string): Subscription;
|
|
39
|
-
___unsubscribe(subscription: Subscription): boolean;
|
|
40
|
-
get queryParameters(): URLSearchParams;
|
|
41
|
-
get headers(): Map<string, string>;
|
|
42
|
-
get request(): any;
|
|
43
|
-
}
|