https://github.com/antoniopol06/gitnode/blob/master/notificaciones/routes/index.js#L91 :
var io=require('../variables').io;
//sockets
io.sockets.on('connection', inicio);
function inicio(socket){
var socketid = notificaciones[usuarioFinal];
if (typeof socketid == 'undefined' || usuario==usuarioFinal)
{
console.log("no emitir");
}else{
io.sockets.socket(socketid).emit('notificar', usuario, mensaje);
}
}
This needs to be put to top-level, since you don't wnat it to be executed everytime someone accesses that url (and triggers that express handler for contestarTema).
So, when a new reply comes in, I'd push that to some user-specific array that contains all unread messages of that particular user. and on top level (aka line 0), I'd set up io.on('connection', inicio), where inicio checks that particular user's array for unread messages and sends them to the client.
cheers
https://github.com/antoniopol06/gitnode/blob/master/notificaciones/routes/index.js#L91 :
This needs to be put to top-level, since you don't wnat it to be executed everytime someone accesses that url (and triggers that express handler for
contestarTema).So, when a new reply comes in, I'd push that to some user-specific array that contains all unread messages of that particular user. and on top level (aka line 0), I'd set up
io.on('connection', inicio), where inicio checks that particular user's array for unread messages and sends them to the client.cheers