Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createLocalTracks with video device with exact id, exact constraint is not maintained on re-enabling camera #1316

Open
mdanilakis opened this issue Nov 18, 2024 · 3 comments · May be fixed by #1388

Comments

@mdanilakis
Copy link

Describe the bug

const video = {
  deviceId: { exact: "deviceId" },
};

const audio = { ... };

const tracks = await createLocalTracks({ video, audio });

Constraining the deviceId with exact on Track creation.

Expectation: internally getUserMedia is called with exact the first time, and should be called again on restart (e.g. unmute of camera).

What happens: internally getUserMedia is called with exact the first time, but on unmute the exact constraint is removed resulting in selecting a different video stream (from a different device) on unmute (tested in Chrome).

Where I think the issue is: https://github.com/livekit/client-sdk-js/pull/773/files

Why is the browser returning a different stream given it actually returned it correctly the first time: I don't know (this is where the whole getUserMedia madness starts).

Reproduction

  1. Create LocalTrack(s) using:
const video = {
  deviceId: { exact: "deviceId" },
};

const audio = { ... };

const tracks = await createLocalTracks({ video, audio });
  1. Verify correct camera feed
  2. Switch off camera e.g. localParticipat.setCameraEnabled(false)
  3. Switch on camera
  4. Camera feed is from a different device from the one specified in exact

Note: it happens under specific circumstances (hard to reproduce on some clients, reproducible with others - e.g. with a different set of devices).

Logs

No response

System Info

Mac OS, Chrome 130.0.6723.119, LiveKit Client 2.1.5

Severity

annoyance

Additional Information

No response

@iiiyx
Copy link

iiiyx commented Jan 28, 2025

I have (I think) a better reproduction scenario, 100% reproducible:

  1. Publish video using NOT a default camera (the default one is usually the first one in the list).
const videoTrack = await createLocalVideoTrack({
  deviceId: { exact: YOUR_SELECTED_CAMERA_ID },
});
const videoTrackPublication = await room!.localParticipant.publishTrack(
  videoTrack,
  {
    name: YOUR_SELECTED_CAMERA_ID // set the publication name for convenience
  },
);
  1. Mute the camera using
const videoTrackPublication = room.localParticipant.getTrackPublicationByName(YOUR_SELECTED_CAMERA_ID);
videoTrackPublication.mute();
  1. Unmute it back
const videoTrackPublication = room.localParticipant.getTrackPublicationByName(YOUR_SELECTED_CAMERA_ID);
videoTrackPublication.unmute();

Expected result: the selected camera is unmuted

Actual result: the default camera is unmuted

The issue comes from here:

await this.restartTrack();

async restartTrack(options?: VideoCaptureOptions) {

The constraints are vanished and the browser starts capturing the default video input device.

This is a major issue for users who use the second camera and for the apps that use all available video input devices (e.g., medical apps).

@lukasIO
Copy link
Contributor

lukasIO commented Jan 29, 2025

thanks for the report, could you provide some debug logs?
The exact parameter is not held on to after restarts currently, but the deviceId constraint as ideal should persist. This is due to the fact that we have to deal with scenarios in which the selected device got unplugged while muted.

@lukasIO lukasIO linked a pull request Jan 29, 2025 that will close this issue
@lukasIO
Copy link
Contributor

lukasIO commented Jan 29, 2025

I gave this a shot in #1388, could you please test with that branch and see if it resolves the issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants