u8-mqtt 0.0.28 → 0.1.2
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/index.cjs +65 -34
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +65 -34
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +65 -34
- package/cjs/v5.cjs.map +1 -1
- package/code/base.jsy +64 -33
- package/esm/deno/index.js +1502 -0
- package/esm/deno/index.js.map +1 -0
- package/esm/deno/index.mjs +65 -34
- package/esm/deno/index.mjs.map +1 -1
- package/esm/deno/v4.js +1496 -0
- package/esm/deno/v4.js.map +1 -0
- package/esm/deno/v4.mjs +65 -34
- package/esm/deno/v4.mjs.map +1 -1
- package/esm/deno/v5.js +1496 -0
- package/esm/deno/v5.js.map +1 -0
- package/esm/deno/v5.mjs +65 -34
- package/esm/deno/v5.mjs.map +1 -1
- package/esm/node/index.js +1504 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/index.mjs +65 -34
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +1498 -0
- package/esm/node/v4.js.map +1 -0
- package/esm/node/v4.mjs +65 -34
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +1498 -0
- package/esm/node/v5.js.map +1 -0
- package/esm/node/v5.mjs +65 -34
- package/esm/node/v5.mjs.map +1 -1
- package/esm/web/index.js +1502 -0
- package/esm/web/index.js.map +1 -0
- package/esm/web/index.min.mjs +1 -1
- package/esm/web/index.mjs +65 -34
- package/esm/web/index.mjs.map +1 -1
- package/esm/web/v4.js +1496 -0
- package/esm/web/v4.js.map +1 -0
- package/esm/web/v4.min.mjs +1 -1
- package/esm/web/v4.mjs +65 -34
- package/esm/web/v4.mjs.map +1 -1
- package/esm/web/v5.js +1496 -0
- package/esm/web/v5.js.map +1 -0
- package/esm/web/v5.min.mjs +1 -1
- package/esm/web/v5.mjs +65 -34
- package/esm/web/v5.mjs.map +1 -1
- package/package.json +7 -7
package/cjs/v5.cjs
CHANGED
|
@@ -1186,6 +1186,10 @@ class MQTTBaseClient {
|
|
|
1186
1186
|
subscribe(pkt, ex) {
|
|
1187
1187
|
pkt = _as_topics(pkt, ex);
|
|
1188
1188
|
return this._send('subscribe', pkt, pkt)}
|
|
1189
|
+
_sub_chain(topic, ex) {
|
|
1190
|
+
let subs = this.subs ||(this.subs = new Map());
|
|
1191
|
+
subs.set(topic, this.subscribe([[ topic ]], ex));
|
|
1192
|
+
return this }// fluent api -- return this and track side effects
|
|
1189
1193
|
|
|
1190
1194
|
// alias: unsub
|
|
1191
1195
|
unsubscribe(pkt, ex) {
|
|
@@ -1196,15 +1200,30 @@ class MQTTBaseClient {
|
|
|
1196
1200
|
|
|
1197
1201
|
// alias: sub_topic
|
|
1198
1202
|
subscribe_topic(topic_route, ...args) {
|
|
1199
|
-
let topic = this.topic_for(topic_route);
|
|
1200
1203
|
this.router.add(topic_route, true, args.pop() );// handler
|
|
1201
|
-
|
|
1202
|
-
return this}
|
|
1204
|
+
let topic = this.topic_for(topic_route);
|
|
1205
|
+
return this._sub_chain(topic, args.pop() ) }// ex
|
|
1203
1206
|
|
|
1204
1207
|
// alias: unsub_topic
|
|
1205
1208
|
unsubscribe_topic(topic_route) {
|
|
1209
|
+
this.router.remove(topic_route, true);
|
|
1206
1210
|
let topic = this.topic_for(topic_route);
|
|
1211
|
+
return this.unsubscribe([[ topic ]]) }
|
|
1212
|
+
|
|
1213
|
+
// alias: shared_sub
|
|
1214
|
+
shared_subscribe(group, topic_route, ...args) {
|
|
1215
|
+
this.router.add(topic_route, true, args.pop() );// handler
|
|
1216
|
+
let topic = this.topic_for(topic_route);
|
|
1217
|
+
if (null != group) {
|
|
1218
|
+
topic = `$share/${group}/${topic}`;}
|
|
1219
|
+
return this._sub_chain(topic, args.pop() ) }// ex
|
|
1220
|
+
|
|
1221
|
+
// alias: shared_unsub
|
|
1222
|
+
shared_unsubscribe(group, topic_route) {
|
|
1207
1223
|
this.router.remove(topic_route, true);
|
|
1224
|
+
let topic = this.topic_for(topic_route);
|
|
1225
|
+
if (null != group) {
|
|
1226
|
+
topic = `$share/${group}/${topic}`;}
|
|
1208
1227
|
return this.unsubscribe([[ topic ]]) }
|
|
1209
1228
|
|
|
1210
1229
|
topic_for(topic_route) {
|
|
@@ -1212,18 +1231,18 @@ class MQTTBaseClient {
|
|
|
1212
1231
|
|
|
1213
1232
|
|
|
1214
1233
|
// alias: pub
|
|
1215
|
-
publish(pkt,
|
|
1216
|
-
post(topic, payload) {return _pub.m(this, topic, payload)}
|
|
1217
|
-
send(topic, payload) {return _pub.mq(this, topic, payload)}
|
|
1218
|
-
store(topic, payload) {return _pub.mqr(this, topic, payload)}
|
|
1234
|
+
publish(pkt, pub_opt) {return _pub(this, pkt, pub_opt)}
|
|
1235
|
+
post(topic, payload, pub_opt) {return _pub.m(this, topic, payload, pub_opt)}
|
|
1236
|
+
send(topic, payload, pub_opt) {return _pub.mq(this, topic, payload, pub_opt)}
|
|
1237
|
+
store(topic, payload, pub_opt) {return _pub.mqr(this, topic, payload, pub_opt)}
|
|
1219
1238
|
|
|
1220
|
-
json_post(topic, msg) {return _pub.o(this, topic, msg)}
|
|
1221
|
-
json_send(topic, msg) {return _pub.oq(this, topic, msg)}
|
|
1222
|
-
json_store(topic, msg) {return _pub.oqr(this, topic, msg)}
|
|
1239
|
+
json_post(topic, msg, pub_opt) {return _pub.o(this, topic, msg, pub_opt)}
|
|
1240
|
+
json_send(topic, msg, pub_opt) {return _pub.oq(this, topic, msg, pub_opt)}
|
|
1241
|
+
json_store(topic, msg, pub_opt) {return _pub.oqr(this, topic, msg, pub_opt)}
|
|
1223
1242
|
|
|
1224
|
-
obj_post(topic, msg,
|
|
1225
|
-
obj_send(topic, msg,
|
|
1226
|
-
obj_store(topic, msg,
|
|
1243
|
+
obj_post(topic, msg, pub_opt) {return _pub.o(this, topic, msg, pub_opt)}
|
|
1244
|
+
obj_send(topic, msg, pub_opt) {return _pub.oq(this, topic, msg, pub_opt)}
|
|
1245
|
+
obj_store(topic, msg, pub_opt) {return _pub.oqr(this, topic, msg, pub_opt)}
|
|
1227
1246
|
|
|
1228
1247
|
|
|
1229
1248
|
|
|
@@ -1282,7 +1301,9 @@ class MQTTBaseClient {
|
|
|
1282
1301
|
, sub: p.subscribe
|
|
1283
1302
|
, unsub: p.unsubscribe
|
|
1284
1303
|
, sub_topic: p.subscribe_topic
|
|
1285
|
-
, unsub_topic: p.unsubscribe_topic
|
|
1304
|
+
, unsub_topic: p.unsubscribe_topic
|
|
1305
|
+
, shared_sub: p.shared_subscribe
|
|
1306
|
+
, shared_unsub: p.shared_unsubscribe} );
|
|
1286
1307
|
|
|
1287
1308
|
/*
|
|
1288
1309
|
p.on_mqtt_type = {
|
|
@@ -1309,41 +1330,51 @@ function _as_topics(pkt, ex) {
|
|
|
1309
1330
|
return ex ? {...pkt, ...ex} : pkt}
|
|
1310
1331
|
|
|
1311
1332
|
|
|
1312
|
-
function _pub(self, pkt,
|
|
1333
|
+
async function _pub(self, pkt, pub_opt) {
|
|
1313
1334
|
if (undefined === pkt.payload) {
|
|
1335
|
+
if ('function' === typeof pub_opt) {
|
|
1336
|
+
pub_opt = {fn_encode: pub_opt};}
|
|
1337
|
+
|
|
1314
1338
|
let {msg} = pkt;
|
|
1315
1339
|
switch (typeof msg) {
|
|
1316
1340
|
case 'function':
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1341
|
+
pub_opt = {...pub_opt, fn_encode: msg};
|
|
1342
|
+
// flow into 'undefined' case
|
|
1320
1343
|
case 'undefined':
|
|
1321
|
-
|
|
1322
|
-
return v => _pub(self, {...pkt, [arg]: v},
|
|
1344
|
+
// return a single-value closure to publish packets
|
|
1345
|
+
return v => _pub(self, {...pkt, [pkt.arg || 'payload']: v}, pub_opt)
|
|
1323
1346
|
|
|
1324
1347
|
default:
|
|
1348
|
+
// Encode payload from msg; fn_encode allows alternative to JSON.stringify
|
|
1349
|
+
let {fn_encode} = pub_opt || {};
|
|
1325
1350
|
pkt.payload = fn_encode
|
|
1326
|
-
? fn_encode(msg)
|
|
1351
|
+
? await fn_encode(msg)
|
|
1327
1352
|
: JSON.stringify(msg);} }
|
|
1328
1353
|
|
|
1354
|
+
if (pub_opt) {
|
|
1355
|
+
if (pub_opt.props) {
|
|
1356
|
+
pkt.props = props;}
|
|
1357
|
+
if (pub_opt.xform) {
|
|
1358
|
+
pkt = pub_opt.xform(pkt) || pkt;} }
|
|
1359
|
+
|
|
1329
1360
|
return self._send('publish', pkt,
|
|
1330
1361
|
pkt.qos ? pkt : void 0 ) }// key
|
|
1331
1362
|
|
|
1332
1363
|
{
|
|
1333
1364
|
Object.assign(_pub,{
|
|
1334
|
-
m: (self, topic, payload) =>
|
|
1335
|
-
_pub(self, {topic, payload, qos:0})
|
|
1336
|
-
, mq: (self, topic, payload) =>
|
|
1337
|
-
_pub(self, {topic, payload, qos:1})
|
|
1338
|
-
, mqr: (self, topic, payload) =>
|
|
1339
|
-
_pub(self, {topic, payload, qos:1, retain: 1})
|
|
1340
|
-
|
|
1341
|
-
, o: (self, topic, msg,
|
|
1342
|
-
_pub(self, {topic, msg, arg: 'msg', qos:0},
|
|
1343
|
-
, oq: (self, topic, msg,
|
|
1344
|
-
_pub(self, {topic, msg, arg: 'msg', qos:1},
|
|
1345
|
-
, oqr: (self, topic, msg,
|
|
1346
|
-
_pub(self, {topic, msg, arg: 'msg', qos:1, retain: 1},
|
|
1365
|
+
m: (self, topic, payload, pub_opt) =>
|
|
1366
|
+
_pub(self, {topic, payload, qos:0}, pub_opt)
|
|
1367
|
+
, mq: (self, topic, payload, pub_opt) =>
|
|
1368
|
+
_pub(self, {topic, payload, qos:1}, pub_opt)
|
|
1369
|
+
, mqr: (self, topic, payload, pub_opt) =>
|
|
1370
|
+
_pub(self, {topic, payload, qos:1, retain: 1}, pub_opt)
|
|
1371
|
+
|
|
1372
|
+
, o: (self, topic, msg, pub_opt) =>
|
|
1373
|
+
_pub(self, {topic, msg, arg: 'msg', qos:0}, pub_opt)
|
|
1374
|
+
, oq: (self, topic, msg, pub_opt) =>
|
|
1375
|
+
_pub(self, {topic, msg, arg: 'msg', qos:1}, pub_opt)
|
|
1376
|
+
, oqr: (self, topic, msg, pub_opt) =>
|
|
1377
|
+
_pub(self, {topic, msg, arg: 'msg', qos:1, retain: 1}, pub_opt)} ); }
|
|
1347
1378
|
|
|
1348
1379
|
class MQTTCoreClient extends MQTTBaseClient {
|
|
1349
1380
|
static _with_session(mqtt_session) {
|