Amr Elgarhy
Amr Elgarhy

Reputation: 68952

How to know if the other user is now writing a message in web chat website?

I am building a chat system in an ASP.Net MVC website, and I want the user see if the other chat user is now writing a message.

The same as it appear in gtalk or msn, when the other user start writing it says: "userA is writing ...." then it hide this message when the user stops.

What will be the concept behind this feature to implement on a website, and what I should know to build it the right way?

Upvotes: 0

Views: 342

Answers (3)

Alex Turpin
Alex Turpin

Reputation: 47776

Client-side, have a timer count to 500ms and a variable sentState set to false.

Whenever the client types something, reset that timer, the, if sentState is, send an AJAX request to the server indicating that the client is typing. Finally, set sentState to true.

If the timer reaches 500ms, send an AJAX request to the server indicating that the client is no longer typing and set sentState to false.

Upvotes: 0

ethrbunny
ethrbunny

Reputation: 10469

Look for an "on change" (or equivalent) for your edit text. Start a timer when it happens and send an ajax message to the chat server(s) to notify them. When the text is submitted or the timer runs out, clear the message.

Upvotes: 0

Chase Florell
Chase Florell

Reputation: 47387

This is all done via AJAX

User1 sends a writing=true value to the server as soon as writing begins, and writing=false when message is submitted.

User2 polls the server every x seconds to see if(writing){display "User1 is writing a message"}

This is obviously two way, so User1 and User2 are both pushing and pulling the writing boolean from the server.

I'd suggest using jQuery and JSON for this process.

Upvotes: 1

Related Questions