views:

71

answers:

3

I've seens this in various places,

during chat,I can see whether the other party is typing or not .

How do implement this most easily?

A: 

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.

SLaks
A: 

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.

Pointy
Making a separate request on each keypress would be extremely inefficient.
SLaks
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...

NilColor
Have you ever digg into how `Strophe.js` implements **Comet**?
No, i didn't. And i'm sure its a server technology - long-help request a-la *Comet*. So here we need to talk about "how jabber server (BOSH) implements it".
NilColor
Actually,I don't think it's a pure server technology.
Yes, its not. Client must understand that this request must be long-held. Personally i prefer xmpp way. But Comet is good too. You can choose - each of them can help you with all kind of chat notifications. But keep in mind thad jabber servers already support it (via presence/iq/etc stanzas) and you can chat with people who uses desctop clients like Adium/Miranda. With Comet you can't do this.
NilColor