instascan-last
Advanced tools
Comparing version 2.0.4 to 2.0.5
{ | ||
"name": "instascan-last", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Webcam-driven QR code scanner.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
function cameraName (label) { | ||
function cameraName(label) { | ||
let clean = label.replace(/\s*\([0-9a-f]+(:[0-9a-f]+)?\)\s*$/, ''); | ||
@@ -7,3 +7,3 @@ return clean || label || null; | ||
class MediaError extends Error { | ||
constructor (type) { | ||
constructor(type) { | ||
super(`Cannot access video stream (${type}).`); | ||
@@ -15,3 +15,3 @@ this.type = type; | ||
class Camera { | ||
constructor (id, name) { | ||
constructor(id, name) { | ||
this.id = id; | ||
@@ -22,3 +22,3 @@ this.name = name; | ||
async start () { | ||
async start() { | ||
this._stream = await Camera._wrapErrors(async () => { | ||
@@ -38,3 +38,3 @@ return await navigator.mediaDevices.getUserMedia({ | ||
stop () { | ||
stop() { | ||
if (!this._stream) { | ||
@@ -51,3 +51,3 @@ return; | ||
static async getCameras () { | ||
static async getCameras() { | ||
await this._ensureAccess(); | ||
@@ -62,11 +62,14 @@ | ||
static async _ensureAccess () { | ||
return this._wrapErrors(async () => { | ||
await navigator.mediaDevices.getUserMedia({video: true}); | ||
static async _ensureAccess() { | ||
return await this._wrapErrors(async () => { | ||
let access = await navigator.mediaDevices.getUserMedia({video: true}); | ||
for (let stream of access.getVideoTracks()) { | ||
stream.stop(); | ||
} | ||
}); | ||
} | ||
static async _wrapErrors (fn) { | ||
static async _wrapErrors(fn) { | ||
try { | ||
return fn(); | ||
return await fn(); | ||
} catch (e) { | ||
@@ -73,0 +76,0 @@ if (e.name) { |
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
1351006
5535