forked from notme001/react-native-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
48 lines (45 loc) · 1.43 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
export type QoS = 0 | 1 | 2;
export class IMqttClient {
constructor(options: {
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
})
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: { uri: string, clientId?: string }): Promise<IMqttClient>;
function removeClient(client: IMqttClient): void;
function disconnectAll(): void;
}
export default mqtt;