@cnhongwei/react-native-mqtt 0.0.0-stage → 0.1.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/LICENSE +20 -0
- package/README.md +169 -2
- package/README.zh-CN.md +100 -0
- package/ReactNativeMqtt.podspec +28 -0
- package/THIRD_PARTY_NOTICES.md +17 -0
- package/android/build.gradle +70 -0
- package/android/consumer-rules.pro +10 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/MqttOptionsParser.kt +176 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/MqttSession.kt +1006 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/PahoLogger.java +44 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/PahoMqttTransport.kt +399 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/ReactNativeMqttModule.kt +619 -0
- package/android/src/main/java/com/cnhongwei/reactnativemqtt/ReactNativeMqttPackage.kt +31 -0
- package/ios/ReactNativeMqtt.h +15 -0
- package/ios/ReactNativeMqtt.mm +1184 -0
- package/ios/ReactNativeMqttCocoaTransport.swift +782 -0
- package/ios/ReactNativeMqttConnAckProbe.swift +87 -0
- package/ios/ReactNativeMqttSession.swift +420 -0
- package/lib/module/NativeReactNativeMqtt.js +5 -0
- package/lib/module/NativeReactNativeMqtt.js.map +1 -0
- package/lib/module/client.js +555 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/errors.js +20 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/helpers.js +116 -0
- package/lib/module/helpers.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/validation.js +306 -0
- package/lib/module/validation.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeReactNativeMqtt.d.ts +154 -0
- package/lib/typescript/src/NativeReactNativeMqtt.d.ts.map +1 -0
- package/lib/typescript/src/client.d.ts +3 -0
- package/lib/typescript/src/client.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +18 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/helpers.d.ts +5 -0
- package/lib/typescript/src/helpers.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +161 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/validation.d.ts +13 -0
- package/lib/typescript/src/validation.d.ts.map +1 -0
- package/package.json +188 -4
- package/react-native.config.js +1 -0
- package/src/NativeReactNativeMqtt.ts +173 -0
- package/src/client.ts +859 -0
- package/src/errors.ts +51 -0
- package/src/helpers.ts +151 -0
- package/src/index.ts +30 -0
- package/src/types.ts +184 -0
- package/src/validation.ts +735 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type MqttErrorCode =
|
|
2
|
+
| 'ERR_INVALID_OPTIONS'
|
|
3
|
+
| 'ERR_INVALID_PAYLOAD'
|
|
4
|
+
| 'ERR_NATIVE_UNAVAILABLE'
|
|
5
|
+
| 'ERR_CONTRACT_MISMATCH'
|
|
6
|
+
| 'ERR_NOT_CONNECTED'
|
|
7
|
+
| 'ERR_DISPOSED'
|
|
8
|
+
| 'ERR_OPERATION_IN_PROGRESS'
|
|
9
|
+
| 'ERR_OPERATION_SUPERSEDED'
|
|
10
|
+
| 'ERR_CONNECT_TIMEOUT'
|
|
11
|
+
| 'ERR_OPERATION_TIMEOUT'
|
|
12
|
+
| 'ERR_CONNECTION_REFUSED'
|
|
13
|
+
| 'ERR_CONNECTION_LOST'
|
|
14
|
+
| 'ERR_SUBSCRIPTION_CONFLICT'
|
|
15
|
+
| 'ERR_SUBSCRIBE_FAILED'
|
|
16
|
+
| 'ERR_UNSUBSCRIBE_FAILED'
|
|
17
|
+
| 'ERR_PUBLISH_FAILED'
|
|
18
|
+
| 'ERR_TLS'
|
|
19
|
+
| 'ERR_CLEANUP_FAILED'
|
|
20
|
+
| 'ERR_UNKNOWN';
|
|
21
|
+
export class MqttError extends Error {
|
|
22
|
+
readonly code: MqttErrorCode;
|
|
23
|
+
readonly operation?: string;
|
|
24
|
+
readonly generation?: number;
|
|
25
|
+
readonly reasonCode?: number;
|
|
26
|
+
readonly reasonString?: string;
|
|
27
|
+
readonly outcome?: 'not-sent' | 'rejected' | 'unknown';
|
|
28
|
+
constructor(
|
|
29
|
+
code: MqttErrorCode,
|
|
30
|
+
message: string,
|
|
31
|
+
details: {
|
|
32
|
+
operation?: string;
|
|
33
|
+
generation?: number;
|
|
34
|
+
reasonCode?: number;
|
|
35
|
+
reasonString?: string;
|
|
36
|
+
outcome?: 'not-sent' | 'rejected' | 'unknown';
|
|
37
|
+
} = {}
|
|
38
|
+
) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = 'MqttError';
|
|
41
|
+
this.code = code;
|
|
42
|
+
this.operation = details.operation;
|
|
43
|
+
this.generation = details.generation;
|
|
44
|
+
this.reasonCode = details.reasonCode;
|
|
45
|
+
this.reasonString = details.reasonString;
|
|
46
|
+
this.outcome = details.outcome;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function invalidOptions(message: string): MqttError {
|
|
50
|
+
return new MqttError('ERR_INVALID_OPTIONS', message, { outcome: 'not-sent' });
|
|
51
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { MqttError } from './errors';
|
|
2
|
+
type TextEncoderLike = { encode(input: string): Uint8Array };
|
|
3
|
+
type TextDecoderLike = { decode(input: Uint8Array): string };
|
|
4
|
+
const textEncoder = (): TextEncoderLike | undefined => {
|
|
5
|
+
const ctor = (
|
|
6
|
+
globalThis as unknown as { TextEncoder?: new () => TextEncoderLike }
|
|
7
|
+
).TextEncoder;
|
|
8
|
+
return ctor === undefined ? undefined : new ctor();
|
|
9
|
+
};
|
|
10
|
+
const textDecoder = (): TextDecoderLike | undefined => {
|
|
11
|
+
const ctor = (
|
|
12
|
+
globalThis as unknown as {
|
|
13
|
+
TextDecoder?: new (
|
|
14
|
+
label?: string,
|
|
15
|
+
options?: { fatal?: boolean }
|
|
16
|
+
) => TextDecoderLike;
|
|
17
|
+
}
|
|
18
|
+
).TextDecoder;
|
|
19
|
+
return ctor === undefined ? undefined : new ctor('utf-8', { fatal: true });
|
|
20
|
+
};
|
|
21
|
+
function invalidPayload(message: string): MqttError {
|
|
22
|
+
return new MqttError('ERR_INVALID_PAYLOAD', message, { outcome: 'not-sent' });
|
|
23
|
+
}
|
|
24
|
+
export function encodeUtf8(text: string): Uint8Array {
|
|
25
|
+
const encoder = textEncoder();
|
|
26
|
+
if (encoder === undefined) throw invalidPayload('TextEncoder is unavailable');
|
|
27
|
+
return encoder.encode(text);
|
|
28
|
+
}
|
|
29
|
+
export function decodeUtf8(bytes: Uint8Array): string {
|
|
30
|
+
const decoder = textDecoder();
|
|
31
|
+
if (decoder !== undefined) {
|
|
32
|
+
try {
|
|
33
|
+
return decoder.decode(bytes);
|
|
34
|
+
} catch {
|
|
35
|
+
throw invalidPayload('Payload is not valid UTF-8');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Hermes/RN versions without TextDecoder still need a deterministic,
|
|
40
|
+
// strict decoder for incoming MQTT payloads.
|
|
41
|
+
let result = '';
|
|
42
|
+
const codePoints: number[] = [];
|
|
43
|
+
const flush = (): void => {
|
|
44
|
+
if (codePoints.length === 0) return;
|
|
45
|
+
result += String.fromCodePoint(...codePoints);
|
|
46
|
+
codePoints.length = 0;
|
|
47
|
+
};
|
|
48
|
+
const continuation = (index: number): number => {
|
|
49
|
+
const value = bytes[index];
|
|
50
|
+
if (value === undefined || (value & 0xc0) !== 0x80)
|
|
51
|
+
throw invalidPayload('Payload is not valid UTF-8');
|
|
52
|
+
return value & 0x3f;
|
|
53
|
+
};
|
|
54
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
55
|
+
const first = bytes[index];
|
|
56
|
+
if (first === undefined) throw invalidPayload('Payload is not valid UTF-8');
|
|
57
|
+
if (first <= 0x7f) {
|
|
58
|
+
codePoints.push(first);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let codePoint: number;
|
|
62
|
+
if (first >= 0xc2 && first <= 0xdf) {
|
|
63
|
+
codePoint = ((first & 0x1f) << 6) | continuation(index + 1);
|
|
64
|
+
index += 1;
|
|
65
|
+
} else if (first >= 0xe0 && first <= 0xef) {
|
|
66
|
+
const second = bytes[index + 1];
|
|
67
|
+
if (
|
|
68
|
+
second === undefined ||
|
|
69
|
+
(second & 0xc0) !== 0x80 ||
|
|
70
|
+
(first === 0xe0 && second < 0xa0) ||
|
|
71
|
+
(first === 0xed && second > 0x9f)
|
|
72
|
+
)
|
|
73
|
+
throw invalidPayload('Payload is not valid UTF-8');
|
|
74
|
+
codePoint =
|
|
75
|
+
((first & 0x0f) << 12) |
|
|
76
|
+
((second & 0x3f) << 6) |
|
|
77
|
+
continuation(index + 2);
|
|
78
|
+
index += 2;
|
|
79
|
+
} else if (first >= 0xf0 && first <= 0xf4) {
|
|
80
|
+
const second = bytes[index + 1];
|
|
81
|
+
if (
|
|
82
|
+
second === undefined ||
|
|
83
|
+
(second & 0xc0) !== 0x80 ||
|
|
84
|
+
(first === 0xf0 && second < 0x90) ||
|
|
85
|
+
(first === 0xf4 && second > 0x8f)
|
|
86
|
+
)
|
|
87
|
+
throw invalidPayload('Payload is not valid UTF-8');
|
|
88
|
+
codePoint =
|
|
89
|
+
((first & 0x07) << 18) |
|
|
90
|
+
((second & 0x3f) << 12) |
|
|
91
|
+
(continuation(index + 2) << 6) |
|
|
92
|
+
continuation(index + 3);
|
|
93
|
+
index += 3;
|
|
94
|
+
} else {
|
|
95
|
+
throw invalidPayload('Payload is not valid UTF-8');
|
|
96
|
+
}
|
|
97
|
+
codePoints.push(codePoint);
|
|
98
|
+
if (codePoints.length >= 0x4000) flush();
|
|
99
|
+
}
|
|
100
|
+
flush();
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
const base64Alphabet =
|
|
104
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
105
|
+
export function encodeBase64(bytes: Uint8Array): string {
|
|
106
|
+
let result = '';
|
|
107
|
+
for (let index = 0; index < bytes.length; index += 3) {
|
|
108
|
+
const a = bytes[index] ?? 0;
|
|
109
|
+
const b = bytes[index + 1];
|
|
110
|
+
const c = bytes[index + 2];
|
|
111
|
+
result += base64Alphabet[a >> 2];
|
|
112
|
+
result += base64Alphabet[((a & 3) << 4) | ((b ?? 0) >> 4)];
|
|
113
|
+
result +=
|
|
114
|
+
b === undefined ? '=' : base64Alphabet[((b & 15) << 2) | ((c ?? 0) >> 6)];
|
|
115
|
+
result += c === undefined ? '=' : base64Alphabet[c & 63];
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
export function decodeBase64(text: string): Uint8Array {
|
|
120
|
+
if (text.length % 4 !== 0 || /[^A-Za-z0-9+/=]/.test(text))
|
|
121
|
+
throw invalidPayload('Base64 must use RFC 4648 alphabet and padding');
|
|
122
|
+
const padding = text.endsWith('==') ? 2 : text.endsWith('=') ? 1 : 0;
|
|
123
|
+
const firstPadding = text.indexOf('=');
|
|
124
|
+
if (firstPadding >= 0 && firstPadding < text.length - padding)
|
|
125
|
+
throw invalidPayload('Base64 padding is invalid');
|
|
126
|
+
const output = new Uint8Array((text.length / 4) * 3 - padding);
|
|
127
|
+
let outputIndex = 0;
|
|
128
|
+
for (let index = 0; index < text.length; index += 4) {
|
|
129
|
+
const chars = text.slice(index, index + 4);
|
|
130
|
+
const values = chars
|
|
131
|
+
.split('')
|
|
132
|
+
.map((char) => (char === '=' ? 0 : base64Alphabet.indexOf(char)));
|
|
133
|
+
const v0 = values[0] ?? -1;
|
|
134
|
+
const v1 = values[1] ?? -1;
|
|
135
|
+
const v2 = values[2] ?? -1;
|
|
136
|
+
const v3 = values[3] ?? -1;
|
|
137
|
+
if ([v0, v1, v2, v3].some((value) => value < 0))
|
|
138
|
+
throw invalidPayload('Base64 contains an invalid character');
|
|
139
|
+
if (chars[2] === '=' && (v1 & 15) !== 0)
|
|
140
|
+
throw invalidPayload('Base64 has non-zero trailing bits');
|
|
141
|
+
if (chars[3] === '=' && chars[2] !== '=' && (v2 & 3) !== 0)
|
|
142
|
+
throw invalidPayload('Base64 has non-zero trailing bits');
|
|
143
|
+
const combined = (v0 << 18) | (v1 << 12) | (v2 << 6) | v3;
|
|
144
|
+
if (outputIndex < output.length)
|
|
145
|
+
output[outputIndex++] = (combined >> 16) & 255;
|
|
146
|
+
if (outputIndex < output.length)
|
|
147
|
+
output[outputIndex++] = (combined >> 8) & 255;
|
|
148
|
+
if (outputIndex < output.length) output[outputIndex++] = combined & 255;
|
|
149
|
+
}
|
|
150
|
+
return output;
|
|
151
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type { Spec as NativeReactNativeMqttSpec } from './NativeReactNativeMqtt';
|
|
2
|
+
export { MqttError } from './errors';
|
|
3
|
+
export type { MqttErrorCode } from './errors';
|
|
4
|
+
export { createMqttClient } from './client';
|
|
5
|
+
export { decodeBase64, decodeUtf8, encodeBase64, encodeUtf8 } from './helpers';
|
|
6
|
+
export type {
|
|
7
|
+
ConnAck,
|
|
8
|
+
ConnectionState,
|
|
9
|
+
DeliveryOptions,
|
|
10
|
+
Diagnostic,
|
|
11
|
+
Listener,
|
|
12
|
+
Message,
|
|
13
|
+
Mqtt4Options,
|
|
14
|
+
Mqtt5Options,
|
|
15
|
+
MqttClient,
|
|
16
|
+
MqttOptions,
|
|
17
|
+
PublishOptions,
|
|
18
|
+
QoS,
|
|
19
|
+
ReconnectOptions,
|
|
20
|
+
SessionSnapshot,
|
|
21
|
+
SubscribeOptions,
|
|
22
|
+
Subscription,
|
|
23
|
+
TlsOptions,
|
|
24
|
+
Transport,
|
|
25
|
+
UserProperty,
|
|
26
|
+
WillOptions,
|
|
27
|
+
} from './types';
|
|
28
|
+
|
|
29
|
+
export const packageName = '@cnhongwei/react-native-mqtt' as const;
|
|
30
|
+
export const packageVersion = '0.1.0' as const;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export type QoS = 0 | 1 | 2;
|
|
2
|
+
export type Transport = 'tcp' | 'tls' | 'ws' | 'wss';
|
|
3
|
+
export type ConnectionState =
|
|
4
|
+
| 'idle'
|
|
5
|
+
| 'connecting'
|
|
6
|
+
| 'connected'
|
|
7
|
+
| 'reconnecting'
|
|
8
|
+
| 'disconnecting'
|
|
9
|
+
| 'disconnected'
|
|
10
|
+
| 'closed';
|
|
11
|
+
export type UserProperty = { key: string; value: string };
|
|
12
|
+
export type TlsOptions = {
|
|
13
|
+
caBase64?: string;
|
|
14
|
+
p12Base64?: string;
|
|
15
|
+
p12Password?: string;
|
|
16
|
+
insecure?: boolean;
|
|
17
|
+
allowInvalidHostnameForTesting?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type ReconnectOptions = {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
initialDelayMs?: number;
|
|
22
|
+
maxDelayMs?: number;
|
|
23
|
+
jitterRatio?: number;
|
|
24
|
+
};
|
|
25
|
+
export type DeliveryOptions = {
|
|
26
|
+
maxQueuedMessages?: number;
|
|
27
|
+
maxQueuedBytes?: number;
|
|
28
|
+
maxMessageBytes?: number;
|
|
29
|
+
batchMaxMessages?: number;
|
|
30
|
+
batchMaxBytes?: number;
|
|
31
|
+
batchAckTimeoutMs?: number;
|
|
32
|
+
overflowPolicy?: 'disconnect' | 'drop-newest';
|
|
33
|
+
};
|
|
34
|
+
export type WillOptions = {
|
|
35
|
+
topic: string;
|
|
36
|
+
payloadBase64: string;
|
|
37
|
+
qos?: QoS;
|
|
38
|
+
retained?: boolean;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CommonMqttOptions = {
|
|
42
|
+
host: string;
|
|
43
|
+
port: number;
|
|
44
|
+
transport?: Transport;
|
|
45
|
+
path?: string;
|
|
46
|
+
clientId?: string;
|
|
47
|
+
username?: string;
|
|
48
|
+
password?: string;
|
|
49
|
+
keepAliveSeconds?: number;
|
|
50
|
+
connectTimeoutMs?: number;
|
|
51
|
+
operationTimeoutMs?: number;
|
|
52
|
+
disconnectTimeoutMs?: number;
|
|
53
|
+
reconnect?: ReconnectOptions;
|
|
54
|
+
tls?: TlsOptions;
|
|
55
|
+
will?: WillOptions;
|
|
56
|
+
delivery?: DeliveryOptions;
|
|
57
|
+
};
|
|
58
|
+
export type Mqtt4Options = CommonMqttOptions & {
|
|
59
|
+
/** MQTT 3.1.1 (default). MQTT 3.1 / protocol level 3 is unsupported. */
|
|
60
|
+
protocolVersion?: 4;
|
|
61
|
+
cleanSession?: boolean;
|
|
62
|
+
cleanStart?: never;
|
|
63
|
+
sessionExpiryIntervalSeconds?: never;
|
|
64
|
+
receiveMaximum?: never;
|
|
65
|
+
userProperties?: never;
|
|
66
|
+
};
|
|
67
|
+
export type Mqtt5Options = CommonMqttOptions & {
|
|
68
|
+
/** MQTT 5.0. Only protocol levels 4 and 5 are supported on Android/iOS. */
|
|
69
|
+
protocolVersion: 5;
|
|
70
|
+
cleanSession?: never;
|
|
71
|
+
cleanStart?: boolean;
|
|
72
|
+
sessionExpiryIntervalSeconds?: number;
|
|
73
|
+
receiveMaximum?: number;
|
|
74
|
+
userProperties?: UserProperty[];
|
|
75
|
+
};
|
|
76
|
+
export type MqttOptions = Mqtt4Options | Mqtt5Options;
|
|
77
|
+
|
|
78
|
+
export type SubscribeOptions = {
|
|
79
|
+
qos?: QoS;
|
|
80
|
+
noLocal?: boolean;
|
|
81
|
+
retainAsPublished?: boolean;
|
|
82
|
+
retainHandling?: 0 | 1 | 2;
|
|
83
|
+
};
|
|
84
|
+
export type PublishOptions = {
|
|
85
|
+
qos?: QoS;
|
|
86
|
+
retained?: boolean;
|
|
87
|
+
userProperties?: UserProperty[];
|
|
88
|
+
contentType?: string;
|
|
89
|
+
responseTopic?: string;
|
|
90
|
+
correlationDataBase64?: string;
|
|
91
|
+
messageExpiryIntervalSeconds?: number;
|
|
92
|
+
payloadFormatIndicator?: 0 | 1;
|
|
93
|
+
};
|
|
94
|
+
export type ConnAck = {
|
|
95
|
+
sessionPresent: boolean;
|
|
96
|
+
assignedClientId?: string;
|
|
97
|
+
reasonCode?: number;
|
|
98
|
+
reasonString?: string;
|
|
99
|
+
userProperties?: UserProperty[];
|
|
100
|
+
};
|
|
101
|
+
export type SessionSnapshot = {
|
|
102
|
+
instanceId: string;
|
|
103
|
+
revision: number;
|
|
104
|
+
generation: number;
|
|
105
|
+
state: ConnectionState;
|
|
106
|
+
lastConnAck: ConnAck | null;
|
|
107
|
+
subscriptionsRevision: number;
|
|
108
|
+
subscriptionsStatus: 'pending' | 'ready' | 'failed';
|
|
109
|
+
deliveryStatus: 'active' | 'stalled' | 'closed';
|
|
110
|
+
};
|
|
111
|
+
export type Message = {
|
|
112
|
+
instanceId: string;
|
|
113
|
+
generation: number;
|
|
114
|
+
topic: string;
|
|
115
|
+
bytes: Uint8Array;
|
|
116
|
+
qos: QoS;
|
|
117
|
+
retained: boolean;
|
|
118
|
+
userProperties?: UserProperty[];
|
|
119
|
+
contentType?: string;
|
|
120
|
+
responseTopic?: string;
|
|
121
|
+
correlationData?: Uint8Array;
|
|
122
|
+
messageExpiryIntervalSeconds?: number;
|
|
123
|
+
payloadFormatIndicator?: 0 | 1;
|
|
124
|
+
};
|
|
125
|
+
export type Diagnostic = {
|
|
126
|
+
instanceId: string;
|
|
127
|
+
generation: number;
|
|
128
|
+
code:
|
|
129
|
+
| 'SUBSCRIPTION_SYNC_FAILED'
|
|
130
|
+
| 'DELIVERY_STALLED'
|
|
131
|
+
| 'QUEUE_OVERFLOW'
|
|
132
|
+
| 'LISTENER_ERROR'
|
|
133
|
+
| 'INSECURE_TLS';
|
|
134
|
+
message: string;
|
|
135
|
+
operation?: string;
|
|
136
|
+
reasonCode?: number;
|
|
137
|
+
reasonString?: string;
|
|
138
|
+
metrics?: {
|
|
139
|
+
queuedMessages: number;
|
|
140
|
+
queuedBytes: number;
|
|
141
|
+
pendingOperations: number;
|
|
142
|
+
droppedMessages: number;
|
|
143
|
+
reconnectAttempts: number;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export type Listener = { remove(): void };
|
|
147
|
+
export type Subscription = {
|
|
148
|
+
readonly topicFilter: string;
|
|
149
|
+
readonly qos: QoS;
|
|
150
|
+
unsubscribe(): Promise<void>;
|
|
151
|
+
};
|
|
152
|
+
export type MqttClient = {
|
|
153
|
+
readonly instanceId: string;
|
|
154
|
+
readonly clientId: string;
|
|
155
|
+
readonly state: ConnectionState;
|
|
156
|
+
connect(): Promise<ConnAck>;
|
|
157
|
+
disconnect(): Promise<void>;
|
|
158
|
+
dispose(): Promise<void>;
|
|
159
|
+
ready(): Promise<void>;
|
|
160
|
+
getSnapshot(): Promise<SessionSnapshot>;
|
|
161
|
+
subscribe(
|
|
162
|
+
topicFilter: string,
|
|
163
|
+
options?: SubscribeOptions
|
|
164
|
+
): Promise<Subscription>;
|
|
165
|
+
publishText(
|
|
166
|
+
topic: string,
|
|
167
|
+
text: string,
|
|
168
|
+
options?: PublishOptions
|
|
169
|
+
): Promise<void>;
|
|
170
|
+
publishBytes(
|
|
171
|
+
topic: string,
|
|
172
|
+
bytes: Uint8Array,
|
|
173
|
+
options?: PublishOptions
|
|
174
|
+
): Promise<void>;
|
|
175
|
+
publishBase64(
|
|
176
|
+
topic: string,
|
|
177
|
+
base64: string,
|
|
178
|
+
options?: PublishOptions
|
|
179
|
+
): Promise<void>;
|
|
180
|
+
onStateChange(listener: (snapshot: SessionSnapshot) => void): Listener;
|
|
181
|
+
onMessage(listener: (message: Message) => void): Listener;
|
|
182
|
+
onDiagnostic(listener: (diagnostic: Diagnostic) => void): Listener;
|
|
183
|
+
readonly [Symbol.asyncDispose]?: () => Promise<void>;
|
|
184
|
+
};
|