Sven Eppler
Sven Eppler

Reputation: 1706

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

Upvotes: 9

Views: 7640

Answers (3)

Ben Matela
Ben Matela

Reputation: 72

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

Upvotes: 0

Christian Fritz
Christian Fritz

Reputation: 21374

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.

Upvotes: 3

Philipp Hancke
Philipp Hancke

Reputation: 17340

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

Upvotes: 9

Related Questions