Showing
3 changed files
with
8 additions
and
42 deletions
| @@ -43,7 +43,9 @@ abstract class BarcodeReader { | @@ -43,7 +43,9 @@ abstract class BarcodeReader { | ||
| 43 | 43 | ||
| 44 | /// Check whether the active camera has a flashlight. | 44 | /// Check whether the active camera has a flashlight. |
| 45 | Future<bool> hasTorch() { | 45 | Future<bool> hasTorch() { |
| 46 | - throw UnimplementedError('hasTorch() has not been implemented.'); | 46 | + // The torch of a media stream is not available for video tracks. |
| 47 | + // See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#instance_properties_of_video_tracks | ||
| 48 | + return Future<bool>.value(false); | ||
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | /// Load the barcode reader library. | 51 | /// Load the barcode reader library. |
| @@ -108,7 +110,10 @@ abstract class BarcodeReader { | @@ -108,7 +110,10 @@ abstract class BarcodeReader { | ||
| 108 | 110 | ||
| 109 | /// Set the torch state for the active camera to the given [value]. | 111 | /// Set the torch state for the active camera to the given [value]. |
| 110 | Future<void> setTorchState(TorchState value) { | 112 | Future<void> setTorchState(TorchState value) { |
| 111 | - throw UnimplementedError('setTorchState() has not been implemented.'); | 113 | + throw UnsupportedError( |
| 114 | + 'Setting the torch state is not supported for video tracks on the web.\n' | ||
| 115 | + 'See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#instance_properties_of_video_tracks', | ||
| 116 | + ); | ||
| 112 | } | 117 | } |
| 113 | 118 | ||
| 114 | /// Start the barcode reader and initialize the [videoStream]. | 119 | /// Start the barcode reader and initialize the [videoStream]. |
| @@ -77,7 +77,7 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -77,7 +77,7 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 77 | 77 | ||
| 78 | @override | 78 | @override |
| 79 | Stream<TorchState> get torchStateStream => | 79 | Stream<TorchState> get torchStateStream => |
| 80 | - _settingsController.stream.map((_) => TorchState.off); | 80 | + _settingsController.stream.map((_) => TorchState.unavailable); |
| 81 | 81 | ||
| 82 | @override | 82 | @override |
| 83 | Stream<double> get zoomScaleStateStream => | 83 | Stream<double> get zoomScaleStateStream => |
| @@ -3,7 +3,6 @@ import 'dart:js_interop'; | @@ -3,7 +3,6 @@ import 'dart:js_interop'; | ||
| 3 | import 'dart:ui'; | 3 | import 'dart:ui'; |
| 4 | 4 | ||
| 5 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; | 5 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; |
| 6 | -import 'package:mobile_scanner/src/enums/torch_state.dart'; | ||
| 7 | import 'package:mobile_scanner/src/objects/barcode_capture.dart'; | 6 | import 'package:mobile_scanner/src/objects/barcode_capture.dart'; |
| 8 | import 'package:mobile_scanner/src/objects/start_options.dart'; | 7 | import 'package:mobile_scanner/src/objects/start_options.dart'; |
| 9 | import 'package:mobile_scanner/src/web/barcode_reader.dart'; | 8 | import 'package:mobile_scanner/src/web/barcode_reader.dart'; |
| @@ -165,17 +164,6 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -165,17 +164,6 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 165 | } | 164 | } |
| 166 | 165 | ||
| 167 | @override | 166 | @override |
| 168 | - Future<bool> hasTorch() { | ||
| 169 | - final web.MediaStream? mediaStream = _reader?.stream; | ||
| 170 | - | ||
| 171 | - if (mediaStream == null) { | ||
| 172 | - return Future<bool>.value(false); | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - return _mediaTrackConstraintsDelegate.hasFlashlight(mediaStream); | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - @override | ||
| 179 | void setMediaTrackSettingsListener( | 167 | void setMediaTrackSettingsListener( |
| 180 | void Function(web.MediaTrackSettings) listener, | 168 | void Function(web.MediaTrackSettings) listener, |
| 181 | ) { | 169 | ) { |
| @@ -183,33 +171,6 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -183,33 +171,6 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 183 | } | 171 | } |
| 184 | 172 | ||
| 185 | @override | 173 | @override |
| 186 | - Future<void> setTorchState(TorchState value) async { | ||
| 187 | - switch (value) { | ||
| 188 | - case TorchState.unavailable: | ||
| 189 | - return Future<void>.value(); | ||
| 190 | - case TorchState.off: | ||
| 191 | - case TorchState.on: | ||
| 192 | - final web.MediaStream? mediaStream = _reader?.stream; | ||
| 193 | - | ||
| 194 | - if (mediaStream == null) { | ||
| 195 | - return Future<void>.value(); | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | - await _mediaTrackConstraintsDelegate.setFlashlightState( | ||
| 199 | - mediaStream, | ||
| 200 | - value, | ||
| 201 | - ); | ||
| 202 | - | ||
| 203 | - final web.MediaTrackSettings? settings = | ||
| 204 | - _mediaTrackConstraintsDelegate.getSettings(mediaStream); | ||
| 205 | - | ||
| 206 | - if (settings != null) { | ||
| 207 | - _onMediaTrackSettingsChanged?.call(settings); | ||
| 208 | - } | ||
| 209 | - } | ||
| 210 | - } | ||
| 211 | - | ||
| 212 | - @override | ||
| 213 | Future<void> start( | 174 | Future<void> start( |
| 214 | StartOptions options, { | 175 | StartOptions options, { |
| 215 | required web.HTMLVideoElement videoElement, | 176 | required web.HTMLVideoElement videoElement, |
-
Please register or login to post a comment