Socket.IO uses heartbeat pattern to be sure that a client is still connected. It would solve my algorithm if I would be able to subscribe to the hearbeat event on server.
for instance: socket.on "heartbeat", -> mycode
any idea if this is possible?
Socket.IO uses heartbeat pattern to be sure that a client is still connected. It would solve my algorithm if I would be able to subscribe to the hearbeat event on server.
for instance: socket.on "heartbeat", -> mycode
any idea if this is possible?
The heartbeat happens very frequently, are you sure that's the right thing? I use the "connect" event, that seems like it might do what you need:
connect: (url, options, connectCallback) =>
someFunction = =>
@doSomeRedisStuff() if @connected
@logger.debug "starting connection to url: #{url}"
@socket = @socket.connect(url, options)
@logger.debug "connecting ..."
@socket.on "connect", =>
@logger.info "connected (socket id #{(@socket.socket.sessionid)})"
@connected = true
setTimeout someFunction, 2000
connectCallback() if connectCallback?
@socket.on "disconnect", =>
@connected = false
If the connection to the server is interrupted (e.g. the server is restarted) the connect event will kick off when the connection comes back. Socket.IO is smart about this.