93 Commits
Author SHA1 Message Date
Daniel 987bbb06c2 Disable native BarcodeDetector on M1/M2 Macs with Ventura
On Macs with an M1/M2 processor and macOS Ventura (macOS version 13), the BarcodeDetector
is broken in Chromium based browsers, regardless of the version. For that constellation,
the BarcodeDetector does not error but does not detect QR codes. Macs without an M1/M2 or
before Ventura are fine. See https://bugs.chromium.org/p/chromium/issues/detail?id=1382442.

Fixes #209
2022-11-22 21:01:12 -06:00
Daniel 2714cb9944 Identify scan requests to worker by unique id's
This avoids that parallel scans on the same worker instance ALL interpret
the first incoming scan result as their result. Instead, now each scan
request to the worker waits for their individual response.

Fixes #149
2022-02-22 23:27:02 +01:00
Daniel 9373237718 Always create new worker instead of reusing a singleton worker
Create a new worker instance on each call to createQrEngine instead of
using a singleton worker instance. Sharing a singleton instance resulted
in problems when destroying the worker, for example in a call to
QrScanner.scanImage, while it was still needed in a scanner instance or
further calls to scanImage.
2022-02-22 18:17:13 +01:00
Daniel 3a2719213b Improve documentation for .destroy()
Make clear that destroyed instances can not be started again.

Closes #144
2022-02-21 14:36:54 +01:00
Daniel 9a70dd984c Fix type generation for namespaced types
Fixes #147
2022-02-21 14:36:54 +01:00
Daniel 60a2b3b2ce Import worker as dynamic import
Doed now not import the worker as a separate worker script via the Worker
constructor which required copying over the worker script and specifying
QrScanner.WORKER_PATH. Instead, the dynamic import will now be handled
automatically by bundlers like Rollup or Webpack.
2022-02-02 17:42:30 +01:00
Daniel 54b40bf917 Nicer default highlight styles 2022-01-28 19:17:22 +01:00
Daniel 70335ba5c2 Better handling of internal issues of native BarcodeDetector
Fixes #98
2022-01-28 18:24:20 +01:00
Daniel 3ce4f1bf6b Limit scan rate to camera's frame rate 2022-01-28 18:24:20 +01:00
Daniel 8ee8d7a45a Support throttling the scans per second
Closes #93
2022-01-28 18:24:20 +01:00
Daniel 158fbf585b Support providing an external overlay element 2022-01-28 18:24:20 +01:00
Daniel 0d48a807f5 Support highlighting the outline of detected codes 2022-01-28 18:24:13 +01:00
Daniel 16ad9b9b82 Smarter positioning of scan region highlight
Now does not make any assumptions on the parent element anymore and can
handle object-fit or object-position being set on the video.
2022-01-26 18:10:12 +01:00
Daniel dea704924f Support highlighting the scan region
Closes #86
2022-01-26 16:43:25 +01:00
Daniel 57b2a52734 Provide more detailed scan results, for now adding qr location
Closes #66
Closes #109
2022-01-25 11:59:08 +01:00
Daniel 954d3e2930 Switch constructor and scanImage to using options objects 2022-01-25 10:21:26 +01:00
Daniel b769540c3b Improve handling of pending actions if scanner was paused or destroyed
- Avoid starting camera stream if scanner was paused in the meantime
- Be lenient on fails to .start() if the scanner was paused in the meantime
- Disallow starting the stream or flash if the scanner was destroyed
- Await video.play calls

Fixes #90
Fixes #139
2022-01-25 10:21:26 +01:00
Daniel d704d3ab37 Don't open a second stream if we already have permission for device listing
This is an optimization but also a fix for iOS Safari which stops an already ongoing
stream when a second stream is opened, see https://bugs.webkit.org/show_bug.cgi?id=179363.

Fixes #125
2022-01-25 10:21:26 +01:00
Daniel a3e87bcf1e Remove limitation to MediaStreams as video srcObject 2022-01-25 10:21:26 +01:00
Daniel bcd5b19f82 Convert to typescript 2022-01-25 10:20:37 +01:00
Daniel 8bf0dc47aa Convert to ES2017 with async/await
Also saves 4.3% in size for qr-scanner.min.js
2022-01-19 17:58:59 +01:00
Daniel a1493c127d Check whether BarcodeDetector.getSupportedFormats exists
Some browsers (iOS specific?) had issues, see issue #115.
2021-08-17 12:10:51 +02:00
Daniel f232f32211 Support hasFlash even if no stream is currently running
But still doing it after scanner.start() is recommended, to avoid creating
a temporary stream.
2021-08-17 12:02:35 +02:00
Daniel 2877944bce Refactor hasFlash to potentially support Firefox and Safari in the future 2021-08-17 08:53:28 +02:00
Daniel fe31236d51 Fix turning flash off
applyConstraints with torch: false does not work to turn the
flashlight off, as a stream's torch stays continuously on, see
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#torch.
Therefore, we have to stop the stream to turn the flashlight off.
2021-08-16 21:20:32 +02:00
Daniel e2edfe1e88 Restart the flash if it was previously on
Also now support flagging the flash as on while the stream is
paused.
2021-08-16 21:14:29 +02:00
Daniel 5f13ff064e Merge PR#112 (lafriks-fork:feat/camera_list) with fixes 2021-08-16 14:08:30 +02:00
Daniel 28c43cdbe3 Simplify and improve setCamera
- Use .pause instead of copying the code
- Remove the unnecessary 300ms delay
- Avoid overwriting _offTimeout if another pause call happened shortly
  before.
- Don't start the stream if is was paused.
2021-08-16 13:40:56 +02:00
Daniel 6a6c593c2d Merge deviceId and preferredFacingMode into preferredCamera
- Merge deviceId and preferredFacingMode options into a single
  option preferredCamera. Also previously, the deviceId took
  precedence over the preferredFacingMode.
- .setCamera now also allows setting a preferred facingMode
  instead of a deviceId.

Additinal fixes to PR#112:

- Correctly fallback to not applying any constraints in .start if
  the preferredCamera (previously deviceId and preferredFacingMode)
  is not available. Previously, if neither for the deviceId nor
  the preferredFacingMode contraint a camera was found, no attempt
  without a constraint was attempted.
- A add missing documentation for deviceId support in the constructor
  to the Readme and generally adapt Readme for merged preferredCamera
  option.
- Fix missing type for deviceId (now merged into preferredCamera) in
  the constructor type definitions and generally adapt the types for
  merged preferredCamera option.
2021-08-14 14:13:33 +02:00
Daniel 1e9f6c6598 Refactor listCameras and improve readme wording
- rename the method from getCameraList to listCameras
- make requesting labels (and the required camera permission) optional
- refactor hasCamera using listCameras

Additinal fixes to PR#112:

- add fallback labels for when no exact labels were requested
- remove unnecessary outer Promise
- make sure the created stream is always destroyed in a finally
2021-08-13 20:49:59 +02:00
Daniel d7a09be088 Avoid that Safari stops the video stream on hidden videos 2021-08-09 11:22:27 +02:00
Daniel e8d107a171 Performance improvements
- round scan region to whole pixel positions to avoid blurry
  drawing at sub-pixel positions
- avoid clearing the canvas by resetting the canvas width or
  height when they actually didn't change.
2021-07-29 19:37:15 +02:00
Daniel 5836ac719b Rename fixedCanvasSize to disallowCanvasResizing 2021-07-29 17:26:29 +02:00
Lauris BH 63f79f97a8 Change setCamera to be async method 2021-06-10 17:31:17 +03:00
Lauris BH c53a1ecb4a Add option to get camera list and allow to set specific device to use 2021-06-04 12:00:40 +03:00
Daniel e8a77dea3f Add option for providing a custom web cam scanning region 2020-07-12 18:57:29 +02:00
Daniel 99111ae23a When the native BarcodeDetector crashed, create a new one
The BarcodeDetector sometimes crashes after some time. If that happens,
create a new one.
2020-07-12 13:01:05 +02:00
Daniel 423101663b Use native BarcodeDetector when supported 2020-07-12 12:30:38 +02:00
Daniel 87336c313b Update source rect when video ready
b3713f2 switched to starting to play immediately, without waiting for
a canplay event. The side effect of this is, that the play event (on
which the source rect is measured) is triggered before the video
is ready and the video dimensions known. To circumvent this, this
commit adds an additional source rect update on loadedmetadata.
2020-07-12 00:00:56 +02:00
Daniel ecc04840dd Increase the timeout
Sometimes when the scanner was processing a frame for a long time, the
timeout apparently could be triggered when it shouldn't.
2020-07-11 10:05:49 +02:00
Daniel 509232f8d1 Support blobs as image source 2020-07-10 20:42:48 +02:00
Daniel c0f922bdda Update jsQR scanner lib
New version of our jsQR-es6 fork has been updated to newest master
of cozmo/jsQR and merged in additional pull requests which are still
open in cozmo/jsQR. Also now makes the 'onlyInvert' inversion mode
usable.
2020-07-09 21:58:13 +02:00
Daniel 4206f44c22 Make sure hasCamera() always returns a Promise 2020-07-09 16:36:44 +02:00
Daniel a3fcd4cf69 Fixes and improvements for flashlight support
- Add instructions to readme
- Update _flashOn after the flash was actually turned on or off
- Throw an error when trying to set the flash if not supported
- Make toggleFlash, turnFlashOn, turnFlashOff return a promise
- Throw an error when trying to detect flash support before the
  video stream is available.
2020-07-09 14:31:41 +02:00
Filip ChalupaandDaniel 50adecec26 Flash detection and control
PR #34

Co-authored-by: Daniel <github.danimoh@neverbox.com>
2020-07-09 12:38:31 +02:00
Magnus HenochandDaniel 49ccc1dde9 Allow specifying a preferred facingMode for camera
PR #35

Co-authored-by: Daniel <github.danimoh@neverbox.com>
2020-07-09 11:33:38 +02:00
Daniel 947fb7ebcf Improvements and fixes for continous scanning error handling
- Make change backwards compatible with previous consructor signature
- Fix demo to interpret errors as proper results
- Update types
- Do not report errors when the scanner is inactive
- Update readme
2020-07-07 23:45:49 +02:00
diego 0961d4e102 add error for continous scanning 2020-07-07 15:52:08 +02:00
Daniel 1daf447a73 On pause stop all tracks if there are multiple
Should typically not be necessary, just to be safe.
2020-07-06 23:31:18 +02:00
DanielandAlessandro Gatti 177a252488 Set playsInline, muted and disablePictureInPicture by default
Set these properties by default to disable picture in picture mode and to
enable inline playback on iPhones.

Co-authored-by: Alessandro Gatti <ale.gatti96@gmail.com>
2020-07-06 23:30:36 +02:00