Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#129, #162 add ws ping-pong and close if no response #169

Merged
merged 1 commit into from
May 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/trans-websocket.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WebSocketReceiver extends transport.GenericReceiver
@connection.setNoDelay(true)
catch x
@ws.addEventListener('message', (m) => @didMessage(m.data))
@heartbeat_cb = => @heartbeat_timeout()
super @connection

setUp: ->
Expand Down Expand Up @@ -88,6 +89,18 @@ class WebSocketReceiver extends transport.GenericReceiver
@ws = null
@connection = null

heartbeat: ->
supportsHeartbeats = @ws.ping null, ->
clearTimeout(hto_ref)

if supportsHeartbeats
hto_ref = setTimeout(@heartbeat_cb, 10000)
else
super

heartbeat_timeout: ->
@session.close(3000, 'No response from heartbeat')



Transport = transport.Transport
Expand Down
5 changes: 4 additions & 1 deletion src/transport.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Session
x = =>
if @recv
@to_tref = setTimeout(x, @heartbeat_delay)
@recv.doSendFrame("h")
@recv.heartbeat()
@to_tref = setTimeout(x, @heartbeat_delay)
return

Expand Down Expand Up @@ -264,6 +264,9 @@ class GenericReceiver
utils.quote(m)
@doSendFrame('a' + '[' + q_msgs.join(',') + ']')

heartbeat: ->
@doSendFrame('h')


# Write stuff to response, using chunked encoding if possible.
class ResponseReceiver extends GenericReceiver
Expand Down