@blocklet/sdk 1.17.1 → 1.17.2-beta-20251110-023854-e91dad6f
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/lib/service/notification.d.ts +1 -1
- package/lib/service/notification.js +7 -10
- package/lib/util/socket.d.ts +2 -0
- package/lib/util/socket.js +66 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +18 -18
|
@@ -31,7 +31,7 @@ export declare const broadcast: (notification: TNotificationInput, options?: TSe
|
|
|
31
31
|
export declare const _eventBus: EventEmitter<[never]>;
|
|
32
32
|
export declare const _emitter: EventEmitter<[never]>;
|
|
33
33
|
export declare const ensureClient: () => Promise<void>;
|
|
34
|
-
export declare const cleanup: () => void
|
|
34
|
+
export declare const cleanup: () => Promise<void>;
|
|
35
35
|
export declare const on: (event: string, cb?: $TSFixMe) => Promise<EventEmitter<[never]>>;
|
|
36
36
|
export declare const off: any;
|
|
37
37
|
export declare const _message: {
|
|
@@ -52,6 +52,7 @@ const constants_1 = require("../util/constants");
|
|
|
52
52
|
const wallet_1 = require("../wallet");
|
|
53
53
|
const notification_1 = require("../validators/notification");
|
|
54
54
|
const parse_docker_endpoint_1 = require("../util/parse-docker-endpoint");
|
|
55
|
+
const socket_1 = require("../util/socket");
|
|
55
56
|
const debug = (0, debug_1.default)('@blocklet/sdk:notification');
|
|
56
57
|
const getSender = () => {
|
|
57
58
|
const wallet = (0, wallet_1.getWallet)();
|
|
@@ -156,14 +157,10 @@ const joinChannelErrorHandler = (name, type, emitters) => (err) => {
|
|
|
156
157
|
// On any join error/timeout, cleanup client and schedule reconnect with fresh token
|
|
157
158
|
if (client) {
|
|
158
159
|
console.log(`Cleaning up client due to ${name} join error, will reconnect with fresh token...`);
|
|
159
|
-
|
|
160
|
-
client
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
console.error('Error disconnecting client:', e);
|
|
164
|
-
}
|
|
165
|
-
client = null;
|
|
166
|
-
reconnect();
|
|
160
|
+
(0, socket_1.safeDisconnect)(client).finally(() => {
|
|
161
|
+
client = null;
|
|
162
|
+
reconnect();
|
|
163
|
+
});
|
|
167
164
|
}
|
|
168
165
|
};
|
|
169
166
|
const joinSuccessHandler = () => {
|
|
@@ -299,13 +296,13 @@ const ensureClient = async () => {
|
|
|
299
296
|
}
|
|
300
297
|
};
|
|
301
298
|
exports.ensureClient = ensureClient;
|
|
302
|
-
const cleanup = () => {
|
|
299
|
+
const cleanup = async () => {
|
|
303
300
|
if (reconnectTimer) {
|
|
304
301
|
clearTimeout(reconnectTimer);
|
|
305
302
|
reconnectTimer = null;
|
|
306
303
|
}
|
|
307
304
|
if (client) {
|
|
308
|
-
|
|
305
|
+
await (0, socket_1.safeDisconnect)(client);
|
|
309
306
|
client = null;
|
|
310
307
|
}
|
|
311
308
|
reconnectAttempts = 0;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeDisconnect = safeDisconnect;
|
|
4
|
+
/* eslint-disable no-await-in-loop */
|
|
5
|
+
/* eslint-disable no-console */
|
|
6
|
+
async function safeDisconnect(socket) {
|
|
7
|
+
try {
|
|
8
|
+
if (!socket)
|
|
9
|
+
return;
|
|
10
|
+
const conn = socket.conn ?? socket.socket?.conn ?? null;
|
|
11
|
+
if (!conn) {
|
|
12
|
+
socket.conn = null;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let state = conn.readyState;
|
|
16
|
+
// 0: CONNECTING, 1: OPEN, 2: CLOSING, 3: CLOSED
|
|
17
|
+
if (state === 0) {
|
|
18
|
+
let attempts = 0;
|
|
19
|
+
const MAX_ATTEMPTS = 10;
|
|
20
|
+
while (conn.readyState === 0 && attempts < MAX_ATTEMPTS) {
|
|
21
|
+
console.warn(`[safeDisconnect] Connection still CONNECTING, waiting before disconnect... attempts: ${attempts} / ${MAX_ATTEMPTS}`);
|
|
22
|
+
await new Promise((resolve) => {
|
|
23
|
+
setTimeout(resolve, 300);
|
|
24
|
+
});
|
|
25
|
+
attempts += 1;
|
|
26
|
+
if (conn.readyState !== 0)
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (conn.readyState === 0) {
|
|
30
|
+
console.warn('[safeDisconnect] Connection still CONNECTING after 10 attempts, skipping disconnect to avoid crash.');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
state = conn.readyState;
|
|
34
|
+
console.log(`[safeDisconnect] Connection state changed to ${state} after waiting ${attempts * 300}ms`);
|
|
35
|
+
}
|
|
36
|
+
if (state === 1 || state === 2) {
|
|
37
|
+
try {
|
|
38
|
+
// Phoenix 的 disconnect 本身是异步 teardown
|
|
39
|
+
await new Promise((resolve) => {
|
|
40
|
+
socket?.disconnect?.(() => resolve());
|
|
41
|
+
// fallback:防止回调永远不触发
|
|
42
|
+
setTimeout(resolve, 1500);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.warn('[safeDisconnect] socket.disconnect threw', err);
|
|
47
|
+
try {
|
|
48
|
+
conn.close();
|
|
49
|
+
}
|
|
50
|
+
catch (closeErr) {
|
|
51
|
+
console.warn('[safeDisconnect] conn.close threw', closeErr);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (state === 3) {
|
|
56
|
+
console.log('[safeDisconnect] Already CLOSED');
|
|
57
|
+
}
|
|
58
|
+
// 最后兜底清理引用
|
|
59
|
+
if (socket) {
|
|
60
|
+
socket.conn = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error('[safeDisconnect] Unexpected error', err);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.
|
|
6
|
+
"version": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"homepage": "https://www.arcblock.io/docs/blocklet-sdk-nodejs",
|
|
9
9
|
"main": "lib/index.js",
|
|
@@ -26,26 +26,26 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/constant": "1.17.
|
|
30
|
-
"@abtnode/db-cache": "1.17.
|
|
31
|
-
"@abtnode/util": "1.17.
|
|
32
|
-
"@arcblock/did": "^1.27.
|
|
33
|
-
"@arcblock/did-connect-js": "^1.27.
|
|
34
|
-
"@arcblock/did-ext": "^1.27.
|
|
35
|
-
"@arcblock/jwt": "^1.27.
|
|
36
|
-
"@arcblock/ws": "^1.27.
|
|
37
|
-
"@blocklet/constant": "1.17.
|
|
38
|
-
"@blocklet/env": "1.17.
|
|
29
|
+
"@abtnode/constant": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
30
|
+
"@abtnode/db-cache": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
31
|
+
"@abtnode/util": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
32
|
+
"@arcblock/did": "^1.27.4",
|
|
33
|
+
"@arcblock/did-connect-js": "^1.27.4",
|
|
34
|
+
"@arcblock/did-ext": "^1.27.4",
|
|
35
|
+
"@arcblock/jwt": "^1.27.4",
|
|
36
|
+
"@arcblock/ws": "^1.27.4",
|
|
37
|
+
"@blocklet/constant": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
38
|
+
"@blocklet/env": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
39
39
|
"@blocklet/error": "^0.3.2",
|
|
40
|
-
"@blocklet/meta": "1.17.
|
|
41
|
-
"@blocklet/server-js": "1.17.
|
|
42
|
-
"@blocklet/theme": "^3.2.
|
|
40
|
+
"@blocklet/meta": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
41
|
+
"@blocklet/server-js": "1.17.2-beta-20251110-023854-e91dad6f",
|
|
42
|
+
"@blocklet/theme": "^3.2.2",
|
|
43
43
|
"@did-connect/authenticator": "^2.2.8",
|
|
44
44
|
"@did-connect/handler": "^2.2.8",
|
|
45
45
|
"@nedb/core": "^2.1.5",
|
|
46
|
-
"@ocap/mcrypto": "^1.27.
|
|
47
|
-
"@ocap/util": "^1.27.
|
|
48
|
-
"@ocap/wallet": "^1.27.
|
|
46
|
+
"@ocap/mcrypto": "^1.27.4",
|
|
47
|
+
"@ocap/util": "^1.27.4",
|
|
48
|
+
"@ocap/wallet": "^1.27.4",
|
|
49
49
|
"axios": "^1.7.9",
|
|
50
50
|
"cheerio": "1.0.0-rc.12",
|
|
51
51
|
"debug": "^4.4.1",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"ts-node": "^10.9.1",
|
|
83
83
|
"typescript": "^5.6.3"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "272f9aeb4b24eba471c5a9f9a5b4a883e3249bbb"
|
|
86
86
|
}
|