@nmtjs/client 0.12.8 → 0.13.0
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/dist/common.d.ts +1 -0
- package/dist/common.js +17 -1
- package/package.json +9 -9
package/dist/common.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare abstract class BaseClient<APIContract extends TAnyAPIContract = T
|
|
|
19
19
|
protected abstract transformer: ProtocolBaseTransformer;
|
|
20
20
|
protected callers: ClientCallers<API, SafeCall>;
|
|
21
21
|
protected auth: any;
|
|
22
|
+
protected reconnectTimeout: number;
|
|
22
23
|
constructor(transport: ProtocolTransport, options: {
|
|
23
24
|
timeout: number;
|
|
24
25
|
autoreconnect?: boolean;
|
package/dist/common.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
|
+
import { noopFn } from '@nmtjs/common';
|
|
1
2
|
import { EventEmitter, ProtocolError, } from '@nmtjs/protocol/client';
|
|
2
3
|
export { ErrorCode, ProtocolBlob, TransportType, } from '@nmtjs/protocol';
|
|
3
4
|
export * from "./types.js";
|
|
4
5
|
export class ClientError extends ProtocolError {
|
|
5
6
|
}
|
|
7
|
+
const DEFAULT_RECONNECT_TIMEOUT = 1000;
|
|
6
8
|
export class BaseClient extends EventEmitter {
|
|
7
9
|
transport;
|
|
8
10
|
options;
|
|
9
11
|
_;
|
|
10
12
|
callers;
|
|
11
13
|
auth;
|
|
14
|
+
reconnectTimeout = DEFAULT_RECONNECT_TIMEOUT;
|
|
12
15
|
constructor(transport, options) {
|
|
13
16
|
super();
|
|
14
17
|
this.transport = transport;
|
|
15
18
|
this.options = options;
|
|
16
19
|
if (this.options.autoreconnect) {
|
|
17
|
-
this.transport.on('disconnected', () =>
|
|
20
|
+
this.transport.on('disconnected', async (reason) => {
|
|
21
|
+
if (reason === 'server') {
|
|
22
|
+
this.connect();
|
|
23
|
+
}
|
|
24
|
+
else if (reason === 'error') {
|
|
25
|
+
const timeout = new Promise((resolve) => setTimeout(resolve, this.reconnectTimeout));
|
|
26
|
+
const connected = new Promise((_, reject) => this.transport.once('connected', reject));
|
|
27
|
+
this.reconnectTimeout += DEFAULT_RECONNECT_TIMEOUT;
|
|
28
|
+
await Promise.race([timeout, connected]).then(this.connect.bind(this), noopFn);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.transport.on('connected', () => {
|
|
32
|
+
this.reconnectTimeout = DEFAULT_RECONNECT_TIMEOUT;
|
|
33
|
+
});
|
|
18
34
|
}
|
|
19
35
|
}
|
|
20
36
|
async _call(namespace, procedure, payload, options) {
|
package/package.json
CHANGED
|
@@ -19,23 +19,23 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@nmtjs/
|
|
23
|
-
"@nmtjs/
|
|
24
|
-
"@nmtjs/
|
|
25
|
-
"@nmtjs/
|
|
22
|
+
"@nmtjs/type": "0.13.0",
|
|
23
|
+
"@nmtjs/contract": "0.13.0",
|
|
24
|
+
"@nmtjs/common": "0.13.0",
|
|
25
|
+
"@nmtjs/protocol": "0.13.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nmtjs/type": "0.
|
|
29
|
-
"@nmtjs/
|
|
30
|
-
"@nmtjs/
|
|
31
|
-
"@nmtjs/protocol": "0.
|
|
28
|
+
"@nmtjs/type": "0.13.0",
|
|
29
|
+
"@nmtjs/common": "0.13.0",
|
|
30
|
+
"@nmtjs/contract": "0.13.0",
|
|
31
|
+
"@nmtjs/protocol": "0.13.0"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
35
35
|
"LICENSE.md",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"version": "0.
|
|
38
|
+
"version": "0.13.0",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc",
|
|
41
41
|
"type-check": "tsc --noEmit"
|