Skip to content

Commit f7d909e

Browse files
committed
Fix camera initialization failure on Firefox Android
When VideoConstraints has no constraints, return true.toJS instead of an empty object. Firefox Android rejects getUserMedia({video: {}}) with an AbortError, but accepts {video: true}. This fixes the camera initialization failure in availableCameras() on Firefox Android while maintaining compatibility with other browsers. Fixes flutter/flutter#XXXXX
1 parent 5fc2fd7 commit f7d909e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/camera/camera_web/lib/src/types/camera_options.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,16 @@ class VideoConstraints {
108108
// TODO(dit): package:web has a class for this. Use it instead of jsify and toJson.
109109
/// Convert `this` to something that can be used on the browser.
110110
JSAny toMediaStreamConstraints() {
111-
return <String, Object>{
111+
final constraints = <String, Object>{
112112
if (width != null) 'width': width!.toJson(),
113113
if (height != null) 'height': height!.toJson(),
114114
if (facingMode != null) 'facingMode': facingMode!.toJson(),
115115
if (deviceId != null) 'deviceId': <String, Object>{'exact': deviceId!},
116-
}.jsify()!;
116+
};
117+
118+
// Return true instead of empty object for better browser compatibility.
119+
// Firefox Android rejects getUserMedia({video: {}}) but accepts {video: true}.
120+
return constraints.isEmpty ? true.toJS : constraints.jsify()!;
117121
}
118122

119123
@override

0 commit comments

Comments
 (0)