]> git.r.bdr.sh - rbdr/junction/blobdiff - server/index.js
Fix server
[rbdr/junction] / server / index.js
index 37104e1d717ed0bacd028412c7fc98b077bd6039..b5d5d1bd36b5ed9f7cd89c555afba5204c67eea8 100644 (file)
@@ -13,14 +13,14 @@ server.on('connection', (socket) => {
 
     console.log(`[CONNECT] New client connected with ID ${me}`);
 
 
     console.log(`[CONNECT] New client connected with ID ${me}`);
 
-    socket.on('join', (data) => {
+    socket.on('join', async (data) => {
         socket.join(data.url);
         socket.join(data.url);
-        const sockets = server.of(data.url).sockets.keys();
-        sockets.forEach((peerId) => {
-            if (peerId !== me) {
-                const peer = server.sockets.sockets.get(peerId)
+        const sockets = await server.in(data.url).fetchSockets()
+        console.log(sockets);
+        sockets.forEach((peer) => {
+            if (peer.id !== me) {
                 peer.emit(events.types.ADD_PEER, events.addPeer(me, false));
                 peer.emit(events.types.ADD_PEER, events.addPeer(me, false));
-                socket.emit(events.types.ADD_PEER, events.addPeer(peerId, true));
+                socket.emit(events.types.ADD_PEER, events.addPeer(peer.id, true));
             }
         });
         console.log(`[CONNECT] Client ${me} added to room ${data.url}`);
             }
         });
         console.log(`[CONNECT] Client ${me} added to room ${data.url}`);
@@ -33,20 +33,20 @@ server.on('connection', (socket) => {
         console.log(`[DISCONNECT] Client ${me} has disconnected and has been removed from all rooms`);
     });
 
         console.log(`[DISCONNECT] Client ${me} has disconnected and has been removed from all rooms`);
     });
 
-    socket.on('relayICECandidate', (data) => {
-        const sockets = server.of(data.url).sockets.keys();
-        sockets.forEach((peerId) => {
-            const peer = server.sockets.sockets.get(peerId)
+    socket.on('relayICECandidate', async (data) => {
+        const sockets = await server.in(data.url).fetchSockets()
+        console.log(sockets);
+        sockets.forEach((peer) => {
             peer.emit(events.types.ICE_CANDIDATE_RECEIVED, events.ICECandidateReceived(me, data.ice_candidate))
         });
 
         console.log(`[RELAY_ICE_CANDIDATE] ICE candidate for client ${me} has been relayed to all peers`);
     });
 
             peer.emit(events.types.ICE_CANDIDATE_RECEIVED, events.ICECandidateReceived(me, data.ice_candidate))
         });
 
         console.log(`[RELAY_ICE_CANDIDATE] ICE candidate for client ${me} has been relayed to all peers`);
     });
 
-    socket.on('relaySessionDescription', (data) => {
-        const sockets = server.of(data.url).sockets.keys();
-        sockets.forEach((peerId) => {
-            const peer = server.sockets.sockets.get(peerId)
+    socket.on('relaySessionDescription', async (data) => {
+        const sockets = await server.in(data.url).fetchSockets()
+        console.log(sockets);
+        sockets.forEach((peer) => {
             peer.emit(events.types.SESSION_DESCRIPTION_RECEIVED, events.SessionDescriptionReceived(me, data.session_description))
         });
 
             peer.emit(events.types.SESSION_DESCRIPTION_RECEIVED, events.SessionDescriptionReceived(me, data.session_description))
         });