UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 3.4 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("../utils.js").log;exports.shimGetUserMedia=function(r,o){if(o.version>=64)return;const t=r&&r.navigator;if(!t.mediaDevices)return;const i=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;const r={};return Object.keys(e).forEach((o=>{if("require"===o||"advanced"===o||"mediaSource"===o)return;const t="object"==typeof e[o]?e[o]:{ideal:e[o]};void 0!==t.exact&&"number"==typeof t.exact&&(t.min=t.max=t.exact);const i=function(e,r){return e?e+r.charAt(0).toUpperCase()+r.slice(1):"deviceId"===r?"sourceId":r};if(void 0!==t.ideal){r.optional=r.optional||[];let e={};"number"==typeof t.ideal?(e[i("min",o)]=t.ideal,r.optional.push(e),e={},e[i("max",o)]=t.ideal,r.optional.push(e)):(e[i("",o)]=t.ideal,r.optional.push(e))}void 0!==t.exact&&"number"!=typeof t.exact?(r.mandatory=r.mandatory||{},r.mandatory[i("",o)]=t.exact):["min","max"].forEach((e=>{void 0!==t[e]&&(r.mandatory=r.mandatory||{},r.mandatory[i(e,o)]=t[e])}))})),e.advanced&&(r.optional=(r.optional||[]).concat(e.advanced)),r},n=function(r,n){if(o.version>=61)return n(r);if((r=JSON.parse(JSON.stringify(r)))&&"object"==typeof r.audio){const e=function(e,r,o){r in e&&!(o in e)&&(e[o]=e[r],delete e[r])};e((r=JSON.parse(JSON.stringify(r))).audio,"autoGainControl","googAutoGainControl"),e(r.audio,"noiseSuppression","googNoiseSuppression"),r.audio=i(r.audio)}if(r&&"object"==typeof r.video){let a=r.video.facingMode;a=a&&("object"==typeof a?a:{ideal:a});const d=o.version<66;if(a&&("user"===a.exact||"environment"===a.exact||"user"===a.ideal||"environment"===a.ideal)&&(!t.mediaDevices.getSupportedConstraints||!t.mediaDevices.getSupportedConstraints().facingMode||d)){let o;if(delete r.video.facingMode,"environment"===a.exact||"environment"===a.ideal?o=["back","rear"]:"user"!==a.exact&&"user"!==a.ideal||(o=["front"]),o)return t.mediaDevices.enumerateDevices().then((t=>{let d=(t=t.filter((e=>"videoinput"===e.kind))).find((e=>o.some((r=>e.label.toLowerCase().includes(r)))));return!d&&t.length&&o.includes("back")&&(d=t[t.length-1]),d&&(r.video.deviceId=a.exact?{exact:d.deviceId}:{ideal:d.deviceId}),r.video=i(r.video),e("chrome: "+JSON.stringify(r)),n(r)}))}r.video=i(r.video)}return e("chrome: "+JSON.stringify(r)),n(r)},a=function(e){return o.version>=64?e:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[e.name]||e.name,message:e.message,constraint:e.constraint||e.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}};if(t.getUserMedia=function(e,r,o){n(e,(e=>{t.webkitGetUserMedia(e,r,(e=>{o&&o(a(e))}))}))}.bind(t),t.mediaDevices.getUserMedia){const e=t.mediaDevices.getUserMedia.bind(t.mediaDevices);t.mediaDevices.getUserMedia=function(r){return n(r,(r=>e(r).then((e=>{if(r.audio&&!e.getAudioTracks().length||r.video&&!e.getVideoTracks().length)throw e.getTracks().forEach((e=>{e.stop()})),new DOMException("","NotFoundError");return e}),(e=>Promise.reject(a(e))))))}}}; //# sourceMappingURL=getusermedia.js.map