Showing
3 changed files
with
25 additions
and
3 deletions
| @@ -95,6 +95,13 @@ abstract class BarcodeReader { | @@ -95,6 +95,13 @@ abstract class BarcodeReader { | ||
| 95 | await completer.future; | 95 | await completer.future; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | + /// Set a listener for the media stream constraints. | ||
| 99 | + void setMediaTrackConstraintsListener(void Function(MediaTrackConstraints) listener) { | ||
| 100 | + throw UnimplementedError( | ||
| 101 | + 'setMediaTrackConstraintsListener() has not been implemented.', | ||
| 102 | + ); | ||
| 103 | + } | ||
| 104 | + | ||
| 98 | /// Set the torch state for the active camera to the given [value]. | 105 | /// Set the torch state for the active camera to the given [value]. |
| 99 | Future<void> setTorchState(TorchState value) { | 106 | Future<void> setTorchState(TorchState value) { |
| 100 | throw UnimplementedError('setTorchState() has not been implemented.'); | 107 | throw UnimplementedError('setTorchState() has not been implemented.'); |
| @@ -33,6 +33,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -33,6 +33,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 33 | /// This container element is used by the barcode reader. | 33 | /// This container element is used by the barcode reader. |
| 34 | HTMLDivElement? _divElement; | 34 | HTMLDivElement? _divElement; |
| 35 | 35 | ||
| 36 | + /// The stream controller for the media track constraints stream. | ||
| 37 | + final StreamController<MediaTrackConstraints> _constraintsController = StreamController.broadcast(); | ||
| 38 | + | ||
| 36 | /// The view type for the platform view factory. | 39 | /// The view type for the platform view factory. |
| 37 | final String _viewType = 'MobileScannerWeb'; | 40 | final String _viewType = 'MobileScannerWeb'; |
| 38 | 41 | ||
| @@ -43,6 +46,14 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -43,6 +46,14 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 43 | @override | 46 | @override |
| 44 | Stream<BarcodeCapture?> get barcodesStream => _barcodesController.stream; | 47 | Stream<BarcodeCapture?> get barcodesStream => _barcodesController.stream; |
| 45 | 48 | ||
| 49 | + void _handleMediaTrackConstraintsChange(MediaTrackConstraints constraints) { | ||
| 50 | + if (_constraintsController.isClosed) { | ||
| 51 | + return; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + _constraintsController.add(constraints); | ||
| 55 | + } | ||
| 56 | + | ||
| 46 | @override | 57 | @override |
| 47 | Widget buildCameraView() { | 58 | Widget buildCameraView() { |
| 48 | if (!_barcodeReader.isScanning) { | 59 | if (!_barcodeReader.isScanning) { |
| @@ -86,6 +97,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -86,6 +97,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 86 | // Clear the existing barcodes. | 97 | // Clear the existing barcodes. |
| 87 | _barcodesController.add(const BarcodeCapture()); | 98 | _barcodesController.add(const BarcodeCapture()); |
| 88 | 99 | ||
| 100 | + // Listen for changes to the media track constraints. | ||
| 101 | + _barcodeReader.setMediaTrackConstraintsListener(_handleMediaTrackConstraintsChange); | ||
| 102 | + | ||
| 89 | await _barcodeReader.start( | 103 | await _barcodeReader.start( |
| 90 | startOptions, | 104 | startOptions, |
| 91 | containerElement: _divElement!, | 105 | containerElement: _divElement!, |
| @@ -170,5 +184,6 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -170,5 +184,6 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 170 | 184 | ||
| 171 | await stop(); | 185 | await stop(); |
| 172 | await _barcodesController.close(); | 186 | await _barcodesController.close(); |
| 187 | + await _constraintsController.close(); | ||
| 173 | } | 188 | } |
| 174 | } | 189 | } |
| @@ -19,7 +19,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -19,7 +19,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 19 | ZXingBarcodeReader(); | 19 | ZXingBarcodeReader(); |
| 20 | 20 | ||
| 21 | /// The internal media stream track constraints delegate. | 21 | /// The internal media stream track constraints delegate. |
| 22 | - final MediaTrackConstraintsDelegate _flashlightDelegate = const MediaTrackConstraintsDelegate(); | 22 | + final MediaTrackConstraintsDelegate _mediaTrackConstraintsDelegate = const MediaTrackConstraintsDelegate(); |
| 23 | 23 | ||
| 24 | /// The internal barcode reader. | 24 | /// The internal barcode reader. |
| 25 | ZXingBrowserMultiFormatReader? _reader; | 25 | ZXingBrowserMultiFormatReader? _reader; |
| @@ -180,7 +180,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -180,7 +180,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 180 | return Future<bool>.value(false); | 180 | return Future<bool>.value(false); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | - return _flashlightDelegate.hasFlashlight(mediaStream); | 183 | + return _mediaTrackConstraintsDelegate.hasFlashlight(mediaStream); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | @override | 186 | @override |
| @@ -196,7 +196,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -196,7 +196,7 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 196 | return Future<void>.value(); | 196 | return Future<void>.value(); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | - return _flashlightDelegate.setFlashlightState(mediaStream, value); | 199 | + return _mediaTrackConstraintsDelegate.setFlashlightState(mediaStream, value); |
| 200 | } | 200 | } |
| 201 | } | 201 | } |
| 202 | 202 |
-
Please register or login to post a comment