UNPKG

4.74 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { EventEmitter } from 'events';
4/**
5 * @see https://github.com/mqttjs/MQTT.js/
6 */
7export declare class MqttClient extends EventEmitter {
8 connected: boolean;
9 disconnecting: boolean;
10 disconnected: boolean;
11 reconnecting: boolean;
12 incomingStore: any;
13 outgoingStore: any;
14 options: any;
15 queueQoSZero: boolean;
16 constructor(streamBuilder: (client: MqttClient) => any, options: any);
17 on(event: 'message', cb: any): this;
18 on(event: 'packetsend' | 'packetreceive', cb: any): this;
19 on(event: 'error', cb: any): this;
20 on(event: string, cb: Function): this;
21 once(event: 'message', cb: any): this;
22 once(event: 'packetsend' | 'packetreceive', cb: any): this;
23 once(event: 'error', cb: any): this;
24 once(event: string, cb: Function): this;
25 /**
26 * publish - publish <message> to <topic>
27 *
28 * @param {String} topic - topic to publish to
29 * @param {(String|Buffer)} message - message to publish
30 *
31 * @param {Object} [opts] - publish options, includes:
32 * @param {Number} [opts.qos] - qos level to publish on
33 * @param {Boolean} [opts.retain] - whether or not to retain the message
34 *
35 * @param {Function} [callback] - function(err){}
36 * called when publish succeeds or fails
37 * @returns {Client} this - for chaining
38 * @api public
39 *
40 * @example client.publish('topic', 'message')
41 * @example
42 * client.publish('topic', 'message', {qos: 1, retain: true})
43 * @example client.publish('topic', 'message', console.log)
44 */
45 publish(topic: string, message: string | Buffer, opts: any, callback?: any): this;
46 publish(topic: string, message: string | Buffer, callback?: any): this;
47 /**
48 * subscribe - subscribe to <topic>
49 *
50 * @param {String, Array, Object} topic - topic(s) to subscribe to, supports objects in the form {'topic': qos}
51 * @param {Object} [opts] - optional subscription options, includes:
52 * @param {Number} [opts.qos] - subscribe qos level
53 * @param {Function} [callback] - function(err, granted){} where:
54 * {Error} err - subscription error (none at the moment!)
55 * {Array} granted - array of {topic: 't', qos: 0}
56 * @returns {MqttClient} this - for chaining
57 * @api public
58 * @example client.subscribe('topic')
59 * @example client.subscribe('topic', {qos: 1})
60 * @example client.subscribe({'topic': 0, 'topic2': 1}, console.log)
61 * @example client.subscribe('topic', console.log)
62 */
63 subscribe(topic: string | string[], opts: any, callback?: any): this;
64 subscribe(topic: string | string[] | any, callback?: any): this;
65 /**
66 * unsubscribe - unsubscribe from topic(s)
67 *
68 * @param {String, Array} topic - topics to unsubscribe from
69 * @param {Function} [callback] - callback fired on unsuback
70 * @returns {MqttClient} this - for chaining
71 * @api public
72 * @example client.unsubscribe('topic')
73 * @example client.unsubscribe('topic', console.log)
74 */
75 unsubscribe(topic: string | string[], callback?: any): this;
76 /**
77 * end - close connection
78 *
79 * @returns {MqttClient} this - for chaining
80 * @param {Boolean} force - do not wait for all in-flight messages to be acked
81 * @param {Function} cb - called when the client has been closed
82 *
83 * @api public
84 */
85 end(force?: boolean, cb?: any): this;
86 /**
87 * removeOutgoingMessage - remove a message in outgoing store
88 * the outgoing callback will be called withe Error('Message removed') if the message is removed
89 *
90 * @param {Number} mid - messageId to remove message
91 * @returns {MqttClient} this - for chaining
92 * @api public
93 *
94 * @example client.removeOutgoingMessage(client.getLastMessageId());
95 */
96 removeOutgoingMessage(mid: number): this;
97 /**
98 * reconnect - connect again using the same options as connect()
99 *
100 * @param {Object} [opts] - optional reconnect options, includes:
101 * {any} incomingStore - a store for the incoming packets
102 * {any} outgoingStore - a store for the outgoing packets
103 * if opts is not given, current stores are used
104 *
105 * @returns {MqttClient} this - for chaining
106 *
107 * @api public
108 */
109 reconnect(opts?: any): this;
110 /**
111 * Handle messages with backpressure support, one at a time.
112 * Override at will.
113 *
114 * @param packet packet the packet
115 * @param callback callback call when finished
116 * @api public
117 */
118 handleMessage(packet: any, callback: any): void;
119 /**
120 * getLastMessageId
121 */
122 getLastMessageId(): number;
123}