...
|
...
|
@@ -183,6 +183,32 @@ function pageInit() { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 连接socket
|
|
|
*/
|
|
|
function connectSocket() {
|
|
|
socketChat.init(Object.assign(originConf, {
|
|
|
onMessage: function(e) {
|
|
|
var jsonString = e.data;
|
|
|
var received = JSON.parse(jsonString);
|
|
|
|
|
|
socketConfCM.conversationId = received.newConversationId !== 0 ?
|
|
|
received.newConversationId :
|
|
|
received.conversationId;
|
|
|
|
|
|
getMessage(received);
|
|
|
},
|
|
|
|
|
|
connectFailCb: function () {
|
|
|
$('.connect-fail').fadeIn();
|
|
|
},
|
|
|
|
|
|
socketClosedCb: function () {
|
|
|
alert('链接已经断开了,请刷新后重试!');
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 处理发送消息
|
|
|
* @param e
|
|
|
* @param msgType
|
...
|
...
|
@@ -255,7 +281,7 @@ function pageInit() { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 人工客服 s
|
|
|
* 人工客服
|
|
|
*/
|
|
|
function manualService() {
|
|
|
socketConfCM.type = allRTs.MANUAL_SERVICE;
|
...
|
...
|
@@ -271,6 +297,14 @@ function pageInit() { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 客服已离线
|
|
|
*/
|
|
|
function csOffline(message) {
|
|
|
// 系统通知
|
|
|
systemTip('', message.content);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 留言
|
|
|
*/
|
|
|
function leaveMsg() {
|
...
|
...
|
@@ -333,6 +367,8 @@ function pageInit() { |
|
|
</span>
|
|
|
</p>
|
|
|
</div>`;
|
|
|
// 隐藏人工
|
|
|
$iconMs.hide();
|
|
|
break;
|
|
|
|
|
|
case MANUAL_SERVICE: // 2是接入人工成功
|
...
|
...
|
@@ -623,6 +659,11 @@ function pageInit() { |
|
|
csChatting(message);
|
|
|
break;
|
|
|
|
|
|
// 对方离开
|
|
|
case allTypes.OP_LEAVE:
|
|
|
csOffline(message);
|
|
|
break;
|
|
|
|
|
|
case allTypes.OFFLINE:
|
|
|
tipTpl =
|
|
|
`<div class="list-item">
|
...
|
...
|
@@ -766,23 +807,13 @@ function pageInit() { |
|
|
if (jsonData && jsonData.data && jsonData.data.result !== -1) {
|
|
|
|
|
|
socketConfCM.userHead = jsonData.data.headIco || '';
|
|
|
socketConfCM.userName = window.getUser()[0];
|
|
|
socketConfCM.userName = decodeURIComponent(window.getUser()[0]);
|
|
|
|
|
|
// 原始配置信息用于重新连线
|
|
|
originConf = JSON.parse(JSON.stringify(socketConf));
|
|
|
|
|
|
socketChat.init(Object.assign(socketConf, {
|
|
|
onMessage: function(e) {
|
|
|
var received = JSON.parse(e.data);
|
|
|
|
|
|
socketConfCM.conversationId = received.newConversationId > 0 ?
|
|
|
received.newConversationId :
|
|
|
received.conversationId;
|
|
|
|
|
|
// 保存过程中信息
|
|
|
getMessage(received);
|
|
|
}
|
|
|
}));
|
|
|
// 连接
|
|
|
connectSocket();
|
|
|
}
|
|
|
});
|
|
|
}());
|
...
|
...
|
@@ -1091,30 +1122,11 @@ function pageInit() { |
|
|
});
|
|
|
|
|
|
// 重新连线
|
|
|
$msgList.on('click', '.reconnect', function() {
|
|
|
$document.on('click', '.reconnect', function() {
|
|
|
$('.connect-fail').hide();
|
|
|
// 共通处理
|
|
|
beforeSendMsg();
|
|
|
socketChat.init(Object.assign(originConf, {
|
|
|
onOpen: function() {
|
|
|
console.log('websocket opened!');
|
|
|
},
|
|
|
|
|
|
onMessage: function(e) {
|
|
|
var jsonString = e.data;
|
|
|
var received = JSON.parse(jsonString);
|
|
|
|
|
|
socketConfCM.conversationId = received.newConversationId !== 0 ?
|
|
|
received.newConversationId :
|
|
|
received.conversationId;
|
|
|
|
|
|
getMessage(received);
|
|
|
},
|
|
|
|
|
|
onClose: function() {
|
|
|
console.log('websocket closed!');
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
connectSocket();
|
|
|
});
|
|
|
|
|
|
// 发送
|
...
|
...
|
|