u8-mqtt 0.6.5 → 0.6.7
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/cjs/basic-v4.cjs +16 -11
- package/cjs/basic-v4.cjs.map +1 -1
- package/cjs/basic-v5.cjs +16 -11
- package/cjs/basic-v5.cjs.map +1 -1
- package/cjs/full-v4.cjs +39 -20
- package/cjs/full-v4.cjs.map +1 -1
- package/cjs/full-v5.cjs +39 -20
- package/cjs/full-v5.cjs.map +1 -1
- package/cjs/index.cjs +39 -20
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +39 -20
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +39 -20
- package/cjs/v5.cjs.map +1 -1
- package/code/_conn.jsy +5 -4
- package/code/base.jsy +3 -2
- package/code/core.jsy +7 -4
- package/code/router_path.jsy +20 -10
- package/code/with_topic_router.jsy +3 -0
- package/esm/basic-v4.js +16 -11
- package/esm/basic-v4.js.map +1 -1
- package/esm/basic-v5.js +16 -11
- package/esm/basic-v5.js.map +1 -1
- package/esm/deno/basic-v4.js +16 -11
- package/esm/deno/basic-v4.js.map +1 -1
- package/esm/deno/basic-v5.js +16 -11
- package/esm/deno/basic-v5.js.map +1 -1
- package/esm/deno/full-v4.js +39 -20
- package/esm/deno/full-v4.js.map +1 -1
- package/esm/deno/full-v5.js +39 -20
- package/esm/deno/full-v5.js.map +1 -1
- package/esm/deno/index.js +39 -20
- package/esm/deno/index.js.map +1 -1
- package/esm/deno/v4.js +39 -20
- package/esm/deno/v4.js.map +1 -1
- package/esm/deno/v5.js +39 -20
- package/esm/deno/v5.js.map +1 -1
- package/esm/full-v4.js +39 -20
- package/esm/full-v4.js.map +1 -1
- package/esm/full-v5.js +39 -20
- package/esm/full-v5.js.map +1 -1
- package/esm/index.js +39 -20
- package/esm/index.js.map +1 -1
- package/esm/node/basic-v4.js +16 -11
- package/esm/node/basic-v4.js.map +1 -1
- package/esm/node/basic-v4.mjs +16 -11
- package/esm/node/basic-v4.mjs.map +1 -1
- package/esm/node/basic-v5.js +16 -11
- package/esm/node/basic-v5.js.map +1 -1
- package/esm/node/basic-v5.mjs +16 -11
- package/esm/node/basic-v5.mjs.map +1 -1
- package/esm/node/full-v4.js +39 -20
- package/esm/node/full-v4.js.map +1 -1
- package/esm/node/full-v4.mjs +39 -20
- package/esm/node/full-v4.mjs.map +1 -1
- package/esm/node/full-v5.js +39 -20
- package/esm/node/full-v5.js.map +1 -1
- package/esm/node/full-v5.mjs +39 -20
- package/esm/node/full-v5.mjs.map +1 -1
- package/esm/node/index.js +39 -20
- package/esm/node/index.js.map +1 -1
- package/esm/node/index.mjs +39 -20
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +39 -20
- package/esm/node/v4.js.map +1 -1
- package/esm/node/v4.mjs +39 -20
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +39 -20
- package/esm/node/v5.js.map +1 -1
- package/esm/node/v5.mjs +39 -20
- package/esm/node/v5.mjs.map +1 -1
- package/esm/v4.js +39 -20
- package/esm/v4.js.map +1 -1
- package/esm/v5.js +39 -20
- package/esm/v5.js.map +1 -1
- package/esm/web/basic-v4.js +16 -11
- package/esm/web/basic-v4.js.map +1 -1
- package/esm/web/basic-v4.min.js +1 -1
- package/esm/web/basic-v4.min.js.br +0 -0
- package/esm/web/basic-v4.min.js.gz +0 -0
- package/esm/web/basic-v5.js +16 -11
- package/esm/web/basic-v5.js.map +1 -1
- package/esm/web/basic-v5.min.js +1 -1
- package/esm/web/basic-v5.min.js.br +0 -0
- package/esm/web/basic-v5.min.js.gz +0 -0
- package/esm/web/full-v4.js +39 -20
- package/esm/web/full-v4.js.map +1 -1
- package/esm/web/full-v4.min.js +1 -1
- package/esm/web/full-v4.min.js.br +0 -0
- package/esm/web/full-v4.min.js.gz +0 -0
- package/esm/web/full-v5.js +39 -20
- package/esm/web/full-v5.js.map +1 -1
- package/esm/web/full-v5.min.js +1 -1
- package/esm/web/full-v5.min.js.br +0 -0
- package/esm/web/full-v5.min.js.gz +0 -0
- package/esm/web/index.js +39 -20
- package/esm/web/index.js.map +1 -1
- package/esm/web/index.min.js +1 -1
- package/esm/web/index.min.js.br +0 -0
- package/esm/web/index.min.js.gz +0 -0
- package/esm/web/v4.js +39 -20
- package/esm/web/v4.js.map +1 -1
- package/esm/web/v4.min.js +1 -1
- package/esm/web/v4.min.js.br +0 -0
- package/esm/web/v4.min.js.gz +0 -0
- package/esm/web/v5.js +39 -20
- package/esm/web/v5.js.map +1 -1
- package/esm/web/v5.min.js +1 -1
- package/esm/web/v5.min.js.br +0 -0
- package/esm/web/v5.min.js.gz +0 -0
- package/package.json +16 -17
package/esm/full-v5.js
CHANGED
|
@@ -868,7 +868,7 @@ function parse(input, loose) {
|
|
|
868
868
|
|
|
869
869
|
return {
|
|
870
870
|
keys: keys,
|
|
871
|
-
pattern: new RegExp('^' + pattern + (
|
|
871
|
+
pattern: new RegExp('^' + pattern + ('\/?$'), 'i')
|
|
872
872
|
};
|
|
873
873
|
}
|
|
874
874
|
|
|
@@ -894,6 +894,7 @@ class AbstractTopicRouter ::
|
|
|
894
894
|
async invoke(pkt, ctx) ::
|
|
895
895
|
add(topic_route, ...args) ::
|
|
896
896
|
remove(topic_route, priority) ::
|
|
897
|
+
count(topic_route) ::
|
|
897
898
|
clear(priority) ::
|
|
898
899
|
find(topic) :: // optional
|
|
899
900
|
mqtt_topic(topic_route)
|
|
@@ -933,6 +934,8 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
933
934
|
|
|
934
935
|
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
935
936
|
router.remove(topic_route, true, fn);
|
|
937
|
+
if (0 !== router.count(topic_route) ) {
|
|
938
|
+
return null}
|
|
936
939
|
|
|
937
940
|
let topic = router.mqtt_topic(topic_route);
|
|
938
941
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
@@ -1001,6 +1004,17 @@ function mqtt_topic_path_router() {
|
|
|
1001
1004
|
query ={topic: query, tgt: args.pop()}; }
|
|
1002
1005
|
return _route_remove(lst, query)}
|
|
1003
1006
|
|
|
1007
|
+
, count(topic_route) {
|
|
1008
|
+
if (! topic_route) {
|
|
1009
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)}
|
|
1010
|
+
|
|
1011
|
+
let count = 0;
|
|
1012
|
+
for (let lst of pri_lsts) {
|
|
1013
|
+
for (let route of lst) {
|
|
1014
|
+
if (topic_route === route.topic) {
|
|
1015
|
+
count++;} } }
|
|
1016
|
+
return count}
|
|
1017
|
+
|
|
1004
1018
|
, clear(priority) {
|
|
1005
1019
|
if (null == priority) {
|
|
1006
1020
|
pri_lsts = [[],[]]; }// null clears both lists
|
|
@@ -1044,21 +1058,21 @@ function * _routes_iter(all_route_lists, topic) {
|
|
|
1044
1058
|
|
|
1045
1059
|
|
|
1046
1060
|
function _route_remove(all_route_lists, query) {
|
|
1047
|
-
let
|
|
1061
|
+
let n_removed = 0;
|
|
1048
1062
|
for (let lst of all_route_lists) {
|
|
1049
1063
|
let idx_tip = 0;
|
|
1050
1064
|
for (let route of lst) {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1065
|
+
if (route.topic === query.topic) {
|
|
1066
|
+
if (null == query.tgt || route.tgt === query.tgt) {
|
|
1067
|
+
// skip matching routes to remove from compacted list
|
|
1068
|
+
n_removed++;
|
|
1069
|
+
continue} }
|
|
1055
1070
|
|
|
1056
|
-
|
|
1071
|
+
lst[idx_tip++] = route;}
|
|
1057
1072
|
|
|
1058
1073
|
// truncate remaining list
|
|
1059
1074
|
lst.length = idx_tip;}
|
|
1060
|
-
|
|
1061
|
-
return ans}
|
|
1075
|
+
return n_removed}
|
|
1062
1076
|
|
|
1063
1077
|
function decode_varint(u8, i0=0, invalid) {
|
|
1064
1078
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1268,8 +1282,9 @@ class MQTTBase {
|
|
|
1268
1282
|
return this.conn.on_conn(pkt, response)}
|
|
1269
1283
|
|
|
1270
1284
|
async disconnect(pkt={}) {
|
|
1271
|
-
let response =
|
|
1272
|
-
|
|
1285
|
+
let response = this._send0('disconnect', pkt);
|
|
1286
|
+
await this.conn.on_dis(pkt, response);
|
|
1287
|
+
return await response}
|
|
1273
1288
|
|
|
1274
1289
|
async auth(pkt={}) {
|
|
1275
1290
|
let response = await this._send0('auth', pkt, 'auth');
|
|
@@ -1434,11 +1449,12 @@ function _mqtt_conn(opt, client, [on_mqtt, pkt_future]) {
|
|
|
1434
1449
|
_dfn_send0.e(err); }// send error to uses of _send0 (connect, auth)
|
|
1435
1450
|
_abort.e(err); // abort in-progress connections
|
|
1436
1451
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1452
|
+
if (conn.is_set) {
|
|
1453
|
+
delete conn.is_set;
|
|
1454
|
+
conn.ready = handshake();
|
|
1455
|
+
client.conn_emit('on_disconnect', false===err, err);} }
|
|
1440
1456
|
|
|
1441
|
-
, abort() {
|
|
1457
|
+
, abort(err) {
|
|
1442
1458
|
_dfn_ready.e(err); // abort all messages awaiting ready state
|
|
1443
1459
|
return conn.reset(err)}
|
|
1444
1460
|
|
|
@@ -1552,7 +1568,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1552
1568
|
|
|
1553
1569
|
// on_ready(client) ::
|
|
1554
1570
|
// on_reconnect(client) ::
|
|
1555
|
-
on_disconnect(client, intentional) {
|
|
1571
|
+
on_disconnect(client, intentional, err) {
|
|
1556
1572
|
if (! intentional) {
|
|
1557
1573
|
return client.on_reconnect?.()} }
|
|
1558
1574
|
|
|
@@ -1562,12 +1578,12 @@ class MQTTCore extends MQTTBase {
|
|
|
1562
1578
|
if (opt.toFixed) {opt ={delay: opt};}
|
|
1563
1579
|
return this.with({
|
|
1564
1580
|
on_reconnect() {
|
|
1565
|
-
this.delay(opt.delay || 2000)
|
|
1581
|
+
this.delay(opt.delay || 2000, opt.jitter)
|
|
1566
1582
|
.then(this.reconnect)
|
|
1567
1583
|
.then(opt.reconnect, opt.error);} }) }
|
|
1568
1584
|
|
|
1569
|
-
delay(ms) {
|
|
1570
|
-
return new Promise(done => setTimeout(done, ms)) }
|
|
1585
|
+
delay(ms, ms_jitter=0.2*ms) {
|
|
1586
|
+
return new Promise(done => setTimeout(done, 0 | (ms + ms_jitter*Math.random()))) }
|
|
1571
1587
|
|
|
1572
1588
|
with_async_iter(async_iter, write_u8_pkt) {
|
|
1573
1589
|
this.conn.setup(async_iter,
|
|
@@ -1663,6 +1679,9 @@ class MQTTCore extends MQTTBase {
|
|
|
1663
1679
|
websock.onmessage = evt =>(
|
|
1664
1680
|
on_mqtt_chunk(new Uint8Array(evt.data)) );
|
|
1665
1681
|
|
|
1682
|
+
websock.onerror = evt => {
|
|
1683
|
+
conn.reset(new Error('websocket error'));};
|
|
1684
|
+
|
|
1666
1685
|
websock.onclose = evt => {
|
|
1667
1686
|
if (! evt.wasClean) {
|
|
1668
1687
|
var err = new Error('websocket close');
|
|
@@ -1673,7 +1692,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1673
1692
|
|
|
1674
1693
|
return this} }
|
|
1675
1694
|
|
|
1676
|
-
const version = '0.6.
|
|
1695
|
+
const version = '0.6.7';
|
|
1677
1696
|
|
|
1678
1697
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1679
1698
|
with_topic_path_router(
|