Skip to content

MediaStreamTrack.applyConstraints({ facingMode }) doesn't change stream feed #61

@smartboyathome

Description

@smartboyathome

We're trying to use LiveKit's fork of react-native-webrtc for our homegrown video streaming offering during a transition over to using full on LiveKit. We are able to create a camera feed for either the front or back camera on a device by specifying the facingMode constraint on the video when requesting a stream using getUserMedia(), like so:

const newStream = await navigator.mediaDevices.getUserMedia({
    audio: true,
    video: {
        facingMode: isFront ? 'user' : 'environment',
    },
});

However, when we then go to flip the camera using a toggle button, like in the following code, we end up with the original video stream from the first piece of code, but flipped vertically:

const videoTracks = streamRef.current.getVideoTracks();
const facingMode = isFront ? 'user' : 'environment';
if (videoTracks) {
    videoTracks.forEach((track) =>
        track.applyConstraints({
            facingMode,
        })
    );
}

It looks like how LiveKit itself handles this is by tearing down the old feed and then fetching a new feed using getUserMedia(), but our homegrown solution does not allow for that. I have confirmed this works with the upstream react-native-webrtc 124.0.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions