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/node/full-v5.mjs
CHANGED
|
@@ -871,7 +871,7 @@ function parse(input, loose) {
|
|
|
871
871
|
|
|
872
872
|
return {
|
|
873
873
|
keys: keys,
|
|
874
|
-
pattern: new RegExp('^' + pattern + (
|
|
874
|
+
pattern: new RegExp('^' + pattern + ('\/?$'), 'i')
|
|
875
875
|
};
|
|
876
876
|
}
|
|
877
877
|
|
|
@@ -897,6 +897,7 @@ class AbstractTopicRouter ::
|
|
|
897
897
|
async invoke(pkt, ctx) ::
|
|
898
898
|
add(topic_route, ...args) ::
|
|
899
899
|
remove(topic_route, priority) ::
|
|
900
|
+
count(topic_route) ::
|
|
900
901
|
clear(priority) ::
|
|
901
902
|
find(topic) :: // optional
|
|
902
903
|
mqtt_topic(topic_route)
|
|
@@ -936,6 +937,8 @@ const with_topic_router = mqtt_topic_router =>
|
|
|
936
937
|
|
|
937
938
|
let fn = args.at(-1)?.call ? args.pop() : null;
|
|
938
939
|
router.remove(topic_route, true, fn);
|
|
940
|
+
if (0 !== router.count(topic_route) ) {
|
|
941
|
+
return null}
|
|
939
942
|
|
|
940
943
|
let topic = router.mqtt_topic(topic_route);
|
|
941
944
|
return this.unsubscribe(topic, ...args ) }// topic_prefix
|
|
@@ -1004,6 +1007,17 @@ function mqtt_topic_path_router() {
|
|
|
1004
1007
|
query ={topic: query, tgt: args.pop()}; }
|
|
1005
1008
|
return _route_remove(lst, query)}
|
|
1006
1009
|
|
|
1010
|
+
, count(topic_route) {
|
|
1011
|
+
if (! topic_route) {
|
|
1012
|
+
return pri_lsts.reduce((r,l) => r+l.length, 0)}
|
|
1013
|
+
|
|
1014
|
+
let count = 0;
|
|
1015
|
+
for (let lst of pri_lsts) {
|
|
1016
|
+
for (let route of lst) {
|
|
1017
|
+
if (topic_route === route.topic) {
|
|
1018
|
+
count++;} } }
|
|
1019
|
+
return count}
|
|
1020
|
+
|
|
1007
1021
|
, clear(priority) {
|
|
1008
1022
|
if (null == priority) {
|
|
1009
1023
|
pri_lsts = [[],[]]; }// null clears both lists
|
|
@@ -1047,21 +1061,21 @@ function * _routes_iter(all_route_lists, topic) {
|
|
|
1047
1061
|
|
|
1048
1062
|
|
|
1049
1063
|
function _route_remove(all_route_lists, query) {
|
|
1050
|
-
let
|
|
1064
|
+
let n_removed = 0;
|
|
1051
1065
|
for (let lst of all_route_lists) {
|
|
1052
1066
|
let idx_tip = 0;
|
|
1053
1067
|
for (let route of lst) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1068
|
+
if (route.topic === query.topic) {
|
|
1069
|
+
if (null == query.tgt || route.tgt === query.tgt) {
|
|
1070
|
+
// skip matching routes to remove from compacted list
|
|
1071
|
+
n_removed++;
|
|
1072
|
+
continue} }
|
|
1058
1073
|
|
|
1059
|
-
|
|
1074
|
+
lst[idx_tip++] = route;}
|
|
1060
1075
|
|
|
1061
1076
|
// truncate remaining list
|
|
1062
1077
|
lst.length = idx_tip;}
|
|
1063
|
-
|
|
1064
|
-
return ans}
|
|
1078
|
+
return n_removed}
|
|
1065
1079
|
|
|
1066
1080
|
function decode_varint(u8, i0=0, invalid) {
|
|
1067
1081
|
let shift=0, i=i0, b=u8[i++], n=(b & 0x7f);
|
|
@@ -1271,8 +1285,9 @@ class MQTTBase {
|
|
|
1271
1285
|
return this.conn.on_conn(pkt, response)}
|
|
1272
1286
|
|
|
1273
1287
|
async disconnect(pkt={}) {
|
|
1274
|
-
let response =
|
|
1275
|
-
|
|
1288
|
+
let response = this._send0('disconnect', pkt);
|
|
1289
|
+
await this.conn.on_dis(pkt, response);
|
|
1290
|
+
return await response}
|
|
1276
1291
|
|
|
1277
1292
|
async auth(pkt={}) {
|
|
1278
1293
|
let response = await this._send0('auth', pkt, 'auth');
|
|
@@ -1437,11 +1452,12 @@ function _mqtt_conn(opt, client, [on_mqtt, pkt_future]) {
|
|
|
1437
1452
|
_dfn_send0.e(err); }// send error to uses of _send0 (connect, auth)
|
|
1438
1453
|
_abort.e(err); // abort in-progress connections
|
|
1439
1454
|
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1455
|
+
if (conn.is_set) {
|
|
1456
|
+
delete conn.is_set;
|
|
1457
|
+
conn.ready = handshake();
|
|
1458
|
+
client.conn_emit('on_disconnect', false===err, err);} }
|
|
1443
1459
|
|
|
1444
|
-
, abort() {
|
|
1460
|
+
, abort(err) {
|
|
1445
1461
|
_dfn_ready.e(err); // abort all messages awaiting ready state
|
|
1446
1462
|
return conn.reset(err)}
|
|
1447
1463
|
|
|
@@ -1555,7 +1571,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1555
1571
|
|
|
1556
1572
|
// on_ready(client) ::
|
|
1557
1573
|
// on_reconnect(client) ::
|
|
1558
|
-
on_disconnect(client, intentional) {
|
|
1574
|
+
on_disconnect(client, intentional, err) {
|
|
1559
1575
|
if (! intentional) {
|
|
1560
1576
|
return client.on_reconnect?.()} }
|
|
1561
1577
|
|
|
@@ -1565,12 +1581,12 @@ class MQTTCore extends MQTTBase {
|
|
|
1565
1581
|
if (opt.toFixed) {opt ={delay: opt};}
|
|
1566
1582
|
return this.with({
|
|
1567
1583
|
on_reconnect() {
|
|
1568
|
-
this.delay(opt.delay || 2000)
|
|
1584
|
+
this.delay(opt.delay || 2000, opt.jitter)
|
|
1569
1585
|
.then(this.reconnect)
|
|
1570
1586
|
.then(opt.reconnect, opt.error);} }) }
|
|
1571
1587
|
|
|
1572
|
-
delay(ms) {
|
|
1573
|
-
return new Promise(done => setTimeout(done, ms)) }
|
|
1588
|
+
delay(ms, ms_jitter=0.2*ms) {
|
|
1589
|
+
return new Promise(done => setTimeout(done, 0 | (ms + ms_jitter*Math.random()))) }
|
|
1574
1590
|
|
|
1575
1591
|
with_async_iter(async_iter, write_u8_pkt) {
|
|
1576
1592
|
this.conn.setup(async_iter,
|
|
@@ -1666,6 +1682,9 @@ class MQTTCore extends MQTTBase {
|
|
|
1666
1682
|
websock.onmessage = evt =>(
|
|
1667
1683
|
on_mqtt_chunk(new Uint8Array(evt.data)) );
|
|
1668
1684
|
|
|
1685
|
+
websock.onerror = evt => {
|
|
1686
|
+
conn.reset(new Error('websocket error'));};
|
|
1687
|
+
|
|
1669
1688
|
websock.onclose = evt => {
|
|
1670
1689
|
if (! evt.wasClean) {
|
|
1671
1690
|
var err = new Error('websocket close');
|
|
@@ -1676,7 +1695,7 @@ class MQTTCore extends MQTTBase {
|
|
|
1676
1695
|
|
|
1677
1696
|
return this} }
|
|
1678
1697
|
|
|
1679
|
-
const version = '0.6.
|
|
1698
|
+
const version = '0.6.7-node';
|
|
1680
1699
|
|
|
1681
1700
|
const MQTTClient_v4 = /* #__PURE__ */
|
|
1682
1701
|
with_topic_path_router(
|