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
|
def pre
|
||||||
|
|
||||||
# check if feature is enabled
|
# check if feature is enabled
|
||||||
if !Setting.get('chat')
|
return if Setting.get('chat')
|
||||||
return {
|
{
|
||||||
event: 'chat_error',
|
event: 'chat_error',
|
||||||
data: {
|
data: {
|
||||||
state: 'chat_disabled',
|
state: 'chat_disabled',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def post
|
def post
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
|
||||||
|
|
||||||
# return new session
|
# return new session
|
||||||
{
|
{
|
||||||
event: 'chat_session_init',
|
event: 'chat_session_queue',
|
||||||
data: {
|
data: {
|
||||||
state: 'queue',
|
state: 'queue',
|
||||||
position: Chat.waiting_chat_count,
|
position: Chat.waiting_chat_count,
|
||||||
|
|
|
@ -36,15 +36,23 @@ class Sessions::Event::ChatSessionStart < Sessions::Event::ChatBase
|
||||||
session_id: chat_session.session_id,
|
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
|
# send position update to other waiting sessions
|
||||||
{
|
position = 0
|
||||||
event: 'chat_session_start',
|
Chat::Session.where(state: 'waiting').order('created_at ASC').each {|local_chat_session|
|
||||||
data: {
|
position += 1
|
||||||
state: 'ok',
|
data = {
|
||||||
session: chat_session,
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,7 @@ do($ = window.jQuery, window) ->
|
||||||
inputTimeout: null
|
inputTimeout: null
|
||||||
isTyping: false
|
isTyping: false
|
||||||
isOnline: true
|
isOnline: true
|
||||||
|
initialQueueDelay: 10000,
|
||||||
debug: true
|
debug: true
|
||||||
host: 'ws://localhost:6042'
|
host: 'ws://localhost:6042'
|
||||||
strings:
|
strings:
|
||||||
|
@ -92,9 +93,9 @@ do($ = window.jQuery, window) ->
|
||||||
|
|
||||||
onWebSocketMessage: (e) =>
|
onWebSocketMessage: (e) =>
|
||||||
pipes = JSON.parse( e.data )
|
pipes = JSON.parse( e.data )
|
||||||
@log 'debug', 'ws:onmessage', pipes
|
|
||||||
|
|
||||||
for pipe in pipes
|
for pipe in pipes
|
||||||
|
@log 'debug', 'ws:onmessage', pipe
|
||||||
switch pipe.event
|
switch pipe.event
|
||||||
when 'chat_session_message'
|
when 'chat_session_message'
|
||||||
return if pipe.data.self_written
|
return if pipe.data.self_written
|
||||||
|
@ -104,10 +105,9 @@ do($ = window.jQuery, window) ->
|
||||||
@onAgentTypingStart()
|
@onAgentTypingStart()
|
||||||
when 'chat_session_start'
|
when 'chat_session_start'
|
||||||
@onConnectionEstablished pipe.data.agent
|
@onConnectionEstablished pipe.data.agent
|
||||||
@sessionId = pipe.data.session_id
|
|
||||||
when 'chat_session_queue'
|
when 'chat_session_queue'
|
||||||
@onQueue pipe.data.position
|
|
||||||
@sessionId = pipe.data.session_id
|
@sessionId = pipe.data.session_id
|
||||||
|
@onQueueScreen pipe.data.position
|
||||||
when 'chat_session_closed'
|
when 'chat_session_closed'
|
||||||
@onSessionClosed pipe.data
|
@onSessionClosed pipe.data
|
||||||
when 'chat_session_left'
|
when 'chat_session_left'
|
||||||
|
@ -254,6 +254,22 @@ do($ = window.jQuery, window) ->
|
||||||
@el.find('.zammad-chat-input').prop('disabled', false)
|
@el.find('.zammad-chat-input').prop('disabled', false)
|
||||||
@el.find('.zammad-chat-send').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) =>
|
onQueue: (position) =>
|
||||||
@log 'notice', 'onQueue', position
|
@log 'notice', 'onQueue', position
|
||||||
@inQueue = true
|
@inQueue = true
|
||||||
|
@ -361,6 +377,11 @@ do($ = window.jQuery, window) ->
|
||||||
@el.find('.zammad-chat-agent-status').addClass('zammad-chat-is-hidden')
|
@el.find('.zammad-chat-agent-status').addClass('zammad-chat-is-hidden')
|
||||||
|
|
||||||
onConnectionEstablished: (agent) =>
|
onConnectionEstablished: (agent) =>
|
||||||
|
|
||||||
|
# stop delay of initial queue position
|
||||||
|
if @onInitialQueueDelayId
|
||||||
|
clearTimeout(@onInitialQueueDelayId)
|
||||||
|
|
||||||
@inQueue = false
|
@inQueue = false
|
||||||
@agent = agent
|
@agent = agent
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue