日期:2014-05-16 浏览次数:20370 次
client:jqm
server:php
manager:extjs
client和manager以轮询方式探测对方是否有消息发送到server。方式比较耗费资源。
manager部分代码:
monitorChatMessage:function(){
var me = this;
//定时器任务
var getMsgNotify = function () {
me.getClientMsgNotify(me.token);
};
var runner = new Ext.util.TaskRunner();
var task = runner.start({
run: getMsgNotify,
interval: 5000
});
}
//请求服务端的client消息
getClientMsgNotify: function(token){
var me = this;
var index = 1;
Ext.Ajax.request({
url : 'http://localhost/wc/server/talk.php',
method : 'POST',
params:{
token:token,
function:'getNewMsgNotify'
},
success : function(res, opts) {
var result = Ext.JSON.decode(res.responseText);
if(result.success){
var userTree = me.getChatUserTree();
//获取根节点
var root = userTree.getRootNode();
var uidArray = result.data;
//root.eachChild(renderNode,uidArray);
for(index in uidArray){
if(root.findChild('uid',uidArray[index].uid) == null){
root.insertChild(0,{
id:uidArray[index].uid,
uid:uidArray[index].uid,
text:uidArray[index].uid,
leaf:1,
parentId:0,
});
}
}
}
}
});
}
ui:双击回复对方
debugger;
if(cellIndex == 2){//我的回复
var mid = record.get('mid');
var smsg = record.get('smsg');
var rmsg = record.get('rmsg');
var replyObj = new Object();
replyObj.rmsg = rmsg;
replyObj.reply = "";
//启动回复界面
var replyMsg = this.startReplyWindow(mid,smsg,replyObj);
&nbs