[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
* Removes obsolete null checks on non-nullable values.

View File

@ -98,24 +98,18 @@ void main() {
);
});
testWidgets('requests video and audio permissions',
(WidgetTester tester) async {
testWidgets('requests video permissions', (WidgetTester tester) async {
final List<CameraDescription> _ =
await CameraPlatform.instance.availableCameras();
verify(
() => cameraService.getMediaStreamForOptions(
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
() => cameraService.getMediaStreamForOptions(const CameraOptions()),
).called(1);
});
testWidgets(
'releases the camera stream '
'used to request video and audio permissions',
(WidgetTester tester) async {
'used to request video permissions', (WidgetTester tester) async {
final MockMediaStreamTrack videoTrack = MockMediaStreamTrack();
bool videoTrackStopped = false;
@ -124,11 +118,7 @@ void main() {
});
when(
() => cameraService.getMediaStreamForOptions(
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
() => cameraService.getMediaStreamForOptions(const CameraOptions()),
).thenAnswer(
(_) => Future<MediaStream>.value(
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 =
await _cameraService.getMediaStreamForOptions(
const CameraOptions(
audio: AudioConstraints(enabled: true),
),
);
await _cameraService.getMediaStreamForOptions(const CameraOptions());
// Release the camera stream used to request video and audio permissions.
// Release the camera stream used to request video permissions.
cameraStream
.getVideoTracks()
.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.
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
version: 0.3.1+4
version: 0.3.2
environment:
sdk: ">=2.18.0 <4.0.0"