UNPKG

@privateid/ultra-web-sdk-alpha

Version:
46 lines 3.07 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 } from '../camera.types'; import { getDefaultCameraDeviceId, printLogs, setDefaultCameraDeviceId } from '../../../global/shared.utils'; import { getFilteredVideoDevices, getDefaultDevice, getExternalDevice, createMacSafariVideoConstraints, } from '../camera.utils'; import { CAMERA_LOW_RES_WIDTH } from '../camera.constants'; export class MacSafariCameraService extends BaseCameraService { openCamera(props) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { try { const faceMode = props.requestFaceMode || CameraFaceMode.front; this.setVideoElementId(props.videoElementId); this.setFaceMode(faceMode); printLogs('Opening Camera on Mac Safari', ''); const devices = yield getFilteredVideoDevices(); const defaultDeviceId = getDefaultCameraDeviceId(); const externalDeviceId = getExternalDevice(devices); const isDefaultDeviceAvailable = devices.find((device) => defaultDeviceId === device.deviceId); const deviceId = props.deviceId || (isDefaultDeviceAvailable ? defaultDeviceId : externalDeviceId.deviceId); this.setCurrentDeviceId(deviceId); setDefaultCameraDeviceId(deviceId); const deviceCapabilities = getDefaultDevice(devices, deviceId); const resolution = ((_a = props.canvasResolution) === null || _a === void 0 ? void 0 : _a.width) || Math.min(((_c = (_b = deviceCapabilities[0]) === null || _b === void 0 ? void 0 : _b.width) === null || _c === void 0 ? void 0 : _c.max) || CAMERA_LOW_RES_WIDTH, CAMERA_LOW_RES_WIDTH); const constraints = createMacSafariVideoConstraints(deviceCapabilities[0].deviceId, resolution, props.canvasResolution); const stream = yield navigator.mediaDevices.getUserMedia(constraints); return this.prepareCameraResult(stream, devices, faceMode, props.videoElementId); } catch (e) { printLogs(`Error while getAccessToCamera: `, e, 'ERROR'); return null; } }); } } //# sourceMappingURL=MacSafariCameraService.js.map