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