@ray-js/wechat-mqtt 0.0.12 → 0.0.13-beta-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.
- package/package.json +5 -5
- package/src/lib/connect.d.ts +7 -1
- package/src/lib/constant.d.ts +53 -0
- package/src/lib/disconnect.d.ts +7 -0
- package/src/lib/factory.d.ts +2 -2
- package/src/lib/interface.d.ts +162 -0
- package/src/lib/packet.d.ts +57 -0
- package/src/lib/parse.d.ts +28 -0
- package/src/lib/ping.d.ts +5 -0
- package/src/lib/publish.d.ts +7 -0
- package/src/lib/subscribe.d.ts +17 -0
- package/src/new.d.ts +2 -0
- package/src/lib/contant.d.ts +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/wechat-mqtt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13-beta-1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"mqtt": "4.1.0",
|
|
21
21
|
"js-md5": "^0.7.3",
|
|
22
|
-
"@ray-js/wechat-tycrypto": "^0.0.
|
|
23
|
-
"@ray-js/wechat-event": "^0.0.
|
|
24
|
-
"@ray-js/wechat-request": "^0.0.
|
|
25
|
-
"@ray-js/wechat-helper": "^0.0.
|
|
22
|
+
"@ray-js/wechat-tycrypto": "^0.0.13-beta-1",
|
|
23
|
+
"@ray-js/wechat-event": "^0.0.13-beta-1",
|
|
24
|
+
"@ray-js/wechat-request": "^0.0.13-beta-1",
|
|
25
|
+
"@ray-js/wechat-helper": "^0.0.13-beta-1",
|
|
26
26
|
"js-base64": "^3.7.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {}
|
package/src/lib/connect.d.ts
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 控制报文类型
|
|
3
|
+
*/
|
|
4
|
+
export declare enum PacketType {
|
|
5
|
+
Reserved = 0,
|
|
6
|
+
CONNECT = 1,
|
|
7
|
+
CONNACK = 2,
|
|
8
|
+
PUBLISH = 3,
|
|
9
|
+
PUBACK = 4,
|
|
10
|
+
PUBREC = 5,
|
|
11
|
+
PUBREL = 6,
|
|
12
|
+
PUBCOMP = 7,
|
|
13
|
+
SUBSCRIBE = 8,
|
|
14
|
+
SUBACK = 9,
|
|
15
|
+
UNSUBSCRIBE = 10,
|
|
16
|
+
UNSUBACK = 11,
|
|
17
|
+
PINGREQ = 12,
|
|
18
|
+
PINGRESP = 13,
|
|
19
|
+
DISCONNECT = 14,
|
|
20
|
+
AUTH = 15
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 属性标记
|
|
24
|
+
*/
|
|
25
|
+
export declare enum PropertySign {
|
|
26
|
+
sessionExpiryInterval = 17,
|
|
27
|
+
receiveMaximum = 33,
|
|
28
|
+
maximumQoS = 36,
|
|
29
|
+
retainAvailable = 37,
|
|
30
|
+
maximumPacketSize = 39,
|
|
31
|
+
topicAliasMaximum = 34,
|
|
32
|
+
topicAlias = 35,
|
|
33
|
+
requestResponseInformation = 25,
|
|
34
|
+
requestProblemInformation = 23,
|
|
35
|
+
userProperties = 38,
|
|
36
|
+
authenticationMethod = 21,
|
|
37
|
+
authenticationData = 22,
|
|
38
|
+
willDelayInterval = 24,
|
|
39
|
+
payloadFormatIndicator = 1,
|
|
40
|
+
messageExpiryInterval = 2,
|
|
41
|
+
contentType = 3,
|
|
42
|
+
responseTopic = 8,
|
|
43
|
+
correlationData = 9,
|
|
44
|
+
subscriptionIdentifier = 11,
|
|
45
|
+
reasonString = 31,
|
|
46
|
+
assignedClientIdentifier = 18,
|
|
47
|
+
wildcardSubscriptionAvailable = 40,
|
|
48
|
+
subscriptionIdentifiersAvailable = 41,
|
|
49
|
+
sharedSubscriptionAvailable = 42,
|
|
50
|
+
serverKeepAlive = 19,
|
|
51
|
+
responseInformation = 26,
|
|
52
|
+
serverReference = 28
|
|
53
|
+
}
|
package/src/lib/factory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Adapter } from "./interface";
|
|
1
|
+
import { Adapter, Client, Options } from "./interface";
|
|
2
2
|
declare type Judge = () => boolean;
|
|
3
3
|
declare type Connect = (url: string) => Adapter;
|
|
4
4
|
/**
|
|
@@ -13,5 +13,5 @@ export declare const addAdapter: (judge: Judge, creater: Connect, priority?: boo
|
|
|
13
13
|
* 创建适配器
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const createClient: (options: Options) => Promise<Client>;
|
|
17
17
|
export {};
|
package/src/lib/interface.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
export interface Adapter {
|
|
2
3
|
/**
|
|
3
4
|
* 关闭连接
|
|
@@ -28,3 +29,164 @@ export interface Adapter {
|
|
|
28
29
|
*/
|
|
29
30
|
onError(cb: (ev: any) => void): void;
|
|
30
31
|
}
|
|
32
|
+
export interface Client extends Adapter {
|
|
33
|
+
protocolVersion: number;
|
|
34
|
+
isClose(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 接收到消息监听
|
|
37
|
+
*/
|
|
38
|
+
onMessage(cb: (data: Uint8Array) => void): void;
|
|
39
|
+
offMessage(cb: (data: Uint8Array) => void): void;
|
|
40
|
+
offClose(cb: (ev: any) => void): void;
|
|
41
|
+
offError(cb: (ev: any) => void): void;
|
|
42
|
+
}
|
|
43
|
+
export declare type QoS = 0 | 1 | 2;
|
|
44
|
+
export declare type UserProperties = Record<string, string | string[]>;
|
|
45
|
+
export interface Options {
|
|
46
|
+
/**
|
|
47
|
+
* mqtt 连接地址
|
|
48
|
+
*/
|
|
49
|
+
url: string;
|
|
50
|
+
/**
|
|
51
|
+
* 账号
|
|
52
|
+
*/
|
|
53
|
+
username?: string;
|
|
54
|
+
/**
|
|
55
|
+
* 账号密码
|
|
56
|
+
*/
|
|
57
|
+
password?: string;
|
|
58
|
+
/**
|
|
59
|
+
* 客户端id
|
|
60
|
+
*/
|
|
61
|
+
clientId: string;
|
|
62
|
+
/**
|
|
63
|
+
* 协议版本
|
|
64
|
+
*/
|
|
65
|
+
protocolVersion?: number;
|
|
66
|
+
/**
|
|
67
|
+
* 心跳间隔时间
|
|
68
|
+
*/
|
|
69
|
+
keepalive?: number;
|
|
70
|
+
/**
|
|
71
|
+
* 待订阅主题
|
|
72
|
+
*/
|
|
73
|
+
subscribeTopics?: string | string[];
|
|
74
|
+
/**
|
|
75
|
+
* 是否为新会话
|
|
76
|
+
*/
|
|
77
|
+
clean?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 遗嘱消息配置
|
|
80
|
+
*/
|
|
81
|
+
will?: {
|
|
82
|
+
/**
|
|
83
|
+
* 遗嘱主题
|
|
84
|
+
*/
|
|
85
|
+
topic: string;
|
|
86
|
+
/**
|
|
87
|
+
* 遗嘱数据
|
|
88
|
+
*/
|
|
89
|
+
payload: Uint8Array | string;
|
|
90
|
+
/**
|
|
91
|
+
* the QoS
|
|
92
|
+
*/
|
|
93
|
+
qos: QoS;
|
|
94
|
+
/**
|
|
95
|
+
* the retain flag
|
|
96
|
+
*/
|
|
97
|
+
retain: boolean;
|
|
98
|
+
properties?: {
|
|
99
|
+
willDelayInterval?: number;
|
|
100
|
+
payloadFormatIndicator?: boolean;
|
|
101
|
+
sessionExpiryInterval?: number;
|
|
102
|
+
contentType?: string;
|
|
103
|
+
responseTopic?: string;
|
|
104
|
+
correlationData?: Buffer;
|
|
105
|
+
userProperties?: UserProperties;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* 协议版本 5 properties
|
|
110
|
+
*/
|
|
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
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
* 连接超时时间
|
|
125
|
+
* 单位秒,默认 10 秒
|
|
126
|
+
*/
|
|
127
|
+
connectTimeout: number;
|
|
128
|
+
}
|
|
129
|
+
export interface Message {
|
|
130
|
+
/**
|
|
131
|
+
* 消息标识
|
|
132
|
+
* qos > 0时必填
|
|
133
|
+
*/
|
|
134
|
+
id?: number;
|
|
135
|
+
dup: boolean;
|
|
136
|
+
qos: 0 | 1 | 2;
|
|
137
|
+
/**
|
|
138
|
+
* 主题名
|
|
139
|
+
*/
|
|
140
|
+
topicName: string;
|
|
141
|
+
/**
|
|
142
|
+
* 协议5版本需要此值
|
|
143
|
+
*/
|
|
144
|
+
properties?: {
|
|
145
|
+
payloadFormatIndicator?: boolean;
|
|
146
|
+
messageExpiryInterval?: number;
|
|
147
|
+
topicAlias?: number;
|
|
148
|
+
responseTopic?: string;
|
|
149
|
+
correlationData?: string;
|
|
150
|
+
userProperties?: UserProperties;
|
|
151
|
+
subscriptionIdentifier?: number;
|
|
152
|
+
contentType?: string;
|
|
153
|
+
};
|
|
154
|
+
payload: Uint8Array;
|
|
155
|
+
}
|
|
156
|
+
export interface SubscribeOptions {
|
|
157
|
+
id: number;
|
|
158
|
+
properties?: {
|
|
159
|
+
subscriptionIdentifier: number;
|
|
160
|
+
userProperties?: UserProperties;
|
|
161
|
+
};
|
|
162
|
+
payload: {
|
|
163
|
+
topic: string;
|
|
164
|
+
qos: number;
|
|
165
|
+
nl?: 0 | 1;
|
|
166
|
+
rap?: 0 | 1;
|
|
167
|
+
rh?: number;
|
|
168
|
+
}[];
|
|
169
|
+
}
|
|
170
|
+
export interface UnSubscribeOptions {
|
|
171
|
+
id: number;
|
|
172
|
+
properties?: {
|
|
173
|
+
subscriptionIdentifier: number;
|
|
174
|
+
userProperties?: UserProperties;
|
|
175
|
+
};
|
|
176
|
+
topics: string[];
|
|
177
|
+
}
|
|
178
|
+
export interface DisconnectOptions {
|
|
179
|
+
/**
|
|
180
|
+
* 原因码,默认为0
|
|
181
|
+
*/
|
|
182
|
+
reasonCode?: number;
|
|
183
|
+
/**
|
|
184
|
+
* 属性,协议版本5支持
|
|
185
|
+
*/
|
|
186
|
+
properties?: {
|
|
187
|
+
sessionExpiryInterval?: number;
|
|
188
|
+
reasonString?: string;
|
|
189
|
+
userProperties?: UserProperties;
|
|
190
|
+
serverReference?: string;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PropertySign } from "./constant";
|
|
2
|
+
declare type WriteData = (data: string | number | number[] | Uint8Array) => void;
|
|
3
|
+
/**
|
|
4
|
+
* 创建数据包
|
|
5
|
+
* @param cmd 控制报文
|
|
6
|
+
* @param fixHeader 固定报文中,4个低字节位数值
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const createPacket: (cmd: number, fixHeader?: number) => {
|
|
10
|
+
header: (data: number | number[] | Uint8Array, needLen?: boolean, isVariable?: boolean) => void;
|
|
11
|
+
payload: (data: string | number | number[] | Uint8Array, needLen?: boolean, isVariable?: boolean) => void;
|
|
12
|
+
cleanCache(): void;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param data
|
|
16
|
+
*/
|
|
17
|
+
cache: (data: string | number | number[] | Uint8Array, needLen?: boolean, isVariable?: boolean) => void;
|
|
18
|
+
putHeader(): void;
|
|
19
|
+
putPayload(): void;
|
|
20
|
+
getCache(): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* 获取 packet 数据
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getPacket: () => Uint8Array;
|
|
26
|
+
};
|
|
27
|
+
export declare const writeString: (sign: PropertySign) => (v: string, write: WriteData) => void;
|
|
28
|
+
export declare const writePair: (sign: PropertySign) => (properies: Record<string, string | string[]>, write: WriteData) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 属性值类型
|
|
31
|
+
*/
|
|
32
|
+
export declare const writeProperty: {
|
|
33
|
+
sessionExpiryInterval: (value: number, write: WriteData) => void;
|
|
34
|
+
receiveMaximum: (value: number, write: WriteData) => void;
|
|
35
|
+
maximumPacketSize: (value: number, write: WriteData) => void;
|
|
36
|
+
topicAliasMaximum: (value: number, write: WriteData) => void;
|
|
37
|
+
topicAlias: (value: number, write: WriteData) => void;
|
|
38
|
+
requestResponseInformation: (value: boolean, write: WriteData) => void;
|
|
39
|
+
requestProblemInformation: (value: boolean, write: WriteData) => void;
|
|
40
|
+
userProperties: (properies: Record<string, string | string[]>, write: WriteData) => void;
|
|
41
|
+
authenticationMethod: (v: string, write: WriteData) => void;
|
|
42
|
+
authenticationData: (value: Uint8Array, write: WriteData) => void;
|
|
43
|
+
willDelayInterval: (value: number, write: WriteData) => void;
|
|
44
|
+
payloadFormatIndicator: (value: boolean, write: WriteData) => void;
|
|
45
|
+
messageExpiryInterval: (value: number, write: WriteData) => void;
|
|
46
|
+
contentType: (v: string, write: WriteData) => void;
|
|
47
|
+
responseTopic: (v: string, write: WriteData) => void;
|
|
48
|
+
correlationData: (value: Uint8Array, write: WriteData) => void;
|
|
49
|
+
subscriptionIdentifier: (value: number, write: WriteData) => void;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 转化 properties 的数据
|
|
53
|
+
* @param properies
|
|
54
|
+
* @param write
|
|
55
|
+
*/
|
|
56
|
+
export declare const packetProperties: (properies: Record<string, any>, write: WriteData) => void;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 属性值类型
|
|
3
|
+
*/
|
|
4
|
+
export declare const parseProperty: {
|
|
5
|
+
sessionExpiryInterval: (data: Uint8Array, offset: number) => number[];
|
|
6
|
+
receiveMaximum: (data: Uint8Array, offset: number) => number[];
|
|
7
|
+
maximumPacketSize: (data: Uint8Array, offset: number) => number[];
|
|
8
|
+
topicAliasMaximum: (data: Uint8Array, offset: number) => number[];
|
|
9
|
+
topicAlias: (data: Uint8Array, offset: number) => number[];
|
|
10
|
+
requestResponseInformation: (data: Uint8Array, offset: number) => (number | boolean)[];
|
|
11
|
+
requestProblemInformation: (data: Uint8Array, offset: number) => (number | boolean)[];
|
|
12
|
+
userProperties: (data: Uint8Array, offset: number) => [Array<string>, number];
|
|
13
|
+
authenticationMethod: (data: Uint8Array, offset: number) => [string, number];
|
|
14
|
+
authenticationData: (data: Uint8Array, offset: number) => [Uint8Array, number];
|
|
15
|
+
willDelayInterval: (data: Uint8Array, offset: number) => number[];
|
|
16
|
+
payloadFormatIndicator: (data: Uint8Array, offset: number) => (number | boolean)[];
|
|
17
|
+
messageExpiryInterval: (data: Uint8Array, offset: number) => number[];
|
|
18
|
+
contentType: (data: Uint8Array, offset: number) => [string, number];
|
|
19
|
+
responseTopic: (data: Uint8Array, offset: number) => [string, number];
|
|
20
|
+
correlationData: (data: Uint8Array, offset: number) => [Uint8Array, number];
|
|
21
|
+
subscriptionIdentifier: (data: Uint8Array, offset: number) => number[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 解析 properties
|
|
25
|
+
* @param data
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare const parseProperties: (data: Uint8Array) => Record<string, any>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Client, SubscribeOptions, UnSubscribeOptions } from "./interface";
|
|
2
|
+
/**
|
|
3
|
+
* 订阅消息
|
|
4
|
+
* @param client
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare const subscribe: (client: Client, subscribe: SubscribeOptions) => Promise<{
|
|
8
|
+
qos: number;
|
|
9
|
+
properties?: any;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* 取消订阅
|
|
13
|
+
*/
|
|
14
|
+
export declare const unsubscribe: (client: Client, subscribe: UnSubscribeOptions) => Promise<{
|
|
15
|
+
qos: number;
|
|
16
|
+
properties?: any;
|
|
17
|
+
}>;
|
package/src/new.d.ts
ADDED
package/src/lib/contant.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 控制报文类型
|
|
3
|
-
*/
|
|
4
|
-
export declare enum PacketType {
|
|
5
|
-
Reserved = 0,
|
|
6
|
-
CONNECT = 1,
|
|
7
|
-
CONNACK = 2,
|
|
8
|
-
PUBLISH = 3,
|
|
9
|
-
PUBACK = 4,
|
|
10
|
-
PUBREC = 5,
|
|
11
|
-
PUBREL = 6,
|
|
12
|
-
PUBCOMP = 7,
|
|
13
|
-
SUBSCRIBE = 8,
|
|
14
|
-
SUBACK = 9,
|
|
15
|
-
UNSUBSCRIBE = 10,
|
|
16
|
-
UNSUBACK = 11,
|
|
17
|
-
PINGREQ = 12,
|
|
18
|
-
PINGRESP = 13,
|
|
19
|
-
DISCONNECT = 14,
|
|
20
|
-
AUTH = 15
|
|
21
|
-
}
|