@zxing/library
Advanced tools
Comparing version 0.14.2 to 0.15.0
@@ -38,2 +38,13 @@ import BinaryBitmap from '../core/BinaryBitmap'; | ||
/** | ||
* Delay time between decode attempts made by the scanner. | ||
*/ | ||
protected _timeBetweenDecodingAttempts: number; | ||
/** Time between two decoding tries in milli seconds. */ | ||
/** | ||
* Change the time span the decoder waits between two decoding tries. | ||
* | ||
* @param {number} millis Time between two decoding tries in milli seconds. | ||
*/ | ||
timeBetweenDecodingAttempts: number; | ||
/** | ||
* The HTML canvas element, used to draw the video or image's frame for decoding. | ||
@@ -88,3 +99,3 @@ */ | ||
* @param {Reader} reader The reader instance to decode the barcode | ||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries | ||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent successful decode tries | ||
* | ||
@@ -115,3 +126,35 @@ * @memberOf BrowserCodeReader | ||
* | ||
* @param {string} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
* | ||
* @deprecated Use `decodeOnceFromVideoDevice` instead. | ||
*/ | ||
decodeFromInputVideoDevice(deviceId?: string, videoSource?: string | HTMLVideoElement): Promise<Result>; | ||
/** | ||
* In one attempt, tries to decode the barcode from the device specified by deviceId while showing the video in the specified video element. | ||
* | ||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
decodeOnceFromVideoDevice(deviceId?: string, videoSource?: string | HTMLVideoElement): Promise<Result>; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param constraints the media stream constraints to get s valid media stream to decode from | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
decodeOnceFromConstraints(constraints: MediaStreamConstraints, videoSource?: string | HTMLVideoElement): Promise<Result>; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
@@ -122,3 +165,3 @@ * @returns {Promise<Result>} The decoding result. | ||
*/ | ||
decodeFromInputVideoDevice(deviceId?: string, videoSource?: string | HTMLVideoElement): Promise<Result>; | ||
decodeOnceFromStream(stream: MediaStream, videoSource?: string | HTMLVideoElement): Promise<Result>; | ||
/** | ||
@@ -132,5 +175,37 @@ * Continuously decodes the barcode from the device specified by device while showing the video in the specified video element. | ||
* @memberOf BrowserCodeReader | ||
* | ||
* @deprecated Use `decodeFromVideoDevice` instead. | ||
*/ | ||
decodeFromInputVideoDeviceContinuously(deviceId: string | null, videoSource: string | HTMLVideoElement | null, callbackFn: DecodeContinuouslyCallback): Promise<void>; | ||
/** | ||
* Continuously tries to decode the barcode from the device specified by device while showing the video in the specified video element. | ||
* | ||
* @param {string|null} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param {string|HTMLVideoElement|null} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<void>} | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
decodeFromVideoDevice(deviceId: string | null, videoSource: string | HTMLVideoElement | null, callbackFn: DecodeContinuouslyCallback): Promise<void>; | ||
/** | ||
* Continuously tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
private decodeFromConstraints; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
private decodeFromStream; | ||
/** | ||
* Breaks the decoding loop. | ||
@@ -165,3 +240,3 @@ */ | ||
*/ | ||
isVideoPLaying(video: HTMLVideoElement): boolean; | ||
isVideoPlaying(video: HTMLVideoElement): boolean; | ||
/** | ||
@@ -252,5 +327,5 @@ * Just tries to play the video and logs any errors. | ||
/** | ||
* Continuously decodes from video input until it finds some value. | ||
* Tries to decode from the video input until it finds some value. | ||
*/ | ||
private decodeAsync; | ||
private decodeOnce; | ||
/** | ||
@@ -257,0 +332,0 @@ * Continuously decodes from video input. |
@@ -55,3 +55,3 @@ "use strict"; | ||
* @param {Reader} reader The reader instance to decode the barcode | ||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries | ||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent successful decode tries | ||
* | ||
@@ -73,2 +73,6 @@ * @memberOf BrowserCodeReader | ||
this._stopAsyncDecode = false; | ||
/** | ||
* Delay time between decode attempts made by the scanner. | ||
*/ | ||
this._timeBetweenDecodingAttempts = 0; | ||
} | ||
@@ -105,2 +109,18 @@ Object.defineProperty(BrowserCodeReader.prototype, "hasNavigator", { | ||
}); | ||
Object.defineProperty(BrowserCodeReader.prototype, "timeBetweenDecodingAttempts", { | ||
/** Time between two decoding tries in milli seconds. */ | ||
get: function () { | ||
return this._timeBetweenDecodingAttempts; | ||
}, | ||
/** | ||
* Change the time span the decoder waits between two decoding tries. | ||
* | ||
* @param {number} millis Time between two decoding tries in milli seconds. | ||
*/ | ||
set: function (millis) { | ||
this._timeBetweenDecodingAttempts = millis < 0 ? 0 : millis; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BrowserCodeReader.prototype, "hints", { | ||
@@ -202,13 +222,34 @@ /** | ||
* | ||
* @param {string} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
* | ||
* @deprecated Use `decodeOnceFromVideoDevice` instead. | ||
*/ | ||
BrowserCodeReader.prototype.decodeFromInputVideoDevice = function (deviceId, videoSource) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var videoConstraints, constraints, stream, video, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.decodeOnceFromVideoDevice(deviceId, videoSource)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* In one attempt, tries to decode the barcode from the device specified by deviceId while showing the video in the specified video element. | ||
* | ||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeOnceFromVideoDevice = function (deviceId, videoSource) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var videoConstraints, constraints; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
@@ -223,10 +264,52 @@ this.reset(); | ||
constraints = { video: videoConstraints }; | ||
return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)]; | ||
return [4 /*yield*/, this.decodeOnceFromConstraints(constraints, videoSource)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param constraints the media stream constraints to get s valid media stream to decode from | ||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeOnceFromConstraints = function (constraints, videoSource) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var stream; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)]; | ||
case 1: | ||
stream = _a.sent(); | ||
return [4 /*yield*/, this.decodeOnceFromStream(stream, videoSource)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeOnceFromStream = function (stream, videoSource) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var video, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.reset(); | ||
return [4 /*yield*/, this.attachStreamToVideo(stream, videoSource)]; | ||
case 1: | ||
video = _a.sent(); | ||
return [4 /*yield*/, this.decodeOnce(video)]; | ||
case 2: | ||
video = _a.sent(); | ||
return [4 /*yield*/, this.decodeAsync(video)]; | ||
case 3: | ||
result = _a.sent(); | ||
@@ -246,10 +329,30 @@ return [2 /*return*/, result]; | ||
* @memberOf BrowserCodeReader | ||
* | ||
* @deprecated Use `decodeFromVideoDevice` instead. | ||
*/ | ||
BrowserCodeReader.prototype.decodeFromInputVideoDeviceContinuously = function (deviceId, videoSource, callbackFn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var videoConstraints, constraints, stream, video; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.decodeFromVideoDevice(deviceId, videoSource, callbackFn)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Continuously tries to decode the barcode from the device specified by device while showing the video in the specified video element. | ||
* | ||
* @param {string|null} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available. | ||
* @param {string|HTMLVideoElement|null} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<void>} | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeFromVideoDevice = function (deviceId, videoSource, callbackFn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var videoConstraints, constraints; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.reset(); | ||
if (!deviceId) { | ||
@@ -262,10 +365,52 @@ videoConstraints = { facingMode: 'environment' }; | ||
constraints = { video: videoConstraints }; | ||
return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)]; | ||
return [4 /*yield*/, this.decodeFromConstraints(constraints, videoSource, callbackFn)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Continuously tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeFromConstraints = function (constraints, videoSource, callbackFn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var stream; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)]; | ||
case 1: | ||
stream = _a.sent(); | ||
return [4 /*yield*/, this.decodeFromStream(stream, videoSource, callbackFn)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element. | ||
* | ||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from | ||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown. | ||
* @returns {Promise<Result>} The decoding result. | ||
* | ||
* @memberOf BrowserCodeReader | ||
*/ | ||
BrowserCodeReader.prototype.decodeFromStream = function (stream, videoSource, callbackFn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var video; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.reset(); | ||
return [4 /*yield*/, this.attachStreamToVideo(stream, videoSource)]; | ||
case 2: | ||
case 1: | ||
video = _a.sent(); | ||
this.decodeContinuously(video, callbackFn); | ||
return [2 /*return*/]; | ||
return [4 /*yield*/, this.decodeContinuously(video, callbackFn)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
@@ -299,3 +444,2 @@ }); | ||
case 0: | ||
this.reset(); | ||
videoElement = this.prepareVideoElement(videoSource); | ||
@@ -340,4 +484,4 @@ this.addVideoSource(videoElement, stream); | ||
*/ | ||
BrowserCodeReader.prototype.isVideoPLaying = function (video) { | ||
return !!(video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2); | ||
BrowserCodeReader.prototype.isVideoPlaying = function (video) { | ||
return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2; | ||
}; | ||
@@ -354,4 +498,4 @@ /** | ||
case 0: | ||
if (!this.isVideoPLaying(videoElement)) { | ||
console.warn('Trying yo play video that is already playing.'); | ||
if (this.isVideoPlaying(videoElement)) { | ||
console.warn('Trying to play video that is already playing.'); | ||
return [2 /*return*/]; | ||
@@ -456,3 +600,3 @@ } | ||
if (this.isImageLoaded(element)) { | ||
task = this.decodeAsync(element, false, true); | ||
task = this.decodeOnce(element, false, true); | ||
} | ||
@@ -485,3 +629,3 @@ else { | ||
if (!source) { | ||
throw new ArgumentException_1.default('An image element must be provided.'); | ||
throw new ArgumentException_1.default('A video element must be provided.'); | ||
} | ||
@@ -541,3 +685,3 @@ this.reset(); | ||
return new Promise(function (resolve, reject) { | ||
_this.imageLoadedListener = function () { return _this.decodeAsync(element, false, true).then(resolve, reject); }; | ||
_this.imageLoadedListener = function () { return _this.decodeOnce(element, false, true).then(resolve, reject); }; | ||
element.addEventListener('load', _this.imageLoadedListener); | ||
@@ -556,3 +700,3 @@ }); | ||
_a.sent(); | ||
return [4 /*yield*/, this.decodeAsync(videoElement)]; | ||
return [4 /*yield*/, this.decodeOnce(videoElement)]; | ||
case 2: | ||
@@ -638,5 +782,5 @@ // starts decoding after played the video | ||
/** | ||
* Continuously decodes from video input until it finds some value. | ||
* Tries to decode from the video input until it finds some value. | ||
*/ | ||
BrowserCodeReader.prototype.decodeAsync = function (element, retryIfNotFound, retryIfChecksumOrFormatError) { | ||
BrowserCodeReader.prototype.decodeOnce = function (element, retryIfNotFound, retryIfChecksumOrFormatError) { | ||
var _this = this; | ||
@@ -662,3 +806,3 @@ if (retryIfNotFound === void 0) { retryIfNotFound = true; } | ||
// trying again | ||
return setTimeout(function () { return loop(resolve, reject); }, 0); | ||
return setTimeout(function () { return loop(resolve, reject); }, _this._timeBetweenDecodingAttempts); | ||
} | ||
@@ -687,11 +831,9 @@ reject(e); | ||
catch (e) { | ||
callbackFn(null, e); | ||
var isChecksumOrFormatError = e instanceof ChecksumException_1.default || e instanceof FormatException_1.default; | ||
var isNotFound = e instanceof NotFoundException_1.default; | ||
if (!isChecksumOrFormatError && !isNotFound) { | ||
// not expected | ||
throw e; | ||
if (isChecksumOrFormatError || isNotFound) { | ||
// trying again | ||
setTimeout(function () { return loop(); }, _this._timeBetweenDecodingAttempts); | ||
} | ||
// trying again | ||
callbackFn(null, e); | ||
setTimeout(function () { return loop(); }, 0); | ||
} | ||
@@ -698,0 +840,0 @@ }; |
{ | ||
"name": "@zxing/library", | ||
"version": "0.14.2", | ||
"version": "0.15.0", | ||
"description": "TypeScript port of ZXing multi-format 1D/2D barcode image processing library.", | ||
@@ -77,3 +77,3 @@ "keywords": [ | ||
"@types/seedrandom": "^2.4.27", | ||
"@types/sharp": "^0.21.2", | ||
"@types/sharp": "^0.22.2", | ||
"@types/text-encoding": "0.0.35", | ||
@@ -101,3 +101,3 @@ "awesome-typescript-loader": "^5.2.1", | ||
"seedrandom": "^2.4.4", | ||
"sharp": "^0.21.3", | ||
"sharp": "^0.22.1", | ||
"shx": "0.3.2", | ||
@@ -104,0 +104,0 @@ "sinon": "^7.2.7", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2711656
22499