X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/06b7617a863d00dbcc91d1e46f09942c6aad366e..e832466bb0afef51770303714f60577ac6bf1a0f:/extension/peers.js?ds=sidebyside diff --git a/extension/peers.js b/extension/peers.js index f9153fd..fced108 100644 --- a/extension/peers.js +++ b/extension/peers.js @@ -13,7 +13,13 @@ 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 +48,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 +66,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 +79,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); }