diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index ce2df2dc0..702908b3a 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -233,6 +233,7 @@ class ChatWindow extends App.Controller @lastTimestamp @lastAddedType @isTyping = false + @isAgentTyping = false @resetUnreadMessages() @on 'layout-change', @scrollToBottom @@ -319,6 +320,10 @@ class ChatWindow extends App.Controller ENTERKEY = 13 if event.keyCode isnt TABKEY && event.keyCode isnt ENTERKEY + + # send typing start event only every 1.4 seconds + return if @isAgentTyping && @isAgentTyping > new Date(new Date().getTime() - 1400) + @isAgentTyping = new Date() App.WebSocket.send( event:'chat_session_typing' data: @@ -413,7 +418,7 @@ class ChatWindow extends App.Controller @scrollToBottom() # clear old delay, set new - @delay(@removeWritingLoader, 1800, 'typing') + @delay(@removeWritingLoader, 2000, 'typing') removeWritingLoader: => @isTyping = false diff --git a/public/assets/chat/chat.coffee b/public/assets/chat/chat.coffee index a999c8968..cfe3df641 100644 --- a/public/assets/chat/chat.coffee +++ b/public/assets/chat/chat.coffee @@ -209,23 +209,15 @@ do($ = window.jQuery, window) -> sessionStorage.setItem 'unfinished_message', @input.val() - @onTypingStart() + @onTyping() - onTypingStart: -> + onTyping: -> - clearTimeout(@isTypingTimeout) if @isTypingTimeout - - # fire typingEnd after 5 seconds - @isTypingTimeout = setTimeout @onTypingEnd, 1500 - - # send typing start event - if !@isTyping - @isTyping = true - @send 'chat_session_typing', - session_id: @sessionId - - onTypingEnd: => - @isTyping = false + # send typing start event only every 1.5 seconds + return if @isTyping && @isTyping > new Date(new Date().getTime() - 1500) + @isTyping = new Date() + @send 'chat_session_typing', + session_id: @sessionId onSubmit: (event) => event.preventDefault() @@ -256,8 +248,6 @@ do($ = window.jQuery, window) -> @input.val('') @scrollToBottom() - @isTyping = false - # send message event @send 'chat_session_message', content: message