Commit 0a71d2b3 by libai

测试

parent 9fdde34c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>客服聊天</title> <title> </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
...@@ -520,6 +520,7 @@ ...@@ -520,6 +520,7 @@
} }
ws.onopen = function() ws.onopen = function()
{ {
clearInterval(timmer)
state("连接成功"); state("连接成功");
system("客服已接入"); system("客服已接入");
if(send){ if(send){
...@@ -537,16 +538,31 @@ ...@@ -537,16 +538,31 @@
}; };
ws.onclose = function(event) ws.onclose = function(event)
{ {
var recNum=0
var timmer=null
state("连接断开"); state("连接断开");
$("#guestid").val(''); $("#guestid").val('');
tips("连接已断开","error",3000); tips("连接已断开","error",3000);
timmer=setinterval(function(){
connect(false);
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
console.error("WebSocket close observed:", event); console.error("WebSocket close observed:", event);
}; };
ws.onerror = function(event) ws.onerror = function(event)
{ {
// 关闭 websocket // 关闭 websocket
var recNum=0
var timmer=null
state("连接错误"); state("连接错误");
msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1); msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1);
timmer=setinterval(function(){
connect(false);
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
console.error("WebSocket error observed:", event); console.error("WebSocket error observed:", event);
}; };
} else{ } else{
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>客服聊天</title> <title> </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
...@@ -281,6 +281,8 @@ ...@@ -281,6 +281,8 @@
var checkTimer; var checkTimer;
var sendtime=0; var sendtime=0;
var map = new Map(); var map = new Map();
var timmer=null;
var recOk=true;
$(function(){ $(function(){
btninit(); btninit();
params(); params();
...@@ -328,9 +330,9 @@ ...@@ -328,9 +330,9 @@
return; return;
} }
if(content.length>120){ if(content.length>120){
tips("内容超过最大限制","warn",5000); tips("内容2超过最大限制","warn",5000);
return; return;2
} }2
var guestid=$("#guestid").val(); var guestid=$("#guestid").val();
if(null==guestid||guestid==''){ if(null==guestid||guestid==''){
//连接客服 //连接客服
...@@ -423,7 +425,7 @@ ...@@ -423,7 +425,7 @@
var chat=$("#cs-chat"); var chat=$("#cs-chat");
chat.append(sysmsg); chat.append(sysmsg);
var offset=chat[0].scrollHeight-chat[0].clientHeight; var offset=chat[0].scrollHeight-chat[0].clientHeight;
if(offset-chat[0].scrollTop<(chat[0].clientHeight/2)){ if(offset-chat[0].scrollTop<(500)){
chat.animate({scrollTop: chat.scrollHeight}, 500); chat.animate({scrollTop: chat.scrollHeight}, 500);
}else{ }else{
tips("有新的系统消息","normal",3000); tips("有新的系统消息","normal",3000);
...@@ -502,6 +504,7 @@ ...@@ -502,6 +504,7 @@
} }
function WebSocketStart(guestid,send) { function WebSocketStart(guestid,send) {
state("连接中"); state("连接中");
if(ws!=null&&ws.readyState == WebSocket.OPEN){ if(ws!=null&&ws.readyState == WebSocket.OPEN){
...@@ -520,6 +523,7 @@ ...@@ -520,6 +523,7 @@
} }
ws.onopen = function() ws.onopen = function()
{ {
clearInterval(timmer)
state("连接成功"); state("连接成功");
system("客服已接入"); system("客服已接入");
if(send){ if(send){
...@@ -537,14 +541,34 @@ ...@@ -537,14 +541,34 @@
}; };
ws.onclose = function(event) ws.onclose = function(event)
{ {
if(recOk){
var recNum=0
timmer=setInterval(function(){
WebSocketStart(guestid,false)
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
}
state("连接断开"); state("连接断开");
$("#guestid").val(''); $("#guestid").val('');
tips("连接已断开","error",3000); tips("连接已断开","error",3000);
console.error("WebSocket close observed:", event); console.error("WebSocket close observed:", event);
}; };
ws.onerror = function(event) ws.onerror = function(event)
{ {
// 关闭 websocket // 关闭 websocket
if(recOk){
var recNum=0
timmer=setInterval(function(){
WebSocketStart(guestid,false)
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
}
state("连接错误"); state("连接错误");
msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1); msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1);
console.error("WebSocket error observed:", event); console.error("WebSocket error observed:", event);
...@@ -571,6 +595,7 @@ ...@@ -571,6 +595,7 @@
msgbulid(1,"因您长时间未回复,本次会话已经中止,如果还有问题需要咨询,请直接发送消息","系统",1); msgbulid(1,"因您长时间未回复,本次会话已经中止,如果还有问题需要咨询,请直接发送消息","系统",1);
checkTimer=null; checkTimer=null;
sendtime=-1; sendtime=-1;
recOk=false
$("#guestid").val(''); $("#guestid").val('');
ws.close(); ws.close();
} }
......
...@@ -521,6 +521,7 @@ ...@@ -521,6 +521,7 @@
} }
ws.onopen = function() ws.onopen = function()
{ {
clearInterval(timmer)
state("连接成功"); state("连接成功");
system("客服已接入"); system("客服已接入");
if(send){ if(send){
...@@ -538,16 +539,31 @@ ...@@ -538,16 +539,31 @@
}; };
ws.onclose = function(event) ws.onclose = function(event)
{ {
var recNum=0
var timmer=null
state("连接断开"); state("连接断开");
$("#guestid").val(''); $("#guestid").val('');
tips("连接已断开","error",3000); tips("连接已断开","error",3000);
timmer=setinterval(function(){
connect(false);
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
console.error("WebSocket close observed:", event); console.error("WebSocket close observed:", event);
}; };
ws.onerror = function(event) ws.onerror = function(event)
{ {
// 关闭 websocket // 关闭 websocket
var recNum=0
var timmer=null
state("连接错误"); state("连接错误");
msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1); msgbulid(1,"会话意外断开,发送消息即可联系客服","系统",1);
timmer=setinterval(function(){
connect(false);
recNum++
if(recNum>=5)clearInterval(timmer)
}, 1000);
console.error("WebSocket error observed:", event); console.error("WebSocket error observed:", event);
}; };
} else{ } else{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment