【发布时间】:2018-04-05 18:20:04
【问题描述】:
这是事后路线。当用户发布事件时,该事件应发送给其所有关注者! 我为此维护了 Follower Array。
如何使用 Socket.io ????
module.exports.postEvent = (req,res) => {
Events.saveEvent(req.body , (err,saveEvent)=>{
var response = {
status : 500,
message : err
};
var id = req.userId;
if(err){
res.status(response.status)
.json(response.message);
}else {
// find the data of user from token and
user.getuserbyname(id ,(err,user)=>{
if(err){
res.status(response.status)
.json(response.message);
}else{
// send to all user subscribers via socket.io
async.each(user.followers ,(id , callback)=>{
what will be the code here???
})
}
})
}
})
};
【问题讨论】:
-
我建议提供更多代码,例如在后端实现套接字库的位置。你用的是快递吗?
-
是的,我正在使用快递。在我的 ASYNC.each 循环中,我正在迭代一个关注者数组,我想向每个订阅者或关注者发送一个新帖子,那么我需要在那个 for 循环中写什么?
标签: node.js mongodb sockets express