How to get typing status of the other side with javascript?
I've seens this i开发者_JAVA百科n various places,
during chat,I can see whether the other party is typing or not .
How do implement this most easily?
The chat client code sends something back to the server when it sees a keyboard event. The server then either pushes information to other clients, or else the other clients poll the server every once in a while.
You'll need to use AJAX.
When user A first presses a key, you can tell the server that he started typing.
5 seconds after the last keypress (call clearTimeout
and setTimeout
in onkeyup
), tell the server that he stopped.
Then, on user B's side, use polling or comet to ask the server what it received from user A.
This is can be solved using XMPP/BOSH way. Check for Strophe.js -- very good xmpp library.
Or you can do this with AJAX and server polling... I'd recommend XMPP...
精彩评论