X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/ff9e30b6132098d29739103abb415cc7410166fc..8c7fb565690890d57b6af20ad0771a48cf82b4c7:/server/index.js 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)) });