// 接受服务器消息
function getServerMsg() {
if (!exitflag) {
$.ajax({
url : "../hf/chat/get",
type : "post",
data : {
sessionId : sessionId
},
dataType : "json",
success : function(response) {
// 显示接收消息
var success=response.success;
if(success==false){
exitflag=true;
}else{
var list = response.msg;
if (list != null && list.length > 0)
window.messageListener(list);
getServerMsg();
}
},
error : function(XMLHttpRequest, textStatus,
errorThrown) {
if (textStatus == "timeout")
getServerMsg();
}
});
}
}
window.messageListener(list);起到什么作用啊
为什么内部又调用自己getServerMsg();
// list 消息列表,列表按消息时间顺序排列
window.messageListener = function(list) {
for ( var i = 0; i < list.length; i++) {
var msgnode = list[i];
if (msgnode.body == "@endconversation") {// 坐席退出聊天
message.clearMessageText();
message.overChat();// 结束会话
overFlag=true;
var leaveFlag = sessionStorage.leaveFlag;
if (leaveFlag && leaveFlag == "hold") {
message.insertMessageText("<i class='mui-icon icon-tongzhi'></i>您已退出人工服务,若继续咨询请重新进入在线咨询");
}
startFlag = false;
// 更新坐席信息
if (typeof ajid != "undefined" && ajid != '') {
message.insertRate(ajid);
}
} else if (msgnode.body == "@endconversation_temp") {
// message.overChat();// 结束会话
} else if (msgnode.body == "@ring") {// 排队
message.clearMessageText();
message.insertMessageText("<i class='mui-icon icon-tongzhi'></i>正在排队,您前面还有"
+ msgnode.queneNum + "人等候," + "请稍后");
// 更新坐席信息
// $("#img_kefu").attr("src", "./images/yewu1.png");
} else if (msgnode.body == "@waitin") {// 进线
startFlag = true;
} else if (msgnode.body == "@sendtimeout") {
var exitFlag = sessionStorage.exitFlag;
if (!autoExit) {
autoExit = true;
message
.insertMessageText(
"<i class='mui-icon icon-tongzhi'></i>由于您长时间未发送消息,人工服务将于60秒后断开",
function() {
var $el = $(this);
var count = 60;
var timers = setInterval(
function() {
$el.html("<i class='mui-icon icon-tongzhi'></i>由于您长时间未发送消息,人工服务将于"
+ count
+ "秒后断开");
if (autoExit) {
if (count == 0) {
autoExit = false;
clearInterval(timers);
$el.html("");
count = 60;
startFlag = false;
}
} else {// 恢复正常
$el.html("");
clearInterval(timers);
count = 60;
}
count--;
}, 1000);
});
}
} else if (msgnode.body == "@rectimeout") {// @rectimeout
message.overChat();// 结束会话
overFlag=true;
message
.insertMessageText("<i class='mui-icon icon-tongzhi'></i>由于坐席繁忙,暂时无法处理您的问题,请重新打开本页面...");
startFlag = false;
} else if (msgnode.type == "@deliver") {
var body = common.unhtml(msgnode.body);// 去除html特殊字符
if (body.indexOf("http") > -1&&body.indexOf(".png") > -1 ) {
body = '<img src="' + body + '">';
}
body = emotion.convertEmotionNew(body);
if (msgnode.from != "" && ajid != msgnode.from) {
ajid = msgnode.from;
sessionStorage.ajid = ajid;
message.clearMessageText();
message.insertMessageText("<i class='mui-icon icon-tongzhi'></i>客服"
+ ajid + "正在为您服务");
}
message.insertLeftText(body, common
.getFormatDateByLong(Math.round(msgnode.time),
"hh:mm:ss"));
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…