Search code examples
video-streamingwebrtcsdponeway

WebRTC one-way video call


we are fiddling around with WebRTC in our company. And i stumbled upon a weird thing, which i'm not sure is by design in WebRTC or an implementaiton error on our side.

We currently have a simple WebApp which displays a Contact-List of online contacts. One can now simply call any user on the contact list.

The Caller and the Callee are free to choose to share WebCam and/or Audio. Which is then respected by GetUserMedia() (MediaConstraints).

The weird thing now: The clients (Chrome 65) only negotiate a Video-Call if the Caller starts with Video enabled. If the caller is not offering his webcam, we don't get the callee webcam streamed back (if he allowed it).

But when the Caller initiates the Call with his webcam enabled and the Callee than decides not to show his, everything works as expected. (Only Caller has live stream).

If both parties agree on showing video, we get bideractional video streaming.

Anybody got some internal knowledge if this is meant to be this way? Isn't it possible to call someone without showing your own webcam, but later on seeing the callees webcam?

Thanks in advance, Sven


Solution

  • Philipp's answer works great. However, by now the proposed option is marked legacy and should not be used anymore. The new way of doing this is to add a video transceiver to the connection before creating the offer:

    connection.addTransceiver('video');
    // this step seems to be optional:
    connection.getTransceivers().forEach(t => t.direction = 'recvonly');
    
    connection.createOffer();
    

    Credit to https://niccoloterreri.com/webrtc-with-transceivers. For the optional step, see https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpTransceiver/direction.