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.
Files changed (64) hide show
  1. package/README.md +42 -59
  2. package/cjs/index.cjs +635 -557
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/v4.cjs +482 -662
  5. package/cjs/v4.cjs.map +1 -1
  6. package/cjs/v5.cjs +634 -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 +5 -4
  13. package/code/v4.mjs +7 -6
  14. package/code/v5.mjs +15 -6
  15. package/esm/deno/index.js +637 -562
  16. package/esm/deno/index.js.map +1 -1
  17. package/esm/deno/v4.js +489 -670
  18. package/esm/deno/v4.js.map +1 -1
  19. package/esm/deno/v5.js +639 -558
  20. package/esm/deno/v5.js.map +1 -1
  21. package/esm/node/index.js +630 -555
  22. package/esm/node/index.js.map +1 -1
  23. package/esm/node/index.mjs +630 -555
  24. package/esm/node/index.mjs.map +1 -1
  25. package/esm/node/v4.js +482 -663
  26. package/esm/node/v4.js.map +1 -1
  27. package/esm/node/v4.mjs +482 -663
  28. package/esm/node/v4.mjs.map +1 -1
  29. package/esm/node/v5.js +632 -551
  30. package/esm/node/v5.js.map +1 -1
  31. package/esm/node/v5.mjs +632 -551
  32. package/esm/node/v5.mjs.map +1 -1
  33. package/esm/web/index.js +632 -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 +484 -665
  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 +634 -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 +24 -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/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
- ```javascript
37
- // using NodeJS
38
- import mqtt_client from 'u8-mqtt/esm/node/v4.mjs'
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
- async function somewhere_in_your_code(my_mqtt) {
63
- my_mqtt
64
- .on_topic('u8-mqtt-demo/topic/:arg', (pkt, params, ctx) => {
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
- await my_mqtt.connect({
76
- client_id: ['my-mqtt--', '--demo'],
77
- will: {
78
- topic: 'u8-mqtt-demo/bye',
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
- await my_mqtt.subscribe([
84
- 'u8-mqtt-demo/another/#',
85
- 'u8-mqtt-demo/topic/+',
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
- my_mqtt.publish({
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
- my_mqtt.send(
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
- ## Sizes
78
+ [automated sizing report](./docs/compressed.md)
101
79
 
102
- Built for small footprint with ES Modules (ESM) using embedded [u8-mqtt-packet][] and [regexparam][] libraries.
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
- | Size | (x) | Measurement
105
- |-------|-----|------------
106
- | 187KB | 13x | `curl -sL https://cdn.jsdelivr.net/npm/mqtt@4.0.1/dist/mqtt.min.js \| wc -c`
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