forked from hawkingnetwork/react-native-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.d.ts
60 lines (44 loc) · 1.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export type QoS = 0 | 1 | 2;
interface IMqttClientOptions {
clientId: string;
uri: string;
host?: string;
port?: number;
protocol?: 'mqtt' | 'tcp' | 'wss' | 'mqtts' | 'ws';
tls?: boolean;
keepalive?: number; // seconds
protocolLevel?: number;
clean?: boolean;
auth?: boolean;
user?: string; // only used when auth is true
pass?: string; // only used when auth is true
will?: boolean;
willMsg?: string; // only used when will is true
willtopic?: string; // only used when will is true
willQos?: QoS; // only used when will is true
willRetainFlag?: boolean; // only used when will is true
automaticReconnect?: boolean; // android only
}
export class IMqttClient {
constructor(options: IMqttClientOptions);
on(event: 'closed', cb: (msg: string) => void): void;
on(event: 'error', cb: (msg: string) => void): void;
on(
event: 'message',
cb: (msg: { data: string; qos: QoS; retain: boolean; topic: string }) => void,
): void;
on(event: 'connect', cb: (msg: { reconnect: boolean }) => void): void;
connect(): void;
disconnect(): void;
subscribe(topic: string, qos: QoS): void;
unsubscribe(topic: string): void;
publish(topic: string, payload: string, qos: QoS, retain: boolean): void;
reconnect(): void;
isConnected(): Promise<boolean>;
}
declare namespace mqtt {
function createClient(options: IMqttClientOptions): Promise<IMqttClient>;
function removeClient(client: IMqttClient): void;
function disconnectAll(): void;
}
export default mqtt;