What happens is that I'm doing an application with Node js, Angular and jQuery, and with sockets, what I need is to know if the user left the application, I issued a socket which removes me from the list of connected users, the user who left, I have the following code and you are only getting it is the id of the user who first logged in, so log me in from another PC or a cell phone.
io.on('connection', function (socket) {
console.log('Nuevo usuario conectado');
io.emit('userconect');
socket.on("disconnect", function () {
io.emit('removeuser');
});
});
y en el archivo js, tengo los sockets de esta manera:
socket.on('userconect', function () {
var iduser = localStorage.getItem('el id del usuario');
var userlist = $('.usersconects .users ul li[id=' + iduser + ']');
if (userlist.length <= 0) {
$('.usersconects .users ul').prepend('<li id="' + iduser + '"><i class="fa fa-user" aria-hidden="true"></i> Usuario prueba</li>');
}
});
socket.on('removeuser', function () {
var iduser = localStorage.getItem('el id del usuario');
var userlist = $('.usersconects .users ul li[id=' + iduser + ']');
if (userlist.length > 0) {
userlist.remove();
}
});
Will there be any way to obtain the user id stored from the localStorage of the client, and send it to the js file?
I appreciate your help.