Skip to content

Commit 743b3e7

Browse files
authored
Merge pull request #14 from msgflo/mqtt-modernize
mqtt: Fix mqtt>1.4.x
2 parents 48d9371 + 4746dc5 commit 743b3e7

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"grunt-mocha-test": "^0.12.2",
3131
"grunt-shell-spawn": "^0.3.1",
3232
"mocha": "~1.21.0",
33-
"mqtt": "1.4.x"
33+
"mqtt": "^1.4.0"
3434
},
3535
"keywords": [],
3636
"bin": {

src/mqtt.coffee

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,27 @@ class Client extends interfaces.MessagingClient
1919
return callback mqtt
2020

2121
@client = mqtt.connect @address
22-
@client.on 'error', (err) =>
23-
debug 'error', err
22+
23+
# debug
2424
@client.on 'reconnect', () =>
2525
debug 'reconnect'
2626
@client.on 'offline', () =>
2727
debug 'offline'
28-
onConnected = (err) =>
28+
29+
@client.on 'error', (err) =>
30+
debug 'error', err
31+
if callback
32+
callback err
33+
callback = null
34+
return
35+
onConnected = (connack) =>
2936
debug 'connected'
3037
@client.on 'message', (topic, message) =>
3138
@_onMessage topic, message
32-
return callback err
39+
if callback
40+
callback null
41+
callback = null
42+
return
3343
@client.once 'connect', onConnected
3444

3545
disconnect: (callback) ->

0 commit comments

Comments
 (0)