This commit is contained in:
Felix Niklas 2015-11-12 11:44:37 +01:00
parent 3602f4f0ea
commit 789cb15640
3 changed files with 22 additions and 35 deletions

View file

@ -34,6 +34,7 @@ do($ = window.jQuery, window) ->
'': '' '': ''
'': '' '': ''
'': '' '': ''
sessionId: undefined
T: (string, items...) => T: (string, items...) =>
if !@strings[string] if !@strings[string]
@ -69,8 +70,6 @@ do($ = window.jQuery, window) ->
keydown: @checkForEnter keydown: @checkForEnter
input: @onInput input: @onInput
@session_id = undefined
if !window.WebSocket if !window.WebSocket
@log 'notice', 'Chat: Browser not supported!' @log 'notice', 'Chat: Browser not supported!'
return return
@ -104,16 +103,11 @@ do($ = window.jQuery, window) ->
return if pipe.data.self_written return if pipe.data.self_written
@onAgentTypingStart() @onAgentTypingStart()
when 'chat_session_start' when 'chat_session_start'
switch pipe.data.state @onConnectionEstablished pipe.data.agent
when 'ok' @sessionId = pipe.data.session_id
@onConnectionEstablished pipe.data.agent when 'chat_session_queue'
when 'chat_session_init' @onQueue pipe.data.position
switch pipe.data.state @sessionId = pipe.data.session_id
when 'ok'
@onConnectionEstablished pipe.data.agent
when 'queue'
@onQueue pipe.data.position
@session_id = pipe.data.session_id
when 'chat_session_closed' when 'chat_session_closed'
@onSessionClosed pipe.data @onSessionClosed pipe.data
when 'chat_session_left' when 'chat_session_left'
@ -157,7 +151,7 @@ do($ = window.jQuery, window) ->
if !@isTyping if !@isTyping
@isTyping = true @isTyping = true
@send 'chat_session_typing', @send 'chat_session_typing',
session_id: @session_id session_id: @sessionId
onTypingEnd: => onTypingEnd: =>
@isTyping = false @isTyping = false
@ -195,7 +189,7 @@ do($ = window.jQuery, window) ->
@send 'chat_session_message', @send 'chat_session_message',
content: message content: message
id: @_messageCount id: @_messageCount
session_id: @session_id session_id: @sessionId
receiveMessage: (data) => receiveMessage: (data) =>
# hide writing indicator # hide writing indicator
@ -240,7 +234,7 @@ do($ = window.jQuery, window) ->
@isOpen = false @isOpen = false
@send 'chat_session_close', @send 'chat_session_close',
session_id: @session_id session_id: @sessionId
hide: -> hide: ->
@el.removeClass('zammad-chat-is-visible') @el.removeClass('zammad-chat-is-visible')
@ -325,7 +319,7 @@ do($ = window.jQuery, window) ->
@ws.onopen = => @ws.onopen = =>
@log 'debug', 'ws connected' @log 'debug', 'ws connected'
@send 'chat_status_customer', @send 'chat_status_customer',
session_id: @session_id session_id: @sessionId
@setAgentOnlineState(true) @setAgentOnlineState(true)
@ws.onmessage = @onWebSocketMessage @ws.onmessage = @onWebSocketMessage

View file

@ -50,6 +50,8 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
'': '' '': ''
}; };
ZammadChat.prototype.sessionId = void 0;
ZammadChat.prototype.T = function() { ZammadChat.prototype.T = function() {
var i, item, items, len, string, translation; var i, item, items, len, string, translation;
string = arguments[0], items = 2 <= arguments.length ? slice.call(arguments, 1) : []; string = arguments[0], items = 2 <= arguments.length ? slice.call(arguments, 1) : [];
@ -121,7 +123,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
keydown: this.checkForEnter, keydown: this.checkForEnter,
input: this.onInput input: this.onInput
}); });
this.session_id = void 0;
if (!window.WebSocket) { if (!window.WebSocket) {
this.log('notice', 'Chat: Browser not supported!'); this.log('notice', 'Chat: Browser not supported!');
return; return;
@ -167,20 +168,12 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.onAgentTypingStart(); this.onAgentTypingStart();
break; break;
case 'chat_session_start': case 'chat_session_start':
switch (pipe.data.state) { this.onConnectionEstablished(pipe.data.agent);
case 'ok': this.sessionId = pipe.data.session_id;
this.onConnectionEstablished(pipe.data.agent);
}
break; break;
case 'chat_session_init': case 'chat_session_queue':
switch (pipe.data.state) { this.onQueue(pipe.data.position);
case 'ok': this.sessionId = pipe.data.session_id;
this.onConnectionEstablished(pipe.data.agent);
break;
case 'queue':
this.onQueue(pipe.data.position);
this.session_id = pipe.data.session_id;
}
break; break;
case 'chat_session_closed': case 'chat_session_closed':
this.onSessionClosed(pipe.data); this.onSessionClosed(pipe.data);
@ -232,7 +225,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
if (!this.isTyping) { if (!this.isTyping) {
this.isTyping = true; this.isTyping = true;
return this.send('chat_session_typing', { return this.send('chat_session_typing', {
session_id: this.session_id session_id: this.sessionId
}); });
} }
}; };
@ -271,7 +264,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
return this.send('chat_session_message', { return this.send('chat_session_message', {
content: message, content: message,
id: this._messageCount, id: this._messageCount,
session_id: this.session_id session_id: this.sessionId
}); });
}; };
@ -322,7 +315,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.disconnect(); this.disconnect();
this.isOpen = false; this.isOpen = false;
return this.send('chat_session_close', { return this.send('chat_session_close', {
session_id: this.session_id session_id: this.sessionId
}); });
}; };
@ -418,7 +411,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
return function() { return function() {
_this.log('debug', 'ws connected'); _this.log('debug', 'ws connected');
_this.send('chat_status_customer', { _this.send('chat_status_customer', {
session_id: _this.session_id session_id: _this.sessionId
}); });
return _this.setAgentOnlineState(true); return _this.setAgentOnlineState(true);
}; };

File diff suppressed because one or more lines are too long