mqtt 4.2.4 → 4.2.8

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.
@@ -1,232 +1,240 @@
1
- /// <reference types="node" />
2
-
3
- import * as events from 'events'
4
- import {
5
- IClientOptions,
6
- IClientPublishOptions,
7
- IClientSubscribeOptions,
8
- IClientReconnectOptions
9
- } from './client-options'
10
- import { Store } from './store'
11
- import { Packet, QoS } from 'mqtt-packet'
12
-
13
- export interface ISubscriptionGrant {
14
- /**
15
- * is a subscribed to topic
16
- */
17
- topic: string
18
- /**
19
- * is the granted qos level on it, may return 128 on error
20
- */
21
- qos: QoS | number
22
- /*
23
- * no local flag
24
- * */
25
- nl?: boolean,
26
- /*
27
- * Retain As Published flag
28
- * */
29
- rap?: boolean,
30
- /*
31
- * Retain Handling option
32
- * */
33
- rh?: number
34
- }
35
- export interface ISubscriptionRequest {
36
- /**
37
- * is a subscribed to topic
38
- */
39
- topic: string
40
- /**
41
- * is the granted qos level on it
42
- */
43
- qos: QoS
44
- /*
45
- * no local flag
46
- * */
47
- nl?: boolean,
48
- /*
49
- * Retain As Published flag
50
- * */
51
- rap?: boolean,
52
- /*
53
- * Retain Handling option
54
- * */
55
- rh?: number
56
- }
57
- export interface ISubscriptionMap {
58
- /**
59
- * object which has topic names as object keys and as value the options, like {'test1': {qos: 0}, 'test2': {qos: 2}}.
60
- */
61
- [topic: string]: {
62
- qos: QoS,
63
- nl?: boolean,
64
- rap?: boolean,
65
- rh?: number
66
- }
67
- }
68
-
69
- export declare type OnConnectCallback = (packet: Packet) => void
70
- export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
71
- export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: Packet) => void
72
- export declare type OnPacketCallback = (packet: Packet) => void
73
- export declare type OnErrorCallback = (error: Error) => void
74
- export declare type PacketCallback = (error?: Error, packet?: Packet) => any
75
- export declare type CloseCallback = () => void
76
-
77
- export interface IStream extends events.EventEmitter {
78
- pipe (to: any): any
79
- destroy (): any
80
- end (): any
81
- }
82
- /**
83
- * MqttClient constructor
84
- *
85
- * @param {Stream} stream - stream
86
- * @param {Object} [options] - connection options
87
- * (see Connection#connect)
88
- */
89
- export declare class MqttClient extends events.EventEmitter {
90
- public connected: boolean
91
- public disconnecting: boolean
92
- public disconnected: boolean
93
- public reconnecting: boolean
94
- public incomingStore: Store
95
- public outgoingStore: Store
96
- public options: IClientOptions
97
- public queueQoSZero: boolean
98
-
99
- constructor (streamBuilder: (client: MqttClient) => IStream, options: IClientOptions)
100
-
101
- public on (event: 'connect', cb: OnConnectCallback): this
102
- public on (event: 'message', cb: OnMessageCallback): this
103
- public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
104
- public on (event: 'error', cb: OnErrorCallback): this
105
- public on (event: string, cb: Function): this
106
-
107
- public once (event: 'connect', cb: OnConnectCallback): this
108
- public once (event: 'message', cb: OnMessageCallback): this
109
- public once (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
110
- public once (event: 'error', cb: OnErrorCallback): this
111
- public once (event: string, cb: Function): this
112
-
113
- /**
114
- * publish - publish <message> to <topic>
115
- *
116
- * @param {String} topic - topic to publish to
117
- * @param {(String|Buffer)} message - message to publish
118
- *
119
- * @param {Object} [opts] - publish options, includes:
120
- * @param {Number} [opts.qos] - qos level to publish on
121
- * @param {Boolean} [opts.retain] - whether or not to retain the message
122
- * @param {Function}[opts.cbStorePut] - function(){}
123
- * called when message is put into `outgoingStore`
124
- *
125
- * @param {Function} [callback] - function(err){}
126
- * called when publish succeeds or fails
127
- *
128
- * @returns {Client} this - for chaining
129
- * @api public
130
- *
131
- * @example client.publish('topic', 'message')
132
- * @example
133
- * client.publish('topic', 'message', {qos: 1, retain: true})
134
- * @example client.publish('topic', 'message', console.log)
135
- */
136
- public publish (topic: string, message: string | Buffer,
137
- opts: IClientPublishOptions, callback?: PacketCallback): this
138
- public publish (topic: string, message: string | Buffer,
139
- callback?: PacketCallback): this
140
-
141
- /**
142
- * subscribe - subscribe to <topic>
143
- *
144
- * @param {String, Array, Object} topic - topic(s) to subscribe to, supports objects in the form {'topic': qos}
145
- * @param {Object} [opts] - optional subscription options, includes:
146
- * @param {Number} [opts.qos] - subscribe qos level
147
- * @param {Function} [callback] - function(err, granted){} where:
148
- * {Error} err - subscription error (none at the moment!)
149
- * {Array} granted - array of {topic: 't', qos: 0}
150
- * @returns {MqttClient} this - for chaining
151
- * @api public
152
- * @example client.subscribe('topic')
153
- * @example client.subscribe('topic', {qos: 1})
154
- * @example client.subscribe({'topic': 0, 'topic2': 1}, console.log)
155
- * @example client.subscribe('topic', console.log)
156
- */
157
- public subscribe (topic:
158
- string
159
- | string[], opts: IClientSubscribeOptions, callback?: ClientSubscribeCallback): this
160
- public subscribe (topic:
161
- string
162
- | string[]
163
- | ISubscriptionMap, callback?: ClientSubscribeCallback): this
164
-
165
- /**
166
- * unsubscribe - unsubscribe from topic(s)
167
- *
168
- * @param {String, Array} topic - topics to unsubscribe from
169
- * @param {Object} opts - opts of unsubscribe
170
- * @param {Function} [callback] - callback fired on unsuback
171
- * @returns {MqttClient} this - for chaining
172
- * @api public
173
- * @example client.unsubscribe('topic')
174
- * @example client.unsubscribe('topic', console.log)
175
- * @example client.unsubscribe('topic', opts, console.log)
176
- */
177
- public unsubscribe (topic: string | string[], opts?: Object, callback?: PacketCallback): this
178
-
179
- /**
180
- * end - close connection
181
- *
182
- * @returns {MqttClient} this - for chaining
183
- * @param {Boolean} force - do not wait for all in-flight messages to be acked
184
- * @param {Object} opts - opts disconnect
185
- * @param {Function} cb - called when the client has been closed
186
- *
187
- * @api public
188
- */
189
- public end (force?: boolean, opts?: Object, cb?: CloseCallback): this
190
-
191
- /**
192
- * removeOutgoingMessage - remove a message in outgoing store
193
- * the outgoing callback will be called withe Error('Message removed') if the message is removed
194
- *
195
- * @param {Number} mid - messageId to remove message
196
- * @returns {MqttClient} this - for chaining
197
- * @api public
198
- *
199
- * @example client.removeOutgoingMessage(client.getLastMessageId());
200
- */
201
- public removeOutgoingMessage (mid: number): this
202
-
203
- /**
204
- * reconnect - connect again using the same options as connect()
205
- *
206
- * @param {Object} [opts] - optional reconnect options, includes:
207
- * {Store} incomingStore - a store for the incoming packets
208
- * {Store} outgoingStore - a store for the outgoing packets
209
- * if opts is not given, current stores are used
210
- *
211
- * @returns {MqttClient} this - for chaining
212
- *
213
- * @api public
214
- */
215
- public reconnect (opts?: IClientReconnectOptions): this
216
-
217
- /**
218
- * Handle messages with backpressure support, one at a time.
219
- * Override at will.
220
- *
221
- * @param packet packet the packet
222
- * @param callback callback call when finished
223
- * @api public
224
- */
225
- public handleMessage (packet: Packet, callback: PacketCallback): void
226
-
227
- /**
228
- * getLastMessageId
229
- */
230
- public getLastMessageId (): number
231
- }
232
- export { IClientOptions }
1
+ /// <reference types="node" />
2
+
3
+ import * as events from 'events'
4
+ import {
5
+ IClientOptions,
6
+ IClientPublishOptions,
7
+ IClientSubscribeOptions,
8
+ IClientReconnectOptions
9
+ } from './client-options'
10
+ import { Store } from './store'
11
+ import { Packet, IConnectPacket, IPublishPacket, IDisconnectPacket, QoS } from 'mqtt-packet'
12
+
13
+ export interface ISubscriptionGrant {
14
+ /**
15
+ * is a subscribed to topic
16
+ */
17
+ topic: string
18
+ /**
19
+ * is the granted qos level on it, may return 128 on error
20
+ */
21
+ qos: QoS | number
22
+ /*
23
+ * no local flag
24
+ * */
25
+ nl?: boolean,
26
+ /*
27
+ * Retain As Published flag
28
+ * */
29
+ rap?: boolean,
30
+ /*
31
+ * Retain Handling option
32
+ * */
33
+ rh?: number
34
+ }
35
+ export interface ISubscriptionRequest {
36
+ /**
37
+ * is a subscribed to topic
38
+ */
39
+ topic: string
40
+ /**
41
+ * is the granted qos level on it
42
+ */
43
+ qos: QoS
44
+ /*
45
+ * no local flag
46
+ * */
47
+ nl?: boolean,
48
+ /*
49
+ * Retain As Published flag
50
+ * */
51
+ rap?: boolean,
52
+ /*
53
+ * Retain Handling option
54
+ * */
55
+ rh?: number
56
+ }
57
+ export interface ISubscriptionMap {
58
+ /**
59
+ * object which has topic names as object keys and as value the options, like {'test1': {qos: 0}, 'test2': {qos: 2}}.
60
+ */
61
+ [topic: string]: {
62
+ qos: QoS,
63
+ nl?: boolean,
64
+ rap?: boolean,
65
+ rh?: number
66
+ }
67
+ }
68
+
69
+ export declare type OnConnectCallback = (packet: IConnectPacket) => void
70
+ export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
71
+ export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
72
+ export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void
73
+ export declare type OnPacketCallback = (packet: Packet) => void
74
+ export declare type OnCloseCallback = () => void
75
+ export declare type OnErrorCallback = (error: Error) => void
76
+ export declare type PacketCallback = (error?: Error, packet?: Packet) => any
77
+ export declare type CloseCallback = (error?: Error) => void
78
+
79
+ export interface IStream extends events.EventEmitter {
80
+ pipe (to: any): any
81
+ destroy (): any
82
+ end (): any
83
+ }
84
+ /**
85
+ * MqttClient constructor
86
+ *
87
+ * @param {Stream} stream - stream
88
+ * @param {Object} [options] - connection options
89
+ * (see Connection#connect)
90
+ */
91
+ export declare class MqttClient extends events.EventEmitter {
92
+ public connected: boolean
93
+ public disconnecting: boolean
94
+ public disconnected: boolean
95
+ public reconnecting: boolean
96
+ public incomingStore: Store
97
+ public outgoingStore: Store
98
+ public options: IClientOptions
99
+ public queueQoSZero: boolean
100
+
101
+ constructor (streamBuilder: (client: MqttClient) => IStream, options: IClientOptions)
102
+
103
+ public on (event: 'connect', cb: OnConnectCallback): this
104
+ public on (event: 'message', cb: OnMessageCallback): this
105
+ public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
106
+ public on (event: 'disconnect', cb: OnDisconnectCallback): this
107
+ public on (event: 'error', cb: OnErrorCallback): this
108
+ public on (event: 'close', cb: OnCloseCallback): this
109
+ public on (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
110
+ public on (event: string, cb: Function): this
111
+
112
+ public once (event: 'connect', cb: OnConnectCallback): this
113
+ public once (event: 'message', cb: OnMessageCallback): this
114
+ public once (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
115
+ public once (event: 'disconnect', cb: OnDisconnectCallback): this
116
+ public once (event: 'error', cb: OnErrorCallback): this
117
+ public once (event: 'close', cb: OnCloseCallback): this
118
+ public once (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
119
+ public once (event: string, cb: Function): this
120
+
121
+ /**
122
+ * publish - publish <message> to <topic>
123
+ *
124
+ * @param {String} topic - topic to publish to
125
+ * @param {(String|Buffer)} message - message to publish
126
+ *
127
+ * @param {Object} [opts] - publish options, includes:
128
+ * @param {Number} [opts.qos] - qos level to publish on
129
+ * @param {Boolean} [opts.retain] - whether or not to retain the message
130
+ * @param {Function}[opts.cbStorePut] - function(){}
131
+ * called when message is put into `outgoingStore`
132
+ *
133
+ * @param {Function} [callback] - function(err){}
134
+ * called when publish succeeds or fails
135
+ *
136
+ * @returns {Client} this - for chaining
137
+ * @api public
138
+ *
139
+ * @example client.publish('topic', 'message')
140
+ * @example
141
+ * client.publish('topic', 'message', {qos: 1, retain: true})
142
+ * @example client.publish('topic', 'message', console.log)
143
+ */
144
+ public publish (topic: string, message: string | Buffer,
145
+ opts: IClientPublishOptions, callback?: PacketCallback): this
146
+ public publish (topic: string, message: string | Buffer,
147
+ callback?: PacketCallback): this
148
+
149
+ /**
150
+ * subscribe - subscribe to <topic>
151
+ *
152
+ * @param {String, Array, Object} topic - topic(s) to subscribe to, supports objects in the form {'topic': qos}
153
+ * @param {Object} [opts] - optional subscription options, includes:
154
+ * @param {Number} [opts.qos] - subscribe qos level
155
+ * @param {Function} [callback] - function(err, granted){} where:
156
+ * {Error} err - subscription error (none at the moment!)
157
+ * {Array} granted - array of {topic: 't', qos: 0}
158
+ * @returns {MqttClient} this - for chaining
159
+ * @api public
160
+ * @example client.subscribe('topic')
161
+ * @example client.subscribe('topic', {qos: 1})
162
+ * @example client.subscribe({'topic': 0, 'topic2': 1}, console.log)
163
+ * @example client.subscribe('topic', console.log)
164
+ */
165
+ public subscribe (topic:
166
+ string
167
+ | string[], opts: IClientSubscribeOptions, callback?: ClientSubscribeCallback): this
168
+ public subscribe (topic:
169
+ string
170
+ | string[]
171
+ | ISubscriptionMap, callback?: ClientSubscribeCallback): this
172
+
173
+ /**
174
+ * unsubscribe - unsubscribe from topic(s)
175
+ *
176
+ * @param {String, Array} topic - topics to unsubscribe from
177
+ * @param {Object} opts - opts of unsubscribe
178
+ * @param {Function} [callback] - callback fired on unsuback
179
+ * @returns {MqttClient} this - for chaining
180
+ * @api public
181
+ * @example client.unsubscribe('topic')
182
+ * @example client.unsubscribe('topic', console.log)
183
+ * @example client.unsubscribe('topic', opts, console.log)
184
+ */
185
+ public unsubscribe (topic: string | string[], opts?: Object, callback?: PacketCallback): this
186
+
187
+ /**
188
+ * end - close connection
189
+ *
190
+ * @returns {MqttClient} this - for chaining
191
+ * @param {Boolean} force - do not wait for all in-flight messages to be acked
192
+ * @param {Object} opts - opts disconnect
193
+ * @param {Function} cb - called when the client has been closed
194
+ *
195
+ * @api public
196
+ */
197
+ public end (force?: boolean, opts?: Object, cb?: CloseCallback): this
198
+
199
+ /**
200
+ * removeOutgoingMessage - remove a message in outgoing store
201
+ * the outgoing callback will be called withe Error('Message removed') if the message is removed
202
+ *
203
+ * @param {Number} mid - messageId to remove message
204
+ * @returns {MqttClient} this - for chaining
205
+ * @api public
206
+ *
207
+ * @example client.removeOutgoingMessage(client.getLastMessageId());
208
+ */
209
+ public removeOutgoingMessage (mid: number): this
210
+
211
+ /**
212
+ * reconnect - connect again using the same options as connect()
213
+ *
214
+ * @param {Object} [opts] - optional reconnect options, includes:
215
+ * {Store} incomingStore - a store for the incoming packets
216
+ * {Store} outgoingStore - a store for the outgoing packets
217
+ * if opts is not given, current stores are used
218
+ *
219
+ * @returns {MqttClient} this - for chaining
220
+ *
221
+ * @api public
222
+ */
223
+ public reconnect (opts?: IClientReconnectOptions): this
224
+
225
+ /**
226
+ * Handle messages with backpressure support, one at a time.
227
+ * Override at will.
228
+ *
229
+ * @param packet packet the packet
230
+ * @param callback callback call when finished
231
+ * @api public
232
+ */
233
+ public handleMessage (packet: Packet, callback: PacketCallback): void
234
+
235
+ /**
236
+ * getLastMessageId
237
+ */
238
+ public getLastMessageId (): number
239
+ }
240
+ export { IClientOptions }
@@ -1,10 +1,10 @@
1
- import { IClientOptions, MqttClient } from '../client'
2
- /**
3
- * connect - connect to an MQTT broker.
4
- *
5
- * @param {String} [brokerUrl] - url of the broker, optional
6
- * @param {Object} opts - see MqttClient#constructor
7
- */
8
- declare function connect (brokerUrl?: string | any, opts?: IClientOptions): MqttClient
9
- export { connect }
10
- export { MqttClient }
1
+ import { IClientOptions, MqttClient } from '../client'
2
+ /**
3
+ * connect - connect to an MQTT broker.
4
+ *
5
+ * @param {String} [brokerUrl] - url of the broker, optional
6
+ * @param {Object} opts - see MqttClient#constructor
7
+ */
8
+ declare function connect (brokerUrl?: string | any, opts?: IClientOptions): MqttClient
9
+ export { connect }
10
+ export { MqttClient }
@@ -1,6 +1,6 @@
1
- export interface IStoreOptions {
2
- /**
3
- * true, clear _inflights at close
4
- */
5
- clean?: boolean
6
- }
1
+ export interface IStoreOptions {
2
+ /**
3
+ * true, clear _inflights at close
4
+ */
5
+ clean?: boolean
6
+ }
@@ -1,46 +1,46 @@
1
- import {
2
- IStoreOptions
3
- } from './store-options'
4
-
5
- /**
6
- * In-memory implementation of the message store
7
- * This can actually be saved into files.
8
- *
9
- */
10
- declare class Store {
11
- /**
12
- * Store constructor
13
- *
14
- * @param {Object} [options] - store options
15
- */
16
- constructor (options: IStoreOptions)
17
-
18
- /**
19
- * Adds a packet to the store, a packet is
20
- * anything that has a messageId property.
21
- *
22
- */
23
- public put (packet: any, cb?: Function): this
24
-
25
- /**
26
- * Creates a stream with all the packets in the store
27
- *
28
- */
29
- public createStream (): any
30
-
31
- /**
32
- * deletes a packet from the store.
33
- */
34
- public del (packet: any, cb: Function): this
35
-
36
- /**
37
- * get a packet from the store.
38
- */
39
- public get (packet: any, cb: Function): this
40
-
41
- /**
42
- * Close the store
43
- */
44
- public close (cb: Function): void
45
- }
46
- export { Store }
1
+ import {
2
+ IStoreOptions
3
+ } from './store-options'
4
+
5
+ /**
6
+ * In-memory implementation of the message store
7
+ * This can actually be saved into files.
8
+ *
9
+ */
10
+ declare class Store {
11
+ /**
12
+ * Store constructor
13
+ *
14
+ * @param {Object} [options] - store options
15
+ */
16
+ constructor (options: IStoreOptions)
17
+
18
+ /**
19
+ * Adds a packet to the store, a packet is
20
+ * anything that has a messageId property.
21
+ *
22
+ */
23
+ public put (packet: any, cb?: Function): this
24
+
25
+ /**
26
+ * Creates a stream with all the packets in the store
27
+ *
28
+ */
29
+ public createStream (): any
30
+
31
+ /**
32
+ * deletes a packet from the store.
33
+ */
34
+ public del (packet: any, cb: Function): this
35
+
36
+ /**
37
+ * get a packet from the store.
38
+ */
39
+ public get (packet: any, cb: Function): this
40
+
41
+ /**
42
+ * Close the store
43
+ */
44
+ public close (cb: Function): void
45
+ }
46
+ export { Store }