File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments