Skip to content

Commit

Permalink
Merge pull request #171 from ericblade/dev
Browse files Browse the repository at this point in the history
Fix #5 parallel use of decodeSingle, part of #105, restructuring
  • Loading branch information
ericblade committed May 1, 2020
2 parents e9c0fd1 + 0be2778 commit e44a619
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 293 deletions.
52 changes: 28 additions & 24 deletions src/common/typedefs.js
@@ -1,29 +1,33 @@
/*
* typedefs.js
* Normalizes browser-specific prefixes
* Normalizes browser-specific prefixes and provide some basic polyfills
*/

if (typeof window !== 'undefined') {
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function FrameRequestCallback */ callback) {
window.setTimeout(callback, 1000 / 60);
};
}());
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function () {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function FrameRequestCallback */ callback) {
window.setTimeout(callback, 1000 / 60);
};
}());
}
}

if (typeof Math.imul !== 'function') {
Math.imul = function(a, b) {
const ah = (a >>> 16) & 0xffff;
const al = a & 0xffff;
const bh = (b >>> 16) & 0xffff;
const bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
};
}
Math.imul = Math.imul || function(a, b) {
var ah = (a >>> 16) & 0xffff,
al = a & 0xffff,
bh = (b >>> 16) & 0xffff,
bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
};

if (typeof Object.assign !== 'function') {
Object.assign = function(target) { // .length of function is 2
Expand All @@ -32,13 +36,13 @@ if (typeof Object.assign !== 'function') {
throw new TypeError('Cannot convert undefined or null to object');
}

var to = Object(target);
const to = Object(target);

for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
for (let index = 1; index < arguments.length; index++) {
const nextSource = arguments[index];

if (nextSource !== null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
for (let nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
Expand Down
1 change: 1 addition & 0 deletions src/config/config.ts
Expand Up @@ -5,6 +5,7 @@ import ProdConfig from './config.prod';

declare var ENV: QuaggaBuildEnvironment;

// @ts-ignore // TODO: this produces a bizarre typescript error
const QuaggaConfig: QuaggaJSConfigObject = ENV.development
? DevConfig
: ENV.node
Expand Down
4 changes: 2 additions & 2 deletions src/input/camera_access.ts
Expand Up @@ -69,7 +69,7 @@ function deprecatedConstraints(videoConstraints: MediaTrackConstraintsWithDeprec
return normalized;
}

export function pickConstraints(videoConstraints: MediaTrackConstraintsWithDeprecated): Promise<MediaStreamConstraints> {
export function pickConstraints(videoConstraints: MediaTrackConstraintsWithDeprecated = {}): Promise<MediaStreamConstraints> {
const video = deprecatedConstraints(videoConstraints);

if (video && video.deviceId && video.facingMode) {
Expand All @@ -95,7 +95,7 @@ function getActiveTrack(): MediaStreamTrack | null {
* Used for accessing information about the active stream track and available video devices.
*/
const QuaggaJSCameraAccess = {
request: function(video: HTMLVideoElement, videoConstraints: MediaTrackConstraintsWithDeprecated): Promise<any> {
request: function(video: HTMLVideoElement, videoConstraints?: MediaTrackConstraintsWithDeprecated): Promise<any> {
return pickConstraints(videoConstraints)
.then((newConstraints) => initCamera(video, newConstraints))
.catch(err => {
Expand Down

0 comments on commit e44a619

Please sign in to comment.