// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Microsoft Software License Terms for the Azure Communications Services, Azure CPaaS, MICROSOFT AZURE COMMUNICATION CALLING EFFECTS
// See LICENSE file for license information.

import{stringifyObject as e}from"./cd7b0b.js";import{simd as t}from"./887ba7.js";var __awaiter=function(e,t,i,o){function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,r){function fulfilled(e){try{step(o.next(e))}catch(e){r(e)}}function rejected(e){try{step(o.throw(e))}catch(e){r(e)}}function step(e){e.done?i(e.value):adopt(e.value).then(fulfilled,rejected)}step((o=o.apply(e,t||[])).next())}))};class CapabilityChecker{constructor(e,t){var i,o,r;this.configProvider=e,this.logger=t,this._videoEffectsSupported=!1,this._audioEffectsSupported=!1,this._config=this.configProvider.config,this._config.videoEffects.enableVideoEffects&&(this._videoEffectsSupported=(null===(r=null===(o=null===(i=this._config)||void 0===i?void 0:i.videoEffects)||void 0===o?void 0:o.webcvConfig)||void 0===r?void 0:r.useWasmEffects)?this.isWasmVideoEffectSupported():this.isWebgl2EffectSupported())}videoEffectsSupported(){return __awaiter(this,void 0,void 0,(function*(){return this._videoEffectsSupported}))}audioEffectsSupported(){return __awaiter(this,void 0,void 0,(function*(){return this._config.audioEffects.enableAudioEffects?(this._audioEffectsSupported=yield this.isWasmAudioEffectSupported(),this._audioEffectsSupported):(this.logger.info("Audio effects are disabled."),!1)}))}isWasmVideoEffectSupported(){var e,t,i;return(null===(i=null===(t=null===(e=this._config)||void 0===e?void 0:e.videoEffects)||void 0===t?void 0:t.webcvConfig)||void 0===i?void 0:i.useWasmEffects)?!!window.MediaStreamTrackProcessor||(this.logger.info("wasmEffects disabled, insertable streams are not supported"),!1):(this.logger.info("wasmEffects disabled by WebCV feature flag"),!1)}isWebgl2EffectSupported(){return this.isCurrentRendererSupported()&&this.isWebGL2Supported()}isCurrentRendererSupported(){var t,i,o,r;const n=null!==(r=null===(o=null===(i=null===(t=this._config)||void 0===t?void 0:t.videoEffects)||void 0===i?void 0:i.webcvConfig)||void 0===o?void 0:o.webGLUnsupportedRenderers)&&void 0!==r?r:[];let s=!1;try{const t=document.createElement("canvas").getContext("webgl"),i=null==t?void 0:t.getExtension("WEBGL_debug_renderer_info"),o=i&&(null==t?void 0:t.getParameter(i.UNMASKED_RENDERER_WEBGL));return o&&!n.some((e=>e===o))?s=!0:this.logger.info(`Unsupported renderer: ${e(o)}`),s}catch(e){return this.logger.warn(`error trying to check compatibility: ${JSON.stringify(e)}`),!1}}isWebGL2Supported(){var t,i,o,r,n;if(CapabilityChecker.webgl2Checked)return CapabilityChecker.webgl2Supported;try{const s=document.createElement("canvas").getContext("webgl2");if(s){const d=null!==(t=s.getSupportedExtensions())&&void 0!==t?t:[],f=(null!==(n=null===(r=null===(o=null===(i=this._config)||void 0===i?void 0:i.videoEffects)||void 0===o?void 0:o.webcvConfig)||void 0===r?void 0:r.webGLRequiredExtensions)&&void 0!==n?n:[]).filter((e=>!d.includes(e)));f.length>0?this.logger.info(`Unsupported WebGL2 extensions: ${e(f)}`):CapabilityChecker.webgl2Supported=!0}else this.logger.info("WebGL2 context is not supported")}catch(t){this.logger.error(`isWebGL2Supported: ${e(t)}`)}return CapabilityChecker.webgl2Checked=!0,CapabilityChecker.webgl2Supported}isWasmAudioEffectSupported(){return __awaiter(this,void 0,void 0,(function*(){if(!window.AudioWorkletNode)return this.logger.info("AudioWorkletNode is not supported"),!1;if(!window.WebAssembly)return this.logger.info("WebAssembly is not supported"),!1;return!!(yield t())||(this.logger.info("SIMD is not supported"),!1)}))}}CapabilityChecker.webgl2Supported=!1,CapabilityChecker.webgl2Checked=!1;export{CapabilityChecker};
