Added /ws, :port/ and ajax long poling auto detection.

This commit is contained in:
Martin Edenhofer 2015-04-12 03:52:53 +02:00
parent 63e8405a99
commit c4c12e34e2

View file

@ -171,7 +171,6 @@ class _webSocketSingleton extends App.Controller
App.Delay.set @ping, 60000, 'websocket-pong', 'ws' App.Delay.set @ping, 60000, 'websocket-pong', 'ws'
connect: => connect: =>
return if @backend is 'ajax'
if !window.WebSocket if !window.WebSocket
@backend = 'ajax' @backend = 'ajax'
@ -183,13 +182,18 @@ class _webSocketSingleton extends App.Controller
if window.location.protocol is 'https:' if window.location.protocol is 'https:'
protocol = 'wss://' protocol = 'wss://'
@ws = new window.WebSocket( protocol + window.location.hostname + ":6042/" ) if @backend is 'websocket'
@ws = new window.WebSocket( protocol + window.location.hostname + '/ws' )
else if @backend is 'websocketPort'
@ws = new window.WebSocket( protocol + window.location.hostname + ':6042/' )
else
@_ajaxInit()
# Set event handlers. # Set event handlers.
@ws.onopen = => @ws.onopen = =>
@log 'notice', 'new websocket connection open' @log 'notice', "new websocket (#{@channel()}) connection open"
@connectionEstablished = true @connectionEstablished = true
@connectionWasEstablished = true @connectionWasEstablished = true
# close error message show up (because try so connect again) if exists # close error message show up (because try so connect again) if exists
@ -224,19 +228,27 @@ class _webSocketSingleton extends App.Controller
if @connectionEstablished if @connectionEstablished
@connectionEstablished = false @connectionEstablished = false
return if @backend is 'ajax' # if connection was not possible
if !@connectionWasEstablished
# use ws dedicated port fallback if no connection was possible
if @backend is 'websocket'
@log 'notice', 'no websocket connection on /ws, use :port/'
@backend = 'websocketPort'
@connect()
return
# use ajax fallback if no connection was possible
if @backend is 'websocketPort'
@log 'notice', 'no websocket connection on :port/, use ajax long polling as fallback'
@backend = 'ajax'
@connect()
return
# show error message, first try to reconnect # show error message, first try to reconnect
if !@error if !@error
message = => message = =>
# use fallback if no connection was possible
if !@connectionWasEstablished
@backend = 'ajax'
@log 'notice', 'No connection to websocket, use ajax long polling as fallback'
@_ajaxInit()
return
# show reconnect message # show reconnect message
@error = new App.ControllerModal( @error = new App.ControllerModal(
head: 'Lost network connection!' head: 'Lost network connection!'