Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: add media camera error codes
  • Loading branch information
bselwe committed Jul 30, 2021
commit 6c7531cd869f25c9a9a7915a7a57207c099314f5
71 changes: 71 additions & 0 deletions packages/camera/camera_web/lib/src/types/camera_error_code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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 'dart:html' as html;

/// Error codes that may occur during the camera initialization,
/// configuration or video streaming.
class CameraErrorCode {
const CameraErrorCode._(this._type);

final String _type;

@override
String toString() => _type;

/// The camera is not supported.
static const CameraErrorCode notSupported =
CameraErrorCode._('cameraNotSupported');

/// The camera is not found.
static const CameraErrorCode notFound = CameraErrorCode._('cameraNotFound');

/// The camera is not readable.
static const CameraErrorCode notReadable =
CameraErrorCode._('cameraNotReadable');

/// The camera options are impossible to satisfy.
static const CameraErrorCode overconstrained =
CameraErrorCode._('cameraOverconstrained');

/// The camera cannot be used or the permission
/// to access the camera is not granted.
static const CameraErrorCode permissionDenied =
CameraErrorCode._('cameraPermission');

/// The camera options are incorrect or attempted
/// to access the media input from an insecure context.
static const CameraErrorCode type = CameraErrorCode._('cameraType');

/// Some problem occurred that prevented the camera from being used.
static const CameraErrorCode abort = CameraErrorCode._('cameraAbort');

/// The user media support is disabled in the current browser.
static const CameraErrorCode security = CameraErrorCode._('cameraSecurity');

/// The camera metadata is missing.
static const CameraErrorCode missingMetadata =
CameraErrorCode._('cameraMissingMetadata');

/// An unknown camera error.
static const CameraErrorCode unknown = CameraErrorCode._('cameraUnknown');

/// Returns a camera error code based on the media error.
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/MediaError/code
static CameraErrorCode fromMediaError(html.MediaError error) {
switch (error.code) {
case html.MediaError.MEDIA_ERR_ABORTED:
return CameraErrorCode._('mediaErrorAborted');
case html.MediaError.MEDIA_ERR_NETWORK:
return CameraErrorCode._('mediaErrorNetwork');
case html.MediaError.MEDIA_ERR_DECODE:
return CameraErrorCode._('mediaErrorDecode');
case html.MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:
return CameraErrorCode._('mediaErrorSourceNotSupported');
default:
return CameraErrorCode._('mediaErrorUnknown');
}
}
}
32 changes: 0 additions & 32 deletions packages/camera/camera_web/lib/src/types/camera_error_codes.dart

This file was deleted.

2 changes: 1 addition & 1 deletion packages/camera/camera_web/lib/src/types/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'camera_error_codes.dart';
export 'camera_error_code.dart';
export 'camera_metadata.dart';
export 'camera_options.dart';
export 'media_device_kind.dart';