Html5QrcodeScanner
html5-qrcode / Html5QrcodeScanner
Class: Html5QrcodeScanner
End to end web based QR and Barcode Scanner.
Use this class for setting up QR scanner in your web application with few lines of codes.
- Supports camera as well as file based scanning.
- Depending on device supports camera selection, zoom and torch features.
- Supports different kind of 2D and 1D codes Html5QrcodeSupportedFormats.
Table of contents
Constructors
Methods
- applyVideoConstraints
- clear
- getRunningTrackCapabilities
- getRunningTrackSettings
- getState
- pause
- render
- resume
Constructors
constructor
• new Html5QrcodeScanner(elementId
, config
, verbose
)
Creates instance of this class.
Parameters
Name | Type | Description |
---|---|---|
elementId | string | Id of the HTML element. |
config | undefined | Html5QrcodeScannerConfig | Extra configurations to tune the code scanner. |
verbose | undefined | boolean | If true, all logs would be printed to console. |
Defined in
Methods
applyVideoConstraints
▸ applyVideoConstraints(videoConstaints
): Promise
<void
>
Apply a video constraints on running video track from camera.
Note: Should only be called if () returns SCANNING or PAUSED.
Throws
error if the scanning is not in running state.
Parameters
Name | Type |
---|---|
videoConstaints | MediaTrackConstraints |
Returns
Promise
<void
>
a Promise which succeeds if the passed constraints are applied, fails otherwise.
Defined in
clear
▸ clear(): Promise
<void
>
Removes the QR Code scanner UI.
Returns
Promise
<void
>
Promise which succeeds if the cleanup is complete successfully, fails otherwise.
Defined in
getRunningTrackCapabilities
▸ getRunningTrackCapabilities(): MediaTrackCapabilities
Returns the capabilities of the running video track.
Read more: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getConstraints
Note: Should only be called if () returns SCANNING or PAUSED.
Throws
error if the scanning is not in running state.
Returns
MediaTrackCapabilities
the capabilities of a running video track.
Defined in
getRunningTrackSettings
▸ getRunningTrackSettings(): MediaTrackSettings
Returns the object containing the current values of each constrainable property of the running video track.
Read more: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getSettings
Note: Should only be called if () returns SCANNING or PAUSED.
Throws
error if the scanning is not in running state.
Returns
MediaTrackSettings
the supported settings of the running video track.
Defined in
getState
▸ getState(): Html5QrcodeScannerState
Gets state of the camera scan.
Returns
state of type Html5QrcodeScannerState.
Defined in
pause
▸ pause(shouldPauseVideo?
): void
Pauses the ongoing scan.
Notes:
- Should only be called if camera scan is ongoing.
Throws
error if method is called when scanner is not in scanning state.
Parameters
Name | Type | Description |
---|---|---|
shouldPauseVideo? | boolean | (Optional, default = false) If true the video will be paused. |
Returns
void
Defined in
render
▸ render(qrCodeSuccessCallback
, qrCodeErrorCallback
): void
Renders the User Interface.
Parameters
Name | Type | Description |
---|---|---|
qrCodeSuccessCallback | QrcodeSuccessCallback | Callback called when an instance of a QR code or any other supported bar code is found. |
qrCodeErrorCallback | undefined | QrcodeErrorCallback | optional, callback called in cases where no instance of QR code or any other supported bar code is found. |
Returns
void
Defined in
resume
▸ resume(): void
Resumes the paused scan.
If the video was previously paused by setting shouldPauseVideo
to true
in (shouldPauseVideo),
calling this method will resume the video.
Notes:
- Should only be called if camera scan is ongoing.
- With this caller will start getting results in success and error callbacks.
Throws
error if method is called when scanner is not in paused state.
Returns
void