Skip to content

Commit

Permalink
Trigger disconnect once only
Browse files Browse the repository at this point in the history
  • Loading branch information
l4u committed Jul 9, 2012
1 parent 888955e commit 0f2d930
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions client_example/erly_juggernaut.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class ErlyJuggernaut
@handlers = {}
@meta = @options.meta

@disconnect_count = 0

@bullet = $.bullet("ws://#{@options.host}:#{@options.port}/websocket")
# TODO configureable path
# TODO configureable protocol

@bullet.onopen = @onconnect
@bullet.onclose = @ondisconnect
@bullet.onclose = @ondisconnect
#@bullet.onclose = @ondisconnect
@bullet.ondisconnect = @ondisconnect
@bullet.onmessage = @onmessage
@bullet.onheartbeat = =>
@bullet.send "ping"
Expand All @@ -27,10 +29,13 @@ class ErlyJuggernaut

onconnect: () =>
# TODO store session id? ref juggernaut/application.js line 3310
@disconnect_count = 0
@trigger("connect")

ondisconnect: () =>
@trigger("disconnect")
if @disconnect_count == 0
@disconnect_count++
@trigger("disconnect")

onmessage: (data) =>
message = JSON.parse(data.data)
Expand Down
10 changes: 7 additions & 3 deletions client_example/erly_juggernaut.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f2d930

Please sign in to comment.