@syncbridge/net 0.4.17 → 0.4.19
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/components/tcp-client.component.d.ts +1 -0
- package/components/tcp-client.component.js +61 -41
- package/components/tcp-client.variables.js +16 -0
- package/components/tcp-server.variables.js +4 -0
- package/components/udp-client.component.d.ts +1 -0
- package/components/udp-client.component.js +12 -0
- package/components/udp-client.variables.js +3 -0
- package/components/udp-listener.component.d.ts +1 -0
- package/components/udp-listener.component.js +12 -0
- package/components/udp-listener.variables.js +5 -0
- package/constants.js +1 -1
- package/package.json +5 -5
|
@@ -13,6 +13,7 @@ export declare class TcpClientComponent<TEvents extends TcpClientComponent.Event
|
|
|
13
13
|
values: TcpClientVariables;
|
|
14
14
|
get connected(): boolean;
|
|
15
15
|
protected _init(): Promise<void>;
|
|
16
|
+
protected _configureClient(): Promise<void>;
|
|
16
17
|
protected _start(abortSignal: AbortSignal): Promise<void>;
|
|
17
18
|
protected _stop(): Promise<void>;
|
|
18
19
|
write(data: string | Buffer): void;
|
|
@@ -16,50 +16,70 @@ let TcpClientComponent = class TcpClientComponent extends IoClientBaseComponent
|
|
|
16
16
|
}
|
|
17
17
|
async _init() {
|
|
18
18
|
await super._init();
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
port: this.values.port || 0,
|
|
22
|
-
connectTimeout: this.values.connectTimeout,
|
|
23
|
-
keepAlive: this.values.keepAlive,
|
|
24
|
-
reconnect: this.values.reconnect,
|
|
25
|
-
tls: this.values.tls,
|
|
19
|
+
this.on('values-updated', async () => {
|
|
20
|
+
await this._configureClient();
|
|
26
21
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
22
|
+
await this._configureClient();
|
|
23
|
+
}
|
|
24
|
+
async _configureClient() {
|
|
25
|
+
try {
|
|
26
|
+
const isStopped = this.stopped;
|
|
27
|
+
await this._client?.disconnect();
|
|
28
|
+
this._client = new TcpClient({
|
|
29
|
+
host: this.values.host || '127.0.0.1',
|
|
30
|
+
port: this.values.port || 0,
|
|
31
|
+
connectTimeout: this.values.connectTimeout,
|
|
32
|
+
keepAlive: this.values.keepAlive,
|
|
33
|
+
reconnect: this.values.reconnect,
|
|
34
|
+
tls: this.values.tls,
|
|
37
35
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
/* On connection */
|
|
37
|
+
this._client.on('connect', (socket) => {
|
|
38
|
+
this._address = {
|
|
39
|
+
address: this.values.host || '127.0.0.1',
|
|
40
|
+
port: socket.remotePort,
|
|
41
|
+
};
|
|
42
|
+
this._address.toString = function () {
|
|
43
|
+
return `${this.address}:${this.port}`;
|
|
44
|
+
}.bind(this._address);
|
|
45
|
+
setImmediate(() => {
|
|
46
|
+
this.logger?.info(`TCP socket connected to ${colors.cyan(this._client.host + ':' + this._client.port)}`);
|
|
47
|
+
this.setStatus(ServiceStatus.started);
|
|
48
|
+
this.emit('connect');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
/* On disconnect */
|
|
52
|
+
this._client.on('disconnect', (err) => {
|
|
53
|
+
if (this._stopping)
|
|
54
|
+
this.emit('disconnect');
|
|
55
|
+
else {
|
|
56
|
+
err = err || new Error('TCP socket disconnected');
|
|
57
|
+
this.logger?.error(err);
|
|
58
|
+
this.setStatus(ServiceStatus.unhealthy, err.message);
|
|
59
|
+
this.emit('disconnect');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/* On data */
|
|
63
|
+
this._client.on('data', (chunk) => {
|
|
64
|
+
this.emit('data', chunk, this._address);
|
|
65
|
+
});
|
|
66
|
+
/* On error */
|
|
67
|
+
this._client.on('error', (err) => {
|
|
68
|
+
this.emit('error', err);
|
|
69
|
+
});
|
|
70
|
+
/* On reconnecting */
|
|
71
|
+
this._client.on('reconnecting', (n, delay) => {
|
|
72
|
+
this.logger?.error(`Connection failed (${colors.cyan(String(n + 1))}). Will be retried after ${colors.cyan(delay + 'ms')}`);
|
|
73
|
+
this.emit('reconnecting', n, delay);
|
|
74
|
+
});
|
|
75
|
+
if (!isStopped) {
|
|
76
|
+
await this._start(new AbortController().signal);
|
|
48
77
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
}
|
|
54
|
-
/* On error */
|
|
55
|
-
this._client.on('error', (err) => {
|
|
56
|
-
this.emit('error', err);
|
|
57
|
-
});
|
|
58
|
-
/* On reconnecting */
|
|
59
|
-
this._client.on('reconnecting', (n, delay) => {
|
|
60
|
-
this.logger?.error(`Connection failed (${colors.cyan(String(n + 1))}). Will be retried after ${colors.cyan(delay + 'ms')}`);
|
|
61
|
-
this.emit('reconnecting', n, delay);
|
|
62
|
-
});
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.logger?.error(err);
|
|
81
|
+
this.setStatus(ServiceStatus.unhealthy, err.message);
|
|
82
|
+
}
|
|
63
83
|
}
|
|
64
84
|
async _start(abortSignal) {
|
|
65
85
|
await super._start(abortSignal);
|
|
@@ -10,6 +10,7 @@ __decorate([
|
|
|
10
10
|
DefineVariable({
|
|
11
11
|
label: 'SNI',
|
|
12
12
|
description: 'SNI (Server Name Indication)',
|
|
13
|
+
hotPlug: true,
|
|
13
14
|
}),
|
|
14
15
|
__metadata("design:type", String)
|
|
15
16
|
], TcpClientTlsVariables.prototype, "servername", void 0);
|
|
@@ -18,6 +19,7 @@ __decorate([
|
|
|
18
19
|
label: 'Key',
|
|
19
20
|
description: 'Private keys in PEM format',
|
|
20
21
|
required: true,
|
|
22
|
+
hotPlug: true,
|
|
21
23
|
}),
|
|
22
24
|
__metadata("design:type", String)
|
|
23
25
|
], TcpClientTlsVariables.prototype, "key", void 0);
|
|
@@ -26,6 +28,7 @@ __decorate([
|
|
|
26
28
|
label: 'Cert',
|
|
27
29
|
description: 'Cert chains in PEM format',
|
|
28
30
|
required: true,
|
|
31
|
+
hotPlug: true,
|
|
29
32
|
}),
|
|
30
33
|
__metadata("design:type", String)
|
|
31
34
|
], TcpClientTlsVariables.prototype, "cert", void 0);
|
|
@@ -36,6 +39,7 @@ __decorate([
|
|
|
36
39
|
"curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified " +
|
|
37
40
|
'using this option.',
|
|
38
41
|
required: true,
|
|
42
|
+
hotPlug: true,
|
|
39
43
|
}),
|
|
40
44
|
__metadata("design:type", String)
|
|
41
45
|
], TcpClientTlsVariables.prototype, "ca", void 0);
|
|
@@ -44,6 +48,7 @@ __decorate([
|
|
|
44
48
|
type: VariableType.Secret,
|
|
45
49
|
label: 'Passphrase',
|
|
46
50
|
description: 'Passphrase to decrypt the private key',
|
|
51
|
+
hotPlug: true,
|
|
47
52
|
}),
|
|
48
53
|
__metadata("design:type", String)
|
|
49
54
|
], TcpClientTlsVariables.prototype, "passphrase", void 0);
|
|
@@ -52,6 +57,7 @@ __decorate([
|
|
|
52
57
|
label: 'Reject unauthorized',
|
|
53
58
|
description: 'If true will reject any connection which is not authorized with the list of supplied CAs',
|
|
54
59
|
default: true,
|
|
60
|
+
hotPlug: true,
|
|
55
61
|
}),
|
|
56
62
|
__metadata("design:type", Boolean)
|
|
57
63
|
], TcpClientTlsVariables.prototype, "rejectUnauthorized", void 0);
|
|
@@ -66,6 +72,7 @@ __decorate([
|
|
|
66
72
|
label: 'Reconnection strategy',
|
|
67
73
|
enumValues: ['exponential', 'fibonacci'],
|
|
68
74
|
default: 'exponential',
|
|
75
|
+
hotPlug: true,
|
|
69
76
|
}),
|
|
70
77
|
__metadata("design:type", String)
|
|
71
78
|
], TcpClientReconnectVariables.prototype, "strategy", void 0);
|
|
@@ -74,6 +81,7 @@ __decorate([
|
|
|
74
81
|
label: 'Initial delay',
|
|
75
82
|
description: 'Initial delay in milliseconds',
|
|
76
83
|
default: 2000,
|
|
84
|
+
hotPlug: true,
|
|
77
85
|
}),
|
|
78
86
|
__metadata("design:type", Number)
|
|
79
87
|
], TcpClientReconnectVariables.prototype, "initialDelay", void 0);
|
|
@@ -82,6 +90,7 @@ __decorate([
|
|
|
82
90
|
label: 'Maximum delay',
|
|
83
91
|
description: 'Maximum delay in milliseconds',
|
|
84
92
|
default: 10000,
|
|
93
|
+
hotPlug: true,
|
|
85
94
|
}),
|
|
86
95
|
__metadata("design:type", Number)
|
|
87
96
|
], TcpClientReconnectVariables.prototype, "maxDelay", void 0);
|
|
@@ -96,6 +105,7 @@ __decorate([
|
|
|
96
105
|
description: 'Hostname or IP address to be connected to',
|
|
97
106
|
required: true,
|
|
98
107
|
index: 100,
|
|
108
|
+
hotPlug: true,
|
|
99
109
|
}),
|
|
100
110
|
__metadata("design:type", String)
|
|
101
111
|
], TcpClientVariables.prototype, "host", void 0);
|
|
@@ -107,6 +117,7 @@ __decorate([
|
|
|
107
117
|
minValue: 1,
|
|
108
118
|
maxValue: 65535,
|
|
109
119
|
index: 101,
|
|
120
|
+
hotPlug: true,
|
|
110
121
|
}),
|
|
111
122
|
__metadata("design:type", Number)
|
|
112
123
|
], TcpClientVariables.prototype, "port", void 0);
|
|
@@ -116,6 +127,7 @@ __decorate([
|
|
|
116
127
|
description: 'Enables keep-alive on the TCP socket',
|
|
117
128
|
default: false,
|
|
118
129
|
index: 102,
|
|
130
|
+
hotPlug: true,
|
|
119
131
|
}),
|
|
120
132
|
__metadata("design:type", Boolean)
|
|
121
133
|
], TcpClientVariables.prototype, "keepAlive", void 0);
|
|
@@ -125,6 +137,7 @@ __decorate([
|
|
|
125
137
|
description: 'Connection timeout in milliseconds',
|
|
126
138
|
default: 10000,
|
|
127
139
|
index: 103,
|
|
140
|
+
hotPlug: true,
|
|
128
141
|
}),
|
|
129
142
|
__metadata("design:type", Number)
|
|
130
143
|
], TcpClientVariables.prototype, "connectTimeout", void 0);
|
|
@@ -132,12 +145,14 @@ __decorate([
|
|
|
132
145
|
DefineVariable({
|
|
133
146
|
label: 'Reconnect',
|
|
134
147
|
description: 'Reconnect options',
|
|
148
|
+
hotPlug: true,
|
|
135
149
|
}),
|
|
136
150
|
__metadata("design:type", TcpClientReconnectVariables)
|
|
137
151
|
], TcpClientVariables.prototype, "reconnect", void 0);
|
|
138
152
|
__decorate([
|
|
139
153
|
DefineVariable({
|
|
140
154
|
label: 'TLS Enabled',
|
|
155
|
+
hotPlug: true,
|
|
141
156
|
}),
|
|
142
157
|
__metadata("design:type", Boolean)
|
|
143
158
|
], TcpClientVariables.prototype, "tls_enabled", void 0);
|
|
@@ -145,6 +160,7 @@ __decorate([
|
|
|
145
160
|
DefineVariable({
|
|
146
161
|
label: 'TLS',
|
|
147
162
|
description: 'TLS options',
|
|
163
|
+
hotPlug: true,
|
|
148
164
|
}),
|
|
149
165
|
__metadata("design:type", TcpClientTlsVariables)
|
|
150
166
|
], TcpClientVariables.prototype, "tls", void 0);
|
|
@@ -12,6 +12,7 @@ __decorate([
|
|
|
12
12
|
label: 'Request cert',
|
|
13
13
|
description: 'If true the server will request a certificate from clients that connect and attempt to verify that certificate',
|
|
14
14
|
default: false,
|
|
15
|
+
hotPlug: true,
|
|
15
16
|
}),
|
|
16
17
|
__metadata("design:type", Boolean)
|
|
17
18
|
], TcpServerTlsVariables.prototype, "requestCert", void 0);
|
|
@@ -28,6 +29,7 @@ __decorate([
|
|
|
28
29
|
minValue: 1,
|
|
29
30
|
maxValue: 65535,
|
|
30
31
|
index: 100,
|
|
32
|
+
hotPlug: true,
|
|
31
33
|
}),
|
|
32
34
|
__metadata("design:type", Number)
|
|
33
35
|
], TcpServerVariables.prototype, "port", void 0);
|
|
@@ -35,6 +37,7 @@ __decorate([
|
|
|
35
37
|
DefineVariable({
|
|
36
38
|
label: 'TLS Enabled',
|
|
37
39
|
description: 'Whether to use TLS for the connection',
|
|
40
|
+
hotPlug: true,
|
|
38
41
|
}),
|
|
39
42
|
__metadata("design:type", Boolean)
|
|
40
43
|
], TcpServerVariables.prototype, "tls_enabled", void 0);
|
|
@@ -42,6 +45,7 @@ __decorate([
|
|
|
42
45
|
DefineVariable({
|
|
43
46
|
label: 'TLS',
|
|
44
47
|
description: 'TLS options',
|
|
48
|
+
hotPlug: true,
|
|
45
49
|
}),
|
|
46
50
|
__metadata("design:type", TcpServerTlsVariables)
|
|
47
51
|
], TcpServerVariables.prototype, "tls", void 0);
|
|
@@ -12,6 +12,7 @@ export declare class UdpClientComponent<TEvents extends UdpClientComponent.Event
|
|
|
12
12
|
};
|
|
13
13
|
protected _stopping?: boolean;
|
|
14
14
|
values: UdpClientVariables;
|
|
15
|
+
protected _init(): Promise<void>;
|
|
15
16
|
protected _start(abortSignal: AbortSignal): Promise<void>;
|
|
16
17
|
protected _stop(): Promise<void>;
|
|
17
18
|
write(data: string | Buffer, port?: number, host?: string): void;
|
|
@@ -9,6 +9,18 @@ import { UdpClientVariables } from './udp-client.variables.js';
|
|
|
9
9
|
let UdpClientComponent = class UdpClientComponent extends IoClientBaseComponent {
|
|
10
10
|
protocol = 'udp';
|
|
11
11
|
_stopping;
|
|
12
|
+
async _init() {
|
|
13
|
+
await super._init();
|
|
14
|
+
this.on('values-updated', async () => {
|
|
15
|
+
const isStopped = this.stopped;
|
|
16
|
+
await this._stop();
|
|
17
|
+
if (!isStopped) {
|
|
18
|
+
await this._start(new AbortController().signal).catch(err => {
|
|
19
|
+
this.setStatus(ServiceStatus.unhealthy, err.message);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
12
24
|
async _start(abortSignal) {
|
|
13
25
|
await super._start(abortSignal);
|
|
14
26
|
this._stopping = false;
|
|
@@ -12,6 +12,7 @@ __decorate([
|
|
|
12
12
|
label: 'Host',
|
|
13
13
|
description: 'Hostname or IP address which udp messages will send to',
|
|
14
14
|
index: 100,
|
|
15
|
+
hotPlug: true,
|
|
15
16
|
}),
|
|
16
17
|
__metadata("design:type", String)
|
|
17
18
|
], UdpClientVariables.prototype, "host", void 0);
|
|
@@ -22,6 +23,7 @@ __decorate([
|
|
|
22
23
|
minValue: 1,
|
|
23
24
|
maxValue: 65535,
|
|
24
25
|
index: 101,
|
|
26
|
+
hotPlug: true,
|
|
25
27
|
}),
|
|
26
28
|
__metadata("design:type", Number)
|
|
27
29
|
], UdpClientVariables.prototype, "port", void 0);
|
|
@@ -32,6 +34,7 @@ __decorate([
|
|
|
32
34
|
type: VariableType.Enum,
|
|
33
35
|
enumValues: getInterfaceAddresses(),
|
|
34
36
|
index: 102,
|
|
37
|
+
hotPlug: true,
|
|
35
38
|
}),
|
|
36
39
|
__metadata("design:type", String)
|
|
37
40
|
], UdpClientVariables.prototype, "bindInterface", void 0);
|
|
@@ -12,6 +12,7 @@ export declare class UdpListenerComponent<TEvents extends UdpListenerComponent.E
|
|
|
12
12
|
};
|
|
13
13
|
protected _stopping?: boolean;
|
|
14
14
|
values: UdpListenerVariables;
|
|
15
|
+
protected _init(): Promise<void>;
|
|
15
16
|
protected _start(abortSignal: AbortSignal): Promise<void>;
|
|
16
17
|
protected _stop(): Promise<void>;
|
|
17
18
|
write(data: string | Buffer, port?: number, host?: string): void;
|
|
@@ -9,6 +9,18 @@ import { UdpListenerVariables } from './udp-listener.variables.js';
|
|
|
9
9
|
let UdpListenerComponent = class UdpListenerComponent extends IoClientBaseComponent {
|
|
10
10
|
protocol = 'udp';
|
|
11
11
|
_stopping;
|
|
12
|
+
async _init() {
|
|
13
|
+
await super._init();
|
|
14
|
+
this.on('values-updated', async () => {
|
|
15
|
+
const isStopped = this.stopped;
|
|
16
|
+
await this._stop();
|
|
17
|
+
if (!isStopped) {
|
|
18
|
+
await this._start(new AbortController().signal).catch(err => {
|
|
19
|
+
this.setStatus(ServiceStatus.unhealthy, err.message);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
12
24
|
async _start(abortSignal) {
|
|
13
25
|
await super._start(abortSignal);
|
|
14
26
|
this._stopping = false;
|
|
@@ -15,6 +15,7 @@ __decorate([
|
|
|
15
15
|
minValue: 1,
|
|
16
16
|
maxValue: 65535,
|
|
17
17
|
index: 100,
|
|
18
|
+
hotPlug: true,
|
|
18
19
|
}),
|
|
19
20
|
__metadata("design:type", Number)
|
|
20
21
|
], UdpListenerVariables.prototype, "port", void 0);
|
|
@@ -23,6 +24,7 @@ __decorate([
|
|
|
23
24
|
label: 'Broadcast',
|
|
24
25
|
description: "Sets the SO_BROADCAST socket option. When set to true, UDP packets may be sent to a local interface's broadcast address.",
|
|
25
26
|
index: 101,
|
|
27
|
+
hotPlug: true,
|
|
26
28
|
}),
|
|
27
29
|
__metadata("design:type", Boolean)
|
|
28
30
|
], UdpListenerVariables.prototype, "broadcast", void 0);
|
|
@@ -33,6 +35,7 @@ __decorate([
|
|
|
33
35
|
type: VariableType.String,
|
|
34
36
|
isArray: true,
|
|
35
37
|
index: 102,
|
|
38
|
+
hotPlug: true,
|
|
36
39
|
}),
|
|
37
40
|
__metadata("design:type", Array)
|
|
38
41
|
], UdpListenerVariables.prototype, "multicastGroups", void 0);
|
|
@@ -43,6 +46,7 @@ __decorate([
|
|
|
43
46
|
type: VariableType.Enum,
|
|
44
47
|
enumValues: getInterfaceAddresses(),
|
|
45
48
|
index: 103,
|
|
49
|
+
hotPlug: true,
|
|
46
50
|
}),
|
|
47
51
|
__metadata("design:type", String)
|
|
48
52
|
], UdpListenerVariables.prototype, "bindInterface", void 0);
|
|
@@ -53,6 +57,7 @@ __decorate([
|
|
|
53
57
|
type: VariableType.Enum,
|
|
54
58
|
enumValues: getInterfaceAddresses(),
|
|
55
59
|
index: 104,
|
|
60
|
+
hotPlug: true,
|
|
56
61
|
}),
|
|
57
62
|
__metadata("design:type", String)
|
|
58
63
|
], UdpListenerVariables.prototype, "multicastInterface", void 0);
|
package/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncbridge/net",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
4
4
|
"description": "SyncBridge builtin net (socket) extensions",
|
|
5
5
|
"author": "Panates Inc",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"date-fns": "^4.1.0",
|
|
17
17
|
"fast-tokenizer": "^1.9.0",
|
|
18
18
|
"file-stream-rotator": "^1.0.0",
|
|
19
|
-
"hl7v2": "^1.
|
|
20
|
-
"hl7v2-net": "^1.
|
|
19
|
+
"hl7v2": "^1.8.0",
|
|
20
|
+
"hl7v2-net": "^1.8.0",
|
|
21
21
|
"kafkajs": "^2.2.4",
|
|
22
22
|
"lightning-pool": "^4.12.0",
|
|
23
23
|
"node-events-async": "^1.5.0",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"serialport": "^13.0.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@syncbridge/common": "^0.
|
|
31
|
-
"@syncbridge/builtins": "^0.4.
|
|
30
|
+
"@syncbridge/common": "^0.6.0",
|
|
31
|
+
"@syncbridge/builtins": "^0.4.19",
|
|
32
32
|
"@sqb/builder": ">=4.19.6 <5",
|
|
33
33
|
"@sqb/connect": ">=4.19.6 <5"
|
|
34
34
|
},
|