Merge pull request #29 from taigaio/increase-robustness

Increase robustness
master
Jesús Espino 2017-04-06 13:36:35 +02:00 committed by GitHub
commit c4a95a3de9
2 changed files with 10 additions and 5 deletions

View File

@ -15,15 +15,18 @@ class Client
@ws.on 'message', @.handleMessage.bind(@)
handleMessage: (message) ->
msg = JSON.parse(message)
try
msg = JSON.parse(message)
catch e
return null
if msg.cmd == 'ping'
@.sendPong()
else if msg.cmd == 'auth'
else if msg.cmd == 'auth' and msg.data
@.authUser(msg.data)
else if msg.cmd == 'subscribe'
else if msg.cmd == 'subscribe' and msg.routing_key
@.addSubscription(msg.routing_key)
else if msg.cmd == 'unsubscribe'
else if msg.cmd == 'unsubscribe' and msg.routing_key
@.removeSubscription(msg.routing_key)
authUser: (auth) ->

View File

@ -105,7 +105,9 @@ subscriptions = do ->
unsubscribe = (client_id, routing_key) ->
channels.get(client_id).then (channel) ->
channel.cancel(subs[client_id][routing_key])
consumerTag = subs[client_id][routing_key]
if consumerTag != undefined
channel.cancel(consumerTag)
removeClient = (client_id) ->
delete subs[client_id]