mqtt 5.0.0-beta.4 → 5.0.0
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 +35 -0
- package/build/package.json +1 -1
- package/build/src/lib/client.d.ts +32 -78
- package/build/src/lib/client.js +70 -13
- package/build/src/lib/client.js.map +1 -1
- package/build/src/lib/connect/ali.js.map +1 -1
- package/build/src/lib/connect/index.d.ts +4 -0
- package/build/src/lib/connect/index.js +36 -1
- package/build/src/lib/connect/index.js.map +1 -1
- package/build/src/lib/connect/tcp.js.map +1 -1
- package/build/src/lib/connect/tls.js.map +1 -1
- package/build/src/lib/connect/ws.js +1 -1
- package/build/src/lib/connect/ws.js.map +1 -1
- package/build/src/lib/connect/wx.js.map +1 -1
- package/build/src/lib/handlers/publish.js.map +1 -1
- package/build/src/lib/shared.d.ts +5 -4
- package/build/src/lib/unique-message-id-provider.d.ts +3 -2
- package/build/src/lib/unique-message-id-provider.js.map +1 -1
- package/build/src/mqtt.d.ts +4 -2
- package/build/src/mqtt.js +18 -2
- package/build/src/mqtt.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/dist/mqtt.js +126 -18
- package/dist/mqtt.min.js +4 -4
- package/doc/subscribe.txt +1 -1
- package/package.json +1 -1
- package/src/lib/client.ts +202 -170
- package/src/lib/connect/ali.ts +2 -2
- package/src/lib/connect/index.ts +66 -5
- package/src/lib/connect/tcp.ts +1 -1
- package/src/lib/connect/tls.ts +1 -3
- package/src/lib/connect/ws.ts +4 -5
- package/src/lib/connect/wx.ts +2 -2
- package/src/lib/default-message-id-provider.ts +2 -2
- package/src/lib/handlers/publish.ts +2 -2
- package/src/lib/shared.ts +4 -4
- package/src/lib/unique-message-id-provider.ts +3 -2
- package/src/mqtt.ts +4 -1
package/src/lib/connect/ws.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Buffer } from 'buffer'
|
|
|
4
4
|
import WS, { ClientOptions } from 'ws'
|
|
5
5
|
import _debug from 'debug'
|
|
6
6
|
import duplexify from 'duplexify'
|
|
7
|
-
import {
|
|
7
|
+
import { DuplexOptions, Transform } from 'readable-stream'
|
|
8
8
|
import IS_BROWSER from '../is-browser'
|
|
9
9
|
import MqttClient, { IClientOptions } from '../client'
|
|
10
10
|
|
|
@@ -137,13 +137,12 @@ const streamBuilder: StreamBuilder = (client, opts) => {
|
|
|
137
137
|
socket,
|
|
138
138
|
options.wsOptions as DuplexOptions,
|
|
139
139
|
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
webSocketStream.url = url
|
|
140
|
+
|
|
141
|
+
webSocketStream['url'] = url
|
|
143
142
|
socket.on('close', () => {
|
|
144
143
|
webSocketStream.destroy()
|
|
145
144
|
})
|
|
146
|
-
return webSocketStream
|
|
145
|
+
return webSocketStream
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
const browserStreamBuilder: StreamBuilder = (client, opts) => {
|
package/src/lib/connect/wx.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StreamBuilder } from '../shared'
|
|
2
2
|
|
|
3
3
|
import { Buffer } from 'buffer'
|
|
4
|
-
import {
|
|
4
|
+
import { Transform } from 'readable-stream'
|
|
5
5
|
import duplexify, { Duplexify } from 'duplexify'
|
|
6
6
|
import MqttClient, { IClientOptions } from '../client'
|
|
7
7
|
|
|
@@ -135,7 +135,7 @@ const buildStream: StreamBuilder = (client, opts) => {
|
|
|
135
135
|
|
|
136
136
|
bindEventHandler()
|
|
137
137
|
|
|
138
|
-
return stream
|
|
138
|
+
return stream
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
export default buildStream
|
|
@@ -14,8 +14,8 @@ export interface IMessageIdProvider {
|
|
|
14
14
|
/**
|
|
15
15
|
* Register the messageId. The messageId become occupied status.
|
|
16
16
|
* If the messageId has already been occupied, then return false.
|
|
17
|
-
* @param {
|
|
18
|
-
* @return {
|
|
17
|
+
* @param {number} num - The messageId to request use.
|
|
18
|
+
* @return {boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
19
19
|
*/
|
|
20
20
|
register(num: number): boolean
|
|
21
21
|
|
|
@@ -106,7 +106,7 @@ const handlePublish: PacketHandler = (client, packet: IPublishPacket, done) => {
|
|
|
106
106
|
error = null
|
|
107
107
|
}
|
|
108
108
|
if (error) {
|
|
109
|
-
return client.emit('error', error)
|
|
109
|
+
return client.emit('error', error as Error)
|
|
110
110
|
}
|
|
111
111
|
if (validReasonCodes.indexOf(code) === -1) {
|
|
112
112
|
return client.emit(
|
|
@@ -143,7 +143,7 @@ const handlePublish: PacketHandler = (client, packet: IPublishPacket, done) => {
|
|
|
143
143
|
error = null
|
|
144
144
|
}
|
|
145
145
|
if (error) {
|
|
146
|
-
return client.emit('error', error)
|
|
146
|
+
return client.emit('error', error as Error)
|
|
147
147
|
}
|
|
148
148
|
if (validReasonCodes.indexOf(code) === -1) {
|
|
149
149
|
return client.emit(
|
package/src/lib/shared.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Packet } from 'mqtt-packet'
|
|
2
|
+
import type internal from 'stream'
|
|
2
3
|
import type MqttClient from './client'
|
|
3
|
-
import {
|
|
4
|
-
import { Duplex, Writable } from 'readable-stream'
|
|
4
|
+
import type { IClientOptions } from './client'
|
|
5
5
|
|
|
6
6
|
export type DoneCallback = (error?: Error) => void
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ export type GenericCallback<T> = (error?: Error, result?: T) => void
|
|
|
9
9
|
|
|
10
10
|
export type VoidCallback = () => void
|
|
11
11
|
|
|
12
|
-
export type IStream = Duplex
|
|
12
|
+
export type IStream = internal.Duplex
|
|
13
13
|
|
|
14
14
|
export type StreamBuilder = (
|
|
15
15
|
client: MqttClient,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { NumberAllocator } from 'number-allocator'
|
|
2
|
+
import { IMessageIdProvider } from './default-message-id-provider'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* UniqueMessageAllocator constructor
|
|
5
6
|
* @constructor
|
|
6
7
|
*/
|
|
7
|
-
export default class UniqueMessageIdProvider {
|
|
8
|
+
export default class UniqueMessageIdProvider implements IMessageIdProvider {
|
|
8
9
|
private numberAllocator: NumberAllocator
|
|
9
10
|
|
|
10
11
|
private lastId: number
|
|
@@ -41,7 +42,7 @@ export default class UniqueMessageIdProvider {
|
|
|
41
42
|
* @return boolean
|
|
42
43
|
*/
|
|
43
44
|
register(messageId: number) {
|
|
44
|
-
return this.numberAllocator.use(messageId)
|
|
45
|
+
return this.numberAllocator.use(messageId) as boolean
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/**
|
package/src/mqtt.ts
CHANGED
|
@@ -9,11 +9,12 @@ import MqttClient from './lib/client'
|
|
|
9
9
|
import DefaultMessageIdProvider from './lib/default-message-id-provider'
|
|
10
10
|
import UniqueMessageIdProvider from './lib/unique-message-id-provider'
|
|
11
11
|
import Store, { IStore } from './lib/store'
|
|
12
|
-
import connect from './lib/connect'
|
|
12
|
+
import connect, { connectAsync } from './lib/connect'
|
|
13
13
|
|
|
14
14
|
export const Client = MqttClient
|
|
15
15
|
export {
|
|
16
16
|
connect,
|
|
17
|
+
connectAsync,
|
|
17
18
|
MqttClient,
|
|
18
19
|
Store,
|
|
19
20
|
DefaultMessageIdProvider,
|
|
@@ -21,3 +22,5 @@ export {
|
|
|
21
22
|
IStore,
|
|
22
23
|
}
|
|
23
24
|
export * from './lib/client'
|
|
25
|
+
export * from './lib/shared'
|
|
26
|
+
export { ReasonCodes } from './lib/handlers/ack'
|