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

[camera_web] Add camera errors handling #4207

Merged
merged 9 commits into from
Jul 30, 2021
Merged

[camera_web] Add camera errors handling #4207

merged 9 commits into from
Jul 30, 2021

Conversation

bselwe
Copy link
Contributor

@bselwe bselwe commented Jul 30, 2021

Adds camera errors handling to the web implementation of the camera platform interface.

  • Added media camera error codes to CameraErrorCode (media error).
  • Added CameraWebException thrown when the camera reports an initialization, configuration or video streaming error, or enters into an unexpected state.
  • Moved getMediaStreamForOptions to CameraSettings - returns a media stream for the camera constrained by the given options.
  • Added camera errors handling in the camera plugin.
    • Methods will now throw a PlatformException rather than a DomException/CameraException for consistency with the MethodChannelCamera implementation. The only exemptions are availableCameras and createCamera that may throw a CameraException.
    • Each CameraWebException is caught and emitted on the onCameraError stream.
    • Added camera video element's onError and onAbort events to the onCameraError stream.

Part of flutter/flutter#45297.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@bselwe
Copy link
Contributor Author

bselwe commented Jul 30, 2021

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the momentum going. Since CameraSettings is an internal implementation detail, it can be renamed/split in a further PR.

Comment on lines +13 to 15
/// A utility to fetch, map camera settings and
/// obtain the camera stream.
class CameraSettings {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it time to find a better name for CameraSettings? Is it maybe doing too much? Slightly confusing naming with CameraOptions?

Maybe the parts regarding the management of the Camera Stream should be moved to a new class? Is this class more of a CameraStreamsHelper/Handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! It is currently responsible for getting the camera stream based on CameraOptions, getting the facing mode setting based on the camera video track and mapping camera video track settings. How about renaming it to a CameraService (this way we will no longer mix settings with options)?

I'm also okay with extracting the camera stream logic to a separate class (CameraStreams.getStreamForOptions maybe?) if you prefer it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CameraService sounds good to me. For the conversion functions, what I've been doing is to have a fat "convert.dart" with a bunch of functions there that translate from one type to my own (and vice-versa). See convert.dart in google maps. I normally prefer those functions to be stateless, so they can be just utility functions (they don't need to belong to any class or namespace).

@ditman ditman added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Jul 30, 2021
@fluttergithubbot fluttergithubbot merged commit 477a13d into flutter:master Jul 30, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 30, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: camera platform-web waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants