Joining socket io room on connect

后端 未结 3 1884
别跟我提以往
别跟我提以往 2021-02-05 04:55

I am trying to make a logged in user to join a certain socket.io room on connect. According to any examples I found on the net I seem to have emit some action from client to be

3条回答
  •  离开以前
    2021-02-05 05:33

    This should be what you need. Feel free to pass in whatever room name you want through the client. Only the server can handle assigning a socket to a room.

    Server:

    io.sockets.on('connection', function(socket) {
            socket.on('join', function(room) {
            socket.join(room);
        });
    });
    

    Client:

    socket.emit('join', roomNum);
    

提交回复
热议问题