1 |
|
2 |
|
3 | import * as events from 'events'
|
4 | import {
|
5 | IClientOptions,
|
6 | IClientPublishOptions,
|
7 | IClientSubscribeOptions,
|
8 | IClientReconnectOptions
|
9 | } from './client-options'
|
10 | import { Store } from './store'
|
11 | import { Packet, QoS } from './types'
|
12 |
|
13 | export interface ISubscriptionGrant {
|
14 | |
15 |
|
16 |
|
17 | topic: string
|
18 | |
19 |
|
20 |
|
21 | qos: QoS | number
|
22 | }
|
23 | export interface ISubscriptionRequest {
|
24 | |
25 |
|
26 |
|
27 | topic: string
|
28 | |
29 |
|
30 |
|
31 | qos: QoS
|
32 | }
|
33 | export interface ISubscriptionMap {
|
34 | |
35 |
|
36 |
|
37 | [topic: string]: QoS
|
38 | }
|
39 |
|
40 | export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
|
41 | export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: Packet) => void
|
42 | export declare type OnPacketCallback = (packet: Packet) => void
|
43 | export declare type OnErrorCallback = (error: Error) => void
|
44 | export declare type PacketCallback = (error?: Error, packet?: Packet) => any
|
45 | export declare type CloseCallback = () => void
|
46 |
|
47 | export interface IStream extends events.EventEmitter {
|
48 | pipe (to: any): any
|
49 | destroy (): any
|
50 | end (): any
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export declare class MqttClient extends events.EventEmitter {
|
60 | public connected: boolean
|
61 | public disconnecting: boolean
|
62 | public disconnected: boolean
|
63 | public reconnecting: boolean
|
64 | public incomingStore: Store
|
65 | public outgoingStore: Store
|
66 | public options: IClientOptions
|
67 | public queueQoSZero: boolean
|
68 |
|
69 | constructor (streamBuilder: (client: MqttClient) => IStream, options: IClientOptions)
|
70 |
|
71 | public on (event: 'message', cb: OnMessageCallback): this
|
72 | public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
|
73 | public on (event: 'error', cb: OnErrorCallback): this
|
74 | public on (event: string, cb: Function): this
|
75 |
|
76 | public once (event: 'message', cb: OnMessageCallback): this
|
77 | public once (event:
|
78 | 'packetsend'
|
79 | | 'packetreceive', cb: OnPacketCallback): this
|
80 | public once (event: 'error', cb: OnErrorCallback): this
|
81 | public once (event: string, cb: Function): this
|
82 |
|
83 | /**
|
84 | * publish - publish <message> to <topic>
|
85 | *
|
86 | * @param {String} topic - topic to publish to
|
87 | * @param {(String|Buffer)} message - message to publish
|
88 | *
|
89 | * @param {Object} [opts] - publish options, includes:
|
90 | * @param {Number} [opts.qos] - qos level to publish on
|
91 | * @param {Boolean} [opts.retain] - whether or not to retain the message
|
92 | *
|
93 | * @param {Function} [callback] - function(err){}
|
94 | * called when publish succeeds or fails
|
95 | * @returns {Client} this - for chaining
|
96 | * @api public
|
97 | *
|
98 | * @example client.publish('topic', 'message')
|
99 | * @example
|
100 | * client.publish('topic', 'message', {qos: 1, retain: true})
|
101 | * @example client.publish('topic', 'message', console.log)
|
102 | */
|
103 | public publish (topic: string, message: string | Buffer,
|
104 | opts: IClientPublishOptions, callback?: PacketCallback): this
|
105 | public publish (topic: string, message: string | Buffer,
|
106 | callback?: PacketCallback): this
|
107 |
|
108 | |
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | public subscribe (topic:
|
125 | string
|
126 | | string[], opts: IClientSubscribeOptions, callback?: ClientSubscribeCallback): this
|
127 | public subscribe (topic:
|
128 | string
|
129 | | string[]
|
130 | | ISubscriptionMap, callback?: ClientSubscribeCallback): this
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | public unsubscribe (topic: string | string[], callback?: PacketCallback): this
|
143 |
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | public end (force?: boolean, cb?: CloseCallback): this
|
154 |
|
155 | |
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | public removeOutgoingMessage (mid: number): this
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | public reconnect (opts?: IClientReconnectOptions): this
|
180 |
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | public handleMessage (packet: Packet, callback: PacketCallback): void
|
190 |
|
191 | |
192 |
|
193 |
|
194 | public getLastMessageId (): number
|
195 | }
|
196 | export { IClientOptions }
|