Extjs round-robin chat

Source: Internet
Author: User

Client: jqm

Server: php

Manager: extjs

The client and manager use polling to check whether messages are sent to the server. The method is resource-consuming.

Some manager Code:


MonitorChatMessage: function (){

Var me = this;

// Timer task
Var getMsgNotify = function (){

Me. getClientMsgNotify (me. token );
};

Var runner = new Ext. util. TaskRunner ();
Var task = runner. start ({
Run: getMsgNotify,
Interval: 5000
});

}

// Request client messages from the server

Getclientmsgpolicy: function (token ){

Var me = this;
Var index = 1;

Ext. Ajax. request ({

Url: 'http: // localhost/wc/server/talk. php ',
Method: 'post ',
Params :{
Token: token,
Function: 'getnewmsgpolicy'
},

Success: function (res, opts ){

Var result = Ext. JSON. decode (res. responseText );
If (result. success ){

Var userTree = me. getChatUserTree ();
// Obtain the root node
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: Double-click to reply to the recipient

Debugger;

If (cellIndex = 2) {// reply to me

Var mid = record. get ('mid ');
Var smsg = record. get ('smsg ');
Var rmsg = record. get ('rmsg ');
Var replyObj = new Object ();
ReplyObj. rmsg = rmsg;
ReplyObj. reply = "";

// Start the reply Interface
Var replyMsg = this. startReplyWindow (mid, smsg, replyObj );
Record. beginEdit ();
Record. set ('rmsg ', replyObj. reply );
Record. endEdit ();

This. getChatMessagStoreStore (). load ();
}

StartReplyWindow


< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>
< pre>

Advantages: easy to implement

Disadvantage: Resource Consumption

After several days, I tried to replace the round-robin method with the socket persistent connection method. Nodejs is used for implementation.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.