u8-mqtt 0.0.23

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/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2020, Shane Holloway
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # u8-mqtt
2
+
3
+ A JavaScript MQTT client using async/await support QOS-0 and QOS-1.
4
+ Zero external dependencies. [Tree-shaking friendly](https://rollupjs.org/guide/en/).
5
+ Suited for use in modern ES6 environments: the Browser, [NodeJS](https://nodejs.org/en/), and [Deno](https://deno.land/).
6
+
7
+ Use ExpressJS-like router to handle publish messages for matching topics.
8
+
9
+ * Static (`/foo`, `/foo/bar`)
10
+ * Parameter (`/:title`, `/books/:title`, `/books/:genre/:title`)
11
+ * Parameter w/ Suffix (`/movies/:title.mp4`, `/movies/:title.(mp4|mov)`)
12
+ * Optional Parameters (`/:title?`, `/books/:title?`, `/books/:genre/:title?`)
13
+ * Wildcards (`*`, `/books/*`, `/books/:genre/*`)
14
+
15
+ (Thanks to @lukeed and the excellent [regexparam][] library!)
16
+
17
+
18
+ [u8-mqtt-packet]: https://github.com/shanewholloway/js-u8-mqtt-packet
19
+ [regexparam]: https://github.com/lukeed/regexparam#readme
20
+
21
+
22
+ ## Docs
23
+
24
+ - [API docs](./docs/api.md)
25
+ - See [u8-mqtt-packet][] for details on packet encode and decoding.
26
+
27
+
28
+ Targeting [MQTT-3.1.1 (v4)][spec-3.1.1] and [MQTT-5.0.0 (v5)][spec-5.0.0] compatibility.
29
+
30
+ [spec-5.0.0]: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
31
+ [spec-3.1.1]: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
32
+
33
+
34
+ ## Use
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')
55
+
56
+
57
+ // use on_live to converse with the MQTT server
58
+ my_mqtt.on_live = somewhere_in_your_code
59
+
60
+
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
+ })
73
+
74
+
75
+ await my_mqtt.connect({
76
+ client_id: ['my-mqtt--', '--demo'],
77
+ will: {
78
+ topic: 'u8-mqtt-demo/bye',
79
+ payload: 'gone!',
80
+ }
81
+ })
82
+
83
+ await my_mqtt.subscribe([
84
+ 'u8-mqtt-demo/another/#',
85
+ 'u8-mqtt-demo/topic/+',
86
+ ])
87
+
88
+ my_mqtt.publish({
89
+ topic: 'u8-mqtt-demo/topic/node-side-fun-test',
90
+ payload: 'awesome from both web and node',
91
+ })
92
+
93
+ my_mqtt.send(
94
+ 'u8-mqtt-demo/another/apple/orange',
95
+ 'MQTT Fruity fun')
96
+
97
+ }
98
+ ```
99
+
100
+ ## Sizes
101
+
102
+ Built for small footprint with ES Modules (ESM) using embedded [u8-mqtt-packet][] and [regexparam][] libraries.
103
+
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`
109
+
110
+
111
+ ## Prior Art
112
+
113
+ The `u8-mqtt` project was inspired by [mqtt](https://github.com/mqttjs/MQTT.js#readme) and [mqtt-packet](https://github.com/mqttjs/mqtt-packet) written for NodeJS. The codecs of those project are written with a NodeJS ecosystem in mind: Buffer, EventEmitter, Streams.
114
+
115
+
116
+ ## License
117
+
118
+ [BSD-2-Clause](LICENSE)
119
+