user5869120
user5869120

Reputation: 119

How do I check if a message sent through socket-io is read?

I'm using socket-io on top of node to manage a chat app.

I was wondering, once a message is recieved, how can I check for a "seen" and "unseen" status of the message. Is there an event on jquery? I'm not sure if i should manage this from the jquery or socket-io side. Thank you!

Upvotes: 2

Views: 11386

Answers (4)

Johan Tchassem
Johan Tchassem

Reputation: 21

There are two things to do. First, check if the browser is currently active. And second, check if an element is visible in the viewport. When an element is in the viewport, it appears in the visible part of the screen. From then on, you can emit a message to socket with read

Upvotes: 0

Chintan Gor
Chintan Gor

Reputation: 1072

For managing seen/unseen we need to fire background message after receiving/reading from user , which is like acknowledgement receipt. It is simple.

Upvotes: 1

Vineet Gupta
Vineet Gupta

Reputation: 136

You have to implement your own logic as to send response back when message is read. There is no such socket-io jquery event to trigger on read .Yon can emit a message on message received by checking that if the tab is currently active as that is the way you can consider a message to be read if the tab is currently active or your chat window is opened.

Upvotes: 7

jfriend00
jfriend00

Reputation: 707426

You will have to send a message back when the message is read. There is no notion of when something is "read" in socket.io.

That's something you would have to invent in your own user interface and when you consider it read, you could send a message back to the sender that indicates it is now read. Unless each message requires some action to open it in order to read it (like an email often does), it's likely hard to know when it was actually "read" by the recipient. In typical chat programs, the message is just displayed automatically and you have no idea whether the recipient is looking at it or not.

Upvotes: 4

Related Questions