@microblink/blinkinput-in-browser-sdk
Version:
A simple barcode scanning library for WebAssembly-enabled browsers.
55 lines (43 loc) • 1.3 kB
text/typescript
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
import * as BlinkInputSDK from "../../../es/blinkinput-sdk";
export function hasVideoDevices(): Promise<boolean> {
return new Promise((resolve) => {
if (
!window.navigator ||
!window.navigator.mediaDevices ||
typeof window.navigator.mediaDevices.enumerateDevices !== 'function'
) {
resolve(false);
return;
}
window.navigator.mediaDevices.enumerateDevices().then((devices) => {
devices = devices || [];
for (const device of devices) {
if (device && device.kind === 'videoinput') {
resolve(true);
return;
}
}
resolve(false);
});
});
}
export function isWasmSupported(): Promise<boolean> {
return new Promise((resolve) => {
const wasmSupport = BlinkInputSDK.isBrowserSupported();
resolve(wasmSupport);
});
}
export async function checkMandatoryCapabilites(): Promise<boolean> {
const wasmSupport = await isWasmSupported();
return wasmSupport;
}
/**
* Determine whether this is a desktop device based on the screen resolution.
*/
export function isDesktop(): boolean {
const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
return viewportWidth >= 1024;
}