@phenixrts/sdk 2023.2.2-beta.69 → 2023.2.4-beta.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/channels/debug/channels.js +74 -18
- package/channels/debug/package.json +1 -1
- package/channels/debug.private/channels.js +74 -18
- package/channels/debug.private/package.json +1 -1
- package/channels/es5.debug.private/channels.js +71 -18
- package/channels/es5.debug.private/package.json +1 -1
- package/channels/min/channels.js +1 -1
- package/channels/min/channels.js.map +1 -1
- package/channels/min/package.json +1 -1
- package/channels/min.private/channels.js +1 -1
- package/channels/min.private/channels.js.map +1 -1
- package/channels/min.private/package.json +1 -1
- package/channels/package.json +1 -1
- package/full/debug/full.js +74 -18
- package/full/debug/package.json +1 -1
- package/full/debug.private/full.js +74 -18
- package/full/debug.private/package.json +1 -1
- package/full/min/full.js +1 -1
- package/full/min/full.js.map +1 -1
- package/full/min/package.json +1 -1
- package/full/min.private/full.js +1 -1
- package/full/min.private/full.js.map +1 -1
- package/full/min.private/package.json +1 -1
- package/full/package.json +1 -1
- package/package.json +1 -1
- package/publish/debug/package.json +1 -1
- package/publish/debug/publish.js +68 -8
- package/publish/debug.private/package.json +1 -1
- package/publish/debug.private/publish.js +68 -8
- package/publish/min/package.json +1 -1
- package/publish/min/publish.js +1 -1
- package/publish/min/publish.js.map +1 -1
- package/publish/min.private/package.json +1 -1
- package/publish/min.private/publish.js +1 -1
- package/publish/min.private/publish.js.map +1 -1
- package/publish/package.json +1 -1
- package/types/environment/Parameters.d.ts +9 -0
- package/types/sdk/channels/Channel.d.ts +3 -1
- package/types/sdk/channels/Channels.d.ts +3 -1
- package/types/sdk/context/ChannelContext.d.ts +6 -2
- package/types/sdk/streaming/InsertableStreams.d.ts +3 -1
package/full/min.private/full.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see full.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.phenix=t():e.phenix=t()}(self,(function(){return(()=>{var e={228:e=>{e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i},e.exports.__esModule=!0,e.exports.default=e.exports},858:e=>{e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},646:(e,t,n)=>{var i=n(228);e.exports=function(e){if(Array.isArray(e))return i(e)},e.exports.__esModule=!0,e.exports.default=e.exports},506:e=>{e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.__esModule=!0,e.exports.default=e.exports},926:(e,t,n)=>{var i=n(202).default;function r(e,t,n,r,o,a,s){try{var u=e[a](s),c=u.value}catch(e){return void n(e)}u.done?t(c):i.resolve(c).then(r,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new i((function(i,o){var a=e.apply(t,n);function s(e){r(a,i,o,s,u,"next",e)}function u(e){r(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},575:e=>{e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},913:(e,t,n)=>{var i=n(696);function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,i(r.key),r)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},713:(e,t,n)=>{var i=n(696);e.exports=function(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.__esModule=!0,e.exports.default=e.exports},754:e=>{function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},205:(e,t,n)=>{var i=n(489);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)},e.exports.__esModule=!0,e.exports.default=e.exports},860:e=>{e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.__esModule=!0,e.exports.default=e.exports},884:e=>{e.exports=function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,o,a,s=[],u=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(i=o.call(n)).done)&&(s.push(i.value),s.length!==t);u=!0);}catch(e){c=!0,r=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw r}}return s}},e.exports.__esModule=!0,e.exports.default=e.exports},521:e=>{e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},206:e=>{e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},585:(e,t,n)=>{var i=n(8).default,r=n(506);e.exports=function(e,t){if(t&&("object"===i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return r(e)},e.exports.__esModule=!0,e.exports.default=e.exports},591:(e,t,n)=>{var i=n(202).default,r=n(8).default;function o(){"use strict";e.exports=o=function(){return t},e.exports.__esModule=!0,e.exports.default=e.exports;var t={},n=Object.prototype,a=n.hasOwnProperty,s=Object.defineProperty||function(e,t,n){e[t]=n.value},u="function"==typeof Symbol?Symbol:{},c=u.iterator||"@@iterator",l=u.asyncIterator||"@@asyncIterator",d=u.toStringTag||"@@toStringTag";function h(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(e){h=function(e,t,n){return e[t]=n}}function p(e,t,n,i){var r=t&&t.prototype instanceof m?t:m,o=Object.create(r.prototype),a=new P(i||[]);return s(o,"_invoke",{value:S(e,n,a)}),o}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=p;var v={};function m(){}function g(){}function _(){}var y={};h(y,c,(function(){return this}));var C=Object.getPrototypeOf,b=C&&C(C(E([])));b&&b!==n&&a.call(b,c)&&(y=b);var k=_.prototype=m.prototype=Object.create(y);function x(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function n(i,o,s,u){var c=f(e[i],e,o);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==r(d)&&a.call(d,"__await")?t.resolve(d.__await).then((function(e){n("next",e,s,u)}),(function(e){n("throw",e,s,u)})):t.resolve(d).then((function(e){l.value=e,s(l)}),(function(e){return n("throw",e,s,u)}))}u(c.arg)}var i;s(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}})}function S(e,t,n){var i="suspendedStart";return function(r,o){if("executing"===i)throw new Error("Generator is already running");if("completed"===i){if("throw"===r)throw o;return{value:void 0,done:!0}}for(n.method=r,n.arg=o;;){var a=n.delegate;if(a){var s=T(a,n);if(s){if(s===v)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===i)throw i="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i="executing";var u=f(e,t,n);if("normal"===u.type){if(i=n.done?"completed":"suspendedYield",u.arg===v)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(i="completed",n.method="throw",n.arg=u.arg)}}}function T(e,t){var n=t.method,i=e.iterator[n];if(void 0===i)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var r=f(i,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,v;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,v):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function P(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function E(e){if(e){var t=e[c];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(a.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return g.prototype=_,s(k,"constructor",{value:_,configurable:!0}),s(_,"constructor",{value:g,configurable:!0}),g.displayName=h(_,d,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,_):(e.__proto__=_,h(e,d,"GeneratorFunction")),e.prototype=Object.create(k),e},t.awrap=function(e){return{__await:e}},x(w.prototype),h(w.prototype,l,(function(){return this})),t.AsyncIterator=w,t.async=function(e,n,r,o,a){void 0===a&&(a=i);var s=new w(p(e,n,r,o),a);return t.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},x(k),h(k,d,"Generator"),h(k,c,(function(){return this})),h(k,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var i in t)n.push(i);return n.reverse(),function e(){for(;n.length;){var i=n.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},t.values=E,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&a.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,i){return o.type="throw",o.arg=e,t.next=n,i&&(t.method="next",t.arg=void 0),!!i}for(var i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i],o=r.completion;if("root"===r.tryLoc)return n("end");if(r.tryLoc<=this.prev){var s=a.call(r,"catchLoc"),u=a.call(r,"finallyLoc");if(s&&u){if(this.prev<r.catchLoc)return n(r.catchLoc,!0);if(this.prev<r.finallyLoc)return n(r.finallyLoc)}else if(s){if(this.prev<r.catchLoc)return n(r.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<r.finallyLoc)return n(r.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&a.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===e||"continue"===e)&&r.tryLoc<=t&&t<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=e,o.arg=t,r?(this.method="next",this.next=r.finallyLoc,v):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),R(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var i=n.completion;if("throw"===i.type){var r=i.arg;R(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),v}},t}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},489:e=>{function t(n,i){return e.exports=t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n,i)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},38:(e,t,n)=>{var i=n(858),r=n(884),o=n(379),a=n(521);e.exports=function(e,t){return i(e)||r(e,t)||o(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},319:(e,t,n)=>{var i=n(646),r=n(860),o=n(379),a=n(206);e.exports=function(e){return i(e)||r(e)||o(e)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},868:(e,t,n)=>{var i=n(8).default;e.exports=function(e,t){if("object"!==i(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},696:(e,t,n)=>{var i=n(8).default,r=n(868);e.exports=function(e){var t=r(e,"string");return"symbol"===i(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},8:e=>{function t(n){return e.exports=t="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.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},379:(e,t,n)=>{var i=n(228);e.exports=function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},757:(e,t,n)=>{var i=n(591)();e.exports=i;try{regeneratorRuntime=i}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}},202:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>p});var i=n(8),r=n.n(i),o=n(575),a=n.n(o),s=n(913),u=n.n(s),c=n(713),l=n.n(c),d=u()((function e(t,n,i){a()(this,e),l()(this,"onFulfilled",void 0),l()(this,"onRejected",void 0),l()(this,"promise",void 0),this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof n?n:null,this.promise=i})),h=function(){function e(t){if(a()(this,e),l()(this,"_state",void 0),l()(this,"_handled",void 0),l()(this,"_value",void 0),l()(this,"_deferreds",void 0),!(this instanceof e))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],this.doResolve(t)}return u()(e,[{key:"doResolve",value:function(e){var t=this,n=!1;try{e((function(e){n||(n=!0,t.promiseResolve(e))}),(function(e){n||(n=!0,t.promiseReject(e))}))}catch(e){if(n)return;n=!0,this.promiseReject(e)}}},{key:"promiseResolve",value:function(t){var n=this;try{if(t===n)throw new TypeError("A Promise cannot be resolved with it self.");if(t&&("object"===r()(t)||"function"==typeof t)){var i=t.then;if(t instanceof e)return n._state=3,n._value=t,void n.finale();if("function"==typeof i)return void n.doResolve((function(){i.apply(t,arguments)}))}n._state=1,n._value=t,n.finale()}catch(e){n.promiseReject(e)}}},{key:"promiseReject",value:function(e){this._state=2,this._value=e,this.finale()}},{key:"finale",value:function(){var t=this;2===this._state&&0===this._deferreds.length&&e._immediate((function(){t._handled||e._unhandledRejection(t._value)}));for(var n=0,i=this._deferreds.length;n<i;n++)this.handle(this._deferreds[n]);this._deferreds=null}},{key:"handle",value:function(t){for(var n=this;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,e._immediate((function(){var e=1===n._state?t.onFulfilled:t.onRejected;if(null!==e){var i;try{i=e(n._value)}catch(e){return void t.promise.promiseReject(e)}t.promise.promiseResolve(i)}else 1===n._state?t.promise.promiseResolve(n._value):t.promise.promiseReject(n._value)}))):n._deferreds.push(t)}}],[{key:"all",value:function(t){return new e((function(e,n){if(!Array.isArray(t))return n(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(t);if(0===i.length)return e([]);for(var o=i.length,a=function t(a,s){try{if(s&&("object"===r()(s)||"function"==typeof s)){var u=s.then;if("function"==typeof u)return void u.call(s,(function(e){return t(a,e)}),n)}i[a]=s,0==--o&&e(i)}catch(e){n(e)}},s=0;s<i.length;s++)a(s,i[s])}))}},{key:"resolve",value:function(t){return t&&"object"===r()(t)&&t.constructor===e?t:new e((function(e){return e(t)}))}},{key:"reject",value:function(t){return new e((function(e,n){return n(t)}))}},{key:"race",value:function(t){return new e((function(n,i){if(!Array.isArray(t))return i(new TypeError("Promise.race accepts an array"));for(var r=0,o=t.length;r<o;r++)e.resolve(t[r]).then(n,i)}))}},{key:"_immediate",value:function(e){setTimeout(e,0)}},{key:"_unhandledRejection",value:function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)}}]),e}();h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){var n=new this.constructor((function(){return null}));return this.handle(new d(e,t,n)),n},h.prototype.finally=function(e){var t=this.constructor;return this.then((function(n){return t.resolve(e()).then((function(){return n}))}),(function(n){return t.resolve(e()).then((function(){return t.reject(n)}))}))};var p=h},547:(e,t,n)=>{"use strict";n.r(t),n.d(t,{ChannelState:()=>me,Channels:()=>Ye,PublisherState:()=>$e,Publishers:()=>st,SDK:()=>he,default:()=>ut});var i=n(575),r=n.n(i),o=n(913),a=n.n(o),s=n(713),u=n.n(s),c=function(e){return e[e.All=-1]="All",e[e.Trace=10]="Trace",e[e.Debug=20]="Debug",e[e.Info=30]="Info",e[e.Warn=40]="Warn",e[e.Error=50]="Error",e[e.Fatal=60]="Fatal",e[e.Off=100]="Off",e}({}),l=function(){function e(t,n,i){r()(this,e),u()(this,"_category",void 0),u()(this,"_appenders",void 0),u()(this,"_threshold",void 0),this._category=t,this._appenders=n,this._threshold=i}return a()(e,[{key:"category",get:function(){return this._category}},{key:"appenders",get:function(){return this._appenders}},{key:"threshold",get:function(){return this._threshold}},{key:"trace",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Trace)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Trace,t)}}},{key:"debug",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Debug)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Debug,t)}}},{key:"info",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Info)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Info,t)}}},{key:"warn",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Warn)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Warn,t)}}},{key:"error",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Error)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Error,t)}}},{key:"fatal",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Fatal)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Fatal,t)}}},{key:"log",value:function(e,t){var n=this,i=new Date,r=this.replacePlaceholders(t);this._appenders.value.forEach((function(t){t.log(e,r,n.category,i)}))}},{key:"replacePlaceholders",value:function(e){for(var t=this,n=e[0],i=0;n.indexOf&&e.length>1&&i>=0;)if((i=n.indexOf("%",i))>0)switch(n.substring(i+1,i+2)){case"%":n=n.substring(0,i)+n.substring(i+1),i++;break;case"s":case"d":e[0]=n=this.replaceArgument(this.toString(e[1]),n,i),e.splice(1,1);break;case"j":e[0]=n=this.replaceArgument(this.stringify(e[1]),n,i),e.splice(1,1);break;default:return e.toString()}return e.length>1&&(e=e.reduce((function(e,n,i,r){return i+1===r.length&&n instanceof Error?e+"\n"+t.toString(n.stack):e+"[".concat(t.toString(n),"]")}))),e.toString()}},{key:"stringify",value:function(e){var t=[];try{return JSON.stringify(e instanceof Error?this.toString(e):e,(function(e,n){if(n&&n instanceof Object){if(t.includes(n))return"<recursive>";t.push(n)}return n}),2)}catch(e){return"[object invalid JSON.stringify]"}}},{key:"replaceArgument",value:function(e,t,n){return t.substring(0,n)+this.toString(e)+t.substring(n+2)}},{key:"toString",value:function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e)return e.toString();var t="";if(e)if("function"==typeof e)t=e.toString();else if(e instanceof Object)try{t=e.toString()}catch(e){t="[object invalid toString()]"}return t}}]),e}(),d=function(){function e(){r()(this,e),u()(this,"_appenders",[])}return a()(e,[{key:"value",get:function(){return this._appenders}},{key:"add",value:function(e){this._appenders.push(e)}},{key:"remove",value:function(e){this._appenders=this._appenders.reduce((function(t,n){return n!==e&&t.push(n),t}),[])}}]),e}(),h=function(){function e(){r()(this,e)}return a()(e,null,[{key:"sendLocalCandidates",get:function(){return this._sendLocalCandidates}},{key:"sendLogs",get:function(){return this._sendLogs}},{key:"sendMetrics",get:function(){return this._sendMetrics}},{key:"logToConsole",get:function(){return this._logToConsole}},{key:"applyFeatures",value:function(){try{var e={sendLocalCandidates:!1,sendLogs:"Off",sendMetrics:"Essential",logToConsole:"Off"};this._sendLocalCandidates=!("sendLocalCandidates"in e)||e.sendLocalCandidates,this._sendLogs="sendLogs"in e?e.sendLogs:"All",this._sendMetrics="sendMetrics"in e?e.sendMetrics:"All",this._logToConsole="logToConsole"in e?e.logToConsole:"All"}catch(e){this._sendLocalCandidates=!0,this._sendLogs="All",this._sendMetrics="All",this._logToConsole="All"}}}]),e}();u()(h,"_sendLocalCandidates",void 0),u()(h,"_sendLogs",void 0),u()(h,"_sendMetrics",void 0),u()(h,"_logToConsole",void 0),h.applyFeatures();var p=function(){function e(){r()(this,e)}return a()(e,null,[{key:"defaultLoggingLevel",get:function(){return c[h.sendLogs]}},{key:"defaultConsoleLoggingLevel",get:function(){return c[h.logToConsole]}},{key:"defaultTelemetryLoggingLevel",get:function(){return c.Info}}]),e}(),f=function(){function e(){r()(this,e),u()(this,"_threshold",p.defaultLoggingLevel)}return a()(e,[{key:"value",get:function(){return this._threshold}},{key:"setThreshold",value:function(e){this._threshold=e}}]),e}(),v=function(){function e(t){r()(this,e),u()(this,"_threshold",void 0),this._threshold=t}return a()(e,[{key:"log",value:function(e,t,n,i){if(!(e<this._threshold)){var r="".concat(i.toISOString()," [").concat(n,"] [").concat(c[e],"] ").concat(t);e<c.Warn?console.log(r):console.error(r)}}}]),e}(),m=n(926),g=n.n(m),_=n(757),y=n.n(_),C=function(){function e(){r()(this,e)}return a()(e,null,[{key:"sdkVersion",get:function(){try{return"2023-06-12T16:28:22.870Z (2023.2.2-beta.69)"}catch(e){return this._defaultVersion}}}]),e}();u()(C,"_defaultVersion",(new Date).toISOString());var b=function(){function e(t){r()(this,e),u()(this,"_telemetryConfiguration",void 0),u()(this,"_logs",[]),u()(this,"_isSending",void 0),u()(this,"_domain",location.hostname),this._telemetryConfiguration=t}var t,n;return a()(e,[{key:"push",value:function(e,t,n,i){var r={timestamp:i.toISOString(),tenancy:this._telemetryConfiguration.tenancy,level:c[e],category:n,message:t,sessionId:this._telemetryConfiguration.sessionId,version:C.sdkVersion,environment:this._telemetryConfiguration.environment,fullQualifiedName:this._domain};e<c.Error?this._logs.push(r):this._logs.unshift(r),this.sendLogsIfAble()}},{key:"sendLogs",value:(n=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=new FormData).append("jsonBody",JSON.stringify({records:t})),e.next=4,fetch(this._telemetryConfiguration.url,{method:"POST",body:n});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"sendLogsIfAble",value:(t=g()(y().mark((function e(){var t,n,i,r,o=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this._logs.length<=0||this._isSending)){e.next=2;break}return e.abrupt("return");case 2:for(t=0,n=0,this._isSending=!0,i=function(e){return Object.values(e).reduce((function(e,t){return e+(t?t.length:0)}),0)};this._logs.length>t&&i(this._logs[t])+n<8192;)n+=i(this._logs[t]),t++;return t||(this._logs[t].message=this._logs[t].message.substring(0,i(this._logs[t])+(8192-i(this._logs[t]))),t=1),r=this._logs.slice(0,t),this._logs=this._logs.slice(t),e.abrupt("return",this.sendLogs(r).then((function(e){return o._isSending=!1,o.sendLogsIfAble(),e})).catch((function(){o._isSending=!1,o.sendLogsIfAble()})));case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),k=function(){function e(t){r()(this,e),u()(this,"_telemetryService",void 0),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_threshold",void 0),this._tenancy=t.tenancy,this._sessionId=t.sessionId,this._threshold=t.threshold,this._telemetryService=new b(t)}return a()(e,[{key:"log",value:function(e,t,n,i){e<this._threshold||this._telemetryService.push(e,t,n,i)}}]),e}(),x=function(){function e(){r()(this,e),u()(this,"_url","https://telemetry.phenixrts.com/telemetry/logs"),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_environment",void 0),u()(this,"_threshold",p.defaultTelemetryLoggingLevel)}return a()(e,[{key:"url",get:function(){return this._url},set:function(e){var t=new URL(e);t.pathname=t.pathname+"/logs",this._url=t.toString()}},{key:"environment",get:function(){return this._environment},set:function(e){this._environment=e}},{key:"tenancy",get:function(){return this._tenancy},set:function(e){this._tenancy=e}},{key:"sessionId",get:function(){return this._sessionId},set:function(e){this._sessionId=e}},{key:"threshold",get:function(){return this._threshold},set:function(e){this._threshold=e}}]),e}(),w=function(){function e(){r()(this,e)}return a()(e,null,[{key:"defaultTelemetryLevel",get:function(){return S[h.sendMetrics]}}]),e}(),S=function(e){return e[e.Off=100]="Off",e[e.Essential=10]="Essential",e[e.All=-1]="All",e}({}),T=function(){function e(){r()(this,e),u()(this,"_url","https://telemetry.phenixrts.com/telemetry/metrics"),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_environment",void 0),u()(this,"_threshold",w.defaultTelemetryLevel)}return a()(e,[{key:"url",get:function(){return this._url},set:function(e){var t=new URL(e);t.pathname=t.pathname+"/metrics",this._url=t.toString()}},{key:"environment",get:function(){return this._environment},set:function(e){this._environment=e}},{key:"tenancy",get:function(){return this._tenancy},set:function(e){this._tenancy=e}},{key:"sessionId",get:function(){return this._sessionId},set:function(e){this._sessionId=e}},{key:"threshold",get:function(){return this._threshold},set:function(e){this._threshold=e}}]),e}(),L=function(e){throw new Error("Unexpected value [".concat(e,"]. This should never be reached"))},R=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertTelemetryLevelToTelemetryLevelType",value:function(e){switch(e){case S.Off:return"Off";case S.Essential:return"Essential";case S.All:return"All";default:L(e)}}},{key:"convertTelemetryLevelTypeToTelemetryLevel",value:function(e){switch(e){case"Off":return S.Off;case"Essential":return S.Essential;case"All":return S.All;default:L(e)}}}]),e}(),P=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertLoggingLevelToLoggingLevelType",value:function(e){switch(e){case c.Off:return"Off";case c.Trace:return"Trace";case c.Debug:return"Debug";case c.Info:return"Trace";case c.Warn:return"Warn";case c.Error:return"Error";case c.Fatal:return"Fatal";case c.All:return"All";default:L(e)}}},{key:"convertLoggingLevelTypeToLoggingLevel",value:function(e){switch(e){case"Off":return c.Off;case"Trace":return c.Trace;case"Debug":return c.Debug;case"Info":return c.Info;case"Warn":return c.Warn;case"Error":return c.Error;case"Fatal":return c.Fatal;case"All":return c.All;default:L(e)}}}]),e}(),E=function(){function e(){r()(this,e)}return a()(e,[{key:"getStringValue",value:function(e){return this.defaultStringValue[e]}},{key:"getBooleanValue",value:function(e){return this.defaultBooleanValue[e]}},{key:"defaultStringValue",get:function(){return{"phenix-metrics-level":R.convertTelemetryLevelToTelemetryLevelType(w.defaultTelemetryLevel),"phenix-logging-level":P.convertLoggingLevelToLoggingLevelType(p.defaultLoggingLevel),"phenix-console-logging-level":P.convertLoggingLevelToLoggingLevelType(p.defaultConsoleLoggingLevel),"phenix-telemetry-logging-level":P.convertLoggingLevelToLoggingLevelType(p.defaultTelemetryLoggingLevel),"phenix-channel-token":"","phenix-uri":"","phenix-base-uri":""}}},{key:"defaultBooleanValue",get:function(){return{"phenix-automatically-retry-on-failure":!0,"phenix-automatically-reconnect-peer-connection":!0}}}]),e}(),O=function(){function e(){throw r()(this,e),new Error("LoggerFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"telemetryConfiguration",get:function(){return e._telemetryConfiguration}},{key:"getLogger",value:function(t){return"string"!=typeof t&&(t="SDK"),e._loggers[t]||(e._loggers[t]=new l(t,this._appenders,this._threshold))}},{key:"applyLoggerConfigFromParameterConfiguration",value:function(){e.applyLoggingLevel(),e.applyAppenderLoggingLevel("console",e.applyConsoleLogger.bind(this)),e.applyAppenderLoggingLevel("telemetry",e.applyTelemetryLogger.bind(this))}},{key:"applyLoggingLevel",value:function(){var e=this._configurationParameterReader.getStringValue("phenix-logging-level");c[e]&&this._threshold.setThreshold(c[e])}},{key:"applyAppenderLoggingLevel",value:function(e,t){var n=this._configurationParameterReader.getStringValue("phenix-".concat(e,"-logging-level"));"Off"!==n&&t(c[n])}},{key:"applyConsoleLogger",value:function(e){this._appenders.add(new v(e||p.defaultConsoleLoggingLevel))}},{key:"applyTelemetryLogger",value:function(e){this._telemetryConfiguration.threshold=e||p.defaultTelemetryLoggingLevel,this._appenders.add(new k(this._telemetryConfiguration))}}]),e}();u()(O,"_configurationParameterReader",new E),u()(O,"_loggers",{}),u()(O,"_appenders",new d),u()(O,"_threshold",new f),u()(O,"_telemetryConfiguration",new x),O.applyLoggerConfigFromParameterConfiguration();var D=function(){function e(){throw r()(this,e),new Error("Strings is a static class that may not be instantiated")}return a()(e,null,[{key:"random",value:function(e){var t=Math.ceil(e/13);return new Array(t).fill((function(){return Math.random().toString(16).substring(2,15)})).reduce((function(e,t){return e+t()}),"").substring(0,e)}}]),e}(),F=n(205),I=n.n(F),M=n(585),A=n.n(M),j=n(754),V=n.n(j),U=function(){function e(t){r()(this,e),u()(this,"_disposed",void 0),u()(this,"_disposable",void 0),this._disposed=!1,this._disposable=t}return a()(e,[{key:"dispose",value:function(){if(!this._disposed)return this._disposed=!0,this._disposable.call(this)}}]),e}();var B=function(e){I()(o,e);var t,n,i=(t=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,i=V()(t);if(n){var r=V()(this).constructor;e=Reflect.construct(i,arguments,r)}else e=i.apply(this,arguments);return A()(this,e)});function o(e,t){return r()(this,o),i.call(this,(function(){var n=e.indexOf(t);n>=0&&e.splice(n,1)}))}return a()(o)}(U),N=function(){function e(t){r()(this,e),u()(this,"_listeners",void 0),u()(this,"_value",void 0),this._listeners=[],this._value=t}return a()(e,[{key:"value",get:function(){return this._value},set:function(e){var t=this._value!==e;if(t&&e){var n=e;"function"==typeof n.equals&&(t=!n.equals(this._value))}t&&(this._value=e,this._listeners.forEach((function(t){t(e)})))}},{key:"subscribe",value:function(e){return this._listeners.push(e),e(this._value),new B(this._listeners,e)}}]),e}(),z=function(){function e(t){r()(this,e),u()(this,"_subject",void 0),this._subject=t}return a()(e,[{key:"value",get:function(){return this._subject.value}},{key:"subscribe",value:function(e){return this._subject.subscribe(e)}}]),e}(),G=function(){function e(t){var n,i;r()(this,e),u()(this,"_applicationId",void 0),u()(this,"_token",void 0),this._applicationId=(null==t?void 0:t.applicationId)||"",this._token={uri:null!=t&&null!==(n=t.token)&&void 0!==n&&n.uri?new URL(t.token.uri):null,capabilities:(null==t||null===(i=t.token)||void 0===i?void 0:i.capabilities)||[]}}return a()(e,[{key:"uri",get:function(){return this._token.uri}},{key:"capabilities",get:function(){return this._token.capabilities}},{key:"tenancy",get:function(){return this._applicationId}}]),e}(),H=function(){function e(){r()(this,e)}return a()(e,null,[{key:"parseToken",value:function(t){if(!this.isEncodedEdgeTokenValid(t))return e._logger.error("Token is not valid [%s]",t),new G(null);try{var n=atob(t.substr(7)),i=JSON.parse(n);return i.token=JSON.parse(i.token),new G(i)}catch(t){return e._logger.error("Cannot parse token value",t),new G(null)}}},{key:"isEncodedEdgeTokenValid",value:function(e){return!!e&&e.startsWith("DIGEST:")}}]),e}();u()(H,"_logger",O.getLogger("EdgeAuthParser"));var W=function(){function e(){r()(this,e)}return a()(e,null,[{key:"browserNameAndVersion",get:function(){return e._browserNameAndVersion}},{key:"browserName",get:function(){return this._browserName}},{key:"browserMajorVersion",get:function(){return this._browserMajorVersion}},{key:"isChrome69",get:function(){return e._isChrome69}},{key:"isChrome70",get:function(){return e._isChrome70}},{key:"isChrome71",get:function(){return e._isChrome71}},{key:"isChrome72",get:function(){return e._isChrome72}},{key:"isChrome74",get:function(){return e._isChrome74}},{key:"isChrome75",get:function(){return e._isChrome75}},{key:"isChrome76",get:function(){return e._isChrome76}},{key:"isChrome77",get:function(){return e._isChrome77}},{key:"parseBrowserNameAndVersion",value:function(){if(!navigator||!navigator.userAgent)return"";var t=navigator.userAgent.match(e._browserNameAndVersionRegex);return t&&t[0]?t[0]:e.parseBrowserNameAndVersionForIE()}},{key:"parseBrowserName",value:function(){if(!e._browserNameAndVersion)return"";var t=e._browserNameAndVersion.split("/");return t&&t[0]?t[0]:""}},{key:"parseBrowserMajorVersion",value:function(){if(!e._browserNameAndVersion)return 0;var t=e._browserNameAndVersion.split("/");if(!t||!t[1])return 0;var n=t[1];return n&&Number(n.split(".")[0])||0}},{key:"parseBrowserNameAndVersionForIE",value:function(){if(!navigator||!navigator.userAgent)return"";var e=navigator.userAgent,t=e.indexOf("MSIE ");if(t>0)return"IE/".concat(parseInt(e.substring(t+5,e.indexOf(".",t)),10));if(e.indexOf("Trident/")>0){var n=e.indexOf("rv:");return"IE/".concat(parseInt(e.substring(n+3,e.indexOf(".",n)),10))}return""}}]),e}();u()(W,"_browserNameAndVersionRegex",/(MSIE|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari|(?!AppleWebKit.+)Chrome|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d.apre]+)/g),u()(W,"_browserNameAndVersion",W.parseBrowserNameAndVersion()),u()(W,"_browserName",W.parseBrowserName()),u()(W,"_browserMajorVersion",W.parseBrowserMajorVersion()),u()(W,"_isChrome69",W._browserNameAndVersion.includes("Chrome/69.")),u()(W,"_isChrome70",W._browserNameAndVersion.includes("Chrome/70.")),u()(W,"_isChrome71",W._browserNameAndVersion.includes("Chrome/71.")),u()(W,"_isChrome72",W._browserNameAndVersion.includes("Chrome/72.")),u()(W,"_isChrome74",W._browserNameAndVersion.includes("Chrome/74.")),u()(W,"_isChrome75",W._browserNameAndVersion.includes("Chrome/75.")),u()(W,"_isChrome76",W._browserNameAndVersion.includes("Chrome/76.")),u()(W,"_isChrome77",W._browserNameAndVersion.includes("Chrome/77."));var J=n(8),K=n.n(J),q=function(){function e(){r()(this,e),u()(this,"_list",[])}return a()(e,[{key:"add",value:function(e){this._list.push(e)}},{key:"dispose",value:function(){this._list.forEach((function(e){return e.dispose()})),this._list.length=0}},{key:"toString",value:function(){return"DisposableList[disposables=".concat(this._list.length,"]")}}]),e}(),Q=function(){function e(){r()(this,e),u()(this,"_disposables",new q),u()(this,"_readOnlyIsForeground",void 0),u()(this,"_isForeground",void 0),u()(this,"_timeOfLastTabFocusChange",Date.now()),u()(this,"_documentFocusInterval",void 0),this._isForeground=new N(!0),this._readOnlyIsForeground=new z(this._isForeground),this.detectTabFocusChange()}return a()(e,[{key:"isForeground",get:function(){return this._readOnlyIsForeground}},{key:"getTimeSinceLastChange",value:function(){return Date.now()-this._timeOfLastTabFocusChange}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"detectTabFocusChange",value:function(){var e,t,n=this;if("object"===("undefined"==typeof document?"undefined":K()(document))){void 0!==document.msHidden?(e="msHidden",t="msvisibilitychange"):void 0!==document.webkitHidden?(e="webkitHidden",t="webkitvisibilitychange"):void 0!==document.hidden&&(e="hidden",t="visibilitychange");var i=function(){var t=!document[e];n.setFocusState(t)};void 0!==document.addEventListener&&void 0!==document[e]?(document.addEventListener(t,i,!1),this._disposables.add(new U((function(){document.removeEventListener(t,i,!1)})))):this.listenForDocumentFocus.call(this)}}},{key:"listenForDocumentFocus",value:function(){var e=this;this._documentFocusInterval=window.setInterval((function(){var t=document.hasFocus();e.setFocusState(t)}),3e3),this._disposables.add(new U((function(){e._documentFocusInterval&&clearInterval(e._documentFocusInterval),e._documentFocusInterval=null})))}},{key:"setFocusState",value:function(e){this._isForeground!==e&&(this._isForeground.value=e)}}]),e}(),Y=function(){function e(){r()(this,e)}return a()(e,null,[{key:"clientOfferDisabled",get:function(){return W.isChrome74||W.isChrome75||W.isChrome76||W.isChrome77}},{key:"addTranceiverDisabled",get:function(){return W.isChrome69||W.isChrome70||W.isChrome71||W.isChrome72}},{key:"getStatsPromiseBasedDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=66}},{key:"getCurrentOfferDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=69||"Firefox"===W.browserName&&W.browserMajorVersion<=56}},{key:"onTrackDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=63||"Firefox"===W.browserName&&W.browserMajorVersion<=52}},{key:"webkitRTCPeerConnectionEnabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=55}},{key:"promiseBasedPCMethodsDisabled",get:function(){return"Firefox"===W.browserName&&W.browserMajorVersion<=52}},{key:"shouldUseNativeHls",get:function(){return"Safari"===W.browserName||"SamsungBrowser"===W.browserName}},{key:"isPrecachingEnabled",get:function(){return"IE"!==W.browserName}},{key:"isInsertableStreamsSupported",get:function(){return!("undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator)}}]),e}(),Z=n(202).default,$=function(){function e(t){r()(this,e),u()(this,"_logger",O.getLogger("VanillaPeerConnection")),u()(this,"_peerConnection",void 0),Y.webkitRTCPeerConnectionEnabled?this._peerConnection=new webkitRTCPeerConnection(t):this._peerConnection=new RTCPeerConnection(t)}var t,n,i,o;return a()(e,[{key:"native",get:function(){return this._peerConnection}},{key:"currentLocalDescription",get:function(){return this._peerConnection.currentLocalDescription}},{key:"currentRemoteDescription",get:function(){return this._peerConnection.currentRemoteDescription}},{key:"iceConnectionState",get:function(){return this._peerConnection.iceConnectionState}},{key:"supportsGetConfiguration",get:function(){return"function"==typeof this._peerConnection.getConfiguration}},{key:"supportsSetConfiguration",get:function(){return"function"==typeof this._peerConnection.setConfiguration}},{key:"supportsAddTransceiver",get:function(){return!Y.addTranceiverDisabled&&"function"==typeof this._peerConnection.addTransceiver}},{key:"createOffer",value:(o=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.promiseBasedPCMethodsDisabled){e.next=2;break}return e.abrupt("return",new Z((function(e,i){return n._peerConnection.createOffer(e,i,t)})));case 2:return e.abrupt("return",this._peerConnection.createOffer(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"createAnswer",value:(i=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.promiseBasedPCMethodsDisabled){e.next=2;break}return e.abrupt("return",new Z((function(e,i){return n._peerConnection.createAnswer(e,i,t)})));case 2:return e.abrupt("return",this._peerConnection.createAnswer(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setLocalDescription",value:(n=g()(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._peerConnection.setLocalDescription(Y.promiseBasedPCMethodsDisabled?new RTCSessionDescription(t):t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setRemoteDescription",value:(t=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(null===(n=t.sdp)||void 0===n?void 0:n.match(/a=crypto:/i))&&this._logger.warn("SDP a=crypto is not supported"),e.abrupt("return",this._peerConnection.setRemoteDescription(Y.promiseBasedPCMethodsDisabled?new RTCSessionDescription(t):t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"getSenders",value:function(){return this._peerConnection.getSenders()}},{key:"getStats",value:function(e){return this._peerConnection.getStats(e)}},{key:"getStatsLegacy",value:function(){var e=this;return new Z((function(t){e._peerConnection.getStats(t)}))}},{key:"addEventListener",value:function(e,t,n){this._peerConnection.addEventListener(e,t,n)}},{key:"removeEventListener",value:function(e,t,n){this._peerConnection.removeEventListener(e,t,n)}},{key:"addTransceiver",value:function(e,t){return this._peerConnection.addTransceiver(e,t)}},{key:"addStream",value:function(e){var t=this;e.getTracks().forEach((function(e){t._peerConnection.addTrack(e)}))}},{key:"getConfiguration",value:function(){return this._peerConnection.getConfiguration()}},{key:"setConfiguration",value:function(e){this._peerConnection.setConfiguration(e)}},{key:"ontrack",get:function(){return this._peerConnection.ontrack},set:function(e){this._peerConnection.ontrack=e}},{key:"onicecandidate",get:function(){return this._peerConnection.onicecandidate},set:function(e){this._peerConnection.onicecandidate=e}},{key:"oniceconnectionstatechange",get:function(){return this._peerConnection.oniceconnectionstatechange},set:function(e){this._peerConnection.oniceconnectionstatechange=e}},{key:"close",value:function(){this._peerConnection.close()}}]),e}(),X=$,ee=function(){function e(){r()(this,e)}var t;return a()(e,[{key:"createPeerConnection",value:(t=g()(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new X(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}(),te=ee,ne=function(){function e(){throw r()(this,e),new Error("PeerConnectionService is a static class that may not be instantiated")}var t,n;return a()(e,null,[{key:"peerConnectionFactory",get:function(){return e._peerConnectionFactory}},{key:"initiateInitialPrecaching",value:function(){Y.isPrecachingEnabled&&e.precacheCreatePeerConnectionOffer().catch((function(t){return e._logger.error("Failed to pre-cache peer connection offer",t)}))}},{key:"precacheCreatePeerConnectionOffer",value:(n=g()(y().mark((function t(){return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e._cached={direction:"recvonly",peerConnection:e.createPeerConnectionOffer().catch((function(t){throw e._cached=null,t}))});case 1:case"end":return t.stop()}}),t)}))),function(){return n.apply(this,arguments)})},{key:"createPeerConnectionOffer",value:(t=g()(y().mark((function t(){var n,i,r=arguments;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.length>0&&void 0!==r[0]?r[0]:"recvonly",!e._cached||e._cached.direction!==n){t.next=5;break}return i=e._cached.peerConnection,e._cached=null,t.abrupt("return",i);case 5:return t.abrupt("return",e._peerConnectionFactory.value.createPeerConnection().then(function(){var e=g()(y().mark((function e(t){var i,r,o;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.supportsAddTransceiver){e.next=11;break}return r=t.addTransceiver("audio",{direction:n}),i=t.addTransceiver("video",{direction:n}),e.t0=r,e.t1=i,e.t2=t,e.next=9,t.createOffer(void 0);case 9:return e.t3=e.sent,e.abrupt("return",{audioTransceiver:e.t0,videoTransceiver:e.t1,peerConnection:e.t2,localOffer:e.t3});case 11:return o="recvonly"===n?{offerToReceiveAudio:!0,offerToReceiveVideo:!0}:{},e.t4=t,e.next=15,t.createOffer(o);case 15:return e.t5=e.sent,e.abrupt("return",{peerConnection:e.t4,localOffer:e.t5});case 17:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 6:case"end":return t.stop()}}),t)}))),function(){return t.apply(this,arguments)})}]),e}();u()(ne,"_logger",O.getLogger("PeerConnectionService")),u()(ne,"_peerConnectionFactory",new N(new te)),u()(ne,"_cached",void 0),ne.initiateInitialPrecaching();var ie=function(){function e(){r()(this,e)}return a()(e,null,[{key:"getTelemetryUrl",value:function(e){try{var t=new URL(e),n=t.hostname.split(".");switch(t.protocol){case"ws:":t.protocol="http:";break;case"wss:":t.protocol="https:"}return 2===n.length||3===n.length&&n[n.length-2].length<=2&&n[n.length-1].length<=3?n.unshift("telemetry"):n[0].startsWith("stg-")||n[0].endsWith("-stg")||n[0].includes("-stg-")||"stg"===n[0]?n[0]="telemetry-stg":n[0].startsWith("local")||n[0].endsWith("-local")||(n[0]="telemetry"),t.hostname=n.join("."),"".concat(t.origin,"/telemetry")}catch(t){return e}}}]),e}(),re=function(){function e(){r()(this,e)}return a()(e,null,[{key:"getEnvironmentFromUrl",value:function(e){try{return new URL(e).origin}catch(e){return""}}}]),e}(),oe=function(){function e(){throw r()(this,e),new Error("DiscoveryUri is a static class that may not be instantiated")}return a()(e,null,[{key:"uri",get:function(){return e._discoveryUri}},{key:"buildDiscoveryUrl",value:function(e){var t=new URL(e.toString()),n=C.sdkVersion;return t.search="?".concat(new URLSearchParams([["version",n],["_","".concat(Date.now())]]).toString()),"/"===t.pathname&&(t.pathname="/pcast/endPoints"),t.toString()}}]),e}();u()(oe,"_discoveryUri",new N("https://pcast.phenixrts.com/pcast/endPoints"));var ae=function(e){return e[e.TimeToFirstFrame=0]="TimeToFirstFrame",e[e.ChannelCreationTimeToFirstFrame=1]="ChannelCreationTimeToFirstFrame",e[e.Stalled=2]="Stalled",e[e.Buffering=3]="Buffering",e[e.SetupCompleted=4]="SetupCompleted",e[e.SetupFailed=5]="SetupFailed",e[e.RoundTripTime=6]="RoundTripTime",e[e.DownlinkThroughputCapacity=7]="DownlinkThroughputCapacity",e[e.NetworkType=8]="NetworkType",e[e.ResolutionChanged=9]="ResolutionChanged",e[e.ApplicationForeground=10]="ApplicationForeground",e[e.ApplicationBackground=11]="ApplicationBackground",e}(ae||{}),se=ae,ue=function(){function e(t){r()(this,e),u()(this,"_metrics",void 0),this._metrics=t}return a()(e,[{key:"getName",value:function(){return se[this._metrics]}},{key:"getTelemetryLevel",value:function(){switch(this._metrics){case se.TimeToFirstFrame:case se.ChannelCreationTimeToFirstFrame:return S.Essential;case se.Stalled:case se.Buffering:case se.SetupCompleted:case se.SetupFailed:case se.RoundTripTime:case se.DownlinkThroughputCapacity:case se.NetworkType:case se.ResolutionChanged:case se.ApplicationForeground:case se.ApplicationBackground:return S.All;default:L(this._metrics)}}}]),e}(),ce=function(){function e(t){r()(this,e),u()(this,"_metricsConfiguration",void 0),u()(this,"_metrics",[]),u()(this,"_isSending",void 0),u()(this,"_domain",location.hostname),this._metricsConfiguration=t}var t,n;return a()(e,[{key:"metricsConfiguration",get:function(){return this._metricsConfiguration}},{key:"push",value:function(e){var t=e.streamId,n=e.value,i=e.previousValue,r=e.runtime,o=e.resource,a=e.kind,s=new ue(e.metricType);if(!(this._metricsConfiguration.threshold>s.getTelemetryLevel())){var u={timestamp:(new Date).toISOString(),tenancy:this._metricsConfiguration.tenancy,sessionId:this._metricsConfiguration.sessionId,streamId:t,metric:s.getName(),value:n,previousValue:i,fullQualifiedName:this._domain,environment:this._metricsConfiguration.environment,version:C.sdkVersion,runtime:r,resource:o,kind:a};this._metrics.push(u),this.sendMetricsIfAble()}}},{key:"sendMetrics",value:(n=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=new FormData).append("jsonBody",JSON.stringify({records:t})),e.next=4,fetch(this._metricsConfiguration.url,{method:"POST",body:n});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"sendMetricsIfAble",value:(t=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this._metrics.length<=0||this._isSending)){e.next=2;break}return e.abrupt("return");case 2:return this._isSending=!0,t=this._metrics.slice(0,1024),this._metrics=this._metrics.slice(1024),e.abrupt("return",this.sendMetrics(t).then((function(e){return n._isSending=!1,n.sendMetricsIfAble(),e})).catch((function(){n._isSending=!1,n.sendMetricsIfAble()})));case 6:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),le=function(){function e(){throw r()(this,e),new Error("LoggerFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"getMetricsService",value:function(t){if("string"!=typeof t)throw new Error("ur");var n=e._metricsServices[t];if(n)return n;var i=new T;return i.sessionId=he.clientSessionId,i.tenancy=he.tenancy.value,i.url=ie.getTelemetryUrl(t),i.environment=re.getEnvironmentFromUrl(t),i.threshold=R.convertTelemetryLevelTypeToTelemetryLevel(he.telemetryLevel),e._metricsServices[t]=new ce(i)}},{key:"setTelemetryLevel",value:function(t){var n=Object.values(e._metricsServices);n&&n.length&&n.forEach((function(e){e.metricsConfiguration.threshold=t}))}}]),e}();u()(le,"_metricsServices",{});var de=window.__phenixPageLoadTime||window.__pageLoadTime||Date.now(),he=function(){function e(){throw r()(this,e),new Error("SDK is a static class that may not be instantiated")}return a()(e,null,[{key:"pageLoadTime",get:function(){return de}},{key:"sendLocalCandidates",get:function(){return this._sendLocalCandidates}},{key:"tenancy",get:function(){return this._tenancy}},{key:"clientSessionId",get:function(){return e._clientSessionId}},{key:"loadedTimestamp",get:function(){return e._loadedTimestamp}},{key:"initialized",get:function(){return e._readOnlyInitialized}},{key:"discoveryUri",get:function(){return e._readOnlyDiscoveryUri}},{key:"peerConnectionFactory",get:function(){return e._readOnlyPeerConnectionFactory}},{key:"automaticRetryOnFailure",get:function(){return e._automaticallyRetryOnFailure}},{key:"automaticallyReconnectPeerConnection",get:function(){return e._automaticallyReconnectPeerConnection}},{key:"automaticallyPlayMediaStream",get:function(){return e._automaticallyPlayMediaStream}},{key:"automaticallyMuteVideoOnPlayFailure",get:function(){return e._automaticallyMuteVideoOnPlayFailure}},{key:"webPlayerLoader",get:function(){return this._webPlayerLoader}},{key:"shakaPlayerLoader",get:function(){return this._shakaPlayerLoader}},{key:"hlsJsLoader",get:function(){return this._hlsJsLoader}},{key:"metricsService",get:function(){return e._metricsService}},{key:"applicationActivityMonitor",get:function(){return this._applicationActivityMonitor}},{key:"telemetryUrl",get:function(){return this._telemetryUrl}},{key:"maximalNumberOfPeerConnectionReconnectAttempts",get:function(){return this._maximalNumberOfPeerConnectionReconnectAttempts},set:function(e){this._maximalNumberOfPeerConnectionReconnectAttempts=e}},{key:"loggingLevel",get:function(){return P.convertLoggingLevelToLoggingLevelType(this._logger.threshold.value)}},{key:"telemetryLevel",get:function(){return R.convertTelemetryLevelToTelemetryLevelType(e._telemetryLevel.value)}},{key:"browserDetector",get:function(){return W}},{key:"applyTelemetryConfiguration",value:function(){var t=this,n=O.telemetryConfiguration;n.sessionId=e.clientSessionId,e._environment.subscribe((function(e){n.environment=e})),e.telemetryUrl.subscribe((function(e){var i=t._logger.appenders.value.find((function(e){return e instanceof k}));i&&(n.url=e,t._logger.appenders.remove(i),t._logger.appenders.add(new k(n)),t._logger.info("Telemetry URL was set to [%s]",n.url))})),e._tenancy.subscribe((function(e){var i=t._logger.appenders.value.find((function(e){return e instanceof k}));i&&e&&(n.tenancy=e,t._logger.appenders.remove(i),t._logger.appenders.add(new k(n)),t._logger.info("Telemetry tenancy was set to [%s]",n.tenancy))}))}},{key:"applyMetricsConfiguration",value:function(){e._metricsService=le.getMetricsService(oe.uri.value),e._metricsConfiguration=e._metricsService.metricsConfiguration,e._metricsConfiguration.sessionId=e.clientSessionId,e._environment.subscribe((function(t){e._metricsConfiguration.environment=t})),e.telemetryUrl.subscribe((function(t){e._metricsConfiguration.url=t})),e._tenancy.subscribe((function(t){e._metricsConfiguration.tenancy=t}));var t=this._configurationParameterReader.getStringValue("phenix-metrics-level");t&&le.setTelemetryLevel(S[t]),e._telemetryLevel.subscribe((function(e){le.setTelemetryLevel(e)}))}},{key:"applyAutomaticallyRetryOnFailureFromParameterConfiguration",value:function(){this._automaticallyRetryOnFailure=this._configurationParameterReader.getBooleanValue("phenix-automatically-retry-on-failure"),this._logger.info("Automatically retry on failure is set to: [%s]",this._automaticallyRetryOnFailure)}},{key:"applyAutomaticallyReconnectPeerConnectionFromParameterConfiguration",value:function(){this._automaticallyReconnectPeerConnection=this._configurationParameterReader.getBooleanValue("phenix-automatically-reconnect-peer-connection"),this._logger.info("Automatically reconnect peer connection is set to: [%s]",this._automaticallyReconnectPeerConnection)}},{key:"applyDiscoveryUriDefaultFromParameterConfiguration",value:function(){e.discoveryUri.subscribe((function(t){e.telemetryUrl.value=e.getTelemetryUrl(t),e._environment.value=re.getEnvironmentFromUrl(t)}));var t=this._configurationParameterReader.getStringValue("phenix-channel-token");if(t){var n=H.parseToken(t);return e._tenancy.value=n.tenancy,oe.uri.value=(n.uri||e.discoveryUri.value).toString(),void this._logger.info("Discovery URI set from configuration parameter to [%s]",e.discoveryUri.value)}var i=this._configurationParameterReader.getStringValue("phenix-uri");if(i)return oe.uri.value=i,void this._logger.info('Discovery URI set from "phenix-uri" configuration parameter tag to [%s]',e.discoveryUri.value);var r=this._configurationParameterReader.getStringValue("phenix-base-uri");return r?(oe.uri.value="".concat(r,"/pcast/endPoints"),void this._logger.info('Discovery URI set from "phenix-base-uri" configuration parameter tag to [%s]',e.discoveryUri.value)):void 0}},{key:"init",value:function(t){if(this._initialized.value||(this._applicationActivityMonitor=new Q),t){if(t.discoveryUri&&(oe.uri.value=t.discoveryUri),t.peerConnectionFactory&&(ne.peerConnectionFactory.value=t.peerConnectionFactory),t.telemetryLevel&&S[t.telemetryLevel]&&(e._telemetryLevel.value=R.convertTelemetryLevelTypeToTelemetryLevel(t.telemetryLevel)),t.loggingLevel&&c[t.loggingLevel]&&this._logger.threshold.setThreshold(P.convertLoggingLevelTypeToLoggingLevel(t.loggingLevel)),t.consoleLoggingLevel&&c[t.consoleLoggingLevel]){var n=this._logger.appenders.value.find((function(e){return e instanceof v}));n&&this._logger.appenders.remove(n),"Off"!==t.consoleLoggingLevel&&this._logger.appenders.add(new v(P.convertLoggingLevelTypeToLoggingLevel(t.consoleLoggingLevel)))}"boolean"==typeof t.automaticallyPlayMediaStream&&(this._automaticallyPlayMediaStream=t.automaticallyPlayMediaStream),"boolean"==typeof t.automaticallyMuteVideoOnPlayFailure&&(this._automaticallyMuteVideoOnPlayFailure=t.automaticallyMuteVideoOnPlayFailure),t.webPlayerLoader&&(this._webPlayerLoader=t.webPlayerLoader),t.shakaPlayerLoader&&(this._shakaPlayerLoader=t.shakaPlayerLoader),t.hlsJsLoader&&(this._hlsJsLoader=t.hlsJsLoader)}e._initialized.value=!0}},{key:"dispose",value:function(){e._initialized.value=!1,this._applicationActivityMonitor.dispose(),this._applicationActivityMonitor=null}},{key:"getTelemetryUrl",value:function(e){return ie.getTelemetryUrl(e)}}]),e}();u()(he,"_automaticallyRetryOnFailure",!0),u()(he,"_automaticallyReconnectPeerConnection",!0),u()(he,"_automaticallyPlayMediaStream",!0),u()(he,"_automaticallyMuteVideoOnPlayFailure",!0),u()(he,"_webPlayerLoader",null),u()(he,"_shakaPlayerLoader",null),u()(he,"_hlsJsLoader",null),u()(he,"_configurationParameterReader",new E),u()(he,"_applicationActivityMonitor",void 0),u()(he,"_environment",new N("")),u()(he,"_telemetryUrl",new N("https://telemetry.phenixrts.com/telemetry")),u()(he,"_maximalNumberOfPeerConnectionReconnectAttempts",8),u()(he,"_telemetryLevel",new N(w.defaultTelemetryLevel)),u()(he,"_metricsService",void 0),u()(he,"_metricsConfiguration",void 0),u()(he,"_sendLocalCandidates",new N(h.sendLocalCandidates)),u()(he,"_tenancy",new N("")),u()(he,"_clientSessionId",D.random(32)),u()(he,"_loadedTimestamp",new Date),u()(he,"_logger",O.getLogger("SDK")),u()(he,"_initialized",new N(!1)),u()(he,"_readOnlyInitialized",new z(he._initialized)),u()(he,"_readOnlyDiscoveryUri",new z(oe.uri)),u()(he,"_readOnlyPeerConnectionFactory",new z(ne.peerConnectionFactory)),window.addEventListener("unload",(function(){he.dispose()})),he.applyDiscoveryUriDefaultFromParameterConfiguration(),he.applyMetricsConfiguration(),he.applyTelemetryConfiguration(),he.applyAutomaticallyRetryOnFailureFromParameterConfiguration(),he.applyAutomaticallyReconnectPeerConnectionFromParameterConfiguration(),he.init();var pe=function(){function e(t,n){r()(this,e),u()(this,"width",void 0),u()(this,"height",void 0),this.width=t,this.height=n}return a()(e,[{key:"equals",value:function(e){return e&&this.width===e.width&&this.height===e.height}},{key:"toString",value:function(){return"".concat(this.width,"x").concat(this.height)}}],[{key:"empty",get:function(){return new e(0,0)}}]),e}(),fe=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e5;r()(this,e),u()(this,"_backoffIntervalInMillisecond",void 0),u()(this,"_minBackoffIntervalInMillisecond",void 0),u()(this,"_maxBackoffIntervalInMillisecond",void 0),this._backoffIntervalInMillisecond=t,this._minBackoffIntervalInMillisecond=n,this._maxBackoffIntervalInMillisecond=i}return a()(e,[{key:"getExponentialBackoffIntervalByFailureCount",value:function(e){var t=this._backoffIntervalInMillisecond/1e3,n=.5+.5*Math.random(),i=Math.pow(t,e-2),r=Math.floor(i)*n,o=Math.ceil(Math.max(1e3*r,this._minBackoffIntervalInMillisecond));return Math.min(o,this._maxBackoffIntervalInMillisecond)}}]),e}(),ve=function(e){return e[e.Offline=1]="Offline",e[e.Starting=2]="Starting",e[e.Paused=3]="Paused",e[e.Playing=4]="Playing",e[e.Recovering=5]="Recovering",e[e.Reconnecting=6]="Reconnecting",e[e.StandBy=7]="StandBy",e[e.Stopped=8]="Stopped",e[e.Unauthorized=9]="Unauthorized",e[e.GeoRestricted=10]="GeoRestricted",e[e.GeoBlocked=11]="GeoBlocked",e[e.UnsupportedFeature=12]="UnsupportedFeature",e[e.ConfigurationError=13]="ConfigurationError",e[e.Error=14]="Error",e}(ve||{}),me=ve,ge=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;r()(this,e),u()(this,"_duration",void 0),this._duration=t}return a()(e,[{key:"toIsoString",value:function(){if(0===this._duration)return"P0S";var e=this._duration<0,t=e?Math.abs(this._duration):this._duration,n=Math.floor(t),i=n%1e3,r=(n=Math.floor(n/1e3))%60,o=(n=Math.floor(n/60))%60,a=(n=Math.floor(n/60))%24,s=["PT"];return e&&s.unshift("-"),a&&s.push(a+"H"),o&&s.push(o+"M"),(r||i)&&(s.push(String(r)),i&&s.push("."+this.padStart(i.toString(),3,"0")),s.push("S")),s.join("")}},{key:"padStart",value:function(e,t,n){return t>>=0,n=String(void 0!==n?n:" "),e.length>t?e:((t-=e.length)>n.length&&(n+=n.repeat(t/n.length)),n.slice(0,t)+e)}}]),e}(),_e=function(){function e(t,n,i,o){r()(this,e),u()(this,"_pageLoadTime",void 0),u()(this,"_channelStartTime",void 0),u()(this,"_logger",O.getLogger("StreamTelemetry")),u()(this,"_disposables",new q),u()(this,"_streamId",void 0),u()(this,"_metricsService",void 0),u()(this,"_listenToFirstTime",void 0),u()(this,"_listenForStall",void 0),u()(this,"_listenForContinuation",void 0),u()(this,"_timeToFirstFrame",void 0),u()(this,"_channelCreationTimeToFirstFrame",void 0),u()(this,"_startRecordingFirstFrame",void 0),u()(this,"_videoStalled",void 0),u()(this,"_lastProgress",void 0),u()(this,"_videoResolution",void 0),u()(this,"_clearTimeToFirstFrameListener",void 0),u()(this,"_clearRebufferingListener",void 0),this._streamId=t,this._pageLoadTime=n,this._channelStartTime=i,this._metricsService=o}return a()(e,[{key:"setupListenerForTimeToFirstTime",value:function(e){var t=this;this._startRecordingFirstFrame=Date.now(),this._listenToFirstTime=function(){return t.callTimeToFirstFrame()},e.addEventListener("loadeddata",this._listenToFirstTime),e.addEventListener("loadedmetadata",this._listenToFirstTime),this._clearTimeToFirstFrameListener=new U((function(){e.removeEventListener("loadeddata",t._listenToFirstTime),e.removeEventListener("loadedmetadata",t._listenToFirstTime)})),this._disposables.add(this._clearTimeToFirstFrameListener)}},{key:"setupListenerForRebuffering",value:function(e){var t=this;this._listenForStall=function(){return t.onStall()},this._listenForContinuation=function(n){return t.onContinuation(n,e)},e.addEventListener("stalled",this._listenForStall),e.addEventListener("pause",this._listenForStall),e.addEventListener("suspend",this._listenForStall),e.addEventListener("play",this._listenForContinuation),e.addEventListener("playing",this._listenForContinuation),e.addEventListener("progress",this._listenForContinuation),e.addEventListener("timeupdate",this._listenForContinuation),this._clearRebufferingListener=new U((function(){e.removeEventListener("stalled",t._listenForStall),e.removeEventListener("pause",t._listenForStall),e.removeEventListener("suspend",t._listenForStall),e.removeEventListener("play",t._listenForContinuation),e.removeEventListener("playing",t._listenForContinuation),e.removeEventListener("progress",t._listenForContinuation),e.removeEventListener("timeupdate",t._listenForContinuation)})),this._disposables.add(this._clearRebufferingListener)}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"durationSincePageLoad",get:function(){var e=Date.now();return new ge(e-this._pageLoadTime).toIsoString()}},{key:"callTimeToFirstFrame",value:function(){var e=Date.now();this.pushTimeToFirstFrame(e),this.pushChannelCreationTimeToFirstFrame(e),this._clearTimeToFirstFrameListener.dispose()}},{key:"pushTimeToFirstFrame",value:function(e){this._timeToFirstFrame=e-this._startRecordingFirstFrame,this._metricsService.push({metricType:se.TimeToFirstFrame,runtime:(e-this._pageLoadTime)/1e3,value:{uint64:this._timeToFirstFrame},streamId:this._streamId}),this._logger.info("[%s] [%s] First frame [%s]",this.durationSincePageLoad,this._streamId,new ge(this._timeToFirstFrame).toIsoString())}},{key:"pushChannelCreationTimeToFirstFrame",value:function(e){this._channelCreationTimeToFirstFrame=e-this._channelStartTime,this._metricsService.push({metricType:se.ChannelCreationTimeToFirstFrame,runtime:(e-this._pageLoadTime)/1e3,value:{uint64:this._channelCreationTimeToFirstFrame},streamId:this._streamId}),this._logger.info("[%s] [%s] Channel creation to first frame [%s]",this.durationSincePageLoad,this._streamId,new ge(this._channelCreationTimeToFirstFrame).toIsoString())}},{key:"onStall",value:function(){this._videoStalled||(this._metricsService.push({metricType:se.Stalled,runtime:(Date.now()-this._pageLoadTime)/1e3,streamId:this._streamId}),this._videoStalled=Date.now(),this._logger.info("[%s] [%s] [buffering] Stream has stalled",this.durationSincePageLoad,this._streamId))}},{key:"onContinuation",value:function(e,t){if(t.buffered){var n=t.buffered.length,i=!("playing"===e.type||n>0)||("progress"===e.type||"timeupdate"===e.type)&&t.buffered.end(n-1)===this._lastProgress;if(this._videoStalled&&!i){"progress"===e.type&&(this._lastProgress=t.buffered.end(n-1));var r=Date.now()-this._videoStalled;this._metricsService.push({metricType:se.Buffering,runtime:(Date.now()-this._pageLoadTime)/1e3,value:{uint64:r},streamId:this._streamId}),this._logger.info("[%s] [%s] [buffering] Stream has recovered from stall after [%s]",this.durationSincePageLoad,this._streamId,new ge(r).toIsoString()),this._videoStalled=null}}}},{key:"onVideoResolutionChanges",value:function(e){this._metricsService.push({metricType:se.ResolutionChanged,runtime:(Date.now()-this._pageLoadTime)/1e3,value:{string:e},previousValue:this._videoResolution?{string:this._videoResolution}:void 0,streamId:this._streamId}),this._videoResolution=e}}]),e}(),ye=function(){function e(t){r()(this,e),u()(this,"_logger",O.getLogger("StreamSetupListener")),u()(this,"metricsService",he.metricsService),u()(this,"_pageLoadTime",void 0),u()(this,"_startTime",void 0),u()(this,"_metricSubmitted",!1),this._startTime=Date.now(),this._pageLoadTime=t}return a()(e,[{key:"success",value:function(e){this.recordStreamMetric(se.SetupCompleted,e)}},{key:"fail",value:function(){this.recordStreamMetric(se.SetupFailed)}},{key:"recordStreamMetric",value:function(e,t){if(!this._metricSubmitted){this._metricSubmitted=!0;var n=Date.now(),i=n-this._startTime,r=new ue(e).getName();this.metricsService.push({metricType:e,runtime:(n-this._pageLoadTime)/1e3,value:{uint64:i},streamId:t}),this._logger.info("[%s] [%s] Stream metric [%s] in [%s]",new ge(n-this._pageLoadTime).toIsoString(),t,r,new ge(i).toIsoString())}}}]),e}(),Ce=function(){function e(){r()(this,e),u()(this,"_disposables",new q),u()(this,"_isSupported",navigator&&navigator.connection),u()(this,"_rtt",new N(void 0)),u()(this,"_effectiveType",new N(void 0)),u()(this,"_downlinkThroughputCapacity",new N(void 0)),this.isSupported&&(this.setupNetworkChangeListeners(),this.updateStatistics())}return a()(e,[{key:"isSupported",get:function(){return this._isSupported}},{key:"rtt",get:function(){return this._rtt}},{key:"effectiveType",get:function(){return this._effectiveType}},{key:"downlinkThroughputCapacity",get:function(){return this._downlinkThroughputCapacity}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"getDownlinkThroughputCapacity",value:function(){return this.isSupported?navigator.connection.downlink||navigator.connection.downlinkMax:-1}},{key:"getEffectiveType",value:function(){return this.isSupported?navigator.connection.effectiveType||navigator.connection.type:"Unknown"}},{key:"getRoundTripTime",value:function(){return navigator.connection.rtt}},{key:"setupNetworkChangeListeners",value:function(){var e=this,t=function(){e.updateStatistics()};navigator.connection.addEventListener("change",t),this._disposables.add(new U((function(){navigator.connection.removeEventListener("change",t)})))}},{key:"updateStatistics",value:function(){this._rtt.value=this.getRoundTripTime(),this._effectiveType.value=this.getEffectiveType(),this._downlinkThroughputCapacity.value=this.getDownlinkThroughputCapacity()}}]),e}(),be=function(){function e(t,n){var i=this;r()(this,e),u()(this,"_logger",O.getLogger("SessionTelemetry")),u()(this,"_metricsService",void 0),u()(this,"_applicationActivityMonitor",he.applicationActivityMonitor),u()(this,"_networkMonitor",new Ce),u()(this,"_pageLoadTime",void 0),u()(this,"_disposables",new q),u()(this,"_lastNetworkStatistics",{}),this._pageLoadTime=t,this._disposables.add(this._networkMonitor),this._metricsService=n,this._networkMonitor.isSupported&&(this._disposables.add(this._applicationActivityMonitor.isForeground.subscribe((function(e){i.recordForegroundChange(e)}))),this._disposables.add(this._networkMonitor.rtt.subscribe((function(e){i.recordNetworkRTTUpdate(e)}))),this._disposables.add(this._networkMonitor.effectiveType.subscribe((function(e){i.recordNetworkTypeChangeUpdate(e)}))),this._disposables.add(this._networkMonitor.downlinkThroughputCapacity.subscribe((function(e){i.recordNetworkDownlinkThroughputCapacityUpdate(e)}))))}return a()(e,[{key:"listenOnStreamSetup",value:function(){return new ye(this._pageLoadTime)}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"recordForegroundChange",value:function(e){var t=Date.now(),n=this._applicationActivityMonitor.getTimeSinceLastChange();this._metricsService.push({metricType:e?se.ApplicationForeground:se.ApplicationBackground,runtime:(t-this._pageLoadTime)/1e3,value:{uint64:n}}),this._logger.info("Application has gone into the [%s] after [%s] ms",e?"foreground":"background",new ge(n).toIsoString())}},{key:"recordNetworkRTTUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.rtt;this._lastNetworkStatistics.rtt=e,this._metricsService.push({metricType:se.RoundTripTime,runtime:(t-this._pageLoadTime)/1e3,value:{uint64:e},previousValue:n?{uint64:n}:void 0,resource:"navigator"}),this._logger.info("[%s] Network RTT changed to [%s] from [%s]",new ge(t-this._pageLoadTime).toIsoString(),e,n)}},{key:"recordNetworkTypeChangeUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.effectiveType;this._lastNetworkStatistics.effectiveType=e,this._metricsService.push({metricType:se.NetworkType,runtime:(t-this._pageLoadTime)/1e3,value:{string:e},previousValue:n?{string:n}:void 0}),this._logger.info("[%s] Network effective type has changed to [%s] from [%s]",new ge(t-this._pageLoadTime).toIsoString(),e,n)}},{key:"recordNetworkDownlinkThroughputCapacityUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.downlinkThroughputCapacity;this._lastNetworkStatistics.downlinkThroughputCapacity=e,this._metricsService.push({metricType:se.DownlinkThroughputCapacity,runtime:(t-this._pageLoadTime)/1e3,value:{float:e},previousValue:n?{float:n}:void 0}),this._logger.info("[%s] Network downlink throughput capacity changed to [%s] from [%s]",new ge(t-this._pageLoadTime).toIsoString(),e,n)}}]),e}(),ke=function(e){return e[e.Keep=0]="Keep",e[e.Reset=1]="Reset",e}({}),xe=function(e){return e[e.Normal=0]="Normal",e[e.Force=1]="Force",e[e.Reset=2]="Reset",e}({}),we=a()((function e(t){r()(this,e),u()(this,"token",void 0),u()(this,"tokenExpiring",void 0),this.token=new N(t),this.tokenExpiring=new N(!1)})),Se=function(){function e(t){var n;r()(this,e),u()(this,"channelInitialization",void 0),u()(this,"disposables",void 0),u()(this,"channelDisposables",void 0),u()(this,"rendererDisposables",void 0),u()(this,"videoElement",void 0),u()(this,"state",void 0),u()(this,"autoMuted",void 0),u()(this,"autoPaused",void 0),u()(this,"authorized",void 0),u()(this,"online",void 0),u()(this,"loading",void 0),u()(this,"playing",void 0),u()(this,"standby",void 0),u()(this,"stopped",void 0),u()(this,"targetLag",void 0),u()(this,"lag",void 0),u()(this,"bitrateLimit",void 0),u()(this,"resolution",void 0),u()(this,"failureCount",void 0),u()(this,"endPoint",void 0),u()(this,"stream",void 0),u()(this,"rtcStatistics",void 0),u()(this,"videoTelemetry",void 0),u()(this,"rtcAudioStatistic",void 0),u()(this,"rtcVideoStatistic",void 0),u()(this,"clearFailureCountTimeout",void 0),u()(this,"videoStreamTransformCallback",void 0),u()(this,"hasInsertableStreams",void 0),this.disposables=new q,this.channelDisposables=new q,this.rendererDisposables=new q,this.channelInitialization=new Date,this.videoElement=new N(null),this.state=new N(me.Starting),this.autoMuted=new N(!1),this.autoPaused=new N(!1),this.authorized=new N(!0),this.online=new N(!0),this.loading=new N(!1),this.playing=new N(!1),this.standby=new N(!1),this.stopped=new N(!1),this.targetLag=new N(null!==(n=null==t?void 0:t.targetLag)&&void 0!==n?n:0),this.lag=new N(0),this.bitrateLimit=new N(0),this.resolution=new N(pe.empty),this.failureCount=new N(0),this.endPoint=new N(null),this.stream=new N(null),this.rtcStatistics=new N(null),this.videoStreamTransformCallback=new N(null==t?void 0:t.videoStreamTransformCallback),this.hasInsertableStreams=new N(!(null==t||!t.hasInsertableStreams))}return a()(e,[{key:"streamId",get:function(){var e=this.stream.value;return e?e.streamId:"-"}},{key:"applyStatus",value:function(e){switch(e){case"ok":break;case"unauthorized":case"geo-restricted":case"geo-blocked":this.authorized.value=!1;case"no-stream":case"not-found":return this.failureCount.value=0,this.playing.value=!1,this.standby.value=!0,this.stopped.value=!1,void(this.stream.value=null);default:return this.failureCount.value++,this.playing.value=!1,this.standby.value=!0,this.stopped.value=!1,this.stream.value=null,void(this.state.value=me.Error)}}},{key:"applySessionAndStreamPropertiesToVideoElement",value:function(){this.videoElement.value&&this.videoElement.value.dataset&&(this.videoElement.value.dataset.sessionId=he.clientSessionId,this.videoElement.value.dataset.streamId=this.streamId)}},{key:"mapSubscribeStatusToChannelStatus",value:function(e){switch(e){case"ok":return me.Starting;case"no-stream":case"not-found":return me.StandBy;case"geo-restricted":return me.GeoRestricted;case"geo-blocked":return me.GeoBlocked;case"unauthorized":return me.Unauthorized;case"capacity":case"rate-limited":case"timeout":return me.Recovering;case"failed":return me.Error;default:L(e)}}}]),e}(),Te=a()((function e(){r()(this,e),u()(this,"mediaStream",void 0),u()(this,"peerConnection",void 0),u()(this,"peerConnectionReconnectAttempts",void 0),this.mediaStream=new N(null),this.peerConnection=new N(null),this.peerConnectionReconnectAttempts=0})),Le=a()((function e(){r()(this,e),u()(this,"isStarting",void 0),u()(this,"isDisposed",void 0),this.isStarting=new N(!1),this.isDisposed=!1})),Re=n(38),Pe=n.n(Re),Ee=n(319),Oe=n.n(Ee),De=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertBitrateModeToBitrateModeType",value:function(e){switch(e){case xe.Normal:return"Normal";case xe.Force:return"Force";case xe.Reset:return"Reset";default:L(e)}}}]),e}(),Fe=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertBitrateStateToBitrateStateType",value:function(e){switch(e){case ke.Keep:return"Keep";case ke.Reset:return"Reset";default:L(e)}}}]),e}(),Ie=n(202).default,Me=function(){function e(t,n){if(r()(this,e),u()(this,"_logger",O.getLogger("EndPoint")),u()(this,"_uri",void 0),u()(this,"_timeout",void 0),u()(this,"_roundTripTime",void 0),this._uri=t,this._timeout=n,!n)throw new Error("End point requires a timeout")}var t,n,i,o,s,c,l,d,h,p,f,v,m;return a()(e,[{key:"roundTripTime",get:function(){return this._roundTripTime}},{key:"toString",value:function(){return"EndPoint[uri=".concat(this._uri,"]")}},{key:"ping",value:(m=g()(y().mark((function e(){var t,n,i,r,o=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.buildPingUrl(),n=Date.now(),e.next=4,Ie.race([fetch(t,{method:"GET",cache:"no-cache"}),new Ie((function(e,n){return setTimeout((function(){return n(new Error("Ping timed out [".concat(t,"]")))}),o._timeout)}))]);case 4:if(i=e.sent,r=Date.now(),i.ok){e.next=8;break}throw new Error("Ping failed [".concat(t,"] [").concat(i.status,"]"));case 8:return this._roundTripTime=r-n,e.abrupt("return",this._roundTripTime);case 10:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"subscribe",value:(v=g()(y().mark((function e(t,n,i){var r,o,a,s,u,c,l,d,h,p,f,v,m=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=H.parseToken(t).tenancy){e.next=4;break}return this._logger.error("Failed to parse token [%s]",t),e.abrupt("return",{status:"unauthorized"});case 4:return o=this.buildUrl([r,"stream","subscribe"]).toString(),a=new FormData,s=C.sdkVersion,0===i&&n?(u={apiVersion:7,clientVersion:s,bearerToken:t,failureCount:i,httpRoundTripTime:this._roundTripTime,setRemoteDescription:{apiVersion:7,sessionDescription:{type:n.type,sdp:n.sdp}},createAnswerDescription:{apiVersion:7}},a.append("jsonBody",JSON.stringify(u))):(c={apiVersion:7,clientVersion:s,bearerToken:t,failureCount:i,httpRoundTripTime:this._roundTripTime,createOfferDescription:{apiVersion:7}},a.append("jsonBody",JSON.stringify(c))),l=Date.now(),e.prev=9,h=null,e.next=13,Ie.race([fetch(o,{method:"POST",body:a}),new Ie((function(e){return h=window.setTimeout((function(){m._logger.error("Failed to subscribe",new Error("Subscribe timed out [".concat(o,"]"))),e({status:408})}),m._timeout)}))]).finally((function(){h&&clearTimeout(h)}));case 13:d=e.sent,e.next=20;break;case 16:return e.prev=16,e.t0=e.catch(9),this._logger.error("Failed to subscribe",e.t0),e.abrupt("return",{status:"failed"});case 20:if("ok"===(p=this.mapHttpStatusToSubscribeStatus(d))){e.next=23;break}return e.abrupt("return",{status:p});case 23:return f=Date.now(),e.next=26,this.convertHttpResponseToSubscribeResponse(r,d);case 26:return v=e.sent,this._logger.debug("Got subscribe response [%j] in [%s] ms",v,f-l),e.abrupt("return",v);case 29:case"end":return e.stop()}}),e,this,[[9,16]])}))),function(e,t,n){return v.apply(this,arguments)})},{key:"publish",value:(f=g()(y().mark((function e(t,n,i,r){var o,a,s,u,c,l,d,h,p,f,v,m,g=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=H.parseToken(n).tenancy){e.next=4;break}return this._logger.error("Failed to parse token [%s]",n),e.abrupt("return",{status:"unauthorized"});case 4:return a=this.buildUrl([o,"stream","publish"]).toString(),s=new FormData,u=C.sdkVersion,0===r&&i?(c={apiVersion:7,clientVersion:u,bearerToken:n,failureCount:r,httpRoundTripTime:this._roundTripTime,name:t,setRemoteDescription:{apiVersion:7,sessionDescription:{type:i.type,sdp:i.sdp}},createAnswerDescription:{streamId:"",options:["upload"],apiVersion:7}},s.append("jsonBody",JSON.stringify(c))):(l={apiVersion:7,clientVersion:u,bearerToken:n,failureCount:r,httpRoundTripTime:this._roundTripTime,name:t,createOfferDescription:{streamId:"",options:["upload"],apiVersion:7}},s.append("jsonBody",JSON.stringify(l))),d=Date.now(),e.prev=9,p=null,e.next=13,Ie.race([fetch(a,{method:"POST",body:s}),new Ie((function(e){return p=window.setTimeout((function(){g._logger.error("Failed to publish",new Error("Publish timed out [".concat(a,"]"))),e({status:408})}),g._timeout)}))]).finally((function(){p&&clearTimeout(p)}));case 13:h=e.sent,e.next=20;break;case 16:return e.prev=16,e.t0=e.catch(9),this._logger.error("Failed to publish",e.t0),e.abrupt("return",{status:"failed"});case 20:if("ok"===(f=this.mapHttpStatusToPublishStatus(h))){e.next=23;break}return e.abrupt("return",{status:f});case 23:return v=Date.now(),e.next=26,this.convertHttpResponseToPublishResponse(o,h);case 26:return m=e.sent,this._logger.debug("Got publish response [%j] in [%s] ms",m,v-d),e.abrupt("return",m);case 29:case"end":return e.stop()}}),e,this,[[9,16]])}))),function(e,t,n,i){return f.apply(this,arguments)})},{key:"setRemoteDescription",value:(p=g()(y().mark((function e(t,n){var i,r,o,a,s,u,c,l,d,h=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this.buildUrl([t.tenancy,"stream",t.streamId,"description","remote"]).toString(),r=new FormData,o={apiVersion:7,sharedSecret:t.sharedSecret,sessionDescription:{type:n.type,sdp:n.sdp}},r.append("jsonBody",JSON.stringify(o)),a=Date.now(),e.prev=5,u=null,e.next=9,Ie.race([fetch(i,{method:"POST",body:r}),new Ie((function(e){return u=window.setTimeout((function(){h._logger.error("Failed to set remote description",new Error("Set remote description timed out [".concat(i,"]"))),e({status:408})}),h._timeout)}))]).finally((function(){u&&clearTimeout(u)}));case 9:s=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to set remote description",e.t0),e.abrupt("return",{status:"failed"});case 16:if("ok"===(c=this.mapHttpStatusToSetRemoteDescriptionStatus(s))){e.next=19;break}return e.abrupt("return",{status:c});case 19:return l=Date.now(),e.next=22,this.convertHttpResponseToSetRemoteDescriptionResponse(s);case 22:return d=e.sent,this._logger.debug("Got set remote description response [%j] in [%s] ms",d,l-a),e.abrupt("return",d);case 25:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t){return p.apply(this,arguments)})},{key:"limitBitrate",value:(h=g()(y().mark((function e(t,n,i,r,o){var a,s,u,c,l,d,h,p,f=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=this.buildUrl([t.tenancy,"stream",t.streamId,"bitrate"]).toString(),s=new FormData,u={apiVersion:7,sharedSecret:t.sharedSecret,elapsedInMilliseconds:n,bitrateInBitsPerSecond:i,bitrateState:Fe.convertBitrateStateToBitrateStateType(r),bitrateMode:De.convertBitrateModeToBitrateModeType(o)},s.append("jsonBody",JSON.stringify(u)),c=Date.now(),e.prev=5,d=null,e.next=9,Ie.race([fetch(a,{method:"POST",body:s}),new Ie((function(e){return d=window.setTimeout((function(){f._logger.error("Failed to set limit bitrate timed",new Error("Set limit bitrate timed out [".concat(a,"]"))),e({status:408})}),f._timeout)}))]).finally((function(){d&&clearTimeout(d)}));case 9:l=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to set limit bitrate timed",e.t0),e.abrupt("return",{status:"failed"});case 16:return h=this.mapHttpStatusToSetTemporaryMaximalBitrateStatus(l),p=Date.now(),this._logger.info("Got set limit bitrate response [%s] in [%s] ms",h,p-c),e.abrupt("return",{status:h});case 20:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t,n,i,r){return h.apply(this,arguments)})},{key:"addIceCandidates",value:(d=g()(y().mark((function e(t,n,i){var r,o,a,s,u,c,l,d,h,p,f=this,v=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=v.length>3&&void 0!==v[3]?v[3]:[],o=this.buildUrl([t.tenancy,"stream",t.streamId,"ice","candidates"]).toString(),a=new FormData,s={apiVersion:7,sharedSecret:t.sharedSecret,candidates:n,discoveryCompleted:i,options:r},a.append("jsonBody",JSON.stringify(s)),u=Date.now(),e.prev=6,l=null,e.next=10,Ie.race([fetch(o,{method:"POST",body:a}),new Ie((function(e){return l=window.setTimeout((function(){f._logger.error("Failed to add ice candidates",new Error("Add ice candidates timed out [".concat(o,"]"))),e({status:408})}),f._timeout)}))]).finally((function(){l&&clearTimeout(l)}));case 10:c=e.sent,e.next=17;break;case 13:return e.prev=13,e.t0=e.catch(6),this._logger.error("Failed to add ice candidates",e.t0),e.abrupt("return",{status:"failed"});case 17:if("ok"===(d=this.mapHttpStatusToAddIceCandidatesStatus(c))){e.next=20;break}return e.abrupt("return",{status:d});case 20:return h=Date.now(),e.next=23,this.convertHttpResponseToAddIceCandidatesResponse(c);case 23:return p=e.sent,this._logger.info("Got add ICE candidates response [%j] in [%s] ms",p,h-u),e.abrupt("return",p);case 26:case"end":return e.stop()}}),e,this,[[6,13]])}))),function(e,t,n){return d.apply(this,arguments)})},{key:"destroyStream",value:(l=g()(y().mark((function e(t,n){var i,r,o,a,s,u,c,l,d,h=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this.buildUrl([t.tenancy,"stream",t.streamId,"destroy"]).toString(),r=new FormData,o={apiVersion:7,sharedSecret:t.sharedSecret,reason:n,options:[]},r.append("jsonBody",JSON.stringify(o)),a=Date.now(),e.prev=5,u=null,e.next=9,Ie.race([fetch(i,{method:"POST",body:r,cache:"no-cache"}),new Ie((function(e){return u=window.setTimeout((function(){h._logger.error("Failed to subscribe",new Error("Delete stream timed out [".concat(i,"]"))),e({status:408})}),h._timeout)}))]).finally((function(){u&&clearTimeout(u)}));case 9:s=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to delete stream",e.t0),e.abrupt("return",{status:"failed"});case 16:if("ok"===(c=this.mapHttpStatusToSetDestroyStreamStatus(s))){e.next=19;break}return e.abrupt("return",{status:c});case 19:return l=Date.now(),e.next=22,this.convertHttpResponseToDestroyStreamResponse(s);case 22:return d=e.sent,this._logger.info("Got destroy stream response [%j] in [%s] ms",d,l-a),e.abrupt("return",d);case 25:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t){return l.apply(this,arguments)})},{key:"destroyStreamOnUnmount",value:(c=g()(y().mark((function e(t,n){var i,r,o,a;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:null!==(i=navigator)&&void 0!==i&&i.sendBeacon||this.destroyStream(t,n),r=this.buildUrl([t.tenancy,"stream",t.streamId,"destroy"]).toString(),o=new FormData,a={apiVersion:7,sharedSecret:t.sharedSecret,reason:n,options:[]},o.append("jsonBody",JSON.stringify(a)),navigator.sendBeacon(r,o);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"buildUrl",value:function(e){var t=new URL(this._uri),n=t.pathname.split("/");return n.length=n.length-1,t.pathname=n.concat.apply(n,Oe()(e)).join("/"),t}},{key:"buildPingUrl",value:function(){var e=new URL(this._uri),t=C.sdkVersion;return e.search="?".concat(new URLSearchParams([["type","http"],["version",t],["_","".concat(Date.now())]]).toString()),e.toString()}},{key:"mapHttpStatusToPublishStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 402:return"geo-restricted";case 403:return"geo-blocked";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSubscribeStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 402:return"geo-restricted";case 403:return"geo-blocked";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetRemoteDescriptionStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetTemporaryMaximalBitrateStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToAddIceCandidatesStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetDestroyStreamStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"convertHttpResponseToSubscribeResponse",value:(s=g()(y().mark((function e(t,n){var i,r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.json();case 2:return i=e.sent,(r={status:i.status}).stream={tenancy:t,streamId:i.streamId,sharedSecret:i.sharedSecret},r.lag=i.lag,i&&(i.rtcConfiguration&&(r.rtcConfiguration=this.convertIRtcConfigurationToRTCConfiguration(i.rtcConfiguration)),i.setRemoteDescriptionResponse&&i.setRemoteDescriptionResponse.sessionDescription&&(r.setRemoteDescriptionResponse={sessionDescription:i.setRemoteDescriptionResponse.sessionDescription}),i.createAnswerDescriptionResponse&&i.createAnswerDescriptionResponse.sessionDescription&&(r.createAnswerDescriptionResponse={sessionDescription:i.createAnswerDescriptionResponse.sessionDescription}),i.createOfferDescriptionResponse&&i.createOfferDescriptionResponse.sessionDescription&&(r.createOfferDescriptionResponse={sessionDescription:i.createOfferDescriptionResponse.sessionDescription})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"convertHttpResponseToPublishResponse",value:(o=g()(y().mark((function e(t,n){var i,r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.json();case 2:return i=e.sent,(r={status:i.status}).stream={tenancy:t,streamId:i.streamId,sharedSecret:i.sharedSecret},i&&(i.rtcConfiguration&&(r.rtcConfiguration=this.convertIRtcConfigurationToRTCConfiguration(i.rtcConfiguration)),i.setRemoteDescriptionResponse&&i.setRemoteDescriptionResponse.sessionDescription&&(r.setRemoteDescriptionResponse={sessionDescription:i.setRemoteDescriptionResponse.sessionDescription}),i.createAnswerDescriptionResponse&&i.createAnswerDescriptionResponse.sessionDescription&&(r.createAnswerDescriptionResponse={sessionDescription:i.createAnswerDescriptionResponse.sessionDescription}),i.createOfferDescriptionResponse&&i.createOfferDescriptionResponse.sessionDescription&&(r.createOfferDescriptionResponse={sessionDescription:i.createOfferDescriptionResponse.sessionDescription})),e.abrupt("return",r);case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"convertIRtcConfigurationToRTCConfiguration",value:function(e){var t={iceServers:[]};if(e.bundlePolicy&&(t.bundlePolicy=e.bundlePolicy),"number"==typeof e.iceCandidatePoolSize&&(t.iceCandidatePoolSize=e.iceCandidatePoolSize),e.iceServers){for(var n=[],i=0;i<e.iceServers.length;i++)n.push({urls:e.iceServers[i].urls,username:e.iceServers[i].username,credential:e.iceServers[i].credential});t.iceServers=n}return e.iceTransportPolicy&&(t.iceTransportPolicy=e.iceTransportPolicy),e.rtcpMuxPolicy&&(t.rtcpMuxPolicy=e.rtcpMuxPolicy),t}},{key:"convertHttpResponseToSetRemoteDescriptionResponse",value:(i=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status},n&&n.sessionDescription&&(i.sessionDescription=n.sessionDescription),e.abrupt("return",i);case 6:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"convertHttpResponseToAddIceCandidatesResponse",value:(n=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status,options:[]},n&&n.options&&(i.options=n.options),e.abrupt("return",i);case 6:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"convertHttpResponseToDestroyStreamResponse",value:(t=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status},e.abrupt("return",i);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}(),Ae=n(202).default,je=function(){function e(t){if(r()(this,e),u()(this,"_logger",O.getLogger("Discovery")),u()(this,"_metricsService",void 0),u()(this,"_uri",void 0),!t)throw new Error("Discovery requires uri");this._metricsService=le.getMetricsService(t.toString()),this._uri=t}var t,n;return a()(e,[{key:"discoverNearbyEndPoints",value:(n=g()(y().mark((function e(t,n){var i,r,o,a;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n){e.next=2;break}throw new Error("Discovery requires timeout");case 2:return i=t.toString(),e.next=5,Ae.race([fetch(i,{method:"GET",cache:"no-cache"}),new Ae((function(e,t){return setTimeout((function(){return t(new Error("Discovery timed out [".concat(i,"]")))}),n)}))]);case 5:if((r=e.sent).ok){e.next=8;break}throw new Error("Discovery failed [".concat(i,"] [").concat(r.status,"]"));case 8:if(null!==r.body){e.next=10;break}throw new Error("Discovery failed with no data [".concat(i,"]"));case 10:return e.next=12,r.text();case 12:return o=e.sent,a=o.split(","),e.abrupt("return",a.map((function(e){return new Me(e,n)})));case 15:case"end":return e.stop()}}),e)}))),function(e,t){return n.apply(this,arguments)})},{key:"discoverClosestEndPoint",value:(t=g()(y().mark((function e(){var t,n,i,r,o,a,s=this,u=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:2e4,n=oe.buildDiscoveryUrl(this._uri),e.next=4,this.discoverNearbyEndPoints(new URL(n),t);case 4:return i=e.sent,r=0,o=function(){return new Ae((function(e,t){r>=i.length&&t("Discovery of [".concat(i.length,"] endpoints from [").concat(n,"] failed, preventing it from completing"))}))},e.next=9,Ae.race(i.map((function(e){return e.ping().catch((function(t){return s._logger.warn("Failed to ping end point [%s]",e,t),r++,o()})).then((function(t){var n=Date.now();return s._logger.info("Discovered end point [%s] with time [%s]",e.toString(),t),s._metricsService.push({metricType:se.RoundTripTime,runtime:(n-he.pageLoadTime)/1e3,value:{uint64:t||0},resource:e.toString(),kind:"ping"}),e}))})));case 9:return a=e.sent,e.abrupt("return",a);case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),Ve=function(){function e(){throw r()(this,e),new Error("Discovery is a static class that may not be instantiated")}var t,n;return a()(e,null,[{key:"precacheClosestEndPointDiscovery",value:(n=g()(y().mark((function t(){var n;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=new URL(he.discoveryUri.value),t.abrupt("return",e.discoverClosestEndPointWithCaching(n));case 2:case"end":return t.stop()}}),t)}))),function(){return n.apply(this,arguments)})},{key:"discoverClosestEndPointWithCaching",value:(t=g()(y().mark((function t(n){var i,r,o;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=n.toString(),!e._cache[i]){t.next=3;break}return t.abrupt("return",e._cache[i]);case 3:return r=new je(n),o=e._cache[i]=r.discoverClosestEndPoint(),e._cache[i].then((function(){setTimeout((function(){e._cache[i]===o&&delete e._cache[i]}),6e4)})).catch((function(){delete e._cache[i]})),t.abrupt("return",o);case 7:case"end":return t.stop()}}),t)}))),function(e){return t.apply(this,arguments)})}]),e}();u()(Ve,"_cache",{}),Ve.precacheClosestEndPointDiscovery();var Ue=function(){function e(t){r()(this,e),u()(this,"_sdp",void 0),u()(this,"_audioCodec",void 0),u()(this,"_videoCodec",void 0),u()(this,"_isAudioTrackEnabled",void 0),u()(this,"_isVideoTrackEnabled",void 0),this._sdp=t;var n=this._sdp.split(/(\r\n|\r|\n)/),i=this._sdp.split("m=");this._audioCodec=this.applyCodec("audio",n),this._videoCodec=this.applyCodec("video",n),this._isAudioTrackEnabled=this.isTrackByTypeEnabled("audio",i),this._isVideoTrackEnabled=this.isTrackByTypeEnabled("video",i)}return a()(e,[{key:"audioCodec",get:function(){return this._audioCodec}},{key:"videoCodec",get:function(){return this._videoCodec}},{key:"isAudioTrackEnabled",get:function(){return this._isAudioTrackEnabled}},{key:"isVideoTrackEnabled",get:function(){return this._isVideoTrackEnabled}},{key:"isTrackByTypeEnabled",value:function(e,t){var n=t.find((function(t){return t.startsWith(e)}));return!!n&&!n.includes("a=inactive")}},{key:"applyCodec",value:function(e,t){return t.find((function(n){return n.includes("a=rtpmap:".concat(t.find((function(t){return t.includes("m=".concat(e))})).split(" ")[3]))})).split(" ")[1].split("/")[0]}}]),e}(),Be=function(){function e(t,n,i){if(r()(this,e),u()(this,"_estimatedRoundTripTime",void 0),u()(this,"_estimatedVideoCodec",void 0),u()(this,"_estimatedAudioCodec",void 0),u()(this,"_rtcStatistic",new N({})),u()(this,"_peerConnection",void 0),u()(this,"_isMonitorRunning",!0),u()(this,"_updateTimeout",void 0),u()(this,"_tracksToMonitor",void 0),this._peerConnection=t,this._estimatedRoundTripTime=i,this._tracksToMonitor=n.getTracks().map((function(e){return e.kind}))||[],this._peerConnection){if(!Y.getCurrentOfferDisabled){var o=new Ue(this._peerConnection.currentRemoteDescription.sdp);this._estimatedAudioCodec=o.audioCodec,this._estimatedVideoCodec=o.videoCodec}this.updateStatistic()}}var t,n;return a()(e,[{key:"rtcStatistic",get:function(){return this._rtcStatistic}},{key:"dispose",value:function(){this._isMonitorRunning=!1,this._peerConnection=null,this._updateTimeout&&(clearTimeout(this._updateTimeout),this._updateTimeout=null)}},{key:"updateStatistic",value:(n=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.getStatsPromiseBasedDisabled){e.next=5;break}return e.next=3,this.updateStatisticLegacy();case 3:return e.sent,e.abrupt("return");case 5:return t=function(e){return e.id.includes("Audio")?"audio":e.id.includes("Video")?"video":""},e.next=8,this._peerConnection.getStats(null).then((function(e){var i={};if(e){var r,o=n._estimatedRoundTripTime;e.forEach((function(a){if("candidate-pair"===a.type&&a.currentRoundTripTime&&(o=1e3*a.currentRoundTripTime,i.audio&&(i.audio.roundTripTime=o),i.video&&(i.video.roundTripTime=o)),"candidate-pair"===a.type&&a.lastPacketReceivedTimestamp&&(r=a.lastPacketReceivedTimestamp,i.audio&&(i.audio.lastPacketReceivedTimestamp=r),i.video&&(i.video.lastPacketReceivedTimestamp=r)),"inbound-rtp"===a.type){var s=a.kind||a.mediaType||t(a),u="";if(e.forEach((function(e){e.id===a.codecId&&(u=e.mimeType)})),s&&n._tracksToMonitor.includes(s)){var c,l,d,h,p,f=(a.bytesReceived||0)-(null!==(c=null===(l=n._rtcStatistic.value)||void 0===l||null===(d=l[s])||void 0===d?void 0:d.bytesReceived)&&void 0!==c?c:0),v=a.timestamp-(null===(h=n._rtcStatistic.value)||void 0===h||null===(p=h[s])||void 0===p?void 0:p.timestamp),m=f&&v?Math.floor(8*f/v*1e3):0;if(i[s]={ssrc:a.ssrc,mediaType:s,timestamp:a.timestamp,bitrate:m,bytesReceived:a.bytesReceived,packetsLost:a.packetsLost,packetsReceived:a.packetsReceived,codec:u||n.getCodecByType(s),roundTripTime:o},(a.lastPacketReceivedTimestamp||r)&&(i[s].lastPacketReceivedTimestamp=a.lastPacketReceivedTimestamp||r),"video"===s&&n._rtcStatistic.value&&n._rtcStatistic.value.video){i[s].framesDecoded=a.framesDecoded;var g=(a.framesDecoded-n._rtcStatistic.value.video.framesDecoded)/(i[s].timestamp-n._rtcStatistic.value.video.timestamp)*1e3;i[s].fps=g?Math.round(100*g)/100:0}}}}))}n._rtcStatistic.value=i})).then((function(){n._isMonitorRunning&&(n._updateTimeout=window.setTimeout((function(){return n.updateStatistic()}),1e3))}));case 8:e.sent;case 9:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateStatisticLegacy",value:(t=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._peerConnection.getStatsLegacy().then((function(e){var n={},i=t._estimatedRoundTripTime;e.result().forEach((function(e){if(e.names().forEach((function(t){"googRTT"===t&&(i=e.stat(t))})),"ssrc"===e.type){var r=e.stat("mediaType").toString();n[r]={timestamp:Date.now()},n[r].ssrc=e.stat("ssrc").toString(),n[r].mediaType=r,n[r].bytesReceived=e.stat("bytesReceived"),n[r].packetsLost=e.stat("packetsLost"),n[r].packetsReceived=e.stat("packetsReceived"),n[r].codec=e.stat("googCodecName").toString()||t.getCodecByType(r),n[r].roundTripTime=i,"video"===r&&t._rtcStatistic.value&&t._rtcStatistic.value.video&&(n[r].framesDecoded=e.stat("framesDecoded"),n[r].fps=(n[r].framesDecoded-t._rtcStatistic.value.video.framesDecoded)/(n[r].timestamp-t._rtcStatistic.value.video.timestamp)*1e3||0)}})),t._rtcStatistic.value=n})).then((function(){t._isMonitorRunning&&(t._updateTimeout=window.setTimeout((function(){return t.updateStatistic()}),1e3))}));case 2:e.sent;case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getCodecByType",value:function(e){switch(e){case"audio":return this._estimatedAudioCodec;case"video":return this._estimatedVideoCodec;default:return"unknown"}}}]),e}(),Ne=function(){function e(){throw r()(this,e),new Error("RtcConfigurationManager is a static class that may not be instantiated")}return a()(e,null,[{key:"truncateIceServers",value:function(e){for(var t=[],n=0;n<e.iceServers.length;n++){for(var i=[],r=0;r<2;r++)e.iceServers[n].urls[r]&&i.push(e.iceServers[n].urls[r]);t.push({urls:i,username:e.iceServers[n].username,credential:e.iceServers[n].credential})}return e.iceServers=t,e}}]),e}(),ze=function(){function e(){throw r()(this,e),new Error("InsertableStreams is a static class that may not be instantiated")}return a()(e,null,[{key:"setupMediaStreamTrackTransform",value:function(e,t){var n=t.getVideoTracks()[0];if(n){var i=new TransformStream({transform:e}),r=new MediaStreamTrackProcessor({track:n}),o=new MediaStreamTrackGenerator({kind:"video"}),a=r.readable,s=o.writable;a.pipeThrough(i).pipeTo(s);var u=new MediaStream;return u.addTrack(o),t.getAudioTracks().forEach((function(e){u.addTrack(e)})),u}return t}}]),e}(),Ge=n(202).default;function He(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function We(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?He(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):He(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var Je=function(){function e(t,n,i){r()(this,e),u()(this,"_logger",O.getLogger("RealTimeStream")),u()(this,"_channelContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_handleStreamFailure",void 0),this._channelContext=t,this._peerConnectionContext=n,this._handleStreamFailure=i}var t;return a()(e,[{key:"start",value:function(e,t,n,i){var r=this;return Ge.all([Ve.discoverClosestEndPointWithCaching(e),ne.createPeerConnectionOffer()]).then((function(e){var n=Pe()(e,2),i=n[0],o=n[1],a=o.localOffer,s=o.peerConnection;return r._channelContext.online.value=!0,r._channelContext.endPoint.value=i,r._logger.info("Connecting to [%s]",i.toString()),r._logger.info("Local offer:\n"+a.sdp),!Y.clientOfferDisabled&&s.supportsSetConfiguration&&s.supportsGetConfiguration||(s.close(),s=null,a=null),r._peerConnectionContext.peerConnection.value=s,i.subscribe(t,a,r._channelContext.failureCount.value)})).then((function(e){var t=e.status,o=e.stream,a=e.rtcConfiguration,s=e.setRemoteDescriptionResponse,u=e.createOfferDescriptionResponse,c=e.createAnswerDescriptionResponse,l=e.lag;if(r._channelContext.stream.value=o,r._channelContext.lag.value=l,r._channelContext.applySessionAndStreamPropertiesToVideoElement(),r._logger.debug("[%s] Subscribe completed [%s] [%j] [%j] [%j] [%j]",r._channelContext.streamId,t,a,s,u,c),r._channelContext.state.value=r._channelContext.mapSubscribeStatusToChannelStatus(t),r._channelContext.applyStatus(t),"ok"===t)return r.applyRtcConfiguration(r._peerConnectionContext.peerConnection.value,a).then((function(e){var t,a=!1,l=!1,d=[];r._peerConnectionContext.peerConnection.value||(r._peerConnectionContext.peerConnection.value=e),e.onicecandidate=function(n){r._channelContext.stream.value===o&&r._peerConnectionContext.peerConnection.value===e&&(a||he.sendLocalCandidates.value&&(n.candidate&&n.candidate.candidate?d.push(n.candidate):l=!0,t||(t=setTimeout((function(){r._channelContext.stream.value!==o||a||r._channelContext.endPoint.value.addIceCandidates(o,d,l).then((function(e){var t=e.status,n=e.options;"ok"===t?(n.includes("cancel")&&(a=!0),r._logger.info("[%s] Added ICE candidates with reason [%s] and options [%s]",r._channelContext.streamId,t,n)):r._logger.warn("[%s] Failed to add ICE candidates with reason [%s]",r._channelContext.streamId,t)})).catch((function(e){r._logger.error("[%s] Failed to add ICE candidates",r._channelContext.streamId,e)}))}),100))))},e.oniceconnectionstatechange=function(){if(r._channelContext.stream.value===o&&r._peerConnectionContext.peerConnection.value===e){var t=function(){r._channelContext.state.value=me.Error,r._channelContext.videoElement.value&&(r._channelContext.videoElement.value.pause(),r._channelContext.videoElement.value.srcObject=null),r._channelContext.playing.value=!1,r._channelContext.loading.value=!0,r._handleStreamFailure().catch((function(t){r._logger.error("[%s] Failed handling stream failure after peer connection stopped with state [%s]",r._channelContext.streamId,e.iceConnectionState,t)}))};switch(e.iceConnectionState){case"checking":case"completed":case"connected":case"new":return;case"disconnected":case"failed":return void(navigator.onLine&&(r._logger.info("[%s] ICE connection state changed to [%s], trying to reconnect",r._channelContext.streamId,e.iceConnectionState),r.reconnectPeerConnection(e,t)));case"closed":return r._logger.info("[%s] ICE connection state changed to [%s], retrying to connect",r._channelContext.streamId,e.iceConnectionState),void t();default:L(e.iceConnectionState)}}};var h=new Ge((function(t,n){if(Y.onTrackDisabled){var i=function n(i){clearTimeout(o),e.removeEventListener("track",n),e.removeEventListener("addstream",n),i.streams?t(i.streams[0]):t(i.stream)},o=setTimeout((function(){e.removeEventListener("track",i),e.removeEventListener("addstream",i),n(new Error("Stream setup timed out"))}),3e4);e.addEventListener("track",i),e.addEventListener("addstream",i)}else{var a=setTimeout((function(){return n(new Error("Stream setup timed out"))}),3e4);e.ontrack=function(e){var n=e.streams[0];r._channelContext.videoStreamTransformCallback.value&&(n=ze.setupMediaStreamTrackTransform(r._channelContext.videoStreamTransformCallback.value,n)),clearTimeout(a),t(n)}}}));return new Ge((function(e){e()})).then((function(){if(s)return r._logger.info("[%s] Set local SDP offer [%s]",r._channelContext.streamId,s.sessionDescription.sdp),e.setLocalDescription(s.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set local description [%j] with message [%s]",r._channelContext.streamId,s.sessionDescription,e.message),e}))})).then((function(){if(c)return r._logger.info("[%s] Set remote SDP answer [%s]",r._channelContext.streamId,c.sessionDescription.sdp),e.setRemoteDescription(c.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set remote description [%j] with message [%s]",r._channelContext.streamId,c.sessionDescription,e.message),e}))})).then((function(){if(u)return r._logger.info("[%s] Set remote SDP offer [%s]",r._channelContext.streamId,u.sessionDescription.sdp),e.setRemoteDescription(u.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set remote description [%j] with message [%s]",r._channelContext.streamId,u.sessionDescription,e.message),e})).then((function(){return e.createAnswer({offerToReceiveAudio:!0,offerToReceiveVideo:!0})})).then((function(e){return r._logger.info("[%s] Set local SDP answer [%j]",r._channelContext.streamId,e),r._channelContext.endPoint.value.setRemoteDescription(o,e)})).then((function(t){var n=t.status,i=t.sessionDescription;return r._channelContext.state.value=r.mapSetRemoteDescriptionStatusToChannelStatus(n),"ok"!==n?(r._channelContext.playing.value=!1,r._channelContext.standby.value=!0,void(r._channelContext.stopped.value=!1)):e.setLocalDescription(i).catch((function(e){throw r._logger.info("[%s] Failed to set local description [%j] with message [%s]",r._channelContext.streamId,i,e.message),e}))}))})).then((function(){return n.success(r._channelContext.streamId),h})).then((function(t){r._peerConnectionContext.mediaStream.value=t;var n=new Be(e,t,r._channelContext.endPoint.value.roundTripTime/4);return r._channelContext.disposables.add(n),n.rtcStatistic.subscribe((function(t){if(r._channelContext.rtcStatistics.value=t,!r._channelContext.rtcVideoStatistic&&!r._channelContext.rtcAudioStatistic)return r._channelContext.rtcAudioStatistic=t.audio,void(r._channelContext.rtcVideoStatistic=t.video);var i=!1,o=!1;t.audio&&r._channelContext.rtcAudioStatistic&&r._channelContext.rtcAudioStatistic.timestamp!==t.audio.timestamp&&((i=r._channelContext.rtcAudioStatistic&&r._channelContext.rtcAudioStatistic.bytesReceived===t.audio.bytesReceived)&&navigator.onLine&&r._logger.info("[%s] Audio track failed with last bytesReceived [%s] is equal to previous bytesReceived [%s] within [%s]",r._channelContext.streamId,t.audio.bytesReceived,r._channelContext.rtcAudioStatistic.bytesReceived,new ge(t.audio.timestamp-r._channelContext.rtcAudioStatistic.timestamp).toIsoString()),r._channelContext.rtcAudioStatistic=t.audio),t.video&&r._channelContext.rtcVideoStatistic&&r._channelContext.rtcVideoStatistic.timestamp!==t.video.timestamp&&((o=r._channelContext.rtcVideoStatistic&&r._channelContext.rtcVideoStatistic.bytesReceived===t.video.bytesReceived)&&navigator.onLine&&r._logger.info("[%s] Video track failed with last bytesReceived [%s] is equal to previous bytesReceived [%s] within [%s]",r._channelContext.streamId,t.video.bytesReceived,r._channelContext.rtcVideoStatistic.bytesReceived,new ge(t.video.timestamp-r._channelContext.rtcVideoStatistic.timestamp).toIsoString()),r._channelContext.rtcVideoStatistic=t.video),(o||i)&&navigator.onLine?r.reconnectPeerConnection(e,(function(){r._channelContext.state.value=me.Error,r._channelContext.videoElement.value&&(r._channelContext.videoElement.value.pause(),r._channelContext.videoElement.value.srcObject=null),r._channelContext.playing.value=!1,r._channelContext.loading.value=!0,n.dispose(),r._handleStreamFailure().catch((function(t){r._logger.error("[%s] Failed handling stream failure after track stopped with state [%s]",r._channelContext.streamId,e.iceConnectionState,t)}))})):r._peerConnectionContext.peerConnectionReconnectAttempts=0})),he.automaticallyPlayMediaStream?i(t):(r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,void(r._channelContext.state.value=me.Paused))}))}))}))}},{key:"applyRtcConfiguration",value:(t=g()(y().mark((function e(t,n){var i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=3;break}return n=Ne.truncateIceServers(n),e.abrupt("return",he.peerConnectionFactory.value.createPeerConnection(n));case 3:return i=We(We({},t.getConfiguration()),n),t.setConfiguration(i),e.abrupt("return",t);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"reconnectPeerConnection",value:function(e,t){var n=this;if("closed"!==e.iceConnectionState)if(this._channelContext.state.value=me.Reconnecting,this._peerConnectionContext.peerConnectionReconnectAttempts<he.maximalNumberOfPeerConnectionReconnectAttempts||!he.automaticallyReconnectPeerConnection){var i;this._peerConnectionContext.peerConnectionReconnectAttempts++;var r="offer"===(null===(i=e.currentLocalDescription)||void 0===i?void 0:i.type);if(Y.clientOfferDisabled||!e.supportsSetConfiguration||!e.supportsGetConfiguration||!r)return;this._logger.info("Reconnecting peer connection by restarting ICE");var o=e.currentLocalDescription;e.createOffer({iceRestart:!0}).then((function(t){return e.setLocalDescription(t).then((function(){return e.setLocalDescription(o)}))})).catch((function(e){n._logger.error("Failed to reconnect peer connection",e),n._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}))}else this._logger.info("Failed to reconnect peer connection after [%s] attempts, performing full recovery",this._peerConnectionContext.peerConnectionReconnectAttempts),this._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}},{key:"mapSetRemoteDescriptionStatusToChannelStatus",value:function(e){switch(e){case"ok":return me.Starting;case"unauthorized":return me.Unauthorized;case"not-found":case"capacity":case"rate-limited":case"timeout":return me.Recovering;case"failed":return me.Error;default:L(e)}}}]),e}(),Ke=function(){function e(){throw r()(this,e),new Error("RealTimeStreamFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"create",value:function(e,t,n,i){var r=H.parseToken(e).capabilities;return r.includes("rtmp")?(this._logger.error("SDK does not support RTMP playback."),void(t.state.value=me.UnsupportedFeature)):r.includes("streaming")?(this._logger.error("This build does not support Live Stream playback."),void(t.state.value=me.UnsupportedFeature)):new Je(t,n,i)}}]),e}();u()(Ke,"_logger",O.getLogger("Streaming"));var qe=n(202).default,Qe=function(){function e(t,n,i){var o=this;r()(this,e),u()(this,"_logger",O.getLogger("Channel")),u()(this,"_tokenContext",void 0),u()(this,"_channelContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_stateContext",void 0),u()(this,"_exponentialBackoff",void 0),u()(this,"_channelStartTime",void 0),u()(this,"_readOnlyVideoElement",void 0),u()(this,"_readOnlyToken",void 0),u()(this,"_readOnlyPeerConnection",void 0),u()(this,"_readOnlyState",void 0),u()(this,"_readOnlyAutoMuted",void 0),u()(this,"_readOnlyAutoPaused",void 0),u()(this,"_readOnlyTokenExpiring",void 0),u()(this,"_readOnlyAuthorized",void 0),u()(this,"_readOnlyOnline",void 0),u()(this,"_readOnlyLoading",void 0),u()(this,"_readOnlyPlaying",void 0),u()(this,"_readOnlyStandby",void 0),u()(this,"_readOnlyStopped",void 0),u()(this,"_readOnlyTargetLag",void 0),u()(this,"_readOnlyLag",void 0),u()(this,"_readOnlyBitrateLimit",void 0),u()(this,"_readOnlyResolution",void 0),u()(this,"_readOnlyFailureCount",void 0),u()(this,"_readOnlyEndPoint",void 0),u()(this,"_readOnlyStream",void 0),u()(this,"_readOnlyRtcStatistics",void 0),u()(this,"_readOnlyMediaStream",void 0),u()(this,"_metricsService",void 0),u()(this,"_sessionTelemetry",void 0),u()(this,"_videoMetaDataChangedHandler",void 0);var a=H.parseToken(n),s={targetLag:null==i?void 0:i.targetLag,videoStreamTransformCallback:null==i?void 0:i.videoStreamTransformCallback,hasInsertableStreams:a.capabilities.includes("insertable-streams")};this._tokenContext=new we(n),this._channelContext=new Se(s),this._peerConnectionContext=new Te,this._stateContext=new Le,this._exponentialBackoff=new fe,this._channelStartTime=Date.now(),this._readOnlyVideoElement=new z(this._channelContext.videoElement),this._readOnlyToken=new z(this._tokenContext.token),this._readOnlyPeerConnection=new z(this._peerConnectionContext.peerConnection),this._readOnlyState=new z(this._channelContext.state),this._readOnlyAutoMuted=new z(this._channelContext.autoMuted),this._readOnlyAutoPaused=new z(this._channelContext.autoPaused),this._readOnlyTokenExpiring=new z(this._tokenContext.tokenExpiring),this._readOnlyAuthorized=new z(this._channelContext.authorized),this._readOnlyOnline=new z(this._channelContext.online),this._readOnlyLoading=new z(this._channelContext.loading),this._readOnlyPlaying=new z(this._channelContext.playing),this._readOnlyStandby=new z(this._channelContext.standby),this._readOnlyStopped=new z(this._channelContext.stopped),this._readOnlyTargetLag=new z(this._channelContext.targetLag),this._readOnlyLag=new z(this._channelContext.lag),this._readOnlyBitrateLimit=new z(this._channelContext.bitrateLimit),this._readOnlyResolution=new z(this._channelContext.resolution),this._readOnlyFailureCount=new z(this._channelContext.failureCount),this._readOnlyEndPoint=new z(this._channelContext.endPoint),this._readOnlyStream=new z(this._channelContext.stream),this._readOnlyRtcStatistics=new z(this._channelContext.rtcStatistics),this._readOnlyMediaStream=new z(this._peerConnectionContext.mediaStream);var c=(a.uri||he.discoveryUri.value).toString();he.tenancy.value=a.tenancy||he.tenancy.value,oe.uri.value=c,this._metricsService=le.getMetricsService(c),this._sessionTelemetry=new be(he.pageLoadTime,this._metricsService),this._channelContext.channelDisposables.add(this._sessionTelemetry),this._videoMetaDataChangedHandler=this.handleVideoMetaDataChanged.bind(this),this.videoElement=t,this._channelContext.channelDisposables.add(this._channelContext.videoElement.subscribe((function(e){o._channelContext.rendererDisposables.dispose(),e&&(o._channelContext.rendererDisposables.add(o._channelContext.stream.subscribe((function(e){o._channelContext.videoTelemetry&&o._channelContext.videoTelemetry.dispose(),e&&o.videoElement&&(o.videoElement.dataset&&(o.videoElement.dataset.sessionId=he.clientSessionId,o.videoElement.dataset.streamId=o.streamId),o._channelContext.videoTelemetry=new _e(o.streamId,he.pageLoadTime,o._channelStartTime,o._metricsService),o._channelContext.videoTelemetry.setupListenerForTimeToFirstTime(o.videoElement),o._channelContext.videoTelemetry.setupListenerForRebuffering(o.videoElement),o._channelContext.state.value===me.Stopped)&&o.restartAfterStop()}))),o._channelContext.channelDisposables.add(o._channelContext.rendererDisposables))}))),this._channelContext.channelDisposables.add(this._channelContext.state.subscribe((function(e){o._channelContext.clearFailureCountTimeout&&clearTimeout(o._channelContext.clearFailureCountTimeout),o._channelContext.failureCount.value&&e===me.Playing&&(o._channelContext.clearFailureCountTimeout=window.setTimeout((function(){o._channelContext.failureCount.value=0}),3e3))}))),this._channelContext.channelDisposables.add(this._channelContext.resolution.subscribe((function(e){o._channelContext.videoTelemetry&&o._channelContext.videoTelemetry.onVideoResolutionChanges(e.toString())}))),this._channelContext.channelDisposables.add(this._channelContext.bitrateLimit.subscribe((function(e){if(e&&o._channelContext.endPoint.value&&o._channelContext.stream.value){var t=Date.now()-o._channelContext.channelInitialization.getTime();o._channelContext.endPoint.value.limitBitrate(o._channelContext.stream.value,t,e,ke.Keep,xe.Normal).catch((function(e){o._logger.error("Error while setting limit bitrate",e)}))}})));var l=function(){o._channelContext.stream.value&&o._channelContext.endPoint.value&&o._channelContext.endPoint.value.destroyStreamOnUnmount(o._channelContext.stream.value,"client:termination-on-window-unload")};window.addEventListener("beforeunload",l),this._channelContext.channelDisposables.add(new U((function(){window.removeEventListener("beforeunload",l)}))),this.start()}var t,n,i,o,s,c,l,d,h;return a()(e,[{key:"videoElement",get:function(){return this._channelContext.videoElement.value},set:function(e){this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.removeEventListener("loadeddata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.removeEventListener("loadedmetadata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.removeEventListener("resize",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.dataset&&(this._channelContext.videoElement.value.dataset.sessionId="",this._channelContext.videoElement.value.dataset.streamId=""),this._channelContext.rendererDisposables.dispose(),this._channelContext.videoElement.value.pause(),this._channelContext.videoElement.value.srcObject=null),this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!1,this._channelContext.state.value=me.Stopped,this._channelContext.videoElement.value=e,this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.addEventListener("loadeddata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.addEventListener("loadedmetadata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.addEventListener("resize",this._videoMetaDataChangedHandler))}},{key:"handleVideoMetaDataChanged",value:function(){var e=this._channelContext.videoElement.value;e?this.resolution.value.width===e.videoWidth&&this.resolution.value.height===e.videoHeight||(this._channelContext.resolution.value=new pe(e.videoWidth,e.videoHeight)):this._channelContext.resolution.value=pe.empty}},{key:"token",get:function(){return this._tokenContext.token.value},set:function(e){this._channelContext.disposables.dispose(),this._tokenContext.token.value=e,this._tokenContext.tokenExpiring.value=!1;var t=H.parseToken(this._tokenContext.token.value),n=(t.uri||he.discoveryUri.value).toString();he.tenancy.value=t.tenancy||he.tenancy.value,oe.uri.value=n,this._metricsService=le.getMetricsService(n),this._channelContext.hasInsertableStreams.value=t.capabilities.includes("insertable-streams"),this.start()}},{key:"peerConnection",get:function(){return this._readOnlyPeerConnection}},{key:"state",get:function(){return this._readOnlyState}},{key:"autoMuted",get:function(){return this._readOnlyAutoMuted}},{key:"autoPaused",get:function(){return this._readOnlyAutoPaused}},{key:"tokenExpiring",get:function(){return this._readOnlyTokenExpiring}},{key:"authorized",get:function(){return this._readOnlyAuthorized}},{key:"online",get:function(){return this._readOnlyOnline}},{key:"loading",get:function(){return this._readOnlyLoading}},{key:"playing",get:function(){return this._readOnlyPlaying}},{key:"standby",get:function(){return this._readOnlyStandby}},{key:"stopped",get:function(){return this._readOnlyStopped}},{key:"targetLag",get:function(){return this._readOnlyTargetLag}},{key:"lag",get:function(){return this._readOnlyLag}},{key:"bitrateLimit",get:function(){return this._readOnlyBitrateLimit.value}},{key:"resolution",get:function(){return this._readOnlyResolution}},{key:"failureCount",get:function(){return this._readOnlyFailureCount}},{key:"endPoint",get:function(){return this._readOnlyEndPoint}},{key:"stream",get:function(){return this._readOnlyStream}},{key:"streamId",get:function(){return this._channelContext.streamId}},{key:"rtcStatistics",get:function(){return this._readOnlyRtcStatistics}},{key:"mediaStream",get:function(){return this._readOnlyMediaStream}},{key:"setBitrateLimit",value:function(e){this._channelContext.bitrateLimit.value=e}},{key:"clearBitrateLimit",value:function(){var e=this;if(this._channelContext.bitrateLimit.value&&this._channelContext.endPoint.value&&this._channelContext.stream.value){var t=Date.now()-this._channelContext.channelInitialization.getTime();this._channelContext.endPoint.value.limitBitrate(this._channelContext.stream.value,t,0,ke.Keep,xe.Reset).then((function(t){"ok"===t.status&&(e._channelContext.bitrateLimit.value=0)})).catch((function(t){e._logger.error("Error while setting limit bitrate",t)}))}}},{key:"updateTargetLag",value:function(e){this._channelContext.targetLag.value=e}},{key:"stop",value:(h=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new qe((function(e){if(!n._stateContext.isStarting.value)return n.processStop(t),void e();n._channelContext.rendererDisposables.add(n._stateContext.isStarting.subscribe((function(i){i||(n.processStop(t),e())})))})));case 1:case"end":return e.stop()}}),e)}))),function(e){return h.apply(this,arguments)})},{key:"processStop",value:function(e){this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.pause(),this._channelContext.videoElement.value.srcObject=null),this._channelContext.rendererDisposables.dispose(),this.cleanUpResources(e),this._channelContext.state.value=me.Stopped}},{key:"resume",value:(d=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._peerConnectionContext.mediaStream.value){e.next=3;break}return this._channelContext.autoPaused.value=!1,e.abrupt("return",this.playMediaStreamInVideoElement(this._peerConnectionContext.mediaStream.value));case 3:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"mute",value:function(){var e=this._channelContext.videoElement.value;e&&(e.muted=!0)}},{key:"unmute",value:function(){var e=this._channelContext.videoElement.value;e&&(e.muted=!1,this._channelContext.autoMuted.value=!1)}},{key:"dispose",value:(l=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stop("client:channel-dispose").then((function(){t._channelContext.channelDisposables.dispose(),t._stateContext.isDisposed=!0})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"getUri",value:function(e){return H.parseToken(e).uri||(this._logger.info("Fall back to the default discover URI [%s]",he.discoveryUri.value),new URL(he.discoveryUri.value))}},{key:"start",value:(c=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._stateContext.isStarting.value){e.next=5;break}return this._logger.info("Channel is already starting, skipping start"),e.abrupt("return");case 5:return this._stateContext.isStarting.value=!0,e.abrupt("return",this.processStart());case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"processStart",value:(s=g()(y().mark((function e(){var t,n,i,r,o,a=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._tokenContext.token.value,n=this._sessionTelemetry.listenOnStreamSetup(),H.isEncodedEdgeTokenValid(t)){e.next=8;break}return this._logger.error("Failed to parse token [%s]",t),this._channelContext.state.value=me.Unauthorized,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 8:if(!this._channelContext.hasInsertableStreams.value){e.next=23;break}if(this._channelContext.videoStreamTransformCallback.value){e.next=15;break}return this._logger.error("insertable-streams enabled, but missing callback function CreateChannelOptions.videoStreamTransformCallback"),this._channelContext.state.value=me.ConfigurationError,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 15:if(Y.isInsertableStreamsSupported){e.next=21;break}return this._logger.error("insertable-streams enabled, but browser does not support Media Stream Track API"),this._channelContext.state.value=me.UnsupportedFeature,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 21:e.next=29;break;case 23:if(!this._channelContext.videoStreamTransformCallback.value){e.next=29;break}return this._logger.error("CreateChannelOptions.videoStreamTransformCallback callback function found, but feature is not enabled via insertable-streams capability"),this._channelContext.state.value=me.ConfigurationError,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 29:if(this.cleanUpResources("client:start"),this._channelContext.state.value=me.Starting,this._channelContext.loading.value=!0,i=this.getUri(t),r=function(){return new qe((function(e){return a._stateContext.isStarting.value=!1,e(a.handleStreamFailure())}))},o=Ke.create(t,this._channelContext,this._peerConnectionContext,r)){e.next=38;break}return this._stateContext.isStarting.value=!1,e.abrupt("return");case 38:return e.abrupt("return",o.start(i,t,n,this.playMediaStreamInVideoElement.bind(this)).then((function(){a._channelContext.loading.value=!1})).catch((function(e){n.fail(),a._channelContext.failureCount.value++,a._channelContext.online.value=!1,a.cleanUpResources("client:cleanup-after-failed-setup"),a._channelContext.state.value=me.Error,a._logger.error("Failed to start channel",e)})).finally((function(){if(a._stateContext.isStarting.value=!1,a._channelContext.state.value!==me.Playing&&he.automaticRetryOnFailure){var e=setTimeout((function(){a.handleStreamFailure().catch((function(e){a._logger.error("Failed handling stream failure",e)}))}),a.getRetryInterval());a._channelContext.disposables.add(new U((function(){clearTimeout(e)})))}})));case 39:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"restartAfterStop",value:(o=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._peerConnectionContext.mediaStream.value){e.next=4;break}return e.abrupt("return",this.playMediaStreamInVideoElement(this._peerConnectionContext.mediaStream.value));case 4:this._tokenContext.token.value&&this.start();case 5:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"play",value:(i=g()(y().mark((function e(){var t;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._peerConnectionContext.mediaStream.value){e.next=3;break}return e.abrupt("return",this.start());case 3:return e.abrupt("return",this.playMediaStreamInVideoElement(t));case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getRetryInterval",value:function(){switch(this._channelContext.state.value){case me.StandBy:case me.Offline:return 15e3;case me.Error:case me.Recovering:case me.Unauthorized:case me.GeoRestricted:case me.GeoBlocked:case me.Stopped:case me.Starting:case me.Playing:case me.Paused:case me.Reconnecting:case me.UnsupportedFeature:case me.ConfigurationError:return this._exponentialBackoff.getExponentialBackoffIntervalByFailureCount(this._channelContext.failureCount.value);default:L(this._channelContext.state.value)}}},{key:"handleStreamFailure",value:(n=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=this._channelContext.state.value,e.next=e.t0===me.Error||e.t0===me.Reconnecting||e.t0===me.StandBy||e.t0===me.Offline||e.t0===me.Recovering?3:e.t0===me.Unauthorized?5:e.t0===me.GeoRestricted?7:e.t0===me.GeoBlocked?9:e.t0===me.Stopped?11:e.t0===me.Playing?13:e.t0===me.Paused?15:e.t0===me.Starting?17:e.t0===me.UnsupportedFeature?19:e.t0===me.ConfigurationError?21:23;break;case 3:return this._logger.info("Retry start with initial state [%s] [%s]",this._channelContext.state.value,me[this._channelContext.state.value]),e.abrupt("break",24);case 5:return this._logger.info("Channel is unauthorized, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 7:return this._logger.info("Channel is geo restricted, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 9:return this._logger.info("Channel is geo blocked, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 11:return this._logger.info("Channel is stopped, skipping retry of start."),e.abrupt("return");case 13:return this._logger.info("Channel is playing, skipping retry of start"),e.abrupt("return");case 15:return this._logger.info("Channel is paused, skipping retry of start. Please invoke play()"),e.abrupt("return");case 17:return this._logger.info("Channel is already starting, skipping retry of start"),e.abrupt("return");case 19:return this._logger.info("Channel is stopped due to unsupported feature, skipping retry of start."),e.abrupt("return");case 21:return this._logger.info("Channel is stopped due to configuration error, skipping retry of start."),e.abrupt("return");case 23:L(this._channelContext.state.value);case 24:return e.abrupt("return",this.start());case 25:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"cleanUpResources",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"client:termination";this._channelContext.disposables.dispose();var n=this._peerConnectionContext.peerConnection.value;n&&(this._peerConnectionContext.peerConnection.value=null,n.close()),this._peerConnectionContext.mediaStream.value&&(this._peerConnectionContext.mediaStream.value.getTracks().forEach((function(e){return e.stop()})),this._peerConnectionContext.mediaStream.value=null),this._channelContext.autoPaused.value=!1,this._channelContext.autoMuted.value=!1,this._channelContext.playing.value=!1,this._channelContext.stopped.value=!0,this._channelContext.standby.value=!1,this._channelContext.stream.value&&this._channelContext.endPoint.value&&this._channelContext.endPoint.value.destroyStream(this._channelContext.stream.value,t).then((function(t){var n=t.status;"ok"===n?e._logger.info("[%s] Destroyed stream with reason [%s]",e.streamId,n):e._logger.warn("[%s] Failed to destroy stream with reason [%s]",e.streamId,n)})).catch((function(t){e._logger.error("[%s] Failed to destroy stream",e.streamId,t)})),this.videoElement&&this.videoElement.dataset&&(this.videoElement.dataset.sessionId="",this.videoElement.dataset.streamId=""),this._channelContext.stream.value=null,this._channelContext.endPoint.value=null,this._peerConnectionContext.peerConnectionReconnectAttempts=0}},{key:"playMediaStreamInVideoElement",value:(t=g()(y().mark((function e(t){var n,i,r=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=this._channelContext.videoElement.value){e.next=8;break}return this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!1,this._channelContext.state.value=me.Stopped,e.abrupt("return");case 8:if(n.srcObject=t,void 0!==(i=n.play())){e.next=17;break}return this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!0,this._channelContext.state.value=me.Playing,e.abrupt("return");case 17:return e.abrupt("return",i.then((function(){r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!1,r._channelContext.loading.value=!1,r._channelContext.playing.value=!0,r._channelContext.state.value=me.Playing})).catch((function(e){var i=!!t.getTracks().filter((function(e){return"audio"===e.kind})),o=!he.automaticallyMuteVideoOnPlayFailure;return o||n.muted||!i?(r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,r._channelContext.state.value=me.Paused,o?(r._logger.info("[%s] Paused video after play failed. Manual user action required.",r.streamId,e),void(n.srcObject=null)):i?void r._logger.info("[%s] Failed to play video. Manual user action required.",r.streamId,e):void r._logger.info("[%s] Failed to play muted video. Manual user action required.",r.streamId,e)):(n.muted=!0,n.play().then((function(){r._logger.info("[%s] Played video after auto muting. Manual user action required to unmute.",r.streamId),r._channelContext.autoMuted.value=!0,r._channelContext.autoPaused.value=!1,r._channelContext.loading.value=!1,r._channelContext.playing.value=!0,r._channelContext.state.value=me.Playing})).catch((function(e){n.muted=!1,r._logger.info("[%s] Failed to play video. Manual user action required.",r.streamId,e),r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,r._channelContext.state.value=me.Paused})))})));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),e}(),Ye=function(){function e(){throw r()(this,e),new Error("Channels is a static class that may not be instantiated")}return a()(e,null,[{key:"createChannel",value:function(e){if(!he.initialized.value)throw new Error("SDK is not loaded.");var t={targetLag:e.targetLag,videoStreamTransformCallback:e.videoStreamTransformCallback};return new Qe(e.videoElement,e.token,t)}}]),e}(),Ze=function(e){return e[e.Offline=1]="Offline",e[e.Starting=2]="Starting",e[e.Publishing=3]="Publishing",e[e.Recovering=4]="Recovering",e[e.Reconnecting=5]="Reconnecting",e[e.Stopped=6]="Stopped",e[e.Unauthorized=7]="Unauthorized",e[e.GeoRestricted=8]="GeoRestricted",e[e.GeoBlocked=9]="GeoBlocked",e[e.UnsupportedFeature=10]="UnsupportedFeature",e[e.NotFound=11]="NotFound",e[e.Error=12]="Error",e}(Ze||{}),$e=Ze,Xe=function(){function e(t){r()(this,e),u()(this,"publisherInitialization",void 0),u()(this,"disposables",void 0),u()(this,"publisherDisposables",void 0),u()(this,"state",void 0),u()(this,"authorized",void 0),u()(this,"online",void 0),u()(this,"loading",void 0),u()(this,"publishing",void 0),u()(this,"standby",void 0),u()(this,"stopped",void 0),u()(this,"failureCount",void 0),u()(this,"endPoint",void 0),u()(this,"stream",void 0),u()(this,"rtcStatistics",void 0),u()(this,"clearFailureCountTimeout",void 0),u()(this,"startReconnectionAttemptsTimeInMilliseconds",void 0),u()(this,"name",void 0),this.disposables=new q,this.publisherDisposables=new q,this.publisherInitialization=new Date,this.state=new N($e.Starting),this.authorized=new N(!0),this.online=new N(!0),this.loading=new N(!1),this.publishing=new N(!1),this.standby=new N(!1),this.stopped=new N(!1),this.failureCount=new N(0),this.endPoint=new N(null),this.stream=new N(null),this.rtcStatistics=new N(null),this.name=t&&t.length?t:this.generateScreenName(),this.startReconnectionAttemptsTimeInMilliseconds=0}return a()(e,[{key:"streamId",get:function(){var e=this.stream.value;return e?e.streamId:"-"}},{key:"applyStatus",value:function(e){switch(e){case"ok":break;case"unauthorized":case"geo-restricted":case"geo-blocked":this.authorized.value=!1;case"not-found":return this.failureCount.value=0,this.publishing.value=!1,this.standby.value=!0,this.stopped.value=!1,void(this.stream.value=null);default:return this.failureCount.value++,this.publishing.value=!1,this.standby.value=!0,this.stopped.value=!1,this.stream.value=null,void(this.state.value=$e.Error)}}},{key:"mapPublishStatusToPublisherStatus",value:function(e){switch(e){case"ok":return $e.Starting;case"not-found":return $e.NotFound;case"geo-restricted":return $e.GeoRestricted;case"geo-blocked":return $e.GeoBlocked;case"unauthorized":return $e.Unauthorized;case"capacity":case"rate-limited":case"timeout":return $e.Recovering;case"failed":return $e.Error;default:L(e)}}},{key:"generateScreenName",value:function(){return D.random(12)}}]),e}(),et=function(){function e(t,n,i){if(r()(this,e),u()(this,"_estimatedRoundTripTime",void 0),u()(this,"_estimatedVideoCodec",void 0),u()(this,"_estimatedAudioCodec",void 0),u()(this,"_rtcStatistic",new N({})),u()(this,"_peerConnection",void 0),u()(this,"_isMonitorRunning",!0),u()(this,"_updateTimeout",void 0),u()(this,"_availableTracks",void 0),this._peerConnection=t,this._estimatedRoundTripTime=i,this._peerConnection){var o=new Ue(this._peerConnection.currentLocalDescription.sdp),a=new Ue(this._peerConnection.currentRemoteDescription.sdp);this._estimatedAudioCodec=a.audioCodec,this._estimatedVideoCodec=a.videoCodec,this._availableTracks={audio:o.isAudioTrackEnabled&&a.isAudioTrackEnabled,video:o.isVideoTrackEnabled&&a.isVideoTrackEnabled},this.updateStatistic()}}var t;return a()(e,[{key:"rtcStatistic",get:function(){return this._rtcStatistic}},{key:"dispose",value:function(){this._isMonitorRunning=!1,this._peerConnection=null,this._updateTimeout&&(clearTimeout(this._updateTimeout),this._updateTimeout=null)}},{key:"updateStatistic",value:(t=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.getStatsPromiseBasedDisabled){e.next=3;break}return e.abrupt("return");case 3:return t=function(e){return e.id.includes("Audio")?"audio":e.id.includes("Video")?"video":""},e.next=6,this._peerConnection.getStats(null).then((function(e){var i={};if(e){var r,o=n._estimatedRoundTripTime;e.forEach((function(a){if("candidate-pair"===a.type&&a.currentRoundTripTime&&(o=1e3*a.currentRoundTripTime,i.audio&&(i.audio.roundTripTime=o),i.video&&(i.video.roundTripTime=o)),"candidate-pair"===a.type&&a.lastPacketSentTimestamp&&(r=a.lastPacketSentTimestamp,i.audio&&(i.audio.lastPacketSentTimestamp=r),i.video&&(i.video.lastPacketSentTimestamp=r)),"outbound-rtp"===a.type){var s=a.kind||a.mediaType||t(a),u="";if(e.forEach((function(e){e.id===a.codecId&&(u=e.mimeType)})),s&&n._availableTracks[s]){var c,l,d,h,p,f=(a.bytesSent||0)-(null!==(c=null===(l=n._rtcStatistic.value)||void 0===l||null===(d=l[s])||void 0===d?void 0:d.bytesSent)&&void 0!==c?c:0),v=a.timestamp-(null===(h=n._rtcStatistic.value)||void 0===h||null===(p=h[s])||void 0===p?void 0:p.timestamp),m=f&&v?Math.floor(8*f/v*1e3):0;if(i[s]={ssrc:a.ssrc,mediaType:s,timestamp:a.timestamp,bitrate:m,bytesSent:a.bytesSent,packetsSent:a.packetsSent,retransmittedBytesSent:a.retransmittedBytesSent,codec:u||n.getCodecByType(s),roundTripTime:o},(a.lastPacketSentTimestamp||r)&&(i[s].lastPacketSentTimestamp=a.lastPacketSentTimestamp||r),"video"===s&&n._rtcStatistic.value&&n._rtcStatistic.value.video){i[s].firCount=a.firCount,i[s].frameHeight=a.frameHeight,i[s].frameWidth=a.frameWidth,i[s].framesEncoded=a.framesEncoded,i[s].framesSent=a.framesSent,i[s].headerBytesSent=a.headerBytesSent,i[s].hugeFramesSent=a.hugeFramesSent,i[s].pliCount=a.pliCount,i[s].qpSum=a.qpSum,i[s].totalEncodeTime=a.totalEncodeTime,i[s].totalEncodedBytesTarget=a.totalEncodedBytesTarget;var g=(a.framesEncoded-n._rtcStatistic.value.video.framesEncoded)/(i[s].timestamp-n._rtcStatistic.value.video.timestamp)*1e3;i[s].fps=g?Math.round(100*g)/100:0}}}}))}n._rtcStatistic.value=i})).then((function(){n._isMonitorRunning&&(n._updateTimeout=window.setTimeout((function(){return n.updateStatistic()}),1e3))}));case 6:e.sent;case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getCodecByType",value:function(e){switch(e){case"audio":return this._estimatedAudioCodec;case"video":return this._estimatedVideoCodec;default:return"unknown"}}}]),e}(),tt=n(202).default;function nt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function it(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?nt(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):nt(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var rt=function(){function e(t,n,i){r()(this,e),u()(this,"_logger",O.getLogger("RealTimePublisher")),u()(this,"_publisherContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_handleStreamFailure",void 0),this._publisherContext=t,this._peerConnectionContext=n,this._handleStreamFailure=i}var t;return a()(e,[{key:"start",value:function(e,t,n){var i=this;return navigator.onLine?tt.all([Ve.discoverClosestEndPointWithCaching(e),ne.createPeerConnectionOffer("sendonly")]).then((function(e){var n=Pe()(e,2),r=n[0],o=n[1],a=o.localOffer,s=o.peerConnection;return i._publisherContext.online.value=!0,i._publisherContext.endPoint.value=r,i._logger.info("Connecting to [%s]",r.toString()),i._logger.info("Local offer:\n"+a.sdp),(Y.clientOfferDisabled||!s.supportsSetConfiguration||!s.supportsGetConfiguration||i._publisherContext.failureCount.value>0)&&(s.close(),s=null,a=null),i._peerConnectionContext.peerConnection.value=s,r.publish(i._publisherContext.name,t,a,i._publisherContext.failureCount.value)})).then((function(e){var t=e.status,r=e.stream,o=e.rtcConfiguration,a=e.setRemoteDescriptionResponse,s=e.createOfferDescriptionResponse,u=e.createAnswerDescriptionResponse;if(i._publisherContext.stream.value=r,i._logger.debug("[%s] Publish completed [%s] [%j] [%j] [%j] [%j]",i._publisherContext.streamId,t,o,a,s,u),i._publisherContext.state.value=i._publisherContext.mapPublishStatusToPublisherStatus(t),i._publisherContext.applyStatus(t),"ok"===t)return i.applyRtcConfiguration(i._peerConnectionContext.peerConnection.value,o).then((function(e){var t,o=!1,c=!1,l=[];return i._peerConnectionContext.peerConnection.value=e,e.addStream(i._peerConnectionContext.mediaStream.value),e.onicecandidate=function(n){i._publisherContext.stream.value===r&&i._peerConnectionContext.peerConnection.value===e&&(o||he.sendLocalCandidates.value&&(n.candidate&&n.candidate.candidate?l.push(n.candidate):c=!0,t||(t=setTimeout((function(){i._publisherContext.stream.value!==r||o||i._publisherContext.endPoint.value.addIceCandidates(r,l,c).then((function(e){var t=e.status,n=e.options;"ok"===t?(n.includes("cancel")&&(o=!0),i._logger.info("[%s] Added ICE candidates with reason [%s] and options [%s]",i._publisherContext.streamId,t,n)):i._logger.warn("[%s] Failed to add ICE candidates with reason [%s]",i._publisherContext.streamId,t)})).catch((function(e){i._logger.error("[%s] Failed to add ICE candidates",i._publisherContext.streamId,e)}))}),100))))},e.oniceconnectionstatechange=function(){if(i._publisherContext.stream.value===r&&i._peerConnectionContext.peerConnection.value===e){var t=function(){i._publisherContext.state.value=$e.Error,i._publisherContext.publishing.value=!1,i._publisherContext.loading.value=!0,i._handleStreamFailure().catch((function(t){i._logger.error("[%s] Failed handling stream failure after peer connection stopped with state [%s]",i._publisherContext.streamId,e.iceConnectionState,t)}))};switch(e.iceConnectionState){case"checking":case"completed":case"connected":case"new":return;case"disconnected":case"failed":return i._logger.info("[%s] ICE connection state changed to [%s], trying to reconnect",i._publisherContext.streamId,e.iceConnectionState),void i.reconnectPeerConnection(e,t);case"closed":return i._logger.info("[%s] ICE connection state changed to [%s], retrying to connect",i._publisherContext.streamId,e.iceConnectionState),void t();default:L(e.iceConnectionState)}}},new tt((function(e){e()})).then((function(){if(a)return i._logger.info("[%s] Set local SDP offer [%s]",i._publisherContext.streamId,a.sessionDescription.sdp),e.setLocalDescription(a.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set local description [%j] with message [%s]",i._publisherContext.streamId,a.sessionDescription,e.message),e}))})).then((function(){if(u)return i._logger.info("[%s] Set remote SDP answer [%s]",i._publisherContext.streamId,u.sessionDescription.sdp),e.setRemoteDescription(u.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set remote description [%j] with message [%s]",i._publisherContext.streamId,u.sessionDescription,e.message),e}))})).then((function(){if(s)return i._logger.info("[%s] Set remote SDP offer [%s]",i._publisherContext.streamId,s.sessionDescription.sdp),e.setRemoteDescription(s.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set remote description [%j] with message [%s]",i._publisherContext.streamId,u.sessionDescription,e.message),e})).then((function(){return e.createAnswer({offerToReceiveAudio:!1,offerToReceiveVideo:!1})})).then((function(e){return i._logger.info("[%s] Set local SDP answer [%s]",i._publisherContext.streamId,e.sdp),i._publisherContext.endPoint.value.setRemoteDescription(r,e)})).then((function(t){var n=t.status,r=t.sessionDescription;return i._publisherContext.state.value=i.mapSetRemoteDescriptionStatusToPublisherStatus(n),"ok"!==n?(i._publisherContext.publishing.value=!1,i._publisherContext.standby.value=!0,void(i._publisherContext.stopped.value=!1)):(i._logger.info("[%s] Set local SDP [%s]",i._publisherContext.streamId,r.sdp),e.setLocalDescription(r).catch((function(e){throw i._logger.info("[%s] Failed to set local description [%j] with message [%s]",i._publisherContext.streamId,r,e.message),e})))}))})).then((function(){return n.success(i._publisherContext.streamId),i._publisherContext.state.value=$e.Publishing,i._publisherContext.publishing.value=!0,new et(e,i._peerConnectionContext.mediaStream.value,i._publisherContext.endPoint.value.roundTripTime/4).rtcStatistic.subscribe((function(e){i._publisherContext.rtcStatistics.value=e})),tt.resolve()}))}))})):(this._publisherContext.state.value=$e.Offline,tt.resolve())}},{key:"applyRtcConfiguration",value:(t=g()(y().mark((function e(t,n){var i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=3;break}return n=Ne.truncateIceServers(n),e.abrupt("return",he.peerConnectionFactory.value.createPeerConnection(n));case 3:return i=it(it({},t.getConfiguration()),n),t.setConfiguration(i),e.abrupt("return",t);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"reconnectPeerConnection",value:function(e,t){var n=this;if("closed"!==e.iceConnectionState)if(this._publisherContext.state.value=$e.Reconnecting,this._peerConnectionContext.peerConnectionReconnectAttempts<he.maximalNumberOfPeerConnectionReconnectAttempts||!he.automaticallyReconnectPeerConnection){var i;this._peerConnectionContext.peerConnectionReconnectAttempts++;var r="offer"===(null===(i=e.currentLocalDescription)||void 0===i?void 0:i.type);if(Y.clientOfferDisabled||!e.supportsSetConfiguration||!e.supportsGetConfiguration||!r){var o=setTimeout((function(){n.reconnectPeerConnection(e,t)}),1e3);return void this._publisherContext.disposables.add(new U((function(){return clearTimeout(o)})))}this._logger.info("Reconnecting peer connection by restarting ICE");var a=e.currentLocalDescription;e.createOffer({iceRestart:!0}).then((function(i){return e.setLocalDescription(i).then((function(){return e.setLocalDescription(a).then((function(){if("disconnected"===e.iceConnectionState||"failed"===e.iceConnectionState){var i=setTimeout((function(){n.reconnectPeerConnection(e,t)}),1e3);n._publisherContext.disposables.add(new U((function(){return clearTimeout(i)})))}else n._publisherContext.state.value=$e.Publishing}))}))})).catch((function(e){n._logger.error("Failed to reconnect peer connection",e),n._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}))}else this._logger.info("Failed to reconnect peer connection after [%s] attempts, performing full recovery",this._peerConnectionContext.peerConnectionReconnectAttempts),this._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}},{key:"mapSetRemoteDescriptionStatusToPublisherStatus",value:function(e){switch(e){case"ok":return $e.Starting;case"unauthorized":return $e.Unauthorized;case"not-found":return $e.NotFound;case"capacity":case"rate-limited":case"timeout":return $e.Recovering;case"failed":return $e.Error;default:L(e)}}}]),e}(),ot=n(202).default,at=function(){function e(t,n,i){var o=this;r()(this,e),u()(this,"_logger",O.getLogger("Publisher")),u()(this,"_tokenContext",void 0),u()(this,"_publisherContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_stateContext",void 0),u()(this,"_exponentialBackoff",void 0),u()(this,"_publisherStartTime",void 0),u()(this,"_readOnlyToken",void 0),u()(this,"_readOnlyPeerConnection",void 0),u()(this,"_readOnlyState",void 0),u()(this,"_readOnlyTokenExpiring",void 0),u()(this,"_readOnlyAuthorized",void 0),u()(this,"_readOnlyOnline",void 0),u()(this,"_readOnlyLoading",void 0),u()(this,"_readOnlyPublishing",void 0),u()(this,"_readOnlyStandby",void 0),u()(this,"_readOnlyStopped",void 0),u()(this,"_readOnlyFailureCount",void 0),u()(this,"_readOnlyEndPoint",void 0),u()(this,"_readOnlyStream",void 0),u()(this,"_readOnlyRtcStatistics",void 0),u()(this,"_readOnlyMediaStream",void 0),u()(this,"_metricsService",void 0),u()(this,"_sessionTelemetry",void 0),this._tokenContext=new we(n),this._publisherContext=new Xe(i),this._peerConnectionContext=new Te,this._stateContext=new Le,this._exponentialBackoff=new fe,this._publisherStartTime=Date.now(),this._readOnlyToken=new z(this._tokenContext.token),this._readOnlyPeerConnection=new z(this._peerConnectionContext.peerConnection),this._readOnlyState=new z(this._publisherContext.state),this._readOnlyTokenExpiring=new z(this._tokenContext.tokenExpiring),this._readOnlyAuthorized=new z(this._publisherContext.authorized),this._readOnlyOnline=new z(this._publisherContext.online),this._readOnlyLoading=new z(this._publisherContext.loading),this._readOnlyPublishing=new z(this._publisherContext.publishing),this._readOnlyStandby=new z(this._publisherContext.standby),this._readOnlyStopped=new z(this._publisherContext.stopped),this._readOnlyFailureCount=new z(this._publisherContext.failureCount),this._readOnlyEndPoint=new z(this._publisherContext.endPoint),this._readOnlyStream=new z(this._publisherContext.stream),this._readOnlyRtcStatistics=new z(this._publisherContext.rtcStatistics),this._readOnlyMediaStream=new z(this._peerConnectionContext.mediaStream),this._peerConnectionContext.mediaStream.value=t;var a=H.parseToken(this._tokenContext.token.value),s=(a.uri||he.discoveryUri.value).toString();he.tenancy.value=a.tenancy||he.tenancy.value,oe.uri.value=s,this._metricsService=le.getMetricsService(s),this._sessionTelemetry=new be(he.pageLoadTime,this._metricsService),this._publisherContext.publisherDisposables.add(this._sessionTelemetry),this._publisherContext.publisherDisposables.add(this._publisherContext.state.subscribe((function(e){o._publisherContext.clearFailureCountTimeout&&clearTimeout(o._publisherContext.clearFailureCountTimeout),o._publisherContext.failureCount.value&&e===$e.Publishing&&(o._publisherContext.clearFailureCountTimeout=window.setTimeout((function(){o._publisherContext.failureCount.value=0}),3e3))})));var c=function(){o._publisherContext.stream.value&&o._publisherContext.endPoint.value&&o._publisherContext.endPoint.value.destroyStreamOnUnmount(o._publisherContext.stream.value,"client:termination-on-window-unload")};window.addEventListener("beforeunload",c),this._publisherContext.publisherDisposables.add(new U((function(){window.removeEventListener("beforeunload",c)}))),this.start()}var t,n,i,o,s;return a()(e,[{key:"token",get:function(){return this._tokenContext.token.value},set:function(e){this._publisherContext.disposables.dispose(),this._tokenContext.token.value=e,this._tokenContext.tokenExpiring.value=!1;var t=H.parseToken(this._tokenContext.token.value),n=(t.uri||he.discoveryUri.value).toString();he.tenancy.value=t.tenancy||he.tenancy.value,oe.uri.value=n,this._metricsService=le.getMetricsService(n),this.start()}},{key:"peerConnection",get:function(){return this._readOnlyPeerConnection}},{key:"state",get:function(){return this._readOnlyState}},{key:"tokenExpiring",get:function(){return this._readOnlyTokenExpiring}},{key:"authorized",get:function(){return this._readOnlyAuthorized}},{key:"online",get:function(){return this._readOnlyOnline}},{key:"loading",get:function(){return this._readOnlyLoading}},{key:"publishing",get:function(){return this._readOnlyPublishing}},{key:"standby",get:function(){return this._readOnlyStandby}},{key:"stopped",get:function(){return this._readOnlyStopped}},{key:"failureCount",get:function(){return this._readOnlyFailureCount}},{key:"endPoint",get:function(){return this._readOnlyEndPoint}},{key:"stream",get:function(){return this._readOnlyStream}},{key:"streamId",get:function(){return this._publisherContext.streamId}},{key:"rtcStatistics",get:function(){return this._readOnlyRtcStatistics}},{key:"mediaStream",get:function(){return this._readOnlyMediaStream}},{key:"stop",value:(s=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new ot((function(e){if(!n._stateContext.isStarting.value)return n.processStop(t),void e();n._publisherContext.disposables.add(n._stateContext.isStarting.subscribe((function(i){i||(n.processStop(t),e())})))})));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"processStop",value:function(e){this.cleanUpResources(e),this._peerConnectionContext.peerConnection.value&&(this._peerConnectionContext.peerConnection.value.close(),this._peerConnectionContext.peerConnection.value=null),this._publisherContext.state.value=$e.Stopped}},{key:"dispose",value:(o=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stop("client:channel-dispose").then((function(){t._publisherContext.publisherDisposables.dispose(),t._stateContext.isDisposed=!0})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getUri",value:function(e){return H.parseToken(e).uri||(this._logger.info("Fall back to the default discover URI [%s]",he.discoveryUri.value),new URL(he.discoveryUri.value))}},{key:"start",value:(i=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._stateContext.isStarting.value){e.next=5;break}return this._logger.info("Publisher is already starting, skipping start"),e.abrupt("return");case 5:return this._stateContext.isStarting.value=!0,e.abrupt("return",this.processStart());case 7:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"setMediaStream",value:function(e){var t=this;this._peerConnectionContext.mediaStream.value=e,this._peerConnectionContext.peerConnection.value&&e.getTracks().forEach((function(e){t._peerConnectionContext.peerConnection.value.getSenders().forEach((function(t){var n;e.kind===(null==t||null===(n=t.track)||void 0===n?void 0:n.kind)&&e.id!==t.track.id&&t.replaceTrack(e)}))}))}},{key:"processStart",value:(n=g()(y().mark((function e(){var t,n,i,r,o,a=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._tokenContext.token.value,n=this._sessionTelemetry.listenOnStreamSetup(),H.isEncodedEdgeTokenValid(t)){e.next=8;break}return this._logger.error("Failed to parse token [%s]",t),this._publisherContext.state.value=$e.Unauthorized,this._publisherContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 8:return this.cleanUpResources("client:start"),this._publisherContext.state.value=$e.Starting,this._publisherContext.loading.value=!0,i=this.getUri(t),r=function(){return new ot((function(e){return a._stateContext.isStarting.value=!1,e(a.handleStreamFailure())}))},o=new rt(this._publisherContext,this._peerConnectionContext,r),e.abrupt("return",o.start(i,t,n).then((function(){a._publisherContext.loading.value=!1})).catch((function(e){n.fail(),a._publisherContext.failureCount.value++,a._publisherContext.online.value=!1,a.cleanUpResources("client:cleanup-after-failed-setup"),a._publisherContext.state.value=$e.Error,a._logger.error("Failed to start publishing",e)})).finally((function(){if(a._stateContext.isStarting.value=!1,a._publisherContext.state.value!==$e.Publishing&&he.automaticRetryOnFailure){var e=setTimeout((function(){a.handleStreamFailure().catch((function(e){a._logger.error("Failed handling stream failure",e)}))}),a.getRetryInterval());a._publisherContext.disposables.add(new U((function(){clearTimeout(e)})))}else a._publisherContext.startReconnectionAttemptsTimeInMilliseconds=0})));case 15:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getRetryInterval",value:function(){switch(this._publisherContext.state.value){case $e.Offline:return 15e3;case $e.NotFound:case $e.Error:case $e.Recovering:case $e.Unauthorized:case $e.GeoRestricted:case $e.GeoBlocked:case $e.Stopped:case $e.Starting:case $e.Publishing:case $e.Reconnecting:case $e.UnsupportedFeature:return this._exponentialBackoff.getExponentialBackoffIntervalByFailureCount(this._publisherContext.failureCount.value);default:L(this._publisherContext.state.value)}}},{key:"handleStreamFailure",value:(t=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=this._publisherContext.state.value,e.next=e.t0===$e.Error||e.t0===$e.Reconnecting||e.t0===$e.Offline||e.t0===$e.Recovering?4:e.t0===$e.Unauthorized?11:e.t0===$e.GeoRestricted?13:e.t0===$e.GeoBlocked?15:e.t0===$e.Stopped?17:e.t0===$e.Publishing?19:e.t0===$e.Starting?21:e.t0===$e.UnsupportedFeature?23:e.t0===$e.NotFound?25:27;break;case 4:if(this._publisherContext.startReconnectionAttemptsTimeInMilliseconds||(this._publisherContext.startReconnectionAttemptsTimeInMilliseconds=Date.now()),!(72e5<=Date.now()-this._publisherContext.startReconnectionAttemptsTimeInMilliseconds)){e.next=9;break}return this._logger.info("Publisher stopped with state [%s] [%s] after exceeding timeout",this._publisherContext.state.value,$e[this._publisherContext.state.value]),e.abrupt("return");case 9:return this._logger.info("Retry start with initial state [%s] [%s]",this._publisherContext.state.value,$e[this._publisherContext.state.value]),e.abrupt("break",28);case 11:return this._logger.info("Publisher is unauthorized, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 13:return this._logger.info("Publisher is geo restricted, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 15:return this._logger.info("Publisher is geo blocked, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 17:return this._logger.info("Publisher is stopped, skipping retry of start."),e.abrupt("return");case 19:return this._logger.info("Publisher is publishing, skipping retry of start"),e.abrupt("return");case 21:return this._logger.info("Publisher is already starting, skipping retry of start"),e.abrupt("return");case 23:return this._logger.info("Publisher is stopped due to unsupported feature, skipping retry of start."),e.abrupt("return");case 25:return this._logger.info("Publisher is stopped due to channel not found, skipping retry of start."),e.abrupt("return");case 27:L(this._publisherContext.state.value);case 28:return e.abrupt("return",this.start());case 29:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"cleanUpResources",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"client:termination";this._publisherContext.disposables.dispose();var n=this._peerConnectionContext.peerConnection.value;n&&(this._peerConnectionContext.peerConnection.value=null,n.close()),this._publisherContext.publishing.value=!1,this._publisherContext.stopped.value=!0,this._publisherContext.standby.value=!1,this._publisherContext.stream.value&&this._publisherContext.endPoint.value&&this._publisherContext.endPoint.value.destroyStream(this._publisherContext.stream.value,t).then((function(t){var n=t.status;"ok"===n?e._logger.info("[%s] Destroyed stream with reason [%s]",e.streamId,n):e._logger.warn("[%s] Failed to destroy stream with reason [%s]",e.streamId,n)})).catch((function(t){e._logger.error("[%s] Failed to destroy stream",e.streamId,t)})),this._publisherContext.stream.value=null,this._publisherContext.endPoint.value=null,this._peerConnectionContext.peerConnectionReconnectAttempts=0}}]),e}(),st=function(){function e(){throw r()(this,e),new Error("Publishers is a static class that may not be instantiated")}return a()(e,null,[{key:"createPublisher",value:function(e){if(!he.initialized.value)throw new Error("SDK is not loaded.");return new at(e.mediaStream,e.token,e.name)}}]),e}(),ut={SDK:he,Channels:Ye,ChannelState:me,Publishers:st,PublisherState:$e}}},t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}return n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(547)})()}));
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.phenix=t():e.phenix=t()}(self,(function(){return(()=>{var e={228:e=>{e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i},e.exports.__esModule=!0,e.exports.default=e.exports},858:e=>{e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},646:(e,t,n)=>{var i=n(228);e.exports=function(e){if(Array.isArray(e))return i(e)},e.exports.__esModule=!0,e.exports.default=e.exports},506:e=>{e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.__esModule=!0,e.exports.default=e.exports},926:(e,t,n)=>{var i=n(202).default;function r(e,t,n,r,o,a,s){try{var u=e[a](s),c=u.value}catch(e){return void n(e)}u.done?t(c):i.resolve(c).then(r,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new i((function(i,o){var a=e.apply(t,n);function s(e){r(a,i,o,s,u,"next",e)}function u(e){r(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},575:e=>{e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},913:(e,t,n)=>{var i=n(696);function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,i(r.key),r)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},713:(e,t,n)=>{var i=n(696);e.exports=function(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.__esModule=!0,e.exports.default=e.exports},754:e=>{function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},205:(e,t,n)=>{var i=n(489);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)},e.exports.__esModule=!0,e.exports.default=e.exports},860:e=>{e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.__esModule=!0,e.exports.default=e.exports},884:e=>{e.exports=function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,o,a,s=[],u=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(i=o.call(n)).done)&&(s.push(i.value),s.length!==t);u=!0);}catch(e){c=!0,r=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw r}}return s}},e.exports.__esModule=!0,e.exports.default=e.exports},521:e=>{e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},206:e=>{e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},585:(e,t,n)=>{var i=n(8).default,r=n(506);e.exports=function(e,t){if(t&&("object"===i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return r(e)},e.exports.__esModule=!0,e.exports.default=e.exports},591:(e,t,n)=>{var i=n(202).default,r=n(8).default;function o(){"use strict";e.exports=o=function(){return t},e.exports.__esModule=!0,e.exports.default=e.exports;var t={},n=Object.prototype,a=n.hasOwnProperty,s=Object.defineProperty||function(e,t,n){e[t]=n.value},u="function"==typeof Symbol?Symbol:{},c=u.iterator||"@@iterator",l=u.asyncIterator||"@@asyncIterator",d=u.toStringTag||"@@toStringTag";function h(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(e){h=function(e,t,n){return e[t]=n}}function p(e,t,n,i){var r=t&&t.prototype instanceof m?t:m,o=Object.create(r.prototype),a=new R(i||[]);return s(o,"_invoke",{value:S(e,n,a)}),o}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=p;var v={};function m(){}function g(){}function _(){}var y={};h(y,c,(function(){return this}));var C=Object.getPrototypeOf,b=C&&C(C(E([])));b&&b!==n&&a.call(b,c)&&(y=b);var k=_.prototype=m.prototype=Object.create(y);function x(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function n(i,o,s,u){var c=f(e[i],e,o);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==r(d)&&a.call(d,"__await")?t.resolve(d.__await).then((function(e){n("next",e,s,u)}),(function(e){n("throw",e,s,u)})):t.resolve(d).then((function(e){l.value=e,s(l)}),(function(e){return n("throw",e,s,u)}))}u(c.arg)}var i;s(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}})}function S(e,t,n){var i="suspendedStart";return function(r,o){if("executing"===i)throw new Error("Generator is already running");if("completed"===i){if("throw"===r)throw o;return{value:void 0,done:!0}}for(n.method=r,n.arg=o;;){var a=n.delegate;if(a){var s=T(a,n);if(s){if(s===v)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===i)throw i="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i="executing";var u=f(e,t,n);if("normal"===u.type){if(i=n.done?"completed":"suspendedYield",u.arg===v)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(i="completed",n.method="throw",n.arg=u.arg)}}}function T(e,t){var n=t.method,i=e.iterator[n];if(void 0===i)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var r=f(i,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,v;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,v):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function E(e){if(e){var t=e[c];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(a.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return g.prototype=_,s(k,"constructor",{value:_,configurable:!0}),s(_,"constructor",{value:g,configurable:!0}),g.displayName=h(_,d,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,_):(e.__proto__=_,h(e,d,"GeneratorFunction")),e.prototype=Object.create(k),e},t.awrap=function(e){return{__await:e}},x(w.prototype),h(w.prototype,l,(function(){return this})),t.AsyncIterator=w,t.async=function(e,n,r,o,a){void 0===a&&(a=i);var s=new w(p(e,n,r,o),a);return t.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},x(k),h(k,d,"Generator"),h(k,c,(function(){return this})),h(k,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var i in t)n.push(i);return n.reverse(),function e(){for(;n.length;){var i=n.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},t.values=E,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&a.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,i){return o.type="throw",o.arg=e,t.next=n,i&&(t.method="next",t.arg=void 0),!!i}for(var i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i],o=r.completion;if("root"===r.tryLoc)return n("end");if(r.tryLoc<=this.prev){var s=a.call(r,"catchLoc"),u=a.call(r,"finallyLoc");if(s&&u){if(this.prev<r.catchLoc)return n(r.catchLoc,!0);if(this.prev<r.finallyLoc)return n(r.finallyLoc)}else if(s){if(this.prev<r.catchLoc)return n(r.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<r.finallyLoc)return n(r.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&a.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===e||"continue"===e)&&r.tryLoc<=t&&t<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=e,o.arg=t,r?(this.method="next",this.next=r.finallyLoc,v):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),P(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var i=n.completion;if("throw"===i.type){var r=i.arg;P(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),v}},t}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},489:e=>{function t(n,i){return e.exports=t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n,i)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},38:(e,t,n)=>{var i=n(858),r=n(884),o=n(379),a=n(521);e.exports=function(e,t){return i(e)||r(e,t)||o(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},319:(e,t,n)=>{var i=n(646),r=n(860),o=n(379),a=n(206);e.exports=function(e){return i(e)||r(e)||o(e)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},868:(e,t,n)=>{var i=n(8).default;e.exports=function(e,t){if("object"!==i(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},696:(e,t,n)=>{var i=n(8).default,r=n(868);e.exports=function(e){var t=r(e,"string");return"symbol"===i(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},8:e=>{function t(n){return e.exports=t="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.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},379:(e,t,n)=>{var i=n(228);e.exports=function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},757:(e,t,n)=>{var i=n(591)();e.exports=i;try{regeneratorRuntime=i}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}},202:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>p});var i=n(8),r=n.n(i),o=n(575),a=n.n(o),s=n(913),u=n.n(s),c=n(713),l=n.n(c),d=u()((function e(t,n,i){a()(this,e),l()(this,"onFulfilled",void 0),l()(this,"onRejected",void 0),l()(this,"promise",void 0),this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof n?n:null,this.promise=i})),h=function(){function e(t){if(a()(this,e),l()(this,"_state",void 0),l()(this,"_handled",void 0),l()(this,"_value",void 0),l()(this,"_deferreds",void 0),!(this instanceof e))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],this.doResolve(t)}return u()(e,[{key:"doResolve",value:function(e){var t=this,n=!1;try{e((function(e){n||(n=!0,t.promiseResolve(e))}),(function(e){n||(n=!0,t.promiseReject(e))}))}catch(e){if(n)return;n=!0,this.promiseReject(e)}}},{key:"promiseResolve",value:function(t){var n=this;try{if(t===n)throw new TypeError("A Promise cannot be resolved with it self.");if(t&&("object"===r()(t)||"function"==typeof t)){var i=t.then;if(t instanceof e)return n._state=3,n._value=t,void n.finale();if("function"==typeof i)return void n.doResolve((function(){i.apply(t,arguments)}))}n._state=1,n._value=t,n.finale()}catch(e){n.promiseReject(e)}}},{key:"promiseReject",value:function(e){this._state=2,this._value=e,this.finale()}},{key:"finale",value:function(){var t=this;2===this._state&&0===this._deferreds.length&&e._immediate((function(){t._handled||e._unhandledRejection(t._value)}));for(var n=0,i=this._deferreds.length;n<i;n++)this.handle(this._deferreds[n]);this._deferreds=null}},{key:"handle",value:function(t){for(var n=this;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,e._immediate((function(){var e=1===n._state?t.onFulfilled:t.onRejected;if(null!==e){var i;try{i=e(n._value)}catch(e){return void t.promise.promiseReject(e)}t.promise.promiseResolve(i)}else 1===n._state?t.promise.promiseResolve(n._value):t.promise.promiseReject(n._value)}))):n._deferreds.push(t)}}],[{key:"all",value:function(t){return new e((function(e,n){if(!Array.isArray(t))return n(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(t);if(0===i.length)return e([]);for(var o=i.length,a=function t(a,s){try{if(s&&("object"===r()(s)||"function"==typeof s)){var u=s.then;if("function"==typeof u)return void u.call(s,(function(e){return t(a,e)}),n)}i[a]=s,0==--o&&e(i)}catch(e){n(e)}},s=0;s<i.length;s++)a(s,i[s])}))}},{key:"resolve",value:function(t){return t&&"object"===r()(t)&&t.constructor===e?t:new e((function(e){return e(t)}))}},{key:"reject",value:function(t){return new e((function(e,n){return n(t)}))}},{key:"race",value:function(t){return new e((function(n,i){if(!Array.isArray(t))return i(new TypeError("Promise.race accepts an array"));for(var r=0,o=t.length;r<o;r++)e.resolve(t[r]).then(n,i)}))}},{key:"_immediate",value:function(e){setTimeout(e,0)}},{key:"_unhandledRejection",value:function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)}}]),e}();h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){var n=new this.constructor((function(){return null}));return this.handle(new d(e,t,n)),n},h.prototype.finally=function(e){var t=this.constructor;return this.then((function(n){return t.resolve(e()).then((function(){return n}))}),(function(n){return t.resolve(e()).then((function(){return t.reject(n)}))}))};var p=h},958:(e,t,n)=>{"use strict";n.r(t),n.d(t,{ChannelState:()=>ge,Channels:()=>Ze,PublisherState:()=>Xe,Publishers:()=>ut,SDK:()=>pe,default:()=>ct});var i=n(575),r=n.n(i),o=n(913),a=n.n(o),s=n(713),u=n.n(s),c=function(e){return e[e.All=-1]="All",e[e.Trace=10]="Trace",e[e.Debug=20]="Debug",e[e.Info=30]="Info",e[e.Warn=40]="Warn",e[e.Error=50]="Error",e[e.Fatal=60]="Fatal",e[e.Off=100]="Off",e}({}),l=function(){function e(t,n,i){r()(this,e),u()(this,"_category",void 0),u()(this,"_appenders",void 0),u()(this,"_threshold",void 0),this._category=t,this._appenders=n,this._threshold=i}return a()(e,[{key:"category",get:function(){return this._category}},{key:"appenders",get:function(){return this._appenders}},{key:"threshold",get:function(){return this._threshold}},{key:"trace",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Trace)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Trace,t)}}},{key:"debug",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Debug)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Debug,t)}}},{key:"info",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Info)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Info,t)}}},{key:"warn",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Warn)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Warn,t)}}},{key:"error",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Error)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Error,t)}}},{key:"fatal",value:function(){if(this._threshold.value&&!(this._threshold.value>c.Fatal)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.log(c.Fatal,t)}}},{key:"log",value:function(e,t){var n=this,i=new Date,r=this.replacePlaceholders(t);this._appenders.value.forEach((function(t){t.log(e,r,n.category,i)}))}},{key:"replacePlaceholders",value:function(e){for(var t=this,n=e[0],i=0;n.indexOf&&e.length>1&&i>=0;)if((i=n.indexOf("%",i))>0)switch(n.substring(i+1,i+2)){case"%":n=n.substring(0,i)+n.substring(i+1),i++;break;case"s":case"d":e[0]=n=this.replaceArgument(this.toString(e[1]),n,i),e.splice(1,1);break;case"j":e[0]=n=this.replaceArgument(this.stringify(e[1]),n,i),e.splice(1,1);break;default:return e.toString()}return e.length>1&&(e=e.reduce((function(e,n,i,r){return i+1===r.length&&n instanceof Error?e+"\n"+t.toString(n.stack):e+"[".concat(t.toString(n),"]")}))),e.toString()}},{key:"stringify",value:function(e){var t=[];try{return JSON.stringify(e instanceof Error?this.toString(e):e,(function(e,n){if(n&&n instanceof Object){if(t.includes(n))return"<recursive>";t.push(n)}return n}),2)}catch(e){return"[object invalid JSON.stringify]"}}},{key:"replaceArgument",value:function(e,t,n){return t.substring(0,n)+this.toString(e)+t.substring(n+2)}},{key:"toString",value:function(e){if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e)return e.toString();var t="";if(e)if("function"==typeof e)t=e.toString();else if(e instanceof Object)try{t=e.toString()}catch(e){t="[object invalid toString()]"}return t}}]),e}(),d=function(){function e(){r()(this,e),u()(this,"_appenders",[])}return a()(e,[{key:"value",get:function(){return this._appenders}},{key:"add",value:function(e){this._appenders.push(e)}},{key:"remove",value:function(e){this._appenders=this._appenders.reduce((function(t,n){return n!==e&&t.push(n),t}),[])}}]),e}(),h=function(){function e(){r()(this,e)}return a()(e,null,[{key:"sendLocalCandidates",get:function(){return this._sendLocalCandidates}},{key:"sendLogs",get:function(){return this._sendLogs}},{key:"sendMetrics",get:function(){return this._sendMetrics}},{key:"logToConsole",get:function(){return this._logToConsole}},{key:"applyFeatures",value:function(){try{var e={sendLocalCandidates:!1,sendLogs:"Off",sendMetrics:"Essential",logToConsole:"Off"};this._sendLocalCandidates=!("sendLocalCandidates"in e)||e.sendLocalCandidates,this._sendLogs="sendLogs"in e?e.sendLogs:"All",this._sendMetrics="sendMetrics"in e?e.sendMetrics:"All",this._logToConsole="logToConsole"in e?e.logToConsole:"All"}catch(e){this._sendLocalCandidates=!0,this._sendLogs="All",this._sendMetrics="All",this._logToConsole="All"}}}]),e}();u()(h,"_sendLocalCandidates",void 0),u()(h,"_sendLogs",void 0),u()(h,"_sendMetrics",void 0),u()(h,"_logToConsole",void 0),h.applyFeatures();var p=function(){function e(){r()(this,e)}return a()(e,null,[{key:"defaultLoggingLevel",get:function(){return c[h.sendLogs]}},{key:"defaultConsoleLoggingLevel",get:function(){return c[h.logToConsole]}},{key:"defaultTelemetryLoggingLevel",get:function(){return c.Info}}]),e}(),f=function(){function e(){r()(this,e),u()(this,"_threshold",p.defaultLoggingLevel)}return a()(e,[{key:"value",get:function(){return this._threshold}},{key:"setThreshold",value:function(e){this._threshold=e}}]),e}(),v=function(){function e(t){r()(this,e),u()(this,"_threshold",void 0),this._threshold=t}return a()(e,[{key:"log",value:function(e,t,n,i){if(!(e<this._threshold)){var r="".concat(i.toISOString()," [").concat(n,"] [").concat(c[e],"] ").concat(t);e<c.Warn?console.log(r):console.error(r)}}}]),e}(),m=n(926),g=n.n(m),_=n(757),y=n.n(_),C=function(){function e(){r()(this,e)}return a()(e,null,[{key:"sdkVersion",get:function(){try{return"2023-06-13T15:38:44.392Z (2023.2.4-beta.71)"}catch(e){return this._defaultVersion}}}]),e}();u()(C,"_defaultVersion",(new Date).toISOString());var b=function(){function e(t){r()(this,e),u()(this,"_telemetryConfiguration",void 0),u()(this,"_logs",[]),u()(this,"_isSending",void 0),u()(this,"_domain",location.hostname),this._telemetryConfiguration=t}var t,n;return a()(e,[{key:"push",value:function(e,t,n,i){var r={timestamp:i.toISOString(),tenancy:this._telemetryConfiguration.tenancy,level:c[e],category:n,message:t,sessionId:this._telemetryConfiguration.sessionId,version:C.sdkVersion,environment:this._telemetryConfiguration.environment,fullQualifiedName:this._domain};e<c.Error?this._logs.push(r):this._logs.unshift(r),this.sendLogsIfAble()}},{key:"sendLogs",value:(n=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=new FormData).append("jsonBody",JSON.stringify({records:t})),e.next=4,fetch(this._telemetryConfiguration.url,{method:"POST",body:n});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"sendLogsIfAble",value:(t=g()(y().mark((function e(){var t,n,i,r,o=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this._logs.length<=0||this._isSending)){e.next=2;break}return e.abrupt("return");case 2:for(t=0,n=0,this._isSending=!0,i=function(e){return Object.values(e).reduce((function(e,t){return e+(t?t.length:0)}),0)};this._logs.length>t&&i(this._logs[t])+n<8192;)n+=i(this._logs[t]),t++;return t||(this._logs[t].message=this._logs[t].message.substring(0,i(this._logs[t])+(8192-i(this._logs[t]))),t=1),r=this._logs.slice(0,t),this._logs=this._logs.slice(t),e.abrupt("return",this.sendLogs(r).then((function(e){return o._isSending=!1,o.sendLogsIfAble(),e})).catch((function(){o._isSending=!1,o.sendLogsIfAble()})));case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),k=function(){function e(t){r()(this,e),u()(this,"_telemetryService",void 0),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_threshold",void 0),this._tenancy=t.tenancy,this._sessionId=t.sessionId,this._threshold=t.threshold,this._telemetryService=new b(t)}return a()(e,[{key:"log",value:function(e,t,n,i){e<this._threshold||this._telemetryService.push(e,t,n,i)}}]),e}(),x=function(){function e(){r()(this,e),u()(this,"_url","https://telemetry.phenixrts.com/telemetry/logs"),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_environment",void 0),u()(this,"_threshold",p.defaultTelemetryLoggingLevel)}return a()(e,[{key:"url",get:function(){return this._url},set:function(e){var t=new URL(e);t.pathname=t.pathname+"/logs",this._url=t.toString()}},{key:"environment",get:function(){return this._environment},set:function(e){this._environment=e}},{key:"tenancy",get:function(){return this._tenancy},set:function(e){this._tenancy=e}},{key:"sessionId",get:function(){return this._sessionId},set:function(e){this._sessionId=e}},{key:"threshold",get:function(){return this._threshold},set:function(e){this._threshold=e}}]),e}(),w=function(){function e(){r()(this,e)}return a()(e,null,[{key:"defaultTelemetryLevel",get:function(){return S[h.sendMetrics]}}]),e}(),S=function(e){return e[e.Off=100]="Off",e[e.Essential=10]="Essential",e[e.All=-1]="All",e}({}),T=function(){function e(){r()(this,e),u()(this,"_url","https://telemetry.phenixrts.com/telemetry/metrics"),u()(this,"_tenancy",void 0),u()(this,"_sessionId",void 0),u()(this,"_environment",void 0),u()(this,"_threshold",w.defaultTelemetryLevel)}return a()(e,[{key:"url",get:function(){return this._url},set:function(e){var t=new URL(e);t.pathname=t.pathname+"/metrics",this._url=t.toString()}},{key:"environment",get:function(){return this._environment},set:function(e){this._environment=e}},{key:"tenancy",get:function(){return this._tenancy},set:function(e){this._tenancy=e}},{key:"sessionId",get:function(){return this._sessionId},set:function(e){this._sessionId=e}},{key:"threshold",get:function(){return this._threshold},set:function(e){this._threshold=e}}]),e}(),L=function(e){throw new Error("Unexpected value [".concat(e,"]. This should never be reached"))},P=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertTelemetryLevelToTelemetryLevelType",value:function(e){switch(e){case S.Off:return"Off";case S.Essential:return"Essential";case S.All:return"All";default:L(e)}}},{key:"convertTelemetryLevelTypeToTelemetryLevel",value:function(e){switch(e){case"Off":return S.Off;case"Essential":return S.Essential;case"All":return S.All;default:L(e)}}}]),e}(),R=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertLoggingLevelToLoggingLevelType",value:function(e){switch(e){case c.Off:return"Off";case c.Trace:return"Trace";case c.Debug:return"Debug";case c.Info:return"Trace";case c.Warn:return"Warn";case c.Error:return"Error";case c.Fatal:return"Fatal";case c.All:return"All";default:L(e)}}},{key:"convertLoggingLevelTypeToLoggingLevel",value:function(e){switch(e){case"Off":return c.Off;case"Trace":return c.Trace;case"Debug":return c.Debug;case"Info":return c.Info;case"Warn":return c.Warn;case"Error":return c.Error;case"Fatal":return c.Fatal;case"All":return c.All;default:L(e)}}}]),e}(),E=function(){function e(){r()(this,e)}return a()(e,[{key:"getStringValue",value:function(e){return this.defaultStringValue[e]}},{key:"getBooleanValue",value:function(e){return this.defaultBooleanValue[e]}},{key:"defaultStringValue",get:function(){return{"phenix-metrics-level":P.convertTelemetryLevelToTelemetryLevelType(w.defaultTelemetryLevel),"phenix-logging-level":R.convertLoggingLevelToLoggingLevelType(p.defaultLoggingLevel),"phenix-console-logging-level":R.convertLoggingLevelToLoggingLevelType(p.defaultConsoleLoggingLevel),"phenix-telemetry-logging-level":R.convertLoggingLevelToLoggingLevelType(p.defaultTelemetryLoggingLevel),"phenix-channel-token":"","phenix-uri":"","phenix-base-uri":""}}},{key:"defaultBooleanValue",get:function(){return{"phenix-automatically-retry-on-failure":!0,"phenix-automatically-reconnect-peer-connection":!0}}}]),e}(),O=function(){function e(){throw r()(this,e),new Error("LoggerFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"telemetryConfiguration",get:function(){return e._telemetryConfiguration}},{key:"getLogger",value:function(t){return"string"!=typeof t&&(t="SDK"),e._loggers[t]||(e._loggers[t]=new l(t,this._appenders,this._threshold))}},{key:"applyLoggerConfigFromParameterConfiguration",value:function(){e.applyLoggingLevel(),e.applyAppenderLoggingLevel("console",e.applyConsoleLogger.bind(this)),e.applyAppenderLoggingLevel("telemetry",e.applyTelemetryLogger.bind(this))}},{key:"applyLoggingLevel",value:function(){var e=this._configurationParameterReader.getStringValue("phenix-logging-level");c[e]&&this._threshold.setThreshold(c[e])}},{key:"applyAppenderLoggingLevel",value:function(e,t){var n=this._configurationParameterReader.getStringValue("phenix-".concat(e,"-logging-level"));"Off"!==n&&t(c[n])}},{key:"applyConsoleLogger",value:function(e){this._appenders.add(new v(e||p.defaultConsoleLoggingLevel))}},{key:"applyTelemetryLogger",value:function(e){this._telemetryConfiguration.threshold=e||p.defaultTelemetryLoggingLevel,this._appenders.add(new k(this._telemetryConfiguration))}}]),e}();u()(O,"_configurationParameterReader",new E),u()(O,"_loggers",{}),u()(O,"_appenders",new d),u()(O,"_threshold",new f),u()(O,"_telemetryConfiguration",new x),O.applyLoggerConfigFromParameterConfiguration();var D=function(){function e(){throw r()(this,e),new Error("Strings is a static class that may not be instantiated")}return a()(e,null,[{key:"random",value:function(e){var t=Math.ceil(e/13);return new Array(t).fill((function(){return Math.random().toString(16).substring(2,15)})).reduce((function(e,t){return e+t()}),"").substring(0,e)}}]),e}(),F=n(205),I=n.n(F),M=n(585),A=n.n(M),j=n(754),V=n.n(j),U=function(){function e(t){r()(this,e),u()(this,"_disposed",void 0),u()(this,"_disposable",void 0),this._disposed=!1,this._disposable=t}return a()(e,[{key:"dispose",value:function(){if(!this._disposed)return this._disposed=!0,this._disposable.call(this)}}]),e}();var B=function(e){I()(o,e);var t,n,i=(t=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,i=V()(t);if(n){var r=V()(this).constructor;e=Reflect.construct(i,arguments,r)}else e=i.apply(this,arguments);return A()(this,e)});function o(e,t){return r()(this,o),i.call(this,(function(){var n=e.indexOf(t);n>=0&&e.splice(n,1)}))}return a()(o)}(U),N=function(){function e(t){r()(this,e),u()(this,"_listeners",void 0),u()(this,"_value",void 0),this._listeners=[],this._value=t}return a()(e,[{key:"value",get:function(){return this._value},set:function(e){var t=this._value!==e;if(t&&e){var n=e;"function"==typeof n.equals&&(t=!n.equals(this._value))}t&&(this._value=e,this._listeners.forEach((function(t){t(e)})))}},{key:"subscribe",value:function(e){return this._listeners.push(e),e(this._value),new B(this._listeners,e)}}]),e}(),z=function(){function e(t){r()(this,e),u()(this,"_subject",void 0),this._subject=t}return a()(e,[{key:"value",get:function(){return this._subject.value}},{key:"subscribe",value:function(e){return this._subject.subscribe(e)}}]),e}(),G=function(){function e(t){var n,i;r()(this,e),u()(this,"_applicationId",void 0),u()(this,"_token",void 0),this._applicationId=(null==t?void 0:t.applicationId)||"",this._token={uri:null!=t&&null!==(n=t.token)&&void 0!==n&&n.uri?new URL(t.token.uri):null,capabilities:(null==t||null===(i=t.token)||void 0===i?void 0:i.capabilities)||[]}}return a()(e,[{key:"uri",get:function(){return this._token.uri}},{key:"capabilities",get:function(){return this._token.capabilities}},{key:"tenancy",get:function(){return this._applicationId}}]),e}(),H=function(){function e(){r()(this,e)}return a()(e,null,[{key:"parseToken",value:function(t){if(!this.isEncodedEdgeTokenValid(t))return e._logger.error("Token is not valid [%s]",t),new G(null);try{var n=atob(t.substr(7)),i=JSON.parse(n);return i.token=JSON.parse(i.token),new G(i)}catch(t){return e._logger.error("Cannot parse token value",t),new G(null)}}},{key:"isEncodedEdgeTokenValid",value:function(e){return!!e&&e.startsWith("DIGEST:")}}]),e}();u()(H,"_logger",O.getLogger("EdgeAuthParser"));var W=function(){function e(){r()(this,e)}return a()(e,null,[{key:"browserNameAndVersion",get:function(){return e._browserNameAndVersion}},{key:"browserName",get:function(){return this._browserName}},{key:"browserMajorVersion",get:function(){return this._browserMajorVersion}},{key:"isChrome69",get:function(){return e._isChrome69}},{key:"isChrome70",get:function(){return e._isChrome70}},{key:"isChrome71",get:function(){return e._isChrome71}},{key:"isChrome72",get:function(){return e._isChrome72}},{key:"isChrome74",get:function(){return e._isChrome74}},{key:"isChrome75",get:function(){return e._isChrome75}},{key:"isChrome76",get:function(){return e._isChrome76}},{key:"isChrome77",get:function(){return e._isChrome77}},{key:"parseBrowserNameAndVersion",value:function(){if(!navigator||!navigator.userAgent)return"";var t=navigator.userAgent.match(e._browserNameAndVersionRegex);return t&&t[0]?t[0]:e.parseBrowserNameAndVersionForIE()}},{key:"parseBrowserName",value:function(){if(!e._browserNameAndVersion)return"";var t=e._browserNameAndVersion.split("/");return t&&t[0]?t[0]:""}},{key:"parseBrowserMajorVersion",value:function(){if(!e._browserNameAndVersion)return 0;var t=e._browserNameAndVersion.split("/");if(!t||!t[1])return 0;var n=t[1];return n&&Number(n.split(".")[0])||0}},{key:"parseBrowserNameAndVersionForIE",value:function(){if(!navigator||!navigator.userAgent)return"";var e=navigator.userAgent,t=e.indexOf("MSIE ");if(t>0)return"IE/".concat(parseInt(e.substring(t+5,e.indexOf(".",t)),10));if(e.indexOf("Trident/")>0){var n=e.indexOf("rv:");return"IE/".concat(parseInt(e.substring(n+3,e.indexOf(".",n)),10))}return""}}]),e}();u()(W,"_browserNameAndVersionRegex",/(MSIE|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari|(?!AppleWebKit.+)Chrome|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d.apre]+)/g),u()(W,"_browserNameAndVersion",W.parseBrowserNameAndVersion()),u()(W,"_browserName",W.parseBrowserName()),u()(W,"_browserMajorVersion",W.parseBrowserMajorVersion()),u()(W,"_isChrome69",W._browserNameAndVersion.includes("Chrome/69.")),u()(W,"_isChrome70",W._browserNameAndVersion.includes("Chrome/70.")),u()(W,"_isChrome71",W._browserNameAndVersion.includes("Chrome/71.")),u()(W,"_isChrome72",W._browserNameAndVersion.includes("Chrome/72.")),u()(W,"_isChrome74",W._browserNameAndVersion.includes("Chrome/74.")),u()(W,"_isChrome75",W._browserNameAndVersion.includes("Chrome/75.")),u()(W,"_isChrome76",W._browserNameAndVersion.includes("Chrome/76.")),u()(W,"_isChrome77",W._browserNameAndVersion.includes("Chrome/77."));var J=n(8),K=n.n(J),q=function(){function e(){r()(this,e),u()(this,"_list",[])}return a()(e,[{key:"add",value:function(e){this._list.push(e)}},{key:"dispose",value:function(){this._list.forEach((function(e){return e.dispose()})),this._list.length=0}},{key:"toString",value:function(){return"DisposableList[disposables=".concat(this._list.length,"]")}}]),e}(),Q=function(){function e(){r()(this,e),u()(this,"_disposables",new q),u()(this,"_readOnlyIsForeground",void 0),u()(this,"_isForeground",void 0),u()(this,"_timeOfLastTabFocusChange",Date.now()),u()(this,"_documentFocusInterval",void 0),this._isForeground=new N(!0),this._readOnlyIsForeground=new z(this._isForeground),this.detectTabFocusChange()}return a()(e,[{key:"isForeground",get:function(){return this._readOnlyIsForeground}},{key:"getTimeSinceLastChange",value:function(){return Date.now()-this._timeOfLastTabFocusChange}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"detectTabFocusChange",value:function(){var e,t,n=this;if("object"===("undefined"==typeof document?"undefined":K()(document))){void 0!==document.msHidden?(e="msHidden",t="msvisibilitychange"):void 0!==document.webkitHidden?(e="webkitHidden",t="webkitvisibilitychange"):void 0!==document.hidden&&(e="hidden",t="visibilitychange");var i=function(){var t=!document[e];n.setFocusState(t)};void 0!==document.addEventListener&&void 0!==document[e]?(document.addEventListener(t,i,!1),this._disposables.add(new U((function(){document.removeEventListener(t,i,!1)})))):this.listenForDocumentFocus.call(this)}}},{key:"listenForDocumentFocus",value:function(){var e=this;this._documentFocusInterval=window.setInterval((function(){var t=document.hasFocus();e.setFocusState(t)}),3e3),this._disposables.add(new U((function(){e._documentFocusInterval&&clearInterval(e._documentFocusInterval),e._documentFocusInterval=null})))}},{key:"setFocusState",value:function(e){this._isForeground!==e&&(this._isForeground.value=e)}}]),e}(),Y=function(){function e(){r()(this,e)}return a()(e,null,[{key:"clientOfferDisabled",get:function(){return W.isChrome74||W.isChrome75||W.isChrome76||W.isChrome77}},{key:"addTranceiverDisabled",get:function(){return W.isChrome69||W.isChrome70||W.isChrome71||W.isChrome72}},{key:"getStatsPromiseBasedDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=66}},{key:"getCurrentOfferDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=69||"Firefox"===W.browserName&&W.browserMajorVersion<=56}},{key:"onTrackDisabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=63||"Firefox"===W.browserName&&W.browserMajorVersion<=52}},{key:"webkitRTCPeerConnectionEnabled",get:function(){return"Chrome"===W.browserName&&W.browserMajorVersion<=55}},{key:"promiseBasedPCMethodsDisabled",get:function(){return"Firefox"===W.browserName&&W.browserMajorVersion<=52}},{key:"shouldUseNativeHls",get:function(){return"Safari"===W.browserName||"SamsungBrowser"===W.browserName}},{key:"isPrecachingEnabled",get:function(){return"IE"!==W.browserName}},{key:"isInsertableStreamsSupported",get:function(){return!("undefined"==typeof MediaStreamTrackProcessor||"undefined"==typeof MediaStreamTrackGenerator)}}]),e}(),Z=n(202).default,$=function(){function e(t){r()(this,e),u()(this,"_logger",O.getLogger("VanillaPeerConnection")),u()(this,"_peerConnection",void 0),Y.webkitRTCPeerConnectionEnabled?this._peerConnection=new webkitRTCPeerConnection(t):this._peerConnection=new RTCPeerConnection(t)}var t,n,i,o;return a()(e,[{key:"native",get:function(){return this._peerConnection}},{key:"currentLocalDescription",get:function(){return this._peerConnection.currentLocalDescription}},{key:"currentRemoteDescription",get:function(){return this._peerConnection.currentRemoteDescription}},{key:"iceConnectionState",get:function(){return this._peerConnection.iceConnectionState}},{key:"supportsGetConfiguration",get:function(){return"function"==typeof this._peerConnection.getConfiguration}},{key:"supportsSetConfiguration",get:function(){return"function"==typeof this._peerConnection.setConfiguration}},{key:"supportsAddTransceiver",get:function(){return!Y.addTranceiverDisabled&&"function"==typeof this._peerConnection.addTransceiver}},{key:"createOffer",value:(o=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.promiseBasedPCMethodsDisabled){e.next=2;break}return e.abrupt("return",new Z((function(e,i){return n._peerConnection.createOffer(e,i,t)})));case 2:return e.abrupt("return",this._peerConnection.createOffer(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"createAnswer",value:(i=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.promiseBasedPCMethodsDisabled){e.next=2;break}return e.abrupt("return",new Z((function(e,i){return n._peerConnection.createAnswer(e,i,t)})));case 2:return e.abrupt("return",this._peerConnection.createAnswer(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setLocalDescription",value:(n=g()(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._peerConnection.setLocalDescription(Y.promiseBasedPCMethodsDisabled?new RTCSessionDescription(t):t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setRemoteDescription",value:(t=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(null===(n=t.sdp)||void 0===n?void 0:n.match(/a=crypto:/i))&&this._logger.warn("SDP a=crypto is not supported"),e.abrupt("return",this._peerConnection.setRemoteDescription(Y.promiseBasedPCMethodsDisabled?new RTCSessionDescription(t):t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"getSenders",value:function(){return this._peerConnection.getSenders()}},{key:"getStats",value:function(e){return this._peerConnection.getStats(e)}},{key:"getStatsLegacy",value:function(){var e=this;return new Z((function(t){e._peerConnection.getStats(t)}))}},{key:"addEventListener",value:function(e,t,n){this._peerConnection.addEventListener(e,t,n)}},{key:"removeEventListener",value:function(e,t,n){this._peerConnection.removeEventListener(e,t,n)}},{key:"addTransceiver",value:function(e,t){return this._peerConnection.addTransceiver(e,t)}},{key:"addStream",value:function(e){var t=this;e.getTracks().forEach((function(e){t._peerConnection.addTrack(e)}))}},{key:"getConfiguration",value:function(){return this._peerConnection.getConfiguration()}},{key:"setConfiguration",value:function(e){this._peerConnection.setConfiguration(e)}},{key:"ontrack",get:function(){return this._peerConnection.ontrack},set:function(e){this._peerConnection.ontrack=e}},{key:"onicecandidate",get:function(){return this._peerConnection.onicecandidate},set:function(e){this._peerConnection.onicecandidate=e}},{key:"oniceconnectionstatechange",get:function(){return this._peerConnection.oniceconnectionstatechange},set:function(e){this._peerConnection.oniceconnectionstatechange=e}},{key:"close",value:function(){this._peerConnection.close()}}]),e}(),X=$,ee=function(){function e(){r()(this,e)}var t;return a()(e,[{key:"createPeerConnection",value:(t=g()(y().mark((function e(t){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new X(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}(),te=ee,ne=function(){function e(){throw r()(this,e),new Error("PeerConnectionService is a static class that may not be instantiated")}var t,n;return a()(e,null,[{key:"peerConnectionFactory",get:function(){return e._peerConnectionFactory}},{key:"initiateInitialPrecaching",value:function(){Y.isPrecachingEnabled&&e.precacheCreatePeerConnectionOffer().catch((function(t){return e._logger.error("Failed to pre-cache peer connection offer",t)}))}},{key:"precacheCreatePeerConnectionOffer",value:(n=g()(y().mark((function t(){return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e._cached={direction:"recvonly",peerConnection:e.createPeerConnectionOffer().catch((function(t){throw e._cached=null,t}))});case 1:case"end":return t.stop()}}),t)}))),function(){return n.apply(this,arguments)})},{key:"createPeerConnectionOffer",value:(t=g()(y().mark((function t(){var n,i,r=arguments;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.length>0&&void 0!==r[0]?r[0]:"recvonly",!e._cached||e._cached.direction!==n){t.next=5;break}return i=e._cached.peerConnection,e._cached=null,t.abrupt("return",i);case 5:return t.abrupt("return",e._peerConnectionFactory.value.createPeerConnection().then(function(){var e=g()(y().mark((function e(t){var i,r,o;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.supportsAddTransceiver){e.next=11;break}return r=t.addTransceiver("audio",{direction:n}),i=t.addTransceiver("video",{direction:n}),e.t0=r,e.t1=i,e.t2=t,e.next=9,t.createOffer(void 0);case 9:return e.t3=e.sent,e.abrupt("return",{audioTransceiver:e.t0,videoTransceiver:e.t1,peerConnection:e.t2,localOffer:e.t3});case 11:return o="recvonly"===n?{offerToReceiveAudio:!0,offerToReceiveVideo:!0}:{},e.t4=t,e.next=15,t.createOffer(o);case 15:return e.t5=e.sent,e.abrupt("return",{peerConnection:e.t4,localOffer:e.t5});case 17:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 6:case"end":return t.stop()}}),t)}))),function(){return t.apply(this,arguments)})}]),e}();u()(ne,"_logger",O.getLogger("PeerConnectionService")),u()(ne,"_peerConnectionFactory",new N(new te)),u()(ne,"_cached",void 0),ne.initiateInitialPrecaching();var ie=function(){function e(){r()(this,e)}return a()(e,null,[{key:"getTelemetryUrl",value:function(e){try{var t=new URL(e),n=t.hostname.split(".");switch(t.protocol){case"ws:":t.protocol="http:";break;case"wss:":t.protocol="https:"}return 2===n.length||3===n.length&&n[n.length-2].length<=2&&n[n.length-1].length<=3?n.unshift("telemetry"):n[0].startsWith("stg-")||n[0].endsWith("-stg")||n[0].includes("-stg-")||"stg"===n[0]?n[0]="telemetry-stg":n[0].startsWith("local")||n[0].endsWith("-local")||(n[0]="telemetry"),t.hostname=n.join("."),"".concat(t.origin,"/telemetry")}catch(t){return e}}}]),e}(),re=function(){function e(){r()(this,e)}return a()(e,null,[{key:"getEnvironmentFromUrl",value:function(e){try{return new URL(e).origin}catch(e){return""}}}]),e}(),oe=function(){function e(){r()(this,e)}return a()(e,null,[{key:"discoveryParameters",get:function(){return this._discoveryParameters}},{key:"applyParameters",value:function(){try{var e={discovery:{intentions:"contribution,distribution"}};this._discoveryParameters="discovery"in e?e.discovery:{intentions:""}}catch(e){this._discoveryParameters={intentions:""}}}}]),e}();u()(oe,"_discoveryParameters",void 0),oe.applyParameters();var ae=function(){function e(){throw r()(this,e),new Error("DiscoveryUri is a static class that may not be instantiated")}return a()(e,null,[{key:"uri",get:function(){return e._discoveryUri}},{key:"buildDiscoveryUrl",value:function(e){var t=new URL(e.toString()),n=C.sdkVersion,i=oe.discoveryParameters.intentions;return t.search="?".concat(new URLSearchParams([["version",n],["intentions",i],["_","".concat(Date.now())]]).toString()),"/"===t.pathname&&(t.pathname="/pcast/endPoints"),t.toString()}}]),e}();u()(ae,"_discoveryUri",new N("https://pcast.phenixrts.com/pcast/endPoints"));var se=function(e){return e[e.TimeToFirstFrame=0]="TimeToFirstFrame",e[e.ChannelCreationTimeToFirstFrame=1]="ChannelCreationTimeToFirstFrame",e[e.Stalled=2]="Stalled",e[e.Buffering=3]="Buffering",e[e.SetupCompleted=4]="SetupCompleted",e[e.SetupFailed=5]="SetupFailed",e[e.RoundTripTime=6]="RoundTripTime",e[e.DownlinkThroughputCapacity=7]="DownlinkThroughputCapacity",e[e.NetworkType=8]="NetworkType",e[e.ResolutionChanged=9]="ResolutionChanged",e[e.ApplicationForeground=10]="ApplicationForeground",e[e.ApplicationBackground=11]="ApplicationBackground",e}(se||{}),ue=se,ce=function(){function e(t){r()(this,e),u()(this,"_metrics",void 0),this._metrics=t}return a()(e,[{key:"getName",value:function(){return ue[this._metrics]}},{key:"getTelemetryLevel",value:function(){switch(this._metrics){case ue.TimeToFirstFrame:case ue.ChannelCreationTimeToFirstFrame:return S.Essential;case ue.Stalled:case ue.Buffering:case ue.SetupCompleted:case ue.SetupFailed:case ue.RoundTripTime:case ue.DownlinkThroughputCapacity:case ue.NetworkType:case ue.ResolutionChanged:case ue.ApplicationForeground:case ue.ApplicationBackground:return S.All;default:L(this._metrics)}}}]),e}(),le=function(){function e(t){r()(this,e),u()(this,"_metricsConfiguration",void 0),u()(this,"_metrics",[]),u()(this,"_isSending",void 0),u()(this,"_domain",location.hostname),this._metricsConfiguration=t}var t,n;return a()(e,[{key:"metricsConfiguration",get:function(){return this._metricsConfiguration}},{key:"push",value:function(e){var t=e.streamId,n=e.value,i=e.previousValue,r=e.runtime,o=e.resource,a=e.kind,s=new ce(e.metricType);if(!(this._metricsConfiguration.threshold>s.getTelemetryLevel())){var u={timestamp:(new Date).toISOString(),tenancy:this._metricsConfiguration.tenancy,sessionId:this._metricsConfiguration.sessionId,streamId:t,metric:s.getName(),value:n,previousValue:i,fullQualifiedName:this._domain,environment:this._metricsConfiguration.environment,version:C.sdkVersion,runtime:r,resource:o,kind:a};this._metrics.push(u),this.sendMetricsIfAble()}}},{key:"sendMetrics",value:(n=g()(y().mark((function e(t){var n;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=new FormData).append("jsonBody",JSON.stringify({records:t})),e.next=4,fetch(this._metricsConfiguration.url,{method:"POST",body:n});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"sendMetricsIfAble",value:(t=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this._metrics.length<=0||this._isSending)){e.next=2;break}return e.abrupt("return");case 2:return this._isSending=!0,t=this._metrics.slice(0,1024),this._metrics=this._metrics.slice(1024),e.abrupt("return",this.sendMetrics(t).then((function(e){return n._isSending=!1,n.sendMetricsIfAble(),e})).catch((function(){n._isSending=!1,n.sendMetricsIfAble()})));case 6:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),de=function(){function e(){throw r()(this,e),new Error("LoggerFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"getMetricsService",value:function(t){if("string"!=typeof t)throw new Error("ur");var n=e._metricsServices[t];if(n)return n;var i=new T;return i.sessionId=pe.clientSessionId,i.tenancy=pe.tenancy.value,i.url=ie.getTelemetryUrl(t),i.environment=re.getEnvironmentFromUrl(t),i.threshold=P.convertTelemetryLevelTypeToTelemetryLevel(pe.telemetryLevel),e._metricsServices[t]=new le(i)}},{key:"setTelemetryLevel",value:function(t){var n=Object.values(e._metricsServices);n&&n.length&&n.forEach((function(e){e.metricsConfiguration.threshold=t}))}}]),e}();u()(de,"_metricsServices",{});var he=window.__phenixPageLoadTime||window.__pageLoadTime||Date.now(),pe=function(){function e(){throw r()(this,e),new Error("SDK is a static class that may not be instantiated")}return a()(e,null,[{key:"pageLoadTime",get:function(){return he}},{key:"sendLocalCandidates",get:function(){return this._sendLocalCandidates}},{key:"tenancy",get:function(){return this._tenancy}},{key:"clientSessionId",get:function(){return e._clientSessionId}},{key:"loadedTimestamp",get:function(){return e._loadedTimestamp}},{key:"initialized",get:function(){return e._readOnlyInitialized}},{key:"discoveryUri",get:function(){return e._readOnlyDiscoveryUri}},{key:"peerConnectionFactory",get:function(){return e._readOnlyPeerConnectionFactory}},{key:"automaticRetryOnFailure",get:function(){return e._automaticallyRetryOnFailure}},{key:"automaticallyReconnectPeerConnection",get:function(){return e._automaticallyReconnectPeerConnection}},{key:"automaticallyPlayMediaStream",get:function(){return e._automaticallyPlayMediaStream}},{key:"automaticallyMuteVideoOnPlayFailure",get:function(){return e._automaticallyMuteVideoOnPlayFailure}},{key:"webPlayerLoader",get:function(){return this._webPlayerLoader}},{key:"shakaPlayerLoader",get:function(){return this._shakaPlayerLoader}},{key:"hlsJsLoader",get:function(){return this._hlsJsLoader}},{key:"metricsService",get:function(){return e._metricsService}},{key:"applicationActivityMonitor",get:function(){return this._applicationActivityMonitor}},{key:"telemetryUrl",get:function(){return this._telemetryUrl}},{key:"maximalNumberOfPeerConnectionReconnectAttempts",get:function(){return this._maximalNumberOfPeerConnectionReconnectAttempts},set:function(e){this._maximalNumberOfPeerConnectionReconnectAttempts=e}},{key:"loggingLevel",get:function(){return R.convertLoggingLevelToLoggingLevelType(this._logger.threshold.value)}},{key:"telemetryLevel",get:function(){return P.convertTelemetryLevelToTelemetryLevelType(e._telemetryLevel.value)}},{key:"browserDetector",get:function(){return W}},{key:"applyTelemetryConfiguration",value:function(){var t=this,n=O.telemetryConfiguration;n.sessionId=e.clientSessionId,e._environment.subscribe((function(e){n.environment=e})),e.telemetryUrl.subscribe((function(e){var i=t._logger.appenders.value.find((function(e){return e instanceof k}));i&&(n.url=e,t._logger.appenders.remove(i),t._logger.appenders.add(new k(n)),t._logger.info("Telemetry URL was set to [%s]",n.url))})),e._tenancy.subscribe((function(e){var i=t._logger.appenders.value.find((function(e){return e instanceof k}));i&&e&&(n.tenancy=e,t._logger.appenders.remove(i),t._logger.appenders.add(new k(n)),t._logger.info("Telemetry tenancy was set to [%s]",n.tenancy))}))}},{key:"applyMetricsConfiguration",value:function(){e._metricsService=de.getMetricsService(ae.uri.value),e._metricsConfiguration=e._metricsService.metricsConfiguration,e._metricsConfiguration.sessionId=e.clientSessionId,e._environment.subscribe((function(t){e._metricsConfiguration.environment=t})),e.telemetryUrl.subscribe((function(t){e._metricsConfiguration.url=t})),e._tenancy.subscribe((function(t){e._metricsConfiguration.tenancy=t}));var t=this._configurationParameterReader.getStringValue("phenix-metrics-level");t&&de.setTelemetryLevel(S[t]),e._telemetryLevel.subscribe((function(e){de.setTelemetryLevel(e)}))}},{key:"applyAutomaticallyRetryOnFailureFromParameterConfiguration",value:function(){this._automaticallyRetryOnFailure=this._configurationParameterReader.getBooleanValue("phenix-automatically-retry-on-failure"),this._logger.info("Automatically retry on failure is set to: [%s]",this._automaticallyRetryOnFailure)}},{key:"applyAutomaticallyReconnectPeerConnectionFromParameterConfiguration",value:function(){this._automaticallyReconnectPeerConnection=this._configurationParameterReader.getBooleanValue("phenix-automatically-reconnect-peer-connection"),this._logger.info("Automatically reconnect peer connection is set to: [%s]",this._automaticallyReconnectPeerConnection)}},{key:"applyDiscoveryUriDefaultFromParameterConfiguration",value:function(){e.discoveryUri.subscribe((function(t){e.telemetryUrl.value=e.getTelemetryUrl(t),e._environment.value=re.getEnvironmentFromUrl(t)}));var t=this._configurationParameterReader.getStringValue("phenix-channel-token");if(t){var n=H.parseToken(t);return e._tenancy.value=n.tenancy,ae.uri.value=(n.uri||e.discoveryUri.value).toString(),void this._logger.info("Discovery URI set from configuration parameter to [%s]",e.discoveryUri.value)}var i=this._configurationParameterReader.getStringValue("phenix-uri");if(i)return ae.uri.value=i,void this._logger.info('Discovery URI set from "phenix-uri" configuration parameter tag to [%s]',e.discoveryUri.value);var r=this._configurationParameterReader.getStringValue("phenix-base-uri");return r?(ae.uri.value="".concat(r,"/pcast/endPoints"),void this._logger.info('Discovery URI set from "phenix-base-uri" configuration parameter tag to [%s]',e.discoveryUri.value)):void 0}},{key:"init",value:function(t){if(this._initialized.value||(this._applicationActivityMonitor=new Q),t){if(t.discoveryUri&&(ae.uri.value=t.discoveryUri),t.peerConnectionFactory&&(ne.peerConnectionFactory.value=t.peerConnectionFactory),t.telemetryLevel&&S[t.telemetryLevel]&&(e._telemetryLevel.value=P.convertTelemetryLevelTypeToTelemetryLevel(t.telemetryLevel)),t.loggingLevel&&c[t.loggingLevel]&&this._logger.threshold.setThreshold(R.convertLoggingLevelTypeToLoggingLevel(t.loggingLevel)),t.consoleLoggingLevel&&c[t.consoleLoggingLevel]){var n=this._logger.appenders.value.find((function(e){return e instanceof v}));n&&this._logger.appenders.remove(n),"Off"!==t.consoleLoggingLevel&&this._logger.appenders.add(new v(R.convertLoggingLevelTypeToLoggingLevel(t.consoleLoggingLevel)))}"boolean"==typeof t.automaticallyPlayMediaStream&&(this._automaticallyPlayMediaStream=t.automaticallyPlayMediaStream),"boolean"==typeof t.automaticallyMuteVideoOnPlayFailure&&(this._automaticallyMuteVideoOnPlayFailure=t.automaticallyMuteVideoOnPlayFailure),t.webPlayerLoader&&(this._webPlayerLoader=t.webPlayerLoader),t.shakaPlayerLoader&&(this._shakaPlayerLoader=t.shakaPlayerLoader),t.hlsJsLoader&&(this._hlsJsLoader=t.hlsJsLoader)}e._initialized.value=!0}},{key:"dispose",value:function(){e._initialized.value=!1,this._applicationActivityMonitor.dispose(),this._applicationActivityMonitor=null}},{key:"getTelemetryUrl",value:function(e){return ie.getTelemetryUrl(e)}}]),e}();u()(pe,"_automaticallyRetryOnFailure",!0),u()(pe,"_automaticallyReconnectPeerConnection",!0),u()(pe,"_automaticallyPlayMediaStream",!0),u()(pe,"_automaticallyMuteVideoOnPlayFailure",!0),u()(pe,"_webPlayerLoader",null),u()(pe,"_shakaPlayerLoader",null),u()(pe,"_hlsJsLoader",null),u()(pe,"_configurationParameterReader",new E),u()(pe,"_applicationActivityMonitor",void 0),u()(pe,"_environment",new N("")),u()(pe,"_telemetryUrl",new N("https://telemetry.phenixrts.com/telemetry")),u()(pe,"_maximalNumberOfPeerConnectionReconnectAttempts",8),u()(pe,"_telemetryLevel",new N(w.defaultTelemetryLevel)),u()(pe,"_metricsService",void 0),u()(pe,"_metricsConfiguration",void 0),u()(pe,"_sendLocalCandidates",new N(h.sendLocalCandidates)),u()(pe,"_tenancy",new N("")),u()(pe,"_clientSessionId",D.random(32)),u()(pe,"_loadedTimestamp",new Date),u()(pe,"_logger",O.getLogger("SDK")),u()(pe,"_initialized",new N(!1)),u()(pe,"_readOnlyInitialized",new z(pe._initialized)),u()(pe,"_readOnlyDiscoveryUri",new z(ae.uri)),u()(pe,"_readOnlyPeerConnectionFactory",new z(ne.peerConnectionFactory)),window.addEventListener("unload",(function(){pe.dispose()})),pe.applyDiscoveryUriDefaultFromParameterConfiguration(),pe.applyMetricsConfiguration(),pe.applyTelemetryConfiguration(),pe.applyAutomaticallyRetryOnFailureFromParameterConfiguration(),pe.applyAutomaticallyReconnectPeerConnectionFromParameterConfiguration(),pe.init();var fe=function(){function e(t,n){r()(this,e),u()(this,"width",void 0),u()(this,"height",void 0),this.width=t,this.height=n}return a()(e,[{key:"equals",value:function(e){return e&&this.width===e.width&&this.height===e.height}},{key:"toString",value:function(){return"".concat(this.width,"x").concat(this.height)}}],[{key:"empty",get:function(){return new e(0,0)}}]),e}(),ve=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e5;r()(this,e),u()(this,"_backoffIntervalInMillisecond",void 0),u()(this,"_minBackoffIntervalInMillisecond",void 0),u()(this,"_maxBackoffIntervalInMillisecond",void 0),this._backoffIntervalInMillisecond=t,this._minBackoffIntervalInMillisecond=n,this._maxBackoffIntervalInMillisecond=i}return a()(e,[{key:"getExponentialBackoffIntervalByFailureCount",value:function(e){var t=this._backoffIntervalInMillisecond/1e3,n=.5+.5*Math.random(),i=Math.pow(t,e-2),r=Math.floor(i)*n,o=Math.ceil(Math.max(1e3*r,this._minBackoffIntervalInMillisecond));return Math.min(o,this._maxBackoffIntervalInMillisecond)}}]),e}(),me=function(e){return e[e.Offline=1]="Offline",e[e.Starting=2]="Starting",e[e.Paused=3]="Paused",e[e.Playing=4]="Playing",e[e.Recovering=5]="Recovering",e[e.Reconnecting=6]="Reconnecting",e[e.StandBy=7]="StandBy",e[e.Stopped=8]="Stopped",e[e.Unauthorized=9]="Unauthorized",e[e.GeoRestricted=10]="GeoRestricted",e[e.GeoBlocked=11]="GeoBlocked",e[e.UnsupportedFeature=12]="UnsupportedFeature",e[e.ConfigurationError=13]="ConfigurationError",e[e.Error=14]="Error",e}(me||{}),ge=me,_e=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;r()(this,e),u()(this,"_duration",void 0),this._duration=t}return a()(e,[{key:"toIsoString",value:function(){if(0===this._duration)return"P0S";var e=this._duration<0,t=e?Math.abs(this._duration):this._duration,n=Math.floor(t),i=n%1e3,r=(n=Math.floor(n/1e3))%60,o=(n=Math.floor(n/60))%60,a=(n=Math.floor(n/60))%24,s=["PT"];return e&&s.unshift("-"),a&&s.push(a+"H"),o&&s.push(o+"M"),(r||i)&&(s.push(String(r)),i&&s.push("."+this.padStart(i.toString(),3,"0")),s.push("S")),s.join("")}},{key:"padStart",value:function(e,t,n){return t>>=0,n=String(void 0!==n?n:" "),e.length>t?e:((t-=e.length)>n.length&&(n+=n.repeat(t/n.length)),n.slice(0,t)+e)}}]),e}(),ye=function(){function e(t,n,i,o){r()(this,e),u()(this,"_pageLoadTime",void 0),u()(this,"_channelStartTime",void 0),u()(this,"_logger",O.getLogger("StreamTelemetry")),u()(this,"_disposables",new q),u()(this,"_streamId",void 0),u()(this,"_metricsService",void 0),u()(this,"_listenToFirstTime",void 0),u()(this,"_listenForStall",void 0),u()(this,"_listenForContinuation",void 0),u()(this,"_timeToFirstFrame",void 0),u()(this,"_channelCreationTimeToFirstFrame",void 0),u()(this,"_startRecordingFirstFrame",void 0),u()(this,"_videoStalled",void 0),u()(this,"_lastProgress",void 0),u()(this,"_videoResolution",void 0),u()(this,"_clearTimeToFirstFrameListener",void 0),u()(this,"_clearRebufferingListener",void 0),this._streamId=t,this._pageLoadTime=n,this._channelStartTime=i,this._metricsService=o}return a()(e,[{key:"setupListenerForTimeToFirstTime",value:function(e){var t=this;this._startRecordingFirstFrame=Date.now(),this._listenToFirstTime=function(){return t.callTimeToFirstFrame()},e.addEventListener("loadeddata",this._listenToFirstTime),e.addEventListener("loadedmetadata",this._listenToFirstTime),this._clearTimeToFirstFrameListener=new U((function(){e.removeEventListener("loadeddata",t._listenToFirstTime),e.removeEventListener("loadedmetadata",t._listenToFirstTime)})),this._disposables.add(this._clearTimeToFirstFrameListener)}},{key:"setupListenerForRebuffering",value:function(e){var t=this;this._listenForStall=function(){return t.onStall()},this._listenForContinuation=function(n){return t.onContinuation(n,e)},e.addEventListener("stalled",this._listenForStall),e.addEventListener("pause",this._listenForStall),e.addEventListener("suspend",this._listenForStall),e.addEventListener("play",this._listenForContinuation),e.addEventListener("playing",this._listenForContinuation),e.addEventListener("progress",this._listenForContinuation),e.addEventListener("timeupdate",this._listenForContinuation),this._clearRebufferingListener=new U((function(){e.removeEventListener("stalled",t._listenForStall),e.removeEventListener("pause",t._listenForStall),e.removeEventListener("suspend",t._listenForStall),e.removeEventListener("play",t._listenForContinuation),e.removeEventListener("playing",t._listenForContinuation),e.removeEventListener("progress",t._listenForContinuation),e.removeEventListener("timeupdate",t._listenForContinuation)})),this._disposables.add(this._clearRebufferingListener)}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"durationSincePageLoad",get:function(){var e=Date.now();return new _e(e-this._pageLoadTime).toIsoString()}},{key:"callTimeToFirstFrame",value:function(){var e=Date.now();this.pushTimeToFirstFrame(e),this.pushChannelCreationTimeToFirstFrame(e),this._clearTimeToFirstFrameListener.dispose()}},{key:"pushTimeToFirstFrame",value:function(e){this._timeToFirstFrame=e-this._startRecordingFirstFrame,this._metricsService.push({metricType:ue.TimeToFirstFrame,runtime:(e-this._pageLoadTime)/1e3,value:{uint64:this._timeToFirstFrame},streamId:this._streamId}),this._logger.info("[%s] [%s] First frame [%s]",this.durationSincePageLoad,this._streamId,new _e(this._timeToFirstFrame).toIsoString())}},{key:"pushChannelCreationTimeToFirstFrame",value:function(e){this._channelCreationTimeToFirstFrame=e-this._channelStartTime,this._metricsService.push({metricType:ue.ChannelCreationTimeToFirstFrame,runtime:(e-this._pageLoadTime)/1e3,value:{uint64:this._channelCreationTimeToFirstFrame},streamId:this._streamId}),this._logger.info("[%s] [%s] Channel creation to first frame [%s]",this.durationSincePageLoad,this._streamId,new _e(this._channelCreationTimeToFirstFrame).toIsoString())}},{key:"onStall",value:function(){this._videoStalled||(this._metricsService.push({metricType:ue.Stalled,runtime:(Date.now()-this._pageLoadTime)/1e3,streamId:this._streamId}),this._videoStalled=Date.now(),this._logger.info("[%s] [%s] [buffering] Stream has stalled",this.durationSincePageLoad,this._streamId))}},{key:"onContinuation",value:function(e,t){if(t.buffered){var n=t.buffered.length,i=!("playing"===e.type||n>0)||("progress"===e.type||"timeupdate"===e.type)&&t.buffered.end(n-1)===this._lastProgress;if(this._videoStalled&&!i){"progress"===e.type&&(this._lastProgress=t.buffered.end(n-1));var r=Date.now()-this._videoStalled;this._metricsService.push({metricType:ue.Buffering,runtime:(Date.now()-this._pageLoadTime)/1e3,value:{uint64:r},streamId:this._streamId}),this._logger.info("[%s] [%s] [buffering] Stream has recovered from stall after [%s]",this.durationSincePageLoad,this._streamId,new _e(r).toIsoString()),this._videoStalled=null}}}},{key:"onVideoResolutionChanges",value:function(e){this._metricsService.push({metricType:ue.ResolutionChanged,runtime:(Date.now()-this._pageLoadTime)/1e3,value:{string:e},previousValue:this._videoResolution?{string:this._videoResolution}:void 0,streamId:this._streamId}),this._videoResolution=e}}]),e}(),Ce=function(){function e(t){r()(this,e),u()(this,"_logger",O.getLogger("StreamSetupListener")),u()(this,"metricsService",pe.metricsService),u()(this,"_pageLoadTime",void 0),u()(this,"_startTime",void 0),u()(this,"_metricSubmitted",!1),this._startTime=Date.now(),this._pageLoadTime=t}return a()(e,[{key:"success",value:function(e){this.recordStreamMetric(ue.SetupCompleted,e)}},{key:"fail",value:function(){this.recordStreamMetric(ue.SetupFailed)}},{key:"recordStreamMetric",value:function(e,t){if(!this._metricSubmitted){this._metricSubmitted=!0;var n=Date.now(),i=n-this._startTime,r=new ce(e).getName();this.metricsService.push({metricType:e,runtime:(n-this._pageLoadTime)/1e3,value:{uint64:i},streamId:t}),this._logger.info("[%s] [%s] Stream metric [%s] in [%s]",new _e(n-this._pageLoadTime).toIsoString(),t,r,new _e(i).toIsoString())}}}]),e}(),be=function(){function e(){r()(this,e),u()(this,"_disposables",new q),u()(this,"_isSupported",navigator&&navigator.connection),u()(this,"_rtt",new N(void 0)),u()(this,"_effectiveType",new N(void 0)),u()(this,"_downlinkThroughputCapacity",new N(void 0)),this.isSupported&&(this.setupNetworkChangeListeners(),this.updateStatistics())}return a()(e,[{key:"isSupported",get:function(){return this._isSupported}},{key:"rtt",get:function(){return this._rtt}},{key:"effectiveType",get:function(){return this._effectiveType}},{key:"downlinkThroughputCapacity",get:function(){return this._downlinkThroughputCapacity}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"getDownlinkThroughputCapacity",value:function(){return this.isSupported?navigator.connection.downlink||navigator.connection.downlinkMax:-1}},{key:"getEffectiveType",value:function(){return this.isSupported?navigator.connection.effectiveType||navigator.connection.type:"Unknown"}},{key:"getRoundTripTime",value:function(){return navigator.connection.rtt}},{key:"setupNetworkChangeListeners",value:function(){var e=this,t=function(){e.updateStatistics()};navigator.connection.addEventListener("change",t),this._disposables.add(new U((function(){navigator.connection.removeEventListener("change",t)})))}},{key:"updateStatistics",value:function(){this._rtt.value=this.getRoundTripTime(),this._effectiveType.value=this.getEffectiveType(),this._downlinkThroughputCapacity.value=this.getDownlinkThroughputCapacity()}}]),e}(),ke=function(){function e(t,n){var i=this;r()(this,e),u()(this,"_logger",O.getLogger("SessionTelemetry")),u()(this,"_metricsService",void 0),u()(this,"_applicationActivityMonitor",pe.applicationActivityMonitor),u()(this,"_networkMonitor",new be),u()(this,"_pageLoadTime",void 0),u()(this,"_disposables",new q),u()(this,"_lastNetworkStatistics",{}),this._pageLoadTime=t,this._disposables.add(this._networkMonitor),this._metricsService=n,this._networkMonitor.isSupported&&(this._disposables.add(this._applicationActivityMonitor.isForeground.subscribe((function(e){i.recordForegroundChange(e)}))),this._disposables.add(this._networkMonitor.rtt.subscribe((function(e){i.recordNetworkRTTUpdate(e)}))),this._disposables.add(this._networkMonitor.effectiveType.subscribe((function(e){i.recordNetworkTypeChangeUpdate(e)}))),this._disposables.add(this._networkMonitor.downlinkThroughputCapacity.subscribe((function(e){i.recordNetworkDownlinkThroughputCapacityUpdate(e)}))))}return a()(e,[{key:"listenOnStreamSetup",value:function(){return new Ce(this._pageLoadTime)}},{key:"dispose",value:function(){this._disposables.dispose()}},{key:"recordForegroundChange",value:function(e){var t=Date.now(),n=this._applicationActivityMonitor.getTimeSinceLastChange();this._metricsService.push({metricType:e?ue.ApplicationForeground:ue.ApplicationBackground,runtime:(t-this._pageLoadTime)/1e3,value:{uint64:n}}),this._logger.info("Application has gone into the [%s] after [%s] ms",e?"foreground":"background",new _e(n).toIsoString())}},{key:"recordNetworkRTTUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.rtt;this._lastNetworkStatistics.rtt=e,this._metricsService.push({metricType:ue.RoundTripTime,runtime:(t-this._pageLoadTime)/1e3,value:{uint64:e},previousValue:n?{uint64:n}:void 0,resource:"navigator"}),this._logger.info("[%s] Network RTT changed to [%s] from [%s]",new _e(t-this._pageLoadTime).toIsoString(),e,n)}},{key:"recordNetworkTypeChangeUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.effectiveType;this._lastNetworkStatistics.effectiveType=e,this._metricsService.push({metricType:ue.NetworkType,runtime:(t-this._pageLoadTime)/1e3,value:{string:e},previousValue:n?{string:n}:void 0}),this._logger.info("[%s] Network effective type has changed to [%s] from [%s]",new _e(t-this._pageLoadTime).toIsoString(),e,n)}},{key:"recordNetworkDownlinkThroughputCapacityUpdate",value:function(e){var t=Date.now(),n=this._lastNetworkStatistics.downlinkThroughputCapacity;this._lastNetworkStatistics.downlinkThroughputCapacity=e,this._metricsService.push({metricType:ue.DownlinkThroughputCapacity,runtime:(t-this._pageLoadTime)/1e3,value:{float:e},previousValue:n?{float:n}:void 0}),this._logger.info("[%s] Network downlink throughput capacity changed to [%s] from [%s]",new _e(t-this._pageLoadTime).toIsoString(),e,n)}}]),e}(),xe=function(e){return e[e.Keep=0]="Keep",e[e.Reset=1]="Reset",e}({}),we=function(e){return e[e.Normal=0]="Normal",e[e.Force=1]="Force",e[e.Reset=2]="Reset",e}({}),Se=a()((function e(t){r()(this,e),u()(this,"token",void 0),u()(this,"tokenExpiring",void 0),this.token=new N(t),this.tokenExpiring=new N(!1)})),Te=function(){function e(t){var n;r()(this,e),u()(this,"channelInitialization",void 0),u()(this,"disposables",void 0),u()(this,"channelDisposables",void 0),u()(this,"rendererDisposables",void 0),u()(this,"videoElement",void 0),u()(this,"state",void 0),u()(this,"autoMuted",void 0),u()(this,"autoPaused",void 0),u()(this,"authorized",void 0),u()(this,"online",void 0),u()(this,"loading",void 0),u()(this,"playing",void 0),u()(this,"standby",void 0),u()(this,"stopped",void 0),u()(this,"targetLag",void 0),u()(this,"lag",void 0),u()(this,"bitrateLimit",void 0),u()(this,"resolution",void 0),u()(this,"failureCount",void 0),u()(this,"endPoint",void 0),u()(this,"stream",void 0),u()(this,"rtcStatistics",void 0),u()(this,"videoTelemetry",void 0),u()(this,"rtcAudioStatistic",void 0),u()(this,"rtcVideoStatistic",void 0),u()(this,"clearFailureCountTimeout",void 0),u()(this,"videoStreamTransformCallback",void 0),u()(this,"hasInsertableStreams",void 0),this.disposables=new q,this.channelDisposables=new q,this.rendererDisposables=new q,this.channelInitialization=new Date,this.videoElement=new N(null),this.state=new N(ge.Starting),this.autoMuted=new N(!1),this.autoPaused=new N(!1),this.authorized=new N(!0),this.online=new N(!0),this.loading=new N(!1),this.playing=new N(!1),this.standby=new N(!1),this.stopped=new N(!1),this.targetLag=new N(null!==(n=null==t?void 0:t.targetLag)&&void 0!==n?n:0),this.lag=new N(0),this.bitrateLimit=new N(0),this.resolution=new N(fe.empty),this.failureCount=new N(0),this.endPoint=new N(null),this.stream=new N(null),this.rtcStatistics=new N(null),this.videoStreamTransformCallback=null==t?void 0:t.videoStreamTransformCallback,this.hasInsertableStreams=new N(!(null==t||!t.hasInsertableStreams))}return a()(e,[{key:"streamId",get:function(){var e=this.stream.value;return e?e.streamId:"-"}},{key:"applyStatus",value:function(e){switch(e){case"ok":break;case"unauthorized":case"geo-restricted":case"geo-blocked":this.authorized.value=!1;case"no-stream":case"not-found":return this.failureCount.value=0,this.playing.value=!1,this.standby.value=!0,this.stopped.value=!1,void(this.stream.value=null);default:return this.failureCount.value++,this.playing.value=!1,this.standby.value=!0,this.stopped.value=!1,this.stream.value=null,void(this.state.value=ge.Error)}}},{key:"applySessionAndStreamPropertiesToVideoElement",value:function(){this.videoElement.value&&this.videoElement.value.dataset&&(this.videoElement.value.dataset.sessionId=pe.clientSessionId,this.videoElement.value.dataset.streamId=this.streamId)}},{key:"mapSubscribeStatusToChannelStatus",value:function(e){switch(e){case"ok":return ge.Starting;case"no-stream":case"not-found":return ge.StandBy;case"geo-restricted":return ge.GeoRestricted;case"geo-blocked":return ge.GeoBlocked;case"unauthorized":return ge.Unauthorized;case"capacity":case"rate-limited":case"timeout":return ge.Recovering;case"failed":return ge.Error;default:L(e)}}}]),e}(),Le=a()((function e(){r()(this,e),u()(this,"mediaStream",void 0),u()(this,"peerConnection",void 0),u()(this,"peerConnectionReconnectAttempts",void 0),this.mediaStream=new N(null),this.peerConnection=new N(null),this.peerConnectionReconnectAttempts=0})),Pe=a()((function e(){r()(this,e),u()(this,"isStarting",void 0),u()(this,"isDisposed",void 0),this.isStarting=new N(!1),this.isDisposed=!1})),Re=n(38),Ee=n.n(Re),Oe=n(319),De=n.n(Oe),Fe=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertBitrateModeToBitrateModeType",value:function(e){switch(e){case we.Normal:return"Normal";case we.Force:return"Force";case we.Reset:return"Reset";default:L(e)}}}]),e}(),Ie=function(){function e(){r()(this,e)}return a()(e,null,[{key:"convertBitrateStateToBitrateStateType",value:function(e){switch(e){case xe.Keep:return"Keep";case xe.Reset:return"Reset";default:L(e)}}}]),e}(),Me=n(202).default,Ae=function(){function e(t,n){if(r()(this,e),u()(this,"_logger",O.getLogger("EndPoint")),u()(this,"_uri",void 0),u()(this,"_timeout",void 0),u()(this,"_roundTripTime",void 0),this._uri=t,this._timeout=n,!n)throw new Error("End point requires a timeout")}var t,n,i,o,s,c,l,d,h,p,f,v,m;return a()(e,[{key:"roundTripTime",get:function(){return this._roundTripTime}},{key:"toString",value:function(){return"EndPoint[uri=".concat(this._uri,"]")}},{key:"ping",value:(m=g()(y().mark((function e(){var t,n,i,r,o=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.buildPingUrl(),n=Date.now(),e.next=4,Me.race([fetch(t,{method:"GET",cache:"no-cache"}),new Me((function(e,n){return setTimeout((function(){return n(new Error("Ping timed out [".concat(t,"]")))}),o._timeout)}))]);case 4:if(i=e.sent,r=Date.now(),i.ok){e.next=8;break}throw new Error("Ping failed [".concat(t,"] [").concat(i.status,"]"));case 8:return this._roundTripTime=r-n,e.abrupt("return",this._roundTripTime);case 10:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"subscribe",value:(v=g()(y().mark((function e(t,n,i){var r,o,a,s,u,c,l,d,h,p,f,v,m=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=H.parseToken(t).tenancy){e.next=4;break}return this._logger.error("Failed to parse token [%s]",t),e.abrupt("return",{status:"unauthorized"});case 4:return o=this.buildUrl([r,"stream","subscribe"]).toString(),a=new FormData,s=C.sdkVersion,0===i&&n?(u={apiVersion:7,clientVersion:s,bearerToken:t,failureCount:i,httpRoundTripTime:this._roundTripTime,setRemoteDescription:{apiVersion:7,sessionDescription:{type:n.type,sdp:n.sdp}},createAnswerDescription:{apiVersion:7}},a.append("jsonBody",JSON.stringify(u))):(c={apiVersion:7,clientVersion:s,bearerToken:t,failureCount:i,httpRoundTripTime:this._roundTripTime,createOfferDescription:{apiVersion:7}},a.append("jsonBody",JSON.stringify(c))),l=Date.now(),e.prev=9,h=null,e.next=13,Me.race([fetch(o,{method:"POST",body:a}),new Me((function(e){return h=window.setTimeout((function(){m._logger.error("Failed to subscribe",new Error("Subscribe timed out [".concat(o,"]"))),e({status:408})}),m._timeout)}))]).finally((function(){h&&clearTimeout(h)}));case 13:d=e.sent,e.next=20;break;case 16:return e.prev=16,e.t0=e.catch(9),this._logger.error("Failed to subscribe",e.t0),e.abrupt("return",{status:"failed"});case 20:if("ok"===(p=this.mapHttpStatusToSubscribeStatus(d))){e.next=23;break}return e.abrupt("return",{status:p});case 23:return f=Date.now(),e.next=26,this.convertHttpResponseToSubscribeResponse(r,d);case 26:return v=e.sent,this._logger.debug("Got subscribe response [%j] in [%s] ms",v,f-l),e.abrupt("return",v);case 29:case"end":return e.stop()}}),e,this,[[9,16]])}))),function(e,t,n){return v.apply(this,arguments)})},{key:"publish",value:(f=g()(y().mark((function e(t,n,i,r){var o,a,s,u,c,l,d,h,p,f,v,m,g=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=H.parseToken(n).tenancy){e.next=4;break}return this._logger.error("Failed to parse token [%s]",n),e.abrupt("return",{status:"unauthorized"});case 4:return a=this.buildUrl([o,"stream","publish"]).toString(),s=new FormData,u=C.sdkVersion,0===r&&i?(c={apiVersion:7,clientVersion:u,bearerToken:n,failureCount:r,httpRoundTripTime:this._roundTripTime,name:t,setRemoteDescription:{apiVersion:7,sessionDescription:{type:i.type,sdp:i.sdp}},createAnswerDescription:{streamId:"",options:["upload"],apiVersion:7}},s.append("jsonBody",JSON.stringify(c))):(l={apiVersion:7,clientVersion:u,bearerToken:n,failureCount:r,httpRoundTripTime:this._roundTripTime,name:t,createOfferDescription:{streamId:"",options:["upload"],apiVersion:7}},s.append("jsonBody",JSON.stringify(l))),d=Date.now(),e.prev=9,p=null,e.next=13,Me.race([fetch(a,{method:"POST",body:s}),new Me((function(e){return p=window.setTimeout((function(){g._logger.error("Failed to publish",new Error("Publish timed out [".concat(a,"]"))),e({status:408})}),g._timeout)}))]).finally((function(){p&&clearTimeout(p)}));case 13:h=e.sent,e.next=20;break;case 16:return e.prev=16,e.t0=e.catch(9),this._logger.error("Failed to publish",e.t0),e.abrupt("return",{status:"failed"});case 20:if("ok"===(f=this.mapHttpStatusToPublishStatus(h))){e.next=23;break}return e.abrupt("return",{status:f});case 23:return v=Date.now(),e.next=26,this.convertHttpResponseToPublishResponse(o,h);case 26:return m=e.sent,this._logger.debug("Got publish response [%j] in [%s] ms",m,v-d),e.abrupt("return",m);case 29:case"end":return e.stop()}}),e,this,[[9,16]])}))),function(e,t,n,i){return f.apply(this,arguments)})},{key:"setRemoteDescription",value:(p=g()(y().mark((function e(t,n){var i,r,o,a,s,u,c,l,d,h=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this.buildUrl([t.tenancy,"stream",t.streamId,"description","remote"]).toString(),r=new FormData,o={apiVersion:7,sharedSecret:t.sharedSecret,sessionDescription:{type:n.type,sdp:n.sdp}},r.append("jsonBody",JSON.stringify(o)),a=Date.now(),e.prev=5,u=null,e.next=9,Me.race([fetch(i,{method:"POST",body:r}),new Me((function(e){return u=window.setTimeout((function(){h._logger.error("Failed to set remote description",new Error("Set remote description timed out [".concat(i,"]"))),e({status:408})}),h._timeout)}))]).finally((function(){u&&clearTimeout(u)}));case 9:s=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to set remote description",e.t0),e.abrupt("return",{status:"failed"});case 16:if("ok"===(c=this.mapHttpStatusToSetRemoteDescriptionStatus(s))){e.next=19;break}return e.abrupt("return",{status:c});case 19:return l=Date.now(),e.next=22,this.convertHttpResponseToSetRemoteDescriptionResponse(s);case 22:return d=e.sent,this._logger.debug("Got set remote description response [%j] in [%s] ms",d,l-a),e.abrupt("return",d);case 25:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t){return p.apply(this,arguments)})},{key:"limitBitrate",value:(h=g()(y().mark((function e(t,n,i,r,o){var a,s,u,c,l,d,h,p,f=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=this.buildUrl([t.tenancy,"stream",t.streamId,"bitrate"]).toString(),s=new FormData,u={apiVersion:7,sharedSecret:t.sharedSecret,elapsedInMilliseconds:n,bitrateInBitsPerSecond:i,bitrateState:Ie.convertBitrateStateToBitrateStateType(r),bitrateMode:Fe.convertBitrateModeToBitrateModeType(o)},s.append("jsonBody",JSON.stringify(u)),c=Date.now(),e.prev=5,d=null,e.next=9,Me.race([fetch(a,{method:"POST",body:s}),new Me((function(e){return d=window.setTimeout((function(){f._logger.error("Failed to set limit bitrate timed",new Error("Set limit bitrate timed out [".concat(a,"]"))),e({status:408})}),f._timeout)}))]).finally((function(){d&&clearTimeout(d)}));case 9:l=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to set limit bitrate timed",e.t0),e.abrupt("return",{status:"failed"});case 16:return h=this.mapHttpStatusToSetTemporaryMaximalBitrateStatus(l),p=Date.now(),this._logger.info("Got set limit bitrate response [%s] in [%s] ms",h,p-c),e.abrupt("return",{status:h});case 20:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t,n,i,r){return h.apply(this,arguments)})},{key:"addIceCandidates",value:(d=g()(y().mark((function e(t,n,i){var r,o,a,s,u,c,l,d,h,p,f=this,v=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=v.length>3&&void 0!==v[3]?v[3]:[],o=this.buildUrl([t.tenancy,"stream",t.streamId,"ice","candidates"]).toString(),a=new FormData,s={apiVersion:7,sharedSecret:t.sharedSecret,candidates:n,discoveryCompleted:i,options:r},a.append("jsonBody",JSON.stringify(s)),u=Date.now(),e.prev=6,l=null,e.next=10,Me.race([fetch(o,{method:"POST",body:a}),new Me((function(e){return l=window.setTimeout((function(){f._logger.error("Failed to add ice candidates",new Error("Add ice candidates timed out [".concat(o,"]"))),e({status:408})}),f._timeout)}))]).finally((function(){l&&clearTimeout(l)}));case 10:c=e.sent,e.next=17;break;case 13:return e.prev=13,e.t0=e.catch(6),this._logger.error("Failed to add ice candidates",e.t0),e.abrupt("return",{status:"failed"});case 17:if("ok"===(d=this.mapHttpStatusToAddIceCandidatesStatus(c))){e.next=20;break}return e.abrupt("return",{status:d});case 20:return h=Date.now(),e.next=23,this.convertHttpResponseToAddIceCandidatesResponse(c);case 23:return p=e.sent,this._logger.info("Got add ICE candidates response [%j] in [%s] ms",p,h-u),e.abrupt("return",p);case 26:case"end":return e.stop()}}),e,this,[[6,13]])}))),function(e,t,n){return d.apply(this,arguments)})},{key:"destroyStream",value:(l=g()(y().mark((function e(t,n){var i,r,o,a,s,u,c,l,d,h=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this.buildUrl([t.tenancy,"stream",t.streamId,"destroy"]).toString(),r=new FormData,o={apiVersion:7,sharedSecret:t.sharedSecret,reason:n,options:[]},r.append("jsonBody",JSON.stringify(o)),a=Date.now(),e.prev=5,u=null,e.next=9,Me.race([fetch(i,{method:"POST",body:r,cache:"no-cache"}),new Me((function(e){return u=window.setTimeout((function(){h._logger.error("Failed to subscribe",new Error("Delete stream timed out [".concat(i,"]"))),e({status:408})}),h._timeout)}))]).finally((function(){u&&clearTimeout(u)}));case 9:s=e.sent,e.next=16;break;case 12:return e.prev=12,e.t0=e.catch(5),this._logger.error("Failed to delete stream",e.t0),e.abrupt("return",{status:"failed"});case 16:if("ok"===(c=this.mapHttpStatusToSetDestroyStreamStatus(s))){e.next=19;break}return e.abrupt("return",{status:c});case 19:return l=Date.now(),e.next=22,this.convertHttpResponseToDestroyStreamResponse(s);case 22:return d=e.sent,this._logger.info("Got destroy stream response [%j] in [%s] ms",d,l-a),e.abrupt("return",d);case 25:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t){return l.apply(this,arguments)})},{key:"destroyStreamOnUnmount",value:(c=g()(y().mark((function e(t,n){var i,r,o,a;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:null!==(i=navigator)&&void 0!==i&&i.sendBeacon||this.destroyStream(t,n),r=this.buildUrl([t.tenancy,"stream",t.streamId,"destroy"]).toString(),o=new FormData,a={apiVersion:7,sharedSecret:t.sharedSecret,reason:n,options:[]},o.append("jsonBody",JSON.stringify(a)),navigator.sendBeacon(r,o);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"buildUrl",value:function(e){var t=new URL(this._uri),n=t.pathname.split("/");return n.length=n.length-1,t.pathname=n.concat.apply(n,De()(e)).join("/"),t}},{key:"buildPingUrl",value:function(){var e=new URL(this._uri),t=C.sdkVersion,n=oe.discoveryParameters.intentions;return e.search="?".concat(new URLSearchParams([["type","http"],["version",t],["intentions",n],["_","".concat(Date.now())]]).toString()),e.toString()}},{key:"mapHttpStatusToPublishStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 402:return"geo-restricted";case 403:return"geo-blocked";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSubscribeStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 402:return"geo-restricted";case 403:return"geo-blocked";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetRemoteDescriptionStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetTemporaryMaximalBitrateStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToAddIceCandidatesStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"mapHttpStatusToSetDestroyStreamStatus",value:function(e){if(!e)return"failed";switch(e.status){case 200:return"ok";case 401:return"unauthorized";case 408:return"timeout";case 503:return"capacity";case 504:return"rate-limited";default:return"failed"}}},{key:"convertHttpResponseToSubscribeResponse",value:(s=g()(y().mark((function e(t,n){var i,r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.json();case 2:return i=e.sent,(r={status:i.status}).stream={tenancy:t,streamId:i.streamId,sharedSecret:i.sharedSecret},r.lag=i.lag,i&&(i.rtcConfiguration&&(r.rtcConfiguration=this.convertIRtcConfigurationToRTCConfiguration(i.rtcConfiguration)),i.setRemoteDescriptionResponse&&i.setRemoteDescriptionResponse.sessionDescription&&(r.setRemoteDescriptionResponse={sessionDescription:i.setRemoteDescriptionResponse.sessionDescription}),i.createAnswerDescriptionResponse&&i.createAnswerDescriptionResponse.sessionDescription&&(r.createAnswerDescriptionResponse={sessionDescription:i.createAnswerDescriptionResponse.sessionDescription}),i.createOfferDescriptionResponse&&i.createOfferDescriptionResponse.sessionDescription&&(r.createOfferDescriptionResponse={sessionDescription:i.createOfferDescriptionResponse.sessionDescription})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"convertHttpResponseToPublishResponse",value:(o=g()(y().mark((function e(t,n){var i,r;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.json();case 2:return i=e.sent,(r={status:i.status}).stream={tenancy:t,streamId:i.streamId,sharedSecret:i.sharedSecret},i&&(i.rtcConfiguration&&(r.rtcConfiguration=this.convertIRtcConfigurationToRTCConfiguration(i.rtcConfiguration)),i.setRemoteDescriptionResponse&&i.setRemoteDescriptionResponse.sessionDescription&&(r.setRemoteDescriptionResponse={sessionDescription:i.setRemoteDescriptionResponse.sessionDescription}),i.createAnswerDescriptionResponse&&i.createAnswerDescriptionResponse.sessionDescription&&(r.createAnswerDescriptionResponse={sessionDescription:i.createAnswerDescriptionResponse.sessionDescription}),i.createOfferDescriptionResponse&&i.createOfferDescriptionResponse.sessionDescription&&(r.createOfferDescriptionResponse={sessionDescription:i.createOfferDescriptionResponse.sessionDescription})),e.abrupt("return",r);case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"convertIRtcConfigurationToRTCConfiguration",value:function(e){var t={iceServers:[]};if(e.bundlePolicy&&(t.bundlePolicy=e.bundlePolicy),"number"==typeof e.iceCandidatePoolSize&&(t.iceCandidatePoolSize=e.iceCandidatePoolSize),e.iceServers){for(var n=[],i=0;i<e.iceServers.length;i++)n.push({urls:e.iceServers[i].urls,username:e.iceServers[i].username,credential:e.iceServers[i].credential});t.iceServers=n}return e.iceTransportPolicy&&(t.iceTransportPolicy=e.iceTransportPolicy),e.rtcpMuxPolicy&&(t.rtcpMuxPolicy=e.rtcpMuxPolicy),t}},{key:"convertHttpResponseToSetRemoteDescriptionResponse",value:(i=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status},n&&n.sessionDescription&&(i.sessionDescription=n.sessionDescription),e.abrupt("return",i);case 6:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"convertHttpResponseToAddIceCandidatesResponse",value:(n=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status,options:[]},n&&n.options&&(i.options=n.options),e.abrupt("return",i);case 6:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"convertHttpResponseToDestroyStreamResponse",value:(t=g()(y().mark((function e(t){var n,i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.json();case 2:return n=e.sent,i={status:n.status},e.abrupt("return",i);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}(),je=n(202).default,Ve=function(){function e(t){if(r()(this,e),u()(this,"_logger",O.getLogger("Discovery")),u()(this,"_metricsService",void 0),u()(this,"_uri",void 0),!t)throw new Error("Discovery requires uri");this._metricsService=de.getMetricsService(t.toString()),this._uri=t}var t,n;return a()(e,[{key:"discoverNearbyEndPoints",value:(n=g()(y().mark((function e(t,n){var i,r,o,a;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n){e.next=2;break}throw new Error("Discovery requires timeout");case 2:return i=t.toString(),e.next=5,je.race([fetch(i,{method:"GET",cache:"no-cache"}),new je((function(e,t){return setTimeout((function(){return t(new Error("Discovery timed out [".concat(i,"]")))}),n)}))]);case 5:if((r=e.sent).ok){e.next=8;break}throw new Error("Discovery failed [".concat(i,"] [").concat(r.status,"]"));case 8:if(null!==r.body){e.next=10;break}throw new Error("Discovery failed with no data [".concat(i,"]"));case 10:return e.next=12,r.text();case 12:return o=e.sent,a=o.split(","),e.abrupt("return",a.map((function(e){return new Ae(e,n)})));case 15:case"end":return e.stop()}}),e)}))),function(e,t){return n.apply(this,arguments)})},{key:"discoverClosestEndPoint",value:(t=g()(y().mark((function e(){var t,n,i,r,o,a,s=this,u=arguments;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:2e4,n=ae.buildDiscoveryUrl(this._uri),e.next=4,this.discoverNearbyEndPoints(new URL(n),t);case 4:return i=e.sent,r=0,o=function(){return new je((function(e,t){r>=i.length&&t("Discovery of [".concat(i.length,"] endpoints from [").concat(n,"] failed, preventing it from completing"))}))},e.next=9,je.race(i.map((function(e){return e.ping().catch((function(t){return s._logger.warn("Failed to ping end point [%s]",e,t),r++,o()})).then((function(t){var n=Date.now();return s._logger.info("Discovered end point [%s] with time [%s]",e.toString(),t),s._metricsService.push({metricType:ue.RoundTripTime,runtime:(n-pe.pageLoadTime)/1e3,value:{uint64:t||0},resource:e.toString(),kind:"ping"}),e}))})));case 9:return a=e.sent,e.abrupt("return",a);case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),Ue=function(){function e(){throw r()(this,e),new Error("Discovery is a static class that may not be instantiated")}var t,n;return a()(e,null,[{key:"precacheClosestEndPointDiscovery",value:(n=g()(y().mark((function t(){var n;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=new URL(pe.discoveryUri.value),t.abrupt("return",e.discoverClosestEndPointWithCaching(n));case 2:case"end":return t.stop()}}),t)}))),function(){return n.apply(this,arguments)})},{key:"discoverClosestEndPointWithCaching",value:(t=g()(y().mark((function t(n){var i,r,o;return y().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=n.toString(),!e._cache[i]){t.next=3;break}return t.abrupt("return",e._cache[i]);case 3:return r=new Ve(n),o=e._cache[i]=r.discoverClosestEndPoint(),e._cache[i].then((function(){setTimeout((function(){e._cache[i]===o&&delete e._cache[i]}),6e4)})).catch((function(){delete e._cache[i]})),t.abrupt("return",o);case 7:case"end":return t.stop()}}),t)}))),function(e){return t.apply(this,arguments)})}]),e}();u()(Ue,"_cache",{}),Ue.precacheClosestEndPointDiscovery();var Be=function(){function e(t){r()(this,e),u()(this,"_sdp",void 0),u()(this,"_audioCodec",void 0),u()(this,"_videoCodec",void 0),u()(this,"_isAudioTrackEnabled",void 0),u()(this,"_isVideoTrackEnabled",void 0),this._sdp=t;var n=this._sdp.split(/(\r\n|\r|\n)/),i=this._sdp.split("m=");this._audioCodec=this.applyCodec("audio",n),this._videoCodec=this.applyCodec("video",n),this._isAudioTrackEnabled=this.isTrackByTypeEnabled("audio",i),this._isVideoTrackEnabled=this.isTrackByTypeEnabled("video",i)}return a()(e,[{key:"audioCodec",get:function(){return this._audioCodec}},{key:"videoCodec",get:function(){return this._videoCodec}},{key:"isAudioTrackEnabled",get:function(){return this._isAudioTrackEnabled}},{key:"isVideoTrackEnabled",get:function(){return this._isVideoTrackEnabled}},{key:"isTrackByTypeEnabled",value:function(e,t){var n=t.find((function(t){return t.startsWith(e)}));return!!n&&!n.includes("a=inactive")}},{key:"applyCodec",value:function(e,t){return t.find((function(n){return n.includes("a=rtpmap:".concat(t.find((function(t){return t.includes("m=".concat(e))})).split(" ")[3]))})).split(" ")[1].split("/")[0]}}]),e}(),Ne=function(){function e(t,n,i){if(r()(this,e),u()(this,"_estimatedRoundTripTime",void 0),u()(this,"_estimatedVideoCodec",void 0),u()(this,"_estimatedAudioCodec",void 0),u()(this,"_rtcStatistic",new N({})),u()(this,"_peerConnection",void 0),u()(this,"_isMonitorRunning",!0),u()(this,"_updateTimeout",void 0),u()(this,"_tracksToMonitor",void 0),this._peerConnection=t,this._estimatedRoundTripTime=i,this._tracksToMonitor=n.getTracks().map((function(e){return e.kind}))||[],this._peerConnection){if(!Y.getCurrentOfferDisabled){var o=new Be(this._peerConnection.currentRemoteDescription.sdp);this._estimatedAudioCodec=o.audioCodec,this._estimatedVideoCodec=o.videoCodec}this.updateStatistic()}}var t,n;return a()(e,[{key:"rtcStatistic",get:function(){return this._rtcStatistic}},{key:"dispose",value:function(){this._isMonitorRunning=!1,this._peerConnection=null,this._updateTimeout&&(clearTimeout(this._updateTimeout),this._updateTimeout=null)}},{key:"updateStatistic",value:(n=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.getStatsPromiseBasedDisabled){e.next=5;break}return e.next=3,this.updateStatisticLegacy();case 3:return e.sent,e.abrupt("return");case 5:return t=function(e){return e.id.includes("Audio")?"audio":e.id.includes("Video")?"video":""},e.next=8,this._peerConnection.getStats(null).then((function(e){var i={};if(e){var r,o=n._estimatedRoundTripTime;e.forEach((function(a){if("candidate-pair"===a.type&&a.currentRoundTripTime&&(o=1e3*a.currentRoundTripTime,i.audio&&(i.audio.roundTripTime=o),i.video&&(i.video.roundTripTime=o)),"candidate-pair"===a.type&&a.lastPacketReceivedTimestamp&&(r=a.lastPacketReceivedTimestamp,i.audio&&(i.audio.lastPacketReceivedTimestamp=r),i.video&&(i.video.lastPacketReceivedTimestamp=r)),"inbound-rtp"===a.type){var s=a.kind||a.mediaType||t(a),u="";if(e.forEach((function(e){e.id===a.codecId&&(u=e.mimeType)})),s&&n._tracksToMonitor.includes(s)){var c,l,d,h,p,f=(a.bytesReceived||0)-(null!==(c=null===(l=n._rtcStatistic.value)||void 0===l||null===(d=l[s])||void 0===d?void 0:d.bytesReceived)&&void 0!==c?c:0),v=a.timestamp-(null===(h=n._rtcStatistic.value)||void 0===h||null===(p=h[s])||void 0===p?void 0:p.timestamp),m=f&&v?Math.floor(8*f/v*1e3):0;if(i[s]={ssrc:a.ssrc,mediaType:s,timestamp:a.timestamp,bitrate:m,bytesReceived:a.bytesReceived,packetsLost:a.packetsLost,packetsReceived:a.packetsReceived,codec:u||n.getCodecByType(s),roundTripTime:o},(a.lastPacketReceivedTimestamp||r)&&(i[s].lastPacketReceivedTimestamp=a.lastPacketReceivedTimestamp||r),"video"===s&&n._rtcStatistic.value&&n._rtcStatistic.value.video){i[s].framesDecoded=a.framesDecoded;var g=(a.framesDecoded-n._rtcStatistic.value.video.framesDecoded)/(i[s].timestamp-n._rtcStatistic.value.video.timestamp)*1e3;i[s].fps=g?Math.round(100*g)/100:0}}}}))}n._rtcStatistic.value=i})).then((function(){n._isMonitorRunning&&(n._updateTimeout=window.setTimeout((function(){return n.updateStatistic()}),1e3))}));case 8:e.sent;case 9:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateStatisticLegacy",value:(t=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._peerConnection.getStatsLegacy().then((function(e){var n={},i=t._estimatedRoundTripTime;e.result().forEach((function(e){if(e.names().forEach((function(t){"googRTT"===t&&(i=e.stat(t))})),"ssrc"===e.type){var r=e.stat("mediaType").toString();n[r]={timestamp:Date.now()},n[r].ssrc=e.stat("ssrc").toString(),n[r].mediaType=r,n[r].bytesReceived=e.stat("bytesReceived"),n[r].packetsLost=e.stat("packetsLost"),n[r].packetsReceived=e.stat("packetsReceived"),n[r].codec=e.stat("googCodecName").toString()||t.getCodecByType(r),n[r].roundTripTime=i,"video"===r&&t._rtcStatistic.value&&t._rtcStatistic.value.video&&(n[r].framesDecoded=e.stat("framesDecoded"),n[r].fps=(n[r].framesDecoded-t._rtcStatistic.value.video.framesDecoded)/(n[r].timestamp-t._rtcStatistic.value.video.timestamp)*1e3||0)}})),t._rtcStatistic.value=n})).then((function(){t._isMonitorRunning&&(t._updateTimeout=window.setTimeout((function(){return t.updateStatistic()}),1e3))}));case 2:e.sent;case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getCodecByType",value:function(e){switch(e){case"audio":return this._estimatedAudioCodec;case"video":return this._estimatedVideoCodec;default:return"unknown"}}}]),e}(),ze=function(){function e(){throw r()(this,e),new Error("RtcConfigurationManager is a static class that may not be instantiated")}return a()(e,null,[{key:"truncateIceServers",value:function(e){for(var t=[],n=0;n<e.iceServers.length;n++){for(var i=[],r=0;r<2;r++)e.iceServers[n].urls[r]&&i.push(e.iceServers[n].urls[r]);t.push({urls:i,username:e.iceServers[n].username,credential:e.iceServers[n].credential})}return e.iceServers=t,e}}]),e}(),Ge=function(){function e(){throw r()(this,e),new Error("InsertableStreams is a static class that may not be instantiated")}return a()(e,null,[{key:"setupMediaStreamTrackTransform",value:function(e,t){var n=t.getVideoTracks()[0];if(n){var i=new TransformStream({transform:e}),r=new MediaStreamTrackProcessor({track:n}),o=new MediaStreamTrackGenerator({kind:"video"}),a=r.readable,s=o.writable;a.pipeThrough(i).pipeTo(s);var u=new MediaStream;return u.addTrack(o),t.getAudioTracks().forEach((function(e){u.addTrack(e)})),u}return t}}]),e}(),He=n(202).default;function We(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function Je(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?We(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):We(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var Ke=function(){function e(t,n,i){r()(this,e),u()(this,"_logger",O.getLogger("RealTimeStream")),u()(this,"_channelContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_handleStreamFailure",void 0),this._channelContext=t,this._peerConnectionContext=n,this._handleStreamFailure=i}var t;return a()(e,[{key:"start",value:function(e,t,n,i){var r=this;return He.all([Ue.discoverClosestEndPointWithCaching(e),ne.createPeerConnectionOffer()]).then((function(e){var n=Ee()(e,2),i=n[0],o=n[1],a=o.localOffer,s=o.peerConnection;return r._channelContext.online.value=!0,r._channelContext.endPoint.value=i,r._logger.info("Connecting to [%s]",i.toString()),r._logger.info("Local offer:\n"+a.sdp),!Y.clientOfferDisabled&&s.supportsSetConfiguration&&s.supportsGetConfiguration||(s.close(),s=null,a=null),r._peerConnectionContext.peerConnection.value=s,i.subscribe(t,a,r._channelContext.failureCount.value)})).then((function(e){var t=e.status,o=e.stream,a=e.rtcConfiguration,s=e.setRemoteDescriptionResponse,u=e.createOfferDescriptionResponse,c=e.createAnswerDescriptionResponse,l=e.lag;if(r._channelContext.stream.value=o,r._channelContext.lag.value=l,r._channelContext.applySessionAndStreamPropertiesToVideoElement(),r._logger.debug("[%s] Subscribe completed [%s] [%j] [%j] [%j] [%j]",r._channelContext.streamId,t,a,s,u,c),r._channelContext.state.value=r._channelContext.mapSubscribeStatusToChannelStatus(t),r._channelContext.applyStatus(t),"ok"===t)return r.applyRtcConfiguration(r._peerConnectionContext.peerConnection.value,a).then((function(e){var t,a=!1,l=!1,d=[];r._peerConnectionContext.peerConnection.value||(r._peerConnectionContext.peerConnection.value=e),e.onicecandidate=function(n){r._channelContext.stream.value===o&&r._peerConnectionContext.peerConnection.value===e&&(a||pe.sendLocalCandidates.value&&(n.candidate&&n.candidate.candidate?d.push(n.candidate):l=!0,t||(t=setTimeout((function(){r._channelContext.stream.value!==o||a||r._channelContext.endPoint.value.addIceCandidates(o,d,l).then((function(e){var t=e.status,n=e.options;"ok"===t?(n.includes("cancel")&&(a=!0),r._logger.info("[%s] Added ICE candidates with reason [%s] and options [%s]",r._channelContext.streamId,t,n)):r._logger.warn("[%s] Failed to add ICE candidates with reason [%s]",r._channelContext.streamId,t)})).catch((function(e){r._logger.error("[%s] Failed to add ICE candidates",r._channelContext.streamId,e)}))}),100))))},e.oniceconnectionstatechange=function(){if(r._channelContext.stream.value===o&&r._peerConnectionContext.peerConnection.value===e){var t=function(){r._channelContext.state.value=ge.Error,r._channelContext.videoElement.value&&(r._channelContext.videoElement.value.pause(),r._channelContext.videoElement.value.srcObject=null),r._channelContext.playing.value=!1,r._channelContext.loading.value=!0,r._handleStreamFailure().catch((function(t){r._logger.error("[%s] Failed handling stream failure after peer connection stopped with state [%s]",r._channelContext.streamId,e.iceConnectionState,t)}))};switch(e.iceConnectionState){case"checking":case"completed":case"connected":case"new":return;case"disconnected":case"failed":return void(navigator.onLine&&(r._logger.info("[%s] ICE connection state changed to [%s], trying to reconnect",r._channelContext.streamId,e.iceConnectionState),r.reconnectPeerConnection(e,t)));case"closed":return r._logger.info("[%s] ICE connection state changed to [%s], retrying to connect",r._channelContext.streamId,e.iceConnectionState),void t();default:L(e.iceConnectionState)}}};var h=new He((function(t,n){if(Y.onTrackDisabled){var i=function n(i){clearTimeout(o),e.removeEventListener("track",n),e.removeEventListener("addstream",n),i.streams?t(i.streams[0]):t(i.stream)},o=setTimeout((function(){e.removeEventListener("track",i),e.removeEventListener("addstream",i),n(new Error("Stream setup timed out"))}),3e4);e.addEventListener("track",i),e.addEventListener("addstream",i)}else{var a=setTimeout((function(){return n(new Error("Stream setup timed out"))}),3e4);e.ontrack=function(e){var n=e.streams[0];r._channelContext.videoStreamTransformCallback&&(n=Ge.setupMediaStreamTrackTransform(r._channelContext.videoStreamTransformCallback,n)),clearTimeout(a),t(n)}}}));return new He((function(e){e()})).then((function(){if(s)return r._logger.info("[%s] Set local SDP offer [%s]",r._channelContext.streamId,s.sessionDescription.sdp),e.setLocalDescription(s.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set local description [%j] with message [%s]",r._channelContext.streamId,s.sessionDescription,e.message),e}))})).then((function(){if(c)return r._logger.info("[%s] Set remote SDP answer [%s]",r._channelContext.streamId,c.sessionDescription.sdp),e.setRemoteDescription(c.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set remote description [%j] with message [%s]",r._channelContext.streamId,c.sessionDescription,e.message),e}))})).then((function(){if(u)return r._logger.info("[%s] Set remote SDP offer [%s]",r._channelContext.streamId,u.sessionDescription.sdp),e.setRemoteDescription(u.sessionDescription).catch((function(e){throw r._logger.info("[%s] Failed to set remote description [%j] with message [%s]",r._channelContext.streamId,u.sessionDescription,e.message),e})).then((function(){return e.createAnswer({offerToReceiveAudio:!0,offerToReceiveVideo:!0})})).then((function(e){return r._logger.info("[%s] Set local SDP answer [%j]",r._channelContext.streamId,e),r._channelContext.endPoint.value.setRemoteDescription(o,e)})).then((function(t){var n=t.status,i=t.sessionDescription;return r._channelContext.state.value=r.mapSetRemoteDescriptionStatusToChannelStatus(n),"ok"!==n?(r._channelContext.playing.value=!1,r._channelContext.standby.value=!0,void(r._channelContext.stopped.value=!1)):e.setLocalDescription(i).catch((function(e){throw r._logger.info("[%s] Failed to set local description [%j] with message [%s]",r._channelContext.streamId,i,e.message),e}))}))})).then((function(){return n.success(r._channelContext.streamId),h})).then((function(t){r._peerConnectionContext.mediaStream.value=t;var n=new Ne(e,t,r._channelContext.endPoint.value.roundTripTime/4);return r._channelContext.disposables.add(n),n.rtcStatistic.subscribe((function(t){if(r._channelContext.rtcStatistics.value=t,!r._channelContext.rtcVideoStatistic&&!r._channelContext.rtcAudioStatistic)return r._channelContext.rtcAudioStatistic=t.audio,void(r._channelContext.rtcVideoStatistic=t.video);var i=!1,o=!1;t.audio&&r._channelContext.rtcAudioStatistic&&r._channelContext.rtcAudioStatistic.timestamp!==t.audio.timestamp&&((i=r._channelContext.rtcAudioStatistic&&r._channelContext.rtcAudioStatistic.bytesReceived===t.audio.bytesReceived)&&navigator.onLine&&r._logger.info("[%s] Audio track failed with last bytesReceived [%s] is equal to previous bytesReceived [%s] within [%s]",r._channelContext.streamId,t.audio.bytesReceived,r._channelContext.rtcAudioStatistic.bytesReceived,new _e(t.audio.timestamp-r._channelContext.rtcAudioStatistic.timestamp).toIsoString()),r._channelContext.rtcAudioStatistic=t.audio),t.video&&r._channelContext.rtcVideoStatistic&&r._channelContext.rtcVideoStatistic.timestamp!==t.video.timestamp&&((o=r._channelContext.rtcVideoStatistic&&r._channelContext.rtcVideoStatistic.bytesReceived===t.video.bytesReceived)&&navigator.onLine&&r._logger.info("[%s] Video track failed with last bytesReceived [%s] is equal to previous bytesReceived [%s] within [%s]",r._channelContext.streamId,t.video.bytesReceived,r._channelContext.rtcVideoStatistic.bytesReceived,new _e(t.video.timestamp-r._channelContext.rtcVideoStatistic.timestamp).toIsoString()),r._channelContext.rtcVideoStatistic=t.video),(o||i)&&navigator.onLine?r.reconnectPeerConnection(e,(function(){r._channelContext.state.value=ge.Error,r._channelContext.videoElement.value&&(r._channelContext.videoElement.value.pause(),r._channelContext.videoElement.value.srcObject=null),r._channelContext.playing.value=!1,r._channelContext.loading.value=!0,n.dispose(),r._handleStreamFailure().catch((function(t){r._logger.error("[%s] Failed handling stream failure after track stopped with state [%s]",r._channelContext.streamId,e.iceConnectionState,t)}))})):r._peerConnectionContext.peerConnectionReconnectAttempts=0})),pe.automaticallyPlayMediaStream?i(t):(r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,void(r._channelContext.state.value=ge.Paused))}))}))}))}},{key:"applyRtcConfiguration",value:(t=g()(y().mark((function e(t,n){var i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=3;break}return n=ze.truncateIceServers(n),e.abrupt("return",pe.peerConnectionFactory.value.createPeerConnection(n));case 3:return i=Je(Je({},t.getConfiguration()),n),t.setConfiguration(i),e.abrupt("return",t);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"reconnectPeerConnection",value:function(e,t){var n=this;if("closed"!==e.iceConnectionState)if(this._channelContext.state.value=ge.Reconnecting,this._peerConnectionContext.peerConnectionReconnectAttempts<pe.maximalNumberOfPeerConnectionReconnectAttempts||!pe.automaticallyReconnectPeerConnection){var i;this._peerConnectionContext.peerConnectionReconnectAttempts++;var r="offer"===(null===(i=e.currentLocalDescription)||void 0===i?void 0:i.type);if(Y.clientOfferDisabled||!e.supportsSetConfiguration||!e.supportsGetConfiguration||!r)return;this._logger.info("Reconnecting peer connection by restarting ICE");var o=e.currentLocalDescription;e.createOffer({iceRestart:!0}).then((function(t){return e.setLocalDescription(t).then((function(){return e.setLocalDescription(o)}))})).catch((function(e){n._logger.error("Failed to reconnect peer connection",e),n._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}))}else this._logger.info("Failed to reconnect peer connection after [%s] attempts, performing full recovery",this._peerConnectionContext.peerConnectionReconnectAttempts),this._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}},{key:"mapSetRemoteDescriptionStatusToChannelStatus",value:function(e){switch(e){case"ok":return ge.Starting;case"unauthorized":return ge.Unauthorized;case"not-found":case"capacity":case"rate-limited":case"timeout":return ge.Recovering;case"failed":return ge.Error;default:L(e)}}}]),e}(),qe=function(){function e(){throw r()(this,e),new Error("RealTimeStreamFactory is a static class that may not be instantiated")}return a()(e,null,[{key:"create",value:function(e,t,n,i){var r=H.parseToken(e).capabilities;return r.includes("rtmp")?(this._logger.error("SDK does not support RTMP playback."),void(t.state.value=ge.UnsupportedFeature)):r.includes("streaming")?(this._logger.error("This build does not support Live Stream playback."),void(t.state.value=ge.UnsupportedFeature)):new Ke(t,n,i)}}]),e}();u()(qe,"_logger",O.getLogger("Streaming"));var Qe=n(202).default,Ye=function(){function e(t,n,i){var o=this;r()(this,e),u()(this,"_logger",O.getLogger("Channel")),u()(this,"_tokenContext",void 0),u()(this,"_channelContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_stateContext",void 0),u()(this,"_exponentialBackoff",void 0),u()(this,"_channelStartTime",void 0),u()(this,"_readOnlyVideoElement",void 0),u()(this,"_readOnlyToken",void 0),u()(this,"_readOnlyPeerConnection",void 0),u()(this,"_readOnlyState",void 0),u()(this,"_readOnlyAutoMuted",void 0),u()(this,"_readOnlyAutoPaused",void 0),u()(this,"_readOnlyTokenExpiring",void 0),u()(this,"_readOnlyAuthorized",void 0),u()(this,"_readOnlyOnline",void 0),u()(this,"_readOnlyLoading",void 0),u()(this,"_readOnlyPlaying",void 0),u()(this,"_readOnlyStandby",void 0),u()(this,"_readOnlyStopped",void 0),u()(this,"_readOnlyTargetLag",void 0),u()(this,"_readOnlyLag",void 0),u()(this,"_readOnlyBitrateLimit",void 0),u()(this,"_readOnlyResolution",void 0),u()(this,"_readOnlyFailureCount",void 0),u()(this,"_readOnlyEndPoint",void 0),u()(this,"_readOnlyStream",void 0),u()(this,"_readOnlyRtcStatistics",void 0),u()(this,"_readOnlyMediaStream",void 0),u()(this,"_metricsService",void 0),u()(this,"_sessionTelemetry",void 0),u()(this,"_videoMetaDataChangedHandler",void 0);var a=H.parseToken(n),s={targetLag:null==i?void 0:i.targetLag,videoStreamTransformCallback:null==i?void 0:i.videoStreamTransformCallback,hasInsertableStreams:a.capabilities.includes("insertable-streams")};this._tokenContext=new Se(n),this._channelContext=new Te(s),this._peerConnectionContext=new Le,this._stateContext=new Pe,this._exponentialBackoff=new ve,this._channelStartTime=Date.now(),this._readOnlyVideoElement=new z(this._channelContext.videoElement),this._readOnlyToken=new z(this._tokenContext.token),this._readOnlyPeerConnection=new z(this._peerConnectionContext.peerConnection),this._readOnlyState=new z(this._channelContext.state),this._readOnlyAutoMuted=new z(this._channelContext.autoMuted),this._readOnlyAutoPaused=new z(this._channelContext.autoPaused),this._readOnlyTokenExpiring=new z(this._tokenContext.tokenExpiring),this._readOnlyAuthorized=new z(this._channelContext.authorized),this._readOnlyOnline=new z(this._channelContext.online),this._readOnlyLoading=new z(this._channelContext.loading),this._readOnlyPlaying=new z(this._channelContext.playing),this._readOnlyStandby=new z(this._channelContext.standby),this._readOnlyStopped=new z(this._channelContext.stopped),this._readOnlyTargetLag=new z(this._channelContext.targetLag),this._readOnlyLag=new z(this._channelContext.lag),this._readOnlyBitrateLimit=new z(this._channelContext.bitrateLimit),this._readOnlyResolution=new z(this._channelContext.resolution),this._readOnlyFailureCount=new z(this._channelContext.failureCount),this._readOnlyEndPoint=new z(this._channelContext.endPoint),this._readOnlyStream=new z(this._channelContext.stream),this._readOnlyRtcStatistics=new z(this._channelContext.rtcStatistics),this._readOnlyMediaStream=new z(this._peerConnectionContext.mediaStream);var c=(a.uri||pe.discoveryUri.value).toString();pe.tenancy.value=a.tenancy||pe.tenancy.value,ae.uri.value=c,this._metricsService=de.getMetricsService(c),this._sessionTelemetry=new ke(pe.pageLoadTime,this._metricsService),this._channelContext.channelDisposables.add(this._sessionTelemetry),this._videoMetaDataChangedHandler=this.handleVideoMetaDataChanged.bind(this),this.videoElement=t,this._channelContext.channelDisposables.add(this._channelContext.videoElement.subscribe((function(e){o._channelContext.rendererDisposables.dispose(),e&&(o._channelContext.rendererDisposables.add(o._channelContext.stream.subscribe((function(e){o._channelContext.videoTelemetry&&o._channelContext.videoTelemetry.dispose(),e&&o.videoElement&&(o.videoElement.dataset&&(o.videoElement.dataset.sessionId=pe.clientSessionId,o.videoElement.dataset.streamId=o.streamId),o._channelContext.videoTelemetry=new ye(o.streamId,pe.pageLoadTime,o._channelStartTime,o._metricsService),o._channelContext.videoTelemetry.setupListenerForTimeToFirstTime(o.videoElement),o._channelContext.videoTelemetry.setupListenerForRebuffering(o.videoElement),o._channelContext.state.value===ge.Stopped)&&o.restartAfterStop()}))),o._channelContext.channelDisposables.add(o._channelContext.rendererDisposables))}))),this._channelContext.channelDisposables.add(this._channelContext.state.subscribe((function(e){o._channelContext.clearFailureCountTimeout&&clearTimeout(o._channelContext.clearFailureCountTimeout),o._channelContext.failureCount.value&&e===ge.Playing&&(o._channelContext.clearFailureCountTimeout=window.setTimeout((function(){o._channelContext.failureCount.value=0}),3e3))}))),this._channelContext.channelDisposables.add(this._channelContext.resolution.subscribe((function(e){o._channelContext.videoTelemetry&&o._channelContext.videoTelemetry.onVideoResolutionChanges(e.toString())}))),this._channelContext.channelDisposables.add(this._channelContext.bitrateLimit.subscribe((function(e){if(e&&o._channelContext.endPoint.value&&o._channelContext.stream.value){var t=Date.now()-o._channelContext.channelInitialization.getTime();o._channelContext.endPoint.value.limitBitrate(o._channelContext.stream.value,t,e,xe.Keep,we.Normal).catch((function(e){o._logger.error("Error while setting limit bitrate",e)}))}})));var l=function(){o._channelContext.stream.value&&o._channelContext.endPoint.value&&o._channelContext.endPoint.value.destroyStreamOnUnmount(o._channelContext.stream.value,"client:termination-on-window-unload")};window.addEventListener("beforeunload",l),this._channelContext.channelDisposables.add(new U((function(){window.removeEventListener("beforeunload",l)}))),this.start()}var t,n,i,o,s,c,l,d,h;return a()(e,[{key:"videoElement",get:function(){return this._channelContext.videoElement.value},set:function(e){this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.removeEventListener("loadeddata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.removeEventListener("loadedmetadata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.removeEventListener("resize",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.dataset&&(this._channelContext.videoElement.value.dataset.sessionId="",this._channelContext.videoElement.value.dataset.streamId=""),this._channelContext.rendererDisposables.dispose(),this._channelContext.videoElement.value.pause(),this._channelContext.videoElement.value.srcObject=null),this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!1,this._channelContext.state.value=ge.Stopped,this._channelContext.videoElement.value=e,this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.addEventListener("loadeddata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.addEventListener("loadedmetadata",this._videoMetaDataChangedHandler),this._channelContext.videoElement.value.addEventListener("resize",this._videoMetaDataChangedHandler))}},{key:"handleVideoMetaDataChanged",value:function(){var e=this._channelContext.videoElement.value;e?this.resolution.value.width===e.videoWidth&&this.resolution.value.height===e.videoHeight||(this._channelContext.resolution.value=new fe(e.videoWidth,e.videoHeight)):this._channelContext.resolution.value=fe.empty}},{key:"token",get:function(){return this._tokenContext.token.value},set:function(e){this._channelContext.disposables.dispose(),this._tokenContext.token.value=e,this._tokenContext.tokenExpiring.value=!1;var t=H.parseToken(this._tokenContext.token.value),n=(t.uri||pe.discoveryUri.value).toString();pe.tenancy.value=t.tenancy||pe.tenancy.value,ae.uri.value=n,this._metricsService=de.getMetricsService(n),this._channelContext.hasInsertableStreams.value=t.capabilities.includes("insertable-streams"),this.start()}},{key:"peerConnection",get:function(){return this._readOnlyPeerConnection}},{key:"state",get:function(){return this._readOnlyState}},{key:"autoMuted",get:function(){return this._readOnlyAutoMuted}},{key:"autoPaused",get:function(){return this._readOnlyAutoPaused}},{key:"tokenExpiring",get:function(){return this._readOnlyTokenExpiring}},{key:"authorized",get:function(){return this._readOnlyAuthorized}},{key:"online",get:function(){return this._readOnlyOnline}},{key:"loading",get:function(){return this._readOnlyLoading}},{key:"playing",get:function(){return this._readOnlyPlaying}},{key:"standby",get:function(){return this._readOnlyStandby}},{key:"stopped",get:function(){return this._readOnlyStopped}},{key:"targetLag",get:function(){return this._readOnlyTargetLag}},{key:"lag",get:function(){return this._readOnlyLag}},{key:"bitrateLimit",get:function(){return this._readOnlyBitrateLimit.value}},{key:"resolution",get:function(){return this._readOnlyResolution}},{key:"failureCount",get:function(){return this._readOnlyFailureCount}},{key:"endPoint",get:function(){return this._readOnlyEndPoint}},{key:"stream",get:function(){return this._readOnlyStream}},{key:"streamId",get:function(){return this._channelContext.streamId}},{key:"rtcStatistics",get:function(){return this._readOnlyRtcStatistics}},{key:"mediaStream",get:function(){return this._readOnlyMediaStream}},{key:"setBitrateLimit",value:function(e){this._channelContext.bitrateLimit.value=e}},{key:"clearBitrateLimit",value:function(){var e=this;if(this._channelContext.bitrateLimit.value&&this._channelContext.endPoint.value&&this._channelContext.stream.value){var t=Date.now()-this._channelContext.channelInitialization.getTime();this._channelContext.endPoint.value.limitBitrate(this._channelContext.stream.value,t,0,xe.Keep,we.Reset).then((function(t){"ok"===t.status&&(e._channelContext.bitrateLimit.value=0)})).catch((function(t){e._logger.error("Error while setting limit bitrate",t)}))}}},{key:"updateTargetLag",value:function(e){this._channelContext.targetLag.value=e}},{key:"stop",value:(h=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Qe((function(e){if(!n._stateContext.isStarting.value)return n.processStop(t),void e();n._channelContext.rendererDisposables.add(n._stateContext.isStarting.subscribe((function(i){i||(n.processStop(t),e())})))})));case 1:case"end":return e.stop()}}),e)}))),function(e){return h.apply(this,arguments)})},{key:"processStop",value:function(e){this._channelContext.videoElement.value&&(this._channelContext.videoElement.value.pause(),this._channelContext.videoElement.value.srcObject=null),this._channelContext.rendererDisposables.dispose(),this.cleanUpResources(e),this._channelContext.state.value=ge.Stopped}},{key:"resume",value:(d=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._peerConnectionContext.mediaStream.value){e.next=3;break}return this._channelContext.autoPaused.value=!1,e.abrupt("return",this.playMediaStreamInVideoElement(this._peerConnectionContext.mediaStream.value));case 3:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"mute",value:function(){var e=this._channelContext.videoElement.value;e&&(e.muted=!0)}},{key:"unmute",value:function(){var e=this._channelContext.videoElement.value;e&&(e.muted=!1,this._channelContext.autoMuted.value=!1)}},{key:"dispose",value:(l=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stop("client:channel-dispose").then((function(){t._channelContext.channelDisposables.dispose(),t._stateContext.isDisposed=!0})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"getUri",value:function(e){return H.parseToken(e).uri||(this._logger.info("Fall back to the default discover URI [%s]",pe.discoveryUri.value),new URL(pe.discoveryUri.value))}},{key:"start",value:(c=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._stateContext.isStarting.value){e.next=5;break}return this._logger.info("Channel is already starting, skipping start"),e.abrupt("return");case 5:return this._stateContext.isStarting.value=!0,e.abrupt("return",this.processStart());case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"processStart",value:(s=g()(y().mark((function e(){var t,n,i,r,o,a=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._tokenContext.token.value,n=this._sessionTelemetry.listenOnStreamSetup(),H.isEncodedEdgeTokenValid(t)){e.next=8;break}return this._logger.error("Failed to parse token [%s]",t),this._channelContext.state.value=ge.Unauthorized,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 8:if(!this._channelContext.hasInsertableStreams.value){e.next=23;break}if(this._channelContext.videoStreamTransformCallback){e.next=15;break}return this._logger.error("insertable-streams enabled, but missing callback function CreateChannelOptions.videoStreamTransformCallback"),this._channelContext.state.value=ge.ConfigurationError,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 15:if(Y.isInsertableStreamsSupported){e.next=21;break}return this._logger.error("insertable-streams enabled, but browser does not support Media Stream Track API"),this._channelContext.state.value=ge.UnsupportedFeature,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 21:e.next=29;break;case 23:if(!this._channelContext.videoStreamTransformCallback){e.next=29;break}return this._logger.error("CreateChannelOptions.videoStreamTransformCallback callback function found, but feature is not enabled via insertable-streams capability"),this._channelContext.state.value=ge.ConfigurationError,this._channelContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 29:if(this.cleanUpResources("client:start"),this._channelContext.state.value=ge.Starting,this._channelContext.loading.value=!0,i=this.getUri(t),r=function(){return new Qe((function(e){return a._stateContext.isStarting.value=!1,e(a.handleStreamFailure())}))},o=qe.create(t,this._channelContext,this._peerConnectionContext,r)){e.next=38;break}return this._stateContext.isStarting.value=!1,e.abrupt("return");case 38:return e.abrupt("return",o.start(i,t,n,this.playMediaStreamInVideoElement.bind(this)).then((function(){a._channelContext.loading.value=!1})).catch((function(e){n.fail(),a._channelContext.failureCount.value++,a._channelContext.online.value=!1,a.cleanUpResources("client:cleanup-after-failed-setup"),a._channelContext.state.value=ge.Error,a._logger.error("Failed to start channel",e)})).finally((function(){if(a._stateContext.isStarting.value=!1,a._channelContext.state.value!==ge.Playing&&pe.automaticRetryOnFailure){var e=setTimeout((function(){a.handleStreamFailure().catch((function(e){a._logger.error("Failed handling stream failure",e)}))}),a.getRetryInterval());a._channelContext.disposables.add(new U((function(){clearTimeout(e)})))}})));case 39:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"restartAfterStop",value:(o=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._peerConnectionContext.mediaStream.value){e.next=4;break}return e.abrupt("return",this.playMediaStreamInVideoElement(this._peerConnectionContext.mediaStream.value));case 4:this._tokenContext.token.value&&this.start();case 5:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"play",value:(i=g()(y().mark((function e(){var t;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._peerConnectionContext.mediaStream.value){e.next=3;break}return e.abrupt("return",this.start());case 3:return e.abrupt("return",this.playMediaStreamInVideoElement(t));case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getRetryInterval",value:function(){switch(this._channelContext.state.value){case ge.StandBy:case ge.Offline:return 15e3;case ge.Error:case ge.Recovering:case ge.Unauthorized:case ge.GeoRestricted:case ge.GeoBlocked:case ge.Stopped:case ge.Starting:case ge.Playing:case ge.Paused:case ge.Reconnecting:case ge.UnsupportedFeature:case ge.ConfigurationError:return this._exponentialBackoff.getExponentialBackoffIntervalByFailureCount(this._channelContext.failureCount.value);default:L(this._channelContext.state.value)}}},{key:"handleStreamFailure",value:(n=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=this._channelContext.state.value,e.next=e.t0===ge.Error||e.t0===ge.Reconnecting||e.t0===ge.StandBy||e.t0===ge.Offline||e.t0===ge.Recovering?3:e.t0===ge.Unauthorized?5:e.t0===ge.GeoRestricted?7:e.t0===ge.GeoBlocked?9:e.t0===ge.Stopped?11:e.t0===ge.Playing?13:e.t0===ge.Paused?15:e.t0===ge.Starting?17:e.t0===ge.UnsupportedFeature?19:e.t0===ge.ConfigurationError?21:23;break;case 3:return this._logger.info("Retry start with initial state [%s] [%s]",this._channelContext.state.value,ge[this._channelContext.state.value]),e.abrupt("break",24);case 5:return this._logger.info("Channel is unauthorized, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 7:return this._logger.info("Channel is geo restricted, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 9:return this._logger.info("Channel is geo blocked, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 11:return this._logger.info("Channel is stopped, skipping retry of start."),e.abrupt("return");case 13:return this._logger.info("Channel is playing, skipping retry of start"),e.abrupt("return");case 15:return this._logger.info("Channel is paused, skipping retry of start. Please invoke play()"),e.abrupt("return");case 17:return this._logger.info("Channel is already starting, skipping retry of start"),e.abrupt("return");case 19:return this._logger.info("Channel is stopped due to unsupported feature, skipping retry of start."),e.abrupt("return");case 21:return this._logger.info("Channel is stopped due to configuration error, skipping retry of start."),e.abrupt("return");case 23:L(this._channelContext.state.value);case 24:return e.abrupt("return",this.start());case 25:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"cleanUpResources",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"client:termination";this._channelContext.disposables.dispose();var n=this._peerConnectionContext.peerConnection.value;n&&(this._peerConnectionContext.peerConnection.value=null,n.close()),this._peerConnectionContext.mediaStream.value&&(this._peerConnectionContext.mediaStream.value.getTracks().forEach((function(e){return e.stop()})),this._peerConnectionContext.mediaStream.value=null),this._channelContext.autoPaused.value=!1,this._channelContext.autoMuted.value=!1,this._channelContext.playing.value=!1,this._channelContext.stopped.value=!0,this._channelContext.standby.value=!1,this._channelContext.stream.value&&this._channelContext.endPoint.value&&this._channelContext.endPoint.value.destroyStream(this._channelContext.stream.value,t).then((function(t){var n=t.status;"ok"===n?e._logger.info("[%s] Destroyed stream with reason [%s]",e.streamId,n):e._logger.warn("[%s] Failed to destroy stream with reason [%s]",e.streamId,n)})).catch((function(t){e._logger.error("[%s] Failed to destroy stream",e.streamId,t)})),this.videoElement&&this.videoElement.dataset&&(this.videoElement.dataset.sessionId="",this.videoElement.dataset.streamId=""),this._channelContext.stream.value=null,this._channelContext.endPoint.value=null,this._peerConnectionContext.peerConnectionReconnectAttempts=0}},{key:"playMediaStreamInVideoElement",value:(t=g()(y().mark((function e(t){var n,i,r=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=this._channelContext.videoElement.value){e.next=8;break}return this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!1,this._channelContext.state.value=ge.Stopped,e.abrupt("return");case 8:if(n.srcObject=t,void 0!==(i=n.play())){e.next=17;break}return this._channelContext.autoMuted.value=!1,this._channelContext.autoPaused.value=!1,this._channelContext.loading.value=!1,this._channelContext.playing.value=!0,this._channelContext.state.value=ge.Playing,e.abrupt("return");case 17:return e.abrupt("return",i.then((function(){r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!1,r._channelContext.loading.value=!1,r._channelContext.playing.value=!0,r._channelContext.state.value=ge.Playing})).catch((function(e){var i=!!t.getTracks().filter((function(e){return"audio"===e.kind})),o=!pe.automaticallyMuteVideoOnPlayFailure;return o||n.muted||!i?(r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,r._channelContext.state.value=ge.Paused,o?(r._logger.info("[%s] Paused video after play failed. Manual user action required.",r.streamId,e),void(n.srcObject=null)):i?void r._logger.info("[%s] Failed to play video. Manual user action required.",r.streamId,e):void r._logger.info("[%s] Failed to play muted video. Manual user action required.",r.streamId,e)):(n.muted=!0,n.play().then((function(){r._logger.info("[%s] Played video after auto muting. Manual user action required to unmute.",r.streamId),r._channelContext.autoMuted.value=!0,r._channelContext.autoPaused.value=!1,r._channelContext.loading.value=!1,r._channelContext.playing.value=!0,r._channelContext.state.value=ge.Playing})).catch((function(e){n.muted=!1,r._logger.info("[%s] Failed to play video. Manual user action required.",r.streamId,e),r._channelContext.autoMuted.value=!1,r._channelContext.autoPaused.value=!0,r._channelContext.loading.value=!1,r._channelContext.playing.value=!1,r._channelContext.state.value=ge.Paused})))})));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),e}(),Ze=function(){function e(){throw r()(this,e),new Error("Channels is a static class that may not be instantiated")}return a()(e,null,[{key:"createChannel",value:function(e){if(!pe.initialized.value)throw new Error("SDK is not loaded.");var t={targetLag:e.targetLag,videoStreamTransformCallback:e.videoStreamTransformCallback};return new Ye(e.videoElement,e.token,t)}}]),e}(),$e=function(e){return e[e.Offline=1]="Offline",e[e.Starting=2]="Starting",e[e.Publishing=3]="Publishing",e[e.Recovering=4]="Recovering",e[e.Reconnecting=5]="Reconnecting",e[e.Stopped=6]="Stopped",e[e.Unauthorized=7]="Unauthorized",e[e.GeoRestricted=8]="GeoRestricted",e[e.GeoBlocked=9]="GeoBlocked",e[e.UnsupportedFeature=10]="UnsupportedFeature",e[e.NotFound=11]="NotFound",e[e.Error=12]="Error",e}($e||{}),Xe=$e,et=function(){function e(t){r()(this,e),u()(this,"publisherInitialization",void 0),u()(this,"disposables",void 0),u()(this,"publisherDisposables",void 0),u()(this,"state",void 0),u()(this,"authorized",void 0),u()(this,"online",void 0),u()(this,"loading",void 0),u()(this,"publishing",void 0),u()(this,"standby",void 0),u()(this,"stopped",void 0),u()(this,"failureCount",void 0),u()(this,"endPoint",void 0),u()(this,"stream",void 0),u()(this,"rtcStatistics",void 0),u()(this,"clearFailureCountTimeout",void 0),u()(this,"startReconnectionAttemptsTimeInMilliseconds",void 0),u()(this,"name",void 0),this.disposables=new q,this.publisherDisposables=new q,this.publisherInitialization=new Date,this.state=new N(Xe.Starting),this.authorized=new N(!0),this.online=new N(!0),this.loading=new N(!1),this.publishing=new N(!1),this.standby=new N(!1),this.stopped=new N(!1),this.failureCount=new N(0),this.endPoint=new N(null),this.stream=new N(null),this.rtcStatistics=new N(null),this.name=t&&t.length?t:this.generateScreenName(),this.startReconnectionAttemptsTimeInMilliseconds=0}return a()(e,[{key:"streamId",get:function(){var e=this.stream.value;return e?e.streamId:"-"}},{key:"applyStatus",value:function(e){switch(e){case"ok":break;case"unauthorized":case"geo-restricted":case"geo-blocked":this.authorized.value=!1;case"not-found":return this.failureCount.value=0,this.publishing.value=!1,this.standby.value=!0,this.stopped.value=!1,void(this.stream.value=null);default:return this.failureCount.value++,this.publishing.value=!1,this.standby.value=!0,this.stopped.value=!1,this.stream.value=null,void(this.state.value=Xe.Error)}}},{key:"mapPublishStatusToPublisherStatus",value:function(e){switch(e){case"ok":return Xe.Starting;case"not-found":return Xe.NotFound;case"geo-restricted":return Xe.GeoRestricted;case"geo-blocked":return Xe.GeoBlocked;case"unauthorized":return Xe.Unauthorized;case"capacity":case"rate-limited":case"timeout":return Xe.Recovering;case"failed":return Xe.Error;default:L(e)}}},{key:"generateScreenName",value:function(){return D.random(12)}}]),e}(),tt=function(){function e(t,n,i){if(r()(this,e),u()(this,"_estimatedRoundTripTime",void 0),u()(this,"_estimatedVideoCodec",void 0),u()(this,"_estimatedAudioCodec",void 0),u()(this,"_rtcStatistic",new N({})),u()(this,"_peerConnection",void 0),u()(this,"_isMonitorRunning",!0),u()(this,"_updateTimeout",void 0),u()(this,"_availableTracks",void 0),this._peerConnection=t,this._estimatedRoundTripTime=i,this._peerConnection){var o=new Be(this._peerConnection.currentLocalDescription.sdp),a=new Be(this._peerConnection.currentRemoteDescription.sdp);this._estimatedAudioCodec=a.audioCodec,this._estimatedVideoCodec=a.videoCodec,this._availableTracks={audio:o.isAudioTrackEnabled&&a.isAudioTrackEnabled,video:o.isVideoTrackEnabled&&a.isVideoTrackEnabled},this.updateStatistic()}}var t;return a()(e,[{key:"rtcStatistic",get:function(){return this._rtcStatistic}},{key:"dispose",value:function(){this._isMonitorRunning=!1,this._peerConnection=null,this._updateTimeout&&(clearTimeout(this._updateTimeout),this._updateTimeout=null)}},{key:"updateStatistic",value:(t=g()(y().mark((function e(){var t,n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y.getStatsPromiseBasedDisabled){e.next=3;break}return e.abrupt("return");case 3:return t=function(e){return e.id.includes("Audio")?"audio":e.id.includes("Video")?"video":""},e.next=6,this._peerConnection.getStats(null).then((function(e){var i={};if(e){var r,o=n._estimatedRoundTripTime;e.forEach((function(a){if("candidate-pair"===a.type&&a.currentRoundTripTime&&(o=1e3*a.currentRoundTripTime,i.audio&&(i.audio.roundTripTime=o),i.video&&(i.video.roundTripTime=o)),"candidate-pair"===a.type&&a.lastPacketSentTimestamp&&(r=a.lastPacketSentTimestamp,i.audio&&(i.audio.lastPacketSentTimestamp=r),i.video&&(i.video.lastPacketSentTimestamp=r)),"outbound-rtp"===a.type){var s=a.kind||a.mediaType||t(a),u="";if(e.forEach((function(e){e.id===a.codecId&&(u=e.mimeType)})),s&&n._availableTracks[s]){var c,l,d,h,p,f=(a.bytesSent||0)-(null!==(c=null===(l=n._rtcStatistic.value)||void 0===l||null===(d=l[s])||void 0===d?void 0:d.bytesSent)&&void 0!==c?c:0),v=a.timestamp-(null===(h=n._rtcStatistic.value)||void 0===h||null===(p=h[s])||void 0===p?void 0:p.timestamp),m=f&&v?Math.floor(8*f/v*1e3):0;if(i[s]={ssrc:a.ssrc,mediaType:s,timestamp:a.timestamp,bitrate:m,bytesSent:a.bytesSent,packetsSent:a.packetsSent,retransmittedBytesSent:a.retransmittedBytesSent,codec:u||n.getCodecByType(s),roundTripTime:o},(a.lastPacketSentTimestamp||r)&&(i[s].lastPacketSentTimestamp=a.lastPacketSentTimestamp||r),"video"===s&&n._rtcStatistic.value&&n._rtcStatistic.value.video){i[s].firCount=a.firCount,i[s].frameHeight=a.frameHeight,i[s].frameWidth=a.frameWidth,i[s].framesEncoded=a.framesEncoded,i[s].framesSent=a.framesSent,i[s].headerBytesSent=a.headerBytesSent,i[s].hugeFramesSent=a.hugeFramesSent,i[s].pliCount=a.pliCount,i[s].qpSum=a.qpSum,i[s].totalEncodeTime=a.totalEncodeTime,i[s].totalEncodedBytesTarget=a.totalEncodedBytesTarget;var g=(a.framesEncoded-n._rtcStatistic.value.video.framesEncoded)/(i[s].timestamp-n._rtcStatistic.value.video.timestamp)*1e3;i[s].fps=g?Math.round(100*g)/100:0}}}}))}n._rtcStatistic.value=i})).then((function(){n._isMonitorRunning&&(n._updateTimeout=window.setTimeout((function(){return n.updateStatistic()}),1e3))}));case 6:e.sent;case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getCodecByType",value:function(e){switch(e){case"audio":return this._estimatedAudioCodec;case"video":return this._estimatedVideoCodec;default:return"unknown"}}}]),e}(),nt=n(202).default;function it(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function rt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?it(Object(n),!0).forEach((function(t){u()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):it(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var ot=function(){function e(t,n,i){r()(this,e),u()(this,"_logger",O.getLogger("RealTimePublisher")),u()(this,"_publisherContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_handleStreamFailure",void 0),this._publisherContext=t,this._peerConnectionContext=n,this._handleStreamFailure=i}var t;return a()(e,[{key:"start",value:function(e,t,n){var i=this;return navigator.onLine?nt.all([Ue.discoverClosestEndPointWithCaching(e),ne.createPeerConnectionOffer("sendonly")]).then((function(e){var n=Ee()(e,2),r=n[0],o=n[1],a=o.localOffer,s=o.peerConnection;return i._publisherContext.online.value=!0,i._publisherContext.endPoint.value=r,i._logger.info("Connecting to [%s]",r.toString()),i._logger.info("Local offer:\n"+a.sdp),(Y.clientOfferDisabled||!s.supportsSetConfiguration||!s.supportsGetConfiguration||i._publisherContext.failureCount.value>0)&&(s.close(),s=null,a=null),i._peerConnectionContext.peerConnection.value=s,r.publish(i._publisherContext.name,t,a,i._publisherContext.failureCount.value)})).then((function(e){var t=e.status,r=e.stream,o=e.rtcConfiguration,a=e.setRemoteDescriptionResponse,s=e.createOfferDescriptionResponse,u=e.createAnswerDescriptionResponse;if(i._publisherContext.stream.value=r,i._logger.debug("[%s] Publish completed [%s] [%j] [%j] [%j] [%j]",i._publisherContext.streamId,t,o,a,s,u),i._publisherContext.state.value=i._publisherContext.mapPublishStatusToPublisherStatus(t),i._publisherContext.applyStatus(t),"ok"===t)return i.applyRtcConfiguration(i._peerConnectionContext.peerConnection.value,o).then((function(e){var t,o=!1,c=!1,l=[];return i._peerConnectionContext.peerConnection.value=e,e.addStream(i._peerConnectionContext.mediaStream.value),e.onicecandidate=function(n){i._publisherContext.stream.value===r&&i._peerConnectionContext.peerConnection.value===e&&(o||pe.sendLocalCandidates.value&&(n.candidate&&n.candidate.candidate?l.push(n.candidate):c=!0,t||(t=setTimeout((function(){i._publisherContext.stream.value!==r||o||i._publisherContext.endPoint.value.addIceCandidates(r,l,c).then((function(e){var t=e.status,n=e.options;"ok"===t?(n.includes("cancel")&&(o=!0),i._logger.info("[%s] Added ICE candidates with reason [%s] and options [%s]",i._publisherContext.streamId,t,n)):i._logger.warn("[%s] Failed to add ICE candidates with reason [%s]",i._publisherContext.streamId,t)})).catch((function(e){i._logger.error("[%s] Failed to add ICE candidates",i._publisherContext.streamId,e)}))}),100))))},e.oniceconnectionstatechange=function(){if(i._publisherContext.stream.value===r&&i._peerConnectionContext.peerConnection.value===e){var t=function(){i._publisherContext.state.value=Xe.Error,i._publisherContext.publishing.value=!1,i._publisherContext.loading.value=!0,i._handleStreamFailure().catch((function(t){i._logger.error("[%s] Failed handling stream failure after peer connection stopped with state [%s]",i._publisherContext.streamId,e.iceConnectionState,t)}))};switch(e.iceConnectionState){case"checking":case"completed":case"connected":case"new":return;case"disconnected":case"failed":return i._logger.info("[%s] ICE connection state changed to [%s], trying to reconnect",i._publisherContext.streamId,e.iceConnectionState),void i.reconnectPeerConnection(e,t);case"closed":return i._logger.info("[%s] ICE connection state changed to [%s], retrying to connect",i._publisherContext.streamId,e.iceConnectionState),void t();default:L(e.iceConnectionState)}}},new nt((function(e){e()})).then((function(){if(a)return i._logger.info("[%s] Set local SDP offer [%s]",i._publisherContext.streamId,a.sessionDescription.sdp),e.setLocalDescription(a.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set local description [%j] with message [%s]",i._publisherContext.streamId,a.sessionDescription,e.message),e}))})).then((function(){if(u)return i._logger.info("[%s] Set remote SDP answer [%s]",i._publisherContext.streamId,u.sessionDescription.sdp),e.setRemoteDescription(u.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set remote description [%j] with message [%s]",i._publisherContext.streamId,u.sessionDescription,e.message),e}))})).then((function(){if(s)return i._logger.info("[%s] Set remote SDP offer [%s]",i._publisherContext.streamId,s.sessionDescription.sdp),e.setRemoteDescription(s.sessionDescription).catch((function(e){throw i._logger.info("[%s] Failed to set remote description [%j] with message [%s]",i._publisherContext.streamId,u.sessionDescription,e.message),e})).then((function(){return e.createAnswer({offerToReceiveAudio:!1,offerToReceiveVideo:!1})})).then((function(e){return i._logger.info("[%s] Set local SDP answer [%s]",i._publisherContext.streamId,e.sdp),i._publisherContext.endPoint.value.setRemoteDescription(r,e)})).then((function(t){var n=t.status,r=t.sessionDescription;return i._publisherContext.state.value=i.mapSetRemoteDescriptionStatusToPublisherStatus(n),"ok"!==n?(i._publisherContext.publishing.value=!1,i._publisherContext.standby.value=!0,void(i._publisherContext.stopped.value=!1)):(i._logger.info("[%s] Set local SDP [%s]",i._publisherContext.streamId,r.sdp),e.setLocalDescription(r).catch((function(e){throw i._logger.info("[%s] Failed to set local description [%j] with message [%s]",i._publisherContext.streamId,r,e.message),e})))}))})).then((function(){return n.success(i._publisherContext.streamId),i._publisherContext.state.value=Xe.Publishing,i._publisherContext.publishing.value=!0,new tt(e,i._peerConnectionContext.mediaStream.value,i._publisherContext.endPoint.value.roundTripTime/4).rtcStatistic.subscribe((function(e){i._publisherContext.rtcStatistics.value=e})),nt.resolve()}))}))})):(this._publisherContext.state.value=Xe.Offline,nt.resolve())}},{key:"applyRtcConfiguration",value:(t=g()(y().mark((function e(t,n){var i;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=3;break}return n=ze.truncateIceServers(n),e.abrupt("return",pe.peerConnectionFactory.value.createPeerConnection(n));case 3:return i=rt(rt({},t.getConfiguration()),n),t.setConfiguration(i),e.abrupt("return",t);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"reconnectPeerConnection",value:function(e,t){var n=this;if("closed"!==e.iceConnectionState)if(this._publisherContext.state.value=Xe.Reconnecting,this._peerConnectionContext.peerConnectionReconnectAttempts<pe.maximalNumberOfPeerConnectionReconnectAttempts||!pe.automaticallyReconnectPeerConnection){var i;this._peerConnectionContext.peerConnectionReconnectAttempts++;var r="offer"===(null===(i=e.currentLocalDescription)||void 0===i?void 0:i.type);if(Y.clientOfferDisabled||!e.supportsSetConfiguration||!e.supportsGetConfiguration||!r){var o=setTimeout((function(){n.reconnectPeerConnection(e,t)}),1e3);return void this._publisherContext.disposables.add(new U((function(){return clearTimeout(o)})))}this._logger.info("Reconnecting peer connection by restarting ICE");var a=e.currentLocalDescription;e.createOffer({iceRestart:!0}).then((function(i){return e.setLocalDescription(i).then((function(){return e.setLocalDescription(a).then((function(){if("disconnected"===e.iceConnectionState||"failed"===e.iceConnectionState){var i=setTimeout((function(){n.reconnectPeerConnection(e,t)}),1e3);n._publisherContext.disposables.add(new U((function(){return clearTimeout(i)})))}else n._publisherContext.state.value=Xe.Publishing}))}))})).catch((function(e){n._logger.error("Failed to reconnect peer connection",e),n._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}))}else this._logger.info("Failed to reconnect peer connection after [%s] attempts, performing full recovery",this._peerConnectionContext.peerConnectionReconnectAttempts),this._peerConnectionContext.peerConnectionReconnectAttempts=0,t()}},{key:"mapSetRemoteDescriptionStatusToPublisherStatus",value:function(e){switch(e){case"ok":return Xe.Starting;case"unauthorized":return Xe.Unauthorized;case"not-found":return Xe.NotFound;case"capacity":case"rate-limited":case"timeout":return Xe.Recovering;case"failed":return Xe.Error;default:L(e)}}}]),e}(),at=n(202).default,st=function(){function e(t,n,i){var o=this;r()(this,e),u()(this,"_logger",O.getLogger("Publisher")),u()(this,"_tokenContext",void 0),u()(this,"_publisherContext",void 0),u()(this,"_peerConnectionContext",void 0),u()(this,"_stateContext",void 0),u()(this,"_exponentialBackoff",void 0),u()(this,"_publisherStartTime",void 0),u()(this,"_readOnlyToken",void 0),u()(this,"_readOnlyPeerConnection",void 0),u()(this,"_readOnlyState",void 0),u()(this,"_readOnlyTokenExpiring",void 0),u()(this,"_readOnlyAuthorized",void 0),u()(this,"_readOnlyOnline",void 0),u()(this,"_readOnlyLoading",void 0),u()(this,"_readOnlyPublishing",void 0),u()(this,"_readOnlyStandby",void 0),u()(this,"_readOnlyStopped",void 0),u()(this,"_readOnlyFailureCount",void 0),u()(this,"_readOnlyEndPoint",void 0),u()(this,"_readOnlyStream",void 0),u()(this,"_readOnlyRtcStatistics",void 0),u()(this,"_readOnlyMediaStream",void 0),u()(this,"_metricsService",void 0),u()(this,"_sessionTelemetry",void 0),this._tokenContext=new Se(n),this._publisherContext=new et(i),this._peerConnectionContext=new Le,this._stateContext=new Pe,this._exponentialBackoff=new ve,this._publisherStartTime=Date.now(),this._readOnlyToken=new z(this._tokenContext.token),this._readOnlyPeerConnection=new z(this._peerConnectionContext.peerConnection),this._readOnlyState=new z(this._publisherContext.state),this._readOnlyTokenExpiring=new z(this._tokenContext.tokenExpiring),this._readOnlyAuthorized=new z(this._publisherContext.authorized),this._readOnlyOnline=new z(this._publisherContext.online),this._readOnlyLoading=new z(this._publisherContext.loading),this._readOnlyPublishing=new z(this._publisherContext.publishing),this._readOnlyStandby=new z(this._publisherContext.standby),this._readOnlyStopped=new z(this._publisherContext.stopped),this._readOnlyFailureCount=new z(this._publisherContext.failureCount),this._readOnlyEndPoint=new z(this._publisherContext.endPoint),this._readOnlyStream=new z(this._publisherContext.stream),this._readOnlyRtcStatistics=new z(this._publisherContext.rtcStatistics),this._readOnlyMediaStream=new z(this._peerConnectionContext.mediaStream),this._peerConnectionContext.mediaStream.value=t;var a=H.parseToken(this._tokenContext.token.value),s=(a.uri||pe.discoveryUri.value).toString();pe.tenancy.value=a.tenancy||pe.tenancy.value,ae.uri.value=s,this._metricsService=de.getMetricsService(s),this._sessionTelemetry=new ke(pe.pageLoadTime,this._metricsService),this._publisherContext.publisherDisposables.add(this._sessionTelemetry),this._publisherContext.publisherDisposables.add(this._publisherContext.state.subscribe((function(e){o._publisherContext.clearFailureCountTimeout&&clearTimeout(o._publisherContext.clearFailureCountTimeout),o._publisherContext.failureCount.value&&e===Xe.Publishing&&(o._publisherContext.clearFailureCountTimeout=window.setTimeout((function(){o._publisherContext.failureCount.value=0}),3e3))})));var c=function(){o._publisherContext.stream.value&&o._publisherContext.endPoint.value&&o._publisherContext.endPoint.value.destroyStreamOnUnmount(o._publisherContext.stream.value,"client:termination-on-window-unload")};window.addEventListener("beforeunload",c),this._publisherContext.publisherDisposables.add(new U((function(){window.removeEventListener("beforeunload",c)}))),this.start()}var t,n,i,o,s;return a()(e,[{key:"token",get:function(){return this._tokenContext.token.value},set:function(e){this._publisherContext.disposables.dispose(),this._tokenContext.token.value=e,this._tokenContext.tokenExpiring.value=!1;var t=H.parseToken(this._tokenContext.token.value),n=(t.uri||pe.discoveryUri.value).toString();pe.tenancy.value=t.tenancy||pe.tenancy.value,ae.uri.value=n,this._metricsService=de.getMetricsService(n),this.start()}},{key:"peerConnection",get:function(){return this._readOnlyPeerConnection}},{key:"state",get:function(){return this._readOnlyState}},{key:"tokenExpiring",get:function(){return this._readOnlyTokenExpiring}},{key:"authorized",get:function(){return this._readOnlyAuthorized}},{key:"online",get:function(){return this._readOnlyOnline}},{key:"loading",get:function(){return this._readOnlyLoading}},{key:"publishing",get:function(){return this._readOnlyPublishing}},{key:"standby",get:function(){return this._readOnlyStandby}},{key:"stopped",get:function(){return this._readOnlyStopped}},{key:"failureCount",get:function(){return this._readOnlyFailureCount}},{key:"endPoint",get:function(){return this._readOnlyEndPoint}},{key:"stream",get:function(){return this._readOnlyStream}},{key:"streamId",get:function(){return this._publisherContext.streamId}},{key:"rtcStatistics",get:function(){return this._readOnlyRtcStatistics}},{key:"mediaStream",get:function(){return this._readOnlyMediaStream}},{key:"stop",value:(s=g()(y().mark((function e(t){var n=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new at((function(e){if(!n._stateContext.isStarting.value)return n.processStop(t),void e();n._publisherContext.disposables.add(n._stateContext.isStarting.subscribe((function(i){i||(n.processStop(t),e())})))})));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"processStop",value:function(e){this.cleanUpResources(e),this._peerConnectionContext.peerConnection.value&&(this._peerConnectionContext.peerConnection.value.close(),this._peerConnectionContext.peerConnection.value=null),this._publisherContext.state.value=Xe.Stopped}},{key:"dispose",value:(o=g()(y().mark((function e(){var t=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stop("client:channel-dispose").then((function(){t._publisherContext.publisherDisposables.dispose(),t._stateContext.isDisposed=!0})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getUri",value:function(e){return H.parseToken(e).uri||(this._logger.info("Fall back to the default discover URI [%s]",pe.discoveryUri.value),new URL(pe.discoveryUri.value))}},{key:"start",value:(i=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._stateContext.isDisposed){e.next=2;break}throw new Error("Channel was already disposed");case 2:if(!this._stateContext.isStarting.value){e.next=5;break}return this._logger.info("Publisher is already starting, skipping start"),e.abrupt("return");case 5:return this._stateContext.isStarting.value=!0,e.abrupt("return",this.processStart());case 7:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"setMediaStream",value:function(e){var t=this;this._peerConnectionContext.mediaStream.value=e,this._peerConnectionContext.peerConnection.value&&e.getTracks().forEach((function(e){t._peerConnectionContext.peerConnection.value.getSenders().forEach((function(t){var n;e.kind===(null==t||null===(n=t.track)||void 0===n?void 0:n.kind)&&e.id!==t.track.id&&t.replaceTrack(e)}))}))}},{key:"processStart",value:(n=g()(y().mark((function e(){var t,n,i,r,o,a=this;return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._tokenContext.token.value,n=this._sessionTelemetry.listenOnStreamSetup(),H.isEncodedEdgeTokenValid(t)){e.next=8;break}return this._logger.error("Failed to parse token [%s]",t),this._publisherContext.state.value=Xe.Unauthorized,this._publisherContext.authorized.value=!1,this._stateContext.isStarting.value=!1,e.abrupt("return");case 8:return this.cleanUpResources("client:start"),this._publisherContext.state.value=Xe.Starting,this._publisherContext.loading.value=!0,i=this.getUri(t),r=function(){return new at((function(e){return a._stateContext.isStarting.value=!1,e(a.handleStreamFailure())}))},o=new ot(this._publisherContext,this._peerConnectionContext,r),e.abrupt("return",o.start(i,t,n).then((function(){a._publisherContext.loading.value=!1})).catch((function(e){n.fail(),a._publisherContext.failureCount.value++,a._publisherContext.online.value=!1,a.cleanUpResources("client:cleanup-after-failed-setup"),a._publisherContext.state.value=Xe.Error,a._logger.error("Failed to start publishing",e)})).finally((function(){if(a._stateContext.isStarting.value=!1,a._publisherContext.state.value!==Xe.Publishing&&pe.automaticRetryOnFailure){var e=setTimeout((function(){a.handleStreamFailure().catch((function(e){a._logger.error("Failed handling stream failure",e)}))}),a.getRetryInterval());a._publisherContext.disposables.add(new U((function(){clearTimeout(e)})))}else a._publisherContext.startReconnectionAttemptsTimeInMilliseconds=0})));case 15:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getRetryInterval",value:function(){switch(this._publisherContext.state.value){case Xe.Offline:return 15e3;case Xe.NotFound:case Xe.Error:case Xe.Recovering:case Xe.Unauthorized:case Xe.GeoRestricted:case Xe.GeoBlocked:case Xe.Stopped:case Xe.Starting:case Xe.Publishing:case Xe.Reconnecting:case Xe.UnsupportedFeature:return this._exponentialBackoff.getExponentialBackoffIntervalByFailureCount(this._publisherContext.failureCount.value);default:L(this._publisherContext.state.value)}}},{key:"handleStreamFailure",value:(t=g()(y().mark((function e(){return y().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=this._publisherContext.state.value,e.next=e.t0===Xe.Error||e.t0===Xe.Reconnecting||e.t0===Xe.Offline||e.t0===Xe.Recovering?4:e.t0===Xe.Unauthorized?11:e.t0===Xe.GeoRestricted?13:e.t0===Xe.GeoBlocked?15:e.t0===Xe.Stopped?17:e.t0===Xe.Publishing?19:e.t0===Xe.Starting?21:e.t0===Xe.UnsupportedFeature?23:e.t0===Xe.NotFound?25:27;break;case 4:if(this._publisherContext.startReconnectionAttemptsTimeInMilliseconds||(this._publisherContext.startReconnectionAttemptsTimeInMilliseconds=Date.now()),!(72e5<=Date.now()-this._publisherContext.startReconnectionAttemptsTimeInMilliseconds)){e.next=9;break}return this._logger.info("Publisher stopped with state [%s] [%s] after exceeding timeout",this._publisherContext.state.value,Xe[this._publisherContext.state.value]),e.abrupt("return");case 9:return this._logger.info("Retry start with initial state [%s] [%s]",this._publisherContext.state.value,Xe[this._publisherContext.state.value]),e.abrupt("break",28);case 11:return this._logger.info("Publisher is unauthorized, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 13:return this._logger.info("Publisher is geo restricted, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 15:return this._logger.info("Publisher is geo blocked, skipping retry of start. Please provide a new token and invoke start()"),e.abrupt("return");case 17:return this._logger.info("Publisher is stopped, skipping retry of start."),e.abrupt("return");case 19:return this._logger.info("Publisher is publishing, skipping retry of start"),e.abrupt("return");case 21:return this._logger.info("Publisher is already starting, skipping retry of start"),e.abrupt("return");case 23:return this._logger.info("Publisher is stopped due to unsupported feature, skipping retry of start."),e.abrupt("return");case 25:return this._logger.info("Publisher is stopped due to channel not found, skipping retry of start."),e.abrupt("return");case 27:L(this._publisherContext.state.value);case 28:return e.abrupt("return",this.start());case 29:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"cleanUpResources",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"client:termination";this._publisherContext.disposables.dispose();var n=this._peerConnectionContext.peerConnection.value;n&&(this._peerConnectionContext.peerConnection.value=null,n.close()),this._publisherContext.publishing.value=!1,this._publisherContext.stopped.value=!0,this._publisherContext.standby.value=!1,this._publisherContext.stream.value&&this._publisherContext.endPoint.value&&this._publisherContext.endPoint.value.destroyStream(this._publisherContext.stream.value,t).then((function(t){var n=t.status;"ok"===n?e._logger.info("[%s] Destroyed stream with reason [%s]",e.streamId,n):e._logger.warn("[%s] Failed to destroy stream with reason [%s]",e.streamId,n)})).catch((function(t){e._logger.error("[%s] Failed to destroy stream",e.streamId,t)})),this._publisherContext.stream.value=null,this._publisherContext.endPoint.value=null,this._peerConnectionContext.peerConnectionReconnectAttempts=0}}]),e}(),ut=function(){function e(){throw r()(this,e),new Error("Publishers is a static class that may not be instantiated")}return a()(e,null,[{key:"createPublisher",value:function(e){if(!pe.initialized.value)throw new Error("SDK is not loaded.");return new st(e.mediaStream,e.token,e.name)}}]),e}(),ct={SDK:pe,Channels:Ze,ChannelState:ge,Publishers:ut,PublisherState:Xe}}},t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}return n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(958)})()}));
|
|
3
3
|
//# sourceMappingURL=full.js.map
|