@arcblock/ws 1.16.15 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/server/index.js +8 -4
- package/package.json +4 -4
package/lib/server/index.js
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
const EventEmitter = require('events');
|
2
2
|
const cluster = require('cluster');
|
3
3
|
|
4
|
-
const
|
4
|
+
const { nanoid } = require('nanoid');
|
5
5
|
const WebSocket = require('ws');
|
6
6
|
const eventHub = cluster.isMaster ? require('@arcblock/event-hub/single') : require('@arcblock/event-hub');
|
7
7
|
|
8
8
|
const createLogger = require('../logger');
|
9
9
|
|
10
|
-
const sleep = (timeout) =>
|
10
|
+
const sleep = (timeout) =>
|
11
|
+
new Promise((resolve) => {
|
12
|
+
setTimeout(resolve, timeout);
|
13
|
+
});
|
11
14
|
|
12
15
|
const reply = (socket, topic, event, response, status = 'ok') => {
|
13
16
|
if (socket.readyState === WebSocket.OPEN) {
|
@@ -74,6 +77,7 @@ class WsServer extends EventEmitter {
|
|
74
77
|
const { pathname } = new URL(request.url, `http://${request.headers.host || 'unknown'}`);
|
75
78
|
this.logger.debug('connect attempt', { pathname });
|
76
79
|
if (this.pathname && pathname !== this.pathname) {
|
80
|
+
socket.write('HTTP/1.1 404 Pathname mismatch\r\n\r\n');
|
77
81
|
socket.destroy();
|
78
82
|
return;
|
79
83
|
}
|
@@ -128,7 +132,7 @@ class WsServer extends EventEmitter {
|
|
128
132
|
}
|
129
133
|
|
130
134
|
const enableLog = options.enableLog !== undefined ? !!options.enableLog : true;
|
131
|
-
const replyId =
|
135
|
+
const replyId = nanoid();
|
132
136
|
|
133
137
|
// Count of clients what will receive the message
|
134
138
|
// The count is NOT reliable
|
@@ -239,7 +243,7 @@ class WsServer extends EventEmitter {
|
|
239
243
|
* @param {socket} socket
|
240
244
|
*/
|
241
245
|
async onWssConnection(socket) {
|
242
|
-
socket.id =
|
246
|
+
socket.id = nanoid();
|
243
247
|
refreshHeartbeat(socket);
|
244
248
|
this.logger.debug('socket connected', { id: socket.id });
|
245
249
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ws",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.17.0",
|
4
4
|
"description": "OCAP Chain websocket server and client",
|
5
5
|
"keywords": [
|
6
6
|
"websocket"
|
@@ -34,15 +34,15 @@
|
|
34
34
|
"url": "https://github.com/ArcBlock/asset-chain/issues"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@arcblock/event-hub": "1.
|
37
|
+
"@arcblock/event-hub": "1.17.0",
|
38
38
|
"debug": "^4.3.3",
|
39
39
|
"eventemitter3": "^4.0.4",
|
40
|
+
"nanoid": "3.x",
|
40
41
|
"phoenix": "1.5.12",
|
41
|
-
"uuid": "^8.3.0",
|
42
42
|
"ws": "^8.2.2"
|
43
43
|
},
|
44
44
|
"devDependencies": {
|
45
45
|
"get-port": "^5.1.1"
|
46
46
|
},
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "f0944b60a5fb4115e1a3727bb07f68174bc56c5c"
|
48
48
|
}
|