+ internals.socket.on("answerReceived", async ({ answer, peerId }) => {
+ const peerConnection = internals.peers[peerId];
+ const remoteDescription = new RTCSessionDescription(answer);
+ await peerConnection.setRemoteDescription(remoteDescription);
+ });
+
+ internals.socket.on(
+ "ICECandidateReceived",
+ async ({ candidate, peerId }) => {
+ const peerConnection = internals.peers[peerId];
+ const iceCandidate = new RTCIceCandidate(candidate);
+ await peerConnection.addIceCandidate(iceCandidate);
+ },
+ );
+
+ internals.socket.on("removePeer", function ({ peerId }) {
+ delete internals.peers[peerId];
+ Peers.remove(peerId);
+ console.log(`There are now ${Peers.count()} participants`);
+ });
+ } catch (err) {