UNPKG

@privateid/ultra-web-sdk-alpha

Version:
50 lines 2.78 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /* eslint-disable import/prefer-default-export */ import { BaseCameraService } from './BaseCameraService'; import { CameraFaceMode, FacingMode } from '../camera.types'; import { printLogs } from '../../../global/shared.utils'; import { getVideoConstraints, getCameraList, getDevicesWithCapabilities, getVideoInputDevices } from '../camera.utils'; export class MobileCameraService extends BaseCameraService { openCamera(props) { return __awaiter(this, void 0, void 0, function* () { try { this.closeMediaStream(); let inCatchBlock = false; this.setVideoElementId(props.videoElementId); this.setFaceMode(props.requestFaceMode || CameraFaceMode.front); printLogs('Opening Camera on Mobile', ''); let devices = yield getVideoInputDevices(); devices = getDevicesWithCapabilities(devices); let stream; let hasError = true; while (hasError) { try { const videoConstraint = getVideoConstraints(yield getCameraList(this.getFaceMode() === CameraFaceMode.back), this.getFaceMode() === CameraFaceMode.back ? FacingMode.environment : FacingMode.face, false, // requireHD props.isDocumentScan, props.canvasResolution, inCatchBlock); printLogs(`videoConstraint: `, videoConstraint); stream = yield navigator.mediaDevices.getUserMedia(videoConstraint); hasError = false; } catch (e) { printLogs(`openCameraMobile: `, e, 'ERROR'); inCatchBlock = true; } } return this.prepareCameraResult(stream, devices, this.getFaceMode(), this.getVideoElementId()); } catch (e) { printLogs(`Error: `, e, 'ERROR'); return null; } }); } } //# sourceMappingURL=MobileCameraService.js.map