Committed by
GitHub
Merge pull request #78 from djpnewton/rear-cam-web
fix use of 'facingMode' to enable rear cam on web
Showing
1 changed file
with
13 additions
and
12 deletions
| @@ -80,8 +80,10 @@ class MobileScannerWebPlugin { | @@ -80,8 +80,10 @@ class MobileScannerWebPlugin { | ||
| 80 | Future<Map> _start(arguments) async { | 80 | Future<Map> _start(arguments) async { |
| 81 | vidDiv.children = [video]; | 81 | vidDiv.children = [video]; |
| 82 | 82 | ||
| 83 | - final CameraFacing cameraFacing = | ||
| 84 | - arguments['cameraFacing'] ?? CameraFacing.front; | 83 | + var cameraFacing = CameraFacing.front; |
| 84 | + if (arguments.containsKey('facing')) { | ||
| 85 | + cameraFacing = CameraFacing.values[arguments['facing']]; | ||
| 86 | + } | ||
| 85 | 87 | ||
| 86 | // See https://github.com/flutter/flutter/issues/41563 | 88 | // See https://github.com/flutter/flutter/issues/41563 |
| 87 | // ignore: UNDEFINED_PREFIXED_NAME | 89 | // ignore: UNDEFINED_PREFIXED_NAME |
| @@ -105,18 +107,17 @@ class MobileScannerWebPlugin { | @@ -105,18 +107,17 @@ class MobileScannerWebPlugin { | ||
| 105 | Map? capabilities = | 107 | Map? capabilities = |
| 106 | html.window.navigator.mediaDevices?.getSupportedConstraints(); | 108 | html.window.navigator.mediaDevices?.getSupportedConstraints(); |
| 107 | if (capabilities != null && capabilities['facingMode']) { | 109 | if (capabilities != null && capabilities['facingMode']) { |
| 108 | - UserMediaOptions constraints = UserMediaOptions( | ||
| 109 | - video: VideoOptions( | 110 | + var constraints = { |
| 111 | + 'video': VideoOptions( | ||
| 110 | facingMode: | 112 | facingMode: |
| 111 | - (cameraFacing == CameraFacing.front ? 'user' : 'environment'), | ||
| 112 | - width: {'ideal': 4096}, | ||
| 113 | - height: {'ideal': 2160}, | ||
| 114 | - )); | 113 | + (cameraFacing == CameraFacing.front ? 'user' : 'environment')) |
| 114 | + }; | ||
| 115 | 115 | ||
| 116 | _localStream = | 116 | _localStream = |
| 117 | - await html.window.navigator.getUserMedia(video: constraints); | 117 | + await html.window.navigator.mediaDevices?.getUserMedia(constraints); |
| 118 | } else { | 118 | } else { |
| 119 | - _localStream = await html.window.navigator.getUserMedia(video: true); | 119 | + _localStream = await html.window.navigator.mediaDevices |
| 120 | + ?.getUserMedia({'video': true}); | ||
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | video.srcObject = _localStream; | 123 | video.srcObject = _localStream; |
| @@ -146,7 +147,7 @@ class MobileScannerWebPlugin { | @@ -146,7 +147,7 @@ class MobileScannerWebPlugin { | ||
| 146 | 'torchable': hasFlash | 147 | 'torchable': hasFlash |
| 147 | }; | 148 | }; |
| 148 | } catch (e) { | 149 | } catch (e) { |
| 149 | - throw PlatformException(code: 'MobileScannerWeb', message: e.toString()); | 150 | + throw PlatformException(code: 'MobileScannerWeb', message: '$e'); |
| 150 | } | 151 | } |
| 151 | } | 152 | } |
| 152 | 153 | ||
| @@ -166,7 +167,7 @@ class MobileScannerWebPlugin { | @@ -166,7 +167,7 @@ class MobileScannerWebPlugin { | ||
| 166 | Future<void> cancel() async { | 167 | Future<void> cancel() async { |
| 167 | try { | 168 | try { |
| 168 | // Stop the camera stream | 169 | // Stop the camera stream |
| 169 | - _localStream!.getTracks().forEach((track) { | 170 | + _localStream?.getTracks().forEach((track) { |
| 170 | if (track.readyState == 'live') { | 171 | if (track.readyState == 'live') { |
| 171 | track.stop(); | 172 | track.stop(); |
| 172 | } | 173 | } |
-
Please register or login to post a comment