US 3463 - Implement heartbeat protocol for taiga-events
parent
35e1e41d3a
commit
bbe40ae13b
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue