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
2023-12-29 15:07:03 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b99652db930f1ce0139405c15211996fa958e9ab
b99652db
1 parent
9fa1d014
use MediaTrackSettings instead of constraints
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
24 deletions
lib/src/web/barcode_reader.dart
lib/src/web/media_track_constraints_delegate.dart
lib/src/web/mobile_scanner_web.dart
lib/src/web/zxing/zxing_barcode_reader.dart
lib/src/web/barcode_reader.dart
View file @
b99652d
...
...
@@ -95,8 +95,8 @@ abstract class BarcodeReader {
await
completer
.
future
;
}
/// Set a listener for the media stream constraints.
void
setMediaTrackConstraintsListener
(
void
Function
(
MediaTrackConstraints
)
listener
)
{
/// Set a listener for the media stream settings.
void
setMediaTrackSettingsListener
(
void
Function
(
MediaTrackSettings
)
listener
)
{
throw
UnimplementedError
(
'setMediaTrackConstraintsListener() has not been implemented.'
,
);
...
...
lib/src/web/media_track_constraints_delegate.dart
View file @
b99652d
...
...
@@ -8,8 +8,8 @@ final class MediaTrackConstraintsDelegate {
/// Constructs a [MediaTrackConstraintsDelegate] instance.
const
MediaTrackConstraintsDelegate
();
/// Get the constraints for the given [mediaStream].
MediaTrackConstraints
?
getConstraints
(
MediaStream
?
mediaStream
)
{
/// Get the settings for the given [mediaStream].
MediaTrackSettings
?
getSettings
(
MediaStream
?
mediaStream
)
{
final
List
<
JSAny
?>
tracks
=
mediaStream
?.
getVideoTracks
().
toDart
??
const
[];
if
(
tracks
.
isEmpty
)
{
...
...
@@ -18,7 +18,7 @@ final class MediaTrackConstraintsDelegate {
final
MediaStreamTrack
?
track
=
tracks
.
first
as
MediaStreamTrack
?;
return
track
?.
get
Constraint
s
();
return
track
?.
get
Setting
s
();
}
/// Returns a list of supported flashlight modes for the given [mediaStream].
...
...
lib/src/web/mobile_scanner_web.dart
View file @
b99652d
...
...
@@ -33,8 +33,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
/// This container element is used by the barcode reader.
HTMLDivElement
?
_divElement
;
/// The stream controller for the media track constraints stream.
final
StreamController
<
MediaTrackConstraints
>
_constraintsController
=
StreamController
.
broadcast
();
/// The stream controller for the media track settings stream.
final
StreamController
<
MediaTrackSettings
>
_settingsController
=
StreamController
.
broadcast
();
/// The view type for the platform view factory.
final
String
_viewType
=
'MobileScannerWeb'
;
...
...
@@ -46,12 +46,12 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Stream
<
BarcodeCapture
?>
get
barcodesStream
=>
_barcodesController
.
stream
;
void
_handleMediaTrackConstraintsChange
(
MediaTrackConstraints
constraints
)
{
if
(
_constraintsController
.
isClosed
)
{
void
_handleMediaTrackSettingsChange
(
MediaTrackSettings
settings
)
{
if
(
_settingsController
.
isClosed
)
{
return
;
}
_
constraintsController
.
add
(
constraint
s
);
_
settingsController
.
add
(
setting
s
);
}
@override
...
...
@@ -97,8 +97,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
// Clear the existing barcodes.
_barcodesController
.
add
(
const
BarcodeCapture
());
// Listen for changes to the media track constraints.
_barcodeReader
.
setMediaTrackConstraintsListener
(
_handleMediaTrackConstraintsChange
);
// Listen for changes to the media track settings.
_barcodeReader
.
setMediaTrackSettingsListener
(
_handleMediaTrackSettingsChange
);
await
_barcodeReader
.
start
(
startOptions
,
...
...
@@ -184,7 +184,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
await
stop
();
await
_barcodesController
.
close
();
await
_
constraint
sController
.
close
();
await
_
setting
sController
.
close
();
// Finally, remove the video element from the DOM.
try
{
...
...
lib/src/web/zxing/zxing_barcode_reader.dart
View file @
b99652d
...
...
@@ -18,8 +18,8 @@ import 'package:web/web.dart' as web;
final
class
ZXingBarcodeReader
extends
BarcodeReader
{
ZXingBarcodeReader
();
/// The listener for media track constraints changes.
void
Function
(
web
.
MediaTrackConstraints
)?
_onMediaTrackConstraintsChanged
;
/// The listener for media track settings changes.
void
Function
(
web
.
MediaTrackSettings
)?
_onMediaTrackSettingsChanged
;
/// The internal media stream track constraints delegate.
final
MediaTrackConstraintsDelegate
_mediaTrackConstraintsDelegate
=
const
MediaTrackConstraintsDelegate
();
...
...
@@ -139,10 +139,10 @@ final class ZXingBarcodeReader extends BarcodeReader {
await
result
?.
toDart
;
final
web
.
MediaTrack
Constraints
?
constraints
=
_mediaTrackConstraintsDelegate
.
getConstraint
s
(
stream
);
final
web
.
MediaTrack
Settings
?
settings
=
_mediaTrackConstraintsDelegate
.
getSetting
s
(
stream
);
if
(
constraints
!=
null
)
{
_onMediaTrackConstraintsChanged
?.
call
(
constraints
);
if
(
settings
!=
null
)
{
_onMediaTrackSettingsChanged
?.
call
(
settings
);
}
}
}
...
...
@@ -193,8 +193,8 @@ final class ZXingBarcodeReader extends BarcodeReader {
}
@override
void
setMediaTrackConstraintsListener
(
void
Function
(
web
.
MediaTrackConstraints
)
listener
)
{
_onMediaTrackConstraintsChanged
??=
listener
;
void
setMediaTrackSettingsListener
(
void
Function
(
web
.
MediaTrackSettings
)
listener
)
{
_onMediaTrackSettingsChanged
??=
listener
;
}
@override
...
...
@@ -212,10 +212,10 @@ final class ZXingBarcodeReader extends BarcodeReader {
await
_mediaTrackConstraintsDelegate
.
setFlashlightState
(
mediaStream
,
value
);
final
web
.
MediaTrack
Constraints
?
constraints
=
_mediaTrackConstraintsDelegate
.
getConstraint
s
(
mediaStream
);
final
web
.
MediaTrack
Settings
?
settings
=
_mediaTrackConstraintsDelegate
.
getSetting
s
(
mediaStream
);
if
(
constraints
!=
null
)
{
_onMediaTrackConstraintsChanged
?.
call
(
constraints
);
if
(
settings
!=
null
)
{
_onMediaTrackSettingsChanged
?.
call
(
settings
);
}
}
}
...
...
@@ -254,7 +254,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
@override
Future
<
void
>
stop
()
async
{
_onMediaTrack
Constraint
sChanged
=
null
;
_onMediaTrack
Setting
sChanged
=
null
;
_reader
?.
stopContinuousDecode
.
callAsFunction
();
_reader
?.
reset
.
callAsFunction
();
_reader
=
null
;
...
...
Please
register
or
login
to post a comment