u8-mqtt 0.0.26 → 0.1.0
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 +36 -11
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +36 -11
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +36 -11
- package/cjs/v5.cjs.map +1 -1
- package/code/_router.jsy +15 -1
- package/code/base.jsy +17 -7
- package/code/core.jsy +3 -3
- package/code/session.mjs +2 -1
- package/esm/deno/index.js +1471 -0
- package/esm/deno/index.js.map +1 -0
- package/esm/deno/index.mjs +37 -12
- package/esm/deno/index.mjs.map +1 -1
- package/esm/deno/v4.js +1465 -0
- package/esm/deno/v4.js.map +1 -0
- package/esm/deno/v4.mjs +37 -12
- package/esm/deno/v4.mjs.map +1 -1
- package/esm/deno/v5.js +1465 -0
- package/esm/deno/v5.js.map +1 -0
- package/esm/deno/v5.mjs +37 -12
- package/esm/deno/v5.mjs.map +1 -1
- package/esm/node/index.js +1473 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/index.mjs +36 -11
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +1467 -0
- package/esm/node/v4.js.map +1 -0
- package/esm/node/v4.mjs +36 -11
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +1467 -0
- package/esm/node/v5.js.map +1 -0
- package/esm/node/v5.mjs +36 -11
- package/esm/node/v5.mjs.map +1 -1
- package/esm/web/index.js +1471 -0
- package/esm/web/index.js.map +1 -0
- package/esm/web/index.min.mjs +1 -1
- package/esm/web/index.mjs +35 -10
- package/esm/web/index.mjs.map +1 -1
- package/esm/web/v4.js +1465 -0
- package/esm/web/v4.js.map +1 -0
- package/esm/web/v4.min.mjs +1 -1
- package/esm/web/v4.mjs +35 -10
- package/esm/web/v4.mjs.map +1 -1
- package/esm/web/v5.js +1465 -0
- package/esm/web/v5.js.map +1 -0
- package/esm/web/v5.min.mjs +1 -1
- package/esm/web/v5.mjs +35 -10
- package/esm/web/v5.mjs.map +1 -1
- package/package.json +10 -10
package/code/base.jsy
CHANGED
|
@@ -48,13 +48,24 @@ export class MQTTBaseClient ::
|
|
|
48
48
|
pkt = _as_topics(pkt, ex)
|
|
49
49
|
return this._send('unsubscribe', pkt, pkt)
|
|
50
50
|
|
|
51
|
+
get on_topic() :: return this.router.add
|
|
52
|
+
|
|
51
53
|
// alias: sub_topic
|
|
52
54
|
subscribe_topic(topic_route, ...args) ::
|
|
53
|
-
let topic =
|
|
54
|
-
this.
|
|
55
|
+
let topic = this.topic_for(topic_route)
|
|
56
|
+
this.router.add @ topic_route, true, args.pop() // handler
|
|
55
57
|
this.subscribe @ [[ topic ]], args.pop() // ex
|
|
56
58
|
return this
|
|
57
59
|
|
|
60
|
+
// alias: unsub_topic
|
|
61
|
+
unsubscribe_topic(topic_route) ::
|
|
62
|
+
let topic = this.topic_for(topic_route)
|
|
63
|
+
this.router.remove @ topic_route, true
|
|
64
|
+
return this.unsubscribe @ [[ topic ]]
|
|
65
|
+
|
|
66
|
+
topic_for(topic_route) ::
|
|
67
|
+
return topic_route.replace(/[:*].*$/, '#')
|
|
68
|
+
|
|
58
69
|
|
|
59
70
|
// alias: pub
|
|
60
71
|
publish(pkt, fn_encode) :: return _pub(this, pkt, fn_encode)
|
|
@@ -105,9 +116,7 @@ export class MQTTBaseClient ::
|
|
|
105
116
|
/* async _send(type, pkt) -- provided by _conn_ and transport */
|
|
106
117
|
|
|
107
118
|
_init_router(opt) ::
|
|
108
|
-
|
|
109
|
-
this.on_topic = router.add
|
|
110
|
-
return this.router = router
|
|
119
|
+
return this.router = _mqtt_topic_router(this)
|
|
111
120
|
|
|
112
121
|
_init_dispatch(opt) ::
|
|
113
122
|
let router = this._init_router(opt, this)
|
|
@@ -129,6 +138,7 @@ export class MQTTBaseClient ::
|
|
|
129
138
|
sub: p.subscribe
|
|
130
139
|
unsub: p.unsubscribe
|
|
131
140
|
sub_topic: p.subscribe_topic
|
|
141
|
+
unsub_topic: p.unsubscribe_topic
|
|
132
142
|
|
|
133
143
|
/*
|
|
134
144
|
p.on_mqtt_type = {
|
|
@@ -155,7 +165,7 @@ function _as_topics(pkt, ex) ::
|
|
|
155
165
|
return ex ? {...pkt, ...ex} : pkt
|
|
156
166
|
|
|
157
167
|
|
|
158
|
-
function _pub(self, pkt, fn_encode) ::
|
|
168
|
+
async function _pub(self, pkt, fn_encode) ::
|
|
159
169
|
if undefined === pkt.payload ::
|
|
160
170
|
let {msg} = pkt
|
|
161
171
|
switch typeof msg ::
|
|
@@ -169,7 +179,7 @@ function _pub(self, pkt, fn_encode) ::
|
|
|
169
179
|
|
|
170
180
|
default:
|
|
171
181
|
pkt.payload = fn_encode
|
|
172
|
-
? fn_encode(msg)
|
|
182
|
+
? await fn_encode(msg)
|
|
173
183
|
: JSON.stringify(msg)
|
|
174
184
|
|
|
175
185
|
return self._send @ 'publish', pkt,
|
package/code/core.jsy
CHANGED
|
@@ -50,10 +50,10 @@ export class MQTTCoreClient extends MQTTBaseClient ::
|
|
|
50
50
|
#IF PLAT_DENO
|
|
51
51
|
with_tcp(port, hostname) ::
|
|
52
52
|
if !Number.isFinite(port) ::
|
|
53
|
-
({port,
|
|
53
|
+
({port, hostname} = new URL(port))
|
|
54
54
|
|
|
55
55
|
Deno.connect @:
|
|
56
|
-
port
|
|
56
|
+
port, hostname, transport: 'tcp'
|
|
57
57
|
.then @\ conn =>
|
|
58
58
|
this.with_async_iter @
|
|
59
59
|
Deno.iter(conn),
|
|
@@ -65,7 +65,7 @@ export class MQTTCoreClient extends MQTTBaseClient ::
|
|
|
65
65
|
#IF PLAT_NODEJS
|
|
66
66
|
with_tcp(port, hostname) ::
|
|
67
67
|
if !Number.isFinite(port) ::
|
|
68
|
-
({port,
|
|
68
|
+
({port, hostname} = new URL(port))
|
|
69
69
|
|
|
70
70
|
let sock = tcp_connect(port, hostname)
|
|
71
71
|
return this.with_stream(sock)
|
package/code/session.mjs
CHANGED
|
@@ -30,7 +30,8 @@ export function mqtt_session_ctx(mqtt_level) {
|
|
|
30
30
|
|
|
31
31
|
let std_pkt_api = {
|
|
32
32
|
utf8(u8) { return as_utf8( u8 || this.payload ) },
|
|
33
|
-
json(u8) { return JSON.parse(
|
|
33
|
+
json(u8) { return JSON.parse( this.utf8(u8) || null ) },
|
|
34
|
+
text(u8) { return this.utf8(u8) },
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
mqtt_session_ctx.ctx = ctx =
|