Skip to content

Commit

Permalink
Make frontend auto-reconnect to backend, fixes issue fw42#7
Browse files Browse the repository at this point in the history
  • Loading branch information
mickey committed Aug 29, 2013
1 parent 4dfc61c commit de02750
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/coffee/transport.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ class Transport
@socket = new SockJS('/data')

@socket.onopen = =>
@reconnectDelay = 1
@log.add("Connection to back-end established")

@socket.onclose = =>
@log.add("Connection to back-end lost :-(")
@log.add("Connection to back-end lost :-( Retrying in #{@reconnectDelay}s...")
setTimeout (=> @reconnect()), @reconnectDelay * 1000

@socket.onmessage = (msg) =>
@handler(JSON.parse(msg.data))

reconnect: ->
@reconnectDelay += 1 if @reconnectDelay < 5
@connect()

0 comments on commit de02750

Please sign in to comment.