[camera] Removed the microphone permission request from availableCameras on Web (#4263)

I've removed the microphone permission request from availableCameras on Web. 
Adding an additional parameter would break either web or android/ios, so in my opinion it is better to change the web behavior.

Changes were made based on this issue: https://github.com/flutter/flutter/issues/112277
This commit is contained in:
Maciej Brzeziński
2023-07-31 17:27:51 +02:00
committed by GitHub
parent 60e9a542f9
commit 9074ea9e38
4 changed files with 12 additions and 22 deletions

View File

@ -1,3 +1,7 @@
## 0.3.2
* Changes `availableCameras` to not ask for the microphone permission.
## 0.3.1+4 ## 0.3.1+4
* Removes obsolete null checks on non-nullable values. * Removes obsolete null checks on non-nullable values.

View File

@ -98,24 +98,18 @@ void main() {
); );
}); });
testWidgets('requests video and audio permissions', testWidgets('requests video permissions', (WidgetTester tester) async {
(WidgetTester tester) async {
final List<CameraDescription> _ = final List<CameraDescription> _ =
await CameraPlatform.instance.availableCameras(); await CameraPlatform.instance.availableCameras();
verify( verify(
() => cameraService.getMediaStreamForOptions( () => cameraService.getMediaStreamForOptions(const CameraOptions()),
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
).called(1); ).called(1);
}); });
testWidgets( testWidgets(
'releases the camera stream ' 'releases the camera stream '
'used to request video and audio permissions', 'used to request video permissions', (WidgetTester tester) async {
(WidgetTester tester) async {
final MockMediaStreamTrack videoTrack = MockMediaStreamTrack(); final MockMediaStreamTrack videoTrack = MockMediaStreamTrack();
bool videoTrackStopped = false; bool videoTrackStopped = false;
@ -124,11 +118,7 @@ void main() {
}); });
when( when(
() => cameraService.getMediaStreamForOptions( () => cameraService.getMediaStreamForOptions(const CameraOptions()),
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
).thenAnswer( ).thenAnswer(
(_) => Future<MediaStream>.value( (_) => Future<MediaStream>.value(
FakeMediaStream(<MediaStreamTrack>[videoTrack]), FakeMediaStream(<MediaStreamTrack>[videoTrack]),

View File

@ -96,15 +96,11 @@ class CameraPlugin extends CameraPlatform {
); );
} }
// Request video and audio permissions. // Request video permissions only.
final html.MediaStream cameraStream = final html.MediaStream cameraStream =
await _cameraService.getMediaStreamForOptions( await _cameraService.getMediaStreamForOptions(const CameraOptions());
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
);
// Release the camera stream used to request video and audio permissions. // Release the camera stream used to request video permissions.
cameraStream cameraStream
.getVideoTracks() .getVideoTracks()
.forEach((html.MediaStreamTrack videoTrack) => videoTrack.stop()); .forEach((html.MediaStreamTrack videoTrack) => videoTrack.stop());

View File

@ -2,7 +2,7 @@ name: camera_web
description: A Flutter plugin for getting information about and controlling the camera on Web. description: A Flutter plugin for getting information about and controlling the camera on Web.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_web repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.3.1+4 version: 0.3.2
environment: environment:
sdk: ">=2.18.0 <4.0.0" sdk: ">=2.18.0 <4.0.0"