首页 > 解决方案 > Is there a way to append addtiional clients manually to a socket room created by a connected client?

问题描述

I'm having difficulties in finding a solution for a scenario when users are mentioned in the comments section. They receive a notification regardless of their online presence.

module.exports = function (io) {
    io.on('connect', function (socket) {
         // pre-processing operations to get the users
         let users = ['user1', 'user2', 'user3'];
 
         socket.join('room', () => {
                  // how would I manually join `users` to this room 
         } 
         
         // While broadcasting a message only to those users who were manually joined
         socket.to('room').emit('event', {"message" : "You were mentioned in this conversation"})    

   }

Any suggestions, resources to look into?

标签: node.jssocket.io

解决方案


我不明白你想要达到什么目的。为什么要手动加入它们?


推荐阅读