From bbe40ae13b7211ffa50c8110c5b1783194f53787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Fri, 6 Nov 2015 14:31:49 +0100 Subject: [PATCH] US 3463 - Implement heartbeat protocol for taiga-events --- client.coffee | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client.coffee b/client.coffee index e2374de..af53cae 100644 --- a/client.coffee +++ b/client.coffee @@ -17,7 +17,9 @@ class Client handleMessage: (message) -> msg = JSON.parse(message) - if msg.cmd == 'auth' + if msg.cmd == 'ping' + @.sendPong() + else if msg.cmd == 'auth' @.auth(msg.data) else if msg.cmd == 'subscribe' @.addSubscription(msg.routing_key) @@ -34,14 +36,17 @@ class Client @.subscriptionManager = new SubscriptionManager(@.id, @.auth, @ws) @.subscriptionManager.add(routing_key) - close: () -> - if @.subscriptionManager - @.subscriptionManager.destroy() - removeSubscription: (routing_key) -> if @.subscriptionManager @.subscriptionManager.remove(routing_key) + sendPong: -> + @ws.send(JSON.stringify({cmd: "pong"})) + + close: () -> + if @.subscriptionManager + @.subscriptionManager.destroy() + exports.createClient = (ws) -> client = new Client(ws)