Reputation: 51393
Are there any node.js module for managing users who are online?
By this I mean for a real-time application knowing who is available/connected. Sending messages between them, subscribing to events from different people, etc.
Thanks for any help.
Upvotes: 1
Views: 806
Reputation: 4539
Integration of socket.io
for real-time updates in Node.js
is what you are searching for.
Sample Code:
io.on('connection',function(socket){
socket.on('update_list',function(data){
//data.purpose;
if((String(data.purpose.trim()))=='login'){
var query="update user set online = ? where id = ?";
con.query(String(query),['Y',data.id],function(err,rows){
// var query="select * from user where id !='"+data.id+"'";
var query="select * from user";
con.query(String(query),function(err,rows){
io.emit('logout update',JSON.stringify(rows));
});
});
}else{
var query="update user set online = ? where id = ?";
con.query(String(query),['N',data.id],function(err,rows){
//var query="select * from user where id !='"+data.id+"'";
var query="select * from user";
con.query(String(query),function(err,rows){
io.emit('logout update',JSON.stringify(rows));
});
});
}
});
});
You can find the proper documentation here: Online Users Node.js
Upvotes: 0