- // WE WILL NOT LOSE TADA SUPPORT
- if (typeof source === 'string') {
- audioElement.src = source;
+ return audioElement;
+ },
+};
+
+export function addPeer({ peerId, shouldCreateOffer, mediaStream, onOffer, socket }) {
+ const peerConnection = new RTCPeerConnection(
+ { iceServers: internals.kIceServers },
+ { optional: [{ DtlsSrtpKeyAgreement: true }] },
+ );
+
+ internals.peers[peerId] = peerConnection;
+ mediaStream.getTracks().forEach((track) => {
+ peerConnection.addTrack(track, mediaStream);
+ });
+
+ peerConnection.onicecandidate = (event) => {
+ if (event.candidate) {
+ socket.emit("relayICECandidate", {
+ peerId: peerId,
+ candidate: event.candidate,
+ });