@arcblock/ws 1.17.19 → 1.17.20
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/server/index.js +19 -10
- package/package.json +3 -3
package/lib/server/index.js
CHANGED
@@ -134,23 +134,29 @@ class WsServer extends EventEmitter {
|
|
134
134
|
}
|
135
135
|
|
136
136
|
const enableLog = options.enableLog !== undefined ? !!options.enableLog : true;
|
137
|
-
const { socketFilters } = options;
|
137
|
+
const { socketFilters, noCluster } = options;
|
138
138
|
const replyId = nanoid();
|
139
139
|
|
140
140
|
// Count of clients what will receive the message
|
141
141
|
// The count is NOT reliable
|
142
142
|
let count = 0;
|
143
|
-
eventHub.on(replyId, ({ count: c } = {}) => {
|
144
|
-
if (c) {
|
145
|
-
count += c;
|
146
|
-
}
|
147
|
-
});
|
148
143
|
|
149
|
-
|
144
|
+
if (noCluster) {
|
145
|
+
const { count: c } = this._doBroadCast({ topic, event, data, enableLog, socketFilters });
|
146
|
+
count = c;
|
147
|
+
} else {
|
148
|
+
eventHub.on(replyId, ({ count: c } = {}) => {
|
149
|
+
if (c) {
|
150
|
+
count += c;
|
151
|
+
}
|
152
|
+
});
|
153
|
+
|
154
|
+
eventHub.broadcast(this.broadcastEventName, { topic, event, data, options, enableLog, replyId, socketFilters });
|
150
155
|
|
151
|
-
|
152
|
-
|
153
|
-
|
156
|
+
// wait 600ms for message sending by each process
|
157
|
+
await sleep(600);
|
158
|
+
eventHub.off(replyId);
|
159
|
+
}
|
154
160
|
|
155
161
|
const opts = { count, topic, event, data, options };
|
156
162
|
cb(opts);
|
@@ -201,8 +207,11 @@ class WsServer extends EventEmitter {
|
|
201
207
|
if (count > 0 && replyId) {
|
202
208
|
eventHub.broadcast(replyId, { count });
|
203
209
|
}
|
210
|
+
|
211
|
+
return { count };
|
204
212
|
} catch (error) {
|
205
213
|
this.logger.error('_doBroadcast error', { error });
|
214
|
+
return { error };
|
206
215
|
}
|
207
216
|
}
|
208
217
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ws",
|
3
|
-
"version": "1.17.
|
3
|
+
"version": "1.17.20",
|
4
4
|
"description": "OCAP Chain websocket server and client",
|
5
5
|
"keywords": [
|
6
6
|
"websocket"
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"url": "https://github.com/ArcBlock/asset-chain/issues"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@arcblock/event-hub": "1.17.
|
37
|
+
"@arcblock/event-hub": "1.17.20",
|
38
38
|
"debug": "^4.3.4",
|
39
39
|
"eventemitter3": "^4.0.7",
|
40
40
|
"lodash": "^4.17.21",
|
@@ -45,5 +45,5 @@
|
|
45
45
|
"devDependencies": {
|
46
46
|
"get-port": "^5.1.1"
|
47
47
|
},
|
48
|
-
"gitHead": "
|
48
|
+
"gitHead": "daa53f1bec6b2f06f73b50fc8de91caa1d625611"
|
49
49
|
}
|