Reputation: 4167
Actually I have to implement read and not read status in simple node chat with socket.io
.
I have already build real time chat application with help of node and socket.io
.
But now what I want is when user1 send message to another user2. user1 has status of if user2 read or not read message which is send to another user like whatsup do right now.
any idea about this status.
Upvotes: 2
Views: 6193
Reputation: 126
I got a draw and send application using Nodejs and Socket.io , Here is my app's repository: https://github.com/mg52/DrawChat. The application has sent/sending (it works like read/not read) status. In my app every users have an unique id. This sent/sending status depends on these unique ids.
For example,
in index.html:
when you click on send button,
message_sent.innerHTML = "Message Send Status: Sending..."
socket.on("get_message", function (data) {
//getting message from sender (from index.js)
socket.emit("message_sent",{sentuserid:data.userid});
});
in index.js:
socket.on("message_sent", function(data){
io.sockets.emit("message_sent_correctly",{msc:data.sentuserid});
//it sends back to all users (includes sender) the sender's id
});
in index.html:
socket.on("message_sent_correctly",function(data){
socket.emit("check_id", {ci: data.msc});
//sends back to server to control who has sent the message
});
in index.js:
socket.on("check_id",function(data){
if(data.ci === user.uid){
socket.emit("id_checked");
}
//if id equals to sender's id returns to index.html that the message has been sent successfully
});
in index.html:
socket.on("id_checked",function(){
message_sent.innerHTML = "Your message has been read!";
});
I know that this codes may not be the shortest way to hande read/not read status. But it works perfect.
Upvotes: 3