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