I’m building a Node.js / Socket.io project.
I have a hash of Users based on their websocket id. When a user makes the following request i’d like to add them to a group of users viewing that page.
app.get('/board/:id', function(req, res){}
I’d like to keep something like
Browsing = {
username : id,
username : id,
…
}
However i’m unsure how to remove a user lets say if they navigate off the page. Is there some kind of function that gets called upon page leave?
Partial Solution:
The following seems to do the trick on Chrome:
$(window).unload(function(){
var username = $('#username').text();
var pid = currentProject;
var data = {
username: username,
id : pid
}
socket.emit('leaving-page', data);
})
Yes, but it is not reliable.
The way the people keep track of who is online and who isn’t, is usually like this: