Reset sessionId if reconnect with sessionStorage sessionId was not successful.
This commit is contained in:
parent
7f3ff9a4c9
commit
59c6fce8df
1 changed files with 29 additions and 10 deletions
|
@ -22,6 +22,7 @@ do($ = window.jQuery, window) ->
|
||||||
initialQueueDelay: 10000,
|
initialQueueDelay: 10000,
|
||||||
debug: true
|
debug: true
|
||||||
host: 'ws://localhost:6042'
|
host: 'ws://localhost:6042'
|
||||||
|
wsReconnectEnable: true
|
||||||
strings:
|
strings:
|
||||||
'Online': 'Online'
|
'Online': 'Online'
|
||||||
'Offline': 'Offline'
|
'Offline': 'Offline'
|
||||||
|
@ -77,7 +78,7 @@ do($ = window.jQuery, window) ->
|
||||||
@log 'notice', 'Chat: Browser not supported!'
|
@log 'notice', 'Chat: Browser not supported!'
|
||||||
return
|
return
|
||||||
|
|
||||||
@connect()
|
@wsConnect()
|
||||||
|
|
||||||
#@onReady()
|
#@onReady()
|
||||||
|
|
||||||
|
@ -116,14 +117,18 @@ do($ = window.jQuery, window) ->
|
||||||
when 'chat_status_customer'
|
when 'chat_status_customer'
|
||||||
switch pipe.data.state
|
switch pipe.data.state
|
||||||
when 'online'
|
when 'online'
|
||||||
|
@sessionId = undefined
|
||||||
@onReady()
|
@onReady()
|
||||||
@log 'debug', 'Zammad Chat: ready'
|
@log 'debug', 'Zammad Chat: ready'
|
||||||
when 'offline'
|
when 'offline'
|
||||||
@log 'debug', 'Zammad Chat: No agent online'
|
@log 'debug', 'Zammad Chat: No agent online'
|
||||||
|
@wsClose()
|
||||||
when 'chat_disabled'
|
when 'chat_disabled'
|
||||||
@log 'debug', 'Zammad Chat: Chat is disabled'
|
@log 'debug', 'Zammad Chat: Chat is disabled'
|
||||||
|
@wsClose()
|
||||||
when 'no_seats_available'
|
when 'no_seats_available'
|
||||||
@log 'debug', 'Zammad Chat: Too many clients in queue. Clients in queue: ', pipe.data.queue
|
@log 'debug', 'Zammad Chat: Too many clients in queue. Clients in queue: ', pipe.data.queue
|
||||||
|
@wsClose()
|
||||||
when 'reconnect'
|
when 'reconnect'
|
||||||
@log 'debug', 'old messages', pipe.data.session
|
@log 'debug', 'old messages', pipe.data.session
|
||||||
@reopenSession pipe.data
|
@reopenSession pipe.data
|
||||||
|
@ -250,13 +255,21 @@ do($ = window.jQuery, window) ->
|
||||||
|
|
||||||
@isOpen = true
|
@isOpen = true
|
||||||
|
|
||||||
onOpenAnimationEnd: =>
|
|
||||||
if !@sessionId
|
if !@sessionId
|
||||||
@session_init()
|
@session_init()
|
||||||
|
|
||||||
|
onOpenAnimationEnd: =>
|
||||||
|
#@showTimeout()
|
||||||
|
|
||||||
close: (event) =>
|
close: (event) =>
|
||||||
event.stopPropagation() if event
|
event.stopPropagation() if event
|
||||||
|
|
||||||
|
# only close if session_id exists
|
||||||
|
return if !@sessionId
|
||||||
|
|
||||||
|
# stop delay of initial queue position
|
||||||
|
if @onInitialQueueDelayId
|
||||||
|
clearTimeout(@onInitialQueueDelayId)
|
||||||
#@ws.close()
|
#@ws.close()
|
||||||
|
|
||||||
sessionStorage.removeItem 'sessionId'
|
sessionStorage.removeItem 'sessionId'
|
||||||
|
@ -300,6 +313,7 @@ do($ = window.jQuery, window) ->
|
||||||
@el.find('.zammad-chat-send').prop('disabled', false)
|
@el.find('.zammad-chat-send').prop('disabled', false)
|
||||||
|
|
||||||
onQueueScreen: (data) =>
|
onQueueScreen: (data) =>
|
||||||
|
@setSessionId data.session_id
|
||||||
|
|
||||||
# delay initial queue position, show connecting first
|
# delay initial queue position, show connecting first
|
||||||
show = =>
|
show = =>
|
||||||
|
@ -318,7 +332,6 @@ do($ = window.jQuery, window) ->
|
||||||
onQueue: (data) =>
|
onQueue: (data) =>
|
||||||
@log 'notice', 'onQueue', data.position
|
@log 'notice', 'onQueue', data.position
|
||||||
@inQueue = true
|
@inQueue = true
|
||||||
@setSessionId data.session_id
|
|
||||||
|
|
||||||
@el.find('.zammad-chat-body').html @view('waiting')
|
@el.find('.zammad-chat-body').html @view('waiting')
|
||||||
position: data.position
|
position: data.position
|
||||||
|
@ -381,7 +394,7 @@ do($ = window.jQuery, window) ->
|
||||||
session_init: ->
|
session_init: ->
|
||||||
@send('chat_session_init')
|
@send('chat_session_init')
|
||||||
|
|
||||||
connect: =>
|
wsConnect: =>
|
||||||
@log 'notice', "Connecting to #{@host}"
|
@log 'notice', "Connecting to #{@host}"
|
||||||
@ws = new window.WebSocket(@host)
|
@ws = new window.WebSocket(@host)
|
||||||
@ws.onopen = @onWebSocketOpen
|
@ws.onopen = @onWebSocketOpen
|
||||||
|
@ -390,15 +403,24 @@ do($ = window.jQuery, window) ->
|
||||||
|
|
||||||
@ws.onclose = (e) =>
|
@ws.onclose = (e) =>
|
||||||
@log 'debug', 'close websocket connection'
|
@log 'debug', 'close websocket connection'
|
||||||
@reconnect()
|
if @wsReconnectEnable
|
||||||
|
@reconnect()
|
||||||
@setAgentOnlineState(false)
|
@setAgentOnlineState(false)
|
||||||
|
|
||||||
@ws.onerror = (e) =>
|
@ws.onerror = (e) =>
|
||||||
@log 'debug', 'ws:onerror', e
|
@log 'debug', 'ws:onerror', e
|
||||||
|
|
||||||
|
wsClose: =>
|
||||||
|
@wsReconnectEnable = false
|
||||||
|
@ws.close()
|
||||||
|
|
||||||
|
wsReconnect: =>
|
||||||
|
if @reconnectDelayId
|
||||||
|
clearTimeout(@reconnectDelayId)
|
||||||
|
@reconnectDelayId = setTimeout(@wsConnect, 5000)
|
||||||
|
|
||||||
onWebSocketOpen: =>
|
onWebSocketOpen: =>
|
||||||
@sessionId = sessionStorage.getItem('sessionId')
|
@sessionId = sessionStorage.getItem('sessionId')
|
||||||
|
|
||||||
@log 'debug', 'ws connected'
|
@log 'debug', 'ws connected'
|
||||||
|
|
||||||
@send 'chat_status_customer',
|
@send 'chat_status_customer',
|
||||||
|
@ -413,10 +435,7 @@ do($ = window.jQuery, window) ->
|
||||||
@lastAddedType = 'status'
|
@lastAddedType = 'status'
|
||||||
@el.find('.zammad-chat-agent-status').attr('data-status', 'connecting').text @T('Reconnecting')
|
@el.find('.zammad-chat-agent-status').attr('data-status', 'connecting').text @T('Reconnecting')
|
||||||
@addStatus @T('Connection lost')
|
@addStatus @T('Connection lost')
|
||||||
|
@wsReconnect()
|
||||||
if @reconnectDelayId
|
|
||||||
clearTimeout(@reconnectDelayId)
|
|
||||||
@reconnectDelayId = setTimeout(@connect, 5000)
|
|
||||||
|
|
||||||
onConnectionReestablished: =>
|
onConnectionReestablished: =>
|
||||||
# set status back to online
|
# set status back to online
|
||||||
|
|
Loading…
Reference in a new issue