Added "connection" placeholder screen for 10 sec. Fixed updating wait list counter in backend.
This commit is contained in:
parent
9b78afe982
commit
b654c4d34b
4 changed files with 48 additions and 22 deletions
|
@ -10,16 +10,13 @@ class Sessions::Event::ChatBase
|
|||
def pre
|
||||
|
||||
# check if feature is enabled
|
||||
if !Setting.get('chat')
|
||||
return {
|
||||
event: 'chat_error',
|
||||
data: {
|
||||
state: 'chat_disabled',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
false
|
||||
return if Setting.get('chat')
|
||||
{
|
||||
event: 'chat_error',
|
||||
data: {
|
||||
state: 'chat_disabled',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
def post
|
||||
|
|
|
@ -34,7 +34,7 @@ class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
|
|||
|
||||
# return new session
|
||||
{
|
||||
event: 'chat_session_init',
|
||||
event: 'chat_session_queue',
|
||||
data: {
|
||||
state: 'queue',
|
||||
position: Chat.waiting_chat_count,
|
||||
|
|
|
@ -36,15 +36,23 @@ class Sessions::Event::ChatSessionStart < Sessions::Event::ChatBase
|
|||
session_id: chat_session.session_id,
|
||||
},
|
||||
}
|
||||
chat_session.send_to_recipients(data, @client_id)
|
||||
chat_session.send_to_recipients(data)
|
||||
|
||||
# send chat_session_init to agent
|
||||
{
|
||||
event: 'chat_session_start',
|
||||
data: {
|
||||
state: 'ok',
|
||||
session: chat_session,
|
||||
},
|
||||
# send position update to other waiting sessions
|
||||
position = 0
|
||||
Chat::Session.where(state: 'waiting').order('created_at ASC').each {|local_chat_session|
|
||||
position += 1
|
||||
data = {
|
||||
event: 'chat_session_queue',
|
||||
data: {
|
||||
state: 'queue',
|
||||
position: position,
|
||||
session_id: local_chat_session.session_id,
|
||||
},
|
||||
}
|
||||
local_chat_session.send_to_recipients(data)
|
||||
}
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@ do($ = window.jQuery, window) ->
|
|||
inputTimeout: null
|
||||
isTyping: false
|
||||
isOnline: true
|
||||
initialQueueDelay: 10000,
|
||||
debug: true
|
||||
host: 'ws://localhost:6042'
|
||||
strings:
|
||||
|
@ -92,9 +93,9 @@ do($ = window.jQuery, window) ->
|
|||
|
||||
onWebSocketMessage: (e) =>
|
||||
pipes = JSON.parse( e.data )
|
||||
@log 'debug', 'ws:onmessage', pipes
|
||||
|
||||
for pipe in pipes
|
||||
@log 'debug', 'ws:onmessage', pipe
|
||||
switch pipe.event
|
||||
when 'chat_session_message'
|
||||
return if pipe.data.self_written
|
||||
|
@ -104,10 +105,9 @@ do($ = window.jQuery, window) ->
|
|||
@onAgentTypingStart()
|
||||
when 'chat_session_start'
|
||||
@onConnectionEstablished pipe.data.agent
|
||||
@sessionId = pipe.data.session_id
|
||||
when 'chat_session_queue'
|
||||
@onQueue pipe.data.position
|
||||
@sessionId = pipe.data.session_id
|
||||
@onQueueScreen pipe.data.position
|
||||
when 'chat_session_closed'
|
||||
@onSessionClosed pipe.data
|
||||
when 'chat_session_left'
|
||||
|
@ -254,6 +254,22 @@ do($ = window.jQuery, window) ->
|
|||
@el.find('.zammad-chat-input').prop('disabled', false)
|
||||
@el.find('.zammad-chat-send').prop('disabled', false)
|
||||
|
||||
onQueueScreen: (data) =>
|
||||
|
||||
# delay initial queue position, show connecting first
|
||||
show = =>
|
||||
@onQueue data.position
|
||||
if @initialQueueDelay && !@onInitialQueueDelayId
|
||||
@onInitialQueueDelayId = setTimeout(show, @initialQueueDelay)
|
||||
return
|
||||
|
||||
# stop delay of initial queue position
|
||||
if @onInitialQueueDelayId
|
||||
clearTimeout(@onInitialQueueDelayId)
|
||||
|
||||
# show queue position
|
||||
show()
|
||||
|
||||
onQueue: (position) =>
|
||||
@log 'notice', 'onQueue', position
|
||||
@inQueue = true
|
||||
|
@ -361,6 +377,11 @@ do($ = window.jQuery, window) ->
|
|||
@el.find('.zammad-chat-agent-status').addClass('zammad-chat-is-hidden')
|
||||
|
||||
onConnectionEstablished: (agent) =>
|
||||
|
||||
# stop delay of initial queue position
|
||||
if @onInitialQueueDelayId
|
||||
clearTimeout(@onInitialQueueDelayId)
|
||||
|
||||
@inQueue = false
|
||||
@agent = agent
|
||||
|
||||
|
|
Loading…
Reference in a new issue