diff --git a/client.coffee b/client.coffee index f023c9c..34dbd81 100644 --- a/client.coffee +++ b/client.coffee @@ -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) -> diff --git a/rabbit.coffee b/rabbit.coffee index 078e1be..d065884 100644 --- a/rabbit.coffee +++ b/rabbit.coffee @@ -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]