opentok-network-test-js
Version:
Precall network test for applications using the OpenTok platform.
2 lines • 91.5 kB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("OpenTokNetworkConnectivity",[],t):"object"==typeof exports?exports.OpenTokNetworkConnectivity=t():e.OpenTokNetworkConnectivity=t()}(self,()=>(()=>{var e={451(e,t,r){var n,o,s;function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,a(n.key),n)}}function a(e){return e=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);if(r=r.call(e,t||"default"),"object"!=c(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string"),"symbol"==c(e)?e:e+""}function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}o=[r(425)],void 0===(s="function"==typeof(n=function(e){function t(t){var o;t=(e=>{if(!e.clientVersion)throw console.log("Error. The clientVersion field cannot be null in the log entry"),new Error("The clientVersion field cannot be null in the log entry");if(!e.source)throw console.log("Error. The source field cannot be null in the log entry"),new Error("The source field cannot be null in the log entry");if(!e.componentId)throw console.log("Error. The componentId field cannot be null in the log entry"),new Error("The componentId field cannot be null in the log entry");var t,r;if(e.name)return t=e.logVersion||"2",r=e.clientSystemTime||(new Date).getTime(),Object.assign({},e,{logVersion:t,clientSystemTime:r});throw console.log("Error. The name field cannot be null in the log entry"),new Error("The guid field cannot be null in the log entry")})(t),n?e.post(r,t):((o=new XMLHttpRequest).open("POST",r,!0),o.setRequestHeader("Content-type","application/json"),o.send(JSON.stringify(t)))}var r,n=!1,o=function(e,t,r){var o,s;return n||(o="",r&&((s=new Date).setTime(s.getTime()+24*r*60*60*1e3),o=["; expires=",s.toGMTString()].join("")),r=[e,"=",t,o,"; path=/"].join(""),document.cookie=r),t},s=function(e){if(!n)for(var t,r="".concat(e,"="),o=document.cookie.split(";"),s=0;s<o.length;s++){for(t=o[s];" "===t.charAt(0);)t=t.substring(1,t.length);if(0===t.indexOf(r))return t.substring(r.length,t.length)}return null},a=function(){for(var e=[],t="0123456789abcdef",r=0;r<36;r++)e.push(t.substr(Math.floor(16*Math.random()),1));return e[14]="4",e[19]=t.substr(3&e[19]|8,1),e[8]=e[13]=e[18]=e[23]="-",e.join("")};return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}(function e(t,i){(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,e),this.analyticsData=t,n=i&&i.server;var c="hlg.tokbox.com/prod/logging/ClientEvent";i&&i.loggingUrl&&(c=i.loggingUrl),r=i&&i.proxyUrl&&"".concat(i.proxyUrl,"/").concat(c)||"https://".concat(c),this.analyticsData.guid=(i=t.name,s(i)||o(i,a(),7))},[{key:"addSessionInfo",value:function(e){if(!e.sessionId)throw console.log("Error. The sessionId field cannot be null in the log entry"),new Error("The sessionId field cannot be null in the log entry");if(this.analyticsData.sessionId=e.sessionId,!e.connectionId)throw console.log("Error. The connectionId field cannot be null in the log entry"),new Error("The connectionId field cannot be null in the log entry");if(this.analyticsData.connectionId=e.connectionId,0===e.partnerId)throw console.log("Error. The partnerId field cannot be null in the log entry"),new Error("The partnerId field cannot be null in the log entry");this.analyticsData.partnerId=e.partnerId}},{key:"logEvent",value:function(e){this.analyticsData=Object.assign({},this.analyticsData,e,{clientSystemTime:(new Date).getTime()}),t(this.analyticsData)}}])})?n.apply(t,o):n)||(e.exports=s)},394(e,t,r){"use strict";t.UnsupportedResolutionError=t.PermissionDeniedError=t.InvalidOnUpdateCallback=t.MissingSessionCredentialsError=t.IncompleteSessionCredentialsError=t.MissingOpenTokInstanceError=t.NetworkTestError=void 0;const n=r(635);class o extends Error{constructor(e,t){super(e),this.name=t||n.ErrorNames.NETWORK_TEST_ERROR,this.stack=new Error(e).stack}}t.NetworkTestError=o;t.MissingOpenTokInstanceError=class extends o{constructor(){super("An instance of OT, the OpenTok.js client SDK, is required."),this.name=n.ErrorNames.MISSING_OPENTOK_INSTANCE}};t.IncompleteSessionCredentialsError=class extends o{constructor(){super("NetworkConnectivity requires an apiKey, sessionId, and token.",n.ErrorNames.INCOMPLETE_SESSON_CREDENTIALS)}};t.MissingSessionCredentialsError=class extends o{constructor(){super("NetworkConnectivity requires OpenTok session credentials.",n.ErrorNames.MISSING_SESSON_CREDENTIALS)}};t.InvalidOnUpdateCallback=class extends o{constructor(){super("The onUpdate callback must be a function that accepts a single parameter.",n.ErrorNames.INVALID_ON_UPDATE_CALLBACK)}};t.PermissionDeniedError=class extends o{constructor(){super("Precall failed to acquire camera due to a permissions error.",n.ErrorNames.PERMISSION_DENIED_ERROR)}};t.UnsupportedResolutionError=class extends o{constructor(){super("The camera does not support the given resolution.",n.ErrorNames.UNSUPPORTED_RESOLUTION_ERROR)}}},635(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.errorHasName=t.OTErrorType=t.ErrorNames=void 0;const n=r(237);var o,s;!function(e){e.NETWORK_TEST_ERROR="NetworkTestError",e.MISSING_OPENTOK_INSTANCE="MissingOpenTokInstanceError",e.INCOMPLETE_SESSON_CREDENTIALS="IncompleteSessionCredentialsError",e.MISSING_SESSON_CREDENTIALS="MissingSessionCredentialsError",e.INVALID_ON_UPDATE_CALLBACK="InvalidOnUpdateCallback",e.CONNECTIVITY_ERROR="ConnectivityError",e.API_CONNECTIVITY_ERROR="APIConnectivityError",e.CONNECT_TO_SESSION_ERROR="ConnectToSessionError",e.CONNECT_TO_SESSION_TOKEN_ERROR="ConnectToSessionTokenError",e.CONNECT_TO_SESSION_ID_ERROR="ConnectToSessionSessionIdError",e.CONNECT_TO_SESSION_NETWORK_ERROR="ConnectToSessionNetworkError",e.MEDIA_DEVICE_ERROR="MediaDeviceError",e.FAILED_TO_OBTAIN_MEDIA_DEVICES="FailedToObtainMediaDevices",e.NO_VIDEO_CAPTURE_DEVICES="NoVideoCaptureDevicesError",e.NO_AUDIO_CAPTURE_DEVICES="NoAudioCaptureDevicesError",e.PUBLISH_TO_SESSION_ERROR="PublishToSessionError",e.INIT_PUBLISHER_ERROR="InitPublisherError",e.FAILED_MESSAGING_SERVER_TEST="FailedMessagingServerTestError",e.FAILED_TO_CREATE_LOCAL_PUBLISHER="FailedToCreateLocalPublisher",e.PUBLISH_TO_SESSION_NOT_CONNECTED="PublishToSessionNotConnectedError",e.PUBLISH_TO_SESSION_PERMISSION_OR_TIMEOUT_ERROR="PublishToSessionPermissionOrTimeoutError",e.PUBLISH_TO_SESSION_NETWORK_ERROR="PublishToSessionNetworkError",e.MEDIA_ACCESS_REVOKED_ERROR="MediaAccessRevokedError",e.SUBSCRIBE_TO_SESSION_ERROR="SubscribeToSessionError",e.LOGGING_SERVER_CONNECTION_ERROR="LoggingServerConnectionError",e.QUALITY_TEST_ERROR="QualityTestError",e.UNSUPPORTED_BROWSER="UnsupportedBrowser",e.SUBSCRIBER_GET_STATS_ERROR="SubscriberGetStatsError",e.MISSING_SUBSCRIBER_ERROR="MissingSubscriberError",e.PERMISSION_DENIED_ERROR="PermissionDeniedError",e.UNSUPPORTED_RESOLUTION_ERROR="UnsupportedResolutionError",e.TYPE_ERROR="TypeError"}(o||(t.ErrorNames=o={})),function(e){e.JS_EXCEPTION="JS_EXCEPTION",e.OT_AUTHENTICATION_ERROR="OT_AUTHENTICATION_ERROR",e.OT_INVALID_HTTP_STATUS="OT_INVALID_HTTP_STATUS",e.OT_CONNECT_FAILED="OT_CONNECT_FAILED",e.OT_INVALID_SESSION_ID="OT_INVALID_SESSION_ID",e.CONNECT_FAILED="CONNECT_FAILED",e.CONNECT_REJECTED="CONNECT_REJECTED",e.CONNECTION_TIMEOUT="CONNECTION_TIMEOUT",e.NOT_CONNECTED="NOT_CONNECTED",e.INVALID_PARAMETER="INVALID_PARAMETER",e.P2P_CONNECTION_FAILED="P2P_CONNECTION_FAILED",e.API_RESPONSE_FAILURE="API_RESPONSE_FAILURE",e.TERMS_OF_SERVICE_FAILURE="TERMS_OF_SERVICE_FAILURE",e.CONNECTION_LIMIT_EXCEEDED="CONNECTION_LIMIT_EXCEEDED",e.UNABLE_TO_PUBLISH="UNABLE_TO_PUBLISH",e.UNABLE_TO_SUBSCRIBE="UNABLE_TO_SUBSCRIBE",e.UNSUPPORTED_VIDEO_CODEC="UNSUPPORTED_VIDEO_CODEC",e.UNABLE_TO_FORCE_DISCONNECT="UNABLE_TO_FORCE_DISCONNECT",e.UNABLE_TO_FORCE_UNPUBLISH="UNABLE_TO_FORCE_UNPUBLISH",e.PUBLISHER_ICE_WORKFLOW_FAILED="PUBLISHER_ICE_WORKFLOW_FAILED",e.SUBSCRIBER_ICE_WORKFLOW_FAILED="SUBSCRIBER_ICE_WORKFLOW_FAILED",e.STREAM_LIMIT_EXCEEDED="STREAM_LIMIT_EXCEEDED",e.UNEXPECTED_SERVER_RESPONSE="UNEXPECTED_SERVER_RESPONSE",e.REPORT_ISSUE_ERROR="REPORT_ISSUE_ERROR",e.ANVIL_BADLY_FORMED_RESPONSE="ANVIL_BADLY_FORMED_RESPONSE",e.ANVIL_INVALID_HTTP_STATUS="ANVIL_INVALID_HTTP_STATUS",e.ANVIL_XDOMAIN_OR_PARSING_ERROR="ANVIL_XDOMAIN_OR_PARSING_ERROR",e.ANVIL_UNKNOWN_HTTP_ERROR="ANVIL_UNKNOWN_HTTP_ERROR",e.ANVIL_UNEXPECTED_ERROR_CODE="ANVIL_UNEXPECTED_ERROR_CODE",e.ANVIL_EMPTY_RESPONSE_BODY="ANVIL_EMPTY_RESPONSE_BODY",e.ANVIL_CONNECT_FAILED="ANVIL_CONNECT_FAILED"}(s||(t.OTErrorType=s={}));t.errorHasName=(e=null,t)=>(0,n.get)("name",e)===t},440(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorNames=t.ConnectivityTestResults=t.QualityTestResults=void 0;const o=r(330),s=r(918),i=r(998),a=r(394),c=n(r(451));var u=r(998);Object.defineProperty(t,"QualityTestResults",{enumerable:!0,get:function(){return u.QualityTestResults}});var l=r(918);Object.defineProperty(t,"ConnectivityTestResults",{enumerable:!0,get:function(){return l.ConnectivityTestResults}});t.default=class{constructor(e,t,r){this.validateOT(e),this.validateCredentials(t);const n=this.validateProxyUrl(r);this.otLogging=this.startLoggingEngine(t.apiKey,t.sessionId,n),this.OTInstance=e,this.credentials=t,this.options=r,this.setProxyUrl(n)}validateOT(e){if(!e||"object"!=typeof e||!e.initSession)throw new a.MissingOpenTokInstanceError}validateCredentials(e){if(!e)throw new a.MissingSessionCredentialsError;if(!e.apiKey||!e.sessionId||!e.token)throw new a.IncompleteSessionCredentialsError}validateProxyUrl(e){return e&&e.proxyServerUrl?e.proxyServerUrl:""}setProxyUrl(e){this.OTInstance.setProxyUrl&&"function"==typeof this.OTInstance.setProxyUrl&&e&&this.OTInstance.setProxyUrl(e)}startLoggingEngine(e,t,r){return new c.default({sessionId:t,partnerId:e,source:window.location.href,clientVersion:`js-network-test-${o.version}`,name:"opentok-network-test",componentId:"opentok-network-test"},{proxyUrl:r})}testConnectivity(){return this.otLogging.logEvent({action:"testConnectivity",variation:"Attempt"}),(0,s.testConnectivity)(this.OTInstance,this.credentials,this.otLogging,this.options)}testQuality(e){if(this.otLogging.logEvent({action:"testQuality",variation:"Attempt"}),e&&("function"!=typeof e||1!==e.length))throw this.otLogging.logEvent({action:"testQuality",variation:"Failure",payload:{errorName:"InvalidOnUpdateCallback",reason:"function"!=typeof e?"updateCallback is not a function":"updateCallback does not accept exactly 1 parameter"}}),new a.InvalidOnUpdateCallback;return(0,i.testQuality)(this.OTInstance,this.credentials,this.otLogging,this.options,e)}stop(){(0,i.stopQualityTest)()}};var d=r(635);Object.defineProperty(t,"ErrorNames",{enumerable:!0,get:function(){return d.ErrorNames}})},60(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LoggingServerConnectionError=t.SubscribeToSessionError=t.PublishToSessionNetworkError=t.PublishToSessionPermissionOrTimeoutError=t.PublishToSessionNotConnectedError=t.FailedToCreateLocalPublisher=t.FailedMessagingServerTestError=t.PublishToSessionError=t.NoAudioCaptureDevicesError=t.NoVideoCaptureDevicesError=t.FailedToObtainMediaDevices=t.MediaDeviceError=t.ConnectToSessionNetworkError=t.ConnectToSessionSessionIdError=t.ConnectToSessionTokenError=t.ConnectToSessionError=t.APIConnectivityError=t.ConnectivityError=void 0;const n=r(394),o=r(635);class s extends n.NetworkTestError{constructor(e,t){super(e,t||o.ErrorNames.CONNECTIVITY_ERROR)}}t.ConnectivityError=s;t.APIConnectivityError=class extends s{constructor(){super("Failed to connect to OpenTOK API Server",o.ErrorNames.API_CONNECTIVITY_ERROR)}};class i extends s{constructor(e,t){super(e||"Failed to connect to the session due to a network error.",t||o.ErrorNames.CONNECT_TO_SESSION_ERROR)}}t.ConnectToSessionError=i;t.ConnectToSessionTokenError=class extends i{constructor(){super("Failed to connect to the session due to an invalid token.",o.ErrorNames.CONNECT_TO_SESSION_TOKEN_ERROR)}};t.ConnectToSessionSessionIdError=class extends i{constructor(){super("Failed to connect to the session due to an invalid session ID.",o.ErrorNames.CONNECT_TO_SESSION_ID_ERROR)}};t.ConnectToSessionNetworkError=class extends i{constructor(){super("Failed to connect to the session due to a network error.",o.ErrorNames.CONNECT_TO_SESSION_NETWORK_ERROR)}};class a extends s{constructor(e,t){super(e||"OpenTok failed to find media devices for this browser.",t||o.ErrorNames.MEDIA_DEVICE_ERROR)}}t.MediaDeviceError=a;t.FailedToObtainMediaDevices=class extends a{constructor(){super("Failed to obtain media devices.",o.ErrorNames.FAILED_TO_OBTAIN_MEDIA_DEVICES)}};t.NoVideoCaptureDevicesError=class extends a{constructor(){super("This browser has no video capture devices",o.ErrorNames.NO_VIDEO_CAPTURE_DEVICES)}};t.NoAudioCaptureDevicesError=class extends a{constructor(){super("This browser has no audio capture devices.",o.ErrorNames.NO_AUDIO_CAPTURE_DEVICES)}};class c extends s{constructor(e,t){super(e||"Encountered an unknown error while attempting to publish to a session.",t||o.ErrorNames.PUBLISH_TO_SESSION_ERROR)}}t.PublishToSessionError=c;t.FailedMessagingServerTestError=class extends c{constructor(){super("Failed to connect to media server due to messaging server connection failure",o.ErrorNames.FAILED_MESSAGING_SERVER_TEST)}};t.FailedToCreateLocalPublisher=class extends c{constructor(){super("Failed to create a local publisher object.",o.ErrorNames.FAILED_TO_CREATE_LOCAL_PUBLISHER)}};t.PublishToSessionNotConnectedError=class extends c{constructor(){super("Precall failed to publish to the session because it was not connected.",o.ErrorNames.PUBLISH_TO_SESSION_NOT_CONNECTED)}};t.PublishToSessionPermissionOrTimeoutError=class extends c{constructor(){super("Precall failed to publish to the session due a permissions error or timeout.",o.ErrorNames.PUBLISH_TO_SESSION_PERMISSION_OR_TIMEOUT_ERROR)}};t.PublishToSessionNetworkError=class extends c{constructor(){super("Precall failed to publish to the session due a network error.",o.ErrorNames.PUBLISH_TO_SESSION_NETWORK_ERROR)}};t.SubscribeToSessionError=class extends s{constructor(e){super(e||"Encountered an unknown error while attempting to subscribe to a session.",o.ErrorNames.SUBSCRIBE_TO_SESSION_ERROR)}};t.LoggingServerConnectionError=class extends s{constructor(){super("Failed to connect to the OpenTok logging server.",o.ErrorNames.LOGGING_SERVER_CONNECTION_ERROR)}}},338(e,t,r){"use strict";t.mapErrors=void 0;const n=r(635);var o;!function(e){e.Api="api",e.Messaging="messaging",e.OpentokJs="OpenTok.js",e.Media="media",e.Logging="logging",e.ConnectivityError="OpenTok.js"}(o||(o={}));const s=e=>({error:e,type:(()=>{switch(e.name){case n.ErrorNames.API_CONNECTIVITY_ERROR:case n.ErrorNames.CONNECT_TO_SESSION_NETWORK_ERROR:return o.Api;case n.ErrorNames.CONNECT_TO_SESSION_ERROR:case n.ErrorNames.CONNECT_TO_SESSION_TOKEN_ERROR:case n.ErrorNames.CONNECT_TO_SESSION_ID_ERROR:return o.Messaging;case n.ErrorNames.MEDIA_DEVICE_ERROR:case n.ErrorNames.FAILED_TO_OBTAIN_MEDIA_DEVICES:case n.ErrorNames.NO_VIDEO_CAPTURE_DEVICES:case n.ErrorNames.NO_AUDIO_CAPTURE_DEVICES:case n.ErrorNames.FAILED_TO_CREATE_LOCAL_PUBLISHER:case n.ErrorNames.PUBLISH_TO_SESSION_NOT_CONNECTED:case n.ErrorNames.PUBLISH_TO_SESSION_PERMISSION_OR_TIMEOUT_ERROR:case n.ErrorNames.PUBLISH_TO_SESSION_NETWORK_ERROR:return o.OpentokJs;case n.ErrorNames.PUBLISH_TO_SESSION_ERROR:case n.ErrorNames.SUBSCRIBE_TO_SESSION_ERROR:case n.ErrorNames.FAILED_MESSAGING_SERVER_TEST:return o.Media;case n.ErrorNames.LOGGING_SERVER_CONNECTION_ERROR:return o.Logging;default:return o.OpentokJs}})()});t.mapErrors=(...e)=>e.map(s)},918(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.testConnectivity=function(e,t,r,n){return new Promise((o,s)=>{(function(e,{apiKey:t,sessionId:r,token:n},o){return new Promise((s,i)=>{let a={};o&&o.initSessionOptions&&(a=o.initSessionOptions),o&&o.proxyServerUrl&&(e.hasOwnProperty("setProxyUrl")||(a.proxyUrl=o.proxyServerUrl));const c=e.initSession(t,r,a);c.connect(n,e=>{(0,l.errorHasName)(e,l.OTErrorType.OT_AUTHENTICATION_ERROR)?i(new u.ConnectToSessionTokenError):(0,l.errorHasName)(e,l.OTErrorType.OT_INVALID_SESSION_ID)?i(new u.ConnectToSessionSessionIdError):(0,l.errorHasName)(e,l.OTErrorType.OT_CONNECT_FAILED)?i(new u.ConnectToSessionNetworkError):(0,l.errorHasName)(e,l.OTErrorType.OT_INVALID_HTTP_STATUS)?i(new u.APIConnectivityError):e?i(new u.ConnectToSessionError):s(c)})})})(e,t,n).then(t=>function(e,t,r){return new Promise((n,o)=>{const s=e=>{E(t).then(()=>{o(e)})};(function(e,t){return new Promise((r,n)=>{(function(e){return new Promise((t,r)=>{e.getDevices((e,n=[])=>{if(e)r(new u.FailedToObtainMediaDevices);else{const e=n.reduce((e,t)=>{const r="audioInput"===t.kind?"audio":"video";return Object.assign(Object.assign({},e),{[r]:Object.assign(Object.assign({},e[r]),{[t.deviceId]:t})})},{audio:{},video:{}});Object.keys(e.audio).length||Object.keys(e.video).length?t(e):r(new u.FailedToObtainMediaDevices)}})})})(e).then(o=>{const s=document.createElement("div");s.style.position="fixed",s.style.bottom="-1px",s.style.width="1px",s.style.height="1px",s.style.opacity="0.01",document.body.appendChild(s);const i={width:"100%",height:"100%",insertMode:"append",showControls:!1,scalableVideo:!1};t&&t.audioSource&&(i.audioSource=t.audioSource),t&&t.videoSource&&(i.videoSource=t.videoSource),t&&t.audioOnly&&(i.videoSource=null),Object.keys(o.audio).length||(i.audioSource=null),Object.keys(o.video).length||(i.videoSource=null),t&&t.scalableVideo&&(i.scalableVideo=t.scalableVideo);const a=e.initPublisher(s,i,e=>{var t;e?(null===(t=s.parentNode)||void 0===t||t.removeChild(s),e&&("OT_USER_MEDIA_ACCESS_DENIED"===e.name||e.message&&(e.message.toLowerCase().includes("permission")||e.message.toLowerCase().includes("access denied")||e.message.toLowerCase().includes("not allowed")))?n(new p.PermissionDeniedError):n(new u.FailedToCreateLocalPublisher)):r({publisher:a})});a.on("streamCreated",()=>{s.style.visibility="hidden"})}).catch(n)})})(e,r).then(({publisher:e})=>{t.publish(e,r=>{r?(0,l.errorHasName)(r,l.OTErrorType.NOT_CONNECTED)?s(new u.PublishToSessionNotConnectedError):(0,l.errorHasName)(r,l.OTErrorType.UNABLE_TO_PUBLISH)?s(new u.PublishToSessionPermissionOrTimeoutError):r&&s(new u.PublishToSessionError):n(Object.assign({session:t},{publisher:e}))})}).catch(e=>{s(e)})})}(e,t,n)).then(S).then(t=>m(e,n,t)).then(e=>{const t={success:!0,failedTests:[]};return r.logEvent({action:"testConnectivity",variation:"Success"}),(n=e.session,s=e.subscriber,new Promise(e=>{s.on("destroyed",()=>{e()}),s||e(),n.unsubscribe(s)})).then(()=>h(e.publisher)).then(()=>E(e.session)).then(()=>o(t));var n,s}).catch(t=>{const o=(...e)=>{const t=(0,d.mapErrors)(...e),n=t.find(e=>"messaging"===e.type),o=[...t,...n?(0,d.mapErrors)(new u.FailedMessagingServerTestError):[]],i={failedTests:o,success:!1};r.logEvent({action:"testConnectivity",variation:"Failure",payload:{failedTests:o.map(e=>({type:e.type,error:e.error.name||"Unknown Error"})),errorNames:e.map(e=>e.name||"Unknown Error")}}),s(i)};"LoggingServerConnectionError"===t.name?o(t):m(e,n).then(()=>o(t)).catch(e=>o(t,e))})})};const c=a(r(425)),u=i(r(60)),l=r(635),d=r(338),f=r(237),p=r(394);function E(e){return new Promise(t=>{e.on("sessionDisconnected",()=>{e.off(),t()}),e.disconnect()})}function h(e){return new Promise(t=>{e.on("destroyed",()=>{t()}),e||t(),e.destroy()})}function S({session:e,publisher:t}){return new Promise((r,n)=>{const o={testNetwork:!0,audioVolume:0},s=r=>{h(t).then(()=>E(e)).then(()=>{n(r)})};if(t.stream){const n=document.createElement("div"),i=e.subscribe(t.stream,n,o,n=>{n?s(new u.SubscribeToSessionError):r(Object.assign(Object.assign({session:e},{publisher:t}),{subscriber:i}))})}else s(new u.SubscribeToSessionError)})}function m(e,t,r){return new Promise((n,o)=>{const s=`${(0,f.getOr)("","properties.loggingURL",e)}/logging/ClientEvent`,i=t&&t.proxyServerUrl&&`${t.proxyServerUrl}/${s.replace("https://","")}`||s,a=()=>o(new u.LoggingServerConnectionError);c.default.post(i).then(e=>200===e.status?n(r):a()).catch(a)})}},500(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MissingSubscriberError=t.SubscriberGetStatsError=t.SubscribeToSessionError=t.MediaAccessRevokedError=t.PublishToSessionPermissionOrTimeoutError=t.PublishToSessionNotConnectedError=t.InitPublisherError=t.PublishToSessionError=t.NoAudioCaptureDevicesError=t.NoVideoCaptureDevicesError=t.FailedToObtainMediaDevices=t.MediaDeviceError=t.ConnectToSessionNetworkError=t.ConnectToSessionSessionIdError=t.ConnectToSessionTokenError=t.ConnectToSessionError=t.UnsupportedBrowserError=t.QualityTestError=void 0;const n=r(394),o=r(635);class s extends n.NetworkTestError{constructor(e,t){super(e,t||o.ErrorNames.QUALITY_TEST_ERROR)}}t.QualityTestError=s;t.UnsupportedBrowserError=class extends s{constructor(e){super(`Your current browser (${e}) does not support the audio-video quality test. Please run the test in a supported browser.`,o.ErrorNames.UNSUPPORTED_BROWSER)}};class i extends s{constructor(e,t){super(e||"Failed to connect to the session due to a network error.",t||o.ErrorNames.CONNECT_TO_SESSION_ERROR)}}t.ConnectToSessionError=i;t.ConnectToSessionTokenError=class extends i{constructor(){super("Failed to connect to the session due to an invalid token.",o.ErrorNames.CONNECT_TO_SESSION_TOKEN_ERROR)}};t.ConnectToSessionSessionIdError=class extends i{constructor(){super("Failed to connect to the session due to an invalid session ID.",o.ErrorNames.CONNECT_TO_SESSION_ID_ERROR)}};t.ConnectToSessionNetworkError=class extends i{constructor(){super("Failed to connect to the session due to a network error.",o.ErrorNames.CONNECT_TO_SESSION_NETWORK_ERROR)}};t.MediaDeviceError=class extends s{constructor(e,t){super(e||"OpenTok failed to find media devices for this browser.",t||o.ErrorNames.MEDIA_DEVICE_ERROR)}};t.FailedToObtainMediaDevices=class extends s{constructor(){super("Failed to obtain media devices.",o.ErrorNames.FAILED_TO_OBTAIN_MEDIA_DEVICES)}};t.NoVideoCaptureDevicesError=class extends s{constructor(){super("This browser has no video capture devices",o.ErrorNames.NO_VIDEO_CAPTURE_DEVICES)}};t.NoAudioCaptureDevicesError=class extends s{constructor(){super("This browser has no audio capture devices.",o.ErrorNames.NO_AUDIO_CAPTURE_DEVICES)}};class a extends s{constructor(e,t){super(e||"Encountered an unknown error while attempting to publish to a session.",t||o.ErrorNames.PUBLISH_TO_SESSION_ERROR)}}t.PublishToSessionError=a;t.InitPublisherError=class extends a{constructor(e){super(e||"Failed to initialize publisher.",o.ErrorNames.INIT_PUBLISHER_ERROR)}};t.PublishToSessionNotConnectedError=class extends a{constructor(){super("Precall failed to publish to the session because it was not connected.",o.ErrorNames.PUBLISH_TO_SESSION_NOT_CONNECTED)}};t.PublishToSessionPermissionOrTimeoutError=class extends a{constructor(){super("Precall failed to publish to the session due a permissions error or timeout.",o.ErrorNames.PUBLISH_TO_SESSION_PERMISSION_OR_TIMEOUT_ERROR)}};t.MediaAccessRevokedError=class extends a{constructor(){super("Media access was revoked during the quality test.",o.ErrorNames.MEDIA_ACCESS_REVOKED_ERROR)}};class c extends s{constructor(e,t){super(e||"Encountered an unknown error while attempting to publish to a session.",t||o.ErrorNames.SUBSCRIBE_TO_SESSION_ERROR)}}t.SubscribeToSessionError=c;t.SubscriberGetStatsError=class extends c{constructor(){super("Failed to get network stats for a subscriber.",o.ErrorNames.SUBSCRIBER_GET_STATS_ERROR)}};t.MissingSubscriberError=class extends c{constructor(){super("Call checkSubscribeToSession before calling checkSubscriberQuality.",o.ErrorNames.MISSING_SUBSCRIBER_ERROR)}}},288(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class r{constructor(e){this.stats={audio:{},video:{}},this.bandwidth={audio:0,video:0},this.hasAudioTrack=()=>this.subscriberStatsLog[0]&&!!this.subscriberStatsLog[0].audio,this.hasVideoTrack=()=>this.subscriberStatsLog[0]&&!!this.subscriberStatsLog[0].video,this.getLastPublisherStats=()=>{var e;return null!==(e=this.publisherStatsLog[this.publisherStatsLog.length-1])&&void 0!==e?e:void 0},this.subscriberStatsLog=[],this.publisherStatsLog=[],this.audioScoresLog=[],this.videoScoresLog=[],this.audioOnlyFallback=!!e}audioScore(){return this.audioScoresLog.reduce((e,t)=>e+t,0)/this.audioScoresLog.length}videoScore(){return this.videoScoresLog.reduce((e,t)=>e+t,0)/this.videoScoresLog.length}clearInterval(){this.intervalId&&window.clearInterval(this.intervalId),this.intervalId=void 0}pruneAudioScores(){const e=this.audioScoresLog;for(;e.length>r.maxLogLength;)e.shift();this.audioScoresLog=e}pruneVideoScores(){const e=this.videoScoresLog;for(;e.length>r.maxLogLength;)e.shift();this.videoScoresLog=e}pruneScores(){this.pruneAudioScores(),this.pruneVideoScores()}audioQualityScore(){return this.hasAudioTrack()?this.audioScore():1}videoQualityScore(){return this.hasVideoTrack()?this.videoScore():1}}r.maxLogLength=1e3,r.scoreInterval=1e3,t.default=r},952(e,t){"use strict";function r(e,t){const r=[];for(let n=1;n<t.length;n+=1){const o=t[n],s=t[n-1];if(o[e]&&s[e]){const t=8*(o[e].bytesReceived?o[e].bytesReceived-s[e].bytesReceived:0)/((o.timestamp-s.timestamp)/1e3),n=o[e].packetsReceived,i=o[e].packetsLost,a=i+n;let c=0;a>0&&i>0&&(c=i/a);const u="video"===e?{frameRate:o[e].frameRate}:{};r.push(Object.assign({averageBitrate:t,packetLossRatio:c},u))}}return r}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){if(e.length<2)throw new Error("Cannot calculate bitrate with less than two data points.");return{audio:r("audio",e),video:r("video",e)}}},322(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=(0,o.default)(e.publisherStatsLog),r=(0,s.default)(e.subscriberStatsLog);return{audio:e.hasAudioTrack()?u("audio",r.audio,t):{supported:!1,reason:a.default.strings.noMic},video:e.audioOnlyFallback?{supported:!1,reason:a.default.strings.bandwidthLow}:e.hasVideoTrack()?u("video",r.video,t):{supported:!1,reason:a.default.strings.noCam}}};const o=n(r(593)),s=n(r(952)),i=n(r(614)),a=n(r(312)),c=r(237);function u(e,t,r){var n,o;let s=0,a=0,u=0;r.forEach(t=>{var r,n;a+=0,s+="video"===e?1e3*t.videoKbsSent:1e3*(null!==(n=null===(r=t.audioStats[0])||void 0===r?void 0:r.kbs)&&void 0!==n?n:0)}),t.forEach(t=>{a+=t.packetLossRatio,"video"===e&&(u+=Number((0,c.getOr)(0,"frameRate",t)))});const l=r.some(e=>e.simulcastEnabled),d=null!==(o=null===(n=r[r.length-1].videoStats.find(e=>null!=e.qualityLimitationReason&&"none"!==e.qualityLimitationReason))||void 0===n?void 0:n.qualityLimitationReason)&&void 0!==o?o:void 0,f={availableOutgoingBitrate:r[r.length-1].availableOutgoingBitrate,simulcast:l,bitrate:s/r.length,packetLossRatio:a/t.length};if("video"===e){const{supported:r,reason:n,recommendedResolution:o,recommendedFrameRate:s}=(0,i.default)(f),a="video"===e?{recommendedResolution:o,recommendedFrameRate:s,frameRate:u/t.length}:{};return Object.assign(Object.assign(Object.assign({},f),{supported:r,reason:n,qualityLimitationReason:d}),a)}return Object.assign({},f)}},312(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={getStatsInterval:1e3,getStatsVideoAndAudioTestDuration:3e4,getStatsAudioOnlyDuration:1e4,subscribeOptions:{testNetwork:!0,audioVolume:0},minimumVideoAndAudioTestSampleSize:5,steadyStateSampleWindow:5e3,steadyStateAllowedDelta:.05,thresholdRatio:.75,qualityThresholds:{video:[{targetBitrate:4e6,targetBitrateSimulcast:555e4,recommendedSetting:"1920x1080 @ 30FPS"},{targetBitrate:25e5,targetBitrateSimulcast:315e4,recommendedSetting:"1280x720 @ 30FPS"},{targetBitrate:12e5,targetBitrateSimulcast:155e4,recommendedSetting:"960x540 @ 30FPS"},{targetBitrate:5e5,targetBitrateSimulcast:65e4,recommendedSetting:"640x360 @ 30FPS"},{targetBitrate:3e5,targetBitrateSimulcast:35e4,recommendedSetting:"480x270 @ 30FPS"},{targetBitrate:15e4,targetBitrateSimulcast:15e4,recommendedSetting:"320x180 @ 30FPS"}],audio:[{minMos:2.4}]},strings:{bandwidthLow:"Bandwidth too low.",noCam:"No camera was found.",noMic:"No microphone was found."}}},593(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=(0,s.getOr)(0,"timestamp",(0,s.last)(e))-o.default.steadyStateSampleWindow;return e.filter(e=>e.timestamp>=t)};const o=n(r(312)),s=r(237)},26(e,t){"use strict";var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:!0}),t.getPublisherStats=function(e,t){return r(this,void 0,void 0,function*(){var r;if("function"==typeof e.getRtcStatsReport)try{const n=yield e.getRtcStatsReport();return null!==(r=s(n,t))&&void 0!==r?r:void 0}catch(e){return}})};const n=(e,t)=>{const r=null==t?void 0:t.audioStats[0];if(!r)return 0;const{currentTimestamp:n,byteSent:o}=r;if(null==e.bytesSent)return 0;const s=e.bytesSent-o,i=(e.timestamp-n)/1e3;return Math.round(8*s/(1e3*i))},o=(e,t)=>{const r=null==t?void 0:t.videoStats.find(t=>t.ssrc===e.ssrc);if(!r)return 0;const{currentTimestamp:n,byteSent:o}=r;if(null==e.bytesSent)return 0;const s=e.bytesSent-o,i=(e.timestamp-n)/1e3;return Math.round(8*s/(1e3*i))},s=(e,t)=>{if(!e)return;const{rtcStatsReport:r}=e[0],s=Array.from(r.values()),i=s.filter(e=>"outbound-rtp"===e.type),a=s.find(e=>"candidate-pair"===e.type&&e.nominated),c=(e,t)=>s.find(r=>r.type===e&&r.id===t),u=(null==a?void 0:a.localCandidateId)?c("local-candidate",a.localCandidateId):null,l=(null==a?void 0:a.remoteCandidateId)?c("remote-candidate",a.remoteCandidateId):null,{videoStats:d,audioStats:f}=((e,t)=>{var r,s;const i=[],a=[];for(const c of e)if("video"===c.kind||"video"===c.mediaType){const e=o(c,t),{ssrc:n,timestamp:s}=c,a={kbs:e,ssrc:n,byteSent:null!==(r=c.bytesSent)&&void 0!==r?r:0,currentTimestamp:s};i.push(Object.assign(Object.assign({},a),{qualityLimitationReason:c.qualityLimitationReason,resolution:`${c.frameWidth||0}x${c.frameHeight||0}`,framerate:c.framesPerSecond||0,active:c.active||!1,pliCount:c.pliCount||0,nackCount:c.nackCount||0}))}else if("audio"===c.kind||"audio"===c.mediaType){const e=n(c,t),{ssrc:r,timestamp:o}=c,i={kbs:e,ssrc:r,byteSent:null!==(s=c.bytesSent)&&void 0!==s?s:0,currentTimestamp:o};a.push(i)}return{videoStats:i,audioStats:a}})(i,t),p=((e,t)=>{if(!e||!t)return"Unknown";const r=e.candidateType,n=t.candidateType,o=(e.protocol||"").toLowerCase();if("host"===r&&"host"===n)return"Routed";if(("prflx"===r||"host"===r)&&"host"===n)return"Routed";const s="tcp"===o;return"relay"===r||"relay"===n?s?"Relayed (TURN/TLS)":"Relayed (TURN/UDP)":"srflx"===r||"srflx"===n||"prflx"===r||"prflx"===n?s?"Relayed (STUN/TLS)":"Relayed (STUN/UDP)":"Unknown"})(u,l),E=(null==a?void 0:a.availableOutgoingBitrate)||-1,h=(null==a?void 0:a.currentRoundTripTime)||-1,S=d.reduce((e,t)=>e+t.kbs,0),m=d.reduce((e,t)=>e+t.byteSent,0);return{videoStats:d,audioStats:f,availableOutgoingBitrate:E,videoByteSent:m,videoKbsSent:S,simulcastEnabled:d.length>1,transportProtocol:(null==u?void 0:u.protocol)||"N/A",currentRoundTripTime:h,timestamp:(null==u?void 0:u.timestamp)||0,mediaRouting:p}}},107(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=(e,t,r)=>{var n,o,s;const{audio:i,video:a}=e,c={bytesSent:t.audioStats[0].byteSent,bytesReceived:(null==i?void 0:i.bytesReceived)||0,packetsLost:(null==i?void 0:i.packetsLost)||0,packetsReceived:(null==i?void 0:i.packetsReceived)||0};let u=null;return"audio-video"===r&&(u={bytesSent:t.videoByteSent,bytesReceived:(null==a?void 0:a.bytesReceived)||0,packetsLost:(null==a?void 0:a.packetsLost)||0,packetsReceived:(null==a?void 0:a.packetsReceived)||0,frameRate:(null==a?void 0:a.frameRate)||0,mediaRouting:t.mediaRouting}),{phase:r,audio:c,video:u,timestamp:e.timestamp,networkCondition:null===(o=null===(n=e.mediaLink)||void 0===n?void 0:n.transport)||void 0===o?void 0:o.networkCondition,networkDegradationSource:null===(s=e.mediaLink)||void 0===s?void 0:s.networkDegradationSource}}},614(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=o.default.qualityThresholds.video,r=o.default.thresholdRatio,n=e.availableOutgoingBitrate;let i,a=!1,c=30,u="";for(let o=0;o<t.length;o+=1){const l=t[o];if(n>=(e.simulcast?l.targetBitrateSimulcast:l.targetBitrate)*r){a=!0,i=(0,s.get)("recommendedSetting",l),c=Number(i.substring(i.indexOf("@")+1).replace("FPS","")),u=i.substring(0,i.indexOf("@")-1);break}}const l={supported:a,recommendedFrameRate:c,recommendedResolution:u};a?(l.recommendedFrameRate=c,l.recommendedResolution=u):l.reason=o.default.strings.bandwidthLow;return l};const o=n(r(312)),s=r(237)},146(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=(0,o.default)(e);let r=!0;if(t.length<s.default.minimumVideoAndAudioTestSampleSize)return!1;for(const[e,n]of t.entries()){if(0===e)continue;const o=t[e-1];if(n.videoKbsSent>0){const e=n.videoKbsSent,t=o.videoKbsSent;e-t>t*s.default.steadyStateAllowedDelta&&(r=!1)}const i=n.audioStats[0].kbs,a=o.audioStats[0].kbs;i-a>a*s.default.steadyStateAllowedDelta&&(r=!1)}return r};const o=n(r(593)),s=n(r(312))},840(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){const e=function(){const e=window&&window.navigator;if("undefined"==typeof window||!window.navigator)return"not a browser";if((0,n.get)("mozGetUserMedia",e))return"Firefox";if((0,n.get)("webkitGetUserMedia",e))return window.hasOwnProperty("webkitRTCPeerConnection")?e.userAgent.match(/Edg/)?"Edge":e.userAgent.match(/Opera|OPR\//)?"Opera":"Chrome":e.userAgent.match(/Version\/(\d+).(\d+)/)?"Safari":"WebKit browser without WebRTC support";if(e.mediaDevices&&e.userAgent.match(/Edge\/(\d+).(\d+)$/))return"non-Chromium Edge";if(e.userAgent.indexOf("MSIE ")>0||e.userAgent.match(/Trident.*rv:11\./))return"Internet Explorer";if(e.mediaDevices&&e.userAgent.match(/AppleWebKit\/(\d+)\./))return"Safari";return"unsupported browser"}(),t=["Chrome","Safari","Edge","Opera"].indexOf(e)>-1;return{browser:e,supported:t}};const n=r(237)},555(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}c((n=n.apply(e,t||[])).next())})},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r,o,f){return e.intervalId=window.setInterval(()=>{t.getStats((a,p)=>n(this,void 0,void 0,function*(){var n,E;if(!p)return null;if((null!==(E=null===(n=p.audio)||void 0===n?void 0:n.bytesReceived)&&void 0!==E?E:0)<0||Number((0,c.getOr)(1,"video.bytesReceived",p))<0)return e.clearInterval(),f(e);const h=yield(0,u.getPublisherStats)(r,e.getLastPublisherStats());if(p&&e.subscriberStatsLog.push(p),h&&e.publisherStatsLog.push(h),o&&"function"==typeof o&&o(a,p,h),e.publisherStatsLog.length&&e.publisherStatsLog.length>=2){e.stats=(0,i.default)(e);const r=function(e,t){const r=3e4,n=e=>{const t=2.069924867*Math.pow(Math.log10(e),.6250223771);return Math.pow(10,t)},o=(0,c.last)(t),s=(0,c.nth)(-2,t);if(!o||!s||!e.stream)return 1;const i=((e,t,r)=>{const n=t.timestamp-r.timestamp;return t[e]&&t[e].bytesReceived?8*(t[e].bytesReceived-r[e].bytesReceived)/(n/1e3):0})("video",o,s),a=e.stream.videoDimensions.width*e.stream.videoDimensions.height,u=n(a);if(i<r)return 1;const l=Math.min(i,u);let d=Math.log(l/r)/Math.log(u/r)*4+1;return d=Math.min(d,4.5),d}(t,e.subscriberStatsLog);e.videoScoresLog.push(r);const n=function(e,t,r){const n=()=>150,o=e=>{const t=30,r=e=>e<0?0:1,o=0,s=19.8,i=29.7,a=n();return(e=>e<0?1:e>100?4.5:1+.035*e+e*(e-60)*(100-e)*7e-6)((()=>{const n=a+t;return 93.2-(.024*n+.11*(n-177.3)*r(n-177.3))-(o+s*Math.log(1+i*e))})())},s=(0,c.last)(r),i=(0,c.nth)(-2,r);if(!s||!i||!e.stream)return 1;const a=(u="audio",f=s,p=i,d(f[u])-d(p[u]));var u,f,p;if(0===a)return 1;let E=(l(s.audio)-l(i.audio))/a;E<0&&(E=0);return o(E)}(t,0,e.subscriberStatsLog);if(e.audioScoresLog.push(n),e.pruneScores(),(0,s.default)(e.publisherStatsLog))return e.clearInterval(),f(e)}return null}))},a.default.scoreInterval),t.on("destroyed",e.clearInterval.bind(e)),r.on("destroyed",e.clearInterval.bind(e)),e};const s=o(r(146)),i=o(r(322)),a=o(r(288)),c=r(237),u=r(26),l=e=>(0,c.getOr)(0,"packetsLost",e),d=e=>l(e)+(e=>(0,c.getOr)(0,"packetsReceived",e))(e)},998(e,t,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),i=0;i<r.length;i++)"default"!==r[i]&&o(t,e,r[i]);return s(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.testQuality=function(e,t,r,n,o){return _=!1,R=!1,new Promise((s,i)=>{g=!(!n||!n.audioOnly),m=g?p.default.getStatsAudioOnlyDuration:p.default.getStatsVideoAndAudioTestDuration,n&&n.timeout&&(m=Math.min(m,n.timeout,3e4));const a=e=>{O=void 0,r.logEvent({action:"testQuality",variation:"Success"}),s(e)},c=e=>{O=void 0,r.logEvent({action:"testQuality",variation:"Failure",payload:{errorName:e.name,errorMessage:e.message}}),i(e)};new Promise((e,t)=>{const{supported:r,browser:n}=(0,E.default)();return r?e():t(new u.UnsupportedBrowserError(n))}).then(()=>{let r={};n&&n.initSessionOptions&&(r=n.initSessionOptions),n&&n.proxyServerUrl&&(e.hasOwnProperty("setProxyUrl")||(r.proxyUrl=n.proxyServerUrl));const s=e.initSession(t.apiKey,t.sessionId,r);N(e,s,t,n,o).then(a).catch(c)}).catch(c)})},t.stopQualityTest=function(){R=!0,_&&O&&O()};const c=r(237),u=i(r(500)),l=r(635),d=a(r(555)),f=a(r(288)),p=a(r(312)),E=a(r(840)),h=a(r(107)),S=r(394);let m,O,b,g=!1,_=!1,R=!1;function T(e,t){return new Promise((r,n)=>{e.getDevices((e,o=[])=>{if(e)return void n(new u.FailedToObtainMediaDevices);const s=o.reduce((e,t)=>{const r="audioInput"===t.kind?"audio":"video";return Object.assign(Object.assign({},e),{[r]:Object.assign(Object.assign({},e[r]),{[t.deviceId]:t})})},{audio:{},video:{}});var i,a;Object.keys(s.audio).length?(null==t?void 0:t.fullHd)?(i=1920,a=1080,new Promise((e,t)=>{navigator.mediaDevices.getUserMedia({video:{width:{exact:i},height:{exact:a}},audio:!1}).then(t=>{t&&e()}).catch(e=>{switch(e.name){case"OverconstrainedError":t(new S.UnsupportedResolutionError);break;case"NotAllowedError":t(new S.PermissionDeniedError);break;default:t(e)}})})).then(()=>r(s)).catch(n):r(s):n(new u.NoAudioCaptureDevicesError)})})}function y(e,t,r,n){return new Promise((o,s)=>{(function(e,t){return new Promise((r,n)=>{e.connection?r(e):e.connect(t,t=>{t&&((0,l.errorHasName)(t,l.OTErrorType.OT_AUTHENTICATION_ERROR)?n(new u.ConnectToSessionTokenError):(0,l.errorHasName)(t,l.OTErrorType.OT_INVALID_SESSION_ID)?n(new u.ConnectToSessionSessionIdError):(0,l.errorHasName)(t,l.OTErrorType.OT_CONNECT_FAILED)?n(new u.ConnectToSessionNetworkError):n(new u.ConnectToSessionError)),r(e)})})})(t,r.token).then(function(e,t){return r=>new Promise((n,o)=>{const s=e=>{v(r).then(()=>{o(e)})},i=document.createElement("div");i.style.position="fixed",i.style.bottom="-1px",i.style.width="1px",i.style.height="1px",i.style.opacity="0",document.body.appendChild(i),T(e,t).then(o=>{Object.keys(o.video).length||(g=!0);const a={resolution:(null==t?void 0:t.fullHd)?"1920x1080":"1280x720",scalableVideo:null==t?void 0:t.scalableVideo,width:"100%",height:"100%",insertMode:"append",showControls:!1};t&&t.audioSource&&(a.audioSource=t.audioSource),t&&t.videoSource&&(a.videoSource=t.videoSource),g&&(a.videoSource=null);const c=e.initPublisher(i,a,e=>{e?"OT_USER_MEDIA_ACCESS_DENIED"===e.name?s(new S.PermissionDeniedError):s(new u.InitPublisherError(e.message)):r.publish(c,e=>{if(e)return(0,l.errorHasName)(e,l.OTErrorType.NOT_CONNECTED)?s(new u.PublishToSessionNotConnectedError):(0,l.errorHasName)(e,l.OTErrorType.UNABLE_TO_PUBLISH)?s(new u.PublishToSessionPermissionOrTimeoutError):s(new u.PublishToSessionError)})});c.on("accessDenied",()=>{s(new S.PermissionDeniedError)}),c.on("mediaStopped",()=>{s(new u.MediaAccessRevokedError)}),c.on("streamCreated",e=>{const t=r.subscribe(e.stream,i,{testNetwork:!0,insertMode:"append",subscribeToAudio:!0,subscribeToVideo:!0},e=>e?s(new u.SubscribeToSessionError(e.message)):n({publisher:c,subscriber:t}))})}).catch(o)})}(e,n)).then(o).catch(s)})}function v(e){return new Promise(t=>{e.on("sessionDisconnected",()=>{e.off(),t()}),e.disconnect()})}function N(e,t,r,n,o,s){let i;return new Promise((a,l)=>{const E=e=>{v(t).then(()=>{l(e)})};y(e,t,r,n).then(({publisher:S,subscriber:T})=>{if(T)try{const l=Object.assign(Object.assign({state:new f.default(s)},{subscriber:T}),{credentials:r}),y=(e,t,r)=>{if(t&&r&&o){const e=(0,h.default)(t,r,g?"audio-only":"audio-video");o(e)}};S.on("streamDestroyed",e=>{"mediaStopped"===e.reason&&(clearTimeout(i),E(new u.MediaAccessRevokedError))});const v=()=>{const s=function(e){var t,r,n;const o=["bitrate","packetLossRatio","supported","reason","mos"];e.state.stats.audio.mos=e.state.audioQualityScore(),e.state.stats.video.mos=e.state.videoQualityScore(),e.state.stats.audio.mos>=p.default.qualityThresholds.audio[0].minMos?e.state.stats.audio.supported=!0:(e.state.stats.audio.supported=!1,e.state.stats.audio.reason=p.default.strings.bandwidthLow);const s=e.state.getLastPublisherStats();s&&s.mediaRouting&&(e.state.stats.video.mediaRouting=s.mediaRouting);const i=e.state.subscriberStatsLog[e.state.subscriberStatsLog.length-1],a=null===(r=null===(t=null==i?void 0:i.mediaLink)||void 0===t?void 0:t.transport)||void 0===r?void 0:r.networkCondition,u=null===(n=null==i?void 0:i.mediaLink)||void 0===n?void 0:n.networkDegradationSource;return Object.assign(Object.assign({audio:(0,c.pick)(o,e.state.stats.audio),video:(0,c.pick)(o.concat(["frameRate","qualityLimitationReason","recommendedResolution","recommendedFrameRate","mediaRouting"]),e.state.stats.video)},void 0!==a&&{networkCondition:a}),void 0!==u&&{networkDegradationSource:u})}(l);if(g||(i=s).audio.mos&&i.audio.mos>=p.default.qualityThresholds.audio[0].minMos||R)t.on("sessionDisconnected",()=>{a(s),t.off()}),function(e,t){return new Promise(r=>{t.on("destroyed",()=>{r()}),t||r(),e.unsubscribe(t)})}(t,T).then(()=>function(e,t){return new Promise(r=>{t.on("destroyed",()=>{r()}),t||r(),e.unpublish(t)})}(t,S)).then(()=>t.disconnect());else{g=!0;const i=s.video;N(e,t,r,n,o,!0).then(e=>{e.video=i,a(e)})}var i};O=()=>{clearTimeout(i),v()};const w=()=>{clearTimeout(i),v()};(0,d.default)(l.state,T,S,y,w),i=window.setTimeout(v,m),window.clearTimeout(b),b=window.setTimeout(()=>{_=!0,R&&O&&O()},5e3)}catch(e){E(new u.SubscriberGetStatsError)}else l(new u.MissingSubscriberError)}).catch(l)})}},237(e,t){"use strict";t.nth=t.last=t.pick=t.getOr=t.get=t.Jr=t.Uf=void 0;t.Uf=(e,t,r)=>Object.assign(Object.assign({},r),{[e]:t});t.Jr=(e,r,n)=>{const o=e.split("."),s=o[0];if(!o.length)return n;if(1===o.length)return(0,t.Uf)(s,r,n);const i=(0,t.get)(s,n),a=i&&"object"==typeof i?i:i?Object.assign(Object.assign({},n),{[s]:{}}):n,c=(0,t.Uf)(s,(0,t.Jr)(o.slice(1).join("."),r,(0,t.get)(s,a)),n);return Object.assign(Object.assign({},n),c)};t.get=(e,r)=>{if(!r)return r;const[n,...o]=e.split("."),s=r[n];return null==s?s:o.length?(0,t.get)(o.join("."),s):s};t.getOr=(e,r,n)=>(0,t.get)(r,n)||e;t.pick=(e,t,r=!1)=>e.reduce((e,n)=>void 0!==t[n]||r?Object.assign(Object.assign({},e),{[n]:t[n]}):e,{});t.last=e=>e[e.length-1];t.nth=(e,t)=>e<0?t[t.length+e]:t[e]},425(e,t,r){"use strict";function n(e,t){return function(){return e.apply(t,arguments)}}const{toString:o}=Object.prototype,{getPrototypeOf:s}=Object,{iterator:i,toStringTag:a}=Symbol,c=(({hasOwnProperty:e})=>(t,r)=>e.call(t,r))(Object.prototype),u=(e,t)=>{let r=e;const n=[];for(;null!=r&&r!==Object.prototype;){if(-1!==n.indexOf(r))return!1;if(n.push(r),c(r,t))return!0;r=s(r)}return!1},l=(d=Object.create(null),e=>{const t=o.call(e);return d[t]||(d[t]=t.slice(8,-1).toLowerCase())});var d;const f=e=>(e=e.toLowerCase(),t=>l(t)===e),p=e=>t=>typeof t===e,{isArray:E}=Array,h=p("undefined");function S(e){return null!==e&&!h(e)&&null!==e.constructor&&!h(e.constructor)&&b(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const m=f("ArrayBuffer");const O=p("string"),b=p("function"),g=p("number"),_=e=>null!==e&&"object"==typeof e,R=e=>{if(!_(e))return!1;const t=s(e);return!(null!==t&&t!==Object.prototype&&null!==s(t)||u(e,a)||u(e,i))},T=f("Date"),y=f("File"),v=f("Blob"),N=f("FileList");const w="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r.g?r.g:{},C=void 0!==w.FormData?w.FormData:void 0,I=f("URLSearchParams"),[P,A,D,L]=["ReadableStream","Request","Response","Headers"].map(f);function U(e,t,{allOwnKeys:r=!1}={}){if(null==e)return;let n,o;if("object"!=typeof e&&(e=[e]),E(e))for(n=0,o=e.length;n<o;n++)t.call(null,e[n],n,e);else{if(S(e))return;const o=r?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(n=0;n<s;n++)i=o[n],t.call(null,e[i],i,e)}}function x(e,t){if(S(e))return null;t=t.toLowerCase();const r=Object.keys(e);let n,o=r.length;for(;o-- >0;)if(n=r[o],t===n.toLowerCase())return n;return null}const k="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:r.g,j=e=>!h(e)&&e!==k;const M=(B="undefined"!=typeof Uint8Array&&s(Uint8Array),e=>B&&e instanceof B);var B;const F=f("HTMLFormElement"),{propertyIsEnumerable:V}=Object.prototype,H=f("RegExp"),q=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};U(r,(r,o)=>{let s;!1!==(s=t(r,o,e))&&(n[o]=s||r)}),Object.defineProperties(e,n)};const K=f("AsyncFunction"),W=(z="function"==typeof setImmediate,G=b(k.postMessage),z?setImmediate:G?(J=`axios@${Math.random()}`,Q=[],k.addEventListener("message",({source:e,data:t})=>{e===k&&t===J&&Q.length&&Q.shift()()},!1),e=>{Q.push(e),k.postMessage(J,"*")}):e=>setTimeout(e));var z,G,J,Q;const $="undefined"!=typeof queueMicrotask?queueMicrotask.bind(k):"undefined"!=typeof process&&process.nextTick||W,X=e=>null!=e&&b(e[i]);var Y={isArray:E,isArrayBuffer:m,isBuffer:S,isFormData:e=>{if(!e)return!1;if(C&&e instanceof C)return!0;const t=s(e);if(!t||t===Object.prototype)return!1;if(!b(e.append))return!1;const r=l(e);return"formdata"===r||"object"===r&&b(e.toString)&&"[object FormData]"===e.toString()},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&m(e.buffer),t},isString:O,isNumber:g,isBoolean:e=>!0===e||!1===e,isObject:_,isPlainObject:R,isEmptyObject:e=>{if(!_(e)||S(e))return!1;try{return 0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype}catch(e){return!1}},isReadableStream:P,isRequest:A,isResponse:D,isHeaders:L,isUndefined:h,isDate:T,isFile:y,isReactNativeBlob:e=>!(!e||void 0===e.uri),isReactNative:e=>e&&void 0!==e.getParts,isBlob:v,isRegExp:H,isFunction:b,isStream:e=>_(e)&&b(e.pipe),isURLSearchParams:I,isTypedArray:M,isFileList:N,forEach:U,merge:function e(...t){const{caseless:r,skipUndefined:n}=j(this)&&this||{},o={},s=(t,s)=>{if("__proto__"===s||"constructor"===s||"prototype"===s)return;const i=r&&"string"==typeof s&&x(o,s)||s,a=c(o,i)?o[i]:void 0;R(a)&&R(t)?o[i]=e(a,t):R(t)?o[i]=e({},t):E(t)?o[i]=t.slice():n&&h(t)||(o[i]=t)};for(let e=0,r=t.length;e<r