如何解决如何在节点中使用socket.io和cron向两个不同的用户发送两个不同的通知
我遇到问题,找不到任何流程或解决方案... 首先,让我解释一下上下文:我的用户可以为我们的不同客户创建许多提醒。时间到了,我想向前台发出一个通知,例如“嘿,来您的集合地!给您的客户打电话”。 我的问题是:当时间到了时,只有一个cron运行时,我的socket.io可以正常工作。当我尝试使用两个用户时,它不能正常工作(第一个通知正在发送给我的所有用户)。
那是我的一部分代码:
var cron_notif = []
//console.log('COMMENCE ICI')
for(let y = 0; y < userconnect.length; y++) {
console.log('TEST 1')
if (userconnect[y] && userconnect[y].userid) {
socket.join(`USER_${userconnect[y].userid}`)
for (let x = 0; x < userconnect[y].reminder.length; x++) {
console.log('TEST 2')
//console.log("LAAAAAAAAAAAA",userconnect[y].reminder[x])
if (userconnect[y].reminder[x].notification_time && userconnect[y].reminder[x].motif) {
console.log('TOTO 1')
if (moment.unix(userconnect[y].reminder[x].notification_time).format('D MM') === moment().format('D MM')) {
console.log('TOTO 2')
//let random = Math.floor(Math.random() * 100000)
//console.log("ICI RANDOM",random)
var time = `${moment.unix(userconnect[y].reminder[x].notification_time).locale('fr').format('mm')} ${moment.unix(userconnect[y].reminder[x].notification_time).locale('fr').format('H')} ${moment.unix(userconnect[y].reminder[x].notification_time).locale('fr').format('D')} ${moment.unix(userconnect[y].reminder[x].notification_time).locale('fr').format('MM')} *`
let data = cron.schedule(time,() => {
console.log("Dans le cron",userconnect[y].userid,userconnect[y].reminder[x].motif)
io.to(`USER_${userconnect[y].userid}`).emit(`notif_rappel_${userconnect[y].userid}`,userconnect[y].reminder[x].motif +' '+ userconnect[y].userid);
let notif_destroy = cron_notif.find(e => e.id === userconnect[y].userid && e.time === time )
if (notif_destroy){
notif_destroy.data.destroy();
}
});
cron_notif.push({
id: userconnect[y].userid,data: data,time: time
})
}
}
}
}
}
很明显,在我前面,我有我的socket.on(notif_rappel_${this.props.auth.payload.userid}
,(message)=> this.test(message))
希望您能提供帮助。 预先谢谢你!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。