const io = require('socket.io')(3555); const nsp = io.of('/randomFree'); class randomFree { constructor() { nsp.on('connection', (socket) => { console.log('someone connected'); socket.join('queue'); this.match(); }); } match() { let clients = Object.keys(nsp.sockets); console.log(clients); if(clients.length > 21) { let p1 = nsp.sockets[clients[0]]; let p2 = nsp.sockets[clients[1]]; //p1.leave('queue'); //p1.join(clients[0] + clients[1]); //p2.leave('queue'); //p2.join(clients[0] + clients[1]); console.log(io.sockets.adapter.sids); console.log("Matched!"); console.log(Object.keys(nsp.to('queue').sockets)); } } join(user){ //join randomFree queue room } } module.exports = new randomFree();