UNPKG

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