u8-mqtt 0.1.3 → 0.3.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.
Files changed (64) hide show
  1. package/README.md +23 -55
  2. package/cjs/index.cjs +632 -557
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/v4.cjs +479 -662
  5. package/cjs/v4.cjs.map +1 -1
  6. package/cjs/v5.cjs +631 -550
  7. package/cjs/v5.cjs.map +1 -1
  8. package/code/_conn.jsy +53 -54
  9. package/code/_router.jsy +15 -4
  10. package/code/base.jsy +35 -16
  11. package/code/core.jsy +78 -59
  12. package/code/index.mjs +4 -4
  13. package/code/v4.mjs +6 -6
  14. package/code/v5.mjs +14 -6
  15. package/esm/deno/index.js +635 -562
  16. package/esm/deno/index.js.map +1 -1
  17. package/esm/deno/v4.js +486 -669
  18. package/esm/deno/v4.js.map +1 -1
  19. package/esm/deno/v5.js +637 -558
  20. package/esm/deno/v5.js.map +1 -1
  21. package/esm/node/index.js +628 -555
  22. package/esm/node/index.js.map +1 -1
  23. package/esm/node/index.mjs +628 -555
  24. package/esm/node/index.mjs.map +1 -1
  25. package/esm/node/v4.js +479 -662
  26. package/esm/node/v4.js.map +1 -1
  27. package/esm/node/v4.mjs +479 -662
  28. package/esm/node/v4.mjs.map +1 -1
  29. package/esm/node/v5.js +630 -551
  30. package/esm/node/v5.js.map +1 -1
  31. package/esm/node/v5.mjs +630 -551
  32. package/esm/node/v5.mjs.map +1 -1
  33. package/esm/web/index.js +630 -557
  34. package/esm/web/index.js.map +1 -1
  35. package/esm/web/index.min.js +1 -0
  36. package/esm/web/index.min.js.br +0 -0
  37. package/esm/web/index.min.js.gz +0 -0
  38. package/esm/web/v4.js +481 -664
  39. package/esm/web/v4.js.map +1 -1
  40. package/esm/web/v4.min.js +1 -0
  41. package/esm/web/v4.min.js.br +0 -0
  42. package/esm/web/v4.min.js.gz +0 -0
  43. package/esm/web/v5.js +632 -553
  44. package/esm/web/v5.js.map +1 -1
  45. package/esm/web/v5.min.js +1 -0
  46. package/esm/web/v5.min.js.br +0 -0
  47. package/esm/web/v5.min.js.gz +0 -0
  48. package/package.json +23 -12
  49. package/code/session.mjs +0 -65
  50. package/esm/deno/index.mjs +0 -1502
  51. package/esm/deno/index.mjs.map +0 -1
  52. package/esm/deno/v4.mjs +0 -1496
  53. package/esm/deno/v4.mjs.map +0 -1
  54. package/esm/deno/v5.mjs +0 -1496
  55. package/esm/deno/v5.mjs.map +0 -1
  56. package/esm/web/index.min.mjs +0 -1
  57. package/esm/web/index.mjs +0 -1502
  58. package/esm/web/index.mjs.map +0 -1
  59. package/esm/web/v4.min.mjs +0 -1
  60. package/esm/web/v4.mjs +0 -1496
  61. package/esm/web/v4.mjs.map +0 -1
  62. package/esm/web/v5.min.mjs +0 -1
  63. package/esm/web/v5.mjs +0 -1496
  64. package/esm/web/v5.mjs.map +0 -1
package/code/_conn.jsy CHANGED
@@ -1,83 +1,82 @@
1
+ import { ao_defer_v } from 'roap'
2
+ export { ao_defer_v }
3
+
1
4
  export function _mqtt_conn(client, [on_mqtt, pkt_future]) ::
2
- let q0 = _tiny_deferred_queue()
3
- let q = _tiny_deferred_queue()
5
+ let _q_init = ao_defer_v(), _q_ready = ao_defer_v()
6
+ let _send_ready = async (...args) => (await _q_ready[0])(...args)
7
+ let _send_mqtt_pkt, _has_connected
8
+ client._send = _send_ready
4
9
 
5
- let _asy_send = async (...args) =>
6
- (await q)(...args)
7
- let _send = client._send = _asy_send
10
+ return @{}
11
+ async when_ready() :: await _q_ready[0]
8
12
 
9
- let _ping = () => client._send('pingreq')
10
- let tid_ping, _is_set = false
13
+ ping: _ping_interval @=> _send_mqtt_pkt?.('pingreq')
11
14
 
12
- return @{}
13
- is_live: @=> _asy_send !== _send
14
- is_set: @=> _is_set
15
+ reset(err) ::
16
+ if ! _send_mqtt_pkt :: return
15
17
 
16
- reset() ::
17
- tid_ping = clearInterval(tid_ping)
18
- client._send = _send = _asy_send
19
- _is_set = false
18
+ if err ::
19
+ _q_init[2](err)
20
20
 
21
- // call client.on_reconnect in next promise microtask
22
- _async_evt(client, client.on_reconnect)
21
+ _send_mqtt_pkt = null
22
+ _q_init = ao_defer_v()
23
+ client._send = _send_ready
23
24
 
24
- ping(td) ::
25
- tid_ping = clearInterval(tid_ping)
26
- if td ::
27
- tid_ping = setInterval(_ping, 1000 * td)
28
- if tid_ping.unref ::
29
- tid_ping.unref()
25
+ // call client.on_conn_reset in next promise microtask
26
+ client.conn_emit('on_disconnect', false===err, err)
30
27
 
31
28
  async send_connect(... args) ::
32
- if _asy_send === _send ::
33
- _send = await q0
29
+ if ! _send_mqtt_pkt ::
30
+ await _q_init[0] // _send_mqtt_pkt is set before fulfilled
34
31
 
35
32
  // await connack response
36
- let res = await _send(...args)
33
+ let res = await _send_mqtt_pkt(...args)
34
+ if 0 == res[0].reason ::
35
+ _has_connected = true
36
+ // resolve _q_ready[0] with _send_mqtt_pkt closure
37
+ _q_ready[1](client._send = _send_mqtt_pkt)
38
+ _q_ready = ao_defer_v()
39
+ client.conn_emit('on_ready')
37
40
 
38
- client._send = _send
39
- q.notify(_send)
40
41
  return res
41
42
 
42
- set(mqtt_session, send_u8_pkt) ::
43
- _is_set = true
44
-
45
- let [mqtt_decode, mqtt_encode] = mqtt_session
43
+ is_set: @=> !! _send_mqtt_pkt
44
+ set(mqtt_ctx, send_u8_pkt) ::
45
+ if _send_mqtt_pkt ::
46
+ throw new Error('Already connected')
46
47
 
48
+ mqtt_ctx = mqtt_ctx.mqtt_stream()
49
+ let sess_ctx = {mqtt: client}
47
50
  let on_mqtt_chunk = u8_buf =>
48
- on_mqtt(
49
- mqtt_decode(u8_buf),
50
- {mqtt: client})
51
+ on_mqtt(mqtt_ctx.decode(u8_buf), sess_ctx)
51
52
 
52
- _send = async (type, pkt, key) => ::
53
+ _send_mqtt_pkt = async (type, pkt, key) => ::
53
54
  let res = undefined !== key
54
55
  ? pkt_future(key) : true
55
56
 
56
57
  await send_u8_pkt @
57
- mqtt_encode(type, pkt)
58
+ mqtt_ctx.encode_pkt(type, pkt)
58
59
 
59
60
  return res
60
61
 
61
-
62
- q0.notify(_send)
62
+ _q_init[1](_send_mqtt_pkt) // resolve _q_init with _send_mqtt_pkt closure
63
63
 
64
64
  // call client.on_live in next promise microtask
65
- _async_evt(client, client.on_live)
66
-
65
+ client.conn_emit('on_live', _has_connected)
67
66
  return on_mqtt_chunk
68
67
 
69
68
 
70
- async function _async_evt(obj, evt) {
71
- // microtask break lookup
72
- if (undefined !== evt) {
73
- await evt.call(obj, await obj)
74
- }
75
- }
76
- function _tiny_deferred_queue() {
77
- let q = [] // tiny resetting deferred queue
78
- q.then = y => { q.push(y) }
79
- q.notify = v => {
80
- for (let fn of q.splice(0,q.length))
81
- fn(v) }
82
- return q
83
- }
69
+ function _ping_interval(send_ping) ::
70
+ let tid
71
+ return @\ td ::
72
+ tid = clearInterval(tid)
73
+ if td ::
74
+ tid = setInterval(send_ping, 1000 * td)
75
+ #IF PLAT_DENO
76
+ // ensure the interval allows the Deno event loop to exit
77
+ Deno.unrefTimer(tid)
78
+ #ELSE
79
+ // ensure the interval allows the NodeJS event loop to exit
80
+ tid.unref?.()
81
+ return true
82
+
package/code/_router.jsy CHANGED
@@ -6,7 +6,7 @@ import {parse as _rxp_parse} from 'regexparam'
6
6
  function _ignore(pkt, params, ctx) :: ctx.done = true
7
7
 
8
8
  export function _mqtt_topic_router() ::
9
- let pri_lsts = [[],[]]
9
+ let pri_lsts = [[],[]], rm = Symbol()
10
10
  let find = topic => _mqtt_routes_iter(pri_lsts, topic)
11
11
 
12
12
  return @{} find,
@@ -30,8 +30,7 @@ export function _mqtt_topic_router() ::
30
30
 
31
31
  remove(topic_route, priority) ::
32
32
  let lst = pri_lsts[priority ? 0 : 1]
33
- lst = lst.filter @ e => e.key !== topic_route
34
- pri_lsts[priority ? 0 : 1] = lst
33
+ return _mqtt_route_remove([lst], topic_route)
35
34
 
36
35
  clear(priority) ::
37
36
  pri_lsts[priority ? 0 : 1] = []
@@ -40,9 +39,13 @@ export function _mqtt_topic_router() ::
40
39
 
41
40
  async invoke(pkt, ctx) ::
42
41
  ctx.idx = 0
42
+ ctx.rm = rm
43
43
 
44
44
  for let [fn, params] of find(pkt.topic) ::
45
- await fn(pkt, params, ctx)
45
+ let res = await fn(pkt, params, ctx)
46
+
47
+ if rm === res ::
48
+ _mqtt_route_remove(pri_lsts, fn)
46
49
 
47
50
  if ctx.done ::
48
51
  break
@@ -88,3 +91,11 @@ export function _mqtt_route_match_one(topic, {keys, pattern, tgt}) ::
88
91
  params[ keys[i] ] = match[1+i]
89
92
  return [tgt, params]
90
93
 
94
+
95
+ export function _mqtt_route_remove(all_route_lists, query) ::
96
+ let match = route => route===query || route.tgt===query || route.key===query
97
+ for let lst of all_route_lists ::
98
+ let i = lst.findIndex(match)
99
+ if 0 <= i :: return !! lst.splice(i,1)
100
+ return false
101
+
package/code/base.jsy CHANGED
@@ -2,20 +2,38 @@ import {_mqtt_conn} from './_conn.jsy'
2
2
  import {_mqtt_topic_router} from './_router.jsy'
3
3
  import {_mqtt_dispatch} from './_dispatch.jsy'
4
4
 
5
- export class MQTTBaseClient ::
5
+ export class MQTTError extends Error ::
6
+ constructor(mqtt_pkt, reason=mqtt_pkt.reason) ::
7
+ super(`[0x${reason.toString(16)}] ${reason.reason}`)
8
+ this.mqtt_pkt = mqtt_pkt
9
+ this.reason = reason
10
+
11
+ export class MQTTBase ::
6
12
  constructor(opt={}) ::
7
13
  this._conn_ = _mqtt_conn @ this,
8
14
  this._init_dispatch(opt, this)
9
15
 
16
+ async conn_emit(evt, arg, err_arg) ::
17
+ this.log_conn?.(evt, arg, err_arg)
18
+ try ::
19
+ let fn_evt = this[await evt] // microtask break
20
+ if fn_evt ::
21
+ await fn_evt.call(this, this, arg, err_arg)
22
+ else if err_arg ::
23
+ await this.on_error(err_arg, evt)
24
+ catch err ::
25
+ this.on_error(err, evt)
26
+
27
+ on_error(err, err_path) ::
28
+ console.warn @ '[[u8-mqtt error: %s]]', err_path, err
29
+
10
30
  // Handshaking Packets
11
31
 
12
32
  async connect(pkt={}) ::
13
- let {client_id: cid} = pkt
14
- if ! cid ::
15
- pkt.client_id = cid = this.init_client_id(['u8-mqtt--', ''])
16
- else if Array.isArray(cid) ::
33
+ let cid = pkt.client_id || ['u8-mqtt--', '']
34
+ if Array.isArray(cid) ::
17
35
  pkt.client_id = cid = this.init_client_id(cid)
18
- else :: this.client_id = cid
36
+ this.client_id = cid
19
37
 
20
38
  if null == pkt.keep_alive ::
21
39
  pkt.keep_alive = 60
@@ -23,13 +41,16 @@ export class MQTTBaseClient ::
23
41
  let res = await this._conn_
24
42
  .send_connect('connect', pkt, 'connack')
25
43
 
44
+ if 0 != res[0].reason ::
45
+ throw new this.MQTTError(res[0])
46
+
26
47
  // TODO: merge with server's keep_alive frequency
27
48
  this._conn_.ping(pkt.keep_alive)
28
49
  return res
29
50
 
30
51
  async disconnect(pkt={}) ::
31
52
  let res = await this._send('disconnect', pkt)
32
- this._conn_.reset()
53
+ this._conn_.reset(false)
33
54
  return res
34
55
 
35
56
  auth(pkt={}) ::
@@ -43,8 +64,9 @@ export class MQTTBaseClient ::
43
64
  pkt = _as_topics(pkt, ex)
44
65
  return this._send('subscribe', pkt, pkt)
45
66
  _sub_chain(topic, ex) ::
67
+ let res = this.subscribe @ [[ topic ]], ex
46
68
  let subs = this.subs || @ this.subs = new Map()
47
- subs.set @ topic, this.subscribe @ [[ topic ]], ex
69
+ subs.set @ (res.topic = topic), (subs.last = res)
48
70
  return this // fluent api -- return this and track side effects
49
71
 
50
72
  // alias: unsub
@@ -122,7 +144,7 @@ export class MQTTBaseClient ::
122
144
 
123
145
  #IF PLAT_WEB
124
146
  sess_client_id(parts) ::
125
- let key = `client_id ${parts.join('')}`
147
+ let key = parts.join('\x20')
126
148
  let cid = sessionStorage.getItem(key)
127
149
  if null == cid ::
128
150
  cid = this.new_client_id(parts)
@@ -138,21 +160,18 @@ export class MQTTBaseClient ::
138
160
  return this.router = _mqtt_topic_router(this)
139
161
 
140
162
  _init_dispatch(opt) ::
141
- let router = this._init_router(opt, this)
142
-
143
163
  let tgt = @{}
144
164
  __proto__: opt.on_mqtt_type || {}
145
- router
146
-
147
- if ! tgt.mqtt_publish ::
148
- tgt.mqtt_publish = router.invoke
165
+ router: this._init_router(opt, this)
149
166
 
167
+ tgt.mqtt_publish ||= tgt.router.invoke
150
168
  return _mqtt_dispatch(this, tgt)
151
169
 
152
170
 
153
171
  ::
154
- let p = MQTTBaseClient.prototype
172
+ let p = MQTTBase.prototype
155
173
  Object.assign @ p, @{}
174
+ MQTTError
156
175
  pub: p.publish
157
176
  sub: p.subscribe
158
177
  unsub: p.unsubscribe
package/code/core.jsy CHANGED
@@ -1,48 +1,70 @@
1
- import {MQTTBaseClient} from './base.jsy'
1
+ import mqtt_pkt_ctx from 'u8-mqtt-packet/esm/codec_bind.js'
2
+ import { MQTTBase } from './base.jsy'
2
3
 
3
4
  #IF PLAT_NODEJS
4
- import {connect as tcp_connect} from 'net'
5
+ import {connect as tcp_connect} from 'node:net'
5
6
 
7
+ const pkt_api = {
8
+ utf8(u8) { return new TextDecoder('utf-8').decode(u8 || this.payload ) },
9
+ json(u8) { return JSON.parse( this.utf8(u8) || null ) },
10
+ text(u8) { return this.utf8(u8) },
11
+ }
6
12
 
7
- export class MQTTCoreClient extends MQTTBaseClient ::
8
- static _with_session(mqtt_session) ::
9
- this.prototype._mqtt_session = mqtt_session
10
-
13
+ export class MQTTCore extends MQTTBase ::
11
14
  constructor(opt={}) ::
12
15
  super(opt)
13
- this.with_live(opt.on_live)
14
- this.with_reconnect(opt.on_reconnect)
15
-
16
+ this.with(opt)
16
17
 
17
- // on_live(client) ::
18
- with_live(on_live) ::
19
- if on_live ::
20
- this.on_live = on_live
18
+ static mqtt_ctx(mqtt_level, mqtt_opts, pkt_ctx=pkt_api) ::
19
+ let self = class extends this {}
20
+ self.prototype.mqtt_ctx =
21
+ mqtt_pkt_ctx(mqtt_level, mqtt_opts, pkt_ctx)
22
+ return self
21
23
 
24
+ with(fns_ns) ::
25
+ for let [k,v] of Object.entries(fns_ns) ::
26
+ if 'function' === typeof v :: this[k] = v
22
27
  return this
23
28
 
24
- // on_reconnect(client) ::
25
- with_reconnect(on_reconnect) ::
26
- if on_reconnect ::
27
- this.on_reconnect = on_reconnect
29
+ //log_conn(evt, arg, err_arg) ::
30
+ //console.info @ '[[u8-mqtt log: %s]]', evt, arg, err_arg
28
31
 
29
- if ! this._conn_.is_set ::
30
- on_reconnect(this)
32
+ on_live(client, is_reconnect) ::
33
+ if is_reconnect ::
34
+ return client.connect()
31
35
 
32
- return this
36
+ //on_reconnect(client) ::
33
37
 
38
+ _use_conn(fn_reconnect) ::
39
+ return (this.reconnect = fn_reconnect)?.()
40
+ with_autoreconnect(opt=2000) ::
41
+ if opt.toFixed :: opt = @{} delay: opt
42
+ return this.with @:
43
+ on_reconnect() ::
44
+ this.delay(opt.delay || 2000)
45
+ .then(this.reconnect)
46
+ .then(opt.reconnect, opt.error)
47
+
48
+ on_disconnect(client, intentional) ::
49
+ if ! intentional ::
50
+ return client.on_reconnect?.()
51
+
52
+ delay(ms) ::
53
+ return new Promise @ done => setTimeout(done, ms)
34
54
 
35
55
  with_async_iter(async_iter, write_u8_pkt) ::
36
56
  let on_mqtt_chunk = this._conn_.set @
37
- this._mqtt_session(),
57
+ this.mqtt_ctx,
38
58
  write_u8_pkt
39
59
 
40
60
  this._msg_loop = @!>
41
- async_iter = await async_iter
42
- for await (let chunk of async_iter)
43
- on_mqtt_chunk(chunk)
44
-
45
- this._conn_.reset()
61
+ try ::
62
+ async_iter = await async_iter
63
+ for await (let chunk of async_iter)
64
+ on_mqtt_chunk(chunk)
65
+ this._conn_.reset()
66
+ catch err ::
67
+ this._conn_.reset(err)
46
68
 
47
69
  return this
48
70
 
@@ -52,14 +74,15 @@ export class MQTTCoreClient extends MQTTBaseClient ::
52
74
  if !Number.isFinite(port) ::
53
75
  ({port, hostname} = new URL(port))
54
76
 
55
- Deno.connect @:
56
- port, hostname, transport: 'tcp'
57
- .then @\ conn =>
77
+ return this._use_conn @::
78
+ let conn = Deno.connect @:
79
+ port, hostname, transport: 'tcp'
80
+
58
81
  this.with_async_iter @
59
- Deno.iter(conn),
60
- u8_pkt => conn.write(u8_pkt)
82
+ conn.then @ Deno.iter,
83
+ async u8_pkt => (await conn).write(u8_pkt)
61
84
 
62
- return this
85
+ return this
63
86
 
64
87
 
65
88
  #IF PLAT_NODEJS
@@ -67,27 +90,25 @@ export class MQTTCoreClient extends MQTTBaseClient ::
67
90
  if !Number.isFinite(port) ::
68
91
  ({port, hostname} = new URL(port))
69
92
 
70
- let sock = tcp_connect(port, hostname)
71
- return this.with_stream(sock)
72
-
73
-
74
- #IF HAS_STREAM
75
- with_stream(read_stream, write_stream) ::
76
- if undefined === write_stream ::
77
- write_stream = read_stream
93
+ return this._use_conn @=>
94
+ this.with_stream @
95
+ tcp_connect(port, hostname)
78
96
 
79
- return this.with_async_iter @ read_stream,
80
- u8_pkt => write_stream.write(u8_pkt)
81
97
 
98
+ with_stream(read_stream, write_stream) ::
99
+ if undefined === write_stream ::
100
+ write_stream = read_stream
82
101
 
102
+ return this.with_async_iter @ read_stream,
103
+ u8_pkt => write_stream.write(u8_pkt)
83
104
 
84
105
 
85
106
  with_websock(websock) ::
86
- if null == websock ::
87
- websock = 'ws://127.0.0.1:9001'
88
-
89
- if websock.origin || 'string' === typeof websock ::
90
- websock = new WebSocket(new URL(websock), ['mqtt'])
107
+ if ! websock?.send ::
108
+ websock = new URL(websock || 'ws://127.0.0.1:9001')
109
+ return this._use_conn @=>
110
+ this.with_websock @
111
+ new WebSocket(websock, ['mqtt'])
91
112
 
92
113
  websock.binaryType = 'arraybuffer'
93
114
 
@@ -96,27 +117,25 @@ export class MQTTCoreClient extends MQTTBaseClient ::
96
117
  if 0 !== readyState ::
97
118
  throw new Error @ 'Invalid WebSocket readyState'
98
119
 
99
- ready = new Promise( y =>
100
- websock.addEventListener('open', y, {once: true}))
120
+ ready = new Promise @ fn => websock.onopen = fn
101
121
 
102
122
 
103
123
  let {_conn_} = this
104
124
  let on_mqtt_chunk = _conn_.set @
105
- this._mqtt_session(),
125
+ this.mqtt_ctx,
106
126
  async u8_pkt => @
107
127
  await ready
108
128
  websock.send(u8_pkt)
109
129
 
110
- websock.addEventListener @ 'close',
111
- @::
112
- delete websock.onmessage
113
- _conn_.reset()
114
-
115
- {once: true}
130
+ websock.onmessage = evt => @ on_mqtt_chunk @ new Uint8Array(evt.data)
131
+ websock.onclose = evt => ::
132
+ if ! evt.wasClean ::
133
+ var err = new Error('websocket connection close')
134
+ err.code = evt.code
135
+ err.reason = evt.reason
116
136
 
117
- websock.onmessage = evt =>
118
- on_mqtt_chunk @
119
- new Uint8Array(evt.data)
137
+ _conn_.reset(err)
120
138
 
121
139
  return this
122
140
 
141
+ export { MQTTCore as default }
package/code/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- export {MQTTClient_v4, mqtt_v4, default} from './v4.mjs'
2
- export {MQTTClient_v5, mqtt_v5} from './v5.mjs'
3
-
4
- export * from './session.mjs'
1
+ export {
2
+ MQTTClient_v5, mqtt_v5,
3
+ MQTTClient_v4, mqtt_v4, mqtt_v4 as default, // u8-mqtt-packet version 5 can also parse version 4 (3.1.1) packets
4
+ } from './v5.mjs'
5
5
 
6
6
  export * from './core.jsy'
7
7
  export * from './base.jsy'
package/code/v4.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import {mqtt_session_ctx} from './session.mjs'
2
- import {MQTTCoreClient} from './core.jsy'
1
+ import mqtt_opts_v4 from 'u8-mqtt-packet/esm/codec_v4_client.js'
2
+ import MQTTCore from './core.jsy'
3
3
 
4
- class MQTTClient_v4 extends MQTTCoreClient {
5
- _mqtt_session() { return mqtt_session_ctx(4)() }
6
- }
4
+ const MQTTClient_v4 = /* #__PURE__ */
5
+ MQTTCore.mqtt_ctx(4, mqtt_opts_v4)
7
6
 
8
- const mqtt_v4 = opt => new MQTTClient_v4(opt)
7
+ const mqtt_v4 = opt =>
8
+ new MQTTClient_v4(opt)
9
9
 
10
10
  export {
11
11
  MQTTClient_v4,
package/code/v5.mjs CHANGED
@@ -1,16 +1,24 @@
1
- import {mqtt_session_ctx} from './session.mjs'
2
- import {MQTTCoreClient} from './core.jsy'
1
+ import mqtt_opts_v5 from 'u8-mqtt-packet/esm/codec_v5_client.js'
2
+ import MQTTCore from './core.jsy'
3
3
 
4
- class MQTTClient_v5 extends MQTTCoreClient {
5
- _mqtt_session() { return mqtt_session_ctx(5)() }
6
- }
4
+ const MQTTClient_v4 = /* #__PURE__ */
5
+ MQTTCore.mqtt_ctx(4, mqtt_opts_v5)
6
+
7
+ const MQTTClient_v5 = /* #__PURE__ */
8
+ MQTTCore.mqtt_ctx(5, mqtt_opts_v5)
9
+
10
+ const mqtt_v4 = opt =>
11
+ new MQTTClient_v4(opt)
7
12
 
8
- const mqtt_v5 = opt => new MQTTClient_v5(opt)
13
+ const mqtt_v5 = opt =>
14
+ new MQTTClient_v5(opt)
9
15
 
10
16
  export {
17
+ MQTTClient_v4,
11
18
  MQTTClient_v5,
12
19
  MQTTClient_v5 as MQTTClient,
13
20
 
21
+ mqtt_v4,
14
22
  mqtt_v5,
15
23
  mqtt_v5 as mqtt,
16
24
  mqtt_v5 as default,