Skip to content

Commit 3e3d4e3

Browse files
committed
Expose error callbacks, prevent always setting header
this allows debugging our local app these weird errors appearing in the header. it also allows us to send the errors to rollbar instead of informing the user. Which is usefull for development, but kinda terrible for production systems. fix webpack build script
1 parent 91a7d63 commit 3e3d4e3

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

scripts/build-webpack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
## Build Script
33
echo 'Initiating webpack build sequence.'
44

src/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ export type QrcodeSuccessCallback
250250
export type QrcodeErrorCallback
251251
= (errorMessage: string, error: Html5QrcodeError) => void;
252252

253+
export type StartErrorCallback
254+
= (error: Html5QrcodeError) => void;
255+
253256
/** Code decoder interface. */
254257
export interface QrcodeDecoderAsync {
255258
/**

src/html5-qrcode-scanner.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Html5QrcodeConstants,
1313
Html5QrcodeScanType,
1414
QrcodeSuccessCallback,
15+
StartErrorCallback,
1516
QrcodeErrorCallback,
1617
Html5QrcodeResult,
1718
Html5QrcodeError,
@@ -196,6 +197,9 @@ export class Html5QrcodeScanner {
196197
private cameraScanImage: HTMLImageElement | null = null;
197198
private fileScanImage: HTMLImageElement | null = null;
198199
private fileSelectionUi: FileSelectionUi | null = null;
200+
201+
public startErrorCallback: StartErrorCallback;
202+
public torchButtonErrorCallback: StartErrorCallback;
199203
//#endregion
200204

201205
/**
@@ -228,6 +232,15 @@ export class Html5QrcodeScanner {
228232
if (config!.rememberLastUsedCamera !== true) {
229233
this.persistedDataManager.reset();
230234
}
235+
const $this = this;
236+
237+
const warnUserViaHeader : StartErrorCallback = (error) => {
238+
$this.setHeaderMessage(
239+
error.toString(), Html5QrcodeScannerStatus.STATUS_WARNING);
240+
};
241+
242+
this.startErrorCallback = warnUserViaHeader;
243+
this.torchButtonErrorCallback = warnUserViaHeader;
231244
}
232245

233246
/**
@@ -584,8 +597,7 @@ export class Html5QrcodeScanner {
584597
// time.
585598
createPermissionButtonIfNotExists();
586599
}
587-
$this.setHeaderMessage(
588-
error, Html5QrcodeScannerStatus.STATUS_WARNING);
600+
$this.startErrorCallback(error);
589601
$this.showHideScanTypeSwapLink(true);
590602
});
591603
}
@@ -765,6 +777,7 @@ export class Html5QrcodeScanner {
765777

766778
// Optional torch button support.
767779
let torchButton: TorchButton;
780+
768781
const createAndShowTorchButtonIfSupported
769782
= (cameraCapabilities: CameraCapabilities) => {
770783
if (!cameraCapabilities.torchFeature().isSupported()) {
@@ -782,9 +795,7 @@ export class Html5QrcodeScanner {
782795
{ display: "none", marginLeft: "5px" },
783796
// Callback in case of torch action failure.
784797
(errorMessage) => {
785-
$this.setHeaderMessage(
786-
errorMessage,
787-
Html5QrcodeScannerStatus.STATUS_WARNING);
798+
$this.torchButtonErrorCallback(Html5QrcodeErrorFactory.createFrom(errorMessage))
788799
}
789800
);
790801
} else {
@@ -996,13 +1007,13 @@ export class Html5QrcodeScanner {
9961007
}
9971008
}
9981009

999-
private resetHeaderMessage() {
1010+
public resetHeaderMessage() {
10001011
const messageDiv = document.getElementById(
10011012
this.getHeaderMessageContainerId())!;
10021013
messageDiv.style.display = "none";
10031014
}
10041015

1005-
private setHeaderMessage(
1016+
public setHeaderMessage(
10061017
messageText: string, scannerStatus?: Html5QrcodeScannerStatus) {
10071018
if (!scannerStatus) {
10081019
scannerStatus = Html5QrcodeScannerStatus.STATUS_DEFAULT;

src/html5-qrcode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export class Html5Qrcode {
363363
): Promise<null> {
364364

365365
// Code will be consumed as javascript.
366-
if (!cameraIdOrConfig) {
366+
if (!cameraIdOrConfig) {
367367
throw "cameraIdOrConfig is required";
368368
}
369369

0 commit comments

Comments
 (0)