I'm new to the MEAN stack and trying to build a web app with it. With socket.io, I would like to randomly pair up all the users that are currently connected to the page.

My approach would be to use random integers in the range of the length of a list of all users connected, as indices of the randomly selected users in the array.

I know this is something that I can do to keep track of all clients/sockets connected:

io.sockets.on('connect', function(client) {
    clients.push(client); 

    client.on('disconnect', function() {
        clients.splice(clients.indexOf(client), 1);
    });
});

But would it have issues with scaling? If so, what would be a better approach? Please advise.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top