@syncbridge/net 0.4.18 → 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-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);
|
|
@@ -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
|
},
|