WebRTC one-way video call
Asked Answered
R

3

9

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

Raising answered 24/4, 2018 at 12:47 Comment(3)
I stumbled over the same issue. No success yet :(Sickly
Check out the answer from Philipp. Worked like a charm for me :) Mozilla documented the additional Options for peerConnection.createOffer() developer.mozilla.org/de/docs/Web/API/RTCPeerConnection/…Raising
It works now. Thx ;)Sickly
L
3

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.

Lunar answered 17/7, 2021 at 0:11 Comment(1)
Oh, great follow up answer! Since it is the official way now, i will mark this as the answer. :)Raising
C
9

try pc.createOffer({offerToReceiveVideo: true}) instead of calling it without those constraints.

Catanddog answered 24/4, 2018 at 13:28 Comment(1)
oh man, I've just spent three hours hitting my head against a wall until I found this answer of yours. Thank you so much -- you saved my day! 🎉Lunar
L
3

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.

Lunar answered 17/7, 2021 at 0:11 Comment(1)
Oh, great follow up answer! Since it is the official way now, i will mark this as the answer. :)Raising
I
0

For my case using React the following works:

Firstly if the current user is the CALLER:

// We have getUserMedia()
const localStream = await navigator.mediaDevices.getUserMedia({
    video: true,
    audio: true,
});
  
localStream.getTracks().forEach((track) => {
  pc.addTrack(track, localStream);
});

// Also important the createOffer()
const offerDescription = await pc.createOffer({offerToReceiveAudio: true,offerToReceiveVideo: true});

localRef.current.srcObject = localStream;

Else if current user is the CALLEE:

No calling of getUserMedia()...

No calling of pc.addTrack(addStream)...

const remoteStream = new MediaStream();

pc.ontrack = (event: RTCTrackEvent) => {
    event.streams[0].getTracks().forEach((track) => {
    remoteStream.addTrack(track);
   });
};

remoteRef.current.srcObject = remoteStream;

Used some info from here: One way communication with WEBRTC

Illusage answered 10/12, 2023 at 4:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.