Search code examples
safariwebrtcmobile-safari

WebRTC Safari: No reception if no emission (more precisely no ICE candidate callback)


The following JS fiddle shows that Safari doesn't want to receive a video stream if a local video track has not been added. More precisely, the ICE candidate callback never happens.

https://jsfiddle.net/2r5mocfz/

  • Using Chrome: Click on "Without Local Camera", you are getting the ICE candidate callback with the alert messages.

  • Using Safari: Click on "Without Local Camera", you are NOT getting the ICE candidate callback. You are getting it only if you click on "With Local Camera" and accept to use your local camera.

The javascript code is:

function handleICECandidateEvent(event) {
    alert("ICE callback");
    console.log(event);
}

async function start_(arg) {
    alert("Starting " + arg);
    let peerConnection = new RTCPeerConnection({iceServers:[{urls: 'stun:stun1.l.google.com:19302'}]});
    peerConnection.onicecandidate = handleICECandidateEvent;
  if (arg) {
        const s = await navigator.mediaDevices.getUserMedia({video:true});
        s.getTracks().forEach(track => {peerConnection.addTrack(track, s);});
  }
    const offer = await peerConnection.createOffer({offerToReceiveAudio: true, offerToReceiveVideo: true});
    await peerConnection.setLocalDescription(offer);
}

Is there any workaround? I would like on Safari to receive a WebRTC video stream without having to involve a local camera with its permission request?


Solution

  • Safari choose not implement the "legacy" offerToReceive* options described in https://w3c.github.io/webrtc-pc/#legacy-configuration-extensions

    You can either port your code to use addTransceiver or use the webrtc-adapter package which polyfills this.