Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera_web] Release the camera stream used to request video and audio permissions #4342

Merged
merged 8 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0+1

* Fix cameraNotReadable error that prevented access to the camera on some Android devices.

## 0.2.0

* Initial release, adapted from the Flutter [I/O Photobooth](https://photobooth.flutter.dev/) project.
2 changes: 1 addition & 1 deletion packages/camera/camera_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The web implementation of [`camera`][camera].
### Depend on the package

This package is not an [endorsed implementation](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin)
of the google_maps_flutter plugin yet, so you'll need to [add it explicitly](https://pub.dev/packages/camera_web/install).
of the camera plugin yet, so you'll need to [add it explicitly](https://pub.dev/packages/camera_web/install).

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ void main() {
).called(1);
});

testWidgets(
'releases the camera stream '
'used to request video and audio permissions', (tester) async {
final videoTrack = MockMediaStreamTrack();

var videoTrackStopped = false;
when(videoTrack.stop).thenAnswer((_) {
videoTrackStopped = true;
});

when(
() => cameraService.getMediaStreamForOptions(
CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
).thenAnswer(
(_) => Future.value(
FakeMediaStream([videoTrack]),
),
);

final _ = await CameraPlatform.instance.availableCameras();

expect(videoTrackStopped, isTrue);
});

testWidgets(
'gets a video stream '
'for a video input device', (tester) async {
Expand Down
5 changes: 4 additions & 1 deletion packages/camera/camera_web/lib/src/camera_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ class CameraPlugin extends CameraPlatform {
}

// Request video and audio permissions.
await _cameraService.getMediaStreamForOptions(
final cameraStream = await _cameraService.getMediaStreamForOptions(
CameraOptions(
audio: AudioConstraints(enabled: true),
),
);

// Release the camera stream used to request video and audio permissions.
cameraStream.getVideoTracks().forEach((videoTrack) => videoTrack.stop());

// Request available media devices.
final devices = await mediaDevices.enumerateDevices();

Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/plugins/tree/master/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.2.0
version: 0.2.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down