Skip to content

Commit f59a2bb

Browse files
authored
fix: update camera deviceId when track is null (#814)
If there is no `LocalVideoTrack` while we are in the call, `setVideoInputDevice` will skip the device selection as a whole since `track` is `null`. This will result in a wrong device being used to create a track. ```mermaid flowchart TD A["Join room with video OFF (X)"] --> B[No video track published] B --> C["Select new camera device (Y)"] C --> D{Is video track available?} D -- No --> E[track is null, switchCamera skipped] E --> F[roomOptions not updated] F --> G[Turn on video] G --> H["New track uses old device (X)"] H --> I[Camera shows wrong input] ```
1 parent 59d1b2c commit f59a2bb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/src/core/room.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,17 +1097,17 @@ extension RoomHardwareManagementMethods on Room {
10971097
/// Set video input device.
10981098
Future<void> setVideoInputDevice(MediaDevice device) async {
10991099
final track = localParticipant?.videoTrackPublications.firstOrNull?.track;
1100-
if (track == null) return;
1101-
if (selectedVideoInputDeviceId != device.deviceId) {
1100+
1101+
// Always update roomOptions so future tracks use the correct device
1102+
engine.roomOptions = engine.roomOptions.copyWith(
1103+
defaultCameraCaptureOptions: roomOptions.defaultCameraCaptureOptions
1104+
.copyWith(deviceId: device.deviceId),
1105+
);
1106+
1107+
if (track != null && selectedVideoInputDeviceId != device.deviceId) {
11021108
await track.switchCamera(device.deviceId);
11031109
Hardware.instance.selectedVideoInput = device;
11041110
}
1105-
engine.roomOptions = engine.roomOptions.copyWith(
1106-
defaultCameraCaptureOptions:
1107-
roomOptions.defaultCameraCaptureOptions.copyWith(
1108-
deviceId: device.deviceId,
1109-
),
1110-
);
11111111
}
11121112

11131113
/// [speakerOn] set speakerphone on or off, by default wired/bluetooth headsets will still

0 commit comments

Comments
 (0)