Extjs 輪詢方式聊天功能

來源:互聯網
上載者:User

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實現了一把。


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.