Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2024-10-05 12:14:01 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
47e39d0f8d4f9ddddf1f0de422fe753f9d4643e3
47e39d0f
1 parent
1e7154cf
update comment
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
16 deletions
lib/src/web/mobile_scanner_web.dart
lib/src/web/mobile_scanner_web.dart
View file @
47e39d0
...
...
@@ -30,8 +30,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
BarcodeReader
?
_barcodeReader
;
/// The stream controller for the barcode stream.
final
StreamController
<
BarcodeCapture
>
_barcodesController
=
StreamController
.
broadcast
();
final
StreamController
<
BarcodeCapture
>
_barcodesController
=
StreamController
.
broadcast
();
/// The subscription for the barcode stream.
StreamSubscription
<
Object
?>?
_barcodesSubscription
;
...
...
@@ -45,8 +44,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
/// because that is the only property for video tracks that can be observed.
///
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#instance_properties_of_video_tracks
final
StreamController
<
MediaTrackSettings
>
_settingsController
=
StreamController
.
broadcast
();
final
StreamController
<
MediaTrackSettings
>
_settingsController
=
StreamController
.
broadcast
();
/// The texture ID for the camera view.
int
_textureId
=
1
;
...
...
@@ -65,12 +63,10 @@ class MobileScannerWeb extends MobileScannerPlatform {
Stream
<
BarcodeCapture
?>
get
barcodesStream
=>
_barcodesController
.
stream
;
@override
Stream
<
TorchState
>
get
torchStateStream
=>
_settingsController
.
stream
.
map
((
_
)
=>
TorchState
.
unavailable
);
Stream
<
TorchState
>
get
torchStateStream
=>
_settingsController
.
stream
.
map
((
_
)
=>
TorchState
.
unavailable
);
@override
Stream
<
double
>
get
zoomScaleStateStream
=>
_settingsController
.
stream
.
map
((
_
)
=>
1.0
);
Stream
<
double
>
get
zoomScaleStateStream
=>
_settingsController
.
stream
.
map
((
_
)
=>
1.0
);
/// Create the [HTMLVideoElement] along with its parent container [HTMLDivElement].
HTMLVideoElement
_createVideoElement
(
int
textureId
)
{
...
...
@@ -143,6 +139,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
final
JSArray
<
JSString
>?
facingModes
=
capabilities
.
facingModeNullable
;
// TODO: this is an empty array on MacOS Chrome, where there is no facing mode, but one, user facing camera.
// We might be able to add a workaround, using the label of the video track.
// Facing mode is not supported by this track, do nothing.
if
(
facingModes
==
null
||
facingModes
.
toDart
.
isEmpty
)
{
return
;
...
...
@@ -166,14 +163,12 @@ class MobileScannerWeb extends MobileScannerPlatform {
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
unsupported
,
errorDetails:
MobileScannerErrorDetails
(
message:
'This browser does not support displaying video from the camera.'
,
message:
'This browser does not support displaying video from the camera.'
,
),
);
}
final
MediaTrackSupportedConstraints
capabilities
=
window
.
navigator
.
mediaDevices
.
getSupportedConstraints
();
final
MediaTrackSupportedConstraints
capabilities
=
window
.
navigator
.
mediaDevices
.
getSupportedConstraints
();
final
MediaStreamConstraints
constraints
;
...
...
@@ -194,8 +189,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
try
{
// Retrieving the media devices requests the camera permission.
final
MediaStream
videoStream
=
await
window
.
navigator
.
mediaDevices
.
getUserMedia
(
constraints
).
toDart
;
final
MediaStream
videoStream
=
await
window
.
navigator
.
mediaDevices
.
getUserMedia
(
constraints
).
toDart
;
return
videoStream
;
}
on
DOMException
catch
(
error
,
stackTrace
)
{
...
...
@@ -204,8 +198,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
MobileScannerErrorCode
errorCode
=
MobileScannerErrorCode
.
genericError
;
// Handle both unsupported and permission errors from the web.
if
(
errorMessage
.
contains
(
'NotFoundError'
)
||
errorMessage
.
contains
(
'NotSupportedError'
))
{
if
(
errorMessage
.
contains
(
'NotFoundError'
)
||
errorMessage
.
contains
(
'NotSupportedError'
))
{
errorCode
=
MobileScannerErrorCode
.
unsupported
;
}
else
if
(
errorMessage
.
contains
(
'NotAllowedError'
))
{
errorCode
=
MobileScannerErrorCode
.
permissionDenied
;
...
...
Please
register
or
login
to post a comment