]> git.r.bdr.sh - rbdr/junction/commitdiff
Fix server
authorRuben Beltran del Rio <redacted>
Mon, 28 Aug 2023 20:34:32 +0000 (20:34 +0000)
committerRuben Beltran del Rio <redacted>
Mon, 28 Aug 2023 20:34:32 +0000 (20:34 +0000)
server/index.js

index 66f47aeefb934ac22c0ed4dd9417ae662690dd71..b5d5d1bd36b5ed9f7cd89c555afba5204c67eea8 100644 (file)
@@ -13,14 +13,14 @@ server.on('connection', (socket) => {
 
     console.log(`[CONNECT] New client connected with ID ${me}`);
 
-    socket.on('join', (data) => {
+    socket.on('join', async (data) => {
         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));
-                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}`);
@@ -33,20 +33,20 @@ server.on('connection', (socket) => {
         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`);
     });
 
-    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))
         });