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.