This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera_web] Add CameraOptions used to constrain the camera audio and video
#4164
Merged
fluttergithubbot
merged 11 commits into
flutter:master
from
VeryGoodOpenSource:feat/camera-web-options
Jul 19, 2021
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ff0a2bb
feat: add camera options
bselwe c842c3d
test: add camera options tests
bselwe 34a1581
feat: define value equality for camera options
bselwe 79241c8
test: add camera options value equality tests
bselwe d6fba4b
feat: use exact for device id in video constraints
bselwe 73562bf
chore: update camera_web version
bselwe 15aa4c2
docs: update comments
bselwe 556e2fc
docs: update comments
bselwe 50be75e
docs: add copyright
bselwe a07ec99
refactor: update test imports
bselwe f243510
Move purely unit tests to test dir. Do not bump versions yet.
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 0.1.1 | ||
|
|
||
| * Added CameraOptions used to constrain the camera audio and video. | ||
|
|
||
| ## 0.1.0 | ||
|
|
||
| * Initial release | ||
203 changes: 203 additions & 0 deletions
203
packages/camera/camera_web/example/integration_test/types/camera_options_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:camera_web/src/types/types.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| group('CameraOptions', () { | ||
| testWidgets('serializes correctly', (tester) async { | ||
| final cameraOptions = CameraOptions( | ||
| audio: AudioConstraints(enabled: true), | ||
| video: VideoConstraints( | ||
| facingMode: FacingModeConstraint.exact(CameraType.user), | ||
| ), | ||
| ); | ||
|
|
||
| expect( | ||
| cameraOptions.toJson(), | ||
| equals({ | ||
| 'audio': cameraOptions.audio.toJson(), | ||
| 'video': cameraOptions.video.toJson(), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| CameraOptions( | ||
| audio: AudioConstraints(enabled: false), | ||
| video: VideoConstraints( | ||
| facingMode: FacingModeConstraint(CameraType.environment), | ||
| width: VideoSizeConstraint(minimum: 10, ideal: 15, maximum: 20), | ||
| height: VideoSizeConstraint(minimum: 15, ideal: 20, maximum: 25), | ||
| deviceId: 'deviceId', | ||
| ), | ||
| ), | ||
| equals( | ||
| CameraOptions( | ||
| audio: AudioConstraints(enabled: false), | ||
| video: VideoConstraints( | ||
| facingMode: FacingModeConstraint(CameraType.environment), | ||
| width: VideoSizeConstraint(minimum: 10, ideal: 15, maximum: 20), | ||
| height: VideoSizeConstraint(minimum: 15, ideal: 20, maximum: 25), | ||
| deviceId: 'deviceId', | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('AudioConstraints', () { | ||
| testWidgets('serializes correctly', (tester) async { | ||
| expect( | ||
| AudioConstraints(enabled: true).toJson(), | ||
| equals(true), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| AudioConstraints(enabled: true), | ||
| equals(AudioConstraints(enabled: true)), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('VideoConstraints', () { | ||
| testWidgets('serializes correctly', (tester) async { | ||
| final videoConstraints = VideoConstraints( | ||
| facingMode: FacingModeConstraint.exact(CameraType.user), | ||
| width: VideoSizeConstraint(ideal: 100, maximum: 100), | ||
| height: VideoSizeConstraint(ideal: 50, maximum: 50), | ||
| deviceId: 'deviceId', | ||
| ); | ||
|
|
||
| expect( | ||
| videoConstraints.toJson(), | ||
| equals({ | ||
| 'facingMode': videoConstraints.facingMode!.toJson(), | ||
| 'width': videoConstraints.width!.toJson(), | ||
| 'height': videoConstraints.height!.toJson(), | ||
| 'deviceId': { | ||
| 'exact': 'deviceId', | ||
| } | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| VideoConstraints( | ||
| facingMode: FacingModeConstraint.exact(CameraType.environment), | ||
| width: VideoSizeConstraint(minimum: 90, ideal: 100, maximum: 100), | ||
| height: VideoSizeConstraint(minimum: 40, ideal: 50, maximum: 50), | ||
| deviceId: 'deviceId', | ||
| ), | ||
| equals( | ||
| VideoConstraints( | ||
| facingMode: FacingModeConstraint.exact(CameraType.environment), | ||
| width: VideoSizeConstraint(minimum: 90, ideal: 100, maximum: 100), | ||
| height: VideoSizeConstraint(minimum: 40, ideal: 50, maximum: 50), | ||
| deviceId: 'deviceId', | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('FacingModeConstraint', () { | ||
| group('ideal', () { | ||
| testWidgets( | ||
| 'serializes correctly ' | ||
| 'for environment camera type', (tester) async { | ||
| expect( | ||
| FacingModeConstraint(CameraType.environment).toJson(), | ||
| equals({'ideal': 'environment'}), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets( | ||
| 'serializes correctly ' | ||
| 'for user camera type', (tester) async { | ||
| expect( | ||
| FacingModeConstraint(CameraType.user).toJson(), | ||
| equals({'ideal': 'user'}), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| FacingModeConstraint(CameraType.user), | ||
| equals(FacingModeConstraint(CameraType.user)), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('exact', () { | ||
| testWidgets( | ||
| 'serializes correctly ' | ||
| 'for environment camera type', (tester) async { | ||
| expect( | ||
| FacingModeConstraint.exact(CameraType.environment).toJson(), | ||
| equals({'exact': 'environment'}), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets( | ||
| 'serializes correctly ' | ||
| 'for user camera type', (tester) async { | ||
| expect( | ||
| FacingModeConstraint.exact(CameraType.user).toJson(), | ||
| equals({'exact': 'user'}), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| FacingModeConstraint.exact(CameraType.environment), | ||
| equals(FacingModeConstraint.exact(CameraType.environment)), | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| group('VideoSizeConstraint ', () { | ||
| testWidgets('serializes correctly', (tester) async { | ||
| expect( | ||
| VideoSizeConstraint( | ||
| minimum: 200, | ||
| ideal: 400, | ||
| maximum: 400, | ||
| ).toJson(), | ||
| equals({ | ||
| 'min': 200, | ||
| 'ideal': 400, | ||
| 'max': 400, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('supports value equality', (tester) async { | ||
| expect( | ||
| VideoSizeConstraint( | ||
| minimum: 100, | ||
| ideal: 200, | ||
| maximum: 300, | ||
| ), | ||
| equals( | ||
| VideoSizeConstraint( | ||
| minimum: 100, | ||
| ideal: 200, | ||
| maximum: 300, | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.