@clonegod/ttd-core 2.0.79 → 2.0.81
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/chains/index.d.ts +6 -0
- package/dist/chains/index.js +6 -0
- package/dist/ws/ws_client.d.ts +2 -0
- package/dist/ws/ws_client.js +28 -2
- package/package.json +1 -1
package/dist/chains/index.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export declare const EvmChainConfig: {
|
|
|
23
23
|
chain_full_name: string;
|
|
24
24
|
weth_addr: string;
|
|
25
25
|
};
|
|
26
|
+
XLAYER: {
|
|
27
|
+
chain_id: number;
|
|
28
|
+
chain_short_name: string;
|
|
29
|
+
chain_full_name: string;
|
|
30
|
+
weth_addr: string;
|
|
31
|
+
};
|
|
26
32
|
};
|
|
27
33
|
export type EvmChainInfoType = {
|
|
28
34
|
chain_id: number;
|
package/dist/chains/index.js
CHANGED
|
@@ -26,4 +26,10 @@ exports.EvmChainConfig = {
|
|
|
26
26
|
chain_full_name: 'AVALANCHE',
|
|
27
27
|
weth_addr: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7".toLowerCase(),
|
|
28
28
|
},
|
|
29
|
+
"XLAYER": {
|
|
30
|
+
chain_id: 196,
|
|
31
|
+
chain_short_name: 'x-layer',
|
|
32
|
+
chain_full_name: 'xlayer',
|
|
33
|
+
weth_addr: "0x5A77f1443D16ee5761d310e38b62f77f726bC71c".toLowerCase(),
|
|
34
|
+
},
|
|
29
35
|
};
|
package/dist/ws/ws_client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class WebSocketClient {
|
|
|
14
14
|
private onMessageCallback;
|
|
15
15
|
private onOpenCallback;
|
|
16
16
|
private keepAliveTimer;
|
|
17
|
+
private isReconnecting;
|
|
17
18
|
constructor(url: string, options?: WebSocketClientOptions);
|
|
18
19
|
connect(): void;
|
|
19
20
|
private reconnect;
|
|
@@ -24,4 +25,5 @@ export declare class WebSocketClient {
|
|
|
24
25
|
isConnected(): boolean;
|
|
25
26
|
private startKeepAlive;
|
|
26
27
|
private stopKeepAlive;
|
|
28
|
+
private forceCleanup;
|
|
27
29
|
}
|
package/dist/ws/ws_client.js
CHANGED
|
@@ -21,6 +21,7 @@ class WebSocketClient {
|
|
|
21
21
|
this.onMessageCallback = null;
|
|
22
22
|
this.onOpenCallback = null;
|
|
23
23
|
this.keepAliveTimer = null;
|
|
24
|
+
this.isReconnecting = false;
|
|
24
25
|
this.url = url;
|
|
25
26
|
this.options = Object.assign({ reconnectInterval: 3000, rejectUnauthorized: false, keepAlive: false, keepAliveInterval: 30000 }, options);
|
|
26
27
|
(0, dist_1.log_info)(`WebSocketClient constructor, url: ${this.url}`, this.options);
|
|
@@ -31,6 +32,7 @@ class WebSocketClient {
|
|
|
31
32
|
this.ws = new ws_1.default(this.url, { headers: this.options.headers });
|
|
32
33
|
this.ws.on('open', () => {
|
|
33
34
|
(0, dist_1.log_info)('ws connected');
|
|
35
|
+
this.isReconnecting = false;
|
|
34
36
|
this.startKeepAlive();
|
|
35
37
|
if (this.onOpenCallback)
|
|
36
38
|
this.onOpenCallback();
|
|
@@ -61,9 +63,13 @@ class WebSocketClient {
|
|
|
61
63
|
}
|
|
62
64
|
reconnect() {
|
|
63
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
if (this.isReconnecting) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.isReconnecting = true;
|
|
64
70
|
(0, dist_1.log_info)(`Reconnecting in ${this.options.reconnectInterval}ms`);
|
|
65
71
|
yield (0, dist_1.sleep)(this.options.reconnectInterval);
|
|
66
|
-
this.
|
|
72
|
+
this.forceCleanup();
|
|
67
73
|
this.connect();
|
|
68
74
|
});
|
|
69
75
|
}
|
|
@@ -85,10 +91,11 @@ class WebSocketClient {
|
|
|
85
91
|
}
|
|
86
92
|
disconnect() {
|
|
87
93
|
this.stopKeepAlive();
|
|
94
|
+
this.isReconnecting = false;
|
|
88
95
|
if (this.ws) {
|
|
89
96
|
this.ws.removeAllListeners();
|
|
90
97
|
try {
|
|
91
|
-
if (this.ws.readyState === ws_1.default.OPEN) {
|
|
98
|
+
if (this.ws.readyState === ws_1.default.OPEN || this.ws.readyState === ws_1.default.CONNECTING) {
|
|
92
99
|
this.ws.close();
|
|
93
100
|
}
|
|
94
101
|
}
|
|
@@ -122,5 +129,24 @@ class WebSocketClient {
|
|
|
122
129
|
(0, dist_1.log_info)('KeepAlive stopped');
|
|
123
130
|
}
|
|
124
131
|
}
|
|
132
|
+
forceCleanup() {
|
|
133
|
+
this.stopKeepAlive();
|
|
134
|
+
this.isReconnecting = false;
|
|
135
|
+
if (this.ws) {
|
|
136
|
+
this.ws.removeAllListeners('open');
|
|
137
|
+
this.ws.removeAllListeners('message');
|
|
138
|
+
this.ws.removeAllListeners('close');
|
|
139
|
+
this.ws.removeAllListeners('error');
|
|
140
|
+
this.ws.removeAllListeners();
|
|
141
|
+
try {
|
|
142
|
+
if (this.ws.readyState !== ws_1.default.CLOSED) {
|
|
143
|
+
this.ws.close();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
}
|
|
148
|
+
this.ws = null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
125
151
|
}
|
|
126
152
|
exports.WebSocketClient = WebSocketClient;
|