u8-mqtt 0.1.3 → 0.3.1
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/README.md +42 -59
- package/cjs/index.cjs +635 -557
- package/cjs/index.cjs.map +1 -1
- package/cjs/v4.cjs +482 -662
- package/cjs/v4.cjs.map +1 -1
- package/cjs/v5.cjs +634 -550
- package/cjs/v5.cjs.map +1 -1
- package/code/_conn.jsy +53 -54
- package/code/_router.jsy +15 -4
- package/code/base.jsy +35 -16
- package/code/core.jsy +78 -59
- package/code/index.mjs +5 -4
- package/code/v4.mjs +7 -6
- package/code/v5.mjs +15 -6
- package/esm/deno/index.js +637 -562
- package/esm/deno/index.js.map +1 -1
- package/esm/deno/v4.js +489 -670
- package/esm/deno/v4.js.map +1 -1
- package/esm/deno/v5.js +639 -558
- package/esm/deno/v5.js.map +1 -1
- package/esm/node/index.js +630 -555
- package/esm/node/index.js.map +1 -1
- package/esm/node/index.mjs +630 -555
- package/esm/node/index.mjs.map +1 -1
- package/esm/node/v4.js +482 -663
- package/esm/node/v4.js.map +1 -1
- package/esm/node/v4.mjs +482 -663
- package/esm/node/v4.mjs.map +1 -1
- package/esm/node/v5.js +632 -551
- package/esm/node/v5.js.map +1 -1
- package/esm/node/v5.mjs +632 -551
- package/esm/node/v5.mjs.map +1 -1
- package/esm/web/index.js +632 -557
- package/esm/web/index.js.map +1 -1
- package/esm/web/index.min.js +1 -0
- package/esm/web/index.min.js.br +0 -0
- package/esm/web/index.min.js.gz +0 -0
- package/esm/web/v4.js +484 -665
- package/esm/web/v4.js.map +1 -1
- package/esm/web/v4.min.js +1 -0
- package/esm/web/v4.min.js.br +0 -0
- package/esm/web/v4.min.js.gz +0 -0
- package/esm/web/v5.js +634 -553
- package/esm/web/v5.js.map +1 -1
- package/esm/web/v5.min.js +1 -0
- package/esm/web/v5.min.js.br +0 -0
- package/esm/web/v5.min.js.gz +0 -0
- package/package.json +24 -12
- package/code/session.mjs +0 -65
- package/esm/deno/index.mjs +0 -1502
- package/esm/deno/index.mjs.map +0 -1
- package/esm/deno/v4.mjs +0 -1496
- package/esm/deno/v4.mjs.map +0 -1
- package/esm/deno/v5.mjs +0 -1496
- package/esm/deno/v5.mjs.map +0 -1
- package/esm/web/index.min.mjs +0 -1
- package/esm/web/index.mjs +0 -1502
- package/esm/web/index.mjs.map +0 -1
- package/esm/web/v4.min.mjs +0 -1
- package/esm/web/v4.mjs +0 -1496
- package/esm/web/v4.mjs.map +0 -1
- package/esm/web/v5.min.mjs +0 -1
- package/esm/web/v5.mjs +0 -1496
- package/esm/web/v5.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -33,79 +33,62 @@ Targeting [MQTT-3.1.1 (v4)][spec-3.1.1] and [MQTT-5.0.0 (v5)][spec-5.0.0] compat
|
|
|
33
33
|
|
|
34
34
|
## Use
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// or using Deno
|
|
41
|
-
import mqtt_client from 'u8-mqtt/esm/deno/v4.mjs'
|
|
42
|
-
|
|
43
|
-
// or using WebSockets
|
|
44
|
-
import mqtt_client from 'u8-mqtt/esm/web/v4.mjs'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const my_mqtt = mqtt_client()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Connect using NodeJS or Deno
|
|
51
|
-
my_mqtt.with_tcp(1883, '127.0.0.1')
|
|
52
|
-
|
|
53
|
-
// or connect using WebSockets
|
|
54
|
-
my_mqtt.with_websock('ws://127.0.0.1:9001')
|
|
36
|
+
- from [Web CDN](./docs/use_from_web_cdn.md)
|
|
37
|
+
- from [Web bundler](./docs/use_from_web_bundler.md) like [Rollup][] or [ESBuild][]
|
|
38
|
+
- from [NodeJS](./docs/use_from_nodejs.md)
|
|
39
|
+
- from [Deno](./docs/use_from_deno.md)
|
|
55
40
|
|
|
41
|
+
[Rollup]: https://rollupjs.org
|
|
42
|
+
[ESBuild]: https://esbuild.github.io
|
|
56
43
|
|
|
57
|
-
// use on_live to converse with the MQTT server
|
|
58
|
-
my_mqtt.on_live = somewhere_in_your_code
|
|
59
44
|
|
|
45
|
+
```javascript
|
|
46
|
+
import mqtt_client from 'https://cdn.jsdelivr.net/npm/u8-mqtt/esm/web/index.js'
|
|
47
|
+
// or import mqtt_client from 'u8-mqtt'
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.log('topic:', params, [params.arg, pkt.utf8()])
|
|
66
|
-
})
|
|
67
|
-
.on_topic('u8-mqtt-demo/another/:first/:second', (pkt, params, ctx) => {
|
|
68
|
-
console.log('another:', params, [params.first, params.second, pkt.utf8()])
|
|
69
|
-
})
|
|
70
|
-
.subscribe_topic('u8-mqtt-demo/bye', (pkt, params, ctx) => {
|
|
71
|
-
console.log('other mqtt said bye:', params, [pkt.utf8()])
|
|
72
|
-
})
|
|
49
|
+
let my_mqtt = mqtt_client()
|
|
50
|
+
.with_websock('wss://test.mosquitto.org:8081')
|
|
51
|
+
// or .with_tcp('tcp://test.mosquitto.org:1883')
|
|
52
|
+
.with_autoreconnect()
|
|
73
53
|
|
|
54
|
+
await my_mqtt.connect()
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
payload: 'gone!',
|
|
80
|
-
}
|
|
56
|
+
my_mqtt.subscribe_topic(
|
|
57
|
+
'u8-mqtt/demo-simple/:topic',
|
|
58
|
+
(pkt, params, ctx) => {
|
|
59
|
+
console.log('topic packet', params, pkt, pkt.json())
|
|
81
60
|
})
|
|
82
61
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
await my_mqtt.json_send(
|
|
63
|
+
'u8-mqtt/demo-simple/live',
|
|
64
|
+
{ note: 'from README example',
|
|
65
|
+
live: new Date().toISOString() })
|
|
66
|
+
```
|
|
87
67
|
|
|
88
|
-
|
|
89
|
-
topic: 'u8-mqtt-demo/topic/node-side-fun-test',
|
|
90
|
-
payload: 'awesome from both web and node',
|
|
91
|
-
})
|
|
68
|
+
## Module size
|
|
92
69
|
|
|
93
|
-
|
|
94
|
-
'u8-mqtt-demo/another/apple/orange',
|
|
95
|
-
'MQTT Fruity fun')
|
|
70
|
+
Built for small footprint with ES Modules (ESM) using embedded [u8-mqtt-packet][] and [regexparam][] libraries.
|
|
96
71
|
|
|
97
|
-
|
|
98
|
-
|
|
72
|
+
| module | brotli | minified |
|
|
73
|
+
|:------------------------|---------:|---------:|
|
|
74
|
+
| `u8-mqtt` | 6476 B | 19895 B |
|
|
75
|
+
| `u8-mqtt/esm/v5.min.js` | 6384 B | 19694 B |
|
|
76
|
+
| `u8-mqtt/esm/v4.min.js` | 5290 B | 15287 B |
|
|
99
77
|
|
|
100
|
-
|
|
78
|
+
[automated sizing report](./docs/compressed.md)
|
|
101
79
|
|
|
102
|
-
|
|
80
|
+
#### MQTT Client sizes
|
|
81
|
+
|
|
82
|
+
| minifeid | (x) | Project | Measurement |
|
|
83
|
+
|---------:|-----:|----------------|-------------|
|
|
84
|
+
| 187.0KB | 12x | [MQTT.js][] | `curl -sL https://cdn.jsdelivr.net/npm/mqtt@4.0.1/dist/mqtt.min.js \| wc -c`
|
|
85
|
+
| 32.3KB | 2x | [paho][] | `curl -sL https://cdn.jsdelivr.net/npm/paho-mqtt@1.1.0/paho-mqtt.min.js \| wc -c`
|
|
86
|
+
| 19.9KB | 1.3x | [u8-mqtt][] v5 | `cat ./u8-mqtt/esm/web/v5.min.mjs \| wc -c`
|
|
87
|
+
| 15.5KB | 1x | [u8-mqtt][] v4 | `cat ./u8-mqtt/esm/web/v4.min.mjs \| wc -c`
|
|
103
88
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
| 32KB | 2x | `curl -sL https://cdn.jsdelivr.net/npm/paho-mqtt@1.1.0/paho-mqtt.min.js \| wc -c`
|
|
108
|
-
| 16KB | 1x | `cat ./u8-mqtt/esm/web/v4.min.mjs \| wc -c`
|
|
89
|
+
[MQTT.js]: https://github.com/mqttjs/MQTT.js/
|
|
90
|
+
[paho]: https://github.com/eclipse/paho.mqtt.javascript/
|
|
91
|
+
[u8-mqtt]: https://github.com/shanewholloway/js-u8-mqtt/
|
|
109
92
|
|
|
110
93
|
|
|
111
94
|
## Prior Art
|