|
@@ -12,22 +12,41 @@ class randomFree {
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
- }
|
|
|
+ nsp.in('queue').clients((error, clients) => {
|
|
|
+ if (error) throw error;
|
|
|
+
|
|
|
+ if(clients.length > 1) {
|
|
|
+ let p1 = nsp.sockets[clients[0]];
|
|
|
+ let p2 = nsp.sockets[clients[1]];
|
|
|
+
|
|
|
+ const channel = clients[0] + clients[1];
|
|
|
+
|
|
|
+ let err = (e) => {
|
|
|
+ if(e)throw e;
|
|
|
+ return 0;
|
|
|
+ };
|
|
|
+
|
|
|
+ p1.leave('queue', err);
|
|
|
+ p1.join(channel, err);
|
|
|
+ p2.leave('queue', err);
|
|
|
+ p2.join(channel, err);
|
|
|
+ // setTimeout(() => {
|
|
|
+ // console.log("MATCH: " +channel+ " !");
|
|
|
+ // console.log(Object.keys(nsp.in(channel).sockets));
|
|
|
+ // console.log("QUEUE!");
|
|
|
+ // console.log(Object.keys(nsp.in('queue').sockets));
|
|
|
+ // }, 5000);
|
|
|
+ nsp.in(channel).clients((err, clients) => {
|
|
|
+ console.log('Channel: ' + channel);
|
|
|
+ console.log(clients);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ nsp.in('queue').clients((err, clients) => {
|
|
|
+ console.log('Queue');
|
|
|
+ console.log(clients)
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
join(user){
|