Navaron Bracke

use MediaTrackSettings instead of constraints

... ... @@ -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.',
);
... ...
... ... @@ -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?.getConstraints();
return track?.getSettings();
}
/// Returns a list of supported flashlight modes for the given [mediaStream].
... ...
... ... @@ -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(constraints);
_settingsController.add(settings);
}
@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 _constraintsController.close();
await _settingsController.close();
// Finally, remove the video element from the DOM.
try {
... ...
... ... @@ -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.MediaTrackConstraints? constraints = _mediaTrackConstraintsDelegate.getConstraints(stream);
final web.MediaTrackSettings? settings = _mediaTrackConstraintsDelegate.getSettings(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.MediaTrackConstraints? constraints = _mediaTrackConstraintsDelegate.getConstraints(mediaStream);
final web.MediaTrackSettings? settings = _mediaTrackConstraintsDelegate.getSettings(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 {
_onMediaTrackConstraintsChanged = null;
_onMediaTrackSettingsChanged = null;
_reader?.stopContinuousDecode.callAsFunction();
_reader?.reset.callAsFunction();
_reader = null;
... ...