mqtt 5.0.0-beta.2 → 5.0.0-beta.4

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 (137) hide show
  1. package/README.md +48 -28
  2. package/build/package.json +162 -0
  3. package/build/src/bin/mqtt.d.ts +2 -0
  4. package/build/src/bin/mqtt.js +27 -0
  5. package/build/src/bin/mqtt.js.map +1 -0
  6. package/build/src/bin/pub.d.ts +2 -0
  7. package/build/src/bin/pub.js +146 -0
  8. package/build/src/bin/pub.js.map +1 -0
  9. package/build/src/bin/sub.d.ts +2 -0
  10. package/build/src/bin/sub.js +121 -0
  11. package/build/src/bin/sub.js.map +1 -0
  12. package/build/src/lib/TypedEmitter.d.ts +11 -0
  13. package/build/src/lib/TypedEmitter.js +13 -0
  14. package/build/src/lib/TypedEmitter.js.map +1 -0
  15. package/build/src/lib/client.d.ts +266 -0
  16. package/build/src/lib/client.js +1147 -0
  17. package/build/src/lib/client.js.map +1 -0
  18. package/build/src/lib/connect/ali.d.ts +3 -0
  19. package/build/src/lib/connect/ali.js +113 -0
  20. package/build/src/lib/connect/ali.js.map +1 -0
  21. package/build/src/lib/connect/index.d.ts +5 -0
  22. package/build/src/lib/connect/index.js +134 -0
  23. package/build/src/lib/connect/index.js.map +1 -0
  24. package/build/src/lib/connect/tcp.d.ts +3 -0
  25. package/build/src/lib/connect/tcp.js +18 -0
  26. package/build/src/lib/connect/tcp.js.map +1 -0
  27. package/build/src/lib/connect/tls.d.ts +3 -0
  28. package/build/src/lib/connect/tls.js +38 -0
  29. package/build/src/lib/connect/tls.js.map +1 -0
  30. package/build/src/lib/connect/ws.d.ts +3 -0
  31. package/build/src/lib/connect/ws.js +212 -0
  32. package/build/src/lib/connect/ws.js.map +1 -0
  33. package/build/src/lib/connect/wx.d.ts +3 -0
  34. package/build/src/lib/connect/wx.js +117 -0
  35. package/build/src/lib/connect/wx.js.map +1 -0
  36. package/build/src/lib/default-message-id-provider.d.ts +16 -0
  37. package/build/src/lib/default-message-id-provider.js +24 -0
  38. package/build/src/lib/default-message-id-provider.js.map +1 -0
  39. package/build/src/lib/handlers/ack.d.ts +48 -0
  40. package/build/src/lib/handlers/ack.js +129 -0
  41. package/build/src/lib/handlers/ack.js.map +1 -0
  42. package/build/src/lib/handlers/auth.d.ts +3 -0
  43. package/build/src/lib/handlers/auth.js +30 -0
  44. package/build/src/lib/handlers/auth.js.map +1 -0
  45. package/build/src/lib/handlers/connack.d.ts +3 -0
  46. package/build/src/lib/handlers/connack.js +48 -0
  47. package/build/src/lib/handlers/connack.js.map +1 -0
  48. package/build/src/lib/handlers/index.d.ts +3 -0
  49. package/build/src/lib/handlers/index.js +64 -0
  50. package/build/src/lib/handlers/index.js.map +1 -0
  51. package/build/src/lib/handlers/publish.d.ts +3 -0
  52. package/build/src/lib/handlers/publish.js +106 -0
  53. package/build/src/lib/handlers/publish.js.map +1 -0
  54. package/build/src/lib/handlers/pubrel.d.ts +3 -0
  55. package/build/src/lib/handlers/pubrel.js +25 -0
  56. package/build/src/lib/handlers/pubrel.js.map +1 -0
  57. package/build/src/lib/is-browser.d.ts +2 -0
  58. package/build/src/lib/is-browser.js +8 -0
  59. package/build/src/lib/is-browser.js.map +1 -0
  60. package/build/src/lib/shared.d.ts +17 -0
  61. package/build/src/lib/shared.js +35 -0
  62. package/build/src/lib/shared.js.map +1 -0
  63. package/build/src/lib/store.d.ts +24 -0
  64. package/build/src/lib/store.js +80 -0
  65. package/build/src/lib/store.js.map +1 -0
  66. package/build/src/lib/topic-alias-recv.d.ts +9 -0
  67. package/build/src/lib/topic-alias-recv.js +24 -0
  68. package/build/src/lib/topic-alias-recv.js.map +1 -0
  69. package/build/src/lib/topic-alias-send.d.ts +13 -0
  70. package/build/src/lib/topic-alias-send.js +56 -0
  71. package/build/src/lib/topic-alias-send.js.map +1 -0
  72. package/build/src/lib/unique-message-id-provider.d.ts +10 -0
  73. package/build/src/lib/unique-message-id-provider.js +26 -0
  74. package/build/src/lib/unique-message-id-provider.js.map +1 -0
  75. package/build/src/lib/validations.d.ts +2 -0
  76. package/build/src/lib/validations.js +32 -0
  77. package/build/src/lib/validations.js.map +1 -0
  78. package/build/src/mqtt.d.ts +8 -0
  79. package/build/src/mqtt.js +33 -0
  80. package/build/src/mqtt.js.map +1 -0
  81. package/build/tsconfig.build.tsbuildinfo +1 -0
  82. package/dist/mqtt.js +4987 -5249
  83. package/dist/mqtt.min.js +4 -4
  84. package/package.json +84 -66
  85. package/src/bin/mqtt.ts +32 -0
  86. package/src/bin/pub.ts +171 -0
  87. package/src/bin/sub.ts +146 -0
  88. package/src/lib/TypedEmitter.ts +45 -0
  89. package/src/lib/client.ts +2279 -0
  90. package/src/lib/connect/ali.ts +128 -0
  91. package/src/lib/connect/index.ts +180 -0
  92. package/src/lib/connect/tcp.ts +23 -0
  93. package/src/lib/connect/tls.ts +56 -0
  94. package/src/lib/connect/ws.ts +282 -0
  95. package/src/lib/connect/wx.ts +141 -0
  96. package/src/lib/default-message-id-provider.ts +99 -0
  97. package/src/lib/handlers/ack.ts +151 -0
  98. package/src/lib/handlers/auth.ts +44 -0
  99. package/src/lib/handlers/connack.ts +55 -0
  100. package/src/lib/handlers/index.ts +67 -0
  101. package/src/lib/handlers/publish.ts +183 -0
  102. package/src/lib/handlers/pubrel.ts +27 -0
  103. package/src/lib/is-browser.ts +12 -0
  104. package/src/lib/shared.ts +73 -0
  105. package/src/lib/store.ts +166 -0
  106. package/src/lib/topic-alias-recv.ts +48 -0
  107. package/src/lib/topic-alias-send.ts +96 -0
  108. package/src/lib/unique-message-id-provider.ts +63 -0
  109. package/src/lib/validations.ts +46 -0
  110. package/src/mqtt.ts +23 -0
  111. package/bin/mqtt.js +0 -27
  112. package/bin/pub.js +0 -146
  113. package/bin/sub.js +0 -123
  114. package/lib/client.js +0 -1918
  115. package/lib/connect/ali.js +0 -129
  116. package/lib/connect/index.js +0 -169
  117. package/lib/connect/tcp.js +0 -20
  118. package/lib/connect/tls.js +0 -48
  119. package/lib/connect/ws.js +0 -257
  120. package/lib/connect/wx.js +0 -133
  121. package/lib/default-message-id-provider.js +0 -69
  122. package/lib/is-browser.js +0 -11
  123. package/lib/store.js +0 -128
  124. package/lib/topic-alias-recv.js +0 -47
  125. package/lib/topic-alias-send.js +0 -91
  126. package/lib/unique-message-id-provider.js +0 -65
  127. package/lib/validations.js +0 -52
  128. package/mqtt.js +0 -21
  129. package/types/index.d.ts +0 -30
  130. package/types/lib/client-options.d.ts +0 -208
  131. package/types/lib/client.d.ts +0 -261
  132. package/types/lib/connect/index.d.ts +0 -19
  133. package/types/lib/default-message-id-provider.d.ts +0 -49
  134. package/types/lib/message-id-provider.d.ts +0 -40
  135. package/types/lib/store-options.d.ts +0 -6
  136. package/types/lib/store.d.ts +0 -46
  137. package/types/lib/unique-message-id-provider.d.ts +0 -48
@@ -1,208 +0,0 @@
1
- import { MqttClient } from './client'
2
- import { Store } from './store'
3
- import { ClientOptions } from 'ws'
4
- import { ClientRequestArgs } from 'http'
5
- import { QoS, UserProperties } from 'mqtt-packet'
6
- import { IMessageIdProvider } from './message-id-provider'
7
-
8
- export declare type StorePutCallback = () => void
9
-
10
- export interface IClientOptions extends ISecureClientOptions {
11
- port?: number // port is made into a number subsequently
12
- host?: string // host does NOT include port
13
- hostname?: string
14
- path?: string
15
- protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
16
-
17
- wsOptions?: ClientOptions | ClientRequestArgs
18
- /**
19
- * 10 seconds, set to 0 to disable
20
- */
21
- keepalive?: number
22
- /**
23
- * 'mqttjs_' + Math.random().toString(16).substr(2, 8)
24
- */
25
- clientId?: string
26
- /**
27
- * 'MQTT'
28
- */
29
- protocolId?: string
30
- /**
31
- * 4
32
- */
33
- protocolVersion?: number
34
- /**
35
- * true, set to false to receive QoS 1 and 2 messages while offline
36
- */
37
- clean?: boolean
38
- /**
39
- * 1000 milliseconds, interval between two reconnections
40
- */
41
- reconnectPeriod?: number
42
- /**
43
- * 30 * 1000 milliseconds, time to wait before a CONNACK is received
44
- */
45
- connectTimeout?: number
46
- /**
47
- * the username required by your broker, if any
48
- */
49
- username?: string
50
- /**
51
- * the password required by your broker, if any
52
- */
53
- password?: Buffer | string
54
- /**
55
- * a Store for the incoming packets
56
- */
57
- incomingStore?: Store
58
- /**
59
- * a Store for the outgoing packets
60
- */
61
- outgoingStore?: Store
62
- queueQoSZero?: boolean
63
-
64
- autoUseTopicAlias?: boolean
65
- autoAssignTopicAlias?: boolean
66
-
67
- reschedulePings?: boolean
68
- servers?: Array<{
69
- host: string
70
- port: number
71
- protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
72
- }>
73
- /**
74
- * true, set to false to disable re-subscribe functionality
75
- */
76
- resubscribe?: boolean
77
- /**
78
- * a message that will sent by the broker automatically when the client disconnect badly.
79
- */
80
- will?: {
81
- /**
82
- * the topic to publish
83
- */
84
- topic: string
85
- /**
86
- * the message to publish
87
- */
88
- payload: Buffer | string
89
- /**
90
- * the QoS
91
- */
92
- qos: QoS
93
- /**
94
- * the retain flag
95
- */
96
- retain: boolean,
97
- /*
98
- * properies object of will
99
- * */
100
- properties?: {
101
- willDelayInterval?: number,
102
- payloadFormatIndicator?: boolean,
103
- messageExpiryInterval?: number,
104
- contentType?: string,
105
- responseTopic?: string,
106
- correlationData?: Buffer,
107
- userProperties?: UserProperties
108
- }
109
- }
110
- transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string,
111
- properties?: {
112
- sessionExpiryInterval?: number,
113
- receiveMaximum?: number,
114
- maximumPacketSize?: number,
115
- topicAliasMaximum?: number,
116
- requestResponseInformation?: boolean,
117
- requestProblemInformation?: boolean,
118
- userProperties?: UserProperties,
119
- authenticationMethod?: string,
120
- authenticationData?: Buffer
121
- },
122
- messageIdProvider?: IMessageIdProvider
123
- }
124
- export interface ISecureClientOptions {
125
- /**
126
- * optional private keys in PEM format
127
- */
128
- key?: string | string[] | Buffer | Buffer[] | Object[]
129
- /**
130
- * optional cert chains in PEM format
131
- */
132
- cert?: string | string[] | Buffer | Buffer[]
133
- /**
134
- * Optionally override the trusted CA certificates in PEM format
135
- */
136
- ca?: string | string[] | Buffer | Buffer[]
137
- rejectUnauthorized?: boolean
138
- /**
139
- * optional alpn's
140
- */
141
- ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array
142
- }
143
- export interface IClientPublishOptions {
144
- /**
145
- * the QoS
146
- */
147
- qos?: QoS
148
- /**
149
- * the retain flag
150
- */
151
- retain?: boolean
152
- /**
153
- * whether or not mark a message as duplicate
154
- */
155
- dup?: boolean
156
- /*
157
- * MQTT 5.0 properties object
158
- */
159
- properties?: {
160
- payloadFormatIndicator?: boolean,
161
- messageExpiryInterval?: number,
162
- topicAlias?: number,
163
- responseTopic?: string,
164
- correlationData?: Buffer,
165
- userProperties?: UserProperties,
166
- subscriptionIdentifier?: number,
167
- contentType?: string
168
- }
169
- /**
170
- * callback called when message is put into `outgoingStore`
171
- */
172
- cbStorePut?: StorePutCallback
173
- }
174
- export interface IClientSubscribeOptions {
175
- /**
176
- * the QoS
177
- */
178
- qos: QoS,
179
- /*
180
- * no local flag
181
- * */
182
- nl?: boolean,
183
- /*
184
- * Retain As Published flag
185
- * */
186
- rap?: boolean,
187
- /*
188
- * Retain Handling option
189
- * */
190
- rh?: number,
191
- /*
192
- * MQTT 5.0 properies object of subscribe
193
- * */
194
- properties?: {
195
- subscriptionIdentifier?: number,
196
- userProperties?: UserProperties
197
- }
198
- }
199
- export interface IClientReconnectOptions {
200
- /**
201
- * a Store for the incoming packets
202
- */
203
- incomingStore?: Store
204
- /**
205
- * a Store for the outgoing packets
206
- */
207
- outgoingStore?: Store
208
- }
@@ -1,261 +0,0 @@
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 { IAuthPacket, IPublishPacket, IDisconnectPacket, IConnackPacket, 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: IConnackPacket) => void
70
- export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
71
- export declare type ClientSubscribeCallback = (err: Error | null, 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
- * Handle auth packages for MQTT 5 enhanced authentication methods such
237
- * as challenge response authentication.
238
- *
239
- * Challenge-response authentication flow would look something like this:
240
- *
241
- * --> CONNECT | authMethod = "mathChallenge" -->
242
- * <-- AUTH | authMethod = "mathChallenge", authData = "12 + 34" <--
243
- * --> AUTH | authMethod = "mathChallenge", authData = "46" -->
244
- * <-- CONNACK | reasonCode = SUCCESS <--
245
- *
246
- * This form of authentication has several advantages over traditional
247
- * credential-based approaches. For instance authentication without the direct
248
- * exchange of authentication secrets.
249
- *
250
- * @param packet the auth packet to handle
251
- * @param callback call when finished
252
- * @api public
253
- */
254
- public handleAuth (packet: IAuthPacket, callback: PacketCallback): void
255
-
256
- /**
257
- * getLastMessageId
258
- */
259
- public getLastMessageId (): number
260
- }
261
- export { IClientOptions }
@@ -1,19 +0,0 @@
1
- import { IClientOptions, MqttClient } from '../client'
2
-
3
- /**
4
- * connect - connect to an MQTT broker.
5
- *
6
- * @param {Object} opts - see MqttClient#constructor
7
- */
8
- declare function connect (opts: IClientOptions): MqttClient
9
-
10
- /**
11
- * connect - connect to an MQTT broker.
12
- *
13
- * @param {String} brokerUrl - url of the broker
14
- * @param {Object} opts - see MqttClient#constructor
15
- */
16
- declare function connect (brokerUrl: string, opts?: IClientOptions): MqttClient
17
-
18
- export { connect }
19
- export { MqttClient }
@@ -1,49 +0,0 @@
1
- import { IMessageIdProvider } from './message-id-provider'
2
-
3
- /**
4
- * DefaultMessageIdProvider
5
- * This is compatible behavior with the original MQTT.js internal messageId allocation.
6
- */
7
- declare class DefaultMessageIdProvider implements IMessageIdProvider {
8
- /**
9
- * DefaultMessageIdProvider constructor.
10
- * Randomize initial messageId
11
- * @constructor
12
- */
13
- constructor ()
14
-
15
- /**
16
- * Return the current messageId and increment the current messageId.
17
- * @return {Number} - messageId
18
- */
19
- public allocate (): Number | null
20
-
21
- /**
22
- * Get the last allocated messageId.
23
- * @return {Number} - messageId.
24
- */
25
- public getLastAllocated (): Number | null
26
-
27
- /**
28
- * Register the messageId.
29
- * This function actually nothing and always return true.
30
- * @param {Number} num - The messageId to request use.
31
- * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
32
- */
33
- public register (num: Number): Boolean
34
-
35
- /**
36
- * Deallocate the messageId.
37
- * This function actually nothing.
38
- * @param {Number} num - The messageId to deallocate.
39
- */
40
- public deallocate (num: Number): void
41
-
42
- /**
43
- * Clear all occupied messageIds.
44
- * This function actually nothing.
45
- */
46
- public clear (): void
47
- }
48
-
49
- export { DefaultMessageIdProvider }
@@ -1,40 +0,0 @@
1
- /**
2
- * MessageIdProvider
3
- */
4
- declare interface IMessageIdProvider {
5
- /**
6
- * Allocate the first vacant messageId. The messageId become occupied status.
7
- * @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
8
- */
9
- allocate (): Number | null
10
-
11
- /**
12
- * Get the last allocated messageId.
13
- * @return {Number} - messageId.
14
- */
15
- getLastAllocated (): Number | null
16
-
17
- /**
18
- * Register the messageId. The messageId become occupied status.
19
- * If the messageId has already been occupied, then return false.
20
- * @param {Number} num - The messageId to request use.
21
- * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
22
- */
23
- register (num: Number): Boolean
24
-
25
- /**
26
- * Deallocate the messageId. The messageId become vacant status.
27
- * @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
28
- * In other words, the messageId must be allocated by allocate() or
29
- * occupied by register().
30
- */
31
- deallocate (num: Number): void
32
-
33
- /**
34
- * Clear all occupied messageIds.
35
- * The all messageIds are set to vacant status.
36
- */
37
- clear (): void
38
- }
39
-
40
- export { IMessageIdProvider }
@@ -1,6 +0,0 @@
1
- export interface IStoreOptions {
2
- /**
3
- * true, clear _inflights at close
4
- */
5
- clean?: boolean
6
- }
@@ -1,46 +0,0 @@
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,48 +0,0 @@
1
- import { IMessageIdProvider } from './message-id-provider'
2
-
3
- /**
4
- * UniqueMessageIdProvider
5
- */
6
- declare class UniqueMessageIdProvider implements IMessageIdProvider {
7
- /**
8
- * UniqueMessageIdProvider constructor.
9
- * @constructor
10
- */
11
- constructor ()
12
-
13
- /**
14
- * Allocate the first vacant messageId. The messageId become occupied status.
15
- * @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
16
- */
17
- public allocate (): Number | null
18
-
19
- /**
20
- * Get the last allocated messageId.
21
- * @return {Number} - messageId.
22
- */
23
- public getLastAllocated (): Number | null
24
-
25
- /**
26
- * Register the messageId. The messageId become occupied status.
27
- * If the messageId has already been occupied, then return false.
28
- * @param {Number} num - The messageId to request use.
29
- * @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
30
- */
31
- public register (num: Number): Boolean
32
-
33
- /**
34
- * Deallocate the messageId. The messageId become vacant status.
35
- * @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
36
- * In other words, the messageId must be allocated by allocate() or
37
- * occupied by register().
38
- */
39
- public deallocate (num: Number): void
40
-
41
- /**
42
- * Clear all occupied messageIds.
43
- * The all messageIds are set to vacant status.
44
- */
45
- public clear (): void
46
- }
47
-
48
- export { UniqueMessageIdProvider }