},
};
-export function addPeer({ peerId, mediaStream, onOffer, socket }) {
+export function addPeer({
+ peerId,
+ shouldCreateOffer,
+ mediaStream,
+ onOffer,
+ socket,
+}) {
const peerConnection = new RTCPeerConnection(
{ iceServers: internals.kIceServers },
{ optional: [{ DtlsSrtpKeyAgreement: true }] },
};
peerConnection.onnegotiationneeded = async () => {
- console.debug("Creating RTC offer to ", peerId);
- const offer = await peerConnection.createOffer();
- await peerConnection.setLocalDescription(offer);
+ if (shouldCreateOffer) {
+ console.debug("Creating RTC offer to ", peerId);
+ const offer = await peerConnection.createOffer();
+ await peerConnection.setLocalDescription(offer);
- onOffer({ peerId, offer });
+ onOffer({ peerId, offer });
+ }
};
console.info(`There are now ${countPeers()} participants`);
}
export async function answerPeerOffer({ peerId, offer }) {
+ console.info(`Answering peer ${peerId}`);
const peerConnection = internals.peers[peerId];
const remoteDescription = new RTCSessionDescription(offer);
}
export async function processPeerAnswer({ peerId, answer }) {
+ console.info(`Processing answer for peer ${peerId}`);
const peerConnection = internals.peers[peerId];
const remoteDescription = new RTCSessionDescription(answer);
await peerConnection.setRemoteDescription(remoteDescription);
}
export async function addIceCandidate({ peerId, candidate }) {
+ console.info(`Adding ICE candidate for peer ${peerId}`);
const peerConnection = internals.peers[peerId];
+ console.info(peerConnection.signalingState);
const iceCandidate = new RTCIceCandidate(candidate);
await peerConnection.addIceCandidate(iceCandidate);
}
}
export function resetPeers() {
+ for (const connection of Object.values(internals.peers)) {
+ connection.close();
+ }
internals.peers = {};
document
.querySelectorAll(".junction-call-audio")