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/Listener.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @class Listener
|
|
6
|
-
*/
|
|
7
|
-
export class Listener {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @type {Function}
|
|
12
|
-
* @memberOf Listener
|
|
13
|
-
*/
|
|
14
|
-
fn: Function;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @type {string}
|
|
19
|
-
* @memberOf Listener
|
|
20
|
-
*/
|
|
21
|
-
topic: string;
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of Listener.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} topic
|
|
26
|
-
* @param {Function} fn
|
|
27
|
-
*
|
|
28
|
-
* @memberOf Listener
|
|
29
|
-
*/
|
|
30
|
-
constructor(topic: string, fn: Function) {
|
|
31
|
-
this.fn = fn;
|
|
32
|
-
this.topic = topic;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { TextMessage } from './TextMessage';
|
|
3
|
-
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
4
|
-
export declare class BufferMessage implements ITransportMessage {
|
|
5
|
-
data: Buffer;
|
|
6
|
-
binary: boolean;
|
|
7
|
-
constructor(data: Buffer, binary: boolean);
|
|
8
|
-
toMessage(): TextMessage;
|
|
9
|
-
toBuffer(): Buffer;
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { TextMessage } from './TextMessage';
|
|
3
|
-
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
4
|
-
export declare class PipeMessage implements ITransportMessage {
|
|
5
|
-
data: any;
|
|
6
|
-
binary: boolean;
|
|
7
|
-
private message;
|
|
8
|
-
private arr;
|
|
9
|
-
constructor(data: any, binary: boolean);
|
|
10
|
-
toBuffer(): Buffer;
|
|
11
|
-
toMessage(): TextMessage;
|
|
12
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class PipeMessage {
|
|
4
|
-
constructor(data, binary) {
|
|
5
|
-
this.data = data;
|
|
6
|
-
this.binary = binary;
|
|
7
|
-
this.message = JSON.parse(this.data);
|
|
8
|
-
this.arr = new Array();
|
|
9
|
-
this.arr.push(this.message.C);
|
|
10
|
-
this.arr.push(this.message.T);
|
|
11
|
-
this.arr.push(this.message.D);
|
|
12
|
-
}
|
|
13
|
-
toBuffer() {
|
|
14
|
-
return new Buffer(this.arr.join("|"));
|
|
15
|
-
}
|
|
16
|
-
toMessage() {
|
|
17
|
-
return this.message;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.PipeMessage = PipeMessage;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare class TextMessage {
|
|
3
|
-
B: Buffer;
|
|
4
|
-
T: string;
|
|
5
|
-
D: any;
|
|
6
|
-
C: string;
|
|
7
|
-
isBinary: Boolean;
|
|
8
|
-
I: string;
|
|
9
|
-
F: boolean;
|
|
10
|
-
get JSON(): any;
|
|
11
|
-
constructor(topic: string, data: any, controller: string, arrayBuffer?: Buffer, uuid?: string, isFinal?: boolean);
|
|
12
|
-
toString(): string;
|
|
13
|
-
static fromArrayBuffer(buffer: Buffer): TextMessage;
|
|
14
|
-
toArrayBuffer(): Buffer;
|
|
15
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const BufferUtils_1 = require("../Utils/BufferUtils");
|
|
4
|
-
const thor_io_client_vnext_1 = require("thor-io.client-vnext");
|
|
5
|
-
class TextMessage {
|
|
6
|
-
constructor(topic, data, controller, arrayBuffer, uuid, isFinal) {
|
|
7
|
-
this.D = data;
|
|
8
|
-
this.T = topic;
|
|
9
|
-
this.C = controller;
|
|
10
|
-
this.B = arrayBuffer;
|
|
11
|
-
this.I = uuid || thor_io_client_vnext_1.Utils.newGuid();
|
|
12
|
-
this.F = true;
|
|
13
|
-
if (arrayBuffer)
|
|
14
|
-
this.isBinary = true;
|
|
15
|
-
}
|
|
16
|
-
get JSON() {
|
|
17
|
-
return {
|
|
18
|
-
T: this.T,
|
|
19
|
-
D: JSON.stringify(this.D),
|
|
20
|
-
C: this.C,
|
|
21
|
-
I: this.I,
|
|
22
|
-
F: this.F
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
;
|
|
26
|
-
toString() {
|
|
27
|
-
return JSON.stringify(this.JSON);
|
|
28
|
-
}
|
|
29
|
-
static fromArrayBuffer(buffer) {
|
|
30
|
-
let headerLen = 8;
|
|
31
|
-
let header = buffer.slice(0, 8);
|
|
32
|
-
let payloadLength = BufferUtils_1.BufferUtils.arrayToLong(header);
|
|
33
|
-
let message = buffer.slice(headerLen, payloadLength + headerLen);
|
|
34
|
-
let blobOffset = headerLen + payloadLength;
|
|
35
|
-
let blob = buffer.slice(blobOffset, buffer.byteLength);
|
|
36
|
-
let data = JSON.parse(message.toString());
|
|
37
|
-
return new TextMessage(data.T, data.D, data.C, blob, data.I, data.F);
|
|
38
|
-
}
|
|
39
|
-
toArrayBuffer() {
|
|
40
|
-
let messagePayload = this.toString();
|
|
41
|
-
let payloadLength = messagePayload.length;
|
|
42
|
-
let header = new Buffer(BufferUtils_1.BufferUtils.longToArray(payloadLength));
|
|
43
|
-
let message = new Buffer(payloadLength);
|
|
44
|
-
message.write(messagePayload, 0, payloadLength, "utf-8");
|
|
45
|
-
var blob = new Buffer(this.B);
|
|
46
|
-
var buffer = Buffer.concat([header, message, blob]);
|
|
47
|
-
return buffer;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.TextMessage = TextMessage;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { TextMessage } from './TextMessage';
|
|
3
|
-
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
4
|
-
export declare class WebSocketMessage implements ITransportMessage {
|
|
5
|
-
data: string;
|
|
6
|
-
binary: any;
|
|
7
|
-
constructor(data: string, binary: any);
|
|
8
|
-
toBuffer(): Buffer;
|
|
9
|
-
toMessage(): TextMessage;
|
|
10
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class WebSocketMessage {
|
|
4
|
-
constructor(data, binary) {
|
|
5
|
-
this.data = data;
|
|
6
|
-
this.binary = binary;
|
|
7
|
-
}
|
|
8
|
-
toBuffer() {
|
|
9
|
-
throw "not yet implemented";
|
|
10
|
-
}
|
|
11
|
-
toMessage() {
|
|
12
|
-
return JSON.parse(this.data);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.WebSocketMessage = WebSocketMessage;
|
package/src/Plugin.d.ts
DELETED
package/src/Plugin.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const StringUtils_1 = require("./Utils/StringUtils");
|
|
4
|
-
class Plugin {
|
|
5
|
-
constructor(controller) {
|
|
6
|
-
this.id = StringUtils_1.StringUtils.newGuid();
|
|
7
|
-
this.alias = Reflect.getMetadata("alias", controller);
|
|
8
|
-
this.instance = controller;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.Plugin = Plugin;
|
package/src/Plugin.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { StringUtils } from './Utils/StringUtils';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @export
|
|
6
|
-
* @class Plugin
|
|
7
|
-
* @template T
|
|
8
|
-
*/
|
|
9
|
-
export class Plugin<T> {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @type {string}
|
|
14
|
-
* @memberOf Plugin
|
|
15
|
-
*/
|
|
16
|
-
public alias: string;
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @type {T}
|
|
21
|
-
* @memberOf Plugin
|
|
22
|
-
*/
|
|
23
|
-
public instance: T;
|
|
24
|
-
id: string;
|
|
25
|
-
/**
|
|
26
|
-
* Creates an instance of Plugin.
|
|
27
|
-
*
|
|
28
|
-
* @param {T} controller
|
|
29
|
-
*
|
|
30
|
-
* @memberOf Plugin
|
|
31
|
-
*/
|
|
32
|
-
constructor(controller: T) {
|
|
33
|
-
this.id = StringUtils.newGuid()
|
|
34
|
-
this.alias = Reflect.getMetadata("alias", controller);
|
|
35
|
-
this.instance = controller;
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/Subscription.d.ts
DELETED
package/src/Subscription.js
DELETED
package/src/ThorIO.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ITransport } from "./Interfaces/ITransport";
|
|
3
|
-
import * as net from 'net';
|
|
4
|
-
import { IInterceptor } from './Interfaces/IInterceptor';
|
|
5
|
-
export declare class ThorIO {
|
|
6
|
-
private controllers;
|
|
7
|
-
private connections;
|
|
8
|
-
private endpoints;
|
|
9
|
-
interceptors: any;
|
|
10
|
-
constructor(controllers: Array<any>, interceptors?: Array<IInterceptor>);
|
|
11
|
-
createSealdControllers(): void;
|
|
12
|
-
removeConnection(id: string, reason: number): void;
|
|
13
|
-
addEndpoint(typeOfTransport: {
|
|
14
|
-
new (...args: any[]): ITransport;
|
|
15
|
-
}, host: string, port: number): net.Server;
|
|
16
|
-
addWebSocket(ws: any, req: any): void;
|
|
17
|
-
private addConnection;
|
|
18
|
-
}
|
package/src/ThorIO.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
|
-
if (mod && mod.__esModule) return mod;
|
|
4
|
-
var result = {};
|
|
5
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
-
result["default"] = mod;
|
|
7
|
-
return result;
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
const Plugin_1 = require("./Plugin");
|
|
11
|
-
const Connection_1 = require("./Connection");
|
|
12
|
-
const WebSocketMessageTransport_1 = require("./Transports/WebSocketMessageTransport");
|
|
13
|
-
const net = __importStar(require("net"));
|
|
14
|
-
class ThorIO {
|
|
15
|
-
constructor(controllers, interceptors) {
|
|
16
|
-
this.endpoints = new Array();
|
|
17
|
-
this.connections = new Map();
|
|
18
|
-
this.controllers = new Array();
|
|
19
|
-
this.interceptors = interceptors;
|
|
20
|
-
controllers.forEach((ctrl) => {
|
|
21
|
-
if (!Reflect.hasOwnMetadata("alias", ctrl)) {
|
|
22
|
-
throw "Faild to register on of the specified Controller's";
|
|
23
|
-
}
|
|
24
|
-
let plugin = new Plugin_1.Plugin(ctrl);
|
|
25
|
-
this.controllers.push(plugin);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
createSealdControllers() {
|
|
29
|
-
this.controllers.forEach((controller) => {
|
|
30
|
-
if (Reflect.getMetadata("seald", controller.instance)) {
|
|
31
|
-
new controller.instance(new Connection_1.Connection(null, this.connections, this.controllers));
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
removeConnection(id, reason) {
|
|
36
|
-
try {
|
|
37
|
-
this.connections.delete(id);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
addEndpoint(typeOfTransport, host, port) {
|
|
43
|
-
let endpoint = net.createServer((socket) => {
|
|
44
|
-
let transport = new typeOfTransport(socket);
|
|
45
|
-
this.addConnection(transport);
|
|
46
|
-
});
|
|
47
|
-
endpoint.listen(port, host, ((listener) => {
|
|
48
|
-
}));
|
|
49
|
-
this.endpoints.push(endpoint);
|
|
50
|
-
return endpoint;
|
|
51
|
-
}
|
|
52
|
-
addWebSocket(ws, req) {
|
|
53
|
-
let transport = new WebSocketMessageTransport_1.WebSocketMessageTransport(ws, req);
|
|
54
|
-
this.addConnection(transport);
|
|
55
|
-
}
|
|
56
|
-
addConnection(transport) {
|
|
57
|
-
transport.addEventListener("close", (reason) => {
|
|
58
|
-
if (transport.onClose)
|
|
59
|
-
transport.onClose(reason);
|
|
60
|
-
this.removeConnection(transport.id, reason);
|
|
61
|
-
});
|
|
62
|
-
this.connections.set(transport.id, new Connection_1.Connection(transport, this.connections, this.controllers));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.ThorIO = ThorIO;
|
package/src/ThorIO.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Plugin } from './Plugin';
|
|
2
|
-
import { Connection } from './Connection';
|
|
3
|
-
import { WebSocketMessageTransport } from "./Transports/WebSocketMessageTransport";
|
|
4
|
-
import { ITransport } from "./Interfaces/ITransport";
|
|
5
|
-
import * as net from 'net';
|
|
6
|
-
import { ControllerBase } from "./Controller/ControllerBase";
|
|
7
|
-
import { IInterceptor } from './Interfaces/IInterceptor';
|
|
8
|
-
/**
|
|
9
|
-
* Creates an hosting container / hug
|
|
10
|
-
*
|
|
11
|
-
* @export
|
|
12
|
-
* @class ThorIO
|
|
13
|
-
*/
|
|
14
|
-
export class ThorIO {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
* @type {Array<Plugin<IController>>}
|
|
20
|
-
* @memberOf ThorIO
|
|
21
|
-
*/
|
|
22
|
-
private controllers: Array<Plugin<ControllerBase>>;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @private
|
|
27
|
-
* @type {Array<Connection>}
|
|
28
|
-
* @memberOf ThorIO
|
|
29
|
-
*/
|
|
30
|
-
private connections: Map<string,Connection>;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @type {Array<any>}
|
|
36
|
-
* @memberOf ThorIO
|
|
37
|
-
*/
|
|
38
|
-
private endpoints: Array<any>;
|
|
39
|
-
interceptors: any;
|
|
40
|
-
/**
|
|
41
|
-
* Creates an instance of ThorIO.
|
|
42
|
-
*
|
|
43
|
-
* @param {Array<any>} controllers
|
|
44
|
-
*
|
|
45
|
-
* @memberOf ThorIO
|
|
46
|
-
*/
|
|
47
|
-
constructor(controllers: Array<any>,interceptors?:Array<IInterceptor>) {
|
|
48
|
-
this.endpoints = new Array<any>();
|
|
49
|
-
this.connections = new Map<string,Connection>();
|
|
50
|
-
this.controllers = new Array<Plugin<ControllerBase>>();
|
|
51
|
-
|
|
52
|
-
this.interceptors = interceptors;
|
|
53
|
-
|
|
54
|
-
controllers.forEach((ctrl: ControllerBase) => {
|
|
55
|
-
if (!Reflect.hasOwnMetadata("alias", ctrl)) {
|
|
56
|
-
throw "Faild to register on of the specified Controller's";
|
|
57
|
-
}
|
|
58
|
-
let plugin = new Plugin<ControllerBase>(ctrl);
|
|
59
|
-
this.controllers.push(plugin);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @public
|
|
66
|
-
*
|
|
67
|
-
* @memberOf ThorIO
|
|
68
|
-
*/
|
|
69
|
-
public createSealdControllers() {
|
|
70
|
-
this.controllers.forEach((controller: Plugin<ControllerBase>) => {
|
|
71
|
-
if (Reflect.getMetadata("seald", controller.instance)) {
|
|
72
|
-
new controller.instance(new Connection(null,
|
|
73
|
-
this.connections, this.controllers));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param {string} id
|
|
81
|
-
* @param {number} reason
|
|
82
|
-
*
|
|
83
|
-
* @memberOf ThorIO
|
|
84
|
-
*/
|
|
85
|
-
removeConnection(id: string, reason: number): void {
|
|
86
|
-
try {
|
|
87
|
-
this.connections.delete(id);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @param {{ new (...args: any[]): ITransport; }} typeOfTransport
|
|
96
|
-
* @param {string} host
|
|
97
|
-
* @param {number} port
|
|
98
|
-
* @returns {net.Server}
|
|
99
|
-
*
|
|
100
|
-
* @memberOf ThorIO
|
|
101
|
-
*/
|
|
102
|
-
addEndpoint(typeOfTransport: {
|
|
103
|
-
new(...args: any[]): ITransport;
|
|
104
|
-
}, host: string, port: number): net.Server {
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @param {net.Socket} socket
|
|
109
|
-
*/
|
|
110
|
-
let endpoint = net.createServer((socket: net.Socket) => {
|
|
111
|
-
let transport = new typeOfTransport(socket);
|
|
112
|
-
this.addConnection(transport);
|
|
113
|
-
});
|
|
114
|
-
endpoint.listen(port, host, ((listener: any) => {
|
|
115
|
-
// do op
|
|
116
|
-
}));
|
|
117
|
-
this.endpoints.push(endpoint);
|
|
118
|
-
return endpoint;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @param {*} ws
|
|
124
|
-
* @param {*} req
|
|
125
|
-
*
|
|
126
|
-
* @memberOf ThorIO
|
|
127
|
-
*/
|
|
128
|
-
addWebSocket(ws: any, req: any): void {
|
|
129
|
-
let transport = new WebSocketMessageTransport(ws,req);
|
|
130
|
-
this.addConnection(transport);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @private
|
|
136
|
-
* @param {ITransport} transport
|
|
137
|
-
*
|
|
138
|
-
* @memberOf ThorIO
|
|
139
|
-
*/
|
|
140
|
-
private addConnection(transport: ITransport): void {
|
|
141
|
-
transport.addEventListener("close", (reason) => {
|
|
142
|
-
if(transport.onClose)
|
|
143
|
-
transport.onClose(reason);
|
|
144
|
-
this.removeConnection(transport.id, reason);
|
|
145
|
-
});
|
|
146
|
-
this.connections.set(transport.id,new Connection(transport, this.connections, this.controllers));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as net from 'net';
|
|
3
|
-
import { ITransport } from '../Interfaces/ITransport';
|
|
4
|
-
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
5
|
-
import { IInterceptor } from '../Interfaces/IInterceptor';
|
|
6
|
-
import { IncomingMessage } from 'http';
|
|
7
|
-
export declare class BufferMessageTransport implements ITransport {
|
|
8
|
-
socket: net.Socket;
|
|
9
|
-
id: string;
|
|
10
|
-
onMessage: (messsage: ITransportMessage) => void;
|
|
11
|
-
constructor(socket: net.Socket);
|
|
12
|
-
request: IncomingMessage | any;
|
|
13
|
-
interceptors: Map<string, IInterceptor>;
|
|
14
|
-
onClose: () => void;
|
|
15
|
-
onOpen: () => void;
|
|
16
|
-
get readyState(): number;
|
|
17
|
-
send(data: string): void;
|
|
18
|
-
addEventListener(name: string, fn: any): void;
|
|
19
|
-
ping(): void;
|
|
20
|
-
close(): void;
|
|
21
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const BufferMessage_1 = require("../Messages/BufferMessage");
|
|
4
|
-
const StringUtils_1 = require("../Utils/StringUtils");
|
|
5
|
-
class BufferMessageTransport {
|
|
6
|
-
constructor(socket) {
|
|
7
|
-
this.socket = socket;
|
|
8
|
-
this.id = StringUtils_1.StringUtils.newGuid();
|
|
9
|
-
this.socket.addListener("data", (buffer) => {
|
|
10
|
-
let bm = new BufferMessage_1.BufferMessage(buffer, false);
|
|
11
|
-
this.onMessage(bm);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
get readyState() {
|
|
15
|
-
return 1;
|
|
16
|
-
}
|
|
17
|
-
send(data) {
|
|
18
|
-
let bm = new BufferMessage_1.BufferMessage(new Buffer(data), false);
|
|
19
|
-
this.socket.write(bm.toBuffer());
|
|
20
|
-
}
|
|
21
|
-
addEventListener(name, fn) {
|
|
22
|
-
this.socket.addListener(name, fn);
|
|
23
|
-
}
|
|
24
|
-
ping() {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
close() {
|
|
28
|
-
this.socket.destroy();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.BufferMessageTransport = BufferMessageTransport;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ITransport } from '../Interfaces/ITransport';
|
|
3
|
-
import { PipeMessage } from '../Messages/PipeMessage';
|
|
4
|
-
import * as net from 'net';
|
|
5
|
-
import { IInterceptor } from '../Interfaces/IInterceptor';
|
|
6
|
-
export declare class PipeMessageTransport implements ITransport {
|
|
7
|
-
socket: net.Socket;
|
|
8
|
-
id: string;
|
|
9
|
-
onMessage: (message: PipeMessage) => void;
|
|
10
|
-
send(data: any): void;
|
|
11
|
-
close(reason: number, message: any): void;
|
|
12
|
-
addEventListener(name: string, fn: any): void;
|
|
13
|
-
get readyState(): number;
|
|
14
|
-
ping(): void;
|
|
15
|
-
constructor(socket: net.Socket);
|
|
16
|
-
request: any;
|
|
17
|
-
interceptors: Map<string, IInterceptor>;
|
|
18
|
-
onClose: () => void;
|
|
19
|
-
onOpen: () => void;
|
|
20
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const PipeMessage_1 = require("../Messages/PipeMessage");
|
|
4
|
-
const StringUtils_1 = require("../Utils/StringUtils");
|
|
5
|
-
const TextMessage_1 = require("../Messages/TextMessage");
|
|
6
|
-
class PipeMessageTransport {
|
|
7
|
-
constructor(socket) {
|
|
8
|
-
this.socket = socket;
|
|
9
|
-
this.id = StringUtils_1.StringUtils.newGuid();
|
|
10
|
-
socket.addListener("data", (buffer) => {
|
|
11
|
-
let args = buffer.toString().split("|");
|
|
12
|
-
let message = new TextMessage_1.TextMessage(args[1], args[2], args[0]);
|
|
13
|
-
this.onMessage(new PipeMessage_1.PipeMessage(message.toString(), false));
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
send(data) {
|
|
17
|
-
let message = new PipeMessage_1.PipeMessage(data, false);
|
|
18
|
-
this.socket.write(message.toBuffer());
|
|
19
|
-
}
|
|
20
|
-
close(reason, message) {
|
|
21
|
-
this.socket.destroy();
|
|
22
|
-
}
|
|
23
|
-
addEventListener(name, fn) {
|
|
24
|
-
this.socket.addListener(name, fn);
|
|
25
|
-
}
|
|
26
|
-
get readyState() {
|
|
27
|
-
return 1;
|
|
28
|
-
}
|
|
29
|
-
ping() {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.PipeMessageTransport = PipeMessageTransport;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ITransport } from '../Interfaces/ITransport';
|
|
3
|
-
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
4
|
-
import { IInterceptor } from '../Interfaces/IInterceptor';
|
|
5
|
-
import { IncomingMessage } from 'http';
|
|
6
|
-
export declare class WebSocketMessageTransport implements ITransport {
|
|
7
|
-
request: IncomingMessage | Request;
|
|
8
|
-
socket: WebSocket;
|
|
9
|
-
onMessage: (message: ITransportMessage) => void;
|
|
10
|
-
id: string;
|
|
11
|
-
send(data: any): void;
|
|
12
|
-
close(reason: number, message: string): void;
|
|
13
|
-
addEventListener(name: string, fn: any): void;
|
|
14
|
-
constructor(socket: any, req: IncomingMessage);
|
|
15
|
-
interceptors: Map<string, IInterceptor>;
|
|
16
|
-
onClose: (ev: any) => void;
|
|
17
|
-
onOpen: (ev: any) => void;
|
|
18
|
-
get readyState(): number;
|
|
19
|
-
ping(): void;
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const WebSocketMessage_1 = require("../Messages/WebSocketMessage");
|
|
4
|
-
const StringUtils_1 = require("../Utils/StringUtils");
|
|
5
|
-
class WebSocketMessageTransport {
|
|
6
|
-
constructor(socket, req) {
|
|
7
|
-
this.id = StringUtils_1.StringUtils.newGuid();
|
|
8
|
-
this.request = req;
|
|
9
|
-
this.socket = socket;
|
|
10
|
-
this.socket.addEventListener("message", (event) => {
|
|
11
|
-
this.onMessage(new WebSocketMessage_1.WebSocketMessage(event.data, typeof (event.data) != "string"));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
;
|
|
15
|
-
send(data) {
|
|
16
|
-
this.socket.send(data);
|
|
17
|
-
}
|
|
18
|
-
close(reason, message) {
|
|
19
|
-
this.socket.close(reason, message);
|
|
20
|
-
}
|
|
21
|
-
addEventListener(name, fn) {
|
|
22
|
-
this.socket.addEventListener(name, fn);
|
|
23
|
-
}
|
|
24
|
-
get readyState() {
|
|
25
|
-
return this.socket.readyState;
|
|
26
|
-
}
|
|
27
|
-
ping() {
|
|
28
|
-
this.socket["ping"]();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.WebSocketMessageTransport = WebSocketMessageTransport;
|