Skip to content

Commit c65c2d4

Browse files
committed
[camera_web] 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 c65c2d4

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

packages/camera/camera_web/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## NEXT
1+
## 0.3.6
22

3-
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
3+
* Fixes camera initialization failure on Firefox Android by using `{video: true}` instead of `{video: {}}` when no video constraints are specified.
44

55
## 0.3.5
66

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 Map<String, Object> 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

packages/camera/camera_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_web
22
description: A Flutter plugin for getting information about and controlling the camera on Web.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.3.5
5+
version: 0.3.6
66

77
environment:
88
sdk: ^3.7.0

0 commit comments

Comments
 (0)