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