Skip to content

Commit 78835ea

Browse files
authored
fix: ensure engine always has correct device id if switching camera fails (#820)
1 parent 335228d commit 78835ea

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/src/core/room.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,15 +1099,26 @@ extension RoomHardwareManagementMethods on Room {
10991099
Future<void> setVideoInputDevice(MediaDevice device) async {
11001100
final track = localParticipant?.videoTrackPublications.firstOrNull?.track;
11011101

1102+
final currentDeviceId =
1103+
engine.roomOptions.defaultCameraCaptureOptions.deviceId;
1104+
11021105
// Always update roomOptions so future tracks use the correct device
11031106
engine.roomOptions = engine.roomOptions.copyWith(
11041107
defaultCameraCaptureOptions: roomOptions.defaultCameraCaptureOptions
11051108
.copyWith(deviceId: device.deviceId),
11061109
);
11071110

1108-
if (track != null && selectedVideoInputDeviceId != device.deviceId) {
1109-
await track.switchCamera(device.deviceId);
1110-
Hardware.instance.selectedVideoInput = device;
1111+
try {
1112+
if (track != null && selectedVideoInputDeviceId != device.deviceId) {
1113+
await track.switchCamera(device.deviceId);
1114+
Hardware.instance.selectedVideoInput = device;
1115+
}
1116+
} catch (e) {
1117+
// if the switching actually fails, reset it to the previous deviceId
1118+
engine.roomOptions = engine.roomOptions.copyWith(
1119+
defaultCameraCaptureOptions: roomOptions.defaultCameraCaptureOptions
1120+
.copyWith(deviceId: currentDeviceId),
1121+
);
11111122
}
11121123
}
11131124

0 commit comments

Comments
 (0)