"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("../../node_modules/mic-check/lib/index.js");var e=require("../webrtc/janus.js"),i=require("../../store/index.js"),r=require("../user/default_device.js");require("react");var t=require("../../utils/genericFunctions/localStorage.js");require("../../node_modules/tslib/tslib.es6.js");var n=require("../../_virtual/index6.js"),o=e.default;exports.checkMediaPermissions=function(){if(r.isPhysical())return i.store.dispatch.alerts.removeAlert("browser_permissions"),i.store.dispatch.alerts.removeAlert("user_permissions"),i.store.dispatch.alerts.removeAlert("busy_camera"),void i.store.dispatch.alerts.removeAlert("unknown_media_permissions");n.__exports.requestMediaPermissions({audio:!0}).then((function(){})).catch((function(e){var r,t,s=e.type,d=null!==(t=((r={})[n.__exports.MediaPermissionsErrorType.SystemPermissionDenied]={alert:"browser_permissions",message:"WebRTC: browser does not have permission to access camera or microphone"},r[n.__exports.MediaPermissionsErrorType.UserPermissionDenied]={alert:"user_permissions",message:"WebRTC: user didn't allow app to access camera or microphone"},r)[s])&&void 0!==t?t:{alert:"unknown_media_permissions",message:"WebRTC: can't access audio or camera on this device. unknown error"};i.store.dispatch.alerts.setAlert(d.alert),o.error&&o.error(d.message)}))},exports.checkWebCamPermission=function(){return new Promise((function(e){n.__exports.requestMediaPermissions({video:!0}).then((function(){e(!0)})).catch((function(i){console.error("Error requesting webcam permission:",i),e(!1)}))}))},exports.getCurrentAudioInputDeviceId=function(){var e=t.getJSONItem("phone-island-audio-input-device").deviceId||null,r=i.store.select.mediaDevices.audioInputDevices(i.store.getState());if(r.find((function(i){return i.deviceId===e})))return e;var n=r.find((function(e){return"default"===e.deviceId||""===e.deviceId}))||r[0],o=n?n.deviceId:"default";return null!==e&&o!==e&&(console.warn("Audio input device ".concat(e," no longer available, falling back to default device")),t.setJSONItem("phone-island-audio-input-device",{deviceId:o})),o},exports.getCurrentAudioOutputDeviceId=function(){var e=t.getJSONItem("phone-island-audio-output-device").deviceId||null,r=i.store.select.mediaDevices.audioOutputDevices(i.store.getState());if(r.find((function(i){return i.deviceId===e})))return e;var n=r.find((function(e){return"default"===e.deviceId||""===e.deviceId}))||r[0],o=n?n.deviceId:"default";return null!==e&&o!==e&&(console.warn("Audio output device ".concat(e," no longer available, falling back to default device")),t.setJSONItem("phone-island-audio-output-device",{deviceId:o})),o},exports.getCurrentVideoInputDeviceId=function(){var e=t.getJSONItem("phone-island-video-input-device").deviceId||null,r=i.store.select.mediaDevices.videoInputDevices(i.store.getState());if(r.find((function(i){return i.deviceId===e})))return e;var n=r.find((function(e){return"default"===e.deviceId||""===e.deviceId}))||r[0],o=n?n.deviceId:"default";return null!==e&&o!==e&&(console.warn("Video input device ".concat(e," no longer available, falling back to default device")),t.setJSONItem("phone-island-video-input-device",{deviceId:o})),o},exports.getSupportedDevices=function(e){var i,r,t=!1,n=!1,s=!1,d=!1;i=function(){var i={audio:t,audioCap:s,video:n,videoCap:d};o.log&&o.log("supportedDevices=",i),e()},r=[],navigator.mediaDevices.enumerateDevices().then((function(e){e.forEach((function(e){var i=!1;r.forEach((function(r){r.deviceId===e.deviceId&&r.kind===e.kind&&(i=!0)})),i||("videoinput"!==e.kind||d||(d=!0),"audioinput"!==e.kind||s||(s=!0),"audioinput"===e.kind&&(t=!0),e.kind,"videoinput"===e.kind&&(n=!0),r.push(e))})),i&&i()}))};
//# sourceMappingURL=devices.js.map
