Merge pull request #7 from taigaio/us/3463/events-ping-and-pong

US 3463 - Implement heartbeat protocol for taiga-events
master
Juanfran 2015-11-12 12:28:38 +01:00
commit 3bb5179619
1 changed files with 10 additions and 5 deletions

View File

@ -17,7 +17,9 @@ class Client
handleMessage: (message) -> handleMessage: (message) ->
msg = JSON.parse(message) msg = JSON.parse(message)
if msg.cmd == 'auth' if msg.cmd == 'ping'
@.sendPong()
else if msg.cmd == 'auth'
@.auth(msg.data) @.auth(msg.data)
else if msg.cmd == 'subscribe' else if msg.cmd == 'subscribe'
@.addSubscription(msg.routing_key) @.addSubscription(msg.routing_key)
@ -34,14 +36,17 @@ class Client
@.subscriptionManager = new SubscriptionManager(@.id, @.auth, @ws) @.subscriptionManager = new SubscriptionManager(@.id, @.auth, @ws)
@.subscriptionManager.add(routing_key) @.subscriptionManager.add(routing_key)
close: () ->
if @.subscriptionManager
@.subscriptionManager.destroy()
removeSubscription: (routing_key) -> removeSubscription: (routing_key) ->
if @.subscriptionManager if @.subscriptionManager
@.subscriptionManager.remove(routing_key) @.subscriptionManager.remove(routing_key)
sendPong: ->
@ws.send(JSON.stringify({cmd: "pong"}))
close: () ->
if @.subscriptionManager
@.subscriptionManager.destroy()
exports.createClient = (ws) -> exports.createClient = (ws) ->
client = new Client(ws) client = new Client(ws)