From: Ruben Beltran del Rio Date: Mon, 28 Aug 2023 20:34:32 +0000 (+0000) Subject: Fix server X-Git-Url: https://git.r.bdr.sh/rbdr/junction/commitdiff_plain/8c7fb565690890d57b6af20ad0771a48cf82b4c7 Fix server --- diff --git a/server/index.js b/server/index.js index 66f47ae..b5d5d1b 100644 --- a/server/index.js +++ b/server/index.js @@ -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)) });