gpt4 book ai didi

javascript - socket.io 从两个房间加入客户

转载 作者:搜寻专家 更新时间:2023-10-31 23:10:19 24 4
gpt4 key购买 nike

我想将来自两个房间的客户加入一个新房间。有没有办法做到这一点?喜欢:

io.sockets.clients(room1 , room2).join(room 3);

最佳答案

var rooms = ['room1', 'room2', room3]; // list of rooms

socket.join('room1'); // assign the room on connection

var clients = io.sockets.clients(rooms[0]); // list of all clients in room1

for (client in clients)
{
clients[client].leave(rooms[0]); // leave room1
clients[client].join(rooms[2]); // join room3
}

对房间 2 重复相同的操作。希望这有帮助

关于javascript - socket.io 从两个房间加入客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10843175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com