X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/06b7617a863d00dbcc91d1e46f09942c6aad366e..3f2e36eabf1494ac60a3cf533d3db86d25a6cc39:/extension/peers.js?ds=inline diff --git a/extension/peers.js b/extension/peers.js index f9153fd..be494b0 100644 --- a/extension/peers.js +++ b/extension/peers.js @@ -13,7 +13,7 @@ const internals = { }, }; -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 }] }, @@ -42,11 +42,13 @@ export function addPeer({ peerId, mediaStream, onOffer, socket }) { }; 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`); @@ -58,6 +60,7 @@ export function removePeer({ peerId }) { } export async function answerPeerOffer({ peerId, offer }) { + console.info(`Answering peer ${peerId}`); const peerConnection = internals.peers[peerId]; const remoteDescription = new RTCSessionDescription(offer); @@ -70,13 +73,16 @@ export async function answerPeerOffer({ peerId, 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); }