commit
c4a95a3de9
|
@ -15,15 +15,18 @@ class Client
|
||||||
@ws.on 'message', @.handleMessage.bind(@)
|
@ws.on 'message', @.handleMessage.bind(@)
|
||||||
|
|
||||||
handleMessage: (message) ->
|
handleMessage: (message) ->
|
||||||
|
try
|
||||||
msg = JSON.parse(message)
|
msg = JSON.parse(message)
|
||||||
|
catch e
|
||||||
|
return null
|
||||||
|
|
||||||
if msg.cmd == 'ping'
|
if msg.cmd == 'ping'
|
||||||
@.sendPong()
|
@.sendPong()
|
||||||
else if msg.cmd == 'auth'
|
else if msg.cmd == 'auth' and msg.data
|
||||||
@.authUser(msg.data)
|
@.authUser(msg.data)
|
||||||
else if msg.cmd == 'subscribe'
|
else if msg.cmd == 'subscribe' and msg.routing_key
|
||||||
@.addSubscription(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)
|
@.removeSubscription(msg.routing_key)
|
||||||
|
|
||||||
authUser: (auth) ->
|
authUser: (auth) ->
|
||||||
|
|
|
@ -105,7 +105,9 @@ subscriptions = do ->
|
||||||
|
|
||||||
unsubscribe = (client_id, routing_key) ->
|
unsubscribe = (client_id, routing_key) ->
|
||||||
channels.get(client_id).then (channel) ->
|
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) ->
|
removeClient = (client_id) ->
|
||||||
delete subs[client_id]
|
delete subs[client_id]
|
||||||
|
|
Loading…
Reference in New Issue