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);
record.beginEdit();
record.set('rmsg', replyObj.reply);
record.endEdit();
this.getChatMessagStoreStore().load();
}
startReplyWindow
優點:實現簡單
缺點:耗費資源
經過,幾天努力把輪詢方式,替換成了socket長串連方式。用nodejs實現了一把。