Socket.IO 按名称删除房间

im_*_*tsm 0 node.js socket.io

当一个房间不再需要它的名字时,有什么方法可以完全删除它。我尝试了以下答案,但它不起作用:https : //stackoverflow.com/a/23342511 我正在使用 socketio 2 并且它抛出以下错误:

node_modules/socket.io-adapter/index.js:210
Run Code Online (Sandbox Code Playgroud)

if (fn) process.nextTick(fn.bind(null, null, sids)); TypeError: fn.bind is not a function

基本上,是否有删除/移除房间而不是leave为每个套接字执行的快捷方式?

im_*_*tsm 6

在这里我是如何最终解决这个问题的:

io.of('/').in('room name').clients(function(error, clients) {
    if (clients.length > 0) {
        console.log('clients in the room: \n');
        console.log(clients);
        clients.forEach(function (socket_id) {
            io.sockets.sockets[socket_id].leave('room name');
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

这应该适用于 socket.IO 版本 2.x