+ socket.on('offerReceived', async (data) => {
+
+ const peerConnection = internals.peers[data.peerId];
+
+ const offer = new RTCSessionDescription(data.offer);
+ await peerConnection.setRemoteDescription(offer);
+
+ const answer = await peerConnection.createAnswer();
+ await peerConnection.setLocalDescription(answer);
+
+ // Send the answer to the peer
+ socket.emit('relayAnswer', { answer, peerId: data.peerId });
+ });
+
+ socket.on('answerReceived', async (data) => {
+
+ const peerConnection = internals.peers[data.peerId];
+ const answer = new RTCSessionDescription(data.answer);
+ await peerConnection.setRemoteDescription(answer);
+ });
+
+ socket.on('ICECandidateReceived', async (data) => {
+
+ const peerConnection = internals.peers[data.peerId];
+ const candidate = new RTCIceCandidate(data.candidate);
+ await peerConnection.addIceCandidate(candidate);
+ });
+
+