wspromisify 3.0.3 → 3.1.1
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/README.md +1 -0
- package/dist/bundle.cjs +17 -6
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.mjs +17 -6
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ interface Config {
|
|
|
72
72
|
server: { // Unique id's and data keys to negotiate with back-end.
|
|
73
73
|
id_key: 'id'
|
|
74
74
|
data_key: 'data'
|
|
75
|
+
on_collision: 'error'|'pass'|'ignore' // if a message with unregistred id_key value has come. pass -> handle in 'message-ext'.
|
|
75
76
|
}
|
|
76
77
|
ping: { // Pings to avoid interruptions or false to disable.
|
|
77
78
|
interval: number // inter-ping interval. default: 55.
|
package/dist/bundle.cjs
CHANGED
|
@@ -284,7 +284,7 @@ const default_config = () => ({
|
|
|
284
284
|
}),
|
|
285
285
|
decode: (rawMessage) => JSON.parse(rawMessage),
|
|
286
286
|
protocols: [], pipes: [],
|
|
287
|
-
server: { id_key: 'id', data_key: 'data' },
|
|
287
|
+
server: { id_key: 'id', data_key: 'data', on_collision: 'error' },
|
|
288
288
|
ping: { interval: 55, timeout: 30, out: 'ping', in: 'pong' }
|
|
289
289
|
});
|
|
290
290
|
const processConfig = (config) => {
|
|
@@ -313,6 +313,7 @@ const nil = null, inf = Infinity;
|
|
|
313
313
|
const resolved = Promise.resolve(nil);
|
|
314
314
|
const label_message = 'message';
|
|
315
315
|
const label_message_ext = 'message-ext';
|
|
316
|
+
const label_error = 'error';
|
|
316
317
|
const zipnum = new J();
|
|
317
318
|
const dnow = () => Date.now();
|
|
318
319
|
const now = () => dnow() / 1e3;
|
|
@@ -455,7 +456,7 @@ class WebSocketClient {
|
|
|
455
456
|
const { reconnect } = config;
|
|
456
457
|
this.ws = ws;
|
|
457
458
|
clear_q(call_q(this.queue.on_ready));
|
|
458
|
-
const { id_key, data_key } = config.server;
|
|
459
|
+
const { id_key, data_key, on_collision } = config.server;
|
|
459
460
|
// works also on previously opened sockets that do not fire 'open' event.
|
|
460
461
|
this.call('open', ws);
|
|
461
462
|
for (const { msg } of queue.send.values())
|
|
@@ -486,11 +487,21 @@ class WebSocketClient {
|
|
|
486
487
|
this.call(label_message, d);
|
|
487
488
|
q.ff(d);
|
|
488
489
|
}
|
|
490
|
+
else
|
|
491
|
+
switch (on_collision) {
|
|
492
|
+
case 'error':
|
|
493
|
+
const err = {
|
|
494
|
+
data,
|
|
495
|
+
message: `WSP: id_key exists in the incoming message, but does not exist in the queue!`
|
|
496
|
+
};
|
|
497
|
+
this.log(label_error, err);
|
|
498
|
+
this.call(label_error, err);
|
|
499
|
+
case 'ignore': return;
|
|
500
|
+
case 'pass': break;
|
|
501
|
+
}
|
|
489
502
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
this.call(label_message_ext, { data });
|
|
493
|
-
}
|
|
503
|
+
this.log(label_message_ext, data);
|
|
504
|
+
this.call(label_message_ext, { data });
|
|
494
505
|
}
|
|
495
506
|
catch (err) {
|
|
496
507
|
console.error(err, `WSP: Decode error. Got: ${raw}`);
|
package/dist/bundle.d.ts
CHANGED
package/dist/bundle.mjs
CHANGED
|
@@ -282,7 +282,7 @@ const default_config = () => ({
|
|
|
282
282
|
}),
|
|
283
283
|
decode: (rawMessage) => JSON.parse(rawMessage),
|
|
284
284
|
protocols: [], pipes: [],
|
|
285
|
-
server: { id_key: 'id', data_key: 'data' },
|
|
285
|
+
server: { id_key: 'id', data_key: 'data', on_collision: 'error' },
|
|
286
286
|
ping: { interval: 55, timeout: 30, out: 'ping', in: 'pong' }
|
|
287
287
|
});
|
|
288
288
|
const processConfig = (config) => {
|
|
@@ -311,6 +311,7 @@ const nil = null, inf = Infinity;
|
|
|
311
311
|
const resolved = Promise.resolve(nil);
|
|
312
312
|
const label_message = 'message';
|
|
313
313
|
const label_message_ext = 'message-ext';
|
|
314
|
+
const label_error = 'error';
|
|
314
315
|
const zipnum = new J();
|
|
315
316
|
const dnow = () => Date.now();
|
|
316
317
|
const now = () => dnow() / 1e3;
|
|
@@ -453,7 +454,7 @@ class WebSocketClient {
|
|
|
453
454
|
const { reconnect } = config;
|
|
454
455
|
this.ws = ws;
|
|
455
456
|
clear_q(call_q(this.queue.on_ready));
|
|
456
|
-
const { id_key, data_key } = config.server;
|
|
457
|
+
const { id_key, data_key, on_collision } = config.server;
|
|
457
458
|
// works also on previously opened sockets that do not fire 'open' event.
|
|
458
459
|
this.call('open', ws);
|
|
459
460
|
for (const { msg } of queue.send.values())
|
|
@@ -484,11 +485,21 @@ class WebSocketClient {
|
|
|
484
485
|
this.call(label_message, d);
|
|
485
486
|
q.ff(d);
|
|
486
487
|
}
|
|
488
|
+
else
|
|
489
|
+
switch (on_collision) {
|
|
490
|
+
case 'error':
|
|
491
|
+
const err = {
|
|
492
|
+
data,
|
|
493
|
+
message: `WSP: id_key exists in the incoming message, but does not exist in the queue!`
|
|
494
|
+
};
|
|
495
|
+
this.log(label_error, err);
|
|
496
|
+
this.call(label_error, err);
|
|
497
|
+
case 'ignore': return;
|
|
498
|
+
case 'pass': break;
|
|
499
|
+
}
|
|
487
500
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
this.call(label_message_ext, { data });
|
|
491
|
-
}
|
|
501
|
+
this.log(label_message_ext, data);
|
|
502
|
+
this.call(label_message_ext, { data });
|
|
492
503
|
}
|
|
493
504
|
catch (err) {
|
|
494
505
|
console.error(err, `WSP: Decode error. Got: ${raw}`);
|
package/package.json
CHANGED
|
@@ -30,18 +30,7 @@
|
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "git+https://github.com/houd1ni/WebsocketPromisify.git"
|
|
32
32
|
},
|
|
33
|
-
"
|
|
34
|
-
"lint": "tslint src/*.ts",
|
|
35
|
-
"test": "tsx test/index",
|
|
36
|
-
"test:report": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
37
|
-
"gentypes": "dts-bundle-generator --no-check -o dist/bundle.d.ts src/WSC.ts",
|
|
38
|
-
"dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
|
|
39
|
-
"prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
|
|
40
|
-
"prod:es": "cross-env NODE_ENV=production BUILD=es rollup -c",
|
|
41
|
-
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
|
-
"all": "npm run dev && npm run prod"
|
|
43
|
-
},
|
|
44
|
-
"version": "3.0.3",
|
|
33
|
+
"version": "3.1.1",
|
|
45
34
|
"type": "module",
|
|
46
35
|
"exports": {
|
|
47
36
|
".": {
|
|
@@ -75,5 +64,16 @@
|
|
|
75
64
|
"dependencies": {
|
|
76
65
|
"pepka": "^1.13.0",
|
|
77
66
|
"zipnum": "^2.1.3"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"lint": "tslint src/*.ts",
|
|
70
|
+
"test": "tsx test/index",
|
|
71
|
+
"test:report": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
72
|
+
"gentypes": "dts-bundle-generator --no-check -o dist/bundle.d.ts src/WSC.ts",
|
|
73
|
+
"dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
|
|
74
|
+
"prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
|
|
75
|
+
"prod:es": "cross-env NODE_ENV=production BUILD=es rollup -c",
|
|
76
|
+
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
77
|
+
"all": "npm run dev && npm run prod"
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|