forked from wongnai/sp-react-native-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
55 lines (49 loc) · 1.69 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
import {EventEmitter2, Listener, OnOptions} from "eventemitter2";
export type QoS = 0 | 1 | 2;
export interface ClientOptions {
clientId: string;
uri: string;
host?: string;
port?: number;
protocol?: 'mqtt' | 'tcp' | 'wss' | 'mqtts' | 'ws';
tls?: boolean;
alpn?: string;
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 interface Message {
data: string;
qos: QoS;
retain: boolean;
topic: string;
}
export class IMqttClient extends EventEmitter2 {
constructor(options: ClientOptions)
on(event: 'closed', cb: (msg: string) => void, options?: boolean|OnOptions): Listener
on(event: 'error', cb: (msg: string) => void, options?: boolean|OnOptions): Listener
on(event: 'message', cb: (msg: Message) => void, options?: boolean|OnOptions): Listener
on(event: 'connect', cb: (msg: { reconnect: boolean; }) => void, options?: boolean|OnOptions): Listener
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: ClientOptions): Promise<IMqttClient>;
function removeClient(client: IMqttClient): void;
function disconnectAll(): void;
}
export default mqtt;