+ // 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);
+ });
+
+
+ internals.socket.on('removePeer', function() {
+
+ delete internals.peers[data.peerId];
+ Peers.remove('id-'+(Peers.count() - 1)); // This is only for testing, don't use count to remove ids.
+ console.log(`There are now ${Peers.count()} participants`);
+ });
+ }
+ catch (err) {
+
+ internals.port.postMessage({
+ action: 'error'
+ });