randomFree.js 779 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const io = require('socket.io')(3555);
  2. const nsp = io.of('/randomFree');
  3. class randomFree {
  4. constructor() {
  5. nsp.on('connection', (socket) => {
  6. console.log('someone connected');
  7. socket.join('queue');
  8. this.match();
  9. });
  10. }
  11. match() {
  12. let clients = Object.keys(nsp.sockets);
  13. console.log(clients);
  14. if(clients.length > 21) {
  15. let p1 = nsp.sockets[clients[0]];
  16. let p2 = nsp.sockets[clients[1]];
  17. //p1.leave('queue');
  18. //p1.join(clients[0] + clients[1]);
  19. //p2.leave('queue');
  20. //p2.join(clients[0] + clients[1]);
  21. console.log(io.sockets.adapter.sids);
  22. console.log("Matched!");
  23. console.log(Object.keys(nsp.to('queue').sockets));
  24. }
  25. }
  26. join(user){
  27. //join randomFree queue room
  28. }
  29. }
  30. module.exports = new randomFree();