|
1 | | -"use strict"; |
2 | | -var mqtt = require("mqtt"); |
3 | | -var inArray = require("in-array"); |
| 1 | +'use strict'; |
| 2 | +var mqtt = require('mqtt'); |
| 3 | +var inArray = require('in-array'); |
4 | 4 |
|
5 | 5 | var RegularClientPrototype = mqtt.MqttClient.prototype; |
6 | 6 |
|
7 | | -var ASYNC_METHODS = ["publish", |
8 | | - "subscribe", |
9 | | - "unsubscribe", |
10 | | - "unsubscribe", |
11 | | - "end" |
| 7 | +var ASYNC_METHODS = ['publish', |
| 8 | + 'subscribe', |
| 9 | + 'unsubscribe', |
| 10 | + 'unsubscribe', |
| 11 | + 'end' |
12 | 12 | ]; |
13 | 13 |
|
14 | 14 | var SYNC_METHODS = [ |
15 | | - "emit", |
16 | | - "addListener", |
17 | | - "on", |
18 | | - "once", |
19 | | - "removeListener", |
20 | | - "removeAllListeners", |
21 | | - "setMaxListeners", |
22 | | - "getMaxListeners", |
23 | | - "listeners", |
24 | | - "listenerCount" |
| 15 | + 'emit', |
| 16 | + 'addListener', |
| 17 | + 'on', |
| 18 | + 'once', |
| 19 | + 'removeListener', |
| 20 | + 'removeAllListeners', |
| 21 | + 'setMaxListeners', |
| 22 | + 'getMaxListeners', |
| 23 | + 'listeners', |
| 24 | + 'listenerCount' |
25 | 25 | ]; |
26 | 26 |
|
27 | 27 | module.exports = { |
28 | | - connect: connect, |
29 | | - AsyncClient: AsyncClient |
| 28 | + connect: connect, |
| 29 | + AsyncClient: AsyncClient |
30 | 30 | }; |
31 | 31 |
|
32 | | -function connect(brokerURL, opts) { |
33 | | - var client = mqtt.connect(brokerURL, opts); |
| 32 | +function connect (brokerURL, opts) { |
| 33 | + var client = mqtt.connect(brokerURL, opts); |
34 | 34 |
|
35 | | - var asyncClient = new AsyncClient(client); |
| 35 | + var asyncClient = new AsyncClient(client); |
36 | 36 |
|
37 | | - return asyncClient; |
| 37 | + return asyncClient; |
38 | 38 | } |
39 | 39 |
|
40 | | -function AsyncClient(client) { |
41 | | - this._client = client; |
| 40 | +function AsyncClient (client) { |
| 41 | + this._client = client; |
42 | 42 | } |
43 | 43 |
|
44 | 44 | AsyncClient.prototype = { |
45 | | - set handleMessage(newHandler) { |
46 | | - this._client.handleMessage = newHandler; |
47 | | - }, |
48 | | - get handleMessage() { |
49 | | - return this._client.handleMessage; |
50 | | - } |
| 45 | + set handleMessage (newHandler) { |
| 46 | + this._client.handleMessage = newHandler; |
| 47 | + }, |
| 48 | + get handleMessage () { |
| 49 | + return this._client.handleMessage; |
| 50 | + } |
51 | 51 | }; |
52 | 52 |
|
53 | 53 | ASYNC_METHODS.forEach(defineAsync); |
54 | 54 | SYNC_METHODS.forEach(definePassthrough); |
55 | 55 |
|
56 | | -function definePassthrough(name) { |
57 | | - AsyncClient.prototype[name] = function() { |
58 | | - var client = this._client; |
59 | | - return client[name].apply(client, arguments); |
60 | | - }; |
| 56 | +function definePassthrough (name) { |
| 57 | + AsyncClient.prototype[name] = function () { |
| 58 | + var client = this._client; |
| 59 | + return client[name].apply(client, arguments); |
| 60 | + }; |
61 | 61 | } |
62 | 62 |
|
63 | | -function defineAsync(name) { |
64 | | - AsyncClient.prototype[name] = function asyncMethod() { |
65 | | - var client = this._client; |
66 | | - var args = []; |
67 | | - var length = arguments.length; |
68 | | - var i = 0; |
69 | | - for (i; i < length; i++) |
70 | | - args.push(arguments[i]); |
| 63 | +function defineAsync (name) { |
| 64 | + AsyncClient.prototype[name] = function asyncMethod () { |
| 65 | + var client = this._client; |
| 66 | + var args = []; |
| 67 | + var length = arguments.length; |
| 68 | + var i = 0; |
| 69 | + for (i; i < length; i++) |
| 70 | + args.push(arguments[i]); |
71 | 71 |
|
72 | | - return new Promise(function(resolve, reject) { |
73 | | - args.push(makeCallback(resolve, reject)); |
74 | | - client[name].apply(client, args); |
75 | | - }); |
76 | | - }; |
| 72 | + return new Promise(function (resolve, reject) { |
| 73 | + args.push(makeCallback(resolve, reject)); |
| 74 | + client[name].apply(client, args); |
| 75 | + }); |
| 76 | + }; |
77 | 77 | } |
78 | 78 |
|
79 | | -function makeCallback(resolve, reject) { |
80 | | - return function(err, data) { |
81 | | - if (err) |
82 | | - reject(err); |
83 | | - else resolve(data); |
84 | | - }; |
| 79 | +function makeCallback (resolve, reject) { |
| 80 | + return function (err, data) { |
| 81 | + if (err) |
| 82 | + reject(err); |
| 83 | + else resolve(data); |
| 84 | + }; |
85 | 85 | } |
0 commit comments