@mastra/deployer-cloud 1.80.0-alpha.2 → 1.80.0-alpha.4
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/dist/index.cjs +9 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -16
- package/dist/index.js.map +1 -1
- package/dist/studio/assets/CodeDiff.es-yDX8ENTX.js +305 -0
- package/dist/studio/assets/{ada-C5qYipkI.js → ada-X3Y2mlq2.js} +1 -1
- package/dist/studio/assets/{ahk-CA9gdOdF.js → ahk-DwADkxyd.js} +1 -1
- package/dist/studio/assets/{angular-html-DolB2A6S.js → angular-html-BswFT_28.js} +1 -1
- package/dist/studio/assets/angular-html-DOLkzBtu.js +1 -0
- package/dist/studio/assets/{angular-ts-B1PKGDnJ.js → angular-ts-DOMhGxLQ.js} +1 -1
- package/dist/studio/assets/{apl-BmC_IO_Q.js → apl-Dio8Ke0X.js} +1 -1
- package/dist/studio/assets/{astro-SDMRz_OH.js → astro-CN6YWUG3.js} +1 -1
- package/dist/studio/assets/babel-B_E7dii_.js +16 -0
- package/dist/studio/assets/beancount-C2IN4Vk8.js +1 -0
- package/dist/studio/assets/{blade-B6w4c-X9.js → blade-BrDpNfUX.js} +1 -1
- package/dist/studio/assets/{cobol-CtA7PaQL.js → cobol-BvqUwMCV.js} +1 -1
- package/dist/studio/assets/coq-CGaSfhwR.js +1 -0
- package/dist/studio/assets/{crystal-BezZpOOT.js → crystal-DEF7AEJQ.js} +1 -1
- package/dist/studio/assets/csharp-B3DbjJyj.js +1 -0
- package/dist/studio/assets/csharp-CFKDkFDZ.js +1 -0
- package/dist/studio/assets/css-BGIxQoYs.js +1 -0
- package/dist/studio/assets/css-DgaLhXQH.js +1 -0
- package/dist/studio/assets/dart-DjhkpiWP.js +1 -0
- package/dist/studio/assets/dart-_dH3dQdM.js +1 -0
- package/dist/studio/assets/{dist-D73uoo3G.js → dist-BVq4x0k2.js} +1 -1
- package/dist/studio/assets/dist-BZ0nnT2j.js +1 -0
- package/dist/studio/assets/dist-BcV0fxOe.js +23 -0
- package/dist/studio/assets/dist-CmRzlq9h.js +1 -0
- package/dist/studio/assets/dist-Dcq2nGKl.js +6 -0
- package/dist/studio/assets/dist-DjFwFQ6-.js +1 -0
- package/dist/studio/assets/dist-DkOJ_COt.js +1 -0
- package/dist/studio/assets/dist-rcSvr8nT.js +13 -0
- package/dist/studio/assets/dist-t_wjP-TL.js +1 -0
- package/dist/studio/assets/dotenv-CuH5my32.js +1 -0
- package/dist/studio/assets/{edge-D7PqnmbS.js → edge-B_SBzXGF.js} +1 -1
- package/dist/studio/assets/{elixir-DeblBytM.js → elixir-BL8v4QDr.js} +1 -1
- package/dist/studio/assets/elixir-BN3BkYei.js +1 -0
- package/dist/studio/assets/emacs-lisp-DR2vtWaj.js +1 -0
- package/dist/studio/assets/{erb-BfjjH6As.js → erb-BjlLGk-_.js} +1 -1
- package/dist/studio/assets/{estree-vwDM3qKy.js → estree-CvDFpEmC.js} +1 -1
- package/dist/studio/assets/{glimmer-js-DHbJ63Uk.js → glimmer-js-CIdbWayl.js} +1 -1
- package/dist/studio/assets/{glimmer-ts-78YraEOQ.js → glimmer-ts-B16xCo2k.js} +1 -1
- package/dist/studio/assets/gn-CAXYAgV-.js +1 -0
- package/dist/studio/assets/{hack-i70bJskv.js → hack-C30D-q0p.js} +1 -1
- package/dist/studio/assets/haml-BU6KMePS.js +1 -0
- package/dist/studio/assets/{haml-CAMQ1nWo.js → haml-C1zHJAQt.js} +1 -1
- package/dist/studio/assets/handlebars-WZCg7K7Q.js +1 -0
- package/dist/studio/assets/handlebars-g-3gLrXt.js +1 -0
- package/dist/studio/assets/html-BCy9P6D2.js +1 -0
- package/dist/studio/assets/{html-B2cKP6UN.js → html-DSw1lh5G.js} +1 -1
- package/dist/studio/assets/{html-derivative-Dhubv07u.js → html-derivative-DyzJkWO6.js} +1 -1
- package/dist/studio/assets/html-derivative-ekTk9Unt.js +1 -0
- package/dist/studio/assets/{index-DiwHG7Kc.js → index-CStRllzQ.js} +2 -2
- package/dist/studio/assets/{jinja-CRuWSMeX.js → jinja-dRcm23Ea.js} +1 -1
- package/dist/studio/assets/julia-C8a5hZkp.js +1 -0
- package/dist/studio/assets/{julia-3RSkklau.js → julia-hqywDEUR.js} +1 -1
- package/dist/studio/assets/{just-G7MH58_L.js → just-CP_wDfXI.js} +1 -1
- package/dist/studio/assets/latex-B_Ztlc7G.js +1 -0
- package/dist/studio/assets/latex-Bn9nYtub.js +1 -0
- package/dist/studio/assets/lib-DRuii7jc.js +1 -0
- package/dist/studio/assets/{liquid-DdvxCDBI.js → liquid-CQNtsgCr.js} +1 -1
- package/dist/studio/assets/livekit-client.esm-DMHgtGvw.js +39 -0
- package/dist/studio/assets/luau-VGWVLoqX.js +1 -0
- package/dist/studio/assets/main-DW5us475.js +699 -0
- package/dist/studio/assets/marko-DPS0EkZ1.js +1 -0
- package/dist/studio/assets/{mdc-Cm3Vtzgo.js → mdc-C6srEd4p.js} +1 -1
- package/dist/studio/assets/monokai-BscAjiQZ.js +1 -0
- package/dist/studio/assets/moonbit-D9W784E_.js +1 -0
- package/dist/studio/assets/{nextflow-groovy-C6U6GzKG.js → nextflow-groovy-C770ykRh.js} +1 -1
- package/dist/studio/assets/nextflow-groovy-D5vAge1Z.js +1 -0
- package/dist/studio/assets/nextflow-uA5IJerx.js +1 -0
- package/dist/studio/assets/nim-DN3EGtL-.js +1 -0
- package/dist/studio/assets/{nim-CkcqHVhZ.js → nim-ZjzS1dcU.js} +1 -1
- package/dist/studio/assets/nushell--0fT3PI1.js +1 -0
- package/dist/studio/assets/one-dark-pro-C6YyR8OD.js +1 -0
- package/dist/studio/assets/{org-BIKsc680.js → org-BRAbLUOJ.js} +1 -1
- package/dist/studio/assets/p-map-D81h6UuU.js +1 -0
- package/dist/studio/assets/perl-Ciba4h2-.js +1 -0
- package/dist/studio/assets/{perl-CrgxsDZk.js → perl-sgZsTtaf.js} +1 -1
- package/dist/studio/assets/php-D9QpVhjP.js +1 -0
- package/dist/studio/assets/php-DBfnyu6d.js +1 -0
- package/dist/studio/assets/powershell-Blb2ISmZ.js +1 -0
- package/dist/studio/assets/{powershell-CB0_OCr_.js → powershell-CItYMEtV.js} +1 -1
- package/dist/studio/assets/pug-C_nSP9Mg.js +1 -0
- package/dist/studio/assets/{pug-ikVFMdBJ.js → pug-nGRwXpob.js} +1 -1
- package/dist/studio/assets/{razor-Ble7Vzo2.js → razor-UAq-8THt.js} +1 -1
- package/dist/studio/assets/red-CYlAq2b0.js +1 -0
- package/dist/studio/assets/{rst-CkovH8lR.js → rst-BCaXiUC4.js} +1 -1
- package/dist/studio/assets/ruby-C4ARPOX3.js +1 -0
- package/dist/studio/assets/{ruby-Dg1QxBW5.js → ruby-Dl3oLoVp.js} +1 -1
- package/dist/studio/assets/rust-Ch0zZBV0.js +1 -0
- package/dist/studio/assets/rust-DBZE5Si3.js +1 -0
- package/dist/studio/assets/{sas-2IEyvoFV.js → sas-BowjnAvi.js} +1 -1
- package/dist/studio/assets/{scss-CPpsOPrU.js → scss-CWs8DVSa.js} +1 -1
- package/dist/studio/assets/scss-D3wBkj3d.js +1 -0
- package/dist/studio/assets/solarized-dark-b97czJOk.js +1 -0
- package/dist/studio/assets/solarized-light-DFPxpIYQ.js +1 -0
- package/dist/studio/assets/{soy-A62BAwxz.js → soy-CUUUw2U6.js} +1 -1
- package/dist/studio/assets/sql-CNu3Or2W.js +1 -0
- package/dist/studio/assets/sql-CfM2IJm3.js +1 -0
- package/dist/studio/assets/{stata-BGsmlsHF.js → stata-Dj4sbAEx.js} +1 -1
- package/dist/studio/assets/style-IQMl5TX8.css +3 -0
- package/dist/studio/assets/{svelte-DcpG3o7o.js → svelte-BaCIHHWd.js} +1 -1
- package/dist/studio/assets/{templ-CvnTbAXa.js → templ-BfgLc4ra.js} +1 -1
- package/dist/studio/assets/{ts-tags--pZs7vYD.js → ts-tags-DLz2GTd3.js} +1 -1
- package/dist/studio/assets/twig-HaHkB3PH.js +1 -0
- package/dist/studio/assets/twig-lMQ09cjh.js +1 -0
- package/dist/studio/assets/typespec-BGhR2SqG.js +1 -0
- package/dist/studio/assets/{typst-Czf1dSai.js → typst-DDNSzYFN.js} +1 -1
- package/dist/studio/assets/{vue-CAw-zJtI.js → vue-qH43U_rv.js} +1 -1
- package/dist/studio/assets/{vue-vine-DPTR_ZYD.js → vue-vine-6XI2pIvQ.js} +1 -1
- package/dist/studio/assets/yaml-BEzOWJ7L.js +1 -0
- package/dist/studio/index.html +2 -2
- package/package.json +9 -9
- package/versions.json +1 -1
- package/dist/studio/assets/CodeDiff.es-ttVWjiVn.js +0 -305
- package/dist/studio/assets/angular-html-06u8ifAB.js +0 -1
- package/dist/studio/assets/babel-qZlmxQ8K.js +0 -16
- package/dist/studio/assets/beancount-D-usSTwE.js +0 -1
- package/dist/studio/assets/coq-DuBRPxYg.js +0 -1
- package/dist/studio/assets/csharp-BviNWcUb.js +0 -1
- package/dist/studio/assets/csharp-DoUovMB6.js +0 -1
- package/dist/studio/assets/css-BN7bbgzh.js +0 -1
- package/dist/studio/assets/css-LbU1hoFO.js +0 -1
- package/dist/studio/assets/dart-BcpK88xC.js +0 -1
- package/dist/studio/assets/dart-zFqxHoQA.js +0 -1
- package/dist/studio/assets/dist-BeXC2sV7.js +0 -1
- package/dist/studio/assets/dist-BgTAL0Im.js +0 -1
- package/dist/studio/assets/dist-C4qaiM5N.js +0 -1
- package/dist/studio/assets/dist-CTvjM30z.js +0 -1
- package/dist/studio/assets/dist-CXMb7aeG.js +0 -13
- package/dist/studio/assets/dist-CgVs1BGt.js +0 -1
- package/dist/studio/assets/dist-DIJvMGBR.js +0 -23
- package/dist/studio/assets/dist-DOBwC-Vj.js +0 -6
- package/dist/studio/assets/dotenv-_5a1GRtc.js +0 -1
- package/dist/studio/assets/elixir-BjfTbpsD.js +0 -1
- package/dist/studio/assets/emacs-lisp-c_oH4hRZ.js +0 -1
- package/dist/studio/assets/gn-ilITqXS6.js +0 -1
- package/dist/studio/assets/haml-3Fo4mycZ.js +0 -1
- package/dist/studio/assets/handlebars-B5qiZlCO.js +0 -1
- package/dist/studio/assets/handlebars-CXhBu6gL.js +0 -1
- package/dist/studio/assets/html-Bls34fXK.js +0 -1
- package/dist/studio/assets/html-derivative-CPgLVSxm.js +0 -1
- package/dist/studio/assets/julia-DKmDyKMZ.js +0 -1
- package/dist/studio/assets/latex-CLPpIAp7.js +0 -1
- package/dist/studio/assets/latex-YWqeWI-c.js +0 -1
- package/dist/studio/assets/lib-DGXbRLQi.js +0 -1
- package/dist/studio/assets/livekit-client.esm-D6tj57cg.js +0 -39
- package/dist/studio/assets/luau-C2pBCSgt.js +0 -1
- package/dist/studio/assets/main-DpHSIux5.js +0 -693
- package/dist/studio/assets/marko-DJ3i0CIR.js +0 -1
- package/dist/studio/assets/monokai-B_bV9PQ9.js +0 -1
- package/dist/studio/assets/moonbit-DgjMoLWr.js +0 -1
- package/dist/studio/assets/nextflow-groovy-DQJ40bag.js +0 -1
- package/dist/studio/assets/nextflow-rSIivlom.js +0 -1
- package/dist/studio/assets/nim-BLCC9zUt.js +0 -1
- package/dist/studio/assets/nushell-DHYfO66s.js +0 -1
- package/dist/studio/assets/one-dark-pro-CLwyXe_n.js +0 -1
- package/dist/studio/assets/p-map-C_4OPQuz.js +0 -1
- package/dist/studio/assets/perl-DldNfCGA.js +0 -1
- package/dist/studio/assets/php-B1kreupY.js +0 -1
- package/dist/studio/assets/php-kBxV6T2i.js +0 -1
- package/dist/studio/assets/powershell-BAeOcVkI.js +0 -1
- package/dist/studio/assets/pug-B0eKJDyz.js +0 -1
- package/dist/studio/assets/red-DX1BQOs8.js +0 -1
- package/dist/studio/assets/ruby-DfKa-Cpp.js +0 -1
- package/dist/studio/assets/rust-08ePcFzV.js +0 -1
- package/dist/studio/assets/rust-CSjmjZYD.js +0 -1
- package/dist/studio/assets/scss-CTp9_vex.js +0 -1
- package/dist/studio/assets/solarized-dark-UdsmMDCL.js +0 -1
- package/dist/studio/assets/solarized-light-C1IUL_tW.js +0 -1
- package/dist/studio/assets/sql-CP0rg-5b.js +0 -1
- package/dist/studio/assets/sql-DOnR2rig.js +0 -1
- package/dist/studio/assets/style-CdGeZT6C.css +0 -3
- package/dist/studio/assets/twig-BL9b48tu.js +0 -1
- package/dist/studio/assets/twig-CiXWCF20.js +0 -1
- package/dist/studio/assets/typespec-BRdr0IET.js +0 -1
- package/dist/studio/assets/yaml-DjjjKWKb.js +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function e(e,t){return t.forEach(function(t){t&&typeof t!=`string`&&!Array.isArray(t)&&Object.keys(t).forEach(function(n){if(n!=="default"&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})}),Object.freeze(e)}var t=Object.defineProperty,n=(e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,r=(e,t,r)=>n(e,typeof t==`symbol`?t:t+``,r),i=class{constructor(){r(this,`_locking`),r(this,`_locks`),this._locking=Promise.resolve(),this._locks=0}isLocked(){return this._locks>0}lock(){this._locks+=1;let e,t=new Promise(t=>e=()=>{--this._locks,t()}),n=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),n}};function a(e,t){if(!e)throw Error(t)}var o=34028234663852886e22,s=-34028234663852886e22,c=4294967295,l=2147483647,u=-2147483648;function d(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>l||e<u)throw Error(`invalid int 32: `+e)}function f(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>c||e<0)throw Error(`invalid uint 32: `+e)}function p(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>o||e<s))throw Error(`invalid float 32: `+e)}var ee=Symbol(`@bufbuild/protobuf/enum-type`);function te(e){let t=e[ee];return a(t,`missing enum type on enum object`),t}function ne(e,t,n,r){e[ee]=re(t,n.map(t=>({no:t.no,name:t.name,localName:e[t.no]})))}function re(e,t,n){let r=Object.create(null),i=Object.create(null),a=[];for(let e of t){let t=ae(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName(e){return r[e]},findNumber(e){return i[e]}}}function ie(e,t,n){let r={};for(let e of t){let t=ae(e);r[t.localName]=t.no,r[t.no]=t.localName}return ne(r,e,t),r}function ae(e){return`localName`in e?e:Object.assign(Object.assign({},e),{localName:e.name})}var oe=class{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){let n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){let n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`cannot decode ${this.getType().typeName} from JSON: ${e instanceof Error?e.message:String(e)}`)}return this.fromJson(n,t)}toBinary(e){let t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){let t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){let t=this.toJson(e);return JSON.stringify(t,null,e?.prettySpaces??0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}};function se(e,t,n,r){let i=r?.localName??t.substring(t.lastIndexOf(`.`)+1),a={[i]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[i];return Object.setPrototypeOf(a.prototype,new oe),Object.assign(a,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary(e,t){return new a().fromBinary(e,t)},fromJson(e,t){return new a().fromJson(e,t)},fromJsonString(e,t){return new a().fromJsonString(e,t)},equals(t,n){return e.util.equals(a,t,n)}}),a}function ce(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}throw Error(`invalid varint`)}function le(e,t,n){for(let r=0;r<28;r+=7){let i=e>>>r,a=!(!(i>>>7)&&t==0),o=(a?i|128:i)&255;if(n.push(o),!a)return}let r=e>>>28&15|(t&7)<<4,i=!!(t>>3);if(n.push((i?r|128:r)&255),i){for(let e=3;e<31;e+=7){let r=t>>>e,i=!!(r>>>7),a=(i?r|128:r)&255;if(n.push(a),!i)return}n.push(t>>>31&1)}}var ue=4294967296;function de(e){let t=e[0]===`-`;t&&(e=e.slice(1));let n=1e6,r=0,i=0;function a(t,a){let o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=ue&&(i+=r/ue|0,r%=ue)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?ge(r,i):he(r,i)}function fe(e,t){let n=he(e,t),r=n.hi&2147483648;r&&(n=ge(n.lo,n.hi));let i=pe(n.lo,n.hi);return r?`-`+i:i}function pe(e,t){var n=me(e,t);if(e=n.lo,t=n.hi,t<=2097151)return String(ue*t+e);let r=e&16777215,i=(e>>>24|t<<8)&16777215,a=t>>16&65535,o=r+i*6777216+a*6710656,s=i+a*8147497,c=a*2,l=1e7;return o>=l&&(s+=Math.floor(o/l),o%=l),s>=l&&(c+=Math.floor(s/l),s%=l),c.toString()+_e(s)+_e(o)}function me(e,t){return{lo:e>>>0,hi:t>>>0}}function he(e,t){return{lo:e|0,hi:t|0}}function ge(e,t){return t=~t,e?e=~e+1:t+=1,he(e,t)}var _e=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function ve(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function ye(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let t=5;e&128&&t<10;t++)e=this.buf[this.pos++];if(e&128)throw Error(`invalid varint`);return this.assertBounds(),t>>>0}function be(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt==`function`&&typeof e.getBigInt64==`function`&&typeof e.getBigUint64==`function`&&typeof e.setBigInt64==`function`&&typeof e.setBigUint64==`function`&&{}.BUF_BIGINT_DISABLE!==`1`){let t=BigInt(`-9223372036854775808`),n=BigInt(`9223372036854775807`),r=BigInt(`0`),i=BigInt(`18446744073709551615`);return{zero:BigInt(0),supported:!0,parse(e){let r=typeof e==`bigint`?e:BigInt(e);if(r>n||r<t)throw Error(`int64 invalid: ${e}`);return r},uParse(e){let t=typeof e==`bigint`?e:BigInt(e);if(t>i||t<r)throw Error(`uint64 invalid: ${e}`);return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)},uDec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0)}}}let t=e=>a(/^-?[0-9]+$/.test(e),`int64 invalid: ${e}`),n=e=>a(/^[0-9]+$/.test(e),`uint64 invalid: ${e}`);return{zero:`0`,supported:!1,parse(e){return typeof e!=`string`&&(e=e.toString()),t(e),e},uParse(e){return typeof e!=`string`&&(e=e.toString()),n(e),e},enc(e){return typeof e!=`string`&&(e=e.toString()),t(e),de(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),de(e)},dec(e,t){return fe(e,t)},uDec(e,t){return pe(e,t)}}}var m=be(),h;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`})(h||={});var xe;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(xe||={});function Se(e,t,n){if(t===n)return!0;if(e==h.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case h.UINT64:case h.FIXED64:case h.INT64:case h.SFIXED64:case h.SINT64:return t==n}return!1}function Ce(e,t){switch(e){case h.BOOL:return!1;case h.UINT64:case h.FIXED64:case h.INT64:case h.SFIXED64:case h.SINT64:return t==0?m.zero:`0`;case h.DOUBLE:case h.FLOAT:return 0;case h.BYTES:return new Uint8Array;case h.STRING:return``;default:return 0}}function we(e,t){switch(e){case h.BOOL:return t===!1;case h.STRING:return t===``;case h.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}function Te(e,t){this.v=e,this.k=t}function Ee(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function De(e){if(Array.isArray(e))return e}function g(e,t,n){return(t=Le(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Oe(e){if(typeof Symbol<`u`&&e[Symbol.iterator]!=null||e[`@@iterator`]!=null)return Array.from(e)}function ke(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Ae(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function je(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Me(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?je(Object(n),!0).forEach(function(t){g(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):je(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ne(e,t){if(e==null)return{};var n,r,i=Pe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Pe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function _(e,t){return De(e)||ke(e,t)||Re(e,t)||Ae()}function Fe(e){return De(e)||Oe(e)||Re(e)||Ae()}function Ie(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Le(e){var t=Ie(e,`string`);return typeof t==`symbol`?t:t+``}function Re(e,t){if(e){if(typeof e==`string`)return Ee(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ee(e,t):void 0}}function ze(e){return function(){return new Be(e.apply(this,arguments))}}function Be(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Te;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Be.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Be.prototype.next=function(e){return this._invoke(`next`,e)},Be.prototype.throw=function(e){return this._invoke(`throw`,e)},Be.prototype.return=function(e){return this._invoke(`return`,e)};var v;(function(e){e[e.Varint=0]=`Varint`,e[e.Bit64=1]=`Bit64`,e[e.LengthDelimited=2]=`LengthDelimited`,e[e.StartGroup=3]=`StartGroup`,e[e.EndGroup=4]=`EndGroup`,e[e.Bit32=5]=`Bit32`})(v||={});var Ve=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error(`invalid state, fork stack empty`);return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(f(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return d(e),ve(e,this.buf),this}bool(e){return this.buf.push(+!!e),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){p(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){f(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){d(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return d(e),e=(e<<1^e>>31)>>>0,ve(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=m.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=m.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=m.enc(e);return le(t.lo,t.hi,this.buf),this}sint64(e){let t=m.enc(e),n=t.hi>>31;return le(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=m.uEnc(e);return le(t.lo,t.hi,this.buf),this}},He=class{constructor(e,t){this.varint64=ce,this.uint32=ye,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error(`illegal tag: field no `+t+` wire type `+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case v.Varint:for(;this.buf[this.pos++]&128;);break;case v.Bit64:this.pos+=4;case v.Bit32:this.pos+=4;break;case v.LengthDelimited:let n=this.uint32();this.pos+=n;break;case v.StartGroup:for(;;){let e=_(this.tag(),2),n=e[0],r=e[1];if(r===v.EndGroup){if(t!==void 0&&n!==t)throw Error(`invalid end group tag`);break}this.skip(r,n)}break;default:throw Error(`cant skip wire type `+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError(`premature EOF`)}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return m.dec(...this.varint64())}uint64(){return m.uDec(...this.varint64())}sint64(){let e=_(this.varint64(),2),t=e[0],n=e[1],r=-(t&1);return t=(t>>>1|(n&1)<<31)^r,n=n>>>1^r,m.dec(t,n)}bool(){let e=_(this.varint64(),2),t=e[0],n=e[1];return t!==0||n!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return m.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return m.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function Ue(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){let n=typeof r==`function`?r():r;n.name=t.split(`.`).pop(),n.jsonName=`[${t}]`,i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}function We(e){let t=e.field.localName,n=Object.create(null);return n[t]=Ge(e),[n,()=>n[t]]}function Ge(e){let t=e.field;if(t.repeated)return[];if(t.default!==void 0)return t.default;switch(t.kind){case`enum`:return t.T.values[0].no;case`scalar`:return Ce(t.T,t.L);case`message`:let e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case`map`:throw`map fields are not allowed to be extensions`}}function Ke(e,t){if(!t.repeated&&(t.kind==`enum`||t.kind==`scalar`)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter(e=>e.no===t.no)}var qe=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),Je=[];for(let e=0;e<qe.length;e++)Je[qe[e].charCodeAt(0)]=e;Je[45]=qe.indexOf(`+`),Je[95]=qe.indexOf(`/`);var Ye={dec(e){let t=e.length*3/4;e[e.length-2]==`=`?t-=2:e[e.length-1]==`=`&&--t;let n=new Uint8Array(t),r=0,i=0,a,o=0;for(let t=0;t<e.length;t++){if(a=Je[e.charCodeAt(t)],a===void 0)switch(e[t]){case`=`:i=0;case`
|
|
3
|
+
`:case`\r`:case` `:case` `:continue;default:throw Error(`invalid base64 string.`)}switch(i){case 0:o=a,i=1;break;case 1:n[r++]=o<<2|(a&48)>>4,o=a,i=2;break;case 2:n[r++]=(o&15)<<4|(a&60)>>2,o=a,i=3;break;case 3:n[r++]=(o&3)<<6|a,i=0}}if(i==1)throw Error(`invalid base64 string.`);return n.subarray(0,r)},enc(e){let t=``,n=0,r,i=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=qe[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=qe[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=qe[i|r>>6],t+=qe[r&63],n=0}return n&&(t+=qe[i],t+=`=`,n==1&&(t+=`=`)),t}};function Xe(e,t,n){$e(t,e);let r=t.runtime.bin.makeReadOptions(n),i=Ke(e.getType().runtime.bin.listUnknownFields(e),t.field),a=_(We(t),2),o=a[0],s=a[1];for(let e of i)t.runtime.bin.readField(o,r.readerFactory(e.data),t.field,e.wireType,r);return s()}function Ze(e,t,n,r){$e(t,e);let i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(Qe(e,t)){let n=e.getType().runtime.bin.listUnknownFields(e).filter(e=>e.no!=t.field.no);e.getType().runtime.bin.discardUnknownFields(e);for(let t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}let o=a.writerFactory(),s=t.field;s.opt||s.repeated||s.kind!=`enum`&&s.kind!=`scalar`||(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);let c=i.readerFactory(o.finish());for(;c.pos<c.len;){let t=_(c.tag(),2),n=t[0],r=t[1],i=c.skip(r,n);e.getType().runtime.bin.onUnknownField(e,n,r,i)}}function Qe(e,t){let n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find(e=>e.no==t.field.no)}function $e(e,t){a(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function et(e,t){let n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case`enum`:case`scalar`:return e.opt||e.req?t[n]!==void 0:e.kind==`enum`?t[n]!==e.T.values[0].no:!we(e.T,t[n]);case`message`:return t[n]!==void 0;case`map`:return Object.keys(t[n]).length>0}}function tt(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case`map`:t[n]={};break;case`enum`:t[n]=r?e.T.values[0].no:void 0;break;case`scalar`:t[n]=r?Ce(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function nt(e,t){if(typeof e!=`object`||!e||!Object.getOwnPropertyNames(oe.prototype).every(t=>t in e&&typeof e[t]==`function`))return!1;let n=e.getType();return n===null||typeof n!=`function`||!(`typeName`in n)||typeof n.typeName!=`string`?!1:t===void 0||n.typeName==t.typeName}function rt(e,t){return nt(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}h.DOUBLE,h.FLOAT,h.INT64,h.UINT64,h.INT32,h.UINT32,h.BOOL,h.STRING,h.BYTES;var it={ignoreUnknownFields:!1},at={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function ot(e){return e?Object.assign(Object.assign({},it),e):it}function st(e){return e?Object.assign(Object.assign({},at),e):at}var ct=Symbol(),lt=Symbol();function ut(){return{makeReadOptions:ot,makeWriteOptions:st,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.typeName} from JSON: ${dt(t)}`);r??=new e;let i=new Map,a=n.typeRegistry;for(let s of Object.entries(t)){var o=_(s,2);let t=o[0],c=o[1],l=e.fields.findJsonName(t);if(l){if(l.oneof){if(c===null&&l.kind==`scalar`)continue;let n=i.get(l.oneof);if(n!==void 0)throw Error(`cannot decode message ${e.typeName} from JSON: multiple keys for oneof "${l.oneof.name}" present: "${n}", "${t}"`);i.set(l.oneof,t)}ft(r,c,l,n,e)}else{let i=!1;if(a?.findExtension&&t.startsWith(`[`)&&t.endsWith(`]`)){let o=a.findExtension(t.substring(1,t.length-1));if(o&&o.extendee.typeName==e.typeName){i=!0;let e=_(We(o),2),t=e[0],a=e[1];ft(t,c,o.field,n,o),Ze(r,o,a(),n)}}if(!i&&!n.ignoreUnknownFields)throw Error(`cannot decode message ${e.typeName} from JSON: key "${t}" is unknown`)}}return r},writeMessage(e,t){let n=e.getType(),r={},i;try{for(i of n.fields.byNumber()){if(!et(i,e)){if(i.req)throw`required field not set`;if(!t.emitDefaultValues||!gt(i))continue}let n=i.oneof?e[i.oneof.localName].value:e[i.localName],a=_t(i,n,t);a!==void 0&&(r[t.useProtoFieldName?i.name:i.jsonName]=a)}let a=t.typeRegistry;if(a?.findExtensionFor)for(let i of n.runtime.bin.listUnknownFields(e)){let o=a.findExtensionFor(n.typeName,i.no);if(o&&Qe(e,o)){let n=Xe(e,o,t),i=_t(o.field,n,t);i!==void 0&&(r[o.field.jsonName]=i)}}}catch(e){let t=i?`cannot encode field ${n.typeName}.${i.name} to JSON`:`cannot encode message ${n.typeName} to JSON`,r=e instanceof Error?e.message:String(e);throw Error(t+(r.length>0?`: ${r}`:``))}return r},readScalar(e,t,n){return mt(e,t,n??xe.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||we(e,t)))return yt(e,t)},debug:dt}}function dt(e){if(e===null)return`null`;switch(typeof e){case`object`:return Array.isArray(e)?`array`:`object`;case`string`:return e.length>100?`string`:`"${e.split(`"`).join(`\\"`)}"`;default:return String(e)}}function ft(e,t,n,r,i){let o=n.localName;if(n.repeated){if(a(n.kind!=`map`),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${dt(t)}`);let s=e[o];for(let e of t){if(e===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${dt(e)}`);switch(n.kind){case`message`:s.push(n.T.fromJson(e,r));break;case`enum`:let t=ht(n.T,e,r.ignoreUnknownFields,!0);t!==lt&&s.push(t);break;case`scalar`:try{s.push(mt(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${dt(e)}`;throw t instanceof Error&&t.message.length>0&&(r+=`: ${t.message}`),Error(r)}}}}else if(n.kind==`map`){if(t===null)return;if(typeof t!=`object`||Array.isArray(t))throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: ${dt(t)}`);let a=e[o];for(let e of Object.entries(t)){var s=_(e,2);let o=s[0],c=s[1];if(c===null)throw Error(`cannot decode field ${i.typeName}.${n.name} from JSON: map value null`);let l;try{l=pt(n.K,o)}catch(e){let r=`cannot decode map key for field ${i.typeName}.${n.name} from JSON: ${dt(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}switch(n.V.kind){case`message`:a[l]=n.V.T.fromJson(c,r);break;case`enum`:let e=ht(n.V.T,c,r.ignoreUnknownFields,!0);e!==lt&&(a[l]=e);break;case`scalar`:try{a[l]=mt(n.V.T,c,xe.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${i.typeName}.${n.name} from JSON: ${dt(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:o},o=`value`),n.kind){case`message`:let a=n.T;if(t===null&&a.typeName!=`google.protobuf.Value`)return;let s=e[o];nt(s)?s.fromJson(t,r):(e[o]=s=a.fromJson(t,r),a.fieldWrapper&&!n.oneof&&(e[o]=a.fieldWrapper.unwrapField(s)));break;case`enum`:let c=ht(n.T,t,r.ignoreUnknownFields,!1);switch(c){case ct:tt(n,e);break;case lt:break;default:e[o]=c}break;case`scalar`:try{let r=mt(n.T,t,n.L,!1);switch(r){case ct:tt(n,e);break;default:e[o]=r}}catch(e){let r=`cannot decode field ${i.typeName}.${n.name} from JSON: ${dt(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r)}}}function pt(e,t){if(e===h.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return mt(e,t,xe.BIGINT,!0).toString()}function mt(e,t,n,r){if(t===null)return r?Ce(e,n):ct;switch(e){case h.DOUBLE:case h.FLOAT:if(t===`NaN`)return NaN;if(t===`Infinity`)return 1/0;if(t===`-Infinity`)return-1/0;if(t===``||typeof t==`string`&&t.trim().length!==t.length||typeof t!=`string`&&typeof t!=`number`)break;let r=Number(t);if(Number.isNaN(r)||!Number.isFinite(r))break;return e==h.FLOAT&&p(r),r;case h.INT32:case h.FIXED32:case h.SFIXED32:case h.SINT32:case h.UINT32:let i;if(typeof t==`number`?i=t:typeof t==`string`&&t.length>0&&t.trim().length===t.length&&(i=Number(t)),i===void 0)break;return e==h.UINT32||e==h.FIXED32?f(i):d(i),i;case h.INT64:case h.SFIXED64:case h.SINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let a=m.parse(t);return n?a.toString():a;case h.FIXED64:case h.UINT64:if(typeof t!=`number`&&typeof t!=`string`)break;let o=m.uParse(t);return n?o.toString():o;case h.BOOL:if(typeof t!=`boolean`)break;return t;case h.STRING:if(typeof t!=`string`)break;return t;case h.BYTES:if(t===``)return new Uint8Array;if(typeof t!=`string`)break;return Ye.dec(t)}throw Error()}function ht(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:ct;switch(typeof t){case`number`:if(Number.isInteger(t))return t;break;case`string`:let r=e.findName(t);if(r!==void 0)return r.no;if(n)return lt}throw Error(`cannot decode enum ${e.typeName} from JSON: ${dt(t)}`)}function gt(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function _t(e,t,n){if(e.kind==`map`){a(typeof t==`object`&&!!t);let s={},c=Object.entries(t);switch(e.V.kind){case`scalar`:for(let t of c){var r=_(t,2);let n=r[0],i=r[1];s[n.toString()]=yt(e.V.T,i)}break;case`message`:for(let e of c){var i=_(e,2);let t=i[0],r=i[1];s[t.toString()]=r.toJson(n)}break;case`enum`:let t=e.V.T;for(let e of c){var o=_(e,2);let r=o[0],i=o[1];s[r.toString()]=vt(t,i,n.enumAsInteger)}}return n.emitDefaultValues||c.length>0?s:void 0}if(e.repeated){a(Array.isArray(t));let r=[];switch(e.kind){case`scalar`:for(let n=0;n<t.length;n++)r.push(yt(e.T,t[n]));break;case`enum`:for(let i=0;i<t.length;i++)r.push(vt(e.T,t[i],n.enumAsInteger));break;case`message`:for(let e=0;e<t.length;e++)r.push(t[e].toJson(n))}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case`scalar`:return yt(e.T,t);case`enum`:return vt(e.T,t,n.enumAsInteger);case`message`:return rt(e.T,t).toJson(n)}}function vt(e,t,n){return a(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}function yt(e,t){switch(e){case h.INT32:case h.SFIXED32:case h.SINT32:case h.FIXED32:case h.UINT32:return a(typeof t==`number`),t;case h.FLOAT:case h.DOUBLE:return a(typeof t==`number`),Number.isNaN(t)?`NaN`:t===1/0?`Infinity`:t===-1/0?`-Infinity`:t;case h.STRING:return a(typeof t==`string`),t;case h.BOOL:return a(typeof t==`boolean`),t;case h.UINT64:case h.FIXED64:case h.INT64:case h.SFIXED64:case h.SINT64:return a(typeof t==`bigint`||typeof t==`string`||typeof t==`number`),t.toString();case h.BYTES:return a(t instanceof Uint8Array),Ye.enc(t)}}var bt=Symbol(`@bufbuild/protobuf/unknown-fields`),xt={readUnknownFields:!0,readerFactory:e=>new He(e)},St={writeUnknownFields:!0,writerFactory:()=>new Ve};function Ct(e){return e?Object.assign(Object.assign({},xt),e):xt}function wt(e){return e?Object.assign(Object.assign({},St),e):St}function Tt(){return{makeReadOptions:Ct,makeWriteOptions:wt,listUnknownFields(e){return e[bt]??[]},discardUnknownFields(e){delete e[bt]},writeUnknownFields(e,t){let n=e[bt];if(n)for(let e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){let i=e;Array.isArray(i[bt])||(i[bt]=[]),i[bt].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){let a=e.getType(),o=i?t.len:t.pos+n,s,c;for(;t.pos<o;){var l=_(t.tag(),2);if(s=l[0],c=l[1],i===!0&&c==v.EndGroup)break;let n=a.fields.find(s);if(n)Et(e,t,n,c,r);else{let n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n)}}if(i&&(c!=v.EndGroup||s!==n))throw Error(`invalid end group tag`)},readField:Et,writeMessage(e,t,n){let r=e.getType();for(let i of r.fields.byNumber())if(et(i,e))jt(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n);else if(i.req)throw Error(`cannot encode field ${r.typeName}.${i.name} to binary: required field not set`);return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){t!==void 0&&jt(e,t,n,r)}}}function Et(e,t,n,r,i){let a=n.repeated,o=n.localName;switch(n.oneof&&(e=e[n.oneof.localName],e.case!=o&&delete e.value,e.case=o,o=`value`),n.kind){case`scalar`:case`enum`:let s=n.kind==`enum`?h.INT32:n.T,c=At;if(n.kind==`scalar`&&n.L>0&&(c=kt),a){let n=e[o];if(r==v.LengthDelimited&&s!=h.STRING&&s!=h.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case`message`:let l=n.T;a?e[o].push(Dt(t,new l,i,n)):nt(e[o])?Dt(t,e[o],i,n):(e[o]=Dt(t,new l,i,n),l.fieldWrapper&&!n.oneof&&!n.repeated&&(e[o]=l.fieldWrapper.unwrapField(e[o])));break;case`map`:let u=_(Ot(n,t,i),2),d=u[0],f=u[1];e[o][d]=f}}function Dt(e,t,n,r){let i=t.getType().runtime.bin,a=r?.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function Ot(e,t,n){let r=t.uint32(),i=t.pos+r,a,o;for(;t.pos<i;)switch(_(t.tag(),1)[0]){case 1:a=At(t,e.K);break;case 2:switch(e.V.kind){case`scalar`:o=At(t,e.V.T);break;case`enum`:o=t.int32();break;case`message`:o=Dt(t,new e.V.T,n,void 0)}}if(a===void 0&&(a=Ce(e.K,xe.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a.toString()),o===void 0)switch(e.V.kind){case`scalar`:o=Ce(e.V.T,xe.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=new e.V.T}return[a,o]}function kt(e,t){let n=At(e,t);return typeof n==`bigint`?n.toString():n}function At(e,t){switch(t){case h.STRING:return e.string();case h.BOOL:return e.bool();case h.DOUBLE:return e.double();case h.FLOAT:return e.float();case h.INT32:return e.int32();case h.INT64:return e.int64();case h.UINT64:return e.uint64();case h.FIXED64:return e.fixed64();case h.BYTES:return e.bytes();case h.FIXED32:return e.fixed32();case h.SFIXED32:return e.sfixed32();case h.SFIXED64:return e.sfixed64();case h.SINT64:return e.sint64();case h.UINT32:return e.uint32();case h.SINT32:return e.sint32()}}function jt(e,t,n,r){a(t!==void 0);let i=e.repeated;switch(e.kind){case`scalar`:case`enum`:let s=e.kind==`enum`?h.INT32:e.T;if(i){if(a(Array.isArray(t)),e.packed)Ft(n,s,e.no,t);else for(let r of t)Pt(n,s,e.no,r)}else Pt(n,s,e.no,t);break;case`message`:if(i){a(Array.isArray(t));for(let i of t)Nt(n,r,e,i)}else Nt(n,r,e,t);break;case`map`:a(typeof t==`object`&&!!t);for(let i of Object.entries(t)){var o=_(i,2);let t=o[0],a=o[1];Mt(n,r,e,t,a)}}}function Mt(e,t,n,r,i){e.tag(n.no,v.LengthDelimited),e.fork();let o=r;switch(n.K){case h.INT32:case h.FIXED32:case h.UINT32:case h.SFIXED32:case h.SINT32:o=Number.parseInt(r);break;case h.BOOL:a(r==`true`||r==`false`),o=r==`true`}switch(Pt(e,n.K,1,o),n.V.kind){case`scalar`:Pt(e,n.V.T,2,i);break;case`enum`:Pt(e,h.INT32,2,i);break;case`message`:a(i!==void 0),e.tag(2,v.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Nt(e,t,n,r){let i=rt(n.T,r);n.delimited?e.tag(n.no,v.StartGroup).raw(i.toBinary(t)).tag(n.no,v.EndGroup):e.tag(n.no,v.LengthDelimited).bytes(i.toBinary(t))}function Pt(e,t,n,r){a(r!==void 0);let i=_(It(t),2),o=i[0],s=i[1];e.tag(n,o)[s](r)}function Ft(e,t,n,r){if(!r.length)return;e.tag(n,v.LengthDelimited).fork();let i=_(It(t),2)[1];for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function It(e){let t=v.Varint;switch(e){case h.BYTES:case h.STRING:t=v.LengthDelimited;break;case h.DOUBLE:case h.FIXED64:case h.SFIXED64:t=v.Bit64;break;case h.FIXED32:case h.SFIXED32:case h.FLOAT:t=v.Bit32}let n=h[e].toLowerCase();return[t,n]}function Lt(){return{setEnumType:ne,initPartial(e,t){if(e===void 0)return;let n=t.getType();for(let i of n.fields.byMember()){let n=i.localName,a=t,o=e;if(o[n]!=null)switch(i.kind){case`oneof`:let e=o[n].case;if(e===void 0)continue;let t=i.findField(e),s=o[n].value;t&&t.kind==`message`&&!nt(s,t.T)?s=new t.T(s):t&&t.kind===`scalar`&&t.T===h.BYTES&&(s=zt(s)),a[n]={case:e,value:s};break;case`scalar`:case`enum`:let c=o[n];i.T===h.BYTES&&(c=i.repeated?c.map(zt):zt(c)),a[n]=c;break;case`map`:switch(i.V.kind){case`scalar`:case`enum`:if(i.V.T===h.BYTES)for(let e of Object.entries(o[n])){var r=_(e,2);let t=r[0],i=r[1];a[n][t]=zt(i)}else Object.assign(a[n],o[n]);break;case`message`:let e=i.V.T;for(let t of Object.keys(o[n])){let r=o[n][t];e.fieldWrapper||(r=new e(r)),a[n][t]=r}}break;case`message`:let l=i.T;if(i.repeated)a[n]=o[n].map(e=>nt(e,l)?e:new l(e));else{let e=o[n];a[n]=l.fieldWrapper?l.typeName===`google.protobuf.BytesValue`?zt(e):e:nt(e,l)?e:new l(e)}}}},equals(e,t,n){return t===n?!0:!t||!n?!1:e.fields.byMember().every(e=>{let r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case`message`:return r.every((t,n)=>e.T.equals(t,i[n]));case`scalar`:return r.every((t,n)=>Se(e.T,t,i[n]));case`enum`:return r.every((e,t)=>Se(h.INT32,e,i[t]))}throw Error(`repeated cannot contain ${e.kind}`)}switch(e.kind){case`message`:let t=r,n=i;return e.T.fieldWrapper&&(t!==void 0&&!nt(t)&&(t=e.T.fieldWrapper.wrapField(t)),n!==void 0&&!nt(n)&&(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case`enum`:return Se(h.INT32,r,i);case`scalar`:return Se(e.T,r,i);case`oneof`:if(r.case!==i.case)return!1;let a=e.findField(r.case);if(a===void 0)return!0;switch(a.kind){case`message`:return a.T.equals(r.value,i.value);case`enum`:return Se(h.INT32,r.value,i.value);case`scalar`:return Se(a.T,r.value,i.value)}throw Error(`oneof cannot contain ${a.kind}`);case`map`:let o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case`message`:let t=e.V.T;return o.every(e=>t.equals(r[e],i[e]));case`enum`:return o.every(e=>Se(h.INT32,r[e],i[e]));case`scalar`:let n=e.V.T;return o.every(e=>Se(n,r[e],i[e]))}}})},clone(e){let t=e.getType(),n=new t,r=n;for(let n of t.fields.byMember()){let t=e[n.localName],a;if(n.repeated)a=t.map(Rt);else if(n.kind==`map`){a=r[n.localName];for(let e of Object.entries(t)){var i=_(e,2);let t=i[0],n=i[1];a[t]=Rt(n)}}else a=n.kind==`oneof`?n.findField(t.case)?{case:t.case,value:Rt(t.value)}:{case:void 0}:Rt(t);r[n.localName]=a}for(let n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}}function Rt(e){if(e===void 0)return e;if(nt(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function zt(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Bt(e,t,n){return{syntax:e,json:ut(),bin:Tt(),util:Object.assign(Object.assign({},Lt()),{newFieldList:t,initFields:n}),makeMessageType(e,t,n){return se(this,e,t,n)},makeEnum:ie,makeEnumType:re,getEnumType:te,makeExtension(e,t,n){return Ue(this,e,t,n)}}}var Vt=class{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let e={};for(let t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){let e={};for(let t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||=this._normalizer(this._fields),this.all}byNumber(){return this.numbersAsc||=this.list().concat().sort((e,t)=>e.no-t.no),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function Ht(e,t){let n=Gt(e);return t?n:Xt(Yt(n))}function Ut(e){return Ht(e,!1)}var Wt=Gt;function Gt(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case`_`:t=!0;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join(``)}var Kt=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]),qt=new Set([`getType`,`clone`,`equals`,`fromBinary`,`fromJson`,`fromJsonString`,`toBinary`,`toJson`,`toJsonString`,`toObject`]),Jt=e=>`${e}$`,Yt=e=>qt.has(e)?Jt(e):e,Xt=e=>Kt.has(e)?Jt(e):e,Zt=class{constructor(e){this.kind=`oneof`,this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Ut(e)}addField(e){a(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}};function Qt(e,t){let n=[],r;for(let t of typeof e==`function`?e():e){let e=t;if(e.localName=Ht(t.name,t.oneof!==void 0),e.jsonName=t.jsonName??Wt(t.name),e.repeated=t.repeated??!1,t.kind==`scalar`&&(e.L=t.L??xe.BIGINT),e.delimited=t.delimited??!1,e.req=t.req??!1,e.opt=t.opt??!1,t.packed===void 0&&(e.packed=t.kind==`enum`||t.kind==`scalar`&&t.T!=h.BYTES&&t.T!=h.STRING),t.oneof!==void 0){let n=typeof t.oneof==`string`?t.oneof:t.oneof.name;r&&r.name==n||(r=new Zt(n)),e.oneof=r,r.addField(e)}n.push(e)}return n}var y=Bt(`proto3`,e=>new Vt(e,e=>Qt(e)),e=>{for(let t of e.getType().fields.byMember()){if(t.opt)continue;let n=t.localName,r=e;if(t.repeated)r[n]=[];else switch(t.kind){case`oneof`:r[n]={case:void 0};break;case`enum`:r[n]=0;break;case`map`:r[n]={};break;case`scalar`:r[n]=Ce(t.T,t.L)}}}),$t=class e extends oe{constructor(e){super(),this.seconds=m.zero,this.nanos=0,y.util.initPartial(e,this)}fromJson(e,t){if(typeof e!=`string`)throw Error(`cannot decode google.protobuf.Timestamp from JSON: ${y.json.debug(e)}`);let n=e.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/);if(!n)throw Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);let r=Date.parse(n[1]+`-`+n[2]+`-`+n[3]+`T`+n[4]+`:`+n[5]+`:`+n[6]+(n[8]?n[8]:`Z`));if(Number.isNaN(r))throw Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);if(r<Date.parse(`0001-01-01T00:00:00Z`)||r>Date.parse(`9999-12-31T23:59:59Z`))throw Error(`cannot decode message google.protobuf.Timestamp from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);return this.seconds=m.parse(r/1e3),this.nanos=0,n[7]&&(this.nanos=parseInt(`1`+n[7]+`0`.repeat(9-n[7].length))-1e9),this}toJson(e){let t=Number(this.seconds)*1e3;if(t<Date.parse(`0001-01-01T00:00:00Z`)||t>Date.parse(`9999-12-31T23:59:59Z`))throw Error(`cannot encode google.protobuf.Timestamp to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);if(this.nanos<0)throw Error(`cannot encode google.protobuf.Timestamp to JSON: nanos must not be negative`);let n=`Z`;if(this.nanos>0){let e=(this.nanos+1e9).toString().substring(1);n=e.substring(3)===`000000`?`.`+e.substring(0,3)+`Z`:e.substring(6)===`000`?`.`+e.substring(0,6)+`Z`:`.`+e+`Z`}return new Date(t).toISOString().replace(`.000Z`,n)}toDate(){return new Date(Number(this.seconds)*1e3+Math.ceil(this.nanos/1e6))}static now(){return e.fromDate(new Date)}static fromDate(t){let n=t.getTime();return new e({seconds:m.parse(Math.floor(n/1e3)),nanos:n%1e3*1e6})}static fromBinary(t,n){return new e().fromBinary(t,n)}static fromJson(t,n){return new e().fromJson(t,n)}static fromJsonString(t,n){return new e().fromJsonString(t,n)}static equals(t,n){return y.util.equals(e,t,n)}};$t.runtime=y,$t.typeName=`google.protobuf.Timestamp`,$t.fields=y.util.newFieldList(()=>[{no:1,name:`seconds`,kind:`scalar`,T:3},{no:2,name:`nanos`,kind:`scalar`,T:5}]);var en=y.makeMessageType(`livekit.MetricsBatch`,()=>[{no:1,name:`timestamp_ms`,kind:`scalar`,T:3},{no:2,name:`normalized_timestamp`,kind:`message`,T:$t},{no:3,name:`str_data`,kind:`scalar`,T:9,repeated:!0},{no:4,name:`time_series`,kind:`message`,T:tn,repeated:!0},{no:5,name:`events`,kind:`message`,T:rn,repeated:!0}]),tn=y.makeMessageType(`livekit.TimeSeriesMetric`,()=>[{no:1,name:`label`,kind:`scalar`,T:13},{no:2,name:`participant_identity`,kind:`scalar`,T:13},{no:3,name:`track_sid`,kind:`scalar`,T:13},{no:4,name:`samples`,kind:`message`,T:nn,repeated:!0},{no:5,name:`rid`,kind:`scalar`,T:13}]),nn=y.makeMessageType(`livekit.MetricSample`,()=>[{no:1,name:`timestamp_ms`,kind:`scalar`,T:3},{no:2,name:`normalized_timestamp`,kind:`message`,T:$t},{no:3,name:`value`,kind:`scalar`,T:2}]),rn=y.makeMessageType(`livekit.EventMetric`,()=>[{no:1,name:`label`,kind:`scalar`,T:13},{no:2,name:`participant_identity`,kind:`scalar`,T:13},{no:3,name:`track_sid`,kind:`scalar`,T:13},{no:4,name:`start_timestamp_ms`,kind:`scalar`,T:3},{no:5,name:`end_timestamp_ms`,kind:`scalar`,T:3,opt:!0},{no:6,name:`normalized_start_timestamp`,kind:`message`,T:$t},{no:7,name:`normalized_end_timestamp`,kind:`message`,T:$t,opt:!0},{no:8,name:`metadata`,kind:`scalar`,T:9},{no:9,name:`rid`,kind:`scalar`,T:13}]),an=y.makeEnum(`livekit.BackupCodecPolicy`,[{no:0,name:`PREFER_REGRESSION`},{no:1,name:`SIMULCAST`},{no:2,name:`REGRESSION`}]),on=y.makeEnum(`livekit.TrackType`,[{no:0,name:`AUDIO`},{no:1,name:`VIDEO`},{no:2,name:`DATA`}]),b=y.makeEnum(`livekit.TrackSource`,[{no:0,name:`UNKNOWN`},{no:1,name:`CAMERA`},{no:2,name:`MICROPHONE`},{no:3,name:`SCREEN_SHARE`},{no:4,name:`SCREEN_SHARE_AUDIO`}]),sn=y.makeEnum(`livekit.VideoQuality`,[{no:0,name:`LOW`},{no:1,name:`MEDIUM`},{no:2,name:`HIGH`},{no:3,name:`OFF`}]),cn=y.makeEnum(`livekit.ConnectionQuality`,[{no:0,name:`POOR`},{no:1,name:`GOOD`},{no:2,name:`EXCELLENT`},{no:3,name:`LOST`}]),ln=y.makeEnum(`livekit.ClientConfigSetting`,[{no:0,name:`UNSET`},{no:1,name:`DISABLED`},{no:2,name:`ENABLED`}]),un=y.makeEnum(`livekit.DisconnectReason`,[{no:0,name:`UNKNOWN_REASON`},{no:1,name:`CLIENT_INITIATED`},{no:2,name:`DUPLICATE_IDENTITY`},{no:3,name:`SERVER_SHUTDOWN`},{no:4,name:`PARTICIPANT_REMOVED`},{no:5,name:`ROOM_DELETED`},{no:6,name:`STATE_MISMATCH`},{no:7,name:`JOIN_FAILURE`},{no:8,name:`MIGRATION`},{no:9,name:`SIGNAL_CLOSE`},{no:10,name:`ROOM_CLOSED`},{no:11,name:`USER_UNAVAILABLE`},{no:12,name:`USER_REJECTED`},{no:13,name:`SIP_TRUNK_FAILURE`},{no:14,name:`CONNECTION_TIMEOUT`},{no:15,name:`MEDIA_FAILURE`},{no:16,name:`AGENT_ERROR`}]),dn=y.makeEnum(`livekit.ReconnectReason`,[{no:0,name:`RR_UNKNOWN`},{no:1,name:`RR_SIGNAL_DISCONNECTED`},{no:2,name:`RR_PUBLISHER_FAILED`},{no:3,name:`RR_SUBSCRIBER_FAILED`},{no:4,name:`RR_SWITCH_CANDIDATE`}]),fn=y.makeEnum(`livekit.SubscriptionError`,[{no:0,name:`SE_UNKNOWN`},{no:1,name:`SE_CODEC_UNSUPPORTED`},{no:2,name:`SE_TRACK_NOTFOUND`}]),x=y.makeEnum(`livekit.AudioTrackFeature`,[{no:0,name:`TF_STEREO`},{no:1,name:`TF_NO_DTX`},{no:2,name:`TF_AUTO_GAIN_CONTROL`},{no:3,name:`TF_ECHO_CANCELLATION`},{no:4,name:`TF_NOISE_SUPPRESSION`},{no:5,name:`TF_ENHANCED_NOISE_CANCELLATION`},{no:6,name:`TF_PRECONNECT_BUFFER`}]),pn=y.makeEnum(`livekit.PacketTrailerFeature`,[{no:0,name:`PTF_USER_TIMESTAMP`},{no:1,name:`PTF_FRAME_ID`},{no:2,name:`PTF_USER_DATA`}]),mn=y.makeMessageType(`livekit.Room`,()=>[{no:1,name:`sid`,kind:`scalar`,T:9},{no:2,name:`name`,kind:`scalar`,T:9},{no:3,name:`empty_timeout`,kind:`scalar`,T:13},{no:14,name:`departure_timeout`,kind:`scalar`,T:13},{no:4,name:`max_participants`,kind:`scalar`,T:13},{no:5,name:`creation_time`,kind:`scalar`,T:3},{no:15,name:`creation_time_ms`,kind:`scalar`,T:3},{no:6,name:`turn_password`,kind:`scalar`,T:9},{no:7,name:`enabled_codecs`,kind:`message`,T:hn,repeated:!0},{no:8,name:`metadata`,kind:`scalar`,T:9},{no:9,name:`num_participants`,kind:`scalar`,T:13},{no:11,name:`num_publishers`,kind:`scalar`,T:13},{no:10,name:`active_recording`,kind:`scalar`,T:8},{no:13,name:`version`,kind:`message`,T:rr}]),hn=y.makeMessageType(`livekit.Codec`,()=>[{no:1,name:`mime`,kind:`scalar`,T:9},{no:2,name:`fmtp_line`,kind:`scalar`,T:9}]),gn=y.makeMessageType(`livekit.ParticipantPermission`,()=>[{no:1,name:`can_subscribe`,kind:`scalar`,T:8},{no:2,name:`can_publish`,kind:`scalar`,T:8},{no:3,name:`can_publish_data`,kind:`scalar`,T:8},{no:9,name:`can_publish_sources`,kind:`enum`,T:y.getEnumType(b),repeated:!0},{no:7,name:`hidden`,kind:`scalar`,T:8},{no:8,name:`recorder`,kind:`scalar`,T:8},{no:10,name:`can_update_metadata`,kind:`scalar`,T:8},{no:11,name:`agent`,kind:`scalar`,T:8},{no:12,name:`can_subscribe_metrics`,kind:`scalar`,T:8},{no:13,name:`can_manage_agent_session`,kind:`scalar`,T:8}]),_n=y.makeMessageType(`livekit.ParticipantInfo`,()=>[{no:1,name:`sid`,kind:`scalar`,T:9},{no:2,name:`identity`,kind:`scalar`,T:9},{no:3,name:`state`,kind:`enum`,T:y.getEnumType(vn)},{no:4,name:`tracks`,kind:`message`,T:Sn,repeated:!0},{no:5,name:`metadata`,kind:`scalar`,T:9},{no:6,name:`joined_at`,kind:`scalar`,T:3},{no:17,name:`joined_at_ms`,kind:`scalar`,T:3},{no:9,name:`name`,kind:`scalar`,T:9},{no:10,name:`version`,kind:`scalar`,T:13},{no:11,name:`permission`,kind:`message`,T:gn},{no:12,name:`region`,kind:`scalar`,T:9},{no:13,name:`is_publisher`,kind:`scalar`,T:8},{no:14,name:`kind`,kind:`enum`,T:y.getEnumType(yn)},{no:15,name:`attributes`,kind:`map`,K:9,V:{kind:`scalar`,T:9}},{no:16,name:`disconnect_reason`,kind:`enum`,T:y.getEnumType(un)},{no:18,name:`kind_details`,kind:`enum`,T:y.getEnumType(bn),repeated:!0},{no:19,name:`data_tracks`,kind:`message`,T:Cn,repeated:!0},{no:20,name:`client_protocol`,kind:`scalar`,T:5},{no:21,name:`capabilities`,kind:`enum`,T:y.getEnumType($n),repeated:!0}]),vn=y.makeEnum(`livekit.ParticipantInfo.State`,[{no:0,name:`JOINING`},{no:1,name:`JOINED`},{no:2,name:`ACTIVE`},{no:3,name:`DISCONNECTED`}]),yn=y.makeEnum(`livekit.ParticipantInfo.Kind`,[{no:0,name:`STANDARD`},{no:1,name:`INGRESS`},{no:2,name:`EGRESS`},{no:3,name:`SIP`},{no:4,name:`AGENT`},{no:7,name:`CONNECTOR`},{no:8,name:`BRIDGE`}]),bn=y.makeEnum(`livekit.ParticipantInfo.KindDetail`,[{no:0,name:`CLOUD_AGENT`},{no:1,name:`FORWARDED`},{no:2,name:`CONNECTOR_WHATSAPP`},{no:3,name:`CONNECTOR_TWILIO`},{no:4,name:`BRIDGE_RTSP`},{no:5,name:`SIMULATION`}]),S=y.makeEnum(`livekit.Encryption.Type`,[{no:0,name:`NONE`},{no:1,name:`GCM`},{no:2,name:`CUSTOM`}]),xn=y.makeMessageType(`livekit.SimulcastCodecInfo`,()=>[{no:1,name:`mime_type`,kind:`scalar`,T:9},{no:2,name:`mid`,kind:`scalar`,T:9},{no:3,name:`cid`,kind:`scalar`,T:9},{no:4,name:`layers`,kind:`message`,T:Mn,repeated:!0},{no:5,name:`video_layer_mode`,kind:`enum`,T:y.getEnumType(Nn)},{no:6,name:`sdp_cid`,kind:`scalar`,T:9}]),Sn=y.makeMessageType(`livekit.TrackInfo`,()=>[{no:1,name:`sid`,kind:`scalar`,T:9},{no:2,name:`type`,kind:`enum`,T:y.getEnumType(on)},{no:3,name:`name`,kind:`scalar`,T:9},{no:4,name:`muted`,kind:`scalar`,T:8},{no:5,name:`width`,kind:`scalar`,T:13},{no:6,name:`height`,kind:`scalar`,T:13},{no:7,name:`simulcast`,kind:`scalar`,T:8},{no:8,name:`disable_dtx`,kind:`scalar`,T:8},{no:9,name:`source`,kind:`enum`,T:y.getEnumType(b)},{no:10,name:`layers`,kind:`message`,T:Mn,repeated:!0},{no:11,name:`mime_type`,kind:`scalar`,T:9},{no:12,name:`mid`,kind:`scalar`,T:9},{no:13,name:`codecs`,kind:`message`,T:xn,repeated:!0},{no:14,name:`stereo`,kind:`scalar`,T:8},{no:15,name:`disable_red`,kind:`scalar`,T:8},{no:16,name:`encryption`,kind:`enum`,T:y.getEnumType(S)},{no:17,name:`stream`,kind:`scalar`,T:9},{no:18,name:`version`,kind:`message`,T:rr},{no:19,name:`audio_features`,kind:`enum`,T:y.getEnumType(x),repeated:!0},{no:20,name:`backup_codec_policy`,kind:`enum`,T:y.getEnumType(an)},{no:21,name:`packet_trailer_features`,kind:`enum`,T:y.getEnumType(pn),repeated:!0}]),Cn=y.makeMessageType(`livekit.DataTrackInfo`,()=>[{no:1,name:`pub_handle`,kind:`scalar`,T:13},{no:2,name:`sid`,kind:`scalar`,T:9},{no:3,name:`name`,kind:`scalar`,T:9},{no:4,name:`encryption`,kind:`enum`,T:y.getEnumType(S)},{no:5,name:`frame_encoding`,kind:`message`,T:wn,opt:!0},{no:6,name:`schema`,kind:`message`,T:On,opt:!0}]),wn=y.makeMessageType(`livekit.DataTrackFrameEncoding`,()=>[{no:1,name:`well_known`,kind:`enum`,T:y.getEnumType(Tn),oneof:`value`},{no:2,name:`custom`,kind:`scalar`,T:9,oneof:`value`}]),Tn=y.makeEnum(`livekit.DataTrackFrameEncoding.WellKnownFrameEncoding`,[{no:0,name:`WELL_KNOWN_FRAME_ENCODING_UNSPECIFIED`,localName:`UNSPECIFIED`},{no:1,name:`WELL_KNOWN_FRAME_ENCODING_ROS1`,localName:`ROS1`},{no:2,name:`WELL_KNOWN_FRAME_ENCODING_CDR`,localName:`CDR`},{no:3,name:`WELL_KNOWN_FRAME_ENCODING_PROTOBUF`,localName:`PROTOBUF`},{no:4,name:`WELL_KNOWN_FRAME_ENCODING_FLATBUFFER`,localName:`FLATBUFFER`},{no:5,name:`WELL_KNOWN_FRAME_ENCODING_CBOR`,localName:`CBOR`},{no:6,name:`WELL_KNOWN_FRAME_ENCODING_MSGPACK`,localName:`MSGPACK`},{no:7,name:`WELL_KNOWN_FRAME_ENCODING_JSON`,localName:`JSON`}]),En=y.makeMessageType(`livekit.DataTrackSchemaEncoding`,()=>[{no:1,name:`well_known`,kind:`enum`,T:y.getEnumType(Dn),oneof:`value`},{no:2,name:`custom`,kind:`scalar`,T:9,oneof:`value`}]),Dn=y.makeEnum(`livekit.DataTrackSchemaEncoding.WellKnownSchemaEncoding`,[{no:0,name:`WELL_KNOWN_SCHEMA_ENCODING_UNSPECIFIED`,localName:`UNSPECIFIED`},{no:1,name:`WELL_KNOWN_SCHEMA_ENCODING_PROTOBUF`,localName:`PROTOBUF`},{no:2,name:`WELL_KNOWN_SCHEMA_ENCODING_FLATBUFFER`,localName:`FLATBUFFER`},{no:3,name:`WELL_KNOWN_SCHEMA_ENCODING_ROS1_MSG`,localName:`ROS1_MSG`},{no:4,name:`WELL_KNOWN_SCHEMA_ENCODING_ROS2_MSG`,localName:`ROS2_MSG`},{no:5,name:`WELL_KNOWN_SCHEMA_ENCODING_ROS2_IDL`,localName:`ROS2_IDL`},{no:6,name:`WELL_KNOWN_SCHEMA_ENCODING_OMG_IDL`,localName:`OMG_IDL`},{no:7,name:`WELL_KNOWN_SCHEMA_ENCODING_JSON_SCHEMA`,localName:`JSON_SCHEMA`}]),On=y.makeMessageType(`livekit.DataTrackSchemaId`,()=>[{no:1,name:`name`,kind:`scalar`,T:9},{no:2,name:`encoding`,kind:`message`,T:En}]),kn=y.makeMessageType(`livekit.DataTrackSubscriptionOptions`,()=>[{no:1,name:`target_fps`,kind:`scalar`,T:13,opt:!0}]),An=y.makeMessageType(`livekit.DataBlobKey`,()=>[{no:1,name:`generic`,kind:`scalar`,T:9,oneof:`key`},{no:2,name:`schema_id`,kind:`message`,T:On,oneof:`key`}]),jn=y.makeMessageType(`livekit.DataBlob`,()=>[{no:1,name:`key`,kind:`message`,T:An},{no:2,name:`contents`,kind:`scalar`,T:12}]),Mn=y.makeMessageType(`livekit.VideoLayer`,()=>[{no:1,name:`quality`,kind:`enum`,T:y.getEnumType(sn)},{no:2,name:`width`,kind:`scalar`,T:13},{no:3,name:`height`,kind:`scalar`,T:13},{no:4,name:`bitrate`,kind:`scalar`,T:13},{no:5,name:`ssrc`,kind:`scalar`,T:13},{no:6,name:`spatial_layer`,kind:`scalar`,T:5},{no:7,name:`rid`,kind:`scalar`,T:9},{no:8,name:`repair_ssrc`,kind:`scalar`,T:13}]),Nn=y.makeEnum(`livekit.VideoLayer.Mode`,[{no:0,name:`MODE_UNUSED`},{no:1,name:`ONE_SPATIAL_LAYER_PER_STREAM`},{no:2,name:`MULTIPLE_SPATIAL_LAYERS_PER_STREAM`},{no:3,name:`ONE_SPATIAL_LAYER_PER_STREAM_INCOMPLETE_RTCP_SR`}]),C=y.makeMessageType(`livekit.DataPacket`,()=>[{no:1,name:`kind`,kind:`enum`,T:y.getEnumType(Pn)},{no:4,name:`participant_identity`,kind:`scalar`,T:9},{no:5,name:`destination_identities`,kind:`scalar`,T:9,repeated:!0},{no:2,name:`user`,kind:`message`,T:zn,oneof:`value`},{no:3,name:`speaker`,kind:`message`,T:Ln,oneof:`value`},{no:6,name:`sip_dtmf`,kind:`message`,T:Bn,oneof:`value`},{no:7,name:`transcription`,kind:`message`,T:Vn,oneof:`value`},{no:8,name:`metrics`,kind:`message`,T:en,oneof:`value`},{no:9,name:`chat_message`,kind:`message`,T:Un,oneof:`value`},{no:10,name:`rpc_request`,kind:`message`,T:Wn,oneof:`value`},{no:11,name:`rpc_ack`,kind:`message`,T:Gn,oneof:`value`},{no:12,name:`rpc_response`,kind:`message`,T:Kn,oneof:`value`},{no:13,name:`stream_header`,kind:`message`,T:sr,oneof:`value`},{no:14,name:`stream_chunk`,kind:`message`,T:cr,oneof:`value`},{no:15,name:`stream_trailer`,kind:`message`,T:lr,oneof:`value`},{no:18,name:`encrypted_packet`,kind:`message`,T:Fn,oneof:`value`},{no:16,name:`sequence`,kind:`scalar`,T:13},{no:17,name:`participant_sid`,kind:`scalar`,T:9}]),Pn=y.makeEnum(`livekit.DataPacket.Kind`,[{no:0,name:`RELIABLE`},{no:1,name:`LOSSY`}]),Fn=y.makeMessageType(`livekit.EncryptedPacket`,()=>[{no:1,name:`encryption_type`,kind:`enum`,T:y.getEnumType(S)},{no:2,name:`iv`,kind:`scalar`,T:12},{no:3,name:`key_index`,kind:`scalar`,T:13},{no:4,name:`encrypted_value`,kind:`scalar`,T:12}]),In=y.makeMessageType(`livekit.EncryptedPacketPayload`,()=>[{no:1,name:`user`,kind:`message`,T:zn,oneof:`value`},{no:3,name:`chat_message`,kind:`message`,T:Un,oneof:`value`},{no:4,name:`rpc_request`,kind:`message`,T:Wn,oneof:`value`},{no:5,name:`rpc_ack`,kind:`message`,T:Gn,oneof:`value`},{no:6,name:`rpc_response`,kind:`message`,T:Kn,oneof:`value`},{no:7,name:`stream_header`,kind:`message`,T:sr,oneof:`value`},{no:8,name:`stream_chunk`,kind:`message`,T:cr,oneof:`value`},{no:9,name:`stream_trailer`,kind:`message`,T:lr,oneof:`value`}]),Ln=y.makeMessageType(`livekit.ActiveSpeakerUpdate`,()=>[{no:1,name:`speakers`,kind:`message`,T:Rn,repeated:!0}]),Rn=y.makeMessageType(`livekit.SpeakerInfo`,()=>[{no:1,name:`sid`,kind:`scalar`,T:9},{no:2,name:`level`,kind:`scalar`,T:2},{no:3,name:`active`,kind:`scalar`,T:8}]),zn=y.makeMessageType(`livekit.UserPacket`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:5,name:`participant_identity`,kind:`scalar`,T:9},{no:2,name:`payload`,kind:`scalar`,T:12},{no:3,name:`destination_sids`,kind:`scalar`,T:9,repeated:!0},{no:6,name:`destination_identities`,kind:`scalar`,T:9,repeated:!0},{no:4,name:`topic`,kind:`scalar`,T:9,opt:!0},{no:8,name:`id`,kind:`scalar`,T:9,opt:!0},{no:9,name:`start_time`,kind:`scalar`,T:4,opt:!0},{no:10,name:`end_time`,kind:`scalar`,T:4,opt:!0},{no:11,name:`nonce`,kind:`scalar`,T:12}]),Bn=y.makeMessageType(`livekit.SipDTMF`,()=>[{no:3,name:`code`,kind:`scalar`,T:13},{no:4,name:`digit`,kind:`scalar`,T:9}]),Vn=y.makeMessageType(`livekit.Transcription`,()=>[{no:2,name:`transcribed_participant_identity`,kind:`scalar`,T:9},{no:3,name:`track_id`,kind:`scalar`,T:9},{no:4,name:`segments`,kind:`message`,T:Hn,repeated:!0}]),Hn=y.makeMessageType(`livekit.TranscriptionSegment`,()=>[{no:1,name:`id`,kind:`scalar`,T:9},{no:2,name:`text`,kind:`scalar`,T:9},{no:3,name:`start_time`,kind:`scalar`,T:4},{no:4,name:`end_time`,kind:`scalar`,T:4},{no:5,name:`final`,kind:`scalar`,T:8},{no:6,name:`language`,kind:`scalar`,T:9}]),Un=y.makeMessageType(`livekit.ChatMessage`,()=>[{no:1,name:`id`,kind:`scalar`,T:9},{no:2,name:`timestamp`,kind:`scalar`,T:3},{no:3,name:`edit_timestamp`,kind:`scalar`,T:3,opt:!0},{no:4,name:`message`,kind:`scalar`,T:9},{no:5,name:`deleted`,kind:`scalar`,T:8},{no:6,name:`generated`,kind:`scalar`,T:8}]),Wn=y.makeMessageType(`livekit.RpcRequest`,()=>[{no:1,name:`id`,kind:`scalar`,T:9},{no:2,name:`method`,kind:`scalar`,T:9},{no:3,name:`payload`,kind:`scalar`,T:9},{no:4,name:`response_timeout_ms`,kind:`scalar`,T:13},{no:5,name:`version`,kind:`scalar`,T:13},{no:6,name:`compressed_payload`,kind:`scalar`,T:12}]),Gn=y.makeMessageType(`livekit.RpcAck`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:9}]),Kn=y.makeMessageType(`livekit.RpcResponse`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:9},{no:2,name:`payload`,kind:`scalar`,T:9,oneof:`value`},{no:3,name:`error`,kind:`message`,T:qn,oneof:`value`},{no:4,name:`compressed_payload`,kind:`scalar`,T:12,oneof:`value`}]),qn=y.makeMessageType(`livekit.RpcError`,()=>[{no:1,name:`code`,kind:`scalar`,T:13},{no:2,name:`message`,kind:`scalar`,T:9},{no:3,name:`data`,kind:`scalar`,T:9}]),Jn=y.makeMessageType(`livekit.ParticipantTracks`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:2,name:`track_sids`,kind:`scalar`,T:9,repeated:!0}]),Yn=y.makeMessageType(`livekit.ServerInfo`,()=>[{no:1,name:`edition`,kind:`enum`,T:y.getEnumType(Xn)},{no:2,name:`version`,kind:`scalar`,T:9},{no:3,name:`protocol`,kind:`scalar`,T:5},{no:4,name:`region`,kind:`scalar`,T:9},{no:5,name:`node_id`,kind:`scalar`,T:9},{no:6,name:`debug_info`,kind:`scalar`,T:9},{no:7,name:`agent_protocol`,kind:`scalar`,T:5}]),Xn=y.makeEnum(`livekit.ServerInfo.Edition`,[{no:0,name:`Standard`},{no:1,name:`Cloud`}]),Zn=y.makeMessageType(`livekit.ClientInfo`,()=>[{no:1,name:`sdk`,kind:`enum`,T:y.getEnumType(Qn)},{no:2,name:`version`,kind:`scalar`,T:9},{no:3,name:`protocol`,kind:`scalar`,T:5},{no:4,name:`os`,kind:`scalar`,T:9},{no:5,name:`os_version`,kind:`scalar`,T:9},{no:6,name:`device_model`,kind:`scalar`,T:9},{no:7,name:`browser`,kind:`scalar`,T:9},{no:8,name:`browser_version`,kind:`scalar`,T:9},{no:9,name:`address`,kind:`scalar`,T:9},{no:10,name:`network`,kind:`scalar`,T:9},{no:11,name:`other_sdks`,kind:`scalar`,T:9},{no:12,name:`client_protocol`,kind:`scalar`,T:5},{no:13,name:`capabilities`,kind:`enum`,T:y.getEnumType($n),repeated:!0}]),Qn=y.makeEnum(`livekit.ClientInfo.SDK`,[{no:0,name:`UNKNOWN`},{no:1,name:`JS`},{no:2,name:`SWIFT`},{no:3,name:`ANDROID`},{no:4,name:`FLUTTER`},{no:5,name:`GO`},{no:6,name:`UNITY`},{no:7,name:`REACT_NATIVE`},{no:8,name:`RUST`},{no:9,name:`PYTHON`},{no:10,name:`CPP`},{no:11,name:`UNITY_WEB`},{no:12,name:`NODE`},{no:13,name:`UNREAL`},{no:14,name:`ESP32`},{no:15,name:`DOTNET`}]),$n=y.makeEnum(`livekit.ClientInfo.Capability`,[{no:0,name:`CAP_UNUSED`},{no:1,name:`CAP_PACKET_TRAILER`},{no:2,name:`CAP_COMPRESSION_DEFLATE_RAW`}]),er=y.makeMessageType(`livekit.ClientConfiguration`,()=>[{no:1,name:`video`,kind:`message`,T:tr},{no:2,name:`screen`,kind:`message`,T:tr},{no:3,name:`resume_connection`,kind:`enum`,T:y.getEnumType(ln)},{no:4,name:`disabled_codecs`,kind:`message`,T:nr},{no:5,name:`force_relay`,kind:`enum`,T:y.getEnumType(ln)}]),tr=y.makeMessageType(`livekit.VideoConfiguration`,()=>[{no:1,name:`hardware_encoder`,kind:`enum`,T:y.getEnumType(ln)}]),nr=y.makeMessageType(`livekit.DisabledCodecs`,()=>[{no:1,name:`codecs`,kind:`message`,T:hn,repeated:!0},{no:2,name:`publish`,kind:`message`,T:hn,repeated:!0}]),rr=y.makeMessageType(`livekit.TimedVersion`,()=>[{no:1,name:`unix_micro`,kind:`scalar`,T:3},{no:2,name:`ticks`,kind:`scalar`,T:5}]),ir=y.makeEnum(`livekit.DataStream.OperationType`,[{no:0,name:`CREATE`},{no:1,name:`UPDATE`},{no:2,name:`DELETE`},{no:3,name:`REACTION`}]),w=y.makeEnum(`livekit.DataStream.CompressionType`,[{no:0,name:`NONE`},{no:1,name:`DEFLATE_RAW`}]),ar=y.makeMessageType(`livekit.DataStream.TextHeader`,()=>[{no:1,name:`operation_type`,kind:`enum`,T:y.getEnumType(ir)},{no:2,name:`version`,kind:`scalar`,T:5},{no:3,name:`reply_to_stream_id`,kind:`scalar`,T:9},{no:4,name:`attached_stream_ids`,kind:`scalar`,T:9,repeated:!0},{no:5,name:`generated`,kind:`scalar`,T:8}],{localName:`DataStream_TextHeader`}),or=y.makeMessageType(`livekit.DataStream.ByteHeader`,()=>[{no:1,name:`name`,kind:`scalar`,T:9}],{localName:`DataStream_ByteHeader`}),sr=y.makeMessageType(`livekit.DataStream.Header`,()=>[{no:1,name:`stream_id`,kind:`scalar`,T:9},{no:2,name:`timestamp`,kind:`scalar`,T:3},{no:3,name:`topic`,kind:`scalar`,T:9},{no:4,name:`mime_type`,kind:`scalar`,T:9},{no:5,name:`total_length`,kind:`scalar`,T:4,opt:!0},{no:7,name:`encryption_type`,kind:`enum`,T:y.getEnumType(S)},{no:8,name:`attributes`,kind:`map`,K:9,V:{kind:`scalar`,T:9}},{no:9,name:`text_header`,kind:`message`,T:ar,oneof:`content_header`},{no:10,name:`byte_header`,kind:`message`,T:or,oneof:`content_header`},{no:11,name:`inline_content`,kind:`scalar`,T:12,opt:!0},{no:12,name:`compression`,kind:`enum`,T:y.getEnumType(w)}],{localName:`DataStream_Header`}),cr=y.makeMessageType(`livekit.DataStream.Chunk`,()=>[{no:1,name:`stream_id`,kind:`scalar`,T:9},{no:2,name:`chunk_index`,kind:`scalar`,T:4},{no:3,name:`content`,kind:`scalar`,T:12},{no:4,name:`version`,kind:`scalar`,T:5},{no:5,name:`iv`,kind:`scalar`,T:12,opt:!0}],{localName:`DataStream_Chunk`}),lr=y.makeMessageType(`livekit.DataStream.Trailer`,()=>[{no:1,name:`stream_id`,kind:`scalar`,T:9},{no:2,name:`reason`,kind:`scalar`,T:9},{no:3,name:`attributes`,kind:`map`,K:9,V:{kind:`scalar`,T:9}}],{localName:`DataStream_Trailer`}),ur=y.makeMessageType(`livekit.SubscribedAudioCodec`,()=>[{no:1,name:`codec`,kind:`scalar`,T:9},{no:2,name:`enabled`,kind:`scalar`,T:8}]),dr=y.makeEnum(`livekit.SignalTarget`,[{no:0,name:`PUBLISHER`},{no:1,name:`SUBSCRIBER`}]),fr=y.makeEnum(`livekit.StreamState`,[{no:0,name:`ACTIVE`},{no:1,name:`PAUSED`}]),pr=y.makeEnum(`livekit.CandidateProtocol`,[{no:0,name:`UDP`},{no:1,name:`TCP`},{no:2,name:`TLS`}]),mr=y.makeMessageType(`livekit.SignalRequest`,()=>[{no:1,name:`offer`,kind:`message`,T:Ar,oneof:`message`},{no:2,name:`answer`,kind:`message`,T:Ar,oneof:`message`},{no:3,name:`trickle`,kind:`message`,T:wr,oneof:`message`},{no:4,name:`add_track`,kind:`message`,T:_r,oneof:`message`},{no:5,name:`mute`,kind:`message`,T:Tr,oneof:`message`},{no:6,name:`subscription`,kind:`message`,T:Mr,oneof:`message`},{no:7,name:`track_setting`,kind:`message`,T:zr,oneof:`message`},{no:8,name:`leave`,kind:`message`,T:Hr,oneof:`message`},{no:10,name:`update_layers`,kind:`message`,T:Wr,oneof:`message`},{no:11,name:`subscription_permission`,kind:`message`,T:ii,oneof:`message`},{no:12,name:`sync_state`,kind:`message`,T:si,oneof:`message`},{no:13,name:`simulate`,kind:`message`,T:ui,oneof:`message`},{no:14,name:`ping`,kind:`scalar`,T:3,oneof:`message`},{no:15,name:`update_metadata`,kind:`message`,T:Gr,oneof:`message`},{no:16,name:`ping_req`,kind:`message`,T:di,oneof:`message`},{no:17,name:`update_audio_track`,kind:`message`,T:Br,oneof:`message`},{no:18,name:`update_video_track`,kind:`message`,T:Vr,oneof:`message`},{no:19,name:`publish_data_track_request`,kind:`message`,T:vr,oneof:`message`},{no:20,name:`unpublish_data_track_request`,kind:`message`,T:br,oneof:`message`},{no:21,name:`update_data_subscription`,kind:`message`,T:Nr,oneof:`message`},{no:22,name:`store_data_blob_request`,kind:`message`,T:Fr,oneof:`message`},{no:23,name:`get_data_blob_request`,kind:`message`,T:Lr,oneof:`message`}]),hr=y.makeMessageType(`livekit.SignalResponse`,()=>[{no:1,name:`join`,kind:`message`,T:Er,oneof:`message`},{no:2,name:`answer`,kind:`message`,T:Ar,oneof:`message`},{no:3,name:`offer`,kind:`message`,T:Ar,oneof:`message`},{no:4,name:`trickle`,kind:`message`,T:wr,oneof:`message`},{no:5,name:`update`,kind:`message`,T:jr,oneof:`message`},{no:6,name:`track_published`,kind:`message`,T:Or,oneof:`message`},{no:8,name:`leave`,kind:`message`,T:Hr,oneof:`message`},{no:9,name:`mute`,kind:`message`,T:Tr,oneof:`message`},{no:10,name:`speakers_changed`,kind:`message`,T:qr,oneof:`message`},{no:11,name:`room_update`,kind:`message`,T:Jr,oneof:`message`},{no:12,name:`connection_quality`,kind:`message`,T:Xr,oneof:`message`},{no:13,name:`stream_state_update`,kind:`message`,T:Qr,oneof:`message`},{no:14,name:`subscribed_quality_update`,kind:`message`,T:ti,oneof:`message`},{no:15,name:`subscription_permission_update`,kind:`message`,T:ai,oneof:`message`},{no:16,name:`refresh_token`,kind:`scalar`,T:9,oneof:`message`},{no:17,name:`track_unpublished`,kind:`message`,T:kr,oneof:`message`},{no:18,name:`pong`,kind:`scalar`,T:3,oneof:`message`},{no:19,name:`reconnect`,kind:`message`,T:Dr,oneof:`message`},{no:20,name:`pong_resp`,kind:`message`,T:fi,oneof:`message`},{no:21,name:`subscription_response`,kind:`message`,T:hi,oneof:`message`},{no:22,name:`request_response`,kind:`message`,T:gi,oneof:`message`},{no:23,name:`track_subscribed`,kind:`message`,T:vi,oneof:`message`},{no:24,name:`room_moved`,kind:`message`,T:oi,oneof:`message`},{no:25,name:`media_sections_requirement`,kind:`message`,T:Ci,oneof:`message`},{no:26,name:`subscribed_audio_codec_update`,kind:`message`,T:ni,oneof:`message`},{no:27,name:`publish_data_track_response`,kind:`message`,T:yr,oneof:`message`},{no:28,name:`unpublish_data_track_response`,kind:`message`,T:xr,oneof:`message`},{no:29,name:`data_track_subscriber_handles`,kind:`message`,T:Sr,oneof:`message`},{no:30,name:`store_data_blob_response`,kind:`message`,T:Ir,oneof:`message`},{no:31,name:`get_data_blob_response`,kind:`message`,T:Rr,oneof:`message`}]),gr=y.makeMessageType(`livekit.SimulcastCodec`,()=>[{no:1,name:`codec`,kind:`scalar`,T:9},{no:2,name:`cid`,kind:`scalar`,T:9},{no:4,name:`layers`,kind:`message`,T:Mn,repeated:!0},{no:5,name:`video_layer_mode`,kind:`enum`,T:y.getEnumType(Nn)}]),_r=y.makeMessageType(`livekit.AddTrackRequest`,()=>[{no:1,name:`cid`,kind:`scalar`,T:9},{no:2,name:`name`,kind:`scalar`,T:9},{no:3,name:`type`,kind:`enum`,T:y.getEnumType(on)},{no:4,name:`width`,kind:`scalar`,T:13},{no:5,name:`height`,kind:`scalar`,T:13},{no:6,name:`muted`,kind:`scalar`,T:8},{no:7,name:`disable_dtx`,kind:`scalar`,T:8},{no:8,name:`source`,kind:`enum`,T:y.getEnumType(b)},{no:9,name:`layers`,kind:`message`,T:Mn,repeated:!0},{no:10,name:`simulcast_codecs`,kind:`message`,T:gr,repeated:!0},{no:11,name:`sid`,kind:`scalar`,T:9},{no:12,name:`stereo`,kind:`scalar`,T:8},{no:13,name:`disable_red`,kind:`scalar`,T:8},{no:14,name:`encryption`,kind:`enum`,T:y.getEnumType(S)},{no:15,name:`stream`,kind:`scalar`,T:9},{no:16,name:`backup_codec_policy`,kind:`enum`,T:y.getEnumType(an)},{no:17,name:`audio_features`,kind:`enum`,T:y.getEnumType(x),repeated:!0},{no:18,name:`packet_trailer_features`,kind:`enum`,T:y.getEnumType(pn),repeated:!0}]),vr=y.makeMessageType(`livekit.PublishDataTrackRequest`,()=>[{no:1,name:`pub_handle`,kind:`scalar`,T:13},{no:2,name:`name`,kind:`scalar`,T:9},{no:3,name:`encryption`,kind:`enum`,T:y.getEnumType(S)},{no:4,name:`frame_encoding`,kind:`message`,T:wn,opt:!0},{no:5,name:`schema`,kind:`message`,T:On,opt:!0}]),yr=y.makeMessageType(`livekit.PublishDataTrackResponse`,()=>[{no:1,name:`info`,kind:`message`,T:Cn}]),br=y.makeMessageType(`livekit.UnpublishDataTrackRequest`,()=>[{no:1,name:`pub_handle`,kind:`scalar`,T:13}]),xr=y.makeMessageType(`livekit.UnpublishDataTrackResponse`,()=>[{no:1,name:`info`,kind:`message`,T:Cn}]),Sr=y.makeMessageType(`livekit.DataTrackSubscriberHandles`,()=>[{no:1,name:`sub_handles`,kind:`map`,K:13,V:{kind:`message`,T:Cr}}]),Cr=y.makeMessageType(`livekit.DataTrackSubscriberHandles.PublishedDataTrack`,()=>[{no:1,name:`publisher_identity`,kind:`scalar`,T:9},{no:2,name:`publisher_sid`,kind:`scalar`,T:9},{no:3,name:`track_sid`,kind:`scalar`,T:9}],{localName:`DataTrackSubscriberHandles_PublishedDataTrack`}),wr=y.makeMessageType(`livekit.TrickleRequest`,()=>[{no:1,name:`candidateInit`,kind:`scalar`,T:9},{no:2,name:`target`,kind:`enum`,T:y.getEnumType(dr)},{no:3,name:`final`,kind:`scalar`,T:8}]),Tr=y.makeMessageType(`livekit.MuteTrackRequest`,()=>[{no:1,name:`sid`,kind:`scalar`,T:9},{no:2,name:`muted`,kind:`scalar`,T:8}]),Er=y.makeMessageType(`livekit.JoinResponse`,()=>[{no:1,name:`room`,kind:`message`,T:mn},{no:2,name:`participant`,kind:`message`,T:_n},{no:3,name:`other_participants`,kind:`message`,T:_n,repeated:!0},{no:4,name:`server_version`,kind:`scalar`,T:9},{no:5,name:`ice_servers`,kind:`message`,T:Kr,repeated:!0},{no:6,name:`subscriber_primary`,kind:`scalar`,T:8},{no:7,name:`alternative_url`,kind:`scalar`,T:9},{no:8,name:`client_configuration`,kind:`message`,T:er},{no:9,name:`server_region`,kind:`scalar`,T:9},{no:10,name:`ping_timeout`,kind:`scalar`,T:5},{no:11,name:`ping_interval`,kind:`scalar`,T:5},{no:12,name:`server_info`,kind:`message`,T:Yn},{no:13,name:`sif_trailer`,kind:`scalar`,T:12},{no:14,name:`enabled_publish_codecs`,kind:`message`,T:hn,repeated:!0},{no:15,name:`fast_publish`,kind:`scalar`,T:8}]),Dr=y.makeMessageType(`livekit.ReconnectResponse`,()=>[{no:1,name:`ice_servers`,kind:`message`,T:Kr,repeated:!0},{no:2,name:`client_configuration`,kind:`message`,T:er},{no:3,name:`server_info`,kind:`message`,T:Yn},{no:4,name:`last_message_seq`,kind:`scalar`,T:13}]),Or=y.makeMessageType(`livekit.TrackPublishedResponse`,()=>[{no:1,name:`cid`,kind:`scalar`,T:9},{no:2,name:`track`,kind:`message`,T:Sn}]),kr=y.makeMessageType(`livekit.TrackUnpublishedResponse`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9}]),Ar=y.makeMessageType(`livekit.SessionDescription`,()=>[{no:1,name:`type`,kind:`scalar`,T:9},{no:2,name:`sdp`,kind:`scalar`,T:9},{no:3,name:`id`,kind:`scalar`,T:13},{no:4,name:`mid_to_track_id`,kind:`map`,K:9,V:{kind:`scalar`,T:9}}]),jr=y.makeMessageType(`livekit.ParticipantUpdate`,()=>[{no:1,name:`participants`,kind:`message`,T:_n,repeated:!0}]),Mr=y.makeMessageType(`livekit.UpdateSubscription`,()=>[{no:1,name:`track_sids`,kind:`scalar`,T:9,repeated:!0},{no:2,name:`subscribe`,kind:`scalar`,T:8},{no:3,name:`participant_tracks`,kind:`message`,T:Jn,repeated:!0}]),Nr=y.makeMessageType(`livekit.UpdateDataSubscription`,()=>[{no:1,name:`updates`,kind:`message`,T:Pr,repeated:!0}]),Pr=y.makeMessageType(`livekit.UpdateDataSubscription.Update`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`subscribe`,kind:`scalar`,T:8},{no:3,name:`options`,kind:`message`,T:kn}],{localName:`UpdateDataSubscription_Update`}),Fr=y.makeMessageType(`livekit.StoreDataBlobRequest`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:13},{no:2,name:`blob`,kind:`message`,T:jn}]),Ir=y.makeMessageType(`livekit.StoreDataBlobResponse`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:13},{no:2,name:`key`,kind:`message`,T:An}]),Lr=y.makeMessageType(`livekit.GetDataBlobRequest`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:13},{no:2,name:`participant_identity`,kind:`scalar`,T:9},{no:3,name:`key`,kind:`message`,T:An}]),Rr=y.makeMessageType(`livekit.GetDataBlobResponse`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:13},{no:2,name:`blob`,kind:`message`,T:jn}]),zr=y.makeMessageType(`livekit.UpdateTrackSettings`,()=>[{no:1,name:`track_sids`,kind:`scalar`,T:9,repeated:!0},{no:3,name:`disabled`,kind:`scalar`,T:8},{no:4,name:`quality`,kind:`enum`,T:y.getEnumType(sn)},{no:5,name:`width`,kind:`scalar`,T:13},{no:6,name:`height`,kind:`scalar`,T:13},{no:7,name:`fps`,kind:`scalar`,T:13},{no:8,name:`priority`,kind:`scalar`,T:13}]),Br=y.makeMessageType(`livekit.UpdateLocalAudioTrack`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`features`,kind:`enum`,T:y.getEnumType(x),repeated:!0}]),Vr=y.makeMessageType(`livekit.UpdateLocalVideoTrack`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`width`,kind:`scalar`,T:13},{no:3,name:`height`,kind:`scalar`,T:13}]),Hr=y.makeMessageType(`livekit.LeaveRequest`,()=>[{no:1,name:`can_reconnect`,kind:`scalar`,T:8},{no:2,name:`reason`,kind:`enum`,T:y.getEnumType(un)},{no:3,name:`action`,kind:`enum`,T:y.getEnumType(Ur)},{no:4,name:`regions`,kind:`message`,T:pi}]),Ur=y.makeEnum(`livekit.LeaveRequest.Action`,[{no:0,name:`DISCONNECT`},{no:1,name:`RESUME`},{no:2,name:`RECONNECT`}]),Wr=y.makeMessageType(`livekit.UpdateVideoLayers`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`layers`,kind:`message`,T:Mn,repeated:!0}]),Gr=y.makeMessageType(`livekit.UpdateParticipantMetadata`,()=>[{no:1,name:`metadata`,kind:`scalar`,T:9},{no:2,name:`name`,kind:`scalar`,T:9},{no:3,name:`attributes`,kind:`map`,K:9,V:{kind:`scalar`,T:9}},{no:4,name:`request_id`,kind:`scalar`,T:13}]),Kr=y.makeMessageType(`livekit.ICEServer`,()=>[{no:1,name:`urls`,kind:`scalar`,T:9,repeated:!0},{no:2,name:`username`,kind:`scalar`,T:9},{no:3,name:`credential`,kind:`scalar`,T:9}]),qr=y.makeMessageType(`livekit.SpeakersChanged`,()=>[{no:1,name:`speakers`,kind:`message`,T:Rn,repeated:!0}]),Jr=y.makeMessageType(`livekit.RoomUpdate`,()=>[{no:1,name:`room`,kind:`message`,T:mn}]),Yr=y.makeMessageType(`livekit.ConnectionQualityInfo`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:2,name:`quality`,kind:`enum`,T:y.getEnumType(cn)},{no:3,name:`score`,kind:`scalar`,T:2}]),Xr=y.makeMessageType(`livekit.ConnectionQualityUpdate`,()=>[{no:1,name:`updates`,kind:`message`,T:Yr,repeated:!0}]),Zr=y.makeMessageType(`livekit.StreamStateInfo`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:2,name:`track_sid`,kind:`scalar`,T:9},{no:3,name:`state`,kind:`enum`,T:y.getEnumType(fr)}]),Qr=y.makeMessageType(`livekit.StreamStateUpdate`,()=>[{no:1,name:`stream_states`,kind:`message`,T:Zr,repeated:!0}]),$r=y.makeMessageType(`livekit.SubscribedQuality`,()=>[{no:1,name:`quality`,kind:`enum`,T:y.getEnumType(sn)},{no:2,name:`enabled`,kind:`scalar`,T:8}]),ei=y.makeMessageType(`livekit.SubscribedCodec`,()=>[{no:1,name:`codec`,kind:`scalar`,T:9},{no:2,name:`qualities`,kind:`message`,T:$r,repeated:!0}]),ti=y.makeMessageType(`livekit.SubscribedQualityUpdate`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`subscribed_qualities`,kind:`message`,T:$r,repeated:!0},{no:3,name:`subscribed_codecs`,kind:`message`,T:ei,repeated:!0}]),ni=y.makeMessageType(`livekit.SubscribedAudioCodecUpdate`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`subscribed_audio_codecs`,kind:`message`,T:ur,repeated:!0}]),ri=y.makeMessageType(`livekit.TrackPermission`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:2,name:`all_tracks`,kind:`scalar`,T:8},{no:3,name:`track_sids`,kind:`scalar`,T:9,repeated:!0},{no:4,name:`participant_identity`,kind:`scalar`,T:9}]),ii=y.makeMessageType(`livekit.SubscriptionPermission`,()=>[{no:1,name:`all_participants`,kind:`scalar`,T:8},{no:2,name:`track_permissions`,kind:`message`,T:ri,repeated:!0}]),ai=y.makeMessageType(`livekit.SubscriptionPermissionUpdate`,()=>[{no:1,name:`participant_sid`,kind:`scalar`,T:9},{no:2,name:`track_sid`,kind:`scalar`,T:9},{no:3,name:`allowed`,kind:`scalar`,T:8}]),oi=y.makeMessageType(`livekit.RoomMovedResponse`,()=>[{no:1,name:`room`,kind:`message`,T:mn},{no:2,name:`token`,kind:`scalar`,T:9},{no:3,name:`participant`,kind:`message`,T:_n},{no:4,name:`other_participants`,kind:`message`,T:_n,repeated:!0}]),si=y.makeMessageType(`livekit.SyncState`,()=>[{no:1,name:`answer`,kind:`message`,T:Ar},{no:2,name:`subscription`,kind:`message`,T:Mr},{no:3,name:`publish_tracks`,kind:`message`,T:Or,repeated:!0},{no:4,name:`data_channels`,kind:`message`,T:li,repeated:!0},{no:5,name:`offer`,kind:`message`,T:Ar},{no:6,name:`track_sids_disabled`,kind:`scalar`,T:9,repeated:!0},{no:7,name:`datachannel_receive_states`,kind:`message`,T:ci,repeated:!0},{no:8,name:`publish_data_tracks`,kind:`message`,T:yr,repeated:!0},{no:9,name:`data_subscription`,kind:`message`,T:Nr}]),ci=y.makeMessageType(`livekit.DataChannelReceiveState`,()=>[{no:1,name:`publisher_sid`,kind:`scalar`,T:9},{no:2,name:`last_seq`,kind:`scalar`,T:13}]),li=y.makeMessageType(`livekit.DataChannelInfo`,()=>[{no:1,name:`label`,kind:`scalar`,T:9},{no:2,name:`id`,kind:`scalar`,T:13},{no:3,name:`target`,kind:`enum`,T:y.getEnumType(dr)}]),ui=y.makeMessageType(`livekit.SimulateScenario`,()=>[{no:1,name:`speaker_update`,kind:`scalar`,T:5,oneof:`scenario`},{no:2,name:`node_failure`,kind:`scalar`,T:8,oneof:`scenario`},{no:3,name:`migration`,kind:`scalar`,T:8,oneof:`scenario`},{no:4,name:`server_leave`,kind:`scalar`,T:8,oneof:`scenario`},{no:5,name:`switch_candidate_protocol`,kind:`enum`,T:y.getEnumType(pr),oneof:`scenario`},{no:6,name:`subscriber_bandwidth`,kind:`scalar`,T:3,oneof:`scenario`},{no:7,name:`disconnect_signal_on_resume`,kind:`scalar`,T:8,oneof:`scenario`},{no:8,name:`disconnect_signal_on_resume_no_messages`,kind:`scalar`,T:8,oneof:`scenario`},{no:9,name:`leave_request_full_reconnect`,kind:`scalar`,T:8,oneof:`scenario`}]),di=y.makeMessageType(`livekit.Ping`,()=>[{no:1,name:`timestamp`,kind:`scalar`,T:3},{no:2,name:`rtt`,kind:`scalar`,T:3}]),fi=y.makeMessageType(`livekit.Pong`,()=>[{no:1,name:`last_ping_timestamp`,kind:`scalar`,T:3},{no:2,name:`timestamp`,kind:`scalar`,T:3}]),pi=y.makeMessageType(`livekit.RegionSettings`,()=>[{no:1,name:`regions`,kind:`message`,T:mi,repeated:!0}]),mi=y.makeMessageType(`livekit.RegionInfo`,()=>[{no:1,name:`region`,kind:`scalar`,T:9},{no:2,name:`url`,kind:`scalar`,T:9},{no:3,name:`distance`,kind:`scalar`,T:3}]),hi=y.makeMessageType(`livekit.SubscriptionResponse`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9},{no:2,name:`err`,kind:`enum`,T:y.getEnumType(fn)}]),gi=y.makeMessageType(`livekit.RequestResponse`,()=>[{no:1,name:`request_id`,kind:`scalar`,T:13},{no:2,name:`reason`,kind:`enum`,T:y.getEnumType(_i)},{no:3,name:`message`,kind:`scalar`,T:9},{no:4,name:`trickle`,kind:`message`,T:wr,oneof:`request`},{no:5,name:`add_track`,kind:`message`,T:_r,oneof:`request`},{no:6,name:`mute`,kind:`message`,T:Tr,oneof:`request`},{no:7,name:`update_metadata`,kind:`message`,T:Gr,oneof:`request`},{no:8,name:`update_audio_track`,kind:`message`,T:Br,oneof:`request`},{no:9,name:`update_video_track`,kind:`message`,T:Vr,oneof:`request`},{no:10,name:`publish_data_track`,kind:`message`,T:vr,oneof:`request`},{no:11,name:`unpublish_data_track`,kind:`message`,T:br,oneof:`request`}]),_i=y.makeEnum(`livekit.RequestResponse.Reason`,[{no:0,name:`OK`},{no:1,name:`NOT_FOUND`},{no:2,name:`NOT_ALLOWED`},{no:3,name:`LIMIT_EXCEEDED`},{no:4,name:`QUEUED`},{no:5,name:`UNSUPPORTED_TYPE`},{no:6,name:`UNCLASSIFIED_ERROR`},{no:7,name:`INVALID_HANDLE`},{no:8,name:`INVALID_NAME`},{no:9,name:`DUPLICATE_HANDLE`},{no:10,name:`DUPLICATE_NAME`},{no:11,name:`INVALID_REQUEST`}]),vi=y.makeMessageType(`livekit.TrackSubscribed`,()=>[{no:1,name:`track_sid`,kind:`scalar`,T:9}]),yi=y.makeMessageType(`livekit.ConnectionSettings`,()=>[{no:1,name:`auto_subscribe`,kind:`scalar`,T:8},{no:2,name:`adaptive_stream`,kind:`scalar`,T:8},{no:3,name:`subscriber_allow_pause`,kind:`scalar`,T:8,opt:!0},{no:4,name:`disable_ice_lite`,kind:`scalar`,T:8},{no:5,name:`auto_subscribe_data_track`,kind:`scalar`,T:8,opt:!0}]),bi=y.makeMessageType(`livekit.JoinRequest`,()=>[{no:1,name:`client_info`,kind:`message`,T:Zn},{no:2,name:`connection_settings`,kind:`message`,T:yi},{no:3,name:`metadata`,kind:`scalar`,T:9},{no:4,name:`participant_attributes`,kind:`map`,K:9,V:{kind:`scalar`,T:9}},{no:5,name:`add_track_requests`,kind:`message`,T:_r,repeated:!0},{no:6,name:`publisher_offer`,kind:`message`,T:Ar},{no:7,name:`reconnect`,kind:`scalar`,T:8},{no:8,name:`reconnect_reason`,kind:`enum`,T:y.getEnumType(dn)},{no:9,name:`participant_sid`,kind:`scalar`,T:9},{no:10,name:`sync_state`,kind:`message`,T:si}]),xi=y.makeMessageType(`livekit.WrappedJoinRequest`,()=>[{no:1,name:`compression`,kind:`enum`,T:y.getEnumType(Si)},{no:2,name:`join_request`,kind:`scalar`,T:12}]),Si=y.makeEnum(`livekit.WrappedJoinRequest.Compression`,[{no:0,name:`NONE`},{no:1,name:`GZIP`}]),Ci=y.makeMessageType(`livekit.MediaSectionsRequirement`,()=>[{no:1,name:`num_audios`,kind:`scalar`,T:13},{no:2,name:`num_videos`,kind:`scalar`,T:13}]);function wi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}var Ti={exports:{}},Ei=Ti.exports,Di;function Oi(){return Di||(Di=1,(function(e){(function(t,n){e.exports?e.exports=n():t.log=n()})(Ei,function(){var e=function(){},t=`undefined`,n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=[`trace`,`debug`,`info`,`warn`,`error`],i={},a=null;function o(e,t){var n=e[t];if(typeof n.bind==`function`)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch{return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(r){return r===`debug`&&(r=`log`),typeof console===t?!1:r===`trace`&&n?s:console[r]===void 0?console.log===void 0?e:o(console,`log`):o(console,r)}function l(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return`No console available for logging`}function u(e){return function(){typeof console!==t&&(l.call(this),this[e].apply(this,arguments))}}function d(e,t,n){return c(e)||u.apply(this,arguments)}function f(e,n){var o=this,s,c,u,f=`loglevel`;typeof e==`string`?f+=`:`+e:typeof e==`symbol`&&(f=void 0);function p(e){var n=(r[e]||`silent`).toUpperCase();if(typeof window!==t&&f){try{window.localStorage[f]=n;return}catch{}try{window.document.cookie=encodeURIComponent(f)+`=`+n+`;`}catch{}}}function ee(){var e;if(typeof window!==t&&f){try{e=window.localStorage[f]}catch{}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(f),i=n.indexOf(r+`=`);i!==-1&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch{}return o.levels[e]===void 0&&(e=void 0),e}}function te(){if(typeof window!==t&&f){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+`=; expires=Thu, 01 Jan 1970 00:00:00 UTC`}catch{}}}function ne(e){var t=e;if(typeof t==`string`&&o.levels[t.toUpperCase()]!==void 0&&(t=o.levels[t.toUpperCase()]),typeof t==`number`&&t>=0&&t<=o.levels.SILENT)return t;throw TypeError(`log.setLevel() called with invalid level: `+e)}o.name=e,o.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.methodFactory=n||d,o.getLevel=function(){return u??c??s},o.setLevel=function(e,t){return u=ne(e),t!==!1&&p(u),l.call(o)},o.setDefaultLevel=function(e){c=ne(e),ee()||o.setLevel(e,!1)},o.resetLevel=function(){u=null,te(),l.call(o)},o.enableAll=function(e){o.setLevel(o.levels.TRACE,e)},o.disableAll=function(e){o.setLevel(o.levels.SILENT,e)},o.rebuild=function(){if(a!==o&&(s=ne(a.getLevel())),l.call(o),a===o)for(var e in i)i[e].rebuild()},s=ne(a?a.getLevel():`WARN`);var re=ee();re!=null&&(u=ne(re)),l.call(o)}a=new f,a.getLogger=function(e){if(typeof e!=`symbol`&&typeof e!=`string`||e===``)throw TypeError(`You must supply a name when creating a logger.`);var t=i[e];return t||=i[e]=new f(e,a.methodFactory),t};var p=typeof window===t?void 0:window.log;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=p),a},a.getLoggers=function(){return i},a.default=a,a})})(Ti)),Ti.exports}var ki=Oi(),Ai;(function(e){e[e.trace=0]=`trace`,e[e.debug=1]=`debug`,e[e.info=2]=`info`,e[e.warn=3]=`warn`,e[e.error=4]=`error`,e[e.silent=5]=`silent`})(Ai||={});var T;(function(e){e.Default=`livekit`,e.Room=`livekit-room`,e.TokenSource=`livekit-token-source`,e.Participant=`livekit-participant`,e.Track=`livekit-track`,e.Publication=`livekit-track-publication`,e.Engine=`livekit-engine`,e.Signal=`livekit-signal`,e.PCManager=`livekit-pc-manager`,e.PCTransport=`livekit-pc-transport`,e.E2EE=`lk-e2ee`,e.DataTracks=`livekit-data-tracks`,e.Region=`livekit-region`,e.ICE=`livekit-ice`,e.Stats=`livekit-stats`})(T||={});var E=ki.getLogger(T.Default);Object.values(T).map(e=>ki.getLogger(e)),E.setDefaultLevel(Ai.info);function D(e,t){let n=ki.getLogger(e);return n.setDefaultLevel(E.getLevel()),t?ji(n,t):n}function ji(e,t){let n=n=>(r,i)=>{let a=t(),o=a||i?Object.assign(Object.assign({},a),i):void 0;e[n](r,o)},r=Object.create(e);return r.trace=n(`trace`),r.debug=n(`debug`),r.info=n(`info`),r.warn=n(`warn`),r.error=n(`error`),r}var Mi=ki.getLogger(T.E2EE),Ni=new Set,Pi=Mi.setLevel.bind(Mi);Mi.setLevel=(e,t)=>{Pi(e,t);let n=Mi.getLevel();Ni.forEach(e=>e(n))};function Fi(e){return Ni.add(e),()=>{Ni.delete(e)}}var Ii=7e3,Li=500,Ri=[0,300,1200,2700,4800,Ii,Ii,Ii,Ii,Ii],zi=class{constructor(e){this._retryDelays=e===void 0?Ri:[...e]}nextRetryDelayInMs(e){if(e.retryCount>=this._retryDelays.length)return null;let t=this._retryDelays[e.retryCount];return e.retryCount===0&&t===0?Math.random()*Li:Math.round(t*(.5+Math.random()))}};function Bi(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function O(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function Vi(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}function Hi(e){return this instanceof Hi?(this.v=e,this):new Hi(e)}function Ui(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof Hi?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}}function Wi(e){var t={},n;return r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:Hi(e[r](t)),done:!1}:i?i(t):t}:i}}function Gi(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof Vi==`function`?Vi(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}}var Ki={exports:{}},qi;function Ji(){if(qi)return Ki.exports;qi=1;var e=typeof Reflect==`object`?Reflect:null,t=e&&typeof e.apply==`function`?e.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},n=e&&typeof e.ownKeys==`function`?e.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function r(e){console&&console.warn&&console.warn(e)}var i=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}Ki.exports=a,Ki.exports.once=re,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var o=10;function s(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if(typeof e!=`number`||e<0||i(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);o=e}}),a.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||i(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function c(e){return e._maxListeners===void 0?a.defaultMaxListeners:e._maxListeners}a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(n.length>0&&(o=n[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)t(c,this,n);else for(var l=c.length,u=ee(c,l),r=0;r<l;++r)t(u[r],this,n);return!0};function l(e,t,n,i){var a,o,l;if(s(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),l=o[t]),l===void 0)l=o[t]=n,++e._eventsCount;else if(typeof l==`function`?l=o[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),a=c(e),a>0&&l.length>a&&!l.warned){l.warned=!0;var u=Error(`Possible EventEmitter memory leak detected. `+l.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);u.name=`MaxListenersExceededWarning`,u.emitter=e,u.type=t,u.count=l.length,r(u)}return e}a.prototype.addListener=function(e,t){return l(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return l(this,e,t,!0)};function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=u.bind(r);return i.listener=n,r.wrapFn=i,i}a.prototype.once=function(e,t){return s(t),this.on(e,d(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,d(this,e,t)),this},a.prototype.removeListener=function(e,t){var n,r,i,a,o;if(s(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():te(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function f(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?ne(i):ee(i,i.length)}a.prototype.listeners=function(e){return f(this,e,!0)},a.prototype.rawListeners=function(e){return f(this,e,!1)},a.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):p.call(e,t)},a.prototype.listenerCount=p;function p(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]};function ee(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function te(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function ne(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function re(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}ae(e,t,a,{once:!0}),t!==`error`&&ie(e,i,{once:!0})})}function ie(e,t,n){typeof e.on==`function`&&ae(e,`error`,t,n)}function ae(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}return Ki.exports}var Yi=Ji(),Xi=!0,Zi=!0;function Qi(e,t,n){let r=e.match(t);return r&&r.length>=n&&parseFloat(r[n],10)}function $i(e,t,n){if(!e.RTCPeerConnection)return;if(!Object.getOwnPropertyDescriptor(EventTarget.prototype,`addEventListener`).writable){na(`Unable to polyfill events`);return}let r=e.RTCPeerConnection.prototype,i=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)return i.apply(this,arguments);let a=e=>{let t=n(e);t&&(r.handleEvent?r.handleEvent(t):r(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(r,a),i.apply(this,[e,a])};let a=r.removeEventListener;r.removeEventListener=function(e,n){if(e!==t||!this._eventMap||!this._eventMap[t]||!this._eventMap[t].has(n))return a.apply(this,arguments);let r=this._eventMap[t].get(n);return this._eventMap[t].delete(n),this._eventMap[t].size===0&&delete this._eventMap[t],Object.keys(this._eventMap).length===0&&delete this._eventMap,a.apply(this,[e,r])},Object.defineProperty(r,`on`+t,{get(){return this[`_on`+t]},set(e){this[`_on`+t]&&(this.removeEventListener(t,this[`_on`+t]),delete this[`_on`+t]),e&&this.addEventListener(t,this[`_on`+t]=e)},enumerable:!0,configurable:!0})}function ea(e){return typeof e==`boolean`?(Xi=e,e?`adapter.js logging disabled`:`adapter.js logging enabled`):Error(`Argument type: `+typeof e+`. Please use a boolean.`)}function ta(e){return typeof e==`boolean`?(Zi=!e,`adapter.js deprecation warnings `+(e?`disabled`:`enabled`)):Error(`Argument type: `+typeof e+`. Please use a boolean.`)}function na(){if(typeof window==`object`){if(Xi)return;typeof console<`u`&&typeof console.log==`function`&&console.log.apply(console,arguments)}}function ra(e,t){Zi&&console.warn(e+` is deprecated, please use `+t+` instead.`)}function ia(e){let t={browser:null,version:null};if(e===void 0||!e.navigator||!e.navigator.userAgent)return t.browser=`Not a browser.`,t;let n=e.navigator;if(n.userAgentData&&n.userAgentData.brands){let e=n.userAgentData.brands.find(e=>e.brand===`Chromium`);if(e){let t=parseInt(e.version,10);if(t>=90)return{browser:`chrome`,version:t}}}if(n.mozGetUserMedia)t.browser=`firefox`,t.version=parseInt(Qi(n.userAgent,/Firefox\/(\d+)\./,1));else if(n.webkitGetUserMedia||e.isSecureContext===!1&&e.webkitRTCPeerConnection)t.browser=`chrome`,t.version=parseInt(Qi(n.userAgent,/Chrom(e|ium)\/(\d+)\./,2))||null;else if(e.RTCPeerConnection&&n.userAgent.match(/AppleWebKit\/(\d+)\./))t.browser=`safari`,t.version=parseInt(Qi(n.userAgent,/AppleWebKit\/(\d+)\./,1)),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&`currentDirection`in e.RTCRtpTransceiver.prototype,t._safariVersion=Qi(n.userAgent,/Version\/(\d+(\.?\d+))/,1);else return t.browser=`Not a supported browser.`,t;return t}function aa(e){return Object.prototype.toString.call(e)===`[object Object]`}function oa(e){return aa(e)?Object.keys(e).reduce(function(t,n){let r=aa(e[n]),i=r?oa(e[n]):e[n],a=r&&!Object.keys(i).length;return i===void 0||a?t:Object.assign(t,{[n]:i})},{}):e}function sa(e,t,n){t&&!n.has(t.id)&&(n.set(t.id,t),Object.keys(t).forEach(r=>{r.endsWith(`Id`)?sa(e,e.get(t[r]),n):r.endsWith(`Ids`)&&t[r].forEach(t=>{sa(e,e.get(t),n)})}))}function ca(e,t,n){let r=n?`outbound-rtp`:`inbound-rtp`,i=new Map;if(t===null)return i;let a=[];return e.forEach(e=>{e.type===`track`&&e.trackIdentifier===t.id&&a.push(e)}),a.forEach(t=>{e.forEach(n=>{n.type===r&&n.trackId===t.id&&sa(e,n,i)})}),i}var la=na;function ua(e,t){if(t.version>=64)return;let n=e&&e.navigator;if(!n.mediaDevices)return;let r=function(e){if(typeof e!=`object`||e.mandatory||e.optional)return e;let t={};return Object.keys(e).forEach(n=>{if(n===`require`||n===`advanced`||n===`mediaSource`)return;let r=typeof e[n]==`object`?e[n]:{ideal:e[n]};r.exact!==void 0&&typeof r.exact==`number`&&(r.min=r.max=r.exact);let i=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):t===`deviceId`?`sourceId`:t};if(r.ideal!==void 0){t.optional=t.optional||[];let e={};typeof r.ideal==`number`?(e[i(`min`,n)]=r.ideal,t.optional.push(e),e={},e[i(`max`,n)]=r.ideal,t.optional.push(e)):(e[i(``,n)]=r.ideal,t.optional.push(e))}r.exact!==void 0&&typeof r.exact!=`number`?(t.mandatory=t.mandatory||{},t.mandatory[i(``,n)]=r.exact):[`min`,`max`].forEach(e=>{r[e]!==void 0&&(t.mandatory=t.mandatory||{},t.mandatory[i(e,n)]=r[e])})}),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},i=function(e,i){if(t.version>=61)return i(e);if(e=JSON.parse(JSON.stringify(e)),e&&typeof e.audio==`object`){let t=function(e,t,n){t in e&&!(n in e)&&(e[n]=e[t],delete e[t])};e=JSON.parse(JSON.stringify(e)),t(e.audio,`autoGainControl`,`googAutoGainControl`),t(e.audio,`noiseSuppression`,`googNoiseSuppression`),e.audio=r(e.audio)}if(e&&typeof e.video==`object`){let a=e.video.facingMode;a&&=typeof a==`object`?a:{ideal:a};let o=t.version<66;if(a&&(a.exact===`user`||a.exact===`environment`||a.ideal===`user`||a.ideal===`environment`)&&!(n.mediaDevices.getSupportedConstraints&&n.mediaDevices.getSupportedConstraints().facingMode&&!o)){delete e.video.facingMode;let t;if(a.exact===`environment`||a.ideal===`environment`?t=[`back`,`rear`]:(a.exact===`user`||a.ideal===`user`)&&(t=[`front`]),t)return n.mediaDevices.enumerateDevices().then(n=>{n=n.filter(e=>e.kind===`videoinput`);let o=n.find(e=>t.some(t=>e.label.toLowerCase().includes(t)));return!o&&n.length&&t.includes(`back`)&&(o=n[n.length-1]),o&&(e.video.deviceId=a.exact?{exact:o.deviceId}:{ideal:o.deviceId}),e.video=r(e.video),la(`chrome: `+JSON.stringify(e)),i(e)})}e.video=r(e.video)}return la(`chrome: `+JSON.stringify(e)),i(e)},a=function(e){return t.version>=64?e:{name:{PermissionDeniedError:`NotAllowedError`,PermissionDismissedError:`NotAllowedError`,InvalidStateError:`NotAllowedError`,DevicesNotFoundError:`NotFoundError`,ConstraintNotSatisfiedError:`OverconstrainedError`,TrackStartError:`NotReadableError`,MediaDeviceFailedDueToShutdown:`NotAllowedError`,MediaDeviceKillSwitchOn:`NotAllowedError`,TabCaptureError:`AbortError`,ScreenCaptureError:`AbortError`,DeviceCaptureError:`AbortError`}[e.name]||e.name,message:e.message,constraint:e.constraint||e.constraintName,toString(){return this.name+(this.message&&`: `)+this.message}}};if(n.getUserMedia=function(e,t,r){i(e,e=>{n.webkitGetUserMedia(e,t,e=>{r&&r(a(e))})})}.bind(n),n.mediaDevices.getUserMedia){let e=n.mediaDevices.getUserMedia.bind(n.mediaDevices);n.mediaDevices.getUserMedia=function(t){return i(t,t=>e(t).then(e=>{if(t.audio&&!e.getAudioTracks().length||t.video&&!e.getVideoTracks().length)throw e.getTracks().forEach(e=>{e.stop()}),new DOMException(``,`NotFoundError`);return e},e=>Promise.reject(a(e))))}}}function da(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function fa(e,t){if(!(t.version>102)){if(typeof e==`object`&&e.RTCPeerConnection&&!(`ontrack`in e.RTCPeerConnection.prototype)){Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(e){this._ontrack&&this.removeEventListener(`track`,this._ontrack),this.addEventListener(`track`,this._ontrack=e)},enumerable:!0,configurable:!0});let t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener(`addtrack`,n=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(e=>e.track&&e.track.id===n.track.id):{track:n.track};let i=new Event(`track`);i.track=n.track,i.receiver=r,i.transceiver={receiver:r},i.streams=[t.stream],this.dispatchEvent(i)}),t.stream.getTracks().forEach(n=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(e=>e.track&&e.track.id===n.id):{track:n};let i=new Event(`track`);i.track=n,i.receiver=r,i.transceiver={receiver:r},i.streams=[t.stream],this.dispatchEvent(i)})},this.addEventListener(`addstream`,this._ontrackpoly)),t.apply(this,arguments)}}else $i(e,`track`,e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}}function pa(e){if(typeof e==`object`&&e.RTCPeerConnection&&!(`getSenders`in e.RTCPeerConnection.prototype)&&`createDTMFSender`in e.RTCPeerConnection.prototype){let t=function(e,t){return{track:t,get dtmf(){return this._dtmf===void 0&&(this._dtmf=t.kind===`audio`?e.createDTMFSender(t):null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};let n=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,r){let i=n.apply(this,arguments);return i||(i=t(this,e),this._senders.push(i)),i};let r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){r.apply(this,arguments);let t=this._senders.indexOf(e);t!==-1&&this._senders.splice(t,1)}}let n=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],n.apply(this,[e]),e.getTracks().forEach(e=>{this._senders.push(t(this,e))})};let r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],r.apply(this,[e]),e.getTracks().forEach(e=>{let t=this._senders.find(t=>t.track===e);t&&this._senders.splice(this._senders.indexOf(t),1)})}}else if(typeof e==`object`&&e.RTCPeerConnection&&`getSenders`in e.RTCPeerConnection.prototype&&`createDTMFSender`in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!(`dtmf`in e.RTCRtpSender.prototype)){let t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this._dtmf=this.track.kind===`audio`?this._pc.createDTMFSender(this.track):null),this._dtmf}})}}function ma(e,t){if(t.version>=67||!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!(`getStats`in e.RTCRtpSender.prototype)){let t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e});let n=e.RTCPeerConnection.prototype.addTrack;n&&(e.RTCPeerConnection.prototype.addTrack=function(){let e=n.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){let e=this;return this._pc.getStats().then(t=>ca(t,e.track,!0))}}if(!(`getStats`in e.RTCRtpReceiver.prototype)){let t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e}),$i(e,`track`,e=>(e.receiver._pc=e.srcElement,e)),e.RTCRtpReceiver.prototype.getStats=function(){let e=this;return this._pc.getStats().then(t=>ca(t,e.track,!1))}}if(!(`getStats`in e.RTCRtpSender.prototype&&`getStats`in e.RTCRtpReceiver.prototype))return;let n=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){let e=arguments[0],t,n,r;return this.getSenders().forEach(n=>{n.track===e&&(t?r=!0:t=n)}),this.getReceivers().forEach(t=>(t.track===e&&(n?r=!0:n=t),t.track===e)),r||t&&n?Promise.reject(new DOMException(`There are more than one sender or receiver for the track.`,`InvalidAccessError`)):t?t.getStats():n?n.getStats():Promise.reject(new DOMException(`There is no sender or receiver for the track.`,`InvalidAccessError`))}return n.apply(this,arguments)}}function ha(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(e=>this._shimmedLocalStreams[e][0])};let t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,n){if(!n)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};let r=t.apply(this,arguments);return this._shimmedLocalStreams[n.id]?this._shimmedLocalStreams[n.id].indexOf(r)===-1&&this._shimmedLocalStreams[n.id].push(r):this._shimmedLocalStreams[n.id]=[n,r],r};let n=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._shimmedLocalStreams=this._shimmedLocalStreams||{},e.getTracks().forEach(e=>{if(this.getSenders().find(t=>t.track===e))throw new DOMException(`Track already exists.`,`InvalidAccessError`)});let t=this.getSenders();n.apply(this,arguments);let r=this.getSenders().filter(e=>t.indexOf(e)===-1);this._shimmedLocalStreams[e.id]=[e].concat(r)};let r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],r.apply(this,arguments)};let i=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach(t=>{let n=this._shimmedLocalStreams[t].indexOf(e);n!==-1&&this._shimmedLocalStreams[t].splice(n,1),this._shimmedLocalStreams[t].length===1&&delete this._shimmedLocalStreams[t]}),i.apply(this,arguments)}}function ga(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return ha(e);let n=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){let e=n.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map(e=>this._reverseStreams[e.id])};let r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(t){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},t.getTracks().forEach(e=>{if(this.getSenders().find(t=>t.track===e))throw new DOMException(`Track already exists.`,`InvalidAccessError`)}),!this._reverseStreams[t.id]){let n=new e.MediaStream(t.getTracks());this._streams[t.id]=n,this._reverseStreams[n.id]=t,t=n}r.apply(this,[t])};let i=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[e.id]||e]),delete this._reverseStreams[this._streams[e.id]?this._streams[e.id].id:e.id],delete this._streams[e.id]},e.RTCPeerConnection.prototype.addTrack=function(t,n){if(this.signalingState===`closed`)throw new DOMException(`The RTCPeerConnection's signalingState is 'closed'.`,`InvalidStateError`);let r=[].slice.call(arguments,1);if(r.length!==1||!r[0].getTracks().find(e=>e===t))throw new DOMException(`The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.`,`NotSupportedError`);if(this.getSenders().find(e=>e.track===t))throw new DOMException(`Track already exists.`,`InvalidAccessError`);this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};let i=this._streams[n.id];if(i)i.addTrack(t),Promise.resolve().then(()=>{this.dispatchEvent(new Event(`negotiationneeded`))});else{let r=new e.MediaStream([t]);this._streams[n.id]=r,this._reverseStreams[r.id]=n,this.addStream(r)}return this.getSenders().find(e=>e.track===t)};function a(e,t){let n=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(t=>{let r=e._reverseStreams[t],i=e._streams[r.id];n=n.replace(new RegExp(i.id,`g`),r.id)}),new RTCSessionDescription({type:t.type,sdp:n})}function o(e,t){let n=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(t=>{let r=e._reverseStreams[t],i=e._streams[r.id];n=n.replace(new RegExp(r.id,`g`),i.id)}),new RTCSessionDescription({type:t.type,sdp:n})}[`createOffer`,`createAnswer`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){let e=arguments;return arguments.length&&typeof arguments[0]==`function`?n.apply(this,[t=>{let n=a(this,t);e[0].apply(null,[n])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):n.apply(this,arguments).then(e=>a(this,e))}};e.RTCPeerConnection.prototype[t]=r[t]});let s=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type||(arguments[0]=o(this,arguments[0])),s.apply(this,arguments)};let c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,`localDescription`);Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){let e=c.get.apply(this);return e.type===``?e:a(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if(this.signalingState===`closed`)throw new DOMException(`The RTCPeerConnection's signalingState is 'closed'.`,`InvalidStateError`);if(!e._pc)throw new DOMException(`Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.`,`TypeError`);if(e._pc!==this)throw new DOMException(`Sender was not created by this connection.`,`InvalidAccessError`);this._streams=this._streams||{};let t;Object.keys(this._streams).forEach(n=>{this._streams[n].getTracks().find(t=>e.track===t)&&(t=this._streams[n])}),t&&(t.getTracks().length===1?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event(`negotiationneeded`)))}}function _a(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&[`setLocalDescription`,`setRemoteDescription`,`addIceCandidate`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new(t===`addIceCandidate`?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]})}function va(e,t){t.version>102||$i(e,`negotiationneeded`,e=>{let n=e.target;if(!((t.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics===`plan-b`)&&n.signalingState!==`stable`))return e})}var ya=Object.freeze({__proto__:null,fixNegotiationNeeded:va,shimAddTrackRemoveTrack:ga,shimAddTrackRemoveTrackWithNative:ha,shimGetSendersWithDtmf:pa,shimGetUserMedia:ua,shimMediaStream:da,shimOnTrack:fa,shimPeerConnection:_a,shimSenderReceiverGetStats:ma});function ba(e,t){let n=e&&e.navigator;if(!n.mediaDevices)return;let r=e&&e.MediaStreamTrack;if(n.getUserMedia=function(e,t,r){ra(`navigator.getUserMedia`,`navigator.mediaDevices.getUserMedia`),n.mediaDevices.getUserMedia(e).then(t,r)},!(t.version>55&&`autoGainControl`in n.mediaDevices.getSupportedConstraints())){let e=function(e,t,n){t in e&&!(n in e)&&(e[n]=e[t],delete e[t])},t=n.mediaDevices.getUserMedia.bind(n.mediaDevices);if(n.mediaDevices.getUserMedia=function(n){return typeof n==`object`&&typeof n.audio==`object`&&(n=JSON.parse(JSON.stringify(n)),e(n.audio,`autoGainControl`,`mozAutoGainControl`),e(n.audio,`noiseSuppression`,`mozNoiseSuppression`)),t(n)},r&&r.prototype.getSettings){let t=r.prototype.getSettings;r.prototype.getSettings=function(){let n=t.apply(this,arguments);return e(n,`mozAutoGainControl`,`autoGainControl`),e(n,`mozNoiseSuppression`,`noiseSuppression`),n}}if(r&&r.prototype.applyConstraints){let t=r.prototype.applyConstraints;r.prototype.applyConstraints=function(n){return this.kind===`audio`&&typeof n==`object`&&(n=JSON.parse(JSON.stringify(n)),e(n,`autoGainControl`,`mozAutoGainControl`),e(n,`noiseSuppression`,`mozNoiseSuppression`)),t.apply(this,[n])}}}}function xa(e,t){e.navigator.mediaDevices&&(e.navigator.mediaDevices&&`getDisplayMedia`in e.navigator.mediaDevices||(e.navigator.mediaDevices.getDisplayMedia=function(n){if(!(n&&n.video)){let e=new DOMException(`getDisplayMedia without video constraints is undefined`);return e.name=`NotFoundError`,e.code=8,Promise.reject(e)}return n.video===!0?n.video={mediaSource:t}:n.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(n)}))}function Sa(e){typeof e==`object`&&e.RTCTrackEvent&&`receiver`in e.RTCTrackEvent.prototype&&!(`transceiver`in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Ca(e,t){typeof e==`object`&&(e.RTCPeerConnection||e.mozRTCPeerConnection)&&(!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&[`setLocalDescription`,`setRemoteDescription`,`addIceCandidate`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new(t===`addIceCandidate`?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]}))}function wa(e,t){if(typeof e!=`object`||!(e.RTCPeerConnection||e.mozRTCPeerConnection)||t.version>=151)return;let n={inboundrtp:`inbound-rtp`,outboundrtp:`outbound-rtp`,candidatepair:`candidate-pair`,localcandidate:`local-candidate`,remotecandidate:`remote-candidate`},r=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){let e=Array.prototype.slice.call(arguments),i=e[0],a=e[1],o=e[2];return this.signalingState===`closed`?Promise.resolve(new Map):r.apply(this,[i||null]).then(e=>{if(t.version<53&&!a)try{e.forEach(e=>{e.type=n[e.type]||e.type})}catch(t){if(t.name!==`TypeError`)throw t;e.forEach((t,r)=>{e.set(r,Object.assign({},t,{type:n[t.type]||t.type}))})}return e}).then(a,o)}}function Ta(e){if(!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&`getStats`in e.RTCRtpSender.prototype)return;let t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e});let n=e.RTCPeerConnection.prototype.addTrack;n&&(e.RTCPeerConnection.prototype.addTrack=function(){let e=n.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function Ea(e){if(!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&`getStats`in e.RTCRtpReceiver.prototype)return;let t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e}),$i(e,`track`,e=>(e.receiver._pc=e.srcElement,e)),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function Da(e){!e.RTCPeerConnection||`removeStream`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){ra(`removeStream`,`removeTrack`),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function Oa(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function ka(e,t){if(!(typeof e==`object`&&e.RTCPeerConnection)||t.version>=110)return;let n=e.RTCPeerConnection.prototype.addTransceiver;n&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];let e=arguments[1]&&arguments[1].sendEncodings;e===void 0&&(e=[]),e=[...e];let t=e.length>0;t&&e.forEach(e=>{if(`rid`in e&&!/^[a-z0-9]{0,16}$/i.test(e.rid))throw TypeError(`Invalid RID value provided.`);if(`scaleResolutionDownBy`in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw RangeError(`scale_resolution_down_by must be >= 1.0`);if(`maxFramerate`in e&&!(parseFloat(e.maxFramerate)>=0))throw RangeError(`max_framerate must be >= 0.0`)});let r=n.apply(this,arguments);if(t){let t=r.sender,n=t.getParameters();(!(`encodings`in n)||n.encodings.length===1&&Object.keys(n.encodings[0]).length===0)&&(n.encodings=e,t.sendEncodings=e,this.setParametersPromises.push(t.setParameters(n).then(()=>{delete t.sendEncodings}).catch(()=>{delete t.sendEncodings})))}return r})}function Aa(e,t){if(!(typeof e==`object`&&e.RTCRtpSender)||t.version>=110)return;let n=e.RTCRtpSender.prototype.getParameters;n&&(e.RTCRtpSender.prototype.getParameters=function(){let e=n.apply(this,arguments);return`encodings`in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function ja(e,t){if(!(typeof e==`object`&&e.RTCPeerConnection)||t.version>=110)return;let n=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>n.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):n.apply(this,arguments)}}function Ma(e,t){if(!(typeof e==`object`&&e.RTCPeerConnection)||t.version>=110)return;let n=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>n.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):n.apply(this,arguments)}}var Na=Object.freeze({__proto__:null,shimAddTransceiver:ka,shimCreateAnswer:Ma,shimCreateOffer:ja,shimGetDisplayMedia:xa,shimGetParameters:Aa,shimGetStats:wa,shimGetUserMedia:ba,shimOnTrack:Sa,shimPeerConnection:Ca,shimRTCDataChannel:Oa,shimReceiverGetStats:Ea,shimRemoveStream:Da,shimSenderGetStats:Ta});function Pa(e){if(typeof e==`object`&&e.RTCPeerConnection){if(`getLocalStreams`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||=[],this._localStreams}),!(`addStream`in e.RTCPeerConnection.prototype)){let t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||=[],this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach(n=>t.call(this,n,e)),e.getVideoTracks().forEach(n=>t.call(this,n,e))},e.RTCPeerConnection.prototype.addTrack=function(e){var n=[...arguments].slice(1);return n&&n.forEach(e=>{this._localStreams?this._localStreams.includes(e)||this._localStreams.push(e):this._localStreams=[e]}),t.apply(this,arguments)}}`removeStream`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||=[];let t=this._localStreams.indexOf(e);if(t===-1)return;this._localStreams.splice(t,1);let n=e.getTracks();this.getSenders().forEach(e=>{n.includes(e.track)&&this.removeTrack(e)})})}}function Fa(e){if(typeof e==`object`&&e.RTCPeerConnection&&(`getRemoteStreams`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!(`onaddstream`in e.RTCPeerConnection.prototype))){Object.defineProperty(e.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(e){this._onaddstream&&(this.removeEventListener(`addstream`,this._onaddstream),this.removeEventListener(`track`,this._onaddstreampoly)),this.addEventListener(`addstream`,this._onaddstream=e),this.addEventListener(`track`,this._onaddstreampoly=e=>{e.streams.forEach(e=>{if(this._remoteStreams||=[],this._remoteStreams.includes(e))return;this._remoteStreams.push(e);let t=new Event(`addstream`);t.stream=e,this.dispatchEvent(t)})})}});let t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){let e=this;return this._onaddstreampoly||this.addEventListener(`track`,this._onaddstreampoly=function(t){t.streams.forEach(t=>{if(e._remoteStreams||=[],e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);let n=new Event(`addstream`);n.stream=t,e.dispatchEvent(n)})}),t.apply(e,arguments)}}}function Ia(e){if(typeof e!=`object`||!e.RTCPeerConnection)return;let t=e.RTCPeerConnection.prototype,n=t.createOffer,r=t.createAnswer,i=t.setLocalDescription,a=t.setRemoteDescription,o=t.addIceCandidate;t.createOffer=function(e,t){let r=arguments.length>=2?arguments[2]:arguments[0],i=n.apply(this,[r]);return t?(i.then(e,t),Promise.resolve()):i},t.createAnswer=function(e,t){let n=arguments.length>=2?arguments[2]:arguments[0],i=r.apply(this,[n]);return t?(i.then(e,t),Promise.resolve()):i};let s=function(e,t,n){let r=i.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r};t.setLocalDescription=s,s=function(e,t,n){let r=a.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},t.setRemoteDescription=s,s=function(e,t,n){let r=o.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},t.addIceCandidate=s}function La(e){let t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){let e=t.mediaDevices,n=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>n(Ra(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,n,r){t.mediaDevices.getUserMedia(e).then(n,r)}.bind(t))}function Ra(e){return e&&e.video!==void 0?Object.assign({},e,{video:oa(e.video)}):e}function za(e){if(!e.RTCPeerConnection)return;let t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,n){if(e&&e.iceServers){let t=[];for(let n=0;n<e.iceServers.length;n++){let r=e.iceServers[n];r.urls===void 0&&r.url?(ra(`RTCIceServer.url`,`RTCIceServer.urls`),r=JSON.parse(JSON.stringify(r)),r.urls=r.url,delete r.url,t.push(r)):t.push(e.iceServers[n])}e.iceServers=t}return new t(e,n)},e.RTCPeerConnection.prototype=t.prototype,`generateCertificate`in t&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get(){return t.generateCertificate}})}function Ba(e){typeof e==`object`&&e.RTCTrackEvent&&`receiver`in e.RTCTrackEvent.prototype&&!(`transceiver`in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Va(e){let t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){e.offerToReceiveAudio!==void 0&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);let t=this.getTransceivers().find(e=>e.receiver.track.kind===`audio`);e.offerToReceiveAudio===!1&&t?t.direction===`sendrecv`?t.setDirection?t.setDirection(`sendonly`):t.direction=`sendonly`:t.direction===`recvonly`&&(t.setDirection?t.setDirection(`inactive`):t.direction=`inactive`):e.offerToReceiveAudio===!0&&!t&&this.addTransceiver(`audio`,{direction:`recvonly`}),e.offerToReceiveVideo!==void 0&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);let n=this.getTransceivers().find(e=>e.receiver.track.kind===`video`);e.offerToReceiveVideo===!1&&n?n.direction===`sendrecv`?n.setDirection?n.setDirection(`sendonly`):n.direction=`sendonly`:n.direction===`recvonly`&&(n.setDirection?n.setDirection(`inactive`):n.direction=`inactive`):e.offerToReceiveVideo===!0&&!n&&this.addTransceiver(`video`,{direction:`recvonly`})}return t.apply(this,arguments)}}function Ha(e){typeof e!=`object`||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var Ua=Object.freeze({__proto__:null,shimAudioContext:Ha,shimCallbacksAPI:Ia,shimConstraints:Ra,shimCreateOfferLegacy:Va,shimGetUserMedia:La,shimLocalStreamsAPI:Pa,shimRTCIceServerUrls:za,shimRemoteStreamsAPI:Fa,shimTrackEventTransceiver:Ba}),Wa={exports:{}},Ga;function Ka(){return Ga||(Ga=1,(function(e){let t={};t.generateIdentifier=function(){return Math.random().toString(36).substring(2,12)},t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split(`
|
|
4
|
+
`).map(e=>e.trim())},t.splitSections=function(e){return e.split(`
|
|
5
|
+
m=`).map((e,t)=>(t>0?`m=`+e:e).trim()+`\r
|
|
6
|
+
`)},t.getDescription=function(e){let n=t.splitSections(e);return n&&n[0]},t.getMediaSections=function(e){let n=t.splitSections(e);return n.shift(),n},t.matchPrefix=function(e,n){return t.splitLines(e).filter(e=>e.indexOf(n)===0)},t.parseCandidate=function(e){let t;t=e.indexOf(`a=candidate:`)===0?e.substring(12).split(` `):e.substring(10).split(` `);let n={foundation:t[0],component:{1:`rtp`,2:`rtcp`}[t[1]]||t[1],protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]};for(let e=8;e<t.length;e+=2)switch(t[e]){case`raddr`:n.relatedAddress=t[e+1];break;case`rport`:n.relatedPort=parseInt(t[e+1],10);break;case`tcptype`:n.tcpType=t[e+1];break;case`ufrag`:n.ufrag=t[e+1],n.usernameFragment=t[e+1];break;default:n[t[e]]===void 0&&(n[t[e]]=t[e+1])}return n},t.writeCandidate=function(e){let t=[];t.push(e.foundation);let n=e.component;n===`rtp`?t.push(1):n===`rtcp`?t.push(2):t.push(n),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);let r=e.type;return t.push(`typ`),t.push(r),r!==`host`&&e.relatedAddress&&e.relatedPort!==void 0&&(t.push(`raddr`),t.push(e.relatedAddress),t.push(`rport`),t.push(e.relatedPort)),e.tcpType&&e.protocol.toLowerCase()===`tcp`&&(t.push(`tcptype`),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push(`ufrag`),t.push(e.usernameFragment||e.ufrag)),`candidate:`+t.join(` `)},t.parseIceOptions=function(e){return e.substring(14).split(` `)},t.parseRtpMap=function(e){let t=e.substring(9).split(` `),n={payloadType:parseInt(t.shift(),10)};return t=t[0].split(`/`),n.name=t[0],n.clockRate=parseInt(t[1],10),n.channels=t.length===3?parseInt(t[2],10):1,n.numChannels=n.channels,n},t.writeRtpMap=function(e){let t=e.payloadType;e.preferredPayloadType!==void 0&&(t=e.preferredPayloadType);let n=e.channels||e.numChannels||1;return`a=rtpmap:`+t+` `+e.name+`/`+e.clockRate+(n===1?``:`/`+n)+`\r
|
|
7
|
+
`},t.parseExtmap=function(e){let t=e.substring(9).split(` `);return{id:parseInt(t[0],10),direction:t[0].indexOf(`/`)>0?t[0].split(`/`)[1]:`sendrecv`,uri:t[1],attributes:t.slice(2).join(` `)}},t.writeExtmap=function(e){return`a=extmap:`+(e.id||e.preferredId)+(e.direction&&e.direction!==`sendrecv`?`/`+e.direction:``)+` `+e.uri+(e.attributes?` `+e.attributes:``)+`\r
|
|
8
|
+
`},t.parseFmtp=function(e){let t={},n,r=e.substring(e.indexOf(` `)+1).split(`;`);for(let e=0;e<r.length;e++)n=r[e].trim().split(`=`),t[n[0].trim()]=n[1];return t},t.writeFmtp=function(e){let t=``,n=e.payloadType;if(e.preferredPayloadType!==void 0&&(n=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){let r=[];Object.keys(e.parameters).forEach(t=>{e.parameters[t]===void 0?r.push(t):r.push(t+`=`+e.parameters[t])}),t+=`a=fmtp:`+n+` `+r.join(`;`)+`\r
|
|
9
|
+
`}return t},t.parseRtcpFb=function(e){let t=e.substring(e.indexOf(` `)+1).split(` `);return{type:t.shift(),parameter:t.join(` `)}},t.writeRtcpFb=function(e){let t=``,n=e.payloadType;return e.preferredPayloadType!==void 0&&(n=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach(e=>{t+=`a=rtcp-fb:`+n+` `+e.type+(e.parameter&&e.parameter.length?` `+e.parameter:``)+`\r
|
|
10
|
+
`}),t},t.parseSsrcMedia=function(e){let t=e.indexOf(` `),n={ssrc:parseInt(e.substring(7,t),10)},r=e.indexOf(`:`,t);return r>-1?(n.attribute=e.substring(t+1,r),n.value=e.substring(r+1)):n.attribute=e.substring(t+1),n},t.parseSsrcGroup=function(e){let t=e.substring(13).split(` `);return{semantics:t.shift(),ssrcs:t.map(e=>parseInt(e,10))}},t.getMid=function(e){let n=t.matchPrefix(e,`a=mid:`)[0];if(n)return n.substring(6)},t.parseFingerprint=function(e){let t=e.substring(14).split(` `);return{algorithm:t[0].toLowerCase(),value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,n){return{role:`auto`,fingerprints:t.matchPrefix(e+n,`a=fingerprint:`).map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let n=`a=setup:`+t+`\r
|
|
11
|
+
`;return e.fingerprints.forEach(e=>{n+=`a=fingerprint:`+e.algorithm+` `+e.value+`\r
|
|
12
|
+
`}),n},t.parseCryptoLine=function(e){let t=e.substring(9).split(` `);return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return`a=crypto:`+e.tag+` `+e.cryptoSuite+` `+(typeof e.keyParams==`object`?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?` `+e.sessionParams.join(` `):``)+`\r
|
|
13
|
+
`},t.parseCryptoKeyParams=function(e){if(e.indexOf(`inline:`)!==0)return null;let t=e.substring(7).split(`|`);return{keyMethod:`inline`,keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(`:`)[0]:void 0,mkiLength:t[2]?t[2].split(`:`)[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+`:`+e.keySalt+(e.lifeTime?`|`+e.lifeTime:``)+(e.mkiValue&&e.mkiLength?`|`+e.mkiValue+`:`+e.mkiLength:``)},t.getCryptoParameters=function(e,n){return t.matchPrefix(e+n,`a=crypto:`).map(t.parseCryptoLine)},t.getIceParameters=function(e,n){let r=t.matchPrefix(e+n,`a=ice-ufrag:`)[0],i=t.matchPrefix(e+n,`a=ice-pwd:`)[0];return r&&i?{usernameFragment:r.substring(12),password:i.substring(10)}:null},t.writeIceParameters=function(e){let t=`a=ice-ufrag:`+e.usernameFragment+`\r
|
|
14
|
+
a=ice-pwd:`+e.password+`\r
|
|
15
|
+
`;return e.iceLite&&(t+=`a=ice-lite\r
|
|
16
|
+
`),t},t.parseRtpParameters=function(e){let n={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=t.splitLines(e)[0].split(` `);n.profile=r[2];for(let i=3;i<r.length;i++){let a=r[i],o=t.matchPrefix(e,`a=rtpmap:`+a+` `)[0];if(o){let r=t.parseRtpMap(o),i=t.matchPrefix(e,`a=fmtp:`+a+` `);switch(r.parameters=i.length?t.parseFmtp(i[0]):{},r.rtcpFeedback=t.matchPrefix(e,`a=rtcp-fb:`+a+` `).map(t.parseRtcpFb),n.codecs.push(r),r.name.toUpperCase()){case`RED`:case`ULPFEC`:n.fecMechanisms.push(r.name.toUpperCase())}}}t.matchPrefix(e,`a=extmap:`).forEach(e=>{n.headerExtensions.push(t.parseExtmap(e))});let i=t.matchPrefix(e,`a=rtcp-fb:* `).map(t.parseRtcpFb);return n.codecs.forEach(e=>{i.forEach(t=>{e.rtcpFeedback.find(e=>e.type===t.type&&e.parameter===t.parameter)||e.rtcpFeedback.push(t)})}),n},t.writeRtpDescription=function(e,n){let r=``;r+=`m=`+e+` `,r+=n.codecs.length>0?`9`:`0`,r+=` `+(n.profile||`UDP/TLS/RTP/SAVPF`)+` `,r+=n.codecs.map(e=>e.preferredPayloadType===void 0?e.payloadType:e.preferredPayloadType).join(` `)+`\r
|
|
17
|
+
`,r+=`c=IN IP4 0.0.0.0\r
|
|
18
|
+
`,r+=`a=rtcp:9 IN IP4 0.0.0.0\r
|
|
19
|
+
`,n.codecs.forEach(e=>{r+=t.writeRtpMap(e),r+=t.writeFmtp(e),r+=t.writeRtcpFb(e)});let i=0;return n.codecs.forEach(e=>{e.maxptime>i&&(i=e.maxptime)}),i>0&&(r+=`a=maxptime:`+i+`\r
|
|
20
|
+
`),n.headerExtensions&&n.headerExtensions.forEach(e=>{r+=t.writeExtmap(e)}),r},t.parseRtpEncodingParameters=function(e){let n=[],r=t.parseRtpParameters(e),i=r.fecMechanisms.indexOf(`RED`)!==-1,a=r.fecMechanisms.indexOf(`ULPFEC`)!==-1,o=t.matchPrefix(e,`a=ssrc:`).map(e=>t.parseSsrcMedia(e)).filter(e=>e.attribute===`cname`),s=o.length>0&&o[0].ssrc,c,l=t.matchPrefix(e,`a=ssrc-group:FID`).map(e=>e.substring(17).split(` `).map(e=>parseInt(e,10)));l.length>0&&l[0].length>1&&l[0][0]===s&&(c=l[0][1]),r.codecs.forEach(e=>{if(e.name.toUpperCase()===`RTX`&&e.parameters.apt){let t={ssrc:s,codecPayloadType:parseInt(e.parameters.apt,10)};s&&c&&(t.rtx={ssrc:c}),n.push(t),i&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:s,mechanism:a?`red+ulpfec`:`red`},n.push(t))}}),n.length===0&&s&&n.push({ssrc:s});let u=t.matchPrefix(e,`b=`);return u.length&&(u=u[0].indexOf(`b=TIAS:`)===0?parseInt(u[0].substring(7),10):u[0].indexOf(`b=AS:`)===0?parseInt(u[0].substring(5),10)*1e3*.95-16e3:void 0,n.forEach(e=>{e.maxBitrate=u})),n},t.parseRtcpParameters=function(e){let n={},r=t.matchPrefix(e,`a=ssrc:`).map(e=>t.parseSsrcMedia(e)).filter(e=>e.attribute===`cname`)[0];r&&(n.cname=r.value,n.ssrc=r.ssrc);let i=t.matchPrefix(e,`a=rtcp-rsize`);return n.reducedSize=i.length>0,n.compound=i.length===0,n.mux=t.matchPrefix(e,`a=rtcp-mux`).length>0,n},t.writeRtcpParameters=function(e){let t=``;return e.reducedSize&&(t+=`a=rtcp-rsize\r
|
|
21
|
+
`),e.mux&&(t+=`a=rtcp-mux\r
|
|
22
|
+
`),e.ssrc!==void 0&&e.cname&&(t+=`a=ssrc:`+e.ssrc+` cname:`+e.cname+`\r
|
|
23
|
+
`),t},t.parseMsid=function(e){let n,r=t.matchPrefix(e,`a=msid:`);if(r.length===1)return n=r[0].substring(7).split(` `),{stream:n[0],track:n[1]};let i=t.matchPrefix(e,`a=ssrc:`).map(e=>t.parseSsrcMedia(e)).filter(e=>e.attribute===`msid`);if(i.length>0)return n=i[0].value.split(` `),{stream:n[0],track:n[1]}},t.parseSctpDescription=function(e){let n=t.parseMLine(e),r=t.matchPrefix(e,`a=max-message-size:`),i;r.length>0&&(i=parseInt(r[0].substring(19),10)),isNaN(i)&&(i=65536);let a=t.matchPrefix(e,`a=sctp-port:`);if(a.length>0)return{port:parseInt(a[0].substring(12),10),protocol:n.fmt,maxMessageSize:i};let o=t.matchPrefix(e,`a=sctpmap:`);if(o.length>0){let e=o[0].substring(10).split(` `);return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:i}}},t.writeSctpDescription=function(e,t){let n=[];return n=e.protocol===`DTLS/SCTP`?[`m=`+e.kind+` 9 `+e.protocol+` `+t.port+`\r
|
|
24
|
+
`,`c=IN IP4 0.0.0.0\r
|
|
25
|
+
`,`a=sctpmap:`+t.port+` `+t.protocol+` 65535\r
|
|
26
|
+
`]:[`m=`+e.kind+` 9 `+e.protocol+` `+t.protocol+`\r
|
|
27
|
+
`,`c=IN IP4 0.0.0.0\r
|
|
28
|
+
`,`a=sctp-port:`+t.port+`\r
|
|
29
|
+
`],t.maxMessageSize!==void 0&&n.push(`a=max-message-size:`+t.maxMessageSize+`\r
|
|
30
|
+
`),n.join(``)},t.generateSessionId=function(){return Math.random().toString().substr(2,22)},t.writeSessionBoilerplate=function(e,n,r){let i,a=n===void 0?2:n;return i=e||t.generateSessionId(),`v=0\r
|
|
31
|
+
o=`+(r||`thisisadapterortc`)+` `+i+` `+a+` IN IP4 127.0.0.1\r
|
|
32
|
+
s=-\r
|
|
33
|
+
t=0 0\r
|
|
34
|
+
`},t.getDirection=function(e,n){let r=t.splitLines(e);for(let e=0;e<r.length;e++)switch(r[e]){case`a=sendrecv`:case`a=sendonly`:case`a=recvonly`:case`a=inactive`:return r[e].substring(2)}return n?t.getDirection(n):`sendrecv`},t.getKind=function(e){return t.splitLines(e)[0].split(` `)[0].substring(2)},t.isRejected=function(e){return e.split(` `,2)[1]===`0`},t.parseMLine=function(e){let n=t.splitLines(e)[0].substring(2).split(` `);return{kind:n[0],port:parseInt(n[1],10),protocol:n[2],fmt:n.slice(3).join(` `)}},t.parseOLine=function(e){let n=t.matchPrefix(e,`o=`)[0].substring(2).split(` `);return{username:n[0],sessionId:n[1],sessionVersion:parseInt(n[2],10),netType:n[3],addressType:n[4],address:n[5]}},t.isValidSDP=function(e){if(typeof e!=`string`||e.length===0)return!1;let n=t.splitLines(e);for(let e=0;e<n.length;e++)if(n[e].length<2||n[e].charAt(1)!==`=`)return!1;return!0},e.exports=t})(Wa)),Wa.exports}var qa=Ka(),Ja=wi(qa),Ya=e({__proto__:null,default:Ja},[qa]);function Xa(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&`foundation`in e.RTCIceCandidate.prototype)return;let t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if(typeof e==`object`&&e.candidate&&e.candidate.indexOf(`a=`)===0&&(e=JSON.parse(JSON.stringify(e)),e.candidate=e.candidate.substring(2)),e.candidate&&e.candidate.length){let n=new t(e),r=Ja.parseCandidate(e.candidate);for(let e in r)e in n||Object.defineProperty(n,e,{value:r[e]});return n.toJSON=function(){return{candidate:n.candidate,sdpMid:n.sdpMid,sdpMLineIndex:n.sdpMLineIndex,usernameFragment:n.usernameFragment}},n}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,$i(e,`icecandidate`,t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:`false`}),t))}function Za(e){!e.RTCIceCandidate||e.RTCIceCandidate&&`relayProtocol`in e.RTCIceCandidate.prototype||$i(e,`icecandidate`,e=>{if(e.candidate){let t=Ja.parseCandidate(e.candidate.candidate);t.type===`relay`&&(e.candidate.relayProtocol={0:`tls`,1:`tcp`,2:`udp`}[t.priority>>24])}return e})}function Qa(e,t){if(!e.RTCPeerConnection||t.browser===`chrome`&&t.version>102||t.browser===`firefox`&&t.version>=113)return;`sctp`in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return this._sctp===void 0?null:this._sctp}});let n=function(e){if(!e||!e.sdp)return!1;let t=Ja.splitSections(e.sdp);return t.shift(),t.some(e=>{let t=Ja.parseMLine(e);return t&&t.kind===`application`&&t.protocol.indexOf(`SCTP`)!==-1})},r=function(e){let t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(t===null||t.length<2)return-1;let n=parseInt(t[1],10);return n===n?n:-1},i=function(e){let n=65536;return t.browser===`firefox`&&(n=t.version<57?e===-1?16384:2147483637:t.version<60?t.version===57?65535:65536:2147483637),n},a=function(e,n){let r=65536;t.browser===`firefox`&&t.version===57&&(r=65535);let i=Ja.matchPrefix(e.sdp,`a=max-message-size:`);return i.length>0?r=parseInt(i[0].substring(19),10):t.browser===`firefox`&&n!==-1&&(r=2147483637),r},o=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,t.browser===`chrome`&&t.version>=76&&this.getConfiguration().sdpSemantics===`plan-b`&&Object.defineProperty(this,"sctp",{get(){return this._sctp===void 0?null:this._sctp},enumerable:!0,configurable:!0}),n(arguments[0])){let e=r(arguments[0]),t=i(e),n=a(arguments[0],e),o;o=t===0&&n===0?1/0:t===0||n===0?Math.max(t,n):Math.min(t,n);let s={};Object.defineProperty(s,"maxMessageSize",{get(){return o}}),this._sctp=s}return o.apply(this,arguments)}}function $a(e,t){if(!(e.RTCPeerConnection&&`createDataChannel`in e.RTCPeerConnection.prototype)||t.browser===`chrome`&&t.version>=149||t.browser===`firefox`&&t.version>60)return;function n(e,t){let n=e.send;e.send=function(){let r=arguments[0],i=r.length||r.size||r.byteLength;if(e.readyState===`open`&&t.sctp&&i>t.sctp.maxMessageSize)throw TypeError(`Message too large (can send a maximum of `+t.sctp.maxMessageSize+` bytes)`);return n.apply(e,arguments)}}let r=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){let e=r.apply(this,arguments);return n(e,this),e},$i(e,`datachannel`,e=>(n(e.channel,e.target),e))}function eo(e){if(!e.RTCPeerConnection||`connectionState`in e.RTCPeerConnection.prototype)return;let t=e.RTCPeerConnection.prototype;Object.defineProperty(t,"connectionState",{get(){return{completed:`connected`,checking:`connecting`}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(t,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(e){this._onconnectionstatechange&&(this.removeEventListener(`connectionstatechange`,this._onconnectionstatechange),delete this._onconnectionstatechange),e&&this.addEventListener(`connectionstatechange`,this._onconnectionstatechange=e)},enumerable:!0,configurable:!0}),[`setLocalDescription`,`setRemoteDescription`].forEach(e=>{let n=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{let t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;let n=new Event(`connectionstatechange`,e);t.dispatchEvent(n)}return e},this.addEventListener(`iceconnectionstatechange`,this._connectionstatechangepoly)),n.apply(this,arguments)}})}function to(e,t){if(!e.RTCPeerConnection||t.browser===`chrome`&&t.version>=71||t.browser===`safari`&&t._safariVersion>=13.1)return;let n=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&t.sdp.indexOf(`
|
|
35
|
+
a=extmap-allow-mixed`)!==-1){let n=t.sdp.split(`
|
|
36
|
+
`).filter(e=>e.trim()!==`a=extmap-allow-mixed`).join(`
|
|
37
|
+
`);e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:n}):t.sdp=n}return n.apply(this,arguments)}}function no(e,t){if(!(e.RTCPeerConnection&&e.RTCPeerConnection.prototype))return;let n=e.RTCPeerConnection.prototype.addIceCandidate;n&&n.length!==0&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(t.browser===`chrome`&&t.version<78||t.browser===`firefox`&&t.version<68||t.browser===`safari`)&&arguments[0]&&arguments[0].candidate===``?Promise.resolve():n.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function ro(e,t){if(!(e.RTCPeerConnection&&e.RTCPeerConnection.prototype))return;let n=e.RTCPeerConnection.prototype.setLocalDescription;n&&n.length!==0&&(e.RTCPeerConnection.prototype.setLocalDescription=function(){let e=arguments[0]||{};if(typeof e!=`object`||e.type&&e.sdp)return n.apply(this,arguments);if(e={type:e.type,sdp:e.sdp},!e.type)switch(this.signalingState){case`stable`:case`have-local-offer`:case`have-remote-pranswer`:e.type=`offer`;break;default:e.type=`answer`}return e.sdp||e.type!==`offer`&&e.type!==`answer`?n.apply(this,[e]):(e.type===`offer`?this.createOffer:this.createAnswer).apply(this).then(e=>n.apply(this,[e]))})}var io=Object.freeze({__proto__:null,removeExtmapAllowMixed:to,shimAddIceCandidateNullOrEmpty:no,shimConnectionState:eo,shimMaxMessageSize:Qa,shimParameterlessSetLocalDescription:ro,shimRTCIceCandidate:Xa,shimRTCIceCandidateRelayProtocol:Za,shimSendThrowTypeError:$a});function ao(){let e=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).window,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{shimChrome:!0,shimFirefox:!0,shimSafari:!0},n=na,r=ia(e),i={browserDetails:r,commonShim:io,extractVersion:Qi,disableLog:ea,disableWarnings:ta,sdp:Ya};switch(r.browser){case`chrome`:if(!ya||!_a||!t.shimChrome)return n(`Chrome shim is not included in this adapter release.`),i;if(r.version===null)return n(`Chrome shim can not determine version, not shimming.`),i;n(`adapter.js shimming chrome.`),i.browserShim=ya,no(e,r),ro(e),ua(e,r),da(e),_a(e,r),fa(e,r),ga(e,r),pa(e),ma(e,r),va(e,r),Xa(e),Za(e),eo(e),Qa(e,r),$a(e,r),to(e,r);break;case`firefox`:if(!Na||!Ca||!t.shimFirefox)return n(`Firefox shim is not included in this adapter release.`),i;n(`adapter.js shimming firefox.`),i.browserShim=Na,no(e,r),ro(e),ba(e,r),Ca(e,r),wa(e,r),Sa(e),Da(e),Ta(e),Ea(e),Oa(e),ka(e,r),Aa(e,r),ja(e,r),Ma(e,r),Xa(e),eo(e),Qa(e,r),$a(e,r);break;case`safari`:if(!Ua||!t.shimSafari)return n(`Safari shim is not included in this adapter release.`),i;n(`adapter.js shimming safari.`),i.browserShim=Ua,no(e,r),ro(e),za(e),Va(e),Ia(e),Pa(e),Fa(e),Ba(e),La(e),Ha(e),Xa(e),Za(e),Qa(e,r),$a(e,r),to(e,r);break;default:n(`Unsupported browser!`)}return i}ao({window:typeof window>`u`?void 0:window});var oo,so,co=class extends (so=Promise){constructor(e){super(e)}catch(e){return super.catch(e)}static reject(e){return super.reject(e)}static all(e){return super.all(e)}static race(e){return super.race(e)}};oo=co,co.resolve=e=>Reflect.get(so,`resolve`,oo).call(oo,e);var lo=/version\/(\d+(\.?_?\d+)+)/i,uo;function k(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;if(e===void 0&&typeof navigator>`u`)return;let n=(e??navigator.userAgent).toLowerCase();return(uo===void 0||t)&&(uo=fo.find(e=>e.test.test(n))?.describe(n)),uo}var fo=[{test:/firefox|iceweasel|fxios/i,describe(e){return{name:`Firefox`,version:po(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes(`fxios`)?`iOS`:void 0,osVersion:mo(e)}}},{test:/chrom|crios|crmo/i,describe(e){return{name:`Chrome`,version:po(/(?:chrome|chromium|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes(`crios`)?`iOS`:void 0,osVersion:mo(e)}}},{test:/safari|applewebkit/i,describe(e){return{name:`Safari`,version:po(lo,e),os:e.includes(`mobile/`)?`iOS`:`macOS`,osVersion:mo(e)}}}];function po(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,r=t.match(e);return r&&r.length>=n&&r[n]||``}function mo(e){return e.includes(`mac os`)?po(/\(.+?(\d+_\d+(:?_\d+)?)/,e,1).replace(/_/g,`.`):void 0}var ho=`2.23.0`,go=class extends Error{constructor(e,t,n){super(t||`an error has occurred`),this.name=`LiveKitError`,this.code=e,n?.cause!==void 0&&(this.cause=n?.cause)}},_o=class extends go{},A;(function(e){e[e.NotAllowed=0]=`NotAllowed`,e[e.ServerUnreachable=1]=`ServerUnreachable`,e[e.InternalError=2]=`InternalError`,e[e.Cancelled=3]=`Cancelled`,e[e.LeaveRequest=4]=`LeaveRequest`,e[e.Timeout=5]=`Timeout`,e[e.WebSocket=6]=`WebSocket`,e[e.ServiceNotFound=7]=`ServiceNotFound`})(A||={});var j=class e extends _o{constructor(e,t,n,r){super(1,e),this.name=`ConnectionError`,this.status=n,this.reason=t,this.context=r,this.reasonName=A[t]}static notAllowed(t,n,r){return new e(t,A.NotAllowed,n,r)}static timeout(t){return new e(t,A.Timeout)}static leaveRequest(t,n){return new e(t,A.LeaveRequest,void 0,n)}static internal(t,n){return new e(t,A.InternalError,void 0,n)}static cancelled(t){return new e(t,A.Cancelled)}static serverUnreachable(t,n){return new e(t,A.ServerUnreachable,n)}static websocket(t,n,r){return new e(t,A.WebSocket,n,r)}static serviceNotFound(t,n){return new e(t,A.ServiceNotFound,void 0,n)}};function vo(e){return e.reason===A.Cancelled?!1:e.reason!==A.NotAllowed||e.status===403}var yo=class extends go{constructor(e){super(21,e??`device is unsupported`),this.name=`DeviceUnsupportedError`}},bo=class extends go{constructor(e){super(20,e??`track is invalid`),this.name=`TrackInvalidError`}},xo=class extends go{constructor(e){super(10,e||`unsupported server`),this.name=`UnsupportedServer`}},M=class extends go{constructor(e){super(12,e||`unexpected connection state`),this.name=`UnexpectedConnectionState`}},So=class extends go{constructor(e){super(13,e||`unable to negotiate`),this.name=`NegotiationError`}},Co=class extends go{constructor(e){super(14,e||`unable to publish data`),this.name=`PublishDataError`}},wo=class extends go{constructor(e,t){super(15,e),this.name=`PublishTrackError`,this.status=t}},To=class extends _o{constructor(e,t){super(15,e),this.name=`SignalRequestError`,this.reason=t,this.reasonName=typeof t==`string`?t:_i[t]}},N;(function(e){e[e.AlreadyOpened=0]=`AlreadyOpened`,e[e.AbnormalEnd=1]=`AbnormalEnd`,e[e.DecodeFailed=2]=`DecodeFailed`,e[e.LengthExceeded=3]=`LengthExceeded`,e[e.Incomplete=4]=`Incomplete`,e[e.HandlerAlreadyRegistered=7]=`HandlerAlreadyRegistered`,e[e.EncryptionTypeMismatch=8]=`EncryptionTypeMismatch`,e[e.HeaderTooLarge=9]=`HeaderTooLarge`,e[e.PayloadTooLarge=10]=`PayloadTooLarge`})(N||={});var P=class extends _o{constructor(e,t){super(16,e),this.name=`DataStreamError`,this.reason=t,this.reasonName=N[t]}},Eo=class extends go{constructor(e){super(18,e),this.name=`SignalReconnectError`}},Do;(function(e){e.PermissionDenied=`PermissionDenied`,e.NotFound=`NotFound`,e.DeviceInUse=`DeviceInUse`,e.Other=`Other`})(Do||={}),(function(e){function t(t){if(t&&`name`in t)return t.name===`NotFoundError`||t.name===`DevicesNotFoundError`?e.NotFound:t.name===`NotAllowedError`||t.name===`PermissionDeniedError`?e.PermissionDenied:t.name===`NotReadableError`||t.name===`TrackStartError`?e.DeviceInUse:e.Other}e.getFailure=t})(Do||={});var F=class{};F.setTimeout=function(){return setTimeout(...arguments)},F.setInterval=function(){return setInterval(...arguments)},F.clearTimeout=function(){return clearTimeout(...arguments)},F.clearInterval=function(){return clearInterval(...arguments)};var I;(function(e){e.Connected=`connected`,e.Reconnecting=`reconnecting`,e.SignalReconnecting=`signalReconnecting`,e.Reconnected=`reconnected`,e.Disconnected=`disconnected`,e.ConnectionStateChanged=`connectionStateChanged`,e.Moved=`moved`,e.MediaDevicesChanged=`mediaDevicesChanged`,e.ParticipantConnected=`participantConnected`,e.ParticipantDisconnected=`participantDisconnected`,e.TrackPublished=`trackPublished`,e.TrackSubscribed=`trackSubscribed`,e.TrackSubscriptionFailed=`trackSubscriptionFailed`,e.TrackUnpublished=`trackUnpublished`,e.TrackUnsubscribed=`trackUnsubscribed`,e.TrackMuted=`trackMuted`,e.TrackUnmuted=`trackUnmuted`,e.LocalTrackPublished=`localTrackPublished`,e.LocalTrackUnpublished=`localTrackUnpublished`,e.LocalAudioSilenceDetected=`localAudioSilenceDetected`,e.ActiveSpeakersChanged=`activeSpeakersChanged`,e.ParticipantMetadataChanged=`participantMetadataChanged`,e.ParticipantNameChanged=`participantNameChanged`,e.ParticipantAttributesChanged=`participantAttributesChanged`,e.ParticipantActive=`participantActive`,e.RoomMetadataChanged=`roomMetadataChanged`,e.DataReceived=`dataReceived`,e.SipDTMFReceived=`sipDTMFReceived`,e.TranscriptionReceived=`transcriptionReceived`,e.ConnectionQualityChanged=`connectionQualityChanged`,e.TrackStreamStateChanged=`trackStreamStateChanged`,e.TrackSubscriptionPermissionChanged=`trackSubscriptionPermissionChanged`,e.TrackSubscriptionStatusChanged=`trackSubscriptionStatusChanged`,e.AudioPlaybackStatusChanged=`audioPlaybackChanged`,e.VideoPlaybackStatusChanged=`videoPlaybackChanged`,e.MediaDevicesError=`mediaDevicesError`,e.ParticipantPermissionsChanged=`participantPermissionsChanged`,e.SignalConnected=`signalConnected`,e.RecordingStatusChanged=`recordingStatusChanged`,e.ParticipantEncryptionStatusChanged=`participantEncryptionStatusChanged`,e.EncryptionError=`encryptionError`,e.DCBufferStatusChanged=`dcBufferStatusChanged`,e.ActiveDeviceChanged=`activeDeviceChanged`,e.ChatMessage=`chatMessage`,e.LocalTrackSubscribed=`localTrackSubscribed`,e.MetricsReceived=`metricsReceived`,e.DataTrackPublished=`dataTrackPublished`,e.DataTrackUnpublished=`dataTrackUnpublished`,e.LocalDataTrackPublished=`localDataTrackPublished`,e.LocalDataTrackUnpublished=`localDataTrackUnpublished`})(I||={});var L;(function(e){e.TrackPublished=`trackPublished`,e.TrackSubscribed=`trackSubscribed`,e.TrackSubscriptionFailed=`trackSubscriptionFailed`,e.TrackUnpublished=`trackUnpublished`,e.TrackUnsubscribed=`trackUnsubscribed`,e.TrackMuted=`trackMuted`,e.TrackUnmuted=`trackUnmuted`,e.LocalTrackPublished=`localTrackPublished`,e.LocalTrackUnpublished=`localTrackUnpublished`,e.LocalTrackCpuConstrained=`localTrackCpuConstrained`,e.LocalSenderCreated=`localSenderCreated`,e.ParticipantMetadataChanged=`participantMetadataChanged`,e.ParticipantNameChanged=`participantNameChanged`,e.DataReceived=`dataReceived`,e.SipDTMFReceived=`sipDTMFReceived`,e.TranscriptionReceived=`transcriptionReceived`,e.IsSpeakingChanged=`isSpeakingChanged`,e.ConnectionQualityChanged=`connectionQualityChanged`,e.TrackStreamStateChanged=`trackStreamStateChanged`,e.TrackSubscriptionPermissionChanged=`trackSubscriptionPermissionChanged`,e.TrackSubscriptionStatusChanged=`trackSubscriptionStatusChanged`,e.TrackCpuConstrained=`trackCpuConstrained`,e.MediaDevicesError=`mediaDevicesError`,e.AudioStreamAcquired=`audioStreamAcquired`,e.ParticipantPermissionsChanged=`participantPermissionsChanged`,e.PCTrackAdded=`pcTrackAdded`,e.AttributesChanged=`attributesChanged`,e.LocalTrackSubscribed=`localTrackSubscribed`,e.ChatMessage=`chatMessage`,e.Active=`active`})(L||={});var R;(function(e){e.TransportsCreated=`transportsCreated`,e.Connected=`connected`,e.Disconnected=`disconnected`,e.Resuming=`resuming`,e.Resumed=`resumed`,e.Restarting=`restarting`,e.Restarted=`restarted`,e.SignalResumed=`signalResumed`,e.SignalRestarted=`signalRestarted`,e.Closing=`closing`,e.MediaTrackAdded=`mediaTrackAdded`,e.ActiveSpeakersUpdate=`activeSpeakersUpdate`,e.DataPacketReceived=`dataPacketReceived`,e.RTPVideoMapUpdate=`rtpVideoMapUpdate`,e.DCBufferStatusChanged=`dcBufferStatusChanged`,e.ParticipantUpdate=`participantUpdate`,e.RoomUpdate=`roomUpdate`,e.SpeakersChanged=`speakersChanged`,e.StreamStateChanged=`streamStateChanged`,e.ConnectionQualityUpdate=`connectionQualityUpdate`,e.SubscriptionError=`subscriptionError`,e.SubscriptionPermissionUpdate=`subscriptionPermissionUpdate`,e.RemoteMute=`remoteMute`,e.SubscribedQualityUpdate=`subscribedQualityUpdate`,e.LocalTrackUnpublished=`localTrackUnpublished`,e.LocalTrackSubscribed=`localTrackSubscribed`,e.Offline=`offline`,e.SignalRequestResponse=`signalRequestResponse`,e.SignalConnected=`signalConnected`,e.RoomMoved=`roomMoved`,e.PublishDataTrackResponse=`publishDataTrackResponse`,e.UnPublishDataTrackResponse=`unPublishDataTrackResponse`,e.DataTrackSubscriberHandles=`dataTrackSubscriberHandles`,e.DataTrackPacketReceived=`dataTrackPacketReceived`,e.Joined=`joined`,e.TokenRefreshed=`tokenRefreshed`,e.ServerRegionsReported=`serverRegionsReported`,e.RequestSubscribedCodecRefresh=`requestSubscribedCodecRefresh`})(R||={});var z;(function(e){e.Message=`message`,e.Muted=`muted`,e.Unmuted=`unmuted`,e.Restarted=`restarted`,e.Ended=`ended`,e.Subscribed=`subscribed`,e.Unsubscribed=`unsubscribed`,e.CpuConstrained=`cpuConstrained`,e.UpdateSettings=`updateSettings`,e.UpdateSubscription=`updateSubscription`,e.AudioPlaybackStarted=`audioPlaybackStarted`,e.AudioPlaybackFailed=`audioPlaybackFailed`,e.AudioSilenceDetected=`audioSilenceDetected`,e.VisibilityChanged=`visibilityChanged`,e.VideoDimensionsChanged=`videoDimensionsChanged`,e.VideoPlaybackStarted=`videoPlaybackStarted`,e.VideoPlaybackFailed=`videoPlaybackFailed`,e.ElementAttached=`elementAttached`,e.ElementDetached=`elementDetached`,e.UpstreamPaused=`upstreamPaused`,e.UpstreamResumed=`upstreamResumed`,e.SubscriptionPermissionChanged=`subscriptionPermissionChanged`,e.SubscriptionStatusChanged=`subscriptionStatusChanged`,e.SubscriptionFailed=`subscriptionFailed`,e.TrackProcessorUpdate=`trackProcessorUpdate`,e.AudioTrackFeatureUpdate=`audioTrackFeatureUpdate`,e.TranscriptionReceived=`transcriptionReceived`,e.TimeSyncUpdate=`timeSyncUpdate`,e.PreConnectBufferFlushed=`preConnectBufferFlushed`})(z||={});function Oo(e){let t={};for(let r of Object.entries(e)){var n=_(r,2);let e=n[0],i=n[1];i!==void 0&&(t[e]=i)}return t}function ko(e,t){return e&&t?`${e}x${t}`:void 0}function Ao(e){return Math.round(e*1e4)/1e4}function jo(e){let t=e.jitterBufferDelay,n=e.jitterBufferEmittedCount;return t!==void 0&&n?Ao(t/n):void 0}function Mo(e,t){if(e.playoutDelay!==void 0)return Ao(e.playoutDelay);let n=t?.totalPlayoutDelay,r=t?.totalSamplesCount;return n!==void 0&&r?Ao(n/r):void 0}function No(e){let t=new Map,n=[],r=[],i=[],a;e.forEach(e=>t.set(e.id,e));let o=e=>e.codecId?t.get(e.codecId)?.mimeType:void 0,s=(e,n)=>e[n]?t.get(e[n]):void 0;e.forEach(e=>{switch(e.type){case`inbound-rtp`:{let t=s(e,`playoutId`);r.push(Oo({kind:e.kind,ssrc:e.ssrc,mid:e.mid,trackId:e.trackIdentifier,codec:o(e),decoder:e.decoderImplementation,resolution:ko(e.frameWidth,e.frameHeight),fps:e.framesPerSecond,bytesReceived:e.bytesReceived,packetsReceived:e.packetsReceived,packetsLost:e.packetsLost,packetsDiscarded:e.packetsDiscarded,framesReceived:e.framesReceived,framesDecoded:e.framesDecoded,framesDropped:e.framesDropped,keyFramesDecoded:e.keyFramesDecoded,freezeCount:e.freezeCount,totalFreezesDuration:e.totalFreezesDuration,pauseCount:e.pauseCount,nackCount:e.nackCount,pliCount:e.pliCount,firCount:e.firCount,jitter:e.jitter,jitterBuffer:jo(e),playoutDelay:Mo(e,t),audioLevel:e.audioLevel,totalSamplesReceived:e.totalSamplesReceived,concealedSamples:e.concealedSamples}));break}case`outbound-rtp`:{let t=s(e,`remoteId`),n=s(e,`mediaSourceId`);i.push(Oo({kind:e.kind,ssrc:e.ssrc,mid:e.mid,rid:e.rid,trackId:n?.trackIdentifier,active:e.active,codec:o(e),encoder:e.encoderImplementation,resolution:ko(e.frameWidth,e.frameHeight),fps:e.framesPerSecond,captureResolution:ko(n?.width,n?.height),captureFps:n?.framesPerSecond,audioLevel:n?.audioLevel,targetBitrate:e.targetBitrate,bytesSent:e.bytesSent,packetsSent:e.packetsSent,retransmittedPacketsSent:e.retransmittedPacketsSent,framesEncoded:e.framesEncoded,keyFramesEncoded:e.keyFramesEncoded,limitedBy:e.qualityLimitationReason===`none`?void 0:e.qualityLimitationReason,nackCount:e.nackCount,pliCount:e.pliCount,firCount:e.firCount,remotePacketsLost:t?.packetsLost,remoteFractionLost:t?.fractionLost,remoteJitter:t?.jitter,remoteRoundTripTime:t?.roundTripTime}));break}case`transport`:a=e;break;case`candidate-pair`:n.push(e)}});let c=a?.selectedCandidatePairId,l=(c?t.get(c):void 0)??n.find(e=>e.selected)??n.find(e=>e.nominated),u=l?.localCandidateId?t.get(l.localCandidateId):void 0,d=l?.remoteCandidateId?t.get(l.remoteCandidateId):void 0,f=Oo({ice:a?.iceState,dtls:a?.dtlsState,route:u&&d?`${u.candidateType}/${u.protocol} -> ${d.candidateType}`:void 0,network:u?.networkType,currentRoundTripTime:l?.currentRoundTripTime,availableOutgoingBitrate:l?.availableOutgoingBitrate,availableIncomingBitrate:l?.availableIncomingBitrate,bytesSent:l?.bytesSent,bytesReceived:l?.bytesReceived,candidatePairChanges:a?.selectedCandidatePairChanges});return{connection:Object.keys(f).length>0?f:void 0,outbound:i.length>0?i:void 0,inbound:r.length>0?r:void 0}}function Po(e){return e===void 0?e:typeof structuredClone==`function`?typeof e==`object`&&e?structuredClone(Object.assign({},e)):structuredClone(e):JSON.parse(JSON.stringify(e))}var B=class{constructor(e,t,n,r,i){if(typeof e==`object`)this.width=e.width,this.height=e.height,this.aspectRatio=e.aspectRatio,this.encoding={maxBitrate:e.maxBitrate,maxFramerate:e.maxFramerate,priority:e.priority};else if(t!==void 0&&n!==void 0)this.width=e,this.height=t,this.aspectRatio=e/t,this.encoding={maxBitrate:n,maxFramerate:r,priority:i};else throw TypeError(`Unsupported options: provide at least width, height and maxBitrate`)}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.aspectRatio}}},Fo=[`vp8`,`h264`],Io=[`vp8`,`h264`,`vp9`,`av1`,`h265`];function Lo(e){return!!Fo.find(t=>t===e)}var Ro=Lo,zo;(function(e){e[e.PREFER_REGRESSION=0]=`PREFER_REGRESSION`,e[e.SIMULCAST=1]=`SIMULCAST`,e[e.REGRESSION=2]=`REGRESSION`})(zo||={});var Bo;(function(e){e.telephone={maxBitrate:12e3},e.speech={maxBitrate:24e3},e.music={maxBitrate:48e3},e.musicStereo={maxBitrate:64e3},e.musicHighQuality={maxBitrate:96e3},e.musicHighQualityStereo={maxBitrate:128e3}})(Bo||={});var Vo={h90:new B(160,90,9e4,20),h180:new B(320,180,16e4,20),h216:new B(384,216,18e4,20),h360:new B(640,360,45e4,20),h540:new B(960,540,8e5,25),h720:new B(1280,720,17e5,30),h1080:new B(1920,1080,3e6,30),h1440:new B(2560,1440,5e6,30),h2160:new B(3840,2160,8e6,30)},Ho={h120:new B(160,120,7e4,20),h180:new B(240,180,125e3,20),h240:new B(320,240,14e4,20),h360:new B(480,360,33e4,20),h480:new B(640,480,5e5,20),h540:new B(720,540,6e5,25),h720:new B(960,720,13e5,30),h1080:new B(1440,1080,23e5,30),h1440:new B(1920,1440,38e5,30)},Uo={h360fps3:new B(640,360,2e5,3,`medium`),h360fps15:new B(640,360,4e5,15,`medium`),h720fps5:new B(1280,720,8e5,5,`medium`),h720fps15:new B(1280,720,15e5,15,`medium`),h720fps30:new B(1280,720,2e6,30,`medium`),h1080fps15:new B(1920,1080,25e5,15,`medium`),h1080fps30:new B(1920,1080,5e6,30,`medium`),original:new B(0,0,7e6,30,`medium`)};function Wo(e,t,n){var r,i;let a=ns(e??{}),o=a.optionsWithoutProcessor,s=a.audioProcessor,c=a.videoProcessor,l=t?.processor,u=n?.processor,d=o??{};return d.audio===!0&&(d.audio={}),d.video===!0&&(d.video={}),d.audio&&(Go(d.audio,t),(r=d.audio).deviceId??(r.deviceId={ideal:`default`}),(s||l)&&(d.audio.processor=s??l)),d.video&&(Go(d.video,n),(i=d.video).deviceId??(i.deviceId={ideal:`default`}),(c||u)&&(d.video.processor=c??u)),d}function Go(e,t){return Object.keys(t).forEach(n=>{e[n]===void 0&&(e[n]=t[n])}),e}function Ko(e){var t,n;let r={};if(e.video){if(typeof e.video==`object`){let n={},i=n,a=e.video;Object.keys(a).forEach(e=>{switch(e){case`resolution`:Go(i,a.resolution);break;default:i[e]=a[e]}}),r.video=n,(t=r.video).deviceId??(t.deviceId={ideal:`default`})}else r.video=e.video?{deviceId:{ideal:`default`}}:!1}else r.video=!1;return e.audio?typeof e.audio==`object`?(r.audio=e.audio,(n=r.audio).deviceId??(n.deviceId={ideal:`default`})):r.audio={deviceId:{ideal:`default`}}:r.audio=!1,r}function qo(e){return O(this,arguments,void 0,function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:200;return function*(){let n=Jo();if(!n)return!1;let r,i;try{i=n.createAnalyser(),i.fftSize=2048;let a=i.frequencyBinCount,o=new Uint8Array(a);r=n.createMediaStreamSource(new MediaStream([e.mediaStreamTrack])),r.connect(i);let s=()=>n.state===`running`;if(!s()){try{yield Promise.race([n.resume(),U(200)])}catch{}if(!s())return!1}return yield U(t),i.getByteTimeDomainData(o),!o.some(e=>e!==128&&e!==0)}finally{r?.disconnect(),i?.disconnect(),yield n.close().catch(()=>{})}}()})}function Jo(){let e=typeof window<`u`&&(window.AudioContext||window.webkitAudioContext);if(e){let t=new e({latencyHint:`interactive`});if(t.state===`suspended`&&typeof window<`u`&&window.document?.body){let e=()=>O(this,void 0,void 0,function*(){var n;try{t.state===`suspended`&&(yield t.resume())}catch(e){console.warn(`Error trying to auto-resume audio context`,e)}finally{(n=window.document.body)==null||n.removeEventListener(`click`,e)}});t.addEventListener(`statechange`,()=>{var n;t.state===`closed`&&((n=window.document.body)==null||n.removeEventListener(`click`,e))}),window.document.body.addEventListener(`click`,e)}return t}}function Yo(e){return e===`audioinput`?H.Source.Microphone:e===`videoinput`?H.Source.Camera:H.Source.Unknown}function Xo(e){if(e===H.Source.Microphone)return`audioinput`;if(e===H.Source.Camera)return`videoinput`}function Zo(e){let t=e.video??!0;return e.resolution&&e.resolution.width>0&&e.resolution.height>0&&(t=typeof t==`boolean`?{}:t,t=As()?Object.assign(Object.assign({},t),{width:{max:e.resolution.width},height:{max:e.resolution.height},frameRate:e.resolution.frameRate}):Object.assign(Object.assign({},t),{width:{ideal:e.resolution.width},height:{ideal:e.resolution.height},frameRate:e.resolution.frameRate})),{audio:e.audio??!1,video:t,controller:e.controller,selfBrowserSurface:e.selfBrowserSurface,surfaceSwitching:e.surfaceSwitching,systemAudio:e.systemAudio,preferCurrentTab:e.preferCurrentTab}}function Qo(e){return e.split(`/`)[1].toLowerCase()}function $o(e){let t=[];return e.forEach(e=>{e.track!==void 0&&t.push(new Or({cid:e.track.mediaStreamID,track:e.trackInfo}))}),t}function V(e){return`mediaStreamTrack`in e?{trackID:e.sid,source:e.source,muted:e.isMuted,enabled:e.mediaStreamTrack.enabled,kind:e.kind,streamID:e.mediaStreamID,streamTrackID:e.mediaStreamTrack.id}:{trackID:e.trackSid,enabled:e.isEnabled,muted:e.isMuted,trackInfo:Object.assign({mimeType:e.mimeType,name:e.trackName,encrypted:e.isEncrypted,kind:e.kind,source:e.source},e.track?V(e.track):{})}}function es(){return typeof RTCRtpReceiver<`u`&&typeof RTCRtpReceiver.prototype.getSynchronizationSources==`function`}function ts(e,t){e===void 0&&(e={}),t===void 0&&(t={});let n=[...Object.keys(t),...Object.keys(e)],r={};for(let i of n)e[i]!==t[i]&&(r[i]=t[i]??``);return r}function ns(e){let t=Object.assign({},e),n,r;return typeof t.audio==`object`&&t.audio.processor&&(n=t.audio.processor,t.audio=Object.assign(Object.assign({},t.audio),{processor:void 0})),typeof t.video==`object`&&t.video.processor&&(r=t.video.processor,t.video=Object.assign(Object.assign({},t.video),{processor:void 0})),{audioProcessor:n,videoProcessor:r,optionsWithoutProcessor:Po(t)}}function rs(e){switch(e){case b.CAMERA:return H.Source.Camera;case b.MICROPHONE:return H.Source.Microphone;case b.SCREEN_SHARE:return H.Source.ScreenShare;case b.SCREEN_SHARE_AUDIO:return H.Source.ScreenShareAudio;default:return H.Source.Unknown}}function is(e,t){return e.width*e.height<t.width*t.height}function as(e,t){return e.layers?.find(e=>e.quality===t)}function os(e,t){return O(this,arguments,void 0,function(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return function*(){var r;if(typeof document>`u`||e.readyState===`ended`||e.muted||!e.enabled)return!1;let i=typeof HTMLVideoElement.prototype.requestVideoFrameCallback==`function`,a=n.find(t=>t instanceof HTMLVideoElement&&t.srcObject instanceof MediaStream&&t.srcObject.getVideoTracks().includes(e)&&(i||t.readyState<2)),o=a??document.createElement(`video`);a||(o.playsInline=!0,o.muted=!0,o.srcObject=new MediaStream([e]),o.play().catch(e=>{E.debug(`could not play element while waiting for the first video frame`,{error:e})}));let s,c,l;try{return yield new Promise(e=>{s=setTimeout(()=>e(!1),t),i?c=o.requestVideoFrameCallback(()=>e(!0)):(l=()=>e(!0),o.addEventListener(`loadeddata`,l))})}finally{clearTimeout(s),c!==void 0&&((r=o.cancelVideoFrameCallback)==null||r.call(o,c)),l&&o.removeEventListener(`loadeddata`,l),a||(o.pause(),o.srcObject=null)}}()})}var ss=5e3,cs=[],ls;(function(e){e[e.LOW=0]=`LOW`,e[e.MEDIUM=1]=`MEDIUM`,e[e.HIGH=2]=`HIGH`})(ls||={});var H=class e extends Yi.EventEmitter{get streamState(){return this._streamState}setStreamState(e){this._streamState!==e&&this.log.debug(`stream state changed: ${this._streamState} -> ${e}`),this._streamState=e}constructor(t,n){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};super(),this.attachedElements=[],this.isMuted=!1,this._streamState=e.StreamState.Active,this.isInBackground=!1,this._currentBitrate=0,this.finalStatsLogged=!1,this.log=E,this.appVisibilityChangedListener=()=>{this.backgroundTimeout&&clearTimeout(this.backgroundTimeout),document.visibilityState===`hidden`?this.backgroundTimeout=setTimeout(()=>this.handleAppVisibilityChanged(),ss):this.handleAppVisibilityChanged()},this.loggerContextCb=r.loggerContextCb,this.log=D(r.loggerName??T.Track,()=>this.logContext),this.setMaxListeners(100),this.kind=n,this._mediaStreamTrack=t,this._mediaStreamID=t.id,this.source=e.Source.Unknown}get logContext(){return Object.assign(Object.assign({},this.loggerContextCb?.call(this)),V(this))}get currentBitrate(){return this._currentBitrate}get mediaStreamTrack(){return this._mediaStreamTrack}get mediaStreamID(){return this._mediaStreamID}attach(t){let n=`audio`;this.kind===e.Kind.Video&&(n=`video`),this.attachedElements.length===0&&this.kind===e.Kind.Video&&this.addAppVisibilityListener(),t||(n===`audio`&&(cs.forEach(e=>{e.parentElement===null&&!t&&(t=e)}),t&&cs.splice(cs.indexOf(t),1)),t||=document.createElement(n)),this.attachedElements.includes(t)||this.attachedElements.push(t),us(this.mediaStreamTrack,t);let r=t.srcObject.getTracks(),i=r.some(e=>e.kind===`audio`);return t.play().then(()=>{this.emit(i?z.AudioPlaybackStarted:z.VideoPlaybackStarted)}).catch(e=>{e.name===`NotAllowedError`?this.emit(i?z.AudioPlaybackFailed:z.VideoPlaybackFailed,e):e.name===`AbortError`?this.log.debug(`${i?`audio`:`video`} playback aborted, likely due to new play request`):this.log.warn(`could not playback ${i?`audio`:`video`}`,{error:e}),i&&t&&r.some(e=>e.kind===`video`)&&e.name===`NotAllowedError`&&(t.muted=!0,t.play().catch(()=>{}))}),this.emit(z.ElementAttached,t),t}detach(e){try{if(e){ds(this.mediaStreamTrack,e);let t=this.attachedElements.indexOf(e);return t>=0&&(this.attachedElements.splice(t,1),this.recycleElement(e),this.emit(z.ElementDetached,e)),e}let t=[];return this.attachedElements.forEach(e=>{ds(this.mediaStreamTrack,e),t.push(e),this.recycleElement(e),this.emit(z.ElementDetached,e)}),this.attachedElements=[],t}finally{this.attachedElements.length===0&&this.removeAppVisibilityListener()}}stop(){this.log.debug(`stopping track`),this.stopMonitor(),this._mediaStreamTrack.stop()}enable(){this._mediaStreamTrack.enabled=!0}disable(){this._mediaStreamTrack.enabled=!1}stopMonitor(){this.monitorInterval&&clearInterval(this.monitorInterval),this.timeSyncHandle!==void 0&&(cancelAnimationFrame(this.timeSyncHandle),this.timeSyncHandle=void 0),this.logFinalStats()}logFinalStats(){this.finalStatsLogged||(this.finalStatsLogged=!0,this.getRTCStatsReport().then(e=>{e&&this.log.info(`final track stats`,No(e))}).catch(e=>this.log.debug(`could not collect final track stats`,{error:e})))}updateLoggerOptions(e){e.loggerContextCb&&(this.loggerContextCb=e.loggerContextCb),e.loggerName&&(this.log=D(e.loggerName,()=>this.logContext))}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),cs.forEach(e=>{e.parentElement||(t=!1)}),t&&cs.push(e)}}handleAppVisibilityChanged(){return O(this,void 0,void 0,function*(){this.isInBackground=document.visibilityState===`hidden`,!this.isInBackground&&this.kind===e.Kind.Video&&setTimeout(()=>this.attachedElements.forEach(e=>e.play().catch(()=>{})),0)})}addAppVisibilityListener(){W()?(this.isInBackground=document.visibilityState===`hidden`,document.addEventListener(`visibilitychange`,this.appVisibilityChangedListener)):this.isInBackground=!1}removeAppVisibilityListener(){W()&&document.removeEventListener(`visibilitychange`,this.appVisibilityChangedListener)}};function us(e,t){let n;n=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream;let r;r=e.kind===`audio`?n.getAudioTracks():n.getVideoTracks(),r.includes(e)||(r.forEach(e=>{n.removeTrack(e)}),n.addTrack(e)),As()&&t instanceof HTMLVideoElement||(t.autoplay=!0),t.muted=n.getAudioTracks().length===0,t instanceof HTMLVideoElement&&(t.playsInline=!0),t.srcObject!==n&&(t.srcObject=n,(As()||Ds())&&t instanceof HTMLVideoElement&&setTimeout(()=>{t.srcObject=n,t.play().catch(()=>{})},0))}function ds(e,t){if(t.srcObject instanceof MediaStream){let n=t.srcObject;n.removeTrack(e),t.srcObject=n.getTracks().length>0?n:null}}(function(e){let t;(function(e){e.Audio=`audio`,e.Video=`video`,e.Unknown=`unknown`})(t=e.Kind||={});let n;(function(e){e.Camera=`camera`,e.Microphone=`microphone`,e.ScreenShare=`screen_share`,e.ScreenShareAudio=`screen_share_audio`,e.Unknown=`unknown`})(n=e.Source||={});let r;(function(e){e.Active=`active`,e.Paused=`paused`,e.Unknown=`unknown`})(r=e.StreamState||={});function i(e){switch(e){case t.Audio:return on.AUDIO;case t.Video:return on.VIDEO;default:return on.DATA}}e.kindToProto=i;function a(e){switch(e){case on.AUDIO:return t.Audio;case on.VIDEO:return t.Video;default:return t.Unknown}}e.kindFromProto=a;function o(e){switch(e){case n.Camera:return b.CAMERA;case n.Microphone:return b.MICROPHONE;case n.ScreenShare:return b.SCREEN_SHARE;case n.ScreenShareAudio:return b.SCREEN_SHARE_AUDIO;default:return b.UNKNOWN}}e.sourceToProto=o;function s(e){switch(e){case b.CAMERA:return n.Camera;case b.MICROPHONE:return n.Microphone;case b.SCREEN_SHARE:return n.ScreenShare;case b.SCREEN_SHARE_AUDIO:return n.ScreenShareAudio;default:return n.Unknown}}e.sourceFromProto=s;function c(e){switch(e){case fr.ACTIVE:return r.Active;case fr.PAUSED:return r.Paused;default:return r.Unknown}}e.streamStateFromProto=c})(H||={});var fs=`|`,ps=`https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension`;function ms(e){let t=e.split(fs);return t.length>1?[t[0],e.substr(t[0].length+1)]:[e,``]}function U(e){return new co(t=>F.setTimeout(t,e))}function hs(){return`addTransceiver`in RTCPeerConnection.prototype}function gs(){return`addTrack`in RTCPeerConnection.prototype}function _s(){if(!(`getCapabilities`in RTCRtpSender)||As()||Ds())return!1;let e=RTCRtpSender.getCapabilities(`video`),t=!1;if(e){for(let n of e.codecs)if(n.mimeType.toLowerCase()===`video/av1`){t=!0;break}}return t}function vs(){if(!(`getCapabilities`in RTCRtpSender)||Ds())return!1;if(As()){let e=k();if(e?.version&&Ws(e.version,`16`)<0||e?.os===`iOS`&&e?.osVersion&&Ws(e.osVersion,`16`)<0)return!1}let e=RTCRtpSender.getCapabilities(`video`),t=!1;if(e){for(let n of e.codecs)if(n.mimeType.toLowerCase()===`video/vp9`){t=!0;break}}return t}function ys(e){return e===`av1`||e===`vp9`}function bs(e){let t=e.getHeaderExtensionsToNegotiate?.call(e);if(!t||!e.setHeaderExtensionsToNegotiate)return!1;let n=t.find(e=>e.uri===ps);if(!n)return!1;if(n.direction!==`stopped`)return!0;n.direction=`sendrecv`;try{return e.setHeaderExtensionsToNegotiate(t),!0}catch{return!1}}function xs(e,t){return ys(e)&&!!t?.simulcast&&!!t.scalabilityMode?.startsWith(`L1T`)}function Ss(){let e=k();return js()||Rs()||e?.name===`Chrome`&&Ws(e.version,`113`)<0}var Cs=`1.13.6`;function ws(e){return e?Ws(e,Cs)>0:!1}function Ts(e){return!document||js()?!1:(e||=document.createElement(`audio`),`setSinkId`in e)}function Es(){return typeof RTCPeerConnection>`u`?!1:hs()||gs()}function Ds(){return k()?.name===`Firefox`}function Os(){let e=k();return!!e&&e.name===`Chrome`&&e.os!==`iOS`}function ks(){return typeof window<`u`&&window.RTCRtpScriptTransform!==void 0&&!Os()}function As(){return k()?.name===`Safari`}function js(){let e=k();return e?.name===`Safari`||e?.os===`iOS`}function Ms(){if(!W())return!1;let e=k();return e?.name===`Safari`&&e?.os===`macOS`&&navigator.maxTouchPoints>1}function Ns(){return k()?.os===`iOS`||Ms()}function Ps(){let e=k();return e?.name===`Safari`&&e.version.startsWith(`17.`)||e?.os===`iOS`&&!!e?.osVersion&&Ws(e.osVersion,`17`)>=0}function Fs(e){return e||=k(),e?.name===`Safari`&&Ws(e.version,`18.3`)>0||e?.os===`iOS`&&!!e?.osVersion&&Ws(e.osVersion,`18.3`)>0}function Is(){return W()?navigator.userAgentData?.mobile??/Tablet|iPad|Mobile|Android|BlackBerry/.test(navigator.userAgent):!1}function Ls(){let e=k(),t=`17.2`;if(e)return!!(e.name!==`Safari`&&e.os!==`iOS`||e.os===`iOS`&&e.osVersion&&Ws(e.osVersion,t)>=0||e.name===`Safari`&&Ws(e.version,t)>=0)}function W(){return typeof document<`u`}function Rs(){return navigator.product==`ReactNative`}function zs(e){return e.hostname.endsWith(`.livekit.cloud`)||e.hostname.endsWith(`.livekit.run`)}function Bs(e){return zs(e)?e.hostname.split(`.`)[0]:null}function Vs(){if(global&&global.LiveKitReactNativeGlobal)return global.LiveKitReactNativeGlobal}function Hs(){if(!Rs())return;let e=Vs();if(e)return e.platform}function Us(){if(W())return window.devicePixelRatio;if(Rs()){let e=Vs();if(e)return e.devicePixelRatio}return 1}function Ws(e,t){let n=e.split(`.`),r=t.split(`.`),i=Math.min(n.length,r.length);for(let e=0;e<i;++e){let t=parseInt(n[e],10),a=parseInt(r[e],10);if(t>a)return 1;if(t<a)return-1;if(e===i-1&&t===a)return 0}return e===``&&t!==``?-1:t===``?1:n.length==r.length?0:n.length<r.length?-1:1}function Gs(e){for(let t of e)t.target.handleResize(t)}function Ks(e){for(let t of e)t.target.handleVisibilityChanged(t)}var qs=null,Js=()=>(qs||=new ResizeObserver(Gs),qs),Ys=null,Xs=()=>(Ys||=new IntersectionObserver(Ks,{root:null,rootMargin:`0px`}),Ys);function Zs(e){let t=new Zn({capabilities:e,sdk:Qn.JS,protocol:17,clientProtocol:2,version:ho});return Rs()&&(t.os=Hs()??``),t}function Qs(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:16,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:16,n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=arguments.length>3&&arguments[3]!==void 0&&arguments[3],i=document.createElement(`canvas`);i.width=e,i.height=t;let a=i.getContext(`2d`);a?.fillRect(0,0,i.width,i.height),r&&a&&(a.beginPath(),a.arc(e/2,t/2,50,0,Math.PI*2,!0),a.closePath(),a.fillStyle=`grey`,a.fill());let o=_(i.captureStream().getTracks(),1)[0];if(!o)throw Error(`Could not get empty media stream video track`);return o.enabled=n,o}var $s,ec,tc=new Set;function nc(){if(!$s){let e=new AudioContext,t=e.createOscillator(),n=e.createGain();n.gain.setValueAtTime(0,0);let r=e.createMediaStreamDestination();if(t.connect(n),n.connect(r),t.start(),$s=_(r.stream.getAudioTracks(),1)[0],!$s)throw e.close().catch(()=>{}),Error(`Could not get empty media stream audio track`);$s.enabled=!1,ec=e}let e=$s.clone();return tc.add(e),e}function rc(e){return O(this,void 0,void 0,function*(){if(!tc.delete(e)||(e.stop(),tc.size>0))return;let t=ec;$s?.stop(),$s=void 0,ec=void 0,yield t?.close()})}var G=class{get isResolved(){return this._isResolved}constructor(e,t){this._isResolved=!1,this.onFinally=t,this.promise=new Promise((t,n)=>O(this,void 0,void 0,function*(){this.resolve=t,this.reject=n,e&&(yield e(t,n))})).finally(()=>{var e;this._isResolved=!0,(e=this.onFinally)==null||e.call(this)})}};function ic(e){return Io.includes(e)}function ac(e){if(typeof e==`string`||typeof e==`number`)return e;if(Array.isArray(e))return e[0];if(e.exact!==void 0)return Array.isArray(e.exact)?e.exact[0]:e.exact;if(e.ideal!==void 0)return Array.isArray(e.ideal)?e.ideal[0]:e.ideal;throw Error(`could not unwrap constraint`)}function oc(e){return typeof e==`object`&&!!e&&`name`in e&&(e.name===`NotAllowedError`||e.name===`SecurityError`||e.name===`PermissionDeniedError`||e.name===`PermissionDismissedError`)}var sc=new WeakSet;function cc(e){typeof e==`object`&&e&&sc.add(e)}function lc(e){return typeof e==`object`&&!!e&&sc.has(e)}function uc(e){return e.startsWith(`http`)?e.replace(/^(http)/,`ws`):e}function dc(e){return e.startsWith(`ws`)?e.replace(/^(ws)/,`http`):e}function fc(e,t){return e.segments.map(e=>{let n=e.id,r=e.text,i=e.language,a=e.startTime,o=e.endTime,s=e.final,c=t.get(n)??Date.now(),l=Date.now();return s?t.delete(n):t.set(n,c),{id:n,text:r,startTime:Number.parseInt(a.toString()),endTime:Number.parseInt(o.toString()),final:s,language:i,firstReceivedTime:c,lastReceivedTime:l}})}function pc(e){let t=e.id,n=e.timestamp,r=e.message,i=e.editTimestamp;return{id:t,timestamp:Number.parseInt(n.toString()),editTimestamp:i?Number.parseInt(i.toString()):void 0,message:r}}function mc(e){switch(e.reason){case A.LeaveRequest:return e.context;case A.Cancelled:return un.CLIENT_INITIATED;case A.NotAllowed:return un.USER_REJECTED;case A.ServerUnreachable:return un.JOIN_FAILURE;default:return un.UNKNOWN_REASON}}function hc(e){return e===void 0?void 0:Number(e)}function gc(e){return e===void 0?void 0:BigInt(e)}function _c(e){return!!e&&!(e instanceof MediaStreamTrack)&&e.isLocal}function vc(e){return!!e&&e.kind==H.Kind.Audio}function yc(e){return!!e&&e.kind==H.Kind.Video}function bc(e){return _c(e)&&yc(e)}function xc(e){return _c(e)&&vc(e)}function Sc(e){return!!e&&!e.isLocal}function Cc(e){return!!e&&!e.isLocal}function wc(e){return Sc(e)&&yc(e)}function Tc(e){return e.isLocal}function Ec(e,t){let n=[],r=new TextEncoder().encode(e);for(;r.length>t;){let e=t;for(;e>0;){let t=r[e];if(t!==void 0&&(t&192)!=128)break;e--}n.push(r.slice(0,e)),r=r.slice(e)}return r.length>0&&n.push(r),n}function Dc(e){return new ReadableStream({start(t){t.enqueue(e),t.close()}})}function Oc(e,t){return Ui(this,arguments,function*(){let n=e.getReader(),r=new Uint8Array;try{for(;;){let e=yield Hi(n.read()),i=e.done,a=e.value;if(i)break;if(a.byteLength===0)continue;let o=new Uint8Array(r.byteLength+a.byteLength);for(o.set(r),o.set(a,r.byteLength),r=o;r.byteLength>=t;)yield yield Hi(r.slice(0,t)),r=r.slice(t)}r.byteLength>0&&(yield yield Hi(r))}finally{n.releaseLock()}})}function kc(e){let t=e.get(`Cache-Control`);if(t){let e=t.match(/(?:^|[,\s])max-age=(\d+)/)?.[1];if(e)return parseInt(e,10)}}function Ac(){return typeof CompressionStream<`u`}var jc=null;function Mc(){return typeof jc!=`boolean`&&(jc=Nc()),jc}function Nc(){if(typeof CompressionStream>`u`||typeof DecompressionStream>`u`)return!1;try{return new CompressionStream(`deflate-raw`),new DecompressionStream(`deflate-raw`),!0}catch{return!1}}function Pc(){return Ac()&&!Ds()}function Fc(e,t){let n=_(ms(t.id),2)[1];if(n?.startsWith(`TR`))return n;if(e.id.startsWith(`TR`))return e.id}function Ic(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=Lc(e,t);return n?r:Bc(r,`v1`)}function Lc(e,t){let n=new URL(uc(e));return t.forEach((e,t)=>{n.searchParams.set(t,e)}),Bc(n,`rtc`)}function Rc(e){return Bc(new URL(dc(e)),`validate`)}function zc(e){return e.endsWith(`/`)?e:`${e}/`}function Bc(e,t){return e.pathname=`${zc(e.pathname)}${t}`,e}function Vc(e){if(typeof e==`string`)return hr.fromJson(JSON.parse(e),{ignoreUnknownFields:!0});if(e instanceof ArrayBuffer)return hr.fromBinary(new Uint8Array(e));throw Error(`could not decode websocket message: ${typeof e}`)}function Hc(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Unknown reason`;if(e instanceof Error)return e.message;if(!(e instanceof AbortSignal))return t;let n=e.reason;switch(typeof n){case`string`:return n;case`object`:return n instanceof Error?n.message:t;default:return`toString`in n?n.toString():t}}function Uc(e,t){return e instanceof Error?e.name&&e.message?`${e.name}: ${e.message}`:e.name:`Encountered unknown ${t} error: ${String(e)}`}var Wc=`lk_e2ee`,Gc=`lk_e2ee_track_id`,Kc;(function(e){e.SetKey=`setKey`,e.RatchetRequest=`ratchetRequest`,e.KeyRatcheted=`keyRatcheted`})(Kc||={});var qc;(function(e){e.KeyRatcheted=`keyRatcheted`})(qc||={});var Jc;(function(e){e.ParticipantEncryptionStatusChanged=`participantEncryptionStatusChanged`,e.EncryptionError=`encryptionError`})(Jc||={});var Yc;(function(e){e.Error=`cryptorError`})(Yc||={});function Xc(){return Qc()||Zc()}function Zc(){return typeof window<`u`&&window.RTCRtpScriptTransform!==void 0}function Qc(){return typeof window<`u`&&window.RTCRtpSender!==void 0&&window.RTCRtpSender.prototype.createEncodedStreams!==void 0}function $c(e){if(e.value?.case!==`sipDtmf`&&e.value?.case!==`metrics`&&e.value?.case!==`speaker`&&e.value?.case!==`transcription`&&e.value?.case!==`encryptedPacket`)return new In({value:e.value})}Yi.EventEmitter;var el;(function(e){e[e.InvalidKey=0]=`InvalidKey`,e[e.MissingKey=1]=`MissingKey`,e[e.InternalError=2]=`InternalError`})(el||={});var tl=class extends go{constructor(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:el.InternalError,n=arguments.length>2?arguments[2]:void 0;super(40,e),this.reason=t,this.participantIdentity=n}};function nl(){return ks()}function rl(e){return!!e?.worker&&(Qc()||nl())}function il(e){return!!(e?.timestamp||e?.frameId)}function al(e){let t=[];return e?.timestamp&&t.push(pn.PTF_USER_TIMESTAMP),e?.frameId&&t.push(pn.PTF_FRAME_ID),t}function ol(e){if(!e||e.length===0)return;let t={};return e.includes(pn.PTF_USER_TIMESTAMP)&&(t.timestamp=!0),e.includes(pn.PTF_FRAME_ID)&&(t.frameId=!0),t.timestamp||t.frameId?t:void 0}function sl(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:50,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r,i=n.isImmediate??!1,a=n.callback??!1,o=n.maxWait,s=Date.now(),c=[];function l(){if(o!==void 0){let e=Date.now()-s;if(e+t>=o)return o-e}return t}let u=function(){var t=[...arguments];let n=this;return new Promise((o,u)=>{let d=function(){if(r=void 0,s=Date.now(),!i){let r=e.apply(n,t);a&&a(r),c.forEach(e=>{let t=e.resolve;return t(r)}),c=[]}},f=i&&r===void 0;if(r!==void 0&&F.clearTimeout(r),r=F.setTimeout(d,l()),f){let r=e.apply(n,t);return a&&a(r),o(r)}c.push({resolve:o,reject:u})})};return u.cancel=function(e){r!==void 0&&F.clearTimeout(r),c.forEach(t=>{let n=t.reject;return n(e)}),c=[]},u}var cl=2e3;function ll(e,t){if(!t)return 0;let n,r;return`bytesReceived`in e?(n=e.bytesReceived,r=t.bytesReceived):`bytesSent`in e&&(n=e.bytesSent,r=t.bytesSent),n===void 0||r===void 0||e.timestamp===void 0||t.timestamp===void 0?0:(n-r)*8*1e3/(e.timestamp-t.timestamp)}var ul=class extends H{constructor(e,t,n,r,i){super(e,n,i),this.timeSyncLoop=()=>{if(this.listenerCount(z.TimeSyncUpdate)===0){this.timeSyncHandle=void 0;return}this.timeSyncHandle=requestAnimationFrame(this.timeSyncLoop);let e=this.receiver?.getSynchronizationSources()[0];if(e){let t=e.timestamp,n=e.rtpTimestamp;n&&this.rtpTimestamp!==n&&(this.emit(z.TimeSyncUpdate,{timestamp:t,rtpTimestamp:n}),this.rtpTimestamp=n)}},this.onTimeSyncListenerAdded=e=>{e===z.TimeSyncUpdate&&this.timeSyncHandle===void 0&&(this.timeSyncHandle=requestAnimationFrame(this.timeSyncLoop))},this.sid=t,this.receiver=r}get isLocal(){return!1}setMuted(e){this.isMuted!==e&&(this.isMuted=e,this._mediaStreamTrack.enabled=!e,this.emit(e?z.Muted:z.Unmuted,this))}setMediaStream(e){this.mediaStream=e;let t=n=>{n.track===this._mediaStreamTrack&&(e.removeEventListener(`removetrack`,t),this.receiver&&`playoutDelayHint`in this.receiver&&(this.receiver.playoutDelayHint=void 0),this.receiver=void 0,this._currentBitrate=0,this.emit(z.Ended,this))};e.addEventListener(`removetrack`,t)}start(){this.startMonitor(),super.enable()}stop(){this.stopMonitor(),super.disable()}getRTCStatsReport(){return O(this,void 0,void 0,function*(){if(this.receiver?.getStats)return yield this.receiver.getStats()})}setPlayoutDelay(e){this.receiver?`playoutDelayHint`in this.receiver?this.receiver.playoutDelayHint=e:this.log.warn(`Playout delay not supported in this browser`):this.log.warn(`Cannot set playout delay, track already ended`)}getPlayoutDelay(){if(this.receiver){if(`playoutDelayHint`in this.receiver)return this.receiver.playoutDelayHint;this.log.warn(`Playout delay not supported in this browser`)}else this.log.warn(`Cannot get playout delay, track already ended`);return 0}startMonitor(){this.monitorInterval||=setInterval(()=>this.monitorReceiver(),cl),es()&&this.registerTimeSyncUpdate()}stopMonitor(){super.stopMonitor(),this.off(`newListener`,this.onTimeSyncListenerAdded)}registerTimeSyncUpdate(){let e=this;e.off(`newListener`,this.onTimeSyncListenerAdded),e.on(`newListener`,this.onTimeSyncListenerAdded),this.timeSyncHandle===void 0&&this.timeSyncLoop()}},dl=100,fl=class extends ul{constructor(e,t,n,r,i){super(e,t,H.Kind.Video,n,i),this.elementInfos=[],this.monitorReceiver=()=>O(this,void 0,void 0,function*(){if(!this.receiver){this._currentBitrate=0;return}let e=yield this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=ll(e,this.prevStats)),this.prevStats=e}),this.debouncedHandleResize=sl(()=>{this.updateDimensions()},dl),this.adaptiveStreamSettings=r}get isAdaptiveStream(){return this.adaptiveStreamSettings!==void 0}lookupFrameMetadata(e){let t=e.rtpTimestamp;return this.frameMetadataExtractor?.lookupMetadata(t)}setStreamState(e){super.setStreamState(e),this.log.debug(`setStreamState`,e),this.isAdaptiveStream&&e===H.StreamState.Active&&this.updateVisibility()}get mediaStreamTrack(){return this._mediaStreamTrack}setMuted(e){super.setMuted(e),this.attachedElements.forEach(t=>{e?ds(this._mediaStreamTrack,t):us(this._mediaStreamTrack,t)})}attach(e){if(e?super.attach(e):e=super.attach(),this.adaptiveStreamSettings&&this.elementInfos.find(t=>t.element===e)===void 0){let t=new pl(e);this.observeElementInfo(t)}return e}observeElementInfo(e){this.adaptiveStreamSettings&&this.elementInfos.find(t=>t===e)===void 0?(e.handleResize=()=>{this.debouncedHandleResize()},e.handleVisibilityChanged=()=>{this.updateVisibility()},this.elementInfos.push(e),e.observe(),this.debouncedHandleResize(),this.updateVisibility()):this.log.warn(`visibility resize observer not triggered`,this.logContext)}stopObservingElementInfo(e){if(!this.isAdaptiveStream){this.log.warn(`stopObservingElementInfo ignored`,this.logContext);return}let t=this.elementInfos.filter(t=>t===e);for(let e of t)e.stopObserving();this.elementInfos=this.elementInfos.filter(t=>t!==e),this.updateVisibility(),this.debouncedHandleResize()}detach(e){if(e)return this.stopObservingElement(e),super.detach(e);let t=super.detach();for(let e of t)this.stopObservingElement(e);return t}getDecoderImplementation(){return this.prevStats?.decoderImplementation}getReceiverStats(){return O(this,void 0,void 0,function*(){if(!this.receiver||!this.receiver.getStats)return;let e=yield this.receiver.getStats(),t,n=``,r=new Map;return e.forEach(e=>{e.type===`inbound-rtp`?(n=e.codecId,t={type:`video`,streamId:e.id,framesDecoded:e.framesDecoded,framesDropped:e.framesDropped,framesReceived:e.framesReceived,packetsReceived:e.packetsReceived,packetsLost:e.packetsLost,frameWidth:e.frameWidth,frameHeight:e.frameHeight,pliCount:e.pliCount,firCount:e.firCount,nackCount:e.nackCount,jitter:e.jitter,timestamp:e.timestamp,bytesReceived:e.bytesReceived,decoderImplementation:e.decoderImplementation}):e.type===`codec`&&r.set(e.id,e)}),t&&n!==``&&r.get(n)&&(t.mimeType=r.get(n).mimeType),t})}stopObservingElement(e){let t=this.elementInfos.filter(t=>t.element===e);for(let e of t)this.stopObservingElementInfo(e)}handleAppVisibilityChanged(){let e=Object.create(null,{handleAppVisibilityChanged:{get:()=>super.handleAppVisibilityChanged}});return O(this,void 0,void 0,function*(){yield e.handleAppVisibilityChanged.call(this),this.isAdaptiveStream&&this.updateVisibility()})}updateVisibility(e){let t=this.elementInfos.reduce((e,t)=>Math.max(e,t.visibilityChangedAt||0),0),n=this.adaptiveStreamSettings?.pauseVideoInBackground??!0?this.isInBackground:!1,r=this.elementInfos.some(e=>e.pictureInPicture),i=this.elementInfos.some(e=>e.visible)&&!n||r;(this.lastVisible!==i||e)&&(!i&&Date.now()-t<dl?F.setTimeout(()=>{this.updateVisibility()},dl):(this.lastVisible=i,this.emit(z.VisibilityChanged,i,this)))}updateDimensions(){let e=0,t=0,n=this.getPixelDensity();for(let r of this.elementInfos){let i=r.width()*n,a=r.height()*n;i+a>e+t&&(e=i,t=a)}(this.lastDimensions?.width!==e||this.lastDimensions?.height!==t)&&(this.lastDimensions={width:e,height:t},this.emit(z.VideoDimensionsChanged,this.lastDimensions,this))}getPixelDensity(){let e=this.adaptiveStreamSettings?.pixelDensity;return e===`screen`?Us():e||(Us()>2?2:1)}},pl=class{get visible(){return this.isPiP||this.isIntersecting}get pictureInPicture(){return this.isPiP}constructor(e,t){this.onVisibilityChanged=e=>{var t;let n=e.target,r=e.isIntersecting;n===this.element&&(this.isIntersecting=r,this.isPiP=ml(this.element),this.visibilityChangedAt=Date.now(),(t=this.handleVisibilityChanged)==null||t.call(this))},this.onEnterPiP=()=>{var e;(e=window.documentPictureInPicture?.window)==null||e.addEventListener(`pagehide`,this.onLeavePiP),queueMicrotask(()=>{requestAnimationFrame(()=>{var e;this.isPiP=ml(this.element),(e=this.handleVisibilityChanged)==null||e.call(this)})})},this.onLeavePiP=()=>{var e;this.isPiP=ml(this.element),(e=this.handleVisibilityChanged)==null||e.call(this)},this.element=e,this.isIntersecting=t??gl(e),this.isPiP=W()&&ml(e),this.visibilityChangedAt=0}width(){return this.element.clientWidth}height(){return this.element.clientHeight}observe(){var e,t;this.isIntersecting=gl(this.element),this.isPiP=ml(this.element),this.element.handleResize=()=>{var e;(e=this.handleResize)==null||e.call(this)},this.element.handleVisibilityChanged=this.onVisibilityChanged,Xs().observe(this.element),Js().observe(this.element),this.element.addEventListener(`enterpictureinpicture`,this.onEnterPiP),this.element.addEventListener(`leavepictureinpicture`,this.onLeavePiP),(e=window.documentPictureInPicture)==null||e.addEventListener(`enter`,this.onEnterPiP),(t=window.documentPictureInPicture?.window)==null||t.addEventListener(`pagehide`,this.onLeavePiP)}stopObserving(){var e,t,n,r;(e=Xs())==null||e.unobserve(this.element),(t=Js())==null||t.unobserve(this.element),this.element.removeEventListener(`enterpictureinpicture`,this.onEnterPiP),this.element.removeEventListener(`leavepictureinpicture`,this.onLeavePiP),(n=window.documentPictureInPicture)==null||n.removeEventListener(`enter`,this.onEnterPiP),(r=window.documentPictureInPicture?.window)==null||r.removeEventListener(`pagehide`,this.onLeavePiP)}};function ml(e){if(document.pictureInPictureElement===e)return!0;let t=window.documentPictureInPicture?.window;return t?hl(e.ownerDocument,t)&&gl(e,t):!1}function hl(e,t){if(e.defaultView?.top===t)return!0;let n=e;for(;n;){if(n===t.document)return!0;try{n=n.defaultView?.frameElement?.ownerDocument}catch{return!1}}return!1}function gl(e,t){let n=t||window,r=e.offsetTop,i=e.offsetLeft,a=e.offsetWidth,o=e.offsetHeight,s=e.hidden,c=getComputedStyle(e).display;for(;e.offsetParent;)e=e.offsetParent,r+=e.offsetTop,i+=e.offsetLeft;return r<n.pageYOffset+n.innerHeight&&i<n.pageXOffset+n.innerWidth&&r+o>n.pageYOffset&&i+a>n.pageXOffset&&!s&&c!==`none`}var _l=class e extends Yi.EventEmitter{get logContext(){return{room:this.room?.name,participant:this.room?.localParticipant.identity}}constructor(e,t){super(),this.decryptDataRequests=new Map,this.encryptDataRequests=new Map,this.log=D(T.E2EE,()=>this.logContext),this.onWorkerMessage=e=>{let t=e.data,n=t.kind,r=t.data;switch(n){case`error`:if(r.uuid){let e=this.decryptDataRequests.get(r.uuid);if(e?.reject){e.reject(r.error);break}let t=this.encryptDataRequests.get(r.uuid);if(t?.reject){t.reject(r.error);break}}this.log.error(r.error.message),this.emit(Jc.EncryptionError,r.error,r.participantIdentity);break;case`initAck`:r.enabled&&this.keyProvider.getKeys().forEach(e=>{this.postKey(e,!1)});break;case`enable`:if(r.enabled&&this.keyProvider.getKeys().forEach(e=>{this.postKey(e,!1)}),this.encryptionEnabled!==r.enabled&&r.participantIdentity===this.room?.localParticipant.identity)this.emit(Jc.ParticipantEncryptionStatusChanged,r.enabled,this.room.localParticipant),this.encryptionEnabled=r.enabled;else if(r.participantIdentity){let e=this.room?.getParticipantByIdentity(r.participantIdentity);if(!e)throw TypeError(`couldn't set encryption status, participant not found${r.participantIdentity}`);this.emit(Jc.ParticipantEncryptionStatusChanged,r.enabled,e)}break;case`ratchetKey`:this.keyProvider.emit(Kc.KeyRatcheted,r.ratchetResult,r.participantIdentity,r.keyIndex);break;case`decryptDataResponse`:let e=this.decryptDataRequests.get(r.uuid);e?.resolve&&e.resolve(r);break;case`encryptDataResponse`:let t=this.encryptDataRequests.get(r.uuid);t?.resolve&&t.resolve(r);break;case`packetTrailerMetadata`:this.handleFrameMetadata(r.trackId,r.rtpTimestamp,r.ssrc,r.metadata);break;case`log`:Mi[r.level](r.msg,r.context)}},this.onWorkerError=e=>{this.log.error(`e2ee worker encountered an error:`,{error:e.error}),this.emit(Jc.EncryptionError,e.error,void 0)},this.keyProvider=e.keyProvider,this.worker=e.worker,this.encryptionEnabled=!1,this.dataChannelEncryptionEnabled=t}get isEnabled(){return this.encryptionEnabled}get isDataChannelEncryptionEnabled(){return this.isEnabled&&this.dataChannelEncryptionEnabled}setup(e){if(!Xc())throw new yo(`tried to setup end-to-end encryption on an unsupported browser`);if(this.log.info(`setting up e2ee`),e!==this.room){this.room=e,this.setupEventListeners(e,this.keyProvider);let t={kind:`init`,data:{keyProviderOptions:this.keyProvider.getOptions(),loglevel:Mi.getLevel()}};this.worker&&(this.log.info(`initializing worker`,{worker:this.worker}),this.worker.onmessage=this.onWorkerMessage,this.worker.onerror=this.onWorkerError,this.worker.postMessage(t),this.subscribeToLogLevelChanges())}}subscribeToLogLevelChanges(){var t;(t=this.unsubscribeLogLevel)==null||t.call(this);let n;if(e.disposeRegistry){let t=new WeakRef(this.worker);n=Fi(e=>{let r=t.deref();r?r.postMessage({kind:`setLogLevel`,data:{level:e}}):n?.()}),e.disposeRegistry.register(this,n,this)}else{let e=this.worker;n=Fi(t=>{e.postMessage({kind:`setLogLevel`,data:{level:t}})})}this.unsubscribeLogLevel=n}dispose(){var t,n,r;(t=this.unsubscribeLogLevel)==null||t.call(this),this.unsubscribeLogLevel=void 0,e.disposeRegistry&&e.disposeRegistry.unregister(this);let i=new tl(`E2EEManager disposed`,el.InternalError);for(let e of[...this.encryptDataRequests.values()])(n=e.reject)==null||n.call(e,i);for(let e of[...this.decryptDataRequests.values()])(r=e.reject)==null||r.call(e,i);this.worker&&(this.worker.onmessage=null,this.worker.onerror=null),this.removeAllListeners()}setParticipantCryptorEnabled(e,t){this.log.debug(`set e2ee to ${e} for participant ${t}`),this.postEnable(e,t)}setSifTrailer(e){!e||e.length===0?this.log.warn(`ignoring server sent trailer as it's empty`):this.postSifTrailer(e)}handleFrameMetadata(e,t,n,r){if(this.room){for(let i of[this.room.localParticipant,...this.room.remoteParticipants.values()])for(let a of i.trackPublications.values())if(a.track&&a.track.mediaStreamID===e&&a.track instanceof fl&&a.track.frameMetadataExtractor){a.track.frameMetadataExtractor.storeMetadata(t,n,r);return}}}setupEngine(e){e.on(R.RTPVideoMapUpdate,e=>{this.postRTPMap(e)})}setupEventListeners(e,t){e.on(I.TrackPublished,(e,t)=>this.setParticipantCryptorEnabledForPublication(e,t.identity)),e.on(I.ConnectionStateChanged,t=>{t===$.Connected&&e.remoteParticipants.forEach(e=>{e.trackPublications.forEach(t=>{this.setParticipantCryptorEnabledForPublication(t,e.identity)})})}).on(I.TrackUnsubscribed,(e,t,n)=>{var r;let i={kind:`removeTransform`,data:{participantIdentity:n.identity,trackId:e.mediaStreamID}};(r=this.worker)==null||r.postMessage(i)}).on(I.TrackSubscribed,(e,t,n)=>{this.setupE2EEReceiver(e,n.identity,t.trackInfo)}).on(I.SignalConnected,()=>{if(!this.room)throw TypeError(`expected room to be present on signal connect`);let e=t.getLatestManuallySetKeyIndex();t.getKeys().forEach(t=>{this.postKey(t,e===(t.keyIndex??0))}),this.setParticipantCryptorEnabled(this.room.localParticipant.isE2EEEnabled,this.room.localParticipant.identity)}),e.localParticipant.on(L.LocalSenderCreated,(e,t)=>O(this,void 0,void 0,function*(){this.setupE2EESender(t,e)})),e.localParticipant.on(L.LocalTrackPublished,e=>{if(!yc(e.track)||!js())return;let t={kind:`updateCodec`,data:{trackId:e.track.mediaStreamID,codec:Qo(e.trackInfo.codecs[0].mimeType),participantIdentity:this.room.localParticipant.identity,hasPacketTrailer:!1}};this.worker.postMessage(t)}),t.on(Kc.SetKey,(e,t)=>this.postKey(e,t??!0)).on(Kc.RatchetRequest,(e,t)=>this.postRatchetRequest(e,t))}encryptData(e){return O(this,void 0,void 0,function*(){if(!this.worker)throw Error(`could not encrypt data, worker is missing`);let t=crypto.randomUUID(),n={kind:`encryptDataRequest`,data:{uuid:t,payload:e,participantIdentity:this.room.localParticipant.identity}},r=new G;return r.onFinally=()=>{this.encryptDataRequests.delete(t)},this.encryptDataRequests.set(t,r),this.worker.postMessage(n),r.promise})}handleEncryptedData(e,t,n,r){if(!this.worker)throw Error(`could not handle encrypted data, worker is missing`);let i=crypto.randomUUID(),a={kind:`decryptDataRequest`,data:{uuid:i,payload:e,iv:t,participantIdentity:n,keyIndex:r}},o=new G;return o.onFinally=()=>{this.decryptDataRequests.delete(i)},this.decryptDataRequests.set(i,o),this.worker.postMessage(a),o.promise}postRatchetRequest(e,t){if(!this.worker)throw Error(`could not ratchet key, worker is missing`);let n={kind:`ratchetRequest`,data:{participantIdentity:e,keyIndex:t}};this.worker.postMessage(n)}postKey(e,t){let n=e.key,r=e.participantIdentity,i=e.keyIndex;if(!this.worker)throw Error(`could not set key, worker is missing`);let a={kind:`setKey`,data:{participantIdentity:r,isPublisher:r===this.room?.localParticipant.identity,key:n,keyIndex:i,updateCurrentKeyIndex:t}};this.worker.postMessage(a)}postEnable(e,t){if(this.worker){let n={kind:`enable`,data:{enabled:e,participantIdentity:t}};this.worker.postMessage(n)}else throw ReferenceError(`failed to enable e2ee, worker is not ready`)}postRTPMap(e){if(!this.worker)throw TypeError(`could not post rtp map, worker is missing`);if(!this.room?.localParticipant.identity)throw TypeError(`could not post rtp map, local participant identity is missing`);let t={kind:`setRTPMap`,data:{map:e,participantIdentity:this.room.localParticipant.identity}};this.worker.postMessage(t)}postSifTrailer(e){if(!this.worker)throw Error(`could not post SIF trailer, worker is missing`);let t={kind:`setSifTrailer`,data:{trailer:e}};this.worker.postMessage(t)}setParticipantCryptorEnabledForPublication(e,t){e.trackInfo?this.setParticipantCryptorEnabled(e.trackInfo.encryption!==S.NONE,t):this.log.warn(`skipping e2ee enabled update for publication without trackInfo`,{trackSid:e.trackSid})}setupE2EEReceiver(e,t,n){if(!e.receiver)return;if(!n?.mimeType||n.mimeType===``)throw TypeError(`MimeType missing from trackInfo, cannot set up E2EE cryptor`);let r=e.kind===`video`&&!!n.packetTrailerFeatures&&n.packetTrailerFeatures.length>0;this.handleReceiver(e.receiver,e.mediaStreamID,t,e.kind===`video`?Qo(n.mimeType):void 0,r)}setupE2EESender(e,t){if(!_c(e)||!t){t||this.log.warn(`early return because sender is not ready`);return}let n=yc(e),r=n?e.publishOptions?.videoCodec:void 0;this.handleSender(t,e.mediaStreamID,r===`h264`||r===`h265`?r:void 0,n?e.publishOptions?.frameMetadata??e.publishOptions?.packetTrailer:void 0)}handleReceiver(e,t,n,r,i){return O(this,void 0,void 0,function*(){if(this.worker){if(ks()){let a={kind:`decode`,participantIdentity:n,trackId:t,codec:r,hasPacketTrailer:i};e.transform=new RTCRtpScriptTransform(this.worker,a)}else{if(Wc in e&&Gc in e){let a={kind:`updateCodec`,data:{trackId:t,previousTrackId:e[Gc],codec:r,participantIdentity:n,hasPacketTrailer:i}};this.worker.postMessage(a),e[Gc]=t;return}let a=e.writableStream,o=e.readableStream;if(!a||!o){let t=e.createEncodedStreams();e.writableStream=t.writable,a=t.writable,e.readableStream=t.readable,o=t.readable}let s={kind:`decode`,data:{readableStream:o,writableStream:a,trackId:t,codec:r,participantIdentity:n,hasPacketTrailer:i}};this.worker.postMessage(s,[o,a])}e[Wc]=!0,e[Gc]=t}})}handleSender(e,t,n,r){if(!(Wc in e||!this.worker)){if(!this.room?.localParticipant.identity||this.room.localParticipant.identity===``)throw TypeError(`local identity needs to be known in order to set up encrypted sender`);if(ks()){this.log.info(`initialize script transform`);let i={kind:`encode`,participantIdentity:this.room.localParticipant.identity,trackId:t,codec:n,hasPacketTrailer:il(r),packetTrailer:r};e.transform=new RTCRtpScriptTransform(this.worker,i)}else{this.log.info(`initialize encoded streams`);let i=e.createEncodedStreams(),a={kind:`encode`,data:{readableStream:i.readable,writableStream:i.writable,codec:n,trackId:t,participantIdentity:this.room.localParticipant.identity,hasPacketTrailer:il(r),packetTrailer:r}};this.worker.postMessage(a,[i.readable,i.writable])}e[Wc]=!0}}};_l.disposeRegistry=typeof FinalizationRegistry<`u`&&typeof WeakRef<`u`&&new FinalizationRegistry(e=>{e()});var vl=300,yl=class{constructor(){this.metadataMap=new Map,this.activeSsrc=0}storeMetadata(e,t,n){for(this.activeSsrc!==0&&this.activeSsrc!==t&&this.metadataMap.clear(),this.activeSsrc=t;this.metadataMap.size>=vl;){let e=this.metadataMap.keys().next().value;this.metadataMap.delete(e)}this.metadataMap.set(e,n)}lookupMetadata(e){return this.metadataMap.get(e)}dispose(){this.metadataMap.clear(),this.activeSsrc=0}},bl=class{constructor(e){this.extractors=new Map,this.workerPipelines=new Map,this.onWorkerMessage=e=>{let t=e.data;if(t.kind===`metadata`){let e=this.extractors.get(t.data.trackId);e&&e.storeMetadata(t.data.rtpTimestamp,t.data.ssrc,t.data.metadata)}},this.onWorkerError=e=>{E.error(`frame metadata worker encountered an error:`,{error:e.error})},this.worker=e?.worker}setup(e){e!==this.room&&(this.room=e,this.worker&&(this.worker.onmessage=this.onWorkerMessage,this.worker.onerror=this.onWorkerError,this.worker.postMessage({kind:`init`})),e.on(I.TrackSubscribed,(e,t,n)=>{e.kind===`video`&&this.setupReceiver(e,t.trackInfo)}).on(I.TrackUnsubscribed,e=>{this.teardownTrack(e)}).on(I.Disconnected,()=>{this.cleanup()}))}setupReceiver(e,t){let n=e.receiver;if(!n)return;if(!(t?.packetTrailerFeatures&&t.packetTrailerFeatures.length>0)){this.room?.hasE2EESetup||this.setupPassthroughReceiver(n,e.mediaStreamID);return}if(!rl(this.worker?{worker:this.worker}:void 0)&&!this.room?.hasE2EESetup){E.warn(`frame metadata transform not supported; skipping extraction`);return}let r=new yl,i=e.mediaStreamID;this.extractors.set(i,r),e.frameMetadataExtractor=r,!this.room?.hasE2EESetup&&this.setupWorkerReceiver(n,i,!0)}setupPassthroughReceiver(e,t){nl()?`transform`in e&&(e.transform=null):(this.worker&&rl({worker:this.worker})&&!this.workerPipelines.has(e)||this.worker&&this.workerPipelines.has(e))&&this.setupWorkerReceiver(e,t,!1)}setupWorkerReceiver(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r=this.worker;if(!r)return;if(nl()){e.transform=new RTCRtpScriptTransform(r,{kind:`decode`,trackId:t});return}let i=this.workerPipelines.get(e);if(i){let a={kind:`updateTrackId`,data:{oldTrackId:i,newTrackId:t,hasPacketTrailer:n}};r.postMessage(a),this.workerPipelines.set(e,t);return}if(!(`createEncodedStreams`in e)){E.warn(`createEncodedStreams not supported`);return}let a;try{a=e.createEncodedStreams()}catch(e){E.warn(`failed to create encoded streams`,{error:e});return}let o={kind:`decode`,data:{readableStream:a.readable,writableStream:a.writable,trackId:t,hasPacketTrailer:n}};r.postMessage(o,[a.readable,a.writable]),this.workerPipelines.set(e,t)}teardownTrack(e){let t=e.mediaStreamID,n=this.extractors.get(t);n&&(n.dispose(),this.extractors.delete(t)),e instanceof fl&&(e.frameMetadataExtractor=void 0)}cleanup(){var e;for(let e of this.extractors.values())e.dispose();this.extractors.clear(),this.workerPipelines.clear(),(e=this.worker)==null||e.terminate()}},xl=500,Sl=15e3,Cl=class e{constructor(){this.failedConnectionAttempts=new Map,this.backOffPromises=new Map}static getInstance(){return this._instance||=new e,this._instance}addFailedConnectionAttempt(e){let t=Bs(new URL(e));if(!t)return;let n=this.failedConnectionAttempts.get(t)??0;this.failedConnectionAttempts.set(t,n+1),this.backOffPromises.set(t,U(Math.min(xl*2**n,Sl)))}getBackOffPromise(e){let t=new URL(e),n=t&&Bs(t);return n&&this.backOffPromises.get(n)||Promise.resolve()}resetFailedConnectionAttempts(e){let t=new URL(e),n=t&&Bs(t);n&&(this.failedConnectionAttempts.set(n,0),this.backOffPromises.set(n,Promise.resolve()))}resetAll(){this.backOffPromises.clear(),this.failedConnectionAttempts.clear()}};Cl._instance=null;var wl=`default`,Tl=class e{constructor(){this._previousDevices=[]}static getInstance(){return this.instance===void 0&&(this.instance=new e),this.instance}get previousDevices(){return this._previousDevices}getDevices(t){return O(this,arguments,void 0,function(t){var n=this;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return function*(){if(e.userMediaPromiseMap?.size>0){E.debug(`awaiting getUserMedia promise`);try{t?yield e.userMediaPromiseMap.get(t):yield Promise.all(e.userMediaPromiseMap.values())}catch{E.warn(`error waiting for media permissons`)}}let i=yield navigator.mediaDevices.enumerateDevices();if(r&&!(As()&&n.hasDeviceInUse(t))&&(i.filter(e=>e.kind===t).length===0||i.some(e=>{let n=e.label===``,r=!t||e.kind===t;return n&&r}))){let e={video:t!==`audioinput`&&t!==`audiooutput`,audio:t!==`videoinput`&&{deviceId:{ideal:`default`}}},n=yield navigator.mediaDevices.getUserMedia(e);i=yield navigator.mediaDevices.enumerateDevices(),n.getTracks().forEach(e=>{e.stop()})}return n._previousDevices=i,t&&(i=i.filter(e=>e.kind===t)),i}()})}normalizeDeviceId(e,t,n){return O(this,void 0,void 0,function*(){if(t!==wl)return t;let r=yield this.getDevices(e),i=r.find(e=>e.deviceId===wl);if(!i){E.warn(`could not reliably determine default device`);return}let a=r.find(e=>e.deviceId!==wl&&e.groupId===(n??i.groupId));if(!a)E.warn(`could not reliably determine default device`);else return a?.deviceId})}hasDeviceInUse(t){return t?e.userMediaPromiseMap.has(t):e.userMediaPromiseMap.size>0}};Tl.mediaDeviceKinds=[`audioinput`,`audiooutput`,`videoinput`],Tl.userMediaPromiseMap=new Map;var El=65535,Dl=4294967295,Ol=class e{static u16(t){return new e(t,El)}static u32(t){return new e(t,Dl)}constructor(e,t){if(this.value=e,e<0)throw Error(`WrapAroundUnsignedInt: cannot faithfully represent an integer smaller than 0`);if(t>2**53-1)throw Error(`WrapAroundUnsignedInt: cannot faithfully represent an integer bigger than MAX_SAFE_INTEGER.`);this.maxSize=t,this.clamp()}clamp(){for(;this.value>this.maxSize;)this.value-=this.maxSize+1;for(;this.value<0;)this.value+=this.maxSize+1}clone(){return new e(this.value,this.maxSize)}update(e){this.value=e(this.value),this.clamp()}increment(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1;this.update(t=>t+e)}decrement(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1;this.update(t=>t-e)}getThenIncrement(){let t=this.value;return this.increment(),new e(t,this.maxSize)}isBefore(e){let t=this.value>>>0,n=(e.value>>>0)-t>>>0;return n!==0&&n<this.maxSize+1}},kl=class e{static fromRtpTicks(t){return new e(t,9e4)}static rtpRandom(){let t=Math.round(Math.random()*Dl);return e.fromRtpTicks(t)}constructor(e,t){this.timestamp=Ol.u32(e),this.rateInHz=t}asTicks(){return this.timestamp.value}clone(){return new e(this.timestamp.value,this.rateInHz)}wrappingAdd(e){this.timestamp.increment(e)}isBefore(e){return this.timestamp.isBefore(e.timestamp)}},Al=class e{constructor(e,t,n){this.epoch=t,this.base=n,this.previous=n.clone(),this.rateInHz=e}static startingNow(t,n){return new e(n,new Date,t)}static startingAtTime(t,n,r){return new e(r,t,n)}static rtpStartingNow(t){return e.startingNow(t,9e4)}static rtpStartingAtTime(t,n){return e.startingAtTime(t,n,9e4)}now(){return this.at(new Date)}at(t){let n=t.getTime()-this.epoch.getTime(),r=e.durationInMsToTicks(n,this.rateInHz),i=this.base.clone();return i.wrappingAdd(r),i.isBefore(this.previous)&&(i=this.previous),this.previous=i.clone(),i.clone()}static durationInMsToTicks(e,t){let n=(e*1e6*t+5e8)/1e9;return Math.round(n)}};function jl(e){if(e instanceof DataView)return e;if(e instanceof ArrayBuffer)return new DataView(e);if(e instanceof Uint8Array)return new DataView(e.buffer,e.byteOffset,e.byteLength);throw Error(`Error coercing ${e} to DataView - input was not DataView, ArrayBuffer, or Uint8Array.`)}var Ml;(function(e){e[e.Reserved=0]=`Reserved`,e[e.TooLarge=1]=`TooLarge`})(Ml||={});var Nl=class e extends _o{constructor(e,t){super(19,e),this.name=`DataTrackHandleError`,this.reason=t,this.reasonName=Ml[t]}isReason(e){return this.reason===e}static tooLarge(){return new e(`Value too large to be a valid track handle`,Ml.TooLarge)}static reserved(t){return new e(`0x${t.toString(16)} is a reserved value.`,Ml.Reserved)}},Pl={fromNumber(e){if(e===0)throw Nl.reserved(e);if(e>El)throw Nl.tooLarge();return e}},Fl=class{constructor(){this.value=0}get(){return this.value+=1,this.value>El?null:this.value}reset(){this.value=0}},Il={from(e){return{sid:e.sid,pubHandle:e.pubHandle,name:e.name,usesE2ee:e.encryption!==S.NONE}},toProtobuf(e){return new Cn({sid:e.sid,pubHandle:e.pubHandle,name:e.name,encryption:e.usesE2ee?S.GCM:S.NONE})}},Ll;(function(e){e[e.WAITING=0]=`WAITING`,e[e.RUNNING=1]=`RUNNING`,e[e.COMPLETED=2]=`COMPLETED`})(Ll||={});var Rl=class{constructor(){this.pendingTasks=new Map,this.taskMutex=new i,this.nextTaskIndex=0}run(e){return O(this,void 0,void 0,function*(){let t={id:this.nextTaskIndex++,enqueuedAt:Date.now(),status:Ll.WAITING};this.pendingTasks.set(t.id,t);let n=yield this.taskMutex.lock();try{return t.executedAt=Date.now(),t.status=Ll.RUNNING,yield e()}finally{t.status=Ll.COMPLETED,this.pendingTasks.delete(t.id),n()}})}flush(){return O(this,void 0,void 0,function*(){return this.run(()=>O(this,void 0,void 0,function*(){}))})}snapshot(){return Array.from(this.pendingTasks.values())}};function zl(e){if(e.length===0)return new AbortController().signal;if(e.length===1)return e[0];for(let t of e)if(t.aborted)return t;let t=new AbortController,n=Array(e.length),r=()=>{for(let e of n)e()};return e.forEach((e,i)=>{let a=()=>{t.abort(e.reason),r()};e.addEventListener(`abort`,a),n[i]=()=>e.removeEventListener(`abort`,a)}),t.signal}function Bl(e){let t=new AbortController;return setTimeout(()=>{t.abort(new DOMException(`signal timed out after ${e} ms`,`TimeoutError`))},e),t.signal}var Vl=[`client`],Hl=class{constructor(){g(this,`listeners`,new Map)}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),{off:()=>{n.delete(t)}}}emit(e,t){let n=this.listeners.get(`*`);if(n)for(let r of n)r(e,t);let r=this.listeners.get(e);if(r)for(let e of r)e(t)}clear(){this.listeners.clear()}},Ul=class extends Error{constructor(e,t){super(`non-serializable value at ${e} (${t})`),this.path=e,this.label=t}},Wl=(e,t)=>Gl(e,t,new Set),Gl=(e,t,n)=>{if(e===null)return null;switch(typeof e){case`string`:case`boolean`:return e;case`number`:if(!Number.isFinite(e))throw new Ul(t,ql(e));return e;case`object`:return Kl(e,t,n);default:throw new Ul(t,typeof e)}},Kl=(e,t,n)=>{if(n.has(e))throw new Ul(t,`circular reference`);if(Array.isArray(e)){if(e.length!==Object.keys(e).length)throw new Ul(t,`sparse array or array with non-index properties`);n.add(e);let r=e.map((e,r)=>Gl(e,`${t}[${r}]`,n));return n.delete(e),r}let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new Ul(t,e.constructor?.name??`object`);n.add(e);let i={};for(let r of Object.keys(e)){let a=Gl(e[r],`${t}.${r}`,n);Object.defineProperty(i,r,{value:a,enumerable:!0,writable:!0,configurable:!0})}return n.delete(e),i},ql=e=>Number.isNaN(e)?`NaN`:e>0?`Infinity`:`-Infinity`,Jl=function(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:new Set;if(typeof e!=`object`||!e||t.has(e))return e;if(Array.isArray(e)){t.add(e);let n=e.map(e=>Jl(e,t));return t.delete(e),n}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)return e;t.add(e);let r={};for(let n of Object.keys(e)){let i=Jl(e[n],t);Object.defineProperty(r,n,{value:i,enumerable:!0,writable:!0,configurable:!0})}return t.delete(e),r},Yl=Symbol(`machina.type`),Xl=20,Zl=class{constructor(e){g(this,`id`,void 0),g(this,`initialState`,void 0),g(this,Yl,`BehavioralFsm`),g(this,`states`,void 0),g(this,`emitter`,new Hl),g(this,`clients`,new WeakMap),g(this,`knownClients`,new Set),g(this,`childSubscriptions`,[]),g(this,`disposed`,!1),g(this,`transitionDepth`,0),this.id=e.id,this.initialState=e.initialState,this.states=e.states,this.wrapChildLinks(),this.setupChildSubscriptions()}handle(e,t){if(this.disposed)return;let n=this.getOrCreateClientMeta(e);var r=[...arguments].slice(2);n.currentActionArgs=r;let i=this.states[n.state]?._child;if(i&&i.canHandle(e,t))try{i.handle(e,t,...r)}finally{n.currentActionArgs=void 0}else this.handleLocally(e,t,r,n)}canHandle(e,t){if(this.disposed)return!1;let n=this.clients.get(e)?.state??this.initialState,r=this.states[n];if(r?.[t]??r?.[`*`])return!0;let i=r?._child;return i?i.canHandle(e,t):!1}reset(e){this.disposed||this.transition(e,this.initialState)}currentState(e){return this.clients.get(e)?.state}transition(e,t){if(this.disposed)return;let n=this.getOrCreateClientMeta(e),r=n.state;if(t!==r){if(!Object.hasOwn(this.states,t))this.emitter.emit(`invalidstate`,{stateName:t,client:e});else{if(this.transitionDepth++,this.transitionDepth>Xl)throw this.transitionDepth=0,Error(`Max transition depth (${Xl}) exceeded in FSM "${this.id}". Likely an infinite _onEnter → transition loop.`);try{let i=this.states[r],a=this.states[t];if(i!=null&&i._onExit&&typeof i._onExit==`function`){let t=this.buildHandlerArgs(e,``,n);i._onExit(t)}n.state=t;let o={fromState:r,toState:t,client:e};this.emitter.emit(`transitioning`,o);let s;if(a!=null&&a._onEnter&&typeof a._onEnter==`function`){let t=this.buildHandlerArgs(e,``,n);s=a._onEnter(t)}this.emitter.emit(`transitioned`,o);let c=a?._child;c&&c.reset(e),this.processQueue(e,n),typeof s==`string`&&n.state===t&&this.transition(e,s)}finally{this.transitionDepth--}}}}compositeState(e){let t=this.clients.get(e);if(!t)return``;let n=this.states[t.state]?._child;if(n){let r=n.compositeState(e);if(r)return`${t.state}.${r}`}return t.state}rehydrate(e,t){if(this.disposed)return;if(typeof t==`string`){this.rehydrateCompositePath(e,t);return}let n=this.planSnapshotWrites(e,t);for(let e of n)e()}dehydrate(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,n=this.clients.get(e);if(!n)return;let r={state:n.state,deferred:n.deferredQueue.map(e=>this.snapshotDeferredInput(e))},i=this.collectChildSnapshots(e,n.state,t);return i&&(r.children=i),r}planSnapshotWrites(e,t){if(this.disposed)return[];let n=t.state,r=t.deferred,i=t.children;if(!Object.hasOwn(this.states,n))throw Error(`rehydrate: unknown state "${n}" in FSM "${this.id}". Valid states: ${Object.keys(this.states).join(`, `)}`);let a=[];if(i)for(let t of Object.keys(i)){if(!Object.hasOwn(this.states,t))throw Error(`rehydrate: unknown state "${t}" in FSM "${this.id}" referenced by snapshot.children.`);let n=this.states[t]?._child;if(!n)throw Error(`rehydrate: state "${t}" in FSM "${this.id}" has no _child, but the snapshot has a children["${t}"] entry.`);a.push(...n.planRehydrate(e,i[t]))}let o=r.map(e=>Me({inputName:e.inputName,args:Jl(e.args)},e.untilState===void 0?{}:{untilState:e.untilState}));return a.push(()=>{this.clients.has(e)||this.knownClients.add(new WeakRef(e)),this.clients.set(e,{state:n,deferredQueue:o})}),a}rehydrateCompositePath(e,t){let n=Fe(t.split(`.`)),r=n[0],i=Ee(n).slice(1);if(!Object.hasOwn(this.states,r))throw Error(`rehydrate: unknown state "${r}" in FSM "${this.id}". Valid states: ${Object.keys(this.states).join(`, `)}`);if(i.length>0){let n=i.join(`.`),a=this.states[r]?._child;if(!a)throw Error(`rehydrate: state "${r}" in FSM "${this.id}" has no _child, but composite path "${t}" requires one.`);a.rehydrate(e,n)}this.clients.has(e)||this.knownClients.add(new WeakRef(e)),this.clients.set(e,{state:r,deferredQueue:[]})}collectChildSnapshots(e,t,n){let r=new Map;for(let e of Object.keys(this.states)){let t=this.states[e]?._child;if(!t)continue;let n=r.get(t.instance);n?n.stateNames.push(e):r.set(t.instance,{childLink:t,stateNames:[e]})}let i;for(let a of r.values()){let r=a.childLink,o=a.stateNames,s=n&&o.includes(t);if(r.instance[Yl]===`Fsm`&&!s)continue;let c=r.dehydrate(e,s);if(c){i??={};for(let e of o)i[e]=c}}return i}snapshotDeferredInput(e){let t;try{t=Wl(e.args,`args`)}catch(t){if(!(t instanceof Ul))throw t;let n=e.untilState?` (until "${e.untilState}")`:``;throw Error(`dehydrate: deferred input "${e.inputName}"${n} in FSM "${this.id}" has a non-serializable value at ${t.path} (${t.label})`)}let n={inputName:e.inputName,args:t};return e.untilState!==void 0&&(n.untilState=e.untilState),n}on(e,t){return this.disposed?{off(){}}:this.emitter.on(e,t)}emit(e,t){this.disposed||this.emitter.emit(e,t)}dispose(e){this.disposed=!0;for(let e of this.childSubscriptions)e.off();if(!(e!=null&&e.preserveChildren)){let e=new Set;for(let t of Object.keys(this.states)){let n=this.states[t]?._child;n&&!e.has(n.instance)&&(e.add(n.instance),n.dispose())}}this.emitter.clear()}wrapChildLinks(){for(let e of Object.keys(this.states)){let t=this.states[e],n=t?._child;if(n){if(typeof n!=`object`)throw Error(`State "${e}"._child: expected an Fsm or BehavioralFsm instance, got ${String(n)}`);if(!(Yl in n))throw Error(`State "${e}"._child: expected an Fsm or BehavioralFsm instance, got a plain object`);t._child=Ql(n)}}}setupChildSubscriptions(){let e=new Set;for(let t of Object.keys(this.states)){let n=this.states[t]?._child;if(!n||e.has(n.instance))continue;e.add(n.instance);let r=n.onAny((e,t)=>{if(e===`nohandler`){let e=t;if(e.client!==void 0)this.bubbleNohandler(e.client,n,e.inputName,e.args??[]);else for(let t of this.knownClients){let r=t.deref();r===void 0?this.knownClients.delete(t):this.bubbleNohandler(r,n,e.inputName,e.args??[])}return}let r=t;if(r&&typeof r==`object`&&`client`in r)this.isChildActiveForClient(r.client,n)&&this.emitter.emit(e,t);else for(let r of this.knownClients){let i=r.deref();if(!i)this.knownClients.delete(r);else if(this.isChildActiveForClient(i,n)){this.emitter.emit(e,t);break}}});this.childSubscriptions.push(r)}}bubbleNohandler(e,t,n,r){if(!this.isChildActiveForClient(e,t))return;let i=this.clients.get(e);i.currentActionArgs=r,this.handleLocally(e,n,r,i)}isChildActiveForClient(e,t){var n;let r=this.clients.get(e);return r?((n=this.states[r.state])==null||(n=n._child)==null?void 0:n.instance)===t.instance:!1}handleLocally(e,t,n,r){let i=this.states[r.state],a=i?.[t]??i?.[`*`];if(!a)this.emitter.emit(`nohandler`,{inputName:t,args:n,client:e}),r.currentActionArgs=void 0;else try{this.emitter.emit(`handling`,{inputName:t,client:e});let i=this.buildHandlerArgs(e,t,r),o;typeof a==`string`?o=a:typeof a==`function`&&(o=a(i,...n)),this.emitter.emit(`handled`,{inputName:t,client:e}),typeof o==`string`&&this.transition(e,o)}finally{r.currentActionArgs=void 0}}getOrCreateClientMeta(e){let t=this.clients.get(e);return t||(t={state:void 0,deferredQueue:[]},this.clients.set(e,t),this.knownClients.add(new WeakRef(e)),this.transition(e,this.initialState),t)}buildHandlerArgs(e,t,n){return{ctx:e,inputName:t,defer:r=>{if(!n.currentActionArgs)return;let i={inputName:t,args:[...n.currentActionArgs],untilState:r?.until};n.deferredQueue.push(i),this.emitter.emit(`deferred`,{inputName:t,client:e})},emit:(e,t)=>{this.emitter.emit(e,t)}}}processQueue(e,t){let n=[],r=[];for(let e of t.deferredQueue)e.untilState===void 0||e.untilState===t.state?n.push(e):r.push(e);t.deferredQueue=r;for(let t of n)this.handle(e,t.inputName,...t.args)}};function Ql(e){if(!e||typeof e!=`object`)throw Error(`createChildLink: expected an Fsm or BehavioralFsm instance, got ${String(e)}`);let t=e[Yl];if(t===`BehavioralFsm`)return{instance:e,canHandle(t,n){return e.canHandle(t,n)},handle(t,n){var r=[...arguments].slice(2);e.handle(t,n,...r)},reset(t){e.transition(t,e.initialState)},onAny(t){return e.on(`*`,t)},compositeState(t){return e.compositeState(t)},rehydrate(t,n){e.rehydrate(t,n)},dehydrate(t,n){return e.dehydrate(t,n)},planRehydrate(t,n){return e.planSnapshotWrites(t,n)},dispose(){e.dispose()}};if(t===`Fsm`)return{instance:e,canHandle(t,n){return e.canHandle(n)},handle(t,n){var r=[...arguments].slice(2);e.handle(n,...r)},reset(t){e.reset()},onAny(t){return e.on(`*`,t)},compositeState(t){return e.compositeState()},rehydrate(e,t){throw Error(`rehydrate: cannot rehydrate an Fsm child. Fsm owns its own context; rehydrate is only valid for BehavioralFsm hierarchies.`)},dehydrate(e,t){throw Error(`dehydrate: cannot dehydrate an Fsm child. Fsm owns its own context; dehydrate is only valid for BehavioralFsm hierarchies.`)},planRehydrate(e,t){throw Error(`rehydrate: cannot rehydrate an Fsm child. Fsm owns its own context; rehydrate is only valid for BehavioralFsm hierarchies.`)},dispose(){e.dispose()}};throw Error(`createChildLink: expected an Fsm or BehavioralFsm instance, got [MACHINA_TYPE] = ${String(t??`undefined`)}`)}var $l=class{constructor(e){g(this,`id`,void 0),g(this,`initialState`,void 0),g(this,Yl,`Fsm`),g(this,`states`,void 0),g(this,`bfsm`,void 0),g(this,`context`,void 0),g(this,`emitter`,new Hl),g(this,`disposed`,!1),this.id=e.id,this.initialState=e.initialState,this.context=e.context??{},this.bfsm=new Zl(e),this.states=e.states,this.bfsm.on(`*`,(e,t)=>{if(t&&typeof t==`object`&&`client`in t){t.client;let n=Ne(t,Vl);this.emitter.emit(e,n)}else this.emitter.emit(e,t)}),this.bfsm.transition(this.context,e.initialState)}handle(e){if(!this.disposed){var t=[...arguments].slice(1);this.bfsm.handle(this.context,e,...t)}}canHandle(e){return!this.disposed&&this.bfsm.canHandle(this.context,e)}reset(){this.disposed||this.bfsm.reset(this.context)}currentState(){return this.bfsm.currentState(this.context)}transition(e){this.disposed||this.bfsm.transition(this.context,e)}compositeState(){return this.bfsm.compositeState(this.context)}on(e,t){return this.disposed?{off(){}}:this.emitter.on(e,t)}emit(e,t){this.disposed||this.bfsm.emit(e,t)}dispose(e){this.disposed=!0,this.bfsm.dispose(e),this.emitter.clear()}};function eu(e){return new $l(e)}function tu(e){return e}function nu(e,t){return t.attemptId===e.attemptId}var ru=tu((e,t)=>{let n=e.ctx;if(nu(n,t))return`connected`}),iu=tu(e=>{let t=e.ctx;return t.attemptId+=1,t.lastError=void 0,`connecting`}),au=tu(e=>{let t=e.ctx;return t.attemptId+=1,t.lastError=void 0,`reconnecting`}),ou=tu((e,t)=>{let n=e.ctx;return n.closeReason=t.reason,`disconnecting`}),su={new:{connect:iu,close:ou},connecting:{connectComplete:ru,connectFailed:tu((e,t)=>{let n=e.ctx;return n.lastError=t.error,`closed`}),close:ou},connected:{reconnect:au,transportFailed:tu((e,t)=>{let n=e.ctx;if(nu(n,t))return n.lastError=t.reason,`offline`}),close:ou},offline:{connect:iu,reconnect:au,close:ou},reconnecting:{reconnectComplete:ru,reconnectFailed:tu((e,t)=>{let n=e.ctx;return n.lastError=t.error,t.recoverable?`offline`:`closed`}),close:ou},disconnecting:{closeComplete:`closed`},closed:{connect:iu,reconnect:au}};function cu(){return eu({id:`signal`,initialState:arguments.length>0&&arguments[0]!==void 0?arguments[0]:`new`,context:{attemptId:0},states:su})}var lu=class{get readyState(){return this.ws.readyState}constructor(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(t.signal?.aborted)throw new DOMException(`This operation was aborted`,`AbortError`);this.url=e;let n=new WebSocket(e,t.protocols??[]);n.binaryType=`arraybuffer`,this.ws=n;let r=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=e.closeCode,r=e.reason;return n.close(t,r===void 0?void 0:du(r))};this.opened=new co((e,t)=>{let i=()=>{t(j.websocket(`Encountered websocket error during connection establishment`))};n.onopen=()=>{e({readable:new ReadableStream({start(e){n.onmessage=t=>{let n=t.data;return e.enqueue(n)},n.onerror=t=>e.error(j.websocket(Uc(t,`websocket`))),n.onclose=t=>{t.wasClean||t.code===1e3?e.close():e.error(j.websocket(`WS closed unexpectedly with code ${t.code}`))}},cancel:r}),writable:new WritableStream({write(e){n.send(e)},abort(){n.close()},close:r}),protocol:n.protocol,extensions:n.extensions}),n.removeEventListener(`error`,i)},n.addEventListener(`error`,i)}),this.closed=new co((e,t)=>{let r=()=>O(this,void 0,void 0,function*(){let r=new co(e=>{n.readyState!==WebSocket.CLOSED&&n.addEventListener(`close`,t=>{e(t)},{once:!0})}),i=yield co.race([U(250),r]);i?e(i):t(j.websocket(`Encountered unspecified websocket error without a timely close event`))});n.addEventListener(`close`,t=>{let i=t.code,a=t.reason;e({closeCode:i,reason:a}),n.removeEventListener(`error`,r)}),n.addEventListener(`error`,r)}),t.signal&&(t.signal.onabort=()=>n.close()),this.close=r}},uu=123;function du(e){let t=new TextEncoder;if(t.encode(e).length<=uu)return e;let n=``,r=0;for(let i of e){if(r+=t.encode(i).length,r>uu)break;n+=i}return n}var fu=[`syncState`,`trickle`,`offer`,`answer`,`simulate`,`leave`];function pu(e){return e instanceof j?e.reason!==A.LeaveRequest&&e.reason!==A.NotAllowed:!0}function mu(e){let t=fu.indexOf(e.case)>=0;return E.trace(`request allowed to bypass queue:`,{canPass:t,req:e}),t}var hu;(function(e){e[e.CONNECTING=0]=`CONNECTING`,e[e.CONNECTED=1]=`CONNECTED`,e[e.RECONNECTING=2]=`RECONNECTING`,e[e.DISCONNECTING=3]=`DISCONNECTING`,e[e.DISCONNECTED=4]=`DISCONNECTED`})(hu||={});function gu(e){switch(e){case`connected`:return hu.CONNECTED;case`connecting`:return hu.CONNECTING;case`reconnecting`:return hu.RECONNECTING;case`disconnecting`:return hu.DISCONNECTING;default:return hu.DISCONNECTED}}var _u=250,vu=5e3,yu=class{get currentState(){return gu(this.lifecycleState)}get isDisconnected(){let e=this.currentState;return e===hu.DISCONNECTING||e===hu.DISCONNECTED}get lifecycleState(){return this.machine.currentState()}get attemptId(){return this.machine.context.attemptId}sendLifecycleInput(e){let t=this.lifecycleState;return this.machine.handle(e.type,e),this.lifecycleState!==t}settleInFlightClose(){return O(this,void 0,void 0,function*(){this.log.debug(`waiting for an in-flight close to settle before establishing a session`),(yield this.closingLock.lock())()})}get isEstablishingConnection(){return this.lifecycleState===`connecting`||this.lifecycleState===`reconnecting`}getNextRequestId(){return this._requestId+=1,this._requestId}constructor(){let e=arguments.length>0&&arguments[0]!==void 0&&arguments[0],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.rtt=0,this.log=E,this._requestId=0,this.useV0SignalPath=!1,this.resetCallbacks=()=>{this.onAnswer=void 0,this.onLeave=void 0,this.onLocalTrackPublished=void 0,this.onLocalTrackUnpublished=void 0,this.onNegotiateRequested=void 0,this.onOffer=void 0,this.onRemoteMuteChanged=void 0,this.onSubscribedQualityUpdate=void 0,this.onTokenRefresh=void 0,this.onTrickle=void 0,this.onClose=void 0,this.onMediaSectionsRequirement=void 0},this.loggerContextCb=t.loggerContextCb,this.log=D(t.loggerName??T.Signal,()=>this.logContext),this.useJSON=e,this.requestQueue=new Rl,this.queuedRequests=[],this.closingLock=new i,this.connectionLock=new i,this.machine=cu(),this.machine.on(`transitioned`,e=>{let t=e.fromState,n=e.toState;this.log.debug(`signal lifecycle: ${t} -> ${n}`)}),this.machine.on(`nohandler`,e=>{let t=e.inputName;this.log.debug(`ignoring signal lifecycle input ${t} in state ${this.lifecycleState}`)}),this.machine}get logContext(){return this.loggerContextCb?.call(this)??{}}join(e,t,n,r){return O(this,arguments,void 0,function(e,t,n,r){var i=this;let a=arguments.length>4&&arguments[4]!==void 0&&arguments[4],o=arguments.length>5?arguments[5]:void 0;return function*(){if(i.lifecycleState===`disconnecting`&&(yield i.settleInFlightClose()),!i.sendLifecycleInput({type:`connect`}))throw j.internal(`cannot establish a signal session from '${i.lifecycleState}', close the current one first`);i.options=n;try{return yield i.connect(e,t,n,r,a,o)}catch(e){throw i.sendLifecycleInput({type:`connectFailed`,error:e}),e}}()})}reconnect(e,t,n,r){return O(this,void 0,void 0,function*(){if(!this.options)this.log.warn(`attempted to reconnect without signal options being set, ignoring`);else{if(this.lifecycleState===`disconnecting`&&(yield this.settleInFlightClose()),!this.sendLifecycleInput({type:`reconnect`}))throw j.internal(`cannot resume the signal session from '${this.lifecycleState}'`);this.clearPingInterval();try{return yield this.connect(e,t,Object.assign(Object.assign({},this.options),{reconnect:!0,sid:n,reconnectReason:r}),void 0,this.useV0SignalPath)}catch(e){throw this.sendLifecycleInput({type:`reconnectFailed`,error:e,recoverable:pu(e)}),e}}})}connect(e,t,n,r){return O(this,arguments,void 0,function(e,t,n,r){var i=this;let a=arguments.length>4&&arguments[4]!==void 0&&arguments[4],o=arguments.length>5?arguments[5]:void 0;return function*(){let s=yield i.connectionLock.lock(),c,l;try{i.connectOptions=n,i.useV0SignalPath=a;let r=Zs(n.clientInfoCapabilities);c=Ic(e,a?Su(t,r,n):yield Cu(t,r,n,o),a).toString(),l=Rc(c).toString()}catch(e){throw s(),e}if(r?.aborted)throw s(),i.log.debug(`signal connect abandoned before opening a transport`),j.cancelled(`Connection aborted`);return new Promise((e,t)=>O(i,void 0,void 0,function*(){try{let i=!1,a=e=>O(this,void 0,void 0,function*(){if(i)return;i=!0;let n=Hc(e instanceof Event?e.currentTarget:e,`Abort handler called`);this.streamWriter&&!this.isDisconnected?this.sendLeave().then(()=>this.close(!0,n)).catch(e=>{this.log.error(e),this.close(!0,n)}):this.close(!0,n),o(),t(e instanceof j?e:j.cancelled(n))});r?.addEventListener(`abort`,a);let o=()=>{clearTimeout(s),r?.removeEventListener(`abort`,a)},s=setTimeout(()=>{a(j.timeout(`room connection has timed out (signal)`))},n.websocketTimeout),u=new URL(c);if(u.searchParams.has(`access_token`)&&u.searchParams.set(`access_token`,`<redacted>`),this.ws){let e=performance.now();yield this.teardownTransport(`replaced by a new connection attempt`),this.log.debug(`closed previous ws connection in ${performance.now()-e}ms`)}if(i){this.log.debug(`signal connect abandoned after tearing down the previous transport`);return}let d=this.attemptId;this.log.info(`signal connecting to ${u}`,{reconnect:n.reconnect,reconnectReason:n.reconnectReason}),this.ws=new lu(c);let f=!1;this.ws.opened.catch(()=>{f=!0});try{this.ws.closed.then(e=>{this.isEstablishingConnection&&!f&&t(j.internal(`Websocket got closed during a (re)connection attempt: ${e.reason}`)),this.log.debug(`websocket closed`,{reason:e.reason,code:e.closeCode,attemptId:d,state:this.lifecycleState}),this.handleOnClose(e.reason||(e.closeCode===1e3?`server closed the signal connection`:`Unexpected WS error`),d)}).catch(e=>{this.isEstablishingConnection&&!f&&t(j.internal(`Websocket error during a (re)connection attempt: ${e}`))});let r=yield this.ws.opened.catch(e=>O(this,void 0,void 0,function*(){i?this.log.debug(`signal connect abandoned while the websocket was opening`):this.lifecycleState===`connected`?(this.handleWSError(e),t(e)):(clearTimeout(s),t(yield this.handleConnectionError(e,l)))}));if(clearTimeout(s),!r)return;let a=r.readable.getReader();this.streamWriter=r.writable.getWriter();let o;try{let e=Date.now()+vu;for(;;){let t=e-Date.now();if(t<=0)throw j.timeout(`signal connection timed out while waiting for the first message`);let n,r=yield Promise.race([a.read(),new Promise((e,r)=>{n=setTimeout(()=>{r(j.timeout(`signal connection timed out while waiting for the first message`))},t)})]);if(clearTimeout(n),!r.value)throw j.internal(`no message received as first message`);let i=Vc(r.value);if(this.lifecycleState===`reconnecting`&&i.message?.case!==`reconnect`&&i.message?.case!==`leave`)this.log.warn(`dropping signal message while awaiting reconnect response`,{messageCase:i.message?.case});else{o=i;break}}}catch(e){a.releaseLock(),t(e),this.close();return}if(a.releaseLock(),i){this.log.debug(`signal connect abandoned while waiting for the first message`);return}let c=this.validateFirstMessage(o,n.reconnect??!1);if(!c.isValid){t(c.error);return}o.message?.case===`join`&&(this.pingTimeoutDuration=o.message.value.pingTimeout,this.pingIntervalDuration=o.message.value.pingInterval,this.pingTimeoutDuration&&this.pingTimeoutDuration>0&&this.log.debug(`ping config`,{timeout:this.pingTimeoutDuration,interval:this.pingIntervalDuration}),this.onJoined&&this.onJoined(o.message.value)),this.handleSignalConnected(r,s,d),e(c.response)}catch(e){t(e)}finally{o()}}finally{s()}}))}()})}startReadingLoop(e){return O(this,void 0,void 0,function*(){let t=this.attemptId;for(;;){this.signalLatency&&(yield U(this.signalLatency));try{let t=yield e.read(),n=t.done,r=t.value;if(n)break;let i=Vc(r);this.handleSignalResponse(i)}catch(e){this.log.error(`error reading from signal stream`,{error:e}),yield this.handleOnClose(`error in reading loop`,t);break}}})}close(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Close method called on signal client`;return function*(){let r=t&&e.sendLifecycleInput({type:`close`,reason:n}),i=yield e.closingLock.lock();try{yield e.teardownTransport(n)}finally{r&&e.sendLifecycleInput({type:`closeComplete`}),i()}}()})}teardownTransport(e){return O(this,void 0,void 0,function*(){try{this.clearPingInterval();let t=this.ws;t&&(this.ws=void 0,this.streamWriter=void 0,t.close({closeCode:1e3,reason:e}),yield Promise.race([t.closed,U(_u)]))}catch(e){this.log.debug(`websocket error while closing`,{error:e})}})}sendOffer(e,t){this.log.debug(`sending offer`,{offerSdp:e.sdp}),this.sendRequest({case:`offer`,value:xu(e,t)})}sendAnswer(e,t){return this.log.debug(`sending answer`,{answerSdp:e.sdp}),this.sendRequest({case:`answer`,value:xu(e,t)})}sendIceCandidate(e,t){return this.log.debug(`sending ice candidate`,{candidate:e}),this.sendRequest({case:`trickle`,value:new wr({candidateInit:JSON.stringify(e),target:t})})}sendMuteTrack(e,t){return this.sendRequest({case:`mute`,value:new Tr({sid:e,muted:t})})}sendAddTrack(e){return this.sendRequest({case:`addTrack`,value:e})}sendUpdateLocalMetadata(e,t){return O(this,arguments,void 0,function(e,t){var n=this;let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return function*(){let i=n.getNextRequestId();return yield n.sendRequest({case:`updateMetadata`,value:new Gr({requestId:i,metadata:e,name:t,attributes:r})}),i}()})}sendUpdateTrackSettings(e){this.sendRequest({case:`trackSetting`,value:e})}sendUpdateSubscription(e){return this.sendRequest({case:`subscription`,value:e})}sendSyncState(e){return this.sendRequest({case:`syncState`,value:e})}sendUpdateVideoLayers(e,t){return this.sendRequest({case:`updateLayers`,value:new Wr({trackSid:e,layers:t})})}sendUpdateSubscriptionPermissions(e,t){return this.sendRequest({case:`subscriptionPermission`,value:new ii({allParticipants:e,trackPermissions:t})})}sendSimulateScenario(e){return this.sendRequest({case:`simulate`,value:e})}sendPing(){return Promise.all([this.sendRequest({case:`ping`,value:m.parse(Date.now())}),this.sendRequest({case:`pingReq`,value:new di({timestamp:m.parse(Date.now()),rtt:m.parse(this.rtt)})})])}sendUpdateLocalAudioTrack(e,t){return this.sendRequest({case:`updateAudioTrack`,value:new Br({trackSid:e,features:t})})}sendLeave(){return this.sendRequest({case:`leave`,value:new Hr({reason:un.CLIENT_INITIATED,action:Ur.DISCONNECT})})}sendPublishDataTrackRequest(e,t,n){return this.sendRequest({case:`publishDataTrackRequest`,value:new vr({pubHandle:e,name:t,encryption:n?S.GCM:S.NONE})})}sendUnPublishDataTrackRequest(e){return this.sendRequest({case:`unpublishDataTrackRequest`,value:new br({pubHandle:e})})}sendUpdateDataSubscription(e,t){return this.sendRequest({case:`updateDataSubscription`,value:new Nr({updates:[new Pr({trackSid:e,subscribe:t})]})})}sendRequest(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return function*(){let r=!n&&!mu(e),i=t.lifecycleState===`reconnecting`||t.queuedRequests.length>0;if(r&&i){t.queuedRequests.push(()=>O(t,void 0,void 0,function*(){yield this.sendRequest(e,!0)}));return}n||(yield t.requestQueue.flush()),t.signalLatency&&(yield U(t.signalLatency));let a=e.case===`leave`&&!!t.streamWriter;if(t.isDisconnected&&!a){t.log.debug(`skipping signal request (type: ${e.case}) - SignalClient disconnected`);return}if(!t.streamWriter){t.log.error(`cannot send signal request before connected, type: ${e?.case}`);return}let o=new mr({message:e});try{t.useJSON?yield t.streamWriter.write(o.toJsonString()):yield t.streamWriter.write(o.toBinary().buffer)}catch(e){t.log.error(`error sending signal message`,{error:e})}}()})}handleSignalResponse(e){let t=e.message;if(t==null){this.log.debug(`received unsupported message`);return}let n=!1;if(t.case===`answer`){let e=bu(t.value);this.onAnswer&&this.onAnswer(e,t.value.id,t.value.midToTrackId)}else if(t.case===`offer`){let e=bu(t.value);this.onOffer&&this.onOffer(e,t.value.id,t.value.midToTrackId)}else if(t.case===`trickle`){let e=JSON.parse(t.value.candidateInit);this.onTrickle&&this.onTrickle(e,t.value.target)}else t.case===`update`?this.onParticipantUpdate&&this.onParticipantUpdate(t.value.participants??[]):t.case===`trackPublished`?this.onLocalTrackPublished&&this.onLocalTrackPublished(t.value):t.case===`speakersChanged`?this.onSpeakersChanged&&this.onSpeakersChanged(t.value.speakers??[]):t.case===`leave`?this.onLeave&&this.onLeave(t.value):t.case===`mute`?this.onRemoteMuteChanged&&this.onRemoteMuteChanged(t.value.sid,t.value.muted):t.case===`roomUpdate`?this.onRoomUpdate&&t.value.room&&this.onRoomUpdate(t.value.room):t.case===`connectionQuality`?this.onConnectionQuality&&this.onConnectionQuality(t.value):t.case===`streamStateUpdate`?this.onStreamStateUpdate&&this.onStreamStateUpdate(t.value):t.case===`subscribedQualityUpdate`?this.onSubscribedQualityUpdate&&this.onSubscribedQualityUpdate(t.value):t.case===`subscriptionPermissionUpdate`?this.onSubscriptionPermissionUpdate&&this.onSubscriptionPermissionUpdate(t.value):t.case===`refreshToken`?this.onTokenRefresh&&this.onTokenRefresh(t.value):t.case===`trackUnpublished`?this.onLocalTrackUnpublished&&this.onLocalTrackUnpublished(t.value):t.case===`subscriptionResponse`?this.onSubscriptionError&&this.onSubscriptionError(t.value):t.case===`pong`||(t.case===`pongResp`?(this.rtt=Date.now()-Number.parseInt(t.value.lastPingTimestamp.toString()),this.resetPingTimeout(),n=!0):t.case===`requestResponse`?this.onRequestResponse&&this.onRequestResponse(t.value):t.case===`trackSubscribed`?this.onLocalTrackSubscribed&&this.onLocalTrackSubscribed(t.value.trackSid):t.case===`roomMoved`?(this.onTokenRefresh&&this.onTokenRefresh(t.value.token),this.onRoomMoved&&this.onRoomMoved(t.value)):t.case===`mediaSectionsRequirement`?this.onMediaSectionsRequirement&&this.onMediaSectionsRequirement(t.value):t.case===`publishDataTrackResponse`?this.onPublishDataTrackResponse&&this.onPublishDataTrackResponse(t.value):t.case===`unpublishDataTrackResponse`?this.onUnPublishDataTrackResponse&&this.onUnPublishDataTrackResponse(t.value):t.case===`dataTrackSubscriberHandles`?this.onDataTrackSubscriberHandles&&this.onDataTrackSubscriberHandles(t.value):this.log.debug(`unsupported message`,{msgCase:t.case}));n||this.resetPingTimeout()}setReconnected(){for(;this.queuedRequests.length>0;){let e=this.queuedRequests.shift();e&&this.requestQueue.run(e)}}handleOnClose(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.attemptId,r=arguments.length>2?arguments[2]:void 0;return function*(){let i=t.onClose;t.sendLifecycleInput({type:`transportFailed`,attemptId:n,reason:e})?(yield t.teardownTransport(e),t.log.info(`websocket connection closed: ${e}`,{reason:e}),r&&(t.log.info(`waiting for ${r}ms until reconnecting signal`),yield U(r)),i&&i(e)):t.log.debug(`ignoring transport close in state ${t.lifecycleState}`,{reason:e,attemptId:n,currentAttemptId:t.attemptId})}()})}handleWSError(e){this.log.error(`websocket error`,{error:e})}resetPingTimeout(){this.clearPingTimeout(),this.pingTimeoutDuration?this.pingTimeout=F.setTimeout(()=>{this.log.warn(`ping timeout triggered. last pong received at: ${new Date(Date.now()-this.pingTimeoutDuration*1e3).toUTCString()}`),this.handleOnClose(`ping timeout`)},this.pingTimeoutDuration*1e3):this.log.warn(`ping timeout duration not set`)}clearPingTimeout(){this.pingTimeout&&F.clearTimeout(this.pingTimeout)}startPingInterval(){this.clearPingInterval(),this.resetPingTimeout(),this.pingIntervalDuration?(this.log.debug(`start ping interval`),this.pingInterval=F.setInterval(()=>{this.sendPing()},this.pingIntervalDuration*1e3)):this.log.warn(`ping interval duration not set`)}clearPingInterval(){this.log.debug(`clearing ping interval`),this.clearPingTimeout(),this.pingInterval&&F.clearInterval(this.pingInterval)}handleSignalConnected(e,t,n){clearTimeout(t),this.sendLifecycleInput(this.lifecycleState===`reconnecting`?{type:`reconnectComplete`,attemptId:n}:{type:`connectComplete`,attemptId:n})?(this.log.info(`signal connected`),this.startPingInterval(),this.startReadingLoop(e.readable.getReader())):this.log.debug(`discarding a connection whose attempt no longer owns the session`,{attemptId:n,currentAttemptId:this.attemptId,state:this.lifecycleState})}validateFirstMessage(e,t){return e.message?.case===`join`||this.lifecycleState===`reconnecting`&&e.message?.case===`reconnect`?{isValid:!0,response:e.message.value}:this.isEstablishingConnection&&e.message?.case===`leave`?{isValid:!1,error:j.leaveRequest(`Received leave request while trying to (re)connect`,e.message.value.reason)}:t?{isValid:!1,error:j.internal(`Unexpected first message`)}:{isValid:!1,error:j.internal(`did not receive join response, got ${e.message?.case} instead`)}}handleConnectionError(e,t){return O(this,void 0,void 0,function*(){try{let n=yield fetch(t,{signal:Bl(3e3)});switch(n.status){case 404:let e=yield n.text();return e.includes(`requested room does not exist`)?j.notAllowed(e,n.status):j.serviceNotFound(`v1 RTC path not found. Consider upgrading your LiveKit server version`,`v0-rtc`);case 401:case 403:let t=yield n.text();return j.notAllowed(t,n.status)}return e instanceof j?e:j.internal(`Encountered unknown websocket error during connection: ${e}`,{status:n.status,statusText:n.statusText})}catch(e){return e instanceof j?e:j.serverUnreachable(e instanceof Error?e.message:`server was not reachable`)}})}};function bu(e){let t={type:`offer`,sdp:e.sdp};switch(e.type){case`answer`:case`offer`:case`pranswer`:case`rollback`:t.type=e.type}return t}function xu(e,t){return new Ar({sdp:e.sdp,type:e.type,id:t})}function Su(e,t,n){let r=new URLSearchParams;return r.set(`access_token`,e),n.reconnect&&(r.set(`reconnect`,`1`),n.sid&&r.set(`sid`,n.sid)),r.set(`auto_subscribe`,n.autoSubscribe?`1`:`0`),r.set(`sdk`,Rs()?`reactnative`:`js`),r.set(`version`,t.version),r.set(`protocol`,t.protocol.toString()),r.set(`client_protocol`,t.clientProtocol.toString()),t.deviceModel&&r.set(`device_model`,t.deviceModel),t.os&&r.set(`os`,t.os),t.osVersion&&r.set(`os_version`,t.osVersion),t.browser&&r.set(`browser`,t.browser),t.browserVersion&&r.set(`browser_version`,t.browserVersion),n.adaptiveStream&&r.set(`adaptive_stream`,`1`),n.disableIceLite&&r.set(`disable_ice_lite`,`1`),n.subscriberAllowPause!==void 0&&r.set(`subscriber_allow_pause`,n.subscriberAllowPause?`1`:`0`),n.reconnectReason&&r.set(`reconnect_reason`,n.reconnectReason.toString()),navigator.connection?.type&&r.set(`network`,navigator.connection.type),r}function Cu(e,t,n,r){return O(this,void 0,void 0,function*(){let i=new URLSearchParams;i.set(`access_token`,e);let a=new bi({clientInfo:t,connectionSettings:new yi({autoSubscribe:!!n.autoSubscribe,adaptiveStream:!!n.adaptiveStream,disableIceLite:!!n.disableIceLite,subscriberAllowPause:n.subscriberAllowPause}),reconnect:!!n.reconnect,participantSid:n.sid?n.sid:void 0,publisherOffer:r});n.reconnectReason&&(a.reconnectReason=n.reconnectReason);let o=a.toBinary(),s,c;if(Ac()){let e=new CompressionStream(`gzip`),t=e.writable.getWriter();t.write(new Uint8Array(o)),t.close();let n=[],r=e.readable.getReader();for(;;){let e=yield r.read(),t=e.done,i=e.value;if(t)break;n.push(i)}let i=n.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),l=0;for(let e of n)a.set(e,l),l+=e.length;s=a,c=Si.GZIP}else s=o,c=Si.NONE;let l=new xi({joinRequest:s,compression:c}).toBinary();return i.set(`join_request`,(e=>{let t=Array.from(e,e=>String.fromCodePoint(e)).join(``);return btoa(t)})(l).replace(/\+/g,`-`).replace(/\//g,`_`)),i})}var wu=class{constructor(e){this._map=new Map,this._lastCleanup=0,this.ttl=e}set(e,t){let n=Date.now();n-this._lastCleanup>this.ttl/2&&this.cleanup();let r=n+this.ttl;return this._map.set(e,{value:t,expiresAt:r}),this}get(e){let t=this._map.get(e);if(t){if(t.expiresAt<Date.now())this._map.delete(e);else return t.value}}has(e){let t=this._map.get(e);return t?t.expiresAt<Date.now()?(this._map.delete(e),!1):!0:!1}delete(e){return this._map.delete(e)}clear(){this._map.clear()}cleanup(){let e=Date.now();for(let n of this._map.entries()){var t=_(n,2);let r=t[0];t[1].expiresAt<e&&this._map.delete(r)}this._lastCleanup=e}get size(){return this.cleanup(),this._map.size}forEach(e){this.cleanup();for(let n of this._map.entries()){var t=_(n,2);let r=t[0],i=t[1];i.expiresAt>=Date.now()&&e(i.value,r,this.asValueMap())}}map(e){this.cleanup();let t=[],n=this.asValueMap();for(let i of n.entries()){var r=_(i,2);let a=r[0],o=r[1];t.push(e(o,a,n))}return t}asValueMap(){let e=new Map;for(let n of this._map.entries()){var t=_(n,2);let r=t[0],i=t[1];i.expiresAt>=Date.now()&&e.set(r,i.value)}return e}},Tu={},Eu={},Du={exports:{}},Ou;function ku(){if(Ou)return Du.exports;Ou=1;var e=Du.exports={v:[{name:`version`,reg:/^(\d*)$/}],o:[{name:`origin`,reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:[`username`,`sessionId`,`sessionVersion`,`netType`,`ipVer`,`address`],format:`%s %s %d %s IP%d %s`}],s:[{name:`name`}],i:[{name:`description`}],u:[{name:`uri`}],e:[{name:`email`}],p:[{name:`phone`}],z:[{name:`timezones`}],r:[{name:`repeats`}],t:[{name:`timing`,reg:/^(\d*) (\d*)/,names:[`start`,`stop`],format:`%d %d`}],c:[{name:`connection`,reg:/^IN IP(\d) (\S*)/,names:[`version`,`ip`],format:`IN IP%d %s`}],b:[{push:`bandwidth`,reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:[`type`,`limit`],format:`%s:%s`}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:[`type`,`port`,`protocol`,`payloads`],format:`%s %d %s %s`}],a:[{push:`rtp`,reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:[`payload`,`codec`,`rate`,`encoding`],format:function(e){return e.encoding?`rtpmap:%d %s/%s/%s`:e.rate?`rtpmap:%d %s/%s`:`rtpmap:%d %s`}},{push:`fmtp`,reg:/^fmtp:(\d*) ([\S| ]*)/,names:[`payload`,`config`],format:`fmtp:%d %s`},{name:`control`,reg:/^control:(.*)/,format:`control:%s`},{name:`rtcp`,reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:[`port`,`netType`,`ipVer`,`address`],format:function(e){return e.address==null?`rtcp:%d`:`rtcp:%d %s IP%d %s`}},{push:`rtcpFbTrrInt`,reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:[`payload`,`value`],format:`rtcp-fb:%s trr-int %d`},{push:`rtcpFb`,reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:[`payload`,`type`,`subtype`],format:function(e){return e.subtype==null?`rtcp-fb:%s %s`:`rtcp-fb:%s %s %s`}},{push:`ext`,reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:[`value`,`direction`,`encrypt-uri`,`uri`,`config`],format:function(e){return`extmap:%d`+(e.direction?`/%s`:`%v`)+(e[`encrypt-uri`]?` %s`:`%v`)+` %s`+(e.config?` %s`:``)}},{name:`extmapAllowMixed`,reg:/^(extmap-allow-mixed)/},{push:`crypto`,reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:[`id`,`suite`,`config`,`sessionConfig`],format:function(e){return e.sessionConfig==null?`crypto:%d %s %s`:`crypto:%d %s %s %s`}},{name:`setup`,reg:/^setup:(\w*)/,format:`setup:%s`},{name:`connectionType`,reg:/^connection:(new|existing)/,format:`connection:%s`},{name:`mid`,reg:/^mid:([^\s]*)/,format:`mid:%s`},{name:`msid`,reg:/^msid:(.*)/,format:`msid:%s`},{name:`ptime`,reg:/^ptime:(\d*(?:\.\d*)*)/,format:`ptime:%d`},{name:`maxptime`,reg:/^maxptime:(\d*(?:\.\d*)*)/,format:`maxptime:%d`},{name:`direction`,reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:`icelite`,reg:/^(ice-lite)/},{name:`iceUfrag`,reg:/^ice-ufrag:(\S*)/,format:`ice-ufrag:%s`},{name:`icePwd`,reg:/^ice-pwd:(\S*)/,format:`ice-pwd:%s`},{name:`fingerprint`,reg:/^fingerprint:(\S*) (\S*)/,names:[`type`,`hash`],format:`fingerprint:%s %s`},{push:`candidates`,reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:[`foundation`,`component`,`transport`,`priority`,`ip`,`port`,`type`,`raddr`,`rport`,`tcptype`,`generation`,`network-id`,`network-cost`],format:function(e){var t=`candidate:%s %d %s %d %s %d typ %s`;return t+=e.raddr==null?`%v%v`:` raddr %s rport %d`,t+=e.tcptype==null?`%v`:` tcptype %s`,e.generation!=null&&(t+=` generation %d`),t+=e[`network-id`]==null?`%v`:` network-id %d`,t+=e[`network-cost`]==null?`%v`:` network-cost %d`,t}},{name:`endOfCandidates`,reg:/^(end-of-candidates)/},{name:`remoteCandidates`,reg:/^remote-candidates:(.*)/,format:`remote-candidates:%s`},{name:`iceOptions`,reg:/^ice-options:(\S*)/,format:`ice-options:%s`},{push:`ssrcs`,reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:[`id`,`attribute`,`value`],format:function(e){var t=`ssrc:%d`;return e.attribute!=null&&(t+=` %s`,e.value!=null&&(t+=`:%s`)),t}},{push:`ssrcGroups`,reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:[`semantics`,`ssrcs`],format:`ssrc-group:%s %s`},{name:`msidSemantic`,reg:/^msid-semantic:\s?(\w*) (\S*)/,names:[`semantic`,`token`],format:`msid-semantic: %s %s`},{push:`groups`,reg:/^group:(\w*) (.*)/,names:[`type`,`mids`],format:`group:%s %s`},{name:`rtcpMux`,reg:/^(rtcp-mux)/},{name:`rtcpRsize`,reg:/^(rtcp-rsize)/},{name:`sctpmap`,reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:[`sctpmapNumber`,`app`,`maxMessageSize`],format:function(e){return e.maxMessageSize==null?`sctpmap:%s %s`:`sctpmap:%s %s %s`}},{name:`xGoogleFlag`,reg:/^x-google-flag:([^\s]*)/,format:`x-google-flag:%s`},{push:`rids`,reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:[`id`,`direction`,`params`],format:function(e){return e.params?`rid:%s %s %s`:`rid:%s %s`}},{push:`imageattrs`,reg:RegExp(`^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?`),names:[`pt`,`dir1`,`attrs1`,`dir2`,`attrs2`],format:function(e){return`imageattr:%s %s %s`+(e.dir2?` %s %s`:``)}},{name:`simulcast`,reg:RegExp(`^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$`),names:[`dir1`,`list1`,`dir2`,`list2`],format:function(e){return`simulcast:%s %s`+(e.dir2?` %s %s`:``)}},{name:`simulcast_03`,reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:[`value`],format:`simulcast: %s`},{name:`framerate`,reg:/^framerate:(\d+(?:$|\.\d+))/,format:`framerate:%s`},{name:`sourceFilter`,reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:[`filterMode`,`netType`,`addressTypes`,`destAddress`,`srcList`],format:`source-filter: %s %s %s %s %s`},{name:`bundleOnly`,reg:/^(bundle-only)/},{name:`label`,reg:/^label:(.+)/,format:`label:%s`},{name:`sctpPort`,reg:/^sctp-port:(\d+)$/,format:`sctp-port:%s`},{name:`maxMessageSize`,reg:/^max-message-size:(\d+)$/,format:`max-message-size:%s`},{push:`tsRefClocks`,reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:[`clksrc`,`clksrcExt`],format:function(e){return`ts-refclk:%s`+(e.clksrcExt==null?``:`=%s`)}},{name:`mediaClk`,reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:[`id`,`mediaClockName`,`mediaClockValue`,`rateNumerator`,`rateDenominator`],format:function(e){var t=`mediaclk:`;return t+=e.id==null?`%v%s`:`id=%s %s`,t+=e.mediaClockValue==null?``:`=%s`,t+=e.rateNumerator==null?``:` rate=%s`,t+=e.rateDenominator==null?``:`/%s`,t}},{name:`keywords`,reg:/^keywds:(.+)$/,format:`keywds:%s`},{name:`content`,reg:/^content:(.+)/,format:`content:%s`},{name:`bfcpFloorCtrl`,reg:/^floorctrl:(c-only|s-only|c-s)/,format:`floorctrl:%s`},{name:`bfcpConfId`,reg:/^confid:(\d+)/,format:`confid:%s`},{name:`bfcpUserId`,reg:/^userid:(\d+)/,format:`userid:%s`},{name:`bfcpFloorId`,reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:[`id`,`mStream`],format:`floorid:%s mstrm:%s`},{push:`invalid`,names:[`value`]}]};return Object.keys(e).forEach(function(t){e[t].forEach(function(e){e.reg||=/(.*)/,e.format||=`%s`})}),Du.exports}var Au;function ju(){return Au||(Au=1,(function(e){var t=function(e){return String(Number(e))===e?Number(e):e},n=function(e,n,r,i){if(i&&!r)n[i]=t(e[1]);else for(var a=0;a<r.length;a+=1)e[a+1]!=null&&(n[r[a]]=t(e[a+1]))},r=function(e,t,r){var i=e.name&&e.names;e.push&&!t[e.push]?t[e.push]=[]:i&&!t[e.name]&&(t[e.name]={});var a=e.push?{}:i?t[e.name]:t;n(r.match(e.reg),a,e.names,e.name),e.push&&t[e.push].push(a)},i=ku(),a=RegExp.prototype.test.bind(/^([a-z])=(.*)/);e.parse=function(e){var t={},n=[],o=t;return e.split(/(\r\n|\r|\n)/).filter(a).forEach(function(e){var t=e[0],a=e.slice(2);t===`m`&&(n.push({rtp:[],fmtp:[]}),o=n[n.length-1]);for(var s=0;s<(i[t]||[]).length;s+=1){var c=i[t][s];if(c.reg.test(a))return r(c,o,a)}}),t.media=n,t};var o=function(e,n){var r=n.split(/=(.+)/,2);return r.length===2?e[r[0]]=t(r[1]):r.length===1&&n.length>1&&(e[r[0]]=void 0),e};e.parseParams=function(e){return e.split(/;\s?/).reduce(o,{})},e.parseFmtpConfig=e.parseParams,e.parsePayloads=function(e){return e.toString().split(` `).map(Number)},e.parseRemoteCandidates=function(e){for(var n=[],r=e.split(` `).map(t),i=0;i<r.length;i+=3)n.push({component:r[i],ip:r[i+1],port:r[i+2]});return n},e.parseImageAttributes=function(e){return e.split(` `).map(function(e){return e.substring(1,e.length-1).split(`,`).reduce(o,{})})},e.parseSimulcastStreamList=function(e){return e.split(`;`).map(function(e){return e.split(`,`).map(function(e){var n,r=!1;return e[0]===`~`?(n=t(e.substring(1,e.length)),r=!0):n=t(e),{scid:n,paused:r}})})}})(Eu)),Eu}var Mu,Nu;function Pu(){if(Nu)return Mu;Nu=1;var e=ku(),t=/%[sdv%]/g,n=function(e){var n=1,r=arguments,i=r.length;return e.replace(t,function(e){if(n>=i)return e;var t=r[n];switch(n+=1,e){case`%%`:return`%`;case`%s`:return String(t);case`%d`:return Number(t);case`%v`:return``}})},r=function(e,t,r){var i=t.format instanceof Function?t.format(t.push?r:r[t.name]):t.format,a=[e+`=`+i];if(t.names)for(var o=0;o<t.names.length;o+=1){var s=t.names[o];t.name?a.push(r[t.name][s]):a.push(r[t.names[o]])}else a.push(r[t.name]);return n.apply(null,a)},i=[`v`,`o`,`s`,`i`,`u`,`e`,`p`,`c`,`b`,`t`,`r`,`z`,`a`],a=[`i`,`c`,`b`,`a`];return Mu=function(t,n){n||={},t.version??=0,t.name??=` `,t.media.forEach(function(e){e.payloads??=``});var o=n.outerOrder||i,s=n.innerOrder||a,c=[];return o.forEach(function(n){e[n].forEach(function(e){e.name in t&&t[e.name]!=null?c.push(r(n,e,t)):e.push in t&&t[e.push]!=null&&t[e.push].forEach(function(t){c.push(r(n,e,t))})})}),t.media.forEach(function(t){c.push(r(`m`,e.m[0],t)),s.forEach(function(n){e[n].forEach(function(e){e.name in t&&t[e.name]!=null?c.push(r(n,e,t)):e.push in t&&t[e.push]!=null&&t[e.push].forEach(function(t){c.push(r(n,e,t))})})})}),c.join(`\r
|
|
38
|
+
`)+`\r
|
|
39
|
+
`},Mu}var Fu;function Iu(){if(Fu)return Tu;Fu=1;var e=ju(),t=Pu();return Tu.grammar=ku(),Tu.write=t,Tu.parse=e.parse,Tu.parseParams=e.parseParams,Tu.parseFmtpConfig=e.parseFmtpConfig,Tu.parsePayloads=e.parsePayloads,Tu.parseRemoteCandidates=e.parseRemoteCandidates,Tu.parseImageAttributes=e.parseImageAttributes,Tu.parseSimulcastStreamList=e.parseSimulcastStreamList,Tu}var Lu=Iu(),Ru=.9,zu=1e3,Bu=300,Vu=1500,Hu=500,Uu=20;function Wu(e,t,n){if(e.msid?.includes(t))return e.rtp.find(e=>e.codec.toUpperCase()===n.toUpperCase())?.payload??0}function Gu(e,t){if(e.maxbr<Bu)return;let n=Math.min(Math.round(e.maxbr*Ru),e.maxbr);if(e.isScreenShare)return n;let r=Math.min(qu(t),Ku());return Math.min(n,r)}function Ku(){switch((typeof navigator<`u`?navigator.connection:void 0)?.effectiveType){case`slow-2g`:case`2g`:return Bu;case`3g`:return Hu;default:return zu}}function qu(e){if(e===void 0)return zu;let t=Math.min(Math.max((e-Vu)/2e3,0),1);return Math.round(zu-t*700)}function Ju(e,t,n){let r;for(let i of e)if(i.type===`video`&&i.direction!==`recvonly`&&i.direction!==`inactive`)for(let e of t){if(!e.cid)continue;let t=Wu(i,e.cid,e.codec);if(t===void 0)continue;let a=t>0?Gu(e,n):void 0;a!==void 0&&(r===void 0||a>r)&&(r=a);break}return r}function Yu(e,t,n){let r=e.fmtp.find(e=>e.payload===t);return r?r.config.includes(`x-google-start-bitrate`)||(r.config+=`;x-google-start-bitrate=${n}`):e.fmtp.push({payload:t,config:`x-google-start-bitrate=${n}`}),!0}var Xu={NegotiationStarted:`negotiationStarted`,NegotiationComplete:`negotiationComplete`,OfferAnswered:`offerAnswered`,RTPVideoPayloadTypes:`rtpVideoPayloadTypes`},Zu=class extends Yi.EventEmitter{get pc(){return this._pc||=this.createPC(),this._pc}constructor(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),this.log=E,this.iceLog=E,this.ddExtID=0,this.latestOfferId=0,this.answeredOfferId=0,this.latestAcknowledgedOfferId=0,this.pendingCandidates=[],this.restartingIce=!1,this.renegotiate=!1,this.trackBitrates=[],this.hasAppliedVideoStartBitrate=!1,this.remoteStereoMids=[],this.remoteNackMids=[],this.negotiate=sl(e=>O(this,void 0,void 0,function*(){this.emit(Xu.NegotiationStarted);try{yield this.createAndSendOffer()}catch(t){if(e)e(t);else throw t}}),Uu),this.close=()=>{this._pc&&=(this.log.debug(`closing peer connection`),this.pendingInitialOffer=void 0,this._pc.close(),this._pc.onconnectionstatechange=null,this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.ondatachannel=null,this._pc.onnegotiationneeded=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ondatachannel=null,this._pc.ontrack=null,this._pc.onconnectionstatechange=null,this._pc.oniceconnectionstatechange=null,null)},this.loggerOptions=t,this.log=D(t.loggerName??T.PCTransport,()=>this.logContext),this.iceLog=D(T.ICE,()=>this.logContext),this.config=e,this._pc=this.createPC(),this.offerLock=new i}createPC(){let e=new RTCPeerConnection(this.config);return e.onicecandidate=e=>{var t;e.candidate&&(this.iceLog.debug(`local ICE candidate gathered`,{candidate:e.candidate.candidate}),(t=this.onIceCandidate)==null||t.call(this,e.candidate))},e.onicecandidateerror=e=>{var t;this.iceLog.debug(`ICE candidate error`,{event:e}),(t=this.onIceCandidateError)==null||t.call(this,e)},e.oniceconnectionstatechange=()=>{var t;this.iceLog.debug(`ICE connection state: ${e.iceConnectionState}`),(t=this.onIceConnectionStateChange)==null||t.call(this,e.iceConnectionState)},e.onsignalingstatechange=()=>{var t;this.log.debug(`signaling state: ${e.signalingState}`),(t=this.onSignalingStatechange)==null||t.call(this,e.signalingState)},e.onconnectionstatechange=()=>{var t;this.log.debug(`connection state: ${e.connectionState}`),(t=this.onConnectionStateChange)==null||t.call(this,e.connectionState)},e.ondatachannel=e=>{var t;this.log.debug(`data channel opened by peer`,{label:e.channel.label,id:e.channel.id}),(t=this.onDataChannel)==null||t.call(this,e)},e.ontrack=e=>{var t;(t=this.onTrack)==null||t.call(this,e)},e}get logContext(){var e;return Object.assign({},(e=this.loggerOptions).loggerContextCb?.call(e))}get isICEConnected(){return this._pc!==null&&(this.pc.iceConnectionState===`connected`||this.pc.iceConnectionState===`completed`)}addIceCandidate(e){return O(this,void 0,void 0,function*(){if(this.pc.remoteDescription&&!this.restartingIce)return this.pc.addIceCandidate(e);this.iceLog.debug(`queuing remote ICE candidate until remote description applied`,{pendingCount:this.pendingCandidates.length+1}),this.pendingCandidates.push(e)})}setRemoteDescription(e,t){return O(this,void 0,void 0,function*(){if(e.type===`answer`&&this.latestOfferId>0&&t>0&&t!==this.latestOfferId)return this.log.warn(`ignoring answer for old offer`,{offerId:t,latestOfferId:this.latestOfferId}),!1;if(e.type===`answer`){if(sd(t,this.answerInFlight,this.answeredOfferId,this._pc?.signalingState,this.pendingInitialOffer!==void 0))return this.log.warn(`ignoring duplicate answer`,{offerId:t}),!1;this.answerInFlight=t}try{return yield this.applyRemoteDescription(e,t)}finally{e.type===`answer`&&(this.answerInFlight=void 0)}})}applyRemoteDescription(e,t){return O(this,void 0,void 0,function*(){let n;if(e.type===`offer`){let t=cd(e),n=t.stereoMids,r=t.nackMids;this.remoteStereoMids=n,this.remoteNackMids=r}else if(e.type===`answer`){if(this.pendingInitialOffer&&this._pc){let e=this.pendingInitialOffer;this.pendingInitialOffer=void 0;let t=Lu.parse(e.sdp??``);t.media.forEach(e=>{ld(e)}),this.log.debug(`setting pending initial offer before processing answer`),yield this.setMungedSDP(e,Lu.write(t))}let t=Lu.parse(e.sdp??``);t.media.forEach(e=>{let t=ud(e.mid);e.type===`audio`&&this.trackBitrates.some(n=>{if(!n.transceiver||t!=n.transceiver.mid)return!1;let r=0;if(e.rtp.some(e=>e.codec.toUpperCase()===n.codec.toUpperCase()&&(r=e.payload,!0)),r===0)return!0;let i=!1;for(let t of e.fmtp)if(t.payload===r){t.config=t.config.split(`;`).filter(e=>!e.includes(`maxaveragebitrate`)).join(`;`),n.maxbr>0&&(t.config+=`;maxaveragebitrate=${n.maxbr*1e3}`),i=!0;break}return i||n.maxbr>0&&e.fmtp.push({payload:r,config:`maxaveragebitrate=${n.maxbr*1e3}`}),!0})});let r=this.getPlaceholderMids();r.size>0&&od(t.media,e=>r.has(ud(e.mid))),n=Lu.write(t)}return yield this.setMungedSDP(e,n,!0),e.type===`answer`&&t>0&&(this.answeredOfferId=t),this.pendingCandidates.length>0&&this.iceLog.debug(`flushing queued ICE candidates`,{count:this.pendingCandidates.length}),this.pendingCandidates.forEach(e=>{this.pc.addIceCandidate(e)}),this.pendingCandidates=[],this.restartingIce=!1,e.type===`answer`&&(this.latestAcknowledgedOfferId=t,this.emit(Xu.OfferAnswered,t)),this.renegotiate?(this.renegotiate=!1,yield this.createAndSendOffer()):e.type===`answer`&&(this.emit(Xu.NegotiationComplete),e.sdp&&Lu.parse(e.sdp).media.forEach(e=>{e.type===`video`&&this.emit(Xu.RTPVideoPayloadTypes,e.rtp)})),!0})}createInitialOffer(){return O(this,void 0,void 0,function*(){let e=yield this.offerLock.lock();try{if(this.pc.signalingState!==`stable`){this.log.warn(`signaling state is not stable, cannot create initial offer`);return}let e=this.latestOfferId+1;this.latestOfferId=e;let t=yield this.pc.createOffer();this.pendingInitialOffer={sdp:t.sdp,type:t.type};let n=Lu.parse(t.sdp??``);return n.media.forEach(e=>{ld(e)}),t.sdp=Lu.write(n),{offer:t,offerId:e}}finally{e()}})}createAndSendOffer(e){return O(this,void 0,void 0,function*(){let t=yield this.offerLock.lock();try{if(this.onOffer===void 0)return;if(e?.iceRestart&&(this.iceLog.debug(`restarting ICE`),this.restartingIce=!0),this._pc&&(this._pc.signalingState===`have-local-offer`||this.pendingInitialOffer)){let t=this._pc.remoteDescription;if(e?.iceRestart&&t)yield this._pc.setRemoteDescription(t);else if(e?.iceRestart)throw new So(`ICE restart requested without a remote description, peer connection must be recreated`);else{this.renegotiate=!0,this.log.debug(`requesting renegotiation`);return}}else if(!this._pc||this._pc.signalingState===`closed`){this.log.warn(`could not createOffer with closed peer connection`);return}this.log.debug(`starting to negotiate`);let t=this.latestOfferId+1;this.latestOfferId=t;let n=yield this.pc.createOffer(e);this.log.debug(`original offer`,{sdp:n.sdp});let r=Lu.parse(n.sdp??``),i=this.hasAppliedVideoStartBitrate?void 0:Ju(r.media,this.trackBitrates,this.connectionSetupTimeEstimateMs()),a=!1;r.media.forEach(e=>{ld(e),e.type===`audio`?id(e,[`all`],[]):e.type===`video`&&this.trackBitrates.some(t=>{if(!t.cid)return!1;let n=Wu(e,t.cid,t.codec);return n!==void 0&&(n>0&&(i!==void 0&&(a=Yu(e,n,i)||a),ys(t.codec)&&!As()&&(this.ddExtID=Qu(e,r,this.ddExtID))),!0)})});let o=this.getPlaceholderMids();if(o.size>0&&od(r.media,e=>o.has(ud(e.mid))),this.latestOfferId>t){this.log.warn(`latestOfferId mismatch`,{latestOfferId:this.latestOfferId,offerId:t});return}let s=Lu.write(r);yield this.setMungedSDP(n,s),a&&n.sdp===s&&(this.hasAppliedVideoStartBitrate=!0,this.log.info(`applied x-google-start-bitrate`,{startBitrateKbps:i,connectionSetupTimeMs:this.connectionSetupTimeEstimateMs()})),this.onOffer(n,this.latestOfferId)}finally{t()}})}createAndSetAnswer(){return O(this,void 0,void 0,function*(){let e=yield this.pc.createAnswer(),t=Lu.parse(e.sdp??``);return t.media.forEach(e=>{ld(e),e.type===`audio`&&id(e,this.remoteStereoMids,this.remoteNackMids)}),yield this.setMungedSDP(e,Lu.write(t)),e})}getPlaceholderMids(){return ad(this._pc?.getTransceivers()??[])}createDataChannel(e,t){return this.pc.createDataChannel(e,t)}addTransceiver(e,t){return this.pc.addTransceiver(e,t)}addTransceiverOfKind(e,t){return this.pc.addTransceiver(e,t)}addTrack(e){if(!this._pc)throw new M(`PC closed, cannot add track`);return this._pc.addTrack(e)}setTrackCodecBitrate(e){this.trackBitrates.push(e)}setConnectionSetupTime(e){this.connectionSetupTimeMs=e}setConnectionStartedAt(e){this.connectionStartedAt=e}connectionSetupTimeEstimateMs(){if(this.connectionSetupTimeMs!==void 0)return this.connectionSetupTimeMs;if(this.connectionStartedAt!==void 0)return Math.round(performance.now()-this.connectionStartedAt)}setConfiguration(e){if(!this._pc)throw new M(`PC closed, cannot configure`);return this._pc?.setConfiguration(e)}canRemoveTrack(){return!!this._pc?.removeTrack}removeTrack(e){return this._pc?.removeTrack(e)}getConnectionState(){return this._pc?.connectionState??`closed`}getICEConnectionState(){return this._pc?.iceConnectionState??`closed`}getSignallingState(){return this._pc?.signalingState??`closed`}getTransceivers(){return this._pc?.getTransceivers()??[]}getSenders(){return this._pc?.getSenders()??[]}getLocalDescription(){return this._pc?.localDescription}getRemoteDescription(){return this.pc?.remoteDescription}getStats(){return this._pc?.getStats()}getMaxMessageSize(){return this._pc?.sctp?.maxMessageSize}getConnectedAddress(){return O(this,void 0,void 0,function*(){if(!this._pc)return;let e=``,t=new Map,n=new Map;if((yield this._pc.getStats()).forEach(r=>{switch(r.type){case`transport`:e=r.selectedCandidatePairId;break;case`candidate-pair`:e===``&&r.selected&&(e=r.id),t.set(r.id,r);break;case`remote-candidate`:n.set(r.id,`${r.address}:${r.port}`)}}),e===``)return;let r=t.get(e)?.remoteCandidateId;if(r!==void 0)return n.get(r)})}setMungedSDP(e,t,n){return O(this,void 0,void 0,function*(){let r=e.sdp;if(t){e.sdp=t;try{this.log.debug(`setting munged ${n?`remote`:`local`} description`),n?yield this.pc.setRemoteDescription(e):yield this.pc.setLocalDescription(e);return}catch(n){this.log.warn(`not able to set ${e.type}, falling back to unmodified sdp`,{error:n,mungedSdp:t,originalSdp:r}),e.sdp=r}}try{n?yield this._pc?.setRemoteDescription(e):yield this._pc?.setLocalDescription(e)}catch(i){let a=`unknown error`;i instanceof Error?a=i.message:typeof i==`string`&&(a=i);let o={error:a,sdp:e.sdp};throw t&&t!==r&&(o.mungedSdp=t),!n&&this.pc.remoteDescription&&(o.remoteSdp=this.pc.remoteDescription),this.log.error(`unable to set ${e.type}`,{fields:o}),new So(a)}})}};function Qu(e,t,n){let r=$u(t,n);return r===void 0?n:(e.ext?.some(e=>e.uri===ps)||(e.ext??=[],e.ext.push({value:r,uri:ps})),r)}function $u(e,t){let n=ed(e,ps);return n===void 0?t!==0&&!td(e,t,ps)?t:nd(e):td(e,n,ps)?void 0:n}function ed(e,t){for(let n of e.media){let e=n.ext?.find(e=>e.uri===t);if(e)return e.value}}function td(e,t,n){return e.media.some(e=>e.ext?.some(e=>e.value===t&&e.uri!==n))}function nd(e){let t=0;return e.media.forEach(e=>{var n;(n=e.ext)==null||n.forEach(e=>{e.value>t&&(t=e.value)})}),t+1===15?16:t+1}function rd(e,t){return e.split(`;`).some(e=>e.trim()===t)}function id(e,t,n){let r=ud(e.mid),i=0;e.rtp.some(e=>e.codec.toLowerCase()===`opus`&&(i=e.payload,!0)),i>0&&(e.rtcpFb||=[],n.includes(r)&&!e.rtcpFb.some(e=>e.payload===i&&e.type===`nack`)&&e.rtcpFb.push({payload:i,type:`nack`}),(t.includes(r)||t.length===1&&t[0]===`all`)&&e.fmtp.some(e=>e.payload===i&&(rd(e.config,`stereo=1`)||(e.config+=`;stereo=1`),!0)))}function ad(e){let t=new Set;for(let n of e)n.mid&&!n.sender.track&&t.add(n.mid);return t}function od(e,t){let n=new Map,r=new Set;for(let i of e){let e=t(i);for(let t of i.fmtp??[])e?n.has(t.payload)||n.set(t.payload,t.config):(n.set(t.payload,t.config),r.add(t.payload))}if(n.size!==0){for(let r of e)if(t(r))for(let e of r.fmtp??[]){let t=n.get(e.payload);t!==void 0&&e.config!==t&&(e.config=t)}}}function sd(e,t,n,r,i){return t===e?!0:e>0?e===n:r===`stable`&&!i}function cd(e){let t=[],n=[],r=Lu.parse(e.sdp??``),i=0;return r.media.forEach(e=>{let r=ud(e.mid);e.type===`audio`&&(e.rtp.some(e=>e.codec.toLowerCase()===`opus`&&(i=e.payload,!0)),e.rtcpFb?.some(e=>e.payload===i&&e.type===`nack`)&&n.push(r),e.fmtp.some(e=>e.payload===i&&(rd(e.config,`sprop-stereo=1`)&&t.push(r),!0)))}),{stereoMids:t,nackMids:n}}function ld(e){if(e.connection){let t=e.connection.ip.indexOf(`:`)>=0;(e.connection.version===4&&t||e.connection.version===6&&!t)&&(e.connection.ip=`0.0.0.0`,e.connection.version=4)}}function ud(e){return typeof e==`number`?e.toFixed(0):e}var dd=`vp8`,fd={audioPreset:Bo.music,dtx:!0,red:!0,forceStereo:!1,simulcast:!0,screenShareEncoding:Uo.h1080fps15.encoding,stopMicTrackOnMute:!1,videoCodec:dd,backupCodec:!0,preConnectBuffer:!1},pd={deviceId:{ideal:`default`},autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0,voiceIsolation:!0},md={deviceId:{ideal:`default`},resolution:Vo.h720.resolution},hd={adaptiveStream:!1,dynacast:!1,stopLocalTrackOnUnpublish:!0,reconnectPolicy:new zi,disconnectOnPageLeave:!0,webAudioMix:!1,singlePeerConnection:!0},gd={autoSubscribe:!0,disableIceLite:!1,maxRetries:1,peerConnectionTimeout:15e3,websocketTimeout:15e3},K;(function(e){e[e.NEW=0]=`NEW`,e[e.CONNECTING=1]=`CONNECTING`,e[e.CONNECTED=2]=`CONNECTED`,e[e.FAILED=3]=`FAILED`,e[e.CLOSING=4]=`CLOSING`,e[e.CLOSED=5]=`CLOSED`})(K||={});var _d=class{get needsPublisher(){return this.isPublisherConnectionRequired}get needsSubscriber(){return this.isSubscriberConnectionRequired}get currentState(){return this.state}get mode(){return this._mode}constructor(e,t,n){this.peerConnectionTimeout=gd.peerConnectionTimeout,this.log=E,this.iceLog=E,this.updateState=()=>{var e;let t=this.state,n=this.requiredTransports.map(e=>e.getConnectionState());n.every(e=>e===`connected`)?this.state=K.CONNECTED:n.some(e=>e===`failed`)?this.state=K.FAILED:n.some(e=>e===`connecting`)?this.state=K.CONNECTING:n.every(e=>e===`closed`)?this.state=K.CLOSED:n.some(e=>e===`closed`)?this.state=K.CLOSING:n.every(e=>e===`new`)&&(this.state=K.NEW),t!==this.state&&(this.log.debug(`pc state change: from ${K[t]} to ${K[this.state]}`),(e=this.onStateChange)==null||e.call(this,this.state,this.publisher.getConnectionState(),this.subscriber?.getConnectionState()))},this.loggerOptions=t,this.log=D(t.loggerName??T.PCManager,()=>this.logContext),this.iceLog=D(T.ICE,()=>this.logContext),this.isPublisherConnectionRequired=e!==`subscriber-primary`,this.isSubscriberConnectionRequired=e===`subscriber-primary`,this.publisher=new Zu(n,t),this._mode=e,e!==`publisher-only`&&(this.subscriber=new Zu(n,t),this.subscriber.onConnectionStateChange=this.updateState,this.subscriber.onIceConnectionStateChange=this.updateState,this.subscriber.onSignalingStatechange=this.updateState,this.subscriber.onIceCandidate=e=>{var t;(t=this.onIceCandidate)==null||t.call(this,e,dr.SUBSCRIBER)},this.subscriber.onDataChannel=e=>{var t;(t=this.onDataChannel)==null||t.call(this,e)},this.subscriber.onTrack=e=>{var t;(t=this.onTrack)==null||t.call(this,e)}),this.publisher.onConnectionStateChange=this.updateState,this.publisher.onIceConnectionStateChange=this.updateState,this.publisher.onSignalingStatechange=this.updateState,this.publisher.onIceCandidate=e=>{var t;(t=this.onIceCandidate)==null||t.call(this,e,dr.PUBLISHER)},this.publisher.onTrack=e=>{var t;(t=this.onTrack)==null||t.call(this,e)},this.publisher.onOffer=(e,t)=>{var n;(n=this.onPublisherOffer)==null||n.call(this,e,t)},this.state=K.NEW,this.connectionLock=new i,this.remoteOfferLock=new i}get logContext(){var e;return Object.assign({},(e=this.loggerOptions).loggerContextCb?.call(e))}requirePublisher(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;this.isPublisherConnectionRequired=e,this.updateState()}createAndSendPublisherOffer(e){return this.publisher.createAndSendOffer(e)}setPublisherAnswer(e,t){return this.publisher.setRemoteDescription(e,t)}removeTrack(e){return this.publisher.removeTrack(e)}close(){return O(this,void 0,void 0,function*(){if(this.publisher&&this.publisher.getSignallingState()!==`closed`){let e=this.publisher;for(let t of e.getSenders())try{e.canRemoveTrack()&&e.removeTrack(t)}catch(e){this.log.warn(`could not removeTrack`,{error:e})}}yield Promise.all([this.publisher.close(),this.subscriber?.close()]),this.updateState()})}triggerIceRestart(){return O(this,void 0,void 0,function*(){this.iceLog.warn(`triggering ICE restart`),this.needsPublisher&&(yield this.createAndSendPublisherOffer({iceRestart:!0}))})}addIceCandidate(e,t){return O(this,void 0,void 0,function*(){this.iceLog.debug(`adding remote ICE candidate`,{target:t,candidate:e}),t===dr.PUBLISHER?yield this.publisher.addIceCandidate(e):yield this.subscriber?.addIceCandidate(e)})}createSubscriberAnswerFromOffer(e,t){return O(this,void 0,void 0,function*(){this.log.debug(`received server offer`,{RTCSdpType:e.type,sdp:e.sdp,signalingState:this.subscriber?.getSignallingState().toString()});let n=yield this.remoteOfferLock.lock();try{return(yield this.subscriber?.setRemoteDescription(e,t))?yield this.subscriber?.createAndSetAnswer():void 0}finally{n()}})}updateConfiguration(e,t){var n;this.log.debug(`updating rtc configuration`,{iceRestart:t}),this.publisher.setConfiguration(e),(n=this.subscriber)==null||n.setConfiguration(e),t&&this.triggerIceRestart()}ensurePCTransportConnection(e,t){return O(this,void 0,void 0,function*(){let n=yield this.connectionLock.lock();try{this.isPublisherConnectionRequired&&this.publisher.getConnectionState()!==`connected`&&this.publisher.getConnectionState()!==`connecting`&&(this.log.debug(`negotiation required, start negotiating`),this.publisher.negotiate().catch(e=>{this.log.error(e)})),yield Promise.all(this.requiredTransports?.map(n=>this.ensureTransportConnected(n,e,t)))}finally{n()}})}negotiate(e){return O(this,void 0,void 0,function*(){return new co((t,n)=>{let r=this.publisher.latestOfferId;if(this.publisher.latestAcknowledgedOfferId>r){this.log.debug(`negotiation already handled in more recent acknowledged offer`,this.logContext),t();return}let i=!1,a=()=>{i||(i=!0,clearTimeout(c),this.publisher.off(Xu.OfferAnswered,o),e.signal.removeEventListener(`abort`,s))},o=e=>{e>r&&(a(),t())},s=()=>{a(),n(new So(`negotiation aborted`))},c=setTimeout(()=>{a(),n(new So(`negotiation timed out`))},this.peerConnectionTimeout);e.signal.addEventListener(`abort`,s),this.publisher.on(Xu.OfferAnswered,o),this.publisher.negotiate(e=>{a(),e instanceof Error?n(e):n(Error(String(e)))})})})}addPublisherTransceiver(e,t){return this.publisher.addTransceiver(e,t)}addPublisherTransceiverOfKind(e,t){return this.publisher.addTransceiverOfKind(e,t)}getMidForReceiver(e){return(this.subscriber?this.subscriber.getTransceivers():this.publisher.getTransceivers()).find(t=>t.receiver===e)?.mid}getMaxPublisherMessageSize(){return this.publisher.getMaxMessageSize()}addPublisherTrack(e){return this.publisher.addTrack(e)}createPublisherDataChannel(e,t){return this.publisher.createDataChannel(e,t)}getConnectedAddress(e){return e===dr.PUBLISHER||e===dr.SUBSCRIBER?this.publisher.getConnectedAddress():this.requiredTransports[0].getConnectedAddress()}get requiredTransports(){let e=[];return this.isPublisherConnectionRequired&&e.push(this.publisher),this.isSubscriberConnectionRequired&&this.subscriber&&e.push(this.subscriber),e}ensureTransportConnected(e,t){return O(this,arguments,void 0,function(e,t){var n=this;let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.peerConnectionTimeout;return function*(){if(e.getConnectionState()!==`connected`)return new Promise((e,i)=>O(n,void 0,void 0,function*(){let n=()=>{this.log.warn(`abort transport connection`),F.clearTimeout(a),i(j.cancelled(`room connection has been cancelled`))};t?.signal.aborted&&n(),t?.signal.addEventListener(`abort`,n);let a=F.setTimeout(()=>{t?.signal.removeEventListener(`abort`,n),i(j.internal(`could not establish pc connection`))},r);for(;this.state!==K.CONNECTED;)if(yield U(50),t?.signal.aborted){i(j.cancelled(`room connection has been cancelled`));return}F.clearTimeout(a),t?.signal.removeEventListener(`abort`,n),e()}))}()})}},vd=class{constructor(e){this.bufferStatusLow=!0,this.headroomLock=new i,this.waiterAbortController=new AbortController,this.kind=e.kind,this.lowWaterMark=e.lowWaterMark,this.highWaterMark=e.highWaterMark,this.isEngineClosed=e.isEngineClosed,this.onBufferStatusChanged=e.onBufferStatusChanged}get channelHandle(){return this.handle}attach(e){let t=this.handle;this.handle=e,t&&t!==e&&this.release(t,`data channel replaced`)}detach(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`data channel torn down`,t=this.handle;this.handle=void 0,t&&this.release(t,e)}release(e,t){this.invalidateWaiters(t),e.close()}getChannel(){return this.handle}isBelowHighWaterMark(e){return e.bufferedAmount<=this.highWaterMark}isBelowLowWaterMark(e){return e.bufferedAmount<=e.bufferedAmountLowThreshold}lockHeadroom(){return this.headroomLock.lock()}waitForHeadroomWithLock(e){return O(this,void 0,void 0,function*(){let t=yield this.lockHeadroom();try{yield this.waitForHeadroomWithoutLock(e)}finally{t()}})}waitForHeadroomWithoutLock(e){return O(this,void 0,void 0,function*(){if(this.isEngineClosed())throw new M(`engine closed`);if(e.readyState!==`open`)throw new M(`DataChannel ${this.kind} is ${e.readyState}`);if(this.isBelowHighWaterMark(e))return;let t=this.waiterAbortController.signal;yield new co((n,r)=>{let i=()=>{s(),n()},a=()=>{s(),r(new M(`DataChannel ${this.kind} closed while draining the buffer`))},o=()=>{s(),r(new M(`DataChannel ${this.kind} was replaced or torn down while waiting for headroom`))},s=()=>{e.removeEventListener(`bufferedamountlow`,i),e.removeEventListener(`close`,a),t.removeEventListener(`abort`,o)};t.aborted?o():(e.addEventListener(`bufferedamountlow`,i),e.addEventListener(`close`,a),t.addEventListener(`abort`,o))})})}invalidateWaiters(e){this.waiterAbortController.abort(e),this.waiterAbortController=new AbortController}refreshBufferStatus(){var e;let t=this.getChannel();if(!t)return;let n=this.isBelowLowWaterMark(t);n!==this.bufferStatusLow&&(this.bufferStatusLow=n,(e=this.onBufferStatusChanged)==null||e.call(this,n))}},yd=class extends vd{constructor(e){super(e),this.statCurrentBytes=0,this.statByterate=0,this.dropCount=0,this.bufferFullBehavior=e.bufferFullBehavior,this.shouldSkipSends=e.shouldSkipSends}send(e){return O(this,void 0,void 0,function*(){let t=this.getChannel();if(t){switch(this.bufferFullBehavior){case`wait`:if(!this.isBelowHighWaterMark(t))try{yield this.waitForHeadroomWithLock(t)}catch(e){if(this.isEngineClosed())throw e;return}break;case`drop`:if(!this.isBelowLowWaterMark(t)){this.dropCount+=1,this.dropCount%100==0&&E.warn(`dropping lossy data channel messages, total dropped: ${this.dropCount}`);return}}if(this.statCurrentBytes+=e.byteLength,!this.shouldSkipSends())try{t.send(e),this.refreshBufferStatus()}catch(e){if(e instanceof TypeError)E.error(e);else throw e}}})}startThresholdTuning(){this.stopThresholdTuning(),this.statInterval=F.setInterval(()=>{this.statByterate=this.statCurrentBytes,this.statCurrentBytes=0;let e=this.getChannel();if(e){let t=this.statByterate/10;e.bufferedAmountLowThreshold=Math.min(Math.max(t,this.lowWaterMark),this.highWaterMark)}},1e3)}stopThresholdTuning(){this.statByterate=0,this.statCurrentBytes=0,this.statInterval&&=(F.clearInterval(this.statInterval),void 0),this.dropCount=0}},bd=class{constructor(){this.buffer=[],this._totalSize=0,this._sentSize=0}push(e){this.buffer.push(e),this._totalSize+=e.data.byteLength,e.sent&&(this._sentSize+=e.data.byteLength)}pop(){let e=this.buffer.shift();return e&&(this._totalSize-=e.data.byteLength,e.sent&&(this._sentSize-=e.data.byteLength)),e}getAll(){return this.buffer.slice()}getUnsent(){return this.buffer.filter(e=>!e.sent)}markSent(e){e.sent||(e.sent=!0,this._sentSize+=e.data.byteLength)}markAllUnsent(){for(let e of this.buffer)e.sent=!1;this._sentSize=0}popToSequence(e){for(;this.buffer.length>0&&this.buffer[0].sequence<=e;)this.pop()}alignBufferedAmount(e){for(;this.buffer.length>0;){let t=this.buffer[0];if(!t.sent||this._sentSize-t.data.byteLength<=e)break;this.pop()}}get length(){return this.buffer.length}},xd=class extends vd{constructor(e){super(e),this.messageBuffer=new bd,this.sequence=1,this.isDeferringSends=e.isDeferringSends}nextSequence(){let e=this.sequence;return this.sequence+=1,e}send(e,t){return O(this,void 0,void 0,function*(){if(this.isDeferringSends()){this.messageBuffer.push({data:e,sequence:t,sent:!1});return}let n=this.getChannel();if(n){try{yield this.waitForHeadroomWithLock(n)}catch(n){if(this.isEngineClosed())throw n;this.messageBuffer.push({data:e,sequence:t,sent:!1});return}this.isDeferringSends()?this.messageBuffer.push({data:e,sequence:t,sent:!1}):(this.messageBuffer.push({data:e,sequence:t,sent:!0}),n.send(e),this.refreshBufferStatus())}})}replay(e){return O(this,void 0,void 0,function*(){if(!this.getChannel())return;this.messageBuffer.popToSequence(e);let t=yield this.lockHeadroom();try{let e=this.getChannel();if(!e)throw new M(`DataChannel not found, kind: ${this.kind}`);this.messageBuffer.markAllUnsent();for(let t=this.messageBuffer.getUnsent();t.length>0;t=this.messageBuffer.getUnsent())for(let n of t)yield this.waitForHeadroomWithoutLock(e),e.send(n.data),this.messageBuffer.markSent(n)}finally{t()}this.refreshBufferStatus()})}refreshBufferStatus(){let e=this.channelHandle;e&&this.messageBuffer.alignBufferedAmount(e.bufferedAmount),super.refreshBufferStatus()}reset(){this.messageBuffer=new bd,this.sequence=1}},q;(function(e){e[e.RELIABLE=0]=`RELIABLE`,e[e.LOSSY=1]=`LOSSY`,e[e.DATA_TRACK_LOSSY=2]=`DATA_TRACK_LOSSY`})(q||={});var Sd=65536,Cd=1048576,wd=8192,Td=262144;function Ed(e){return e===q.RELIABLE?Sd:wd}function Dd(e){return e===q.RELIABLE?Cd:Td}var Od=`_lossy`,kd=`_reliable`,Ad=`_data_track`;function jd(e){e.onbufferedamountlow=null,e.onclose=null,e.onclosing=null,e.onerror=null,e.onmessage=null,e.onopen=null}var Md=class{constructor(e){this.opts=e;let t=t=>({kind:t,lowWaterMark:Ed(t),highWaterMark:Dd(t),isEngineClosed:e.isEngineClosed,onBufferStatusChanged:n=>e.onBufferStatusChanged(t,n)});this.reliable=new xd(Object.assign(Object.assign({},t(q.RELIABLE)),{isDeferringSends:e.isReconnecting})),this.lossy=new yd(Object.assign(Object.assign({},t(q.LOSSY)),{bufferFullBehavior:`drop`,shouldSkipSends:e.isReconnecting})),this.dataTrack=new yd(Object.assign(Object.assign({},t(q.DATA_TRACK_LOSSY)),{bufferFullBehavior:`wait`,shouldSkipSends:e.isReconnecting}))}channelFor(e){switch(e){case q.RELIABLE:return this.reliable;case q.LOSSY:return this.lossy;case q.DATA_TRACK_LOSSY:return this.dataTrack}}getHandle(e){if(!(arguments.length>1&&arguments[1]!==void 0&&arguments[1]))return this.channelFor(e).channelHandle;switch(e){case q.RELIABLE:return this.reliableSub;case q.LOSSY:return this.lossySub;case q.DATA_TRACK_LOSSY:return this.dataTrackSub}}get hasPublisherChannels(){return!!(this.reliable.channelHandle||this.lossy.channelHandle||this.dataTrack.channelHandle)}createPublisherChannels(e){for(let e of[this.lossy,this.reliable,this.dataTrack]){let t=e.channelHandle;t&&jd(t)}let t=(e,t,n)=>{t.onmessage=n,t.onerror=this.opts.onDataError,t.onclose=()=>this.opts.onChannelClose(e.kind),t.bufferedAmountLowThreshold=e.lowWaterMark,t.onbufferedamountlow=()=>e.refreshBufferStatus(),e.attach(t)};t(this.lossy,e.createPublisherDataChannel(Od,{ordered:!1,maxRetransmits:0}),this.opts.onDataMessage),t(this.reliable,e.createPublisherDataChannel(kd,{ordered:!0}),this.opts.onDataMessage),t(this.dataTrack,e.createPublisherDataChannel(Ad,{ordered:!1,maxRetransmits:0}),this.opts.onDataTrackMessage),this.lossy.startThresholdTuning()}adoptSubscriberChannel(e){let t;if(e.label===kd)this.reliableSub=e,t=this.opts.onDataMessage;else if(e.label===Od)this.lossySub=e,t=this.opts.onDataMessage;else if(e.label===Ad)this.dataTrackSub=e,t=this.opts.onDataTrackMessage;else return!1;return e.onmessage=t,!0}teardown(){let e=[this.lossy,this.reliable,this.dataTrack],t=[this.lossySub,this.reliableSub,this.dataTrackSub];for(let t of e){let e=t.channelHandle;e&&jd(e),t.detach(`peer connections cleaned up`)}for(let e of t)e&&(jd(e),e.close());this.lossySub=void 0,this.reliableSub=void 0,this.dataTrackSub=void 0,this.reliable.reset()}},Nd=typeof MediaRecorder<`u`,Pd=Nd?MediaRecorder:class{constructor(){throw Error(`MediaRecorder is not available in this environment`)}},Fd=class extends Pd{constructor(e,t){if(!Nd)throw Error(`MediaRecorder is not available in this environment`);super(new MediaStream([e.mediaStreamTrack]),t);let n,r,i=()=>r===void 0,a=()=>{this.removeEventListener(`dataavailable`,n),this.removeEventListener(`stop`,a),this.removeEventListener(`error`,o),r?.close(),r=void 0},o=e=>{r?.error(e),this.removeEventListener(`dataavailable`,n),this.removeEventListener(`stop`,a),this.removeEventListener(`error`,o),r=void 0};this.byteStream=new ReadableStream({start:e=>{r=e,n=t=>O(this,void 0,void 0,function*(){let n;if(t.data.arrayBuffer){let e=yield t.data.arrayBuffer();n=new Uint8Array(e)}else if(t.data.byteArray)n=t.data.byteArray;else throw Error(`no data available!`);i()||e.enqueue(n)}),this.addEventListener(`dataavailable`,n)},cancel:()=>{a()}}),this.addEventListener(`stop`,a),this.addEventListener(`error`,o)}};function Id(){return Nd}var Ld=1e3,Rd=1e4,zd=class extends H{get sender(){return this._sender}set sender(e){this._sender=e}get constraints(){return this._constraints}get hasPreConnectBuffer(){return!!this.localTrackRecorder}constructor(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0&&arguments[3],a=arguments.length>4?arguments[4]:void 0;super(e,t,a),this.manuallyStopped=!1,this.pendingDeviceChange=!1,this._isUpstreamPaused=!1,this.handleTrackMuteEvent=()=>this.debouncedTrackMuteHandler().catch(()=>this.log.debug(`track mute bounce got cancelled by an unmute event`,this.logContext)),this.debouncedTrackMuteHandler=sl(()=>O(this,void 0,void 0,function*(){yield this.pauseUpstream()}),5e3),this.handleTrackUnmuteEvent=()=>O(this,void 0,void 0,function*(){this.debouncedTrackMuteHandler.cancel(`unmute`),yield this.resumeUpstream()}),this.handleEnded=()=>{this.isInBackground&&(this.reacquireTrack=!0),this._mediaStreamTrack.removeEventListener(`mute`,this.handleTrackMuteEvent),this._mediaStreamTrack.removeEventListener(`unmute`,this.handleTrackUnmuteEvent),this.emit(z.Ended,this)},this.reacquireTrack=!1,this.providedByUser=r,this.muteLock=new i,this.pauseUpstreamLock=new i,this.trackChangeLock=new i,this.trackChangeLock.lock().then(t=>O(this,void 0,void 0,function*(){try{yield this.setMediaStreamTrack(e,!0)}finally{t()}})),this._constraints=e.getConstraints(),n&&(this._constraints=n)}get id(){return this._mediaStreamTrack.id}get dimensions(){if(this.kind!==H.Kind.Video)return;let e=this._mediaStreamTrack.getSettings(),t=e.width,n=e.height;if(t&&n)return{width:t,height:n}}get isUpstreamPaused(){return this._isUpstreamPaused}get isUserProvided(){return this.providedByUser}get isStopped(){return this.manuallyStopped}get mediaStreamTrack(){return this.processor?.processedTrack??this._mediaStreamTrack}get isLocal(){return!0}getSourceTrackSettings(){return this._mediaStreamTrack.getSettings()}setMediaStreamTrack(e,t,n){return O(this,void 0,void 0,function*(){if(e===this._mediaStreamTrack&&!t)return;this._mediaStreamTrack&&(this.attachedElements.forEach(e=>{ds(this._mediaStreamTrack,e)}),this.debouncedTrackMuteHandler.cancel(`new-track`),this._mediaStreamTrack.removeEventListener(`ended`,this.handleEnded),this._mediaStreamTrack.removeEventListener(`mute`,this.handleTrackMuteEvent),this._mediaStreamTrack.removeEventListener(`unmute`,this.handleTrackUnmuteEvent)),this.mediaStream=new MediaStream([e]),e&&(e.addEventListener(`ended`,this.handleEnded),e.addEventListener(`mute`,this.handleTrackMuteEvent),e.addEventListener(`unmute`,this.handleTrackUnmuteEvent),this._constraints=e.getConstraints());let r;if(this.processor&&e){if(this.log.debug(`restarting processor`,this.logContext),this.kind===`unknown`)throw TypeError(`cannot set processor on track of unknown kind`);this.processorElement&&(us(e,this.processorElement),this.processorElement.muted=!0),yield this.processor.restart({track:e,kind:this.kind,element:this.processorElement,audioContext:this.audioContext,localTrack:this}),r=this.processor.processedTrack}this.sender&&this.sender.transport?.state!==`closed`&&(yield this.sender.replaceTrack(r??e)),!this.providedByUser&&this._mediaStreamTrack!==e&&this._mediaStreamTrack.stop(),this._mediaStreamTrack=e,e&&(this._mediaStreamTrack.enabled=n?!0:!this.isMuted,yield this.resumeUpstream(),this.attachedElements.forEach(t=>{us(r??e,t)})),yield this.onMediaStreamTrackChanged()})}onMediaStreamTrackChanged(){return O(this,void 0,void 0,function*(){})}waitForDimensions(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ld;return function*(){if(e.kind===H.Kind.Audio)throw Error(`cannot get dimensions for audio tracks`);let n=Date.now();for(Ns()&&(yield os(e._mediaStreamTrack,t,e.attachedElements));;){let r=e.dimensions;if(r)return r;if(Date.now()-n>=t)break;yield U(50)}throw new bo(`unable to get track dimensions after timeout`)}()})}setDeviceId(e){return O(this,void 0,void 0,function*(){return this._constraints.deviceId===e&&this._mediaStreamTrack.getSettings().deviceId===ac(e)&&this._mediaStreamTrack.readyState===`live`||(this._constraints.deviceId=e,this.isMuted?(this.pendingDeviceChange=!0,!0):(yield this.restartTrack(),ac(e)===this._mediaStreamTrack.getSettings().deviceId))})}getDeviceId(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;return function*(){if(e.source===H.Source.ScreenShare)return;let n=e._mediaStreamTrack.getSettings(),r=n.deviceId,i=n.groupId,a=e.kind===H.Kind.Audio?`audioinput`:`videoinput`;return t?Tl.getInstance().normalizeDeviceId(a,r,i):r}()})}mute(){return O(this,void 0,void 0,function*(){return this.setTrackMuted(!0),this})}unmute(){return O(this,void 0,void 0,function*(){return this.setTrackMuted(!1),this})}replaceTrack(e,t){return O(this,void 0,void 0,function*(){let n=yield this.trackChangeLock.lock();try{if(!this.sender)throw new bo(`unable to replace an unpublished track`);let n,r;typeof t==`boolean`?n=t:t!==void 0&&(n=t.userProvidedTrack,r=t.stopProcessor),this.providedByUser=n??!0,this.log.debug(`replace MediaStreamTrack`,this.logContext),yield this.setMediaStreamTrack(e),r&&this.processor&&(yield this.internalStopProcessor())}finally{n()}return yield this.onSenderTrackSwapped(),this})}onSenderTrackSwapped(){return O(this,void 0,void 0,function*(){})}restart(e,t){return O(this,void 0,void 0,function*(){this.manuallyStopped=!1;let n=yield this.trackChangeLock.lock();try{e||=this._constraints;let n=e,r=n.deviceId,i=n.facingMode,a=Bi(e,[`deviceId`,`facingMode`]);this.log.debug(`restarting track with constraints`,Object.assign(Object.assign({},this.logContext),{constraints:e}));let o={audio:!1,video:!1};this.kind===H.Kind.Video?o.video=r||i?{deviceId:r,facingMode:i}:!0:o.audio=!r||Object.assign({deviceId:r},a),this.attachedElements.forEach(e=>{ds(this.mediaStreamTrack,e)}),this._mediaStreamTrack.removeEventListener(`ended`,this.handleEnded),this._mediaStreamTrack.stop();let s;try{s=yield navigator.mediaDevices.getUserMedia(o)}catch(e){throw cc(e),e}let c=s.getTracks()[0];try{this.kind===H.Kind.Video&&(yield c.applyConstraints(a)),c.addEventListener(`ended`,this.handleEnded),this.log.debug(`re-acquired MediaStreamTrack`,this.logContext),yield this.setMediaStreamTrack(c,!1,t)}catch(e){throw this._mediaStreamTrack!==c&&c.stop(),e}return this._constraints=e,this.pendingDeviceChange=!1,this.emit(z.Restarted,this),this}finally{this.manuallyStopped&&(this.log.warn(`track was stopped during a restart, stopping restarted track`,this.logContext),this.stop()),n()}})}setTrackMuted(e){this.log.debug(`setting ${this.kind} track ${e?`muted`:`unmuted`}`,this.logContext),(this.isMuted!==e||this._mediaStreamTrack.enabled===e)&&(this.isMuted=e,this._mediaStreamTrack.enabled=!e,this.emit(e?z.Muted:z.Unmuted,this))}get needsReAcquisition(){return this._mediaStreamTrack.readyState!==`live`||this._mediaStreamTrack.muted||!this._mediaStreamTrack.enabled||this.reacquireTrack}handleAppVisibilityChanged(){let e=Object.create(null,{handleAppVisibilityChanged:{get:()=>super.handleAppVisibilityChanged}});return O(this,void 0,void 0,function*(){yield e.handleAppVisibilityChanged.call(this),Is()&&(this.log.debug(`visibility changed, is in Background: ${this.isInBackground}`,this.logContext),!this.isInBackground&&this.needsReAcquisition&&!this.isUserProvided&&!this.isMuted&&(this.log.debug(`track needs to be reacquired, restarting ${this.source}`,this.logContext),yield this.restart(),this.reacquireTrack=!1))})}stop(){var e;this.manuallyStopped=!0,super.stop(),this._mediaStreamTrack.removeEventListener(`ended`,this.handleEnded),this._mediaStreamTrack.removeEventListener(`mute`,this.handleTrackMuteEvent),this._mediaStreamTrack.removeEventListener(`unmute`,this.handleTrackUnmuteEvent),(e=this.processor)==null||e.destroy().catch(e=>{this.log.error(`failed to destroy processor`,Object.assign(Object.assign({},this.logContext),{error:e}))}),this.processor=void 0}pauseUpstream(){return O(this,void 0,void 0,function*(){let e=yield this.pauseUpstreamLock.lock();try{if(this._isUpstreamPaused===!0)return;if(!this.sender){this.log.warn(`unable to pause upstream for an unpublished track`,this.logContext);return}this._isUpstreamPaused=!0,this.emit(z.UpstreamPaused,this);let e=k();if(e?.name===`Safari`&&Ws(e.version,`12.0`)<0)throw new yo(`pauseUpstream is not supported on Safari < 12.`);this.sender.transport?.state!==`closed`&&(yield this.sender.replaceTrack(null))}finally{e()}})}resumeUpstream(){return O(this,void 0,void 0,function*(){let e=yield this.pauseUpstreamLock.lock();try{if(this._isUpstreamPaused===!1)return;if(!this.sender){this.log.warn(`unable to resume upstream for an unpublished track`,this.logContext);return}this._isUpstreamPaused=!1,this.emit(z.UpstreamResumed,this),this.sender.transport?.state!==`closed`&&(yield this.sender.replaceTrack(this.mediaStreamTrack))}finally{e()}})}getRTCStatsReport(){return O(this,void 0,void 0,function*(){if(this.sender?.getStats)return yield this.sender.getStats()})}setProcessor(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return function*(){let r=yield t.trackChangeLock.lock();try{t.log.debug(`setting up processor`,t.logContext);let r=document.createElement(t.kind),i={kind:t.kind,track:t._mediaStreamTrack,element:r,audioContext:t.audioContext,localTrack:t};if(yield e.init(i),t.log.debug(`processor initialized`,t.logContext),t.processor&&(yield t.internalStopProcessor()),t.kind===`unknown`)throw TypeError(`cannot set processor on track of unknown kind`);if(us(t._mediaStreamTrack,r),r.muted=!0,r.play().catch(e=>{e instanceof DOMException&&e.name===`AbortError`?(t.log.warn(`failed to play processor element, retrying`,Object.assign(Object.assign({},t.logContext),{error:e})),setTimeout(()=>{r.play().catch(e=>{t.log.error(`failed to play processor element`,Object.assign(Object.assign({},t.logContext),{err:e}))})},100)):t.log.error(`failed to play processor element`,Object.assign(Object.assign({},t.logContext),{error:e}))}),t.processor=e,t.processorElement=r,t.processor.processedTrack){for(let e of t.attachedElements)e!==t.processorElement&&n&&(ds(t._mediaStreamTrack,e),us(t.processor.processedTrack,e));yield t.sender?.replaceTrack(t.processor.processedTrack)}t.emit(z.TrackProcessorUpdate,t.processor)}finally{r()}yield t.onSenderTrackSwapped()}()})}getProcessor(){return this.processor}stopProcessor(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;return function*(){let n=yield e.trackChangeLock.lock();try{yield e.internalStopProcessor(t)}finally{n()}yield e.onSenderTrackSwapped()}()})}internalStopProcessor(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;return function*(){var n,r;e.processor&&(e.log.debug(`stopping processor`,e.logContext),(n=e.processor.processedTrack)==null||n.stop(),yield e.processor.destroy(),e.processor=void 0,t||((r=e.processorElement)==null||r.remove(),e.processorElement=void 0),yield e._mediaStreamTrack.applyConstraints(e._constraints),yield e.setMediaStreamTrack(e._mediaStreamTrack,!0),e.emit(z.TrackProcessorUpdate))}()})}startPreConnectBuffer(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:100;if(!Id())this.log.warn(`MediaRecorder is not available, cannot start preconnect buffer`,this.logContext);else if(this.localTrackRecorder)this.log.warn(`preconnect buffer already started`);else{{let e=`audio/webm;codecs=opus`;MediaRecorder.isTypeSupported(e)||(e=`video/mp4`),this.localTrackRecorder=new Fd(this,{mimeType:e})}this.localTrackRecorder.start(e),this.autoStopPreConnectBuffer=setTimeout(()=>{this.log.warn(`preconnect buffer timed out, stopping recording automatically`,this.logContext),this.stopPreConnectBuffer()},Rd)}}stopPreConnectBuffer(){clearTimeout(this.autoStopPreConnectBuffer),this.localTrackRecorder&&=(this.localTrackRecorder.stop(),void 0)}getPreConnectBuffer(){return this.localTrackRecorder?.byteStream}getPreConnectBufferMimeType(){return this.localTrackRecorder?.mimeType}},Bd=class extends zd{get enhancedNoiseCancellation(){return this.isKrispNoiseFilterEnabled}constructor(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;super(e,H.Kind.Audio,t,n,i),this.stopOnMute=!1,this.isKrispNoiseFilterEnabled=!1,this.monitorSender=()=>O(this,void 0,void 0,function*(){if(!this.sender){this._currentBitrate=0;return}let e;try{e=yield this.getSenderStats()}catch(e){this.log.error(`could not get audio sender stats`,Object.assign(Object.assign({},this.logContext),{error:e}));return}e&&this.prevStats&&(this._currentBitrate=ll(e,this.prevStats)),this.prevStats=e}),this.handleKrispNoiseFilterEnable=()=>{this.isKrispNoiseFilterEnabled=!0,this.log.debug(`Krisp noise filter enabled`,this.logContext),this.emit(z.AudioTrackFeatureUpdate,this,x.TF_ENHANCED_NOISE_CANCELLATION,!0)},this.handleKrispNoiseFilterDisable=()=>{this.isKrispNoiseFilterEnabled=!1,this.log.debug(`Krisp noise filter disabled`,this.logContext),this.emit(z.AudioTrackFeatureUpdate,this,x.TF_ENHANCED_NOISE_CANCELLATION,!1)},this.audioContext=r,this.checkForSilence()}mute(){let e=Object.create(null,{mute:{get:()=>super.mute}});return O(this,void 0,void 0,function*(){let t=yield this.muteLock.lock();try{return this.isMuted?(this.log.debug(`Track already muted`,this.logContext),this):(this.source===H.Source.Microphone&&this.stopOnMute&&!this.isUserProvided&&(this.log.debug(`stopping mic track`,this.logContext),this._mediaStreamTrack.stop()),yield e.mute.call(this),this)}finally{t()}})}unmute(){let e=Object.create(null,{unmute:{get:()=>super.unmute}});return O(this,void 0,void 0,function*(){let t=yield this.muteLock.lock();try{return this.isMuted?(this.source===H.Source.Microphone&&(this.stopOnMute||this._mediaStreamTrack.readyState===`ended`||this.pendingDeviceChange)&&!this.isUserProvided&&(this.log.debug(`reacquiring mic track`,this.logContext),yield this.restart(void 0,!0)),yield e.unmute.call(this),this):(this.log.debug(`Track already unmuted`,this.logContext),this)}finally{t()}})}restartTrack(e){return O(this,void 0,void 0,function*(){let t;if(e){let n=Ko({audio:e});typeof n.audio!=`boolean`&&(t=n.audio)}yield this.restart(t)})}applyConstraints(e){return O(this,void 0,void 0,function*(){let t=yield this.trackChangeLock.lock();try{let t=yield this._mediaStreamTrack.applyConstraints(e);return this._constraints=Object.assign(Object.assign({},this._constraints),e),t}finally{t()}})}restart(e,t){let n=Object.create(null,{restart:{get:()=>super.restart}});return O(this,void 0,void 0,function*(){let r=yield n.restart.call(this,e,t);return this.checkForSilence(),r})}startMonitor(){W()&&(this.monitorInterval||=setInterval(()=>{this.monitorSender()},cl))}observeProcessedTrack(e){this.observedProcessedTrack!==e&&(this.observedProcessedTrack&&(this.observedProcessedTrack.removeEventListener(`enable-lk-krisp-noise-filter`,this.handleKrispNoiseFilterEnable),this.observedProcessedTrack.removeEventListener(`disable-lk-krisp-noise-filter`,this.handleKrispNoiseFilterDisable),this.observedProcessedTrack=void 0,this.isKrispNoiseFilterEnabled&&this.handleKrispNoiseFilterDisable()),e&&(e.addEventListener(`enable-lk-krisp-noise-filter`,this.handleKrispNoiseFilterEnable),e.addEventListener(`disable-lk-krisp-noise-filter`,this.handleKrispNoiseFilterDisable),this.observedProcessedTrack=e))}setProcessor(e){return O(this,void 0,void 0,function*(){let t=yield this.trackChangeLock.lock();try{if(!Rs()&&!this.audioContext)throw Error(`Audio context needs to be set on LocalAudioTrack in order to enable processors`);this.processor&&(yield this.internalStopProcessor());let t={kind:this.kind,track:this._mediaStreamTrack,audioContext:this.audioContext,localTrack:this};this.log.debug(`setting up audio processor ${e.name}`,this.logContext),yield e.init(t),this.processor=e,this.processor.processedTrack&&(yield this.sender?.replaceTrack(this.processor.processedTrack),this.observeProcessedTrack(this.processor.processedTrack)),this.emit(z.TrackProcessorUpdate,this.processor)}finally{t()}})}onMediaStreamTrackChanged(){return O(this,void 0,void 0,function*(){this.observeProcessedTrack(this.processor?.processedTrack)})}internalStopProcessor(){let e=Object.create(null,{internalStopProcessor:{get:()=>super.internalStopProcessor}});return O(this,arguments,void 0,function(){var t=this;let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;return function*(){t.observeProcessedTrack(void 0),yield e.internalStopProcessor.call(t,n)}()})}stop(){this.observeProcessedTrack(void 0),super.stop()}setAudioContext(e){return O(this,void 0,void 0,function*(){if(this.audioContext===e)return;let t=yield this.trackChangeLock.lock();try{if(this.audioContext=e,!this.processor||Rs())return;if(!e){this.log.debug(`stopping audio processor, audio context has been removed`,this.logContext),yield this.internalStopProcessor();return}this.log.debug(`restarting audio processor on new audio context`,this.logContext),yield this.processor.restart({kind:this.kind,track:this._mediaStreamTrack,audioContext:e,localTrack:this}),this.processor.processedTrack&&(yield this.sender?.replaceTrack(this.processor.processedTrack),this.observeProcessedTrack(this.processor.processedTrack)),this.emit(z.TrackProcessorUpdate,this.processor)}finally{t()}})}getSenderStats(){return O(this,void 0,void 0,function*(){if(!this.sender?.getStats)return;let e=yield this.sender.getStats(),t;return e.forEach(n=>{if(n.type===`outbound-rtp`){t={type:`audio`,streamId:n.id,packetsSent:n.packetsSent,bytesSent:n.bytesSent,timestamp:n.timestamp};let r=e.get(n.remoteId);r&&(t.packetsLost=r.packetsLost,t.jitter=r.jitter,t.roundTripTime=r.roundTripTime)}}),t})}checkForSilence(){return O(this,void 0,void 0,function*(){let e=yield qo(this);return e&&(this.isMuted||this.log.debug(`silence detected on local audio track`,this.logContext),this.emit(z.AudioSilenceDetected)),e})}};function Vd(e,t,n){switch(e.kind){case`audio`:return new Bd(e,t,!1,void 0,n);case`video`:return new sf(e,t,!1,n);default:throw new bo(`unsupported track type: ${e.kind}`)}}var Hd=Object.values(Vo),Ud=Object.values(Ho),Wd=Object.values(Uo),Gd=[Vo.h180,Vo.h360],Kd=[Ho.h180,Ho.h360],qd=e=>[{scaleResolutionDownBy:2,fps:e.encoding.maxFramerate}].map(t=>new B(Math.floor(e.width/t.scaleResolutionDownBy),Math.floor(e.height/t.scaleResolutionDownBy),Math.max(15e4,Math.floor(e.encoding.maxBitrate/(t.scaleResolutionDownBy**2*((e.encoding.maxFramerate??30)/(t.fps??30))))),t.fps,e.encoding.priority)),Jd=[`q`,`h`,`f`];function Yd(e,t,n,r){let i=r?.videoEncoding;e&&(i=r?.screenShareEncoding);let a=r?.simulcast,o=r?.scalabilityMode,s=r?.videoCodec,c=xs(s,r);if(!i&&!a&&!o||!t||!n)return[{}];i||(i=Qd(e,t,n,s),E.debug(`using video encoding`,i));let l=i.maxFramerate,u=new B(t,n,i.maxBitrate,i.maxFramerate,i.priority);if(o&&ys(s)&&!c){let e=new rf(o),t=[];if(e.spatial>3)throw Error(`unsupported scalabilityMode: ${o}`);let n=k();if(Ss()){let r=e.suffix==`h`?2:3,a=Fs(n);for(let n=0;n<e.spatial;n+=1)t.push({rid:Jd[2-n],maxBitrate:i.maxBitrate/r**+n,maxFramerate:u.encoding.maxFramerate,scaleResolutionDownBy:a?2**n:void 0});t[0].scalabilityMode=o}else t.push({maxBitrate:i.maxBitrate,maxFramerate:u.encoding.maxFramerate,scalabilityMode:o});return u.encoding.priority&&(t[0].priority=u.encoding.priority,t[0].networkPriority=u.encoding.priority),E.debug(`using svc encoding`,{encodings:t}),t}if(!a)return[i];let d=e=>(c&&e.forEach(e=>{e.scalabilityMode=o}),e),f;f=e?nf(r?.screenShareSimulcastLayers)??ef(e,u):nf(r?.videoSimulcastLayers)??ef(e,u);let p;if(f.length>0){let e=f[0];f.length>1&&(p=_(f,2)[1]);let r=Math.max(t,n);if(r>=960&&p)return d(tf(t,n,[e,p,u],l));if(r>=480)return d(tf(t,n,[e,u],l))}return d(tf(t,n,[u]))}function Xd(e,t,n){return ys(e)&&!xs(e,t)?n[0]?.maxBitrate??0:n.reduce((e,t)=>e+(t.maxBitrate??0),0)}function Zd(e,t,n){if(!n.backupCodec||n.backupCodec===!0||n.backupCodec.codec===n.videoCodec)return;t!==n.backupCodec.codec&&E.warn(`requested a different codec than specified as backup`,{serverRequested:t,backup:n.backupCodec.codec}),n.videoCodec=t,n.videoEncoding=n.backupCodec.encoding;let r=e.mediaStreamTrack.getSettings(),i=r.width??e.dimensions?.width,a=r.height??e.dimensions?.height;return e.source===H.Source.ScreenShare&&n.simulcast&&(n.simulcast=!1),Yd(e.source===H.Source.ScreenShare,i,a,n)}function Qd(e,t,n,r){let i=$d(e,t,n),a=i[0].encoding,o=Math.max(t,n);for(let e=0;e<i.length;e+=1){let t=i[e];if(a=t.encoding,t.width>=o)break}if(r)switch(r){case`av1`:case`h265`:a=Object.assign({},a),a.maxBitrate*=.7;break;case`vp9`:a=Object.assign({},a),a.maxBitrate*=.85}return a}function $d(e,t,n){if(e)return Wd;let r=t>n?t/n:n/t;return Math.abs(r-16/9)<Math.abs(r-4/3)?Hd:Ud}function ef(e,t){if(e)return qd(t);let n=t.width,r=t.height,i=n>r?n/r:r/n;return Math.abs(i-16/9)<Math.abs(i-4/3)?Gd:Kd}function tf(e,t,n,r){let i=[];if(n.forEach((n,a)=>{if(a>=Jd.length)return;let o=Math.min(e,t),s={rid:Jd[a],scaleResolutionDownBy:Math.max(1,o/Math.min(n.width,n.height)),maxBitrate:n.encoding.maxBitrate},c=r&&n.encoding.maxFramerate?Math.min(r,n.encoding.maxFramerate):n.encoding.maxFramerate;c&&(s.maxFramerate=c);let l=k(),u=l?.name===`Firefox`&&l.os!==`iOS`||a===0;n.encoding.priority&&u&&(s.priority=n.encoding.priority,s.networkPriority=n.encoding.priority),i.push(s)}),Rs()&&Hs()===`ios`){let e;i.forEach(t=>{e?t.maxFramerate&&t.maxFramerate>e&&(e=t.maxFramerate):e=t.maxFramerate});let t=!0;i.forEach(n=>{n.maxFramerate!=e&&(t&&(t=!1,E.info(`Simulcast on iOS React-Native requires all encodings to share the same framerate.`)),E.info(`Setting framerate of encoding "${n.rid??``}" to ${e}`),n.maxFramerate=e)})}return i}function nf(e){if(e)return e.slice().sort((e,t)=>{let n=e.encoding,r=t.encoding;return n.maxBitrate>r.maxBitrate?1:n.maxBitrate<r.maxBitrate?-1:n.maxBitrate===r.maxBitrate&&n.maxFramerate&&r.maxFramerate?n.maxFramerate>r.maxFramerate?1:-1:0})}var rf=class{constructor(e){let t=e.match(/^L(\d)T(\d)(h|_KEY|_KEY_SHIFT){0,1}$/);if(!t)throw Error(`invalid scalability mode`);if(this.spatial=parseInt(t[1]),this.temporal=parseInt(t[2]),t.length>3)switch(t[3]){case`h`:case`_KEY`:case`_KEY_SHIFT`:this.suffix=t[3]}}toString(){return`L${this.spatial}T${this.temporal}${this.suffix??``}`}};function af(e){switch(e.source){case H.Source.Camera:return`maintain-framerate`;case H.Source.ScreenShare:return`maintain-resolution`;default:return`balanced`}}var of=5e3,sf=class extends zd{get sender(){return this._sender}set sender(e){this._sender=e,this.degradationPreference&&this.setDegradationPreference(this.degradationPreference)}constructor(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r=arguments.length>3?arguments[3]:void 0;super(e,H.Kind.Video,t,n,r),this.simulcastCodecs=new Map,this.degradationPreference=`balanced`,this.isCpuConstrained=!1,this.optimizeForPerformance=!1,this.monitorSender=()=>O(this,void 0,void 0,function*(){if(!this.sender){this._currentBitrate=0;return}let e;try{e=yield this.getSenderStats()}catch(e){this.log.error(`could not get video sender stats`,Object.assign(Object.assign({},this.logContext),{error:e}));return}let t=new Map(e.map(e=>[e.rid,e])),n=e.some(e=>e.qualityLimitationReason===`cpu`);if(n!==this.isCpuConstrained&&(this.isCpuConstrained=n,this.isCpuConstrained&&this.emit(z.CpuConstrained)),this.prevStats){let e=0;t.forEach((t,n)=>{let r=this.prevStats?.get(n);e+=ll(t,r)}),this._currentBitrate=e}this.prevStats=t}),this.senderLock=new i}get isSimulcast(){return!!(this.sender&&this.sender.getParameters().encodings.length>1)}startMonitor(e){if(this.signalClient=e,!W())return;let t=this.sender?.getParameters();t&&(this.encodings=t.encodings),!this.monitorInterval&&(this.monitorInterval=setInterval(()=>{this.monitorSender()},cl))}stop(){this._mediaStreamTrack.getConstraints(),this.simulcastCodecs.forEach(e=>{e.mediaStreamTrack.stop()}),super.stop()}pauseUpstream(){let e=Object.create(null,{pauseUpstream:{get:()=>super.pauseUpstream}});return O(this,void 0,void 0,function*(){var t,n,r,i;yield e.pauseUpstream.call(this);try{for(var a=!0,o=Gi(this.simulcastCodecs.values()),s;s=yield o.next(),t=s.done,!t;a=!0)i=s.value,a=!1,yield i.sender?.replaceTrack(null)}catch(e){n={error:e}}finally{try{!a&&!t&&(r=o.return)&&(yield r.call(o))}finally{if(n)throw n.error}}})}resumeUpstream(){let e=Object.create(null,{resumeUpstream:{get:()=>super.resumeUpstream}});return O(this,void 0,void 0,function*(){var t,n,r,i;yield e.resumeUpstream.call(this);try{for(var a=!0,o=Gi(this.simulcastCodecs.values()),s;s=yield o.next(),t=s.done,!t;a=!0){i=s.value,a=!1;let e=i;yield e.sender?.replaceTrack(e.mediaStreamTrack)}}catch(e){n={error:e}}finally{try{!a&&!t&&(r=o.return)&&(yield r.call(o))}finally{if(n)throw n.error}}})}mute(){let e=Object.create(null,{mute:{get:()=>super.mute}});return O(this,void 0,void 0,function*(){let t=yield this.muteLock.lock();try{return this.isMuted?(this.log.debug(`Track already muted`,this.logContext),this):(this.source===H.Source.Camera&&!this.isUserProvided&&(this.log.debug(`stopping camera track`,this.logContext),this._mediaStreamTrack.stop()),yield e.mute.call(this),this)}finally{t()}})}unmute(){let e=Object.create(null,{unmute:{get:()=>super.unmute}});return O(this,void 0,void 0,function*(){let t=yield this.muteLock.lock();try{return this.isMuted?(this.source===H.Source.Camera&&!this.isUserProvided&&(this.log.debug(`reacquiring camera track`,this.logContext),yield this.restart(void 0,!0)),yield e.unmute.call(this),this):(this.log.debug(`Track already unmuted`,this.logContext),this)}finally{t()}})}setTrackMuted(e){super.setTrackMuted(e);for(let t of this.simulcastCodecs.values())t.mediaStreamTrack.enabled=!e}getSenderStats(){return O(this,void 0,void 0,function*(){if(!this.sender?.getStats)return[];let e=[],t=yield this.sender.getStats();return t.forEach(n=>{if(n.type===`outbound-rtp`){let r={type:`video`,streamId:n.id,frameHeight:n.frameHeight,frameWidth:n.frameWidth,framesPerSecond:n.framesPerSecond,framesSent:n.framesSent,firCount:n.firCount,pliCount:n.pliCount,nackCount:n.nackCount,packetsSent:n.packetsSent,bytesSent:n.bytesSent,qualityLimitationReason:n.qualityLimitationReason,qualityLimitationDurations:n.qualityLimitationDurations,qualityLimitationResolutionChanges:n.qualityLimitationResolutionChanges,rid:n.rid??n.id,retransmittedPacketsSent:n.retransmittedPacketsSent,targetBitrate:n.targetBitrate,timestamp:n.timestamp},i=t.get(n.remoteId);i&&(r.jitter=i.jitter,r.packetsLost=i.packetsLost,r.roundTripTime=i.roundTripTime),e.push(r)}}),e.sort((e,t)=>(t.frameWidth??0)-(e.frameWidth??0)),e})}isSvcPublish(e){return ys(e)&&!xs(e,this.publishOptions)}setPublishingQuality(e){let t=[];for(let n=ls.LOW;n<=ls.HIGH;n+=1)t.push(new $r({quality:n,enabled:n<=e}));this.log.debug(`setting publishing quality. max quality ${e}`,this.logContext),this.setPublishingLayers(this.isSvcPublish(this.codec),t)}restartTrack(e){return O(this,void 0,void 0,function*(){var t,n,r,i;let a;if(e){let t=Ko({video:e});typeof t.video!=`boolean`&&(a=t.video)}yield this.restart(a),this.isCpuConstrained=!1;try{for(var o=!0,s=Gi(this.simulcastCodecs.values()),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let e=i;e.sender&&e.sender.transport?.state!==`closed`&&(e.mediaStreamTrack=this.mediaStreamTrack.clone(),yield e.sender.replaceTrack(e.mediaStreamTrack))}}catch(e){n={error:e}}finally{try{!o&&!t&&(r=s.return)&&(yield r.call(s))}finally{if(n)throw n.error}}yield this.onSenderTrackSwapped()})}onSenderTrackSwapped(){return O(this,void 0,void 0,function*(){yield this.refreshSenderEncodings()})}refreshSenderEncodings(){return O(this,void 0,void 0,function*(){if(!this.sender||!this.publishOptions||this.optimizeForPerformance)return;let e=yield this.senderLock.lock();try{let e;try{e=yield this.waitForDimensions()}catch(e){this.log.warn(`could not determine new track dimensions, skipping encoding recompute`,Object.assign(Object.assign({},this.logContext),{error:e}));return}if(this.lastEncodedDimensions&&this.lastEncodedDimensions.width===e.width&&this.lastEncodedDimensions.height===e.height)return;let n=Yd(this.source===H.Source.ScreenShare,e.width,e.height,Object.assign({},this.publishOptions));yield this.applyEncodingsToSender(this.sender,n),this.encodings=n,this.lastEncodedDimensions=e;for(let e of this.simulcastCodecs){var t=_(e,2);let n=t[0],r=t[1];if(!r.sender||r.sender.transport?.state===`closed`||!Lo(n))continue;let i=Object.assign({},this.publishOptions),a=Zd(this,n,i);a&&(yield this.applyEncodingsToSender(r.sender,a),r.encodings=a)}}catch(e){this.log.warn(`failed to apply recomputed encodings`,Object.assign(Object.assign({},this.logContext),{error:e}))}finally{e()}})}applyEncodingsToSender(e,t){return O(this,void 0,void 0,function*(){let n=e.getParameters();n.encodings&&n.encodings.length===t.length&&(n.encodings.forEach((e,n)=>{if(e.active===!1)return;let r=t[n];r.scaleResolutionDownBy!==void 0&&(e.scaleResolutionDownBy=r.scaleResolutionDownBy),r.maxBitrate!==void 0&&(e.maxBitrate=r.maxBitrate),r.maxFramerate!==void 0&&(e.maxFramerate=r.maxFramerate),r.priority!==void 0&&(e.priority=r.priority,e.networkPriority=r.priority)}),this.log.debug(`updating sender encodings after track restart`,Object.assign(Object.assign({},this.logContext),{encodings:n.encodings})),yield e.setParameters(n))})}setProcessor(e){let t=Object.create(null,{setProcessor:{get:()=>super.setProcessor}});return O(this,arguments,void 0,function(e){var n=this;let r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return function*(){var i,a,o,s;if(yield t.setProcessor.call(n,e,r),n.processor?.processedTrack)try{for(var c=!0,l=Gi(n.simulcastCodecs.values()),u;u=yield l.next(),i=u.done,!i;c=!0)s=u.value,c=!1,yield s.sender?.replaceTrack(n.processor.processedTrack)}catch(e){a={error:e}}finally{try{!c&&!i&&(o=l.return)&&(yield o.call(l))}finally{if(a)throw a.error}}}()})}setDegradationPreference(e){return O(this,void 0,void 0,function*(){this.degradationPreference=e,yield this.applyDegradationPreference(this.sender);for(let e of this.simulcastCodecs.values())yield this.applyDegradationPreference(e.sender)})}applyDegradationPreference(e){return O(this,void 0,void 0,function*(){if(e)try{this.log.debug(`setting degradationPreference to ${this.degradationPreference}`,this.logContext);let t=e.getParameters();t.degradationPreference=this.degradationPreference,yield e.setParameters(t)}catch(e){this.log.warn(`failed to set degradationPreference`,Object.assign({error:e},this.logContext))}})}addSimulcastTrack(e,t){if(this.simulcastCodecs.has(e)){this.log.error(`${e} already added, skipping adding simulcast codec`,this.logContext);return}let n={codec:e,mediaStreamTrack:this.mediaStreamTrack.clone(),sender:void 0,encodings:t};return this.simulcastCodecs.set(e,n),n}setSimulcastTrackSender(e,t){return O(this,void 0,void 0,function*(){let n=this.simulcastCodecs.get(e);n&&(n.sender=t,yield this.applyDegradationPreference(t),setTimeout(()=>{this.refreshSubscribedCodecs()},of))})}refreshSubscribedCodecs(){return O(this,void 0,void 0,function*(){if(this.subscribedCodecs)return this.setPublishingCodecs(this.subscribedCodecs).catch(e=>this.log.warn(`failed to refresh codec for track`,Object.assign(Object.assign({},this.logContext),{error:e})))})}setPublishingCodecs(e){return O(this,void 0,void 0,function*(){var t,n,r,i,a,o,s;if(this.log.debug(`setting publishing codecs`,Object.assign(Object.assign({},this.logContext),{codecs:e,currentCodec:this.codec})),!this.codec&&e.length>0)return yield this.setPublishingLayers(this.isSvcPublish(e[0].codec),e[0].qualities),[];this.subscribedCodecs=e;let c=[];try{for(t=!0,n=Gi(e);r=yield n.next(),i=r.done,!i;t=!0){s=r.value,t=!1;let e=s;if(!this.codec||this.codec===e.codec)yield this.setPublishingLayers(this.isSvcPublish(e.codec),e.qualities);else{let t=this.simulcastCodecs.get(e.codec);if(this.log.debug(`try setPublishingCodec for ${e.codec}`,Object.assign(Object.assign({},this.logContext),{simulcastCodecInfo:t})),!t||!t.sender){for(let t of e.qualities)if(t.enabled){c.push(e.codec);break}}else t.encodings&&(this.log.debug(`try setPublishingLayersForSender ${e.codec}`,this.logContext),yield cf(t.sender,t.encodings,e.qualities,this.senderLock,this.isSvcPublish(e.codec),this.log,this.logContext))}}}catch(e){a={error:e}}finally{try{!t&&!i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a.error}}return c})}setPublishingLayers(e,t){return O(this,void 0,void 0,function*(){this.optimizeForPerformance?this.log.info(`skipping setPublishingLayers due to optimized publishing performance`,Object.assign(Object.assign({},this.logContext),{qualities:t})):(this.log.debug(`setting publishing layers`,Object.assign(Object.assign({},this.logContext),{qualities:t})),this.sender&&this.encodings&&(yield cf(this.sender,this.encodings,t,this.senderLock,e,this.log,this.logContext)))})}prioritizePerformance(){return O(this,void 0,void 0,function*(){if(!this.sender)throw Error(`sender not found`);let e=yield this.senderLock.lock();try{this.optimizeForPerformance=!0;let e=this.sender.getParameters();e.encodings=e.encodings.map((e,t)=>Object.assign(Object.assign({},e),{active:t===0,scaleResolutionDownBy:Math.max(1,Math.ceil((this.mediaStreamTrack.getSettings().height??360)/360)),scalabilityMode:t===0&&ys(this.codec)?`L1T3`:void 0,maxFramerate:t===0?15:0,maxBitrate:t===0?e.maxBitrate:0})),this.log.debug(`setting performance optimised encodings`,Object.assign(Object.assign({},this.logContext),{encodings:e.encodings})),this.encodings=e.encodings,yield this.sender.setParameters(e)}catch(e){this.log.error(`failed to set performance optimised encodings`,Object.assign(Object.assign({},this.logContext),{error:e})),this.optimizeForPerformance=!1}finally{e()}})}handleAppVisibilityChanged(){let e=Object.create(null,{handleAppVisibilityChanged:{get:()=>super.handleAppVisibilityChanged}});return O(this,void 0,void 0,function*(){yield e.handleAppVisibilityChanged.call(this),Is()&&this.isInBackground&&this.source===H.Source.Camera&&(this._mediaStreamTrack.enabled=!1)})}};function cf(e,t,n,r,i,a,o){return O(this,void 0,void 0,function*(){let s=yield r.lock();a.debug(`setPublishingLayersForSender`,Object.assign(Object.assign({},o),{sender:e,qualities:n,senderEncodings:t}));try{let r=e.getParameters(),s=r.encodings;if(!s)return;if(s.length!==t.length){a.warn(`cannot set publishing layers, encodings mismatch`,Object.assign(Object.assign({},o),{encodings:s,senderEncodings:t}));return}let c=!1;i&&n.some(e=>e.enabled)&&n.forEach(e=>e.enabled=!0),s.forEach((e,r)=>{let i=e.rid??``;i===``&&(i=`q`);let s=lf(i),l=n.find(e=>e.quality===s);l&&e.active!==l.enabled&&(c=!0,e.active=l.enabled,a.debug(`setting layer ${l.quality} to ${e.active?`enabled`:`disabled`}`,o),Ds()&&(l.enabled?(e.scaleResolutionDownBy=t[r].scaleResolutionDownBy,e.maxBitrate=t[r].maxBitrate,e.maxFrameRate=t[r].maxFrameRate):(e.scaleResolutionDownBy=4,e.maxBitrate=10,e.maxFrameRate=2)))}),c&&(r.encodings=s,a.debug(`setting encodings`,Object.assign(Object.assign({},o),{encodings:r.encodings})),yield e.setParameters(r))}finally{s()}})}function lf(e){switch(e){case`f`:return ls.HIGH;case`h`:return ls.MEDIUM;case`q`:return ls.LOW;default:return ls.HIGH}}function uf(e,t,n,r){if(!n)return[new Mn({quality:ls.HIGH,width:e,height:t,bitrate:0,ssrc:0})];if(r){let r=n[0].scalabilityMode,i=new rf(r),a=[],o=i.suffix==`h`?1.5:2,s=i.suffix==`h`?2:3;for(let r=0;r<i.spatial;r+=1)a.push(new Mn({quality:Math.min(ls.HIGH,i.spatial-1)-r,width:Math.ceil(e/o**+r),height:Math.ceil(t/o**+r),bitrate:n[0].maxBitrate?Math.ceil(n[0].maxBitrate/s**+r):0,ssrc:0}));return a}return n.map(n=>{let r=n.scaleResolutionDownBy??1;return new Mn({quality:lf(n.rid??``),width:Math.ceil(e/r),height:Math.ceil(t/r),bitrate:n.maxBitrate??0,ssrc:0})})}var df=2e3,ff=`leave-reconnect`,pf=1e4,mf=3e4,hf=3,gf=3,_f;(function(e){e[e.New=0]=`New`,e[e.Connected=1]=`Connected`,e[e.Disconnected=2]=`Disconnected`,e[e.Reconnecting=3]=`Reconnecting`,e[e.Closed=4]=`Closed`})(_f||={});var vf=64e3,yf=class extends Yi.EventEmitter{get isClosed(){return this._isClosed}get isNewlyCreated(){return this._isNewlyCreated}get pendingReconnect(){return!!this.reconnectTimeout}get serverVersion(){return this.latestJoinResponse?.serverInfo?.version||this.latestJoinResponse?.serverVersion||void 0}get reliableChannel(){return this.dataChannels.reliable}get lossyChannel(){return this.dataChannels.lossy}get dataTrackChannel(){return this.dataChannels.dataTrack}constructor(e){super(),this.options=e,this.rtcConfig={},this.peerConnectionTimeout=gd.peerConnectionTimeout,this.fullReconnectOnNext=!1,this.latestRemoteOfferId=0,this.subscriberPrimary=!1,this.pcState=_f.New,this._isClosed=!0,this._isNewlyCreated=!0,this.pendingTrackResolvers={},this.reconnectAttempts=0,this.reconnectStart=0,this.attemptingReconnect=!1,this.joinAttempts=0,this.maxJoinAttempts=1,this.shouldFailNext=!1,this.shouldFailOnV1Path=!1,this.log=E,this.reliableReceivedState=new wu(mf),this.midToTrackId={},this.isWaitingForNetworkReconnect=!1,this.pendingNegotiationAborts=new Set,this.handleDataChannel=e=>O(this,[e],void 0,function(e){var t=this;let n=e.channel;return function*(){n&&t.dataChannels.adoptSubscriberChannel(n)&&t.log.debug(`on data channel ${n.id}, ${n.label}`)}()}),this.handleDataMessage=e=>O(this,void 0,void 0,function*(){let t=yield this.dataProcessLock.lock();try{let t=yield this.decodeDataMessage(e);if(!t)return;let n=C.fromBinary(t);if(n.sequence>0&&n.participantSid!==``){let e=this.reliableReceivedState.get(n.participantSid);if(e&&n.sequence<=e)return;this.reliableReceivedState.set(n.participantSid,n.sequence)}if(n.value?.case===`speaker`)this.emit(R.ActiveSpeakersUpdate,n.value.value.speakers);else if(n.value?.case===`encryptedPacket`){if(!this.e2eeManager){this.log.error(`Received encrypted packet but E2EE not set up`);return}let e;try{e=yield this.e2eeManager.handleEncryptedData(n.value.value.encryptedValue,n.value.value.iv,n.participantIdentity,n.value.value.keyIndex)}catch(e){this.log.debug(`failed to decrypt data packet`,{error:e,participantIdentity:n.participantIdentity});return}let t=new C({value:In.fromBinary(e.payload).value,participantIdentity:n.participantIdentity,participantSid:n.participantSid});t.value?.case===`user`&&bf(t,t.value.value),this.emit(R.DataPacketReceived,t,n.value.value.encryptionType)}else n.value?.case===`user`&&bf(n,n.value.value),this.emit(R.DataPacketReceived,n,S.NONE)}finally{t()}}),this.handleDataTrackMessage=e=>O(this,void 0,void 0,function*(){let t=yield this.decodeDataMessage(e);t&&this.emit(`dataTrackPacketReceived`,t)}),this.handleDataError=e=>{if(this._isClosed)return;let t=e.currentTarget.maxRetransmits===0?`lossy`:`reliable`;if(typeof RTCErrorEvent<`u`&&e instanceof RTCErrorEvent&&e.error){let n=e.error;this.log.error(`DataChannel error on ${t}: ${n.message}`,{error:n,errorDetail:n.errorDetail,sctpCauseCode:n.sctpCauseCode})}else this.log.error(`Unknown DataChannel error on ${t}`,{event:e})},this.handleDataChannelClose=e=>()=>{!this._isClosed&&this.pcManager?.publisher.getConnectionState()===`connected`&&this.log.error(`publisher data channel '${q[e]}' closed unexpectedly`,this.logContext)},this.handleDisconnect=(e,t)=>{if(this._isClosed)return;this.log.warn(`${e} disconnected`),this.reconnectAttempts===0&&(this.reconnectStart=Date.now());let n=e=>{this.log.warn(`could not recover connection after ${this.reconnectAttempts} attempts, ${e}ms. giving up`),this.emit(R.Disconnected),this.close(`gave up reconnecting after ${this.reconnectAttempts} attempts, ${e}ms`)},r=Date.now()-this.reconnectStart,i=this.getNextRetryDelay({elapsedMs:r,retryCount:this.reconnectAttempts});i===null||e===ff&&(i=this.getNextRetryDelay({elapsedMs:r,retryCount:0}),i===null)?n(r):(this.log.debug(`reconnecting in ${i}ms`),this.clearReconnectTimeout(),this.token&&this.emit(R.TokenRefreshed,this.token),this.reconnectTimeout=F.setTimeout(()=>this.attemptReconnect(t).finally(()=>this.reconnectTimeout=void 0),i))},this.waitForRestarted=()=>new Promise((e,t)=>{this.pcState===_f.Connected&&e();let n=()=>{this.off(R.Disconnected,r),e()},r=()=>{this.off(R.Restarted,n),t()};this.once(R.Restarted,n),this.once(R.Disconnected,r)}),this.onRtpMapAvailable=e=>{let t=new Map;e.forEach(e=>{let n=e.codec.toLowerCase();ic(n)&&t.set(e.payload,n)}),this.emit(R.RTPVideoMapUpdate,t)},this.handleBrowserOnLine=()=>O(this,void 0,void 0,function*(){this.url&&(yield fetch(dc(this.url),{method:`HEAD`}).then(e=>e.ok).catch(()=>!1))&&(this.log.info(`detected network reconnected`),(this.client.currentState===hu.RECONNECTING||this.isWaitingForNetworkReconnect&&this.client.currentState===hu.CONNECTED)&&(this.clearReconnectTimeout(),this.attemptReconnect(dn.RR_SIGNAL_DISCONNECTED),this.isWaitingForNetworkReconnect=!1))}),this.handleBrowserOffline=()=>O(this,void 0,void 0,function*(){if(this.url)try{yield Promise.race([fetch(dc(this.url),{method:`HEAD`}),U(4e3).then(()=>Promise.reject())])}catch{window.navigator.onLine===!1&&(this.log.info(`detected network interruption`),this.isWaitingForNetworkReconnect=!0)}}),this.log=D(e.loggerName??T.Engine,()=>this.logContext),this.loggerOptions={loggerName:e.loggerName,loggerContextCb:()=>this.logContext},this.client=new yu(void 0,this.loggerOptions),this.client.signalLatency=this.options.expSignalLatency,this.reconnectPolicy=this.options.reconnectPolicy,this.closingLock=new i,this.dataProcessLock=new i,this.dataChannels=new Md({isEngineClosed:()=>this.isClosed,isReconnecting:()=>this.attemptingReconnect,onDataMessage:e=>this.handleDataMessage(e),onDataTrackMessage:e=>this.handleDataTrackMessage(e),onDataError:e=>this.handleDataError(e),onChannelClose:e=>this.handleDataChannelClose(e)(),onBufferStatusChanged:(e,t)=>this.emit(R.DCBufferStatusChanged,t,e)}),this.client.onParticipantUpdate=e=>this.emit(R.ParticipantUpdate,e),this.client.onConnectionQuality=e=>{this.handleLocalConnectionQuality(e),this.emit(R.ConnectionQualityUpdate,e)},this.client.onRoomUpdate=e=>this.emit(R.RoomUpdate,e),this.client.onSubscriptionError=e=>this.emit(R.SubscriptionError,e),this.client.onSubscriptionPermissionUpdate=e=>this.emit(R.SubscriptionPermissionUpdate,e),this.client.onSpeakersChanged=e=>this.emit(R.SpeakersChanged,e),this.client.onStreamStateUpdate=e=>this.emit(R.StreamStateChanged,e),this.client.onRequestResponse=e=>this.emit(R.SignalRequestResponse,e),this.client.onParticipantUpdate=e=>this.emit(R.ParticipantUpdate,e),this.client.onJoined=e=>this.emit(R.Joined,e);let t=()=>{for(let e of Array.from(this.pendingNegotiationAborts))e()};this.on(R.Closing,t),this.on(R.Restarting,t)}get logContext(){return{room:this.latestJoinResponse?.room?.name,roomID:this.latestJoinResponse?.room?.sid,participant:this.latestJoinResponse?.participant?.identity,participantID:this.participantSid}}join(e,t,n,r){return O(this,arguments,void 0,function(e,t,n,r){var i=this;let a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return function*(){var o,s;i._isNewlyCreated=!1,i.url=e,i.token=t,i.signalOpts=n,i.maxJoinAttempts=n.maxRetries;try{i.joinAttempts+=1,i.joinStartedAt=performance.now(),i.setupSignalClientCallbacks();let c=!a&&Pc(),l;if(c){i.pcManager||(yield i.configure(),i.applyInitialPublisherLayout());let e=yield i.pcManager?.publisher.createInitialOffer();e&&(l=xu(e.offer,e.offerId))}if(r?.aborted)throw j.cancelled(`Connection aborted`);if(!a&&i.shouldFailOnV1Path)throw i.shouldFailOnV1Path=!1,j.serviceNotFound(`Simulated v1 path failure`,`v0-rtc`);let u=yield i.client.join(e,t,n,r,a,l);if(r?.aborted)throw i.log.info(`join cancelled after the signal join response`),j.cancelled(`Connection aborted`);if(i._isClosed=!1,i.latestJoinResponse=u,i.participantSid=u.participant?.sid,i.subscriberPrimary=u.subscriberPrimary,c)(o=i.pcManager)==null||o.updateConfiguration(i.makeRTCConfiguration(u));else{if(!i.pcManager){if(yield i.configure(u,!a),r?.aborted)throw i.log.info(`join cancelled after configuring peer connections`),j.cancelled(`Connection aborted`);a||i.applyInitialPublisherLayout()}(!i.subscriberPrimary||u.fastPublish)&&i.negotiate().catch(e=>{i.log.error(e)})}i.joinStartedAt!==void 0&&((s=i.pcManager)==null||s.publisher.setConnectionStartedAt(i.joinStartedAt)),i.registerOnLineListener(),i.clientConfiguration=u.clientConfiguration,i.emit(R.SignalConnected,u);let d=u.serverInfo;return d||={version:u.serverVersion,region:u.serverRegion},i.log.info(`connected to Livekit Server ${Object.entries(d).map(e=>{let t=_(e,2);return`${t[0]}: ${t[1]}`}).join(`, `)}`),{joinResponse:u,serverInfo:d}}catch(o){if(o instanceof j){if(o.reason===A.ServerUnreachable){if(i.log.warn(`Couldn't connect to server, attempt ${i.joinAttempts} of ${i.maxJoinAttempts}`),i.joinAttempts<i.maxJoinAttempts)return i.join(e,t,n,r,a)}else if(o.reason===A.ServiceNotFound)return i.log.warn(`Initial connection failed: ${o.message} – Retrying`),i.pcManager&&(i.pcManager.onStateChange=void 0,yield i.cleanupPeerConnections()),i.join(e,t,n,r,!0)}throw o}}()})}close(e){return O(this,void 0,void 0,function*(){var t;(t=this.reconnectAbortController)==null||t.abort(),this.reconnectAbortController=void 0;let n=yield this.closingLock.lock();if(this.isClosed)n();else try{this._isClosed=!0,this.joinAttempts=0,this.joinStartedAt=void 0,this.emit(R.Closing),this.removeAllListeners(),this.deregisterOnLineListener(),this.clearPendingReconnect(),this.clearLostQualityTimeout(),this.cleanupLossyDataStats(),yield this.cleanupPeerConnections(),yield this.cleanupClient(e)}finally{n()}})}cleanupPeerConnections(){return O(this,void 0,void 0,function*(){this.dataChannels.teardown(),yield this.pcManager?.close(),this.pcManager=void 0,this.transportConnectingSince=void 0,this.reliableReceivedState.clear()})}cleanupLossyDataStats(){this.lossyChannel.stopThresholdTuning()}cleanupClient(e){return O(this,void 0,void 0,function*(){yield this.client.close(!0,e),this.client.resetCallbacks();for(let e of Object.keys(this.pendingTrackResolvers))this.pendingTrackResolvers[e].reject();this.pendingTrackResolvers={}})}addTrack(e){if(this.pendingTrackResolvers[e.cid])throw new bo(`a track with the same ID has already been published`);return new Promise((t,n)=>{let r=F.setTimeout(()=>{delete this.pendingTrackResolvers[e.cid],n(j.timeout(`publication of local track timed out, no response from server`))},1e4);this.pendingTrackResolvers[e.cid]={resolve:e=>{F.clearTimeout(r),t(e)},reject:()=>{F.clearTimeout(r),n(Error(`Cancelled publication by calling unpublish`))}},this.client.sendAddTrack(e)})}removeTrack(e){if(e.track&&this.pendingTrackResolvers[e.track.id]){let t=this.pendingTrackResolvers[e.track.id].reject;t&&t(),delete this.pendingTrackResolvers[e.track.id]}try{return this.pcManager.removeTrack(e),!0}catch(e){this.log.warn(`failed to remove track`,{error:e})}return!1}updateMuteStatus(e,t){this.client.sendMuteTrack(e,t)}get dataSubscriberReadyState(){return this.dataChannelForKind(q.RELIABLE,!0)?.readyState}getConnectedServerAddress(){return O(this,void 0,void 0,function*(){return this.pcManager?.getConnectedAddress()})}setRegionStrategy(e){this.regionStrategy=e}configure(e,t){return O(this,void 0,void 0,function*(){if(!(this.pcManager&&this.pcManager.currentState!==K.NEW)){if(e){this.participantSid=e.participant?.sid;let n=this.makeRTCConfiguration(e);this.pcManager=new _d(t?`publisher-only`:e.subscriberPrimary?`subscriber-primary`:`publisher-primary`,this.loggerOptions,n)}else{let e=this.makeRTCConfiguration();this.pcManager=new _d(`publisher-only`,this.loggerOptions,e)}this.emit(R.TransportsCreated,this.pcManager.publisher,this.pcManager.subscriber),this.pcManager.onIceCandidate=(e,t)=>{this.client.sendIceCandidate(e,t)},this.pcManager.onPublisherOffer=(e,t)=>{this.client.sendOffer(e,t)},this.pcManager.onDataChannel=this.handleDataChannel,this.pcManager.onStateChange=(e,t,n)=>O(this,void 0,void 0,function*(){var r;if(this.log.debug(`primary PC state changed ${e}`),this.transportConnectingSince=e===K.CONNECTING?Date.now():void 0,[`closed`,`disconnected`,`failed`].includes(t)&&(this.publisherConnectionPromise=void 0),e===K.CONNECTED){if(this.joinStartedAt!==void 0){let e=Math.round(performance.now()-this.joinStartedAt);this.joinStartedAt=void 0,this.log.info(`connection setup took ${e} ms`),(r=this.pcManager)==null||r.publisher.setConnectionSetupTime(e)}let e=this.pcState===_f.New;this.pcState=_f.Connected,e&&this.emit(R.Connected,this.latestJoinResponse)}else e===K.FAILED&&(this.pcState===_f.Connected||this.pcState===_f.Reconnecting)&&(this.pcState=_f.Disconnected,this.handleDisconnect(`peerconnection failed`,n===`failed`?dn.RR_SUBSCRIBER_FAILED:dn.RR_PUBLISHER_FAILED));let i=this.client.isDisconnected||this.client.currentState===hu.RECONNECTING,a=[K.FAILED,K.CLOSING,K.CLOSED].includes(e);i&&a&&!this._isClosed&&this.emit(R.Offline)}),this.pcManager.onTrack=e=>{e.streams.length!==0&&this.emit(R.MediaTrackAdded,e.track,e.streams[0],e.receiver)}}})}setupSignalClientCallbacks(){this.client.onAnswer=(e,t,n)=>O(this,void 0,void 0,function*(){this.pcManager&&(this.log.debug(`received server answer`,{RTCSdpType:e.type,sdp:e.sdp,midToTrackId:n}),this.pcManager.mode===`publisher-only`&&(this.midToTrackId=n),yield this.pcManager.setPublisherAnswer(e,t),this.emit(R.RequestSubscribedCodecRefresh))}),this.client.onTrickle=(e,t)=>{this.pcManager&&(this.log.debug(`got ICE candidate from peer`,{candidate:e,target:t}),this.pcManager.addIceCandidate(e,t))},this.client.onOffer=(e,t,n)=>O(this,void 0,void 0,function*(){if(this.latestRemoteOfferId=t,!this.pcManager)return;this.midToTrackId=n;let r=yield this.pcManager.createSubscriberAnswerFromOffer(e,t);r&&this.client.sendAnswer(r,t)}),this.client.onLocalTrackPublished=e=>{if(this.log.debug(`received trackPublishedResponse`,{cid:e.cid,track:e.track?.sid}),!this.pendingTrackResolvers[e.cid]){this.log.error(`missing track resolver for ${e.cid}`,{cid:e.cid});return}let t=this.pendingTrackResolvers[e.cid].resolve;delete this.pendingTrackResolvers[e.cid],t(e.track)},this.client.onLocalTrackUnpublished=e=>{this.emit(R.LocalTrackUnpublished,e)},this.client.onLocalTrackSubscribed=e=>{this.emit(R.LocalTrackSubscribed,e)},this.client.onTokenRefresh=e=>{this.token=e,this.emit(R.TokenRefreshed,e)},this.client.onRemoteMuteChanged=(e,t)=>{this.emit(R.RemoteMute,e,t)},this.client.onSubscribedQualityUpdate=e=>{this.emit(R.SubscribedQualityUpdate,e)},this.client.onRoomMoved=e=>{this.participantSid=e.participant?.sid,this.latestJoinResponse&&(this.latestJoinResponse.room=e.room),this.emit(R.RoomMoved,e)},this.client.onMediaSectionsRequirement=e=>{this.addMediaSections(e.numAudios,e.numVideos),this.negotiate().catch(e=>{this.log.error(e)})},this.client.onPublishDataTrackResponse=e=>{this.emit(R.PublishDataTrackResponse,e)},this.client.onUnPublishDataTrackResponse=e=>{this.emit(R.UnPublishDataTrackResponse,e)},this.client.onDataTrackSubscriberHandles=e=>{this.emit(R.DataTrackSubscriberHandles,e)},this.client.onClose=()=>{this.handleDisconnect(`signal`,dn.RR_SIGNAL_DISCONNECTED)},this.client.onLeave=e=>{switch(this.log.info(`client leave request received (action=${e?.action})`,{reason:e?.reason}),e.regions&&(this.log.debug(`updating regions`),this.emit(R.ServerRegionsReported,e.regions)),e.action){case Ur.DISCONNECT:this.emit(R.Disconnected,e?.reason),this.close(`server leave: ${un[e.reason]??e.reason}`);break;case Ur.RECONNECT:this.fullReconnectOnNext=!0,this.handleDisconnect(ff);break;case Ur.RESUME:this.handleDisconnect(ff)}}}makeRTCConfiguration(e){let t=Object.assign({},this.rtcConfig);if((this.signalOpts?.e2eeEnabled||this.frameMetadataWorker&&!nl())&&Qc()&&(this.log.debug(`E2EE - setting up transports with insertable streams`),t.encodedInsertableStreams=!0),t.sdpSemantics=`unified-plan`,t.continualGatheringPolicy=`gather_continually`,!e)return t;if(e.iceServers&&!t.iceServers){let n=[];e.iceServers.forEach(e=>{let t={urls:e.urls};e.username&&(t.username=e.username),e.credential&&(t.credential=e.credential),n.push(t)}),t.iceServers=n}return e.clientConfiguration&&e.clientConfiguration.forceRelay===ln.ENABLED&&(t.iceTransportPolicy=`relay`),t}applyInitialPublisherLayout(){this.createDataChannels(),Rs()||this.addMediaSections(hf,gf)}addMediaSections(e,t){var n;let r={direction:`recvonly`};for(let t=0;t<e;t++)(n=this.pcManager)==null||n.addPublisherTransceiverOfKind(`audio`,r);let i=this.pcManager?.mode===`publisher-only`;for(let e=0;e<t;e++){let e=this.pcManager?.addPublisherTransceiverOfKind(`video`,r);if(i&&e){let t=bs(e);this.log.debug(`dependency descriptor negotiated for received video`,{negotiated:t})}}}createDataChannels(){this.pcManager&&(this.dataChannels.hasPublisherChannels&&(this.publisherConnectionPromise=void 0),this.dataChannels.createPublisherChannels(this.pcManager))}decodeDataMessage(e){return O(this,void 0,void 0,function*(){if(e.data instanceof ArrayBuffer)return new Uint8Array(e.data);if(e.data instanceof Blob)return new Uint8Array(yield e.data.arrayBuffer());this.log.error(`unsupported data type`,{data:e.data})})}createSender(e,t,n){return O(this,void 0,void 0,function*(){let r;if(hs())r=yield this.createTransceiverRTCRtpSender(e,t,n);else if(gs())this.log.warn(`using add-track fallback`),r=yield this.createRTCRtpSender(e.mediaStreamTrack);else throw new M(`Required webRTC APIs not supported on this device`);return this.setupFrameMetadataSender(r,t),r})}createSimulcastSender(e,t,n,r){return O(this,void 0,void 0,function*(){let i;if(hs())i=yield this.createSimulcastTransceiverSender(e,t,n,r);else if(gs())this.log.debug(`using add-track fallback`),i=yield this.createRTCRtpSender(e.mediaStreamTrack);else throw new M(`Cannot stream on this device`);return i&&this.setupFrameMetadataSender(i,n),i})}get frameMetadataWorker(){return(this.options.frameMetadata??this.options.packetTrailer)?.worker}setupFrameMetadataSender(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=this.frameMetadataWorker;if(!n||this.signalOpts?.e2eeEnabled)return;let r=t.frameMetadata??t.packetTrailer,i=il(r);if(nl()){i&&(e.transform=new RTCRtpScriptTransform(n,{kind:`encode`,packetTrailer:r}));return}if(!rl(this.options.frameMetadata??this.options.packetTrailer)||!(`createEncodedStreams`in e)){i&&this.log.warn(`frame metadata transform not supported; skipping write`,this.logContext);return}let a=e.createEncodedStreams(),o=a.readable,s=a.writable;i?n.postMessage({kind:`encode`,data:{readableStream:o,writableStream:s,packetTrailer:r}},[o,s]):o.pipeTo(s)}createTransceiverRTCRtpSender(e,t,n){return O(this,void 0,void 0,function*(){if(!this.pcManager)throw new M(`publisher is closed`);let r=[];e.mediaStream&&r.push(e.mediaStream),yc(e)&&(e.codec=t.videoCodec);let i={direction:`sendonly`,streams:r};return n&&(i.sendEncodings=n),(yield this.pcManager.addPublisherTransceiver(e.mediaStreamTrack,i)).sender})}createSimulcastTransceiverSender(e,t,n,r){return O(this,void 0,void 0,function*(){if(!this.pcManager)throw new M(`publisher is closed`);let i={direction:`sendonly`};r&&(i.sendEncodings=r);let a=yield this.pcManager.addPublisherTransceiver(t.mediaStreamTrack,i);if(n.videoCodec)return yield e.setSimulcastTrackSender(n.videoCodec,a.sender),a.sender})}createRTCRtpSender(e){return O(this,void 0,void 0,function*(){if(!this.pcManager)throw new M(`publisher is closed`);return this.pcManager.addPublisherTrack(e)})}handleLocalConnectionQuality(e){if(!this.participantSid)return;let t=e.updates.find(e=>e.participantSid===this.participantSid);t&&(t.quality===cn.LOST?this.scheduleLostQualityReconnect():this.clearLostQualityTimeout())}scheduleLostQualityReconnect(){this.lostQualityTimeout||=F.setTimeout(()=>{this.lostQualityTimeout=void 0,!(this._isClosed||this.pcState!==_f.Connected||this.attemptingReconnect)&&this.hasActivePublisherSenders()&&(this.log.warn(`local connection quality lost while publishing, triggering full reconnect`,this.logContext),this.fullReconnectOnNext=!0,this.handleDisconnect(`connection quality lost`,dn.RR_PUBLISHER_FAILED))},pf)}clearLostQualityTimeout(){this.lostQualityTimeout&&=(F.clearTimeout(this.lostQualityTimeout),void 0)}hasActivePublisherSenders(){return this.pcManager?.publisher.getSenders().some(e=>!!e.track&&e.track.readyState===`live`)??!1}reconnect(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:dn.RR_UNKNOWN;this.fullReconnectOnNext=!0,this.handleDisconnect(`reconcile`,e)}attemptReconnect(e){return O(this,void 0,void 0,function*(){if(this._isClosed)return;if(this.attemptingReconnect){this.log.warn(`already attempting reconnect, returning early`);return}this.clearLostQualityTimeout(),(this.clientConfiguration?.resumeConnection===ln.DISABLED||(this.pcManager?.currentState??K.NEW)===K.NEW)&&(this.fullReconnectOnNext=!0);let t=this.fullReconnectOnNext;this.fullReconnectOnNext=!1;let n=!1,r=new AbortController;this.reconnectAbortController=r;try{if(this.attemptingReconnect=!0,t?yield this.restartConnection(r.signal):yield this.resumeConnection(e),r.signal.aborted){this.log.info(`reconnect attempt cancelled, not marking it as succeeded`);return}this.clearPendingReconnect(),n=!0}catch(e){if(r.signal.aborted){this.log.info(`reconnect attempt cancelled, not retrying`,{error:e});return}this.reconnectAttempts+=1;let n=!0;e instanceof M?(this.log.debug(`received unrecoverable error`,{error:e}),n=!1):(t||!(e instanceof Eo))&&(this.fullReconnectOnNext=!0),n?this.handleDisconnect(`reconnect`,dn.RR_UNKNOWN):(this.log.info(`could not recover connection after ${this.reconnectAttempts} attempts, ${Date.now()-this.reconnectStart}ms. giving up`),this.emit(R.Disconnected),yield this.close(`gave up reconnecting after ${this.reconnectAttempts} attempts, ${Date.now()-this.reconnectStart}ms`))}finally{this.reconnectAbortController===r&&(this.reconnectAbortController=void 0),this.attemptingReconnect=!1,n&&this.fullReconnectOnNext&&!this._isClosed&&(this.log.debug(`full reconnect requested during in-progress attempt, dispatching`),this.handleDisconnect(`reconnect`))}})}getNextRetryDelay(e){try{return this.reconnectPolicy.nextRetryDelayInMs(e)}catch(e){this.log.warn(`encountered error in reconnect policy`,{error:e})}return null}restartConnection(e,t){return O(this,void 0,void 0,function*(){var n,r;try{if(e.aborted){this.log.info(`full reconnect cancelled before starting`,{regionUrl:t});return}if(!this.url||!this.token)throw new M(`could not reconnect, url or token not saved`);if(this.log.info(`reconnecting, attempt: ${this.reconnectAttempts}`),this.emit(R.Restarting),this.client.isDisconnected||(yield this.client.sendLeave()),yield this.cleanupPeerConnections(),yield this.cleanupClient(),e.aborted){this.log.info(`full reconnect cancelled after cleaning up the previous session`,{regionUrl:t});return}let r;try{if(!this.signalOpts)throw this.log.warn(`attempted connection restart, without signal options present`),new Eo;r=(yield this.join(t??this.url,this.token,this.signalOpts,e,!this.options.singlePeerConnection)).joinResponse}catch(e){throw e instanceof j&&e.reason===A.NotAllowed?new M(`could not reconnect, token might be expired`):new Eo}if(e.aborted){this.log.info(`full reconnect cancelled after the signal join response`,{regionUrl:t});return}if(this.shouldFailNext)throw this.shouldFailNext=!1,Error(`simulated failure`);if(this.client.setReconnected(),this.emit(R.SignalRestarted,r),yield this.waitForPCReconnected(),e.aborted){this.log.info(`full reconnect cancelled after peer connections reconnected`,{regionUrl:t});return}if(this.client.currentState!==hu.CONNECTED)throw new Eo(`Signal connection got severed during reconnect`);(n=this.regionStrategy)==null||n.resetAttempts(),this.emit(R.Restarted)}catch(n){if(e.aborted){this.log.info(`full reconnect cancelled after a failed attempt`,{regionUrl:t});return}let i=yield this.regionStrategy?.getNextUrl(e);if(e.aborted){this.log.info(`full reconnect cancelled during region selection`,{regionUrl:t});return}if(i){yield this.restartConnection(e,i);return}throw(r=this.regionStrategy)==null||r.resetAttempts(),n}})}resumeConnection(e){return O(this,void 0,void 0,function*(){if(!this.url||!this.token)throw new M(`could not reconnect, url or token not saved`);if(!this.pcManager)throw new M(`publisher and subscriber connections unset`);this.log.info(`resuming signal connection, attempt ${this.reconnectAttempts}`),this.emit(R.Resuming);let t;try{this.setupSignalClientCallbacks(),t=yield this.client.reconnect(this.url,this.token,this.participantSid,e)}catch(e){let t=``;throw e instanceof Error&&(t=e.message,this.log.error(e.message,{error:e})),e instanceof j&&e.reason===A.NotAllowed?new M(`could not reconnect, token might be expired`):e instanceof j&&e.reason===A.LeaveRequest?e:new Eo(t)}if(this.emit(R.SignalResumed),t){let e=this.makeRTCConfiguration(t);this.pcManager.updateConfiguration(e),this.latestJoinResponse&&(this.latestJoinResponse.serverInfo=t.serverInfo)}else this.log.warn(`Did not receive reconnect response`);if(this.shouldFailNext)throw this.shouldFailNext=!1,Error(`simulated failure`);if(yield this.pcManager.triggerIceRestart(),yield this.waitForPCReconnected(),this.client.currentState!==hu.CONNECTED)throw new Eo(`Signal connection got severed during reconnect`);this.client.setReconnected();let n=this.dataChannelForKind(q.RELIABLE);n?.readyState===`open`&&n.id===null&&this.createDataChannels(),t?.lastMessageSeq&&this.resendReliableMessagesForResume(t.lastMessageSeq).catch(e=>{this.log.warn(`failed to resend reliable messages after resume`,Object.assign(Object.assign({},this.logContext),{error:e}))}),this.emit(R.Resumed)})}waitForPCInitialConnection(e,t){return O(this,void 0,void 0,function*(){if(!this.pcManager)throw new M(`PC manager is closed`);yield this.pcManager.ensurePCTransportConnection(t,e)})}waitForPCReconnected(){return O(this,void 0,void 0,function*(){this.pcState=_f.Reconnecting,this.log.debug(`waiting for peer connection to reconnect`);try{if(yield U(df),!this.pcManager)throw new M(`PC manager is closed`);yield this.pcManager.ensurePCTransportConnection(void 0,this.peerConnectionTimeout),this.pcState=_f.Connected}catch(e){throw this.pcState=_f.Disconnected,j.internal(`could not establish PC connection, ${e.message}`)}})}publishRpcAck(e,t){return O(this,void 0,void 0,function*(){let n=new C({destinationIdentities:[e],kind:Pn.RELIABLE,value:{case:`rpcAck`,value:new Gn({requestId:t})}});yield this.sendDataPacket(n,q.RELIABLE)})}sendDataPacket(e,t){return O(this,void 0,void 0,function*(){if(yield this.ensurePublisherConnected(t),this.e2eeManager&&this.e2eeManager.isDataChannelEncryptionEnabled){let t=$c(e);if(t){let n=yield this.e2eeManager.encryptData(t.toBinary());e.value={case:`encryptedPacket`,value:new Fn({encryptedValue:n.payload,iv:n.iv,keyIndex:n.keyIndex})}}}t===q.RELIABLE&&(e.sequence=this.reliableChannel.nextSequence());let n=e.toBinary(),r=Math.min(this.pcManager?.getMaxPublisherMessageSize()??vf,vf);if(r!==void 0&&r!==0&&n.byteLength>r)throw new Co(`cannot publish data packet larger than ${r} bytes (got ${n.byteLength})`);t===q.RELIABLE?yield this.reliableChannel.send(n,e.sequence):yield this.lossyChannel.send(n)})}sendDataTrackFrame(e){return O(this,void 0,void 0,function*(){yield this.ensurePublisherConnected(q.DATA_TRACK_LOSSY),yield this.dataTrackChannel.send(e)})}resendReliableMessagesForResume(e){return O(this,void 0,void 0,function*(){yield this.ensurePublisherConnected(q.RELIABLE),yield this.reliableChannel.replay(e)})}flowControlFor(e){return this.dataChannels.channelFor(e)}waitForBufferHeadroom(e){return O(this,void 0,void 0,function*(){let t=this.dataChannelForKind(e);if(!t)throw new M(`DataChannel not found, kind: ${e}`);return this.flowControlFor(e).waitForHeadroomWithLock(t)})}ensureDataTransportConnected(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.subscriberPrimary;return function*(){if(!t.pcManager)throw new M(`PC manager is closed`);let r=n?t.pcManager.subscriber:t.pcManager.publisher,i=n?`Subscriber`:`Publisher`;if(!r)throw j.internal(`${i} connection not set`);let a=!1;if(!n&&!t.dataChannelForKind(e,n)&&(t.createDataChannels(),a=!0),a||n||t.pcManager.publisher.isICEConnected||t.pcManager.publisher.getICEConnectionState()===`checking`||(a=!0),a&&t.negotiate().catch(e=>{t.log.error(e)}),t.dataChannelForKind(e,n)?.readyState===`open`)return;let o=new Date().getTime()+t.peerConnectionTimeout;for(;new Date().getTime()<o;){if(r.isICEConnected&&t.dataChannelForKind(e,n)?.readyState===`open`)return;yield U(50)}throw j.internal(`could not establish ${i} connection, state: ${r.getICEConnectionState()}`)}()})}ensurePublisherConnected(e){return O(this,void 0,void 0,function*(){this.publisherConnectionPromise||=this.ensureDataTransportConnected(e,!1),yield this.publisherConnectionPromise})}verifyTransport(){if(!this.pcManager)return!1;let e=this.pcManager.currentState;return![K.CONNECTING,K.CONNECTED].includes(e)||!this.client.ws||this.client.ws.readyState===WebSocket.CLOSED?!1:e===K.CONNECTING&&this.transportConnectingSince!==void 0&&Date.now()-this.transportConnectingSince>this.peerConnectionTimeout?(this.log.warn(`transport stuck in connecting state`,this.logContext),!1):!0}negotiate(){return O(this,void 0,void 0,function*(){return new co((e,t)=>O(this,void 0,void 0,function*(){if(!this.pcManager){t(new So(`PC manager is closed`));return}this.pcManager.requirePublisher(),this.pcManager.publisher.getTransceivers().length==0&&!this.dataChannels.hasPublisherChannels&&this.createDataChannels();let n=new AbortController,r=()=>{n.abort(),this.log.debug(`engine disconnected while negotiation was ongoing`),e()};this.isClosed&&t(new So(`cannot negotiate on closed engine`)),this.pendingNegotiationAborts.add(r),this.pcManager.publisher.off(Xu.RTPVideoPayloadTypes,this.onRtpMapAvailable),this.pcManager.publisher.once(Xu.RTPVideoPayloadTypes,this.onRtpMapAvailable);try{yield this.pcManager.negotiate(n),e()}catch(r){if(n.signal.aborted){e();return}r instanceof So&&(this.fullReconnectOnNext=!0),this.handleDisconnect(`negotiation`,dn.RR_UNKNOWN),r instanceof Error?t(r):t(Error(String(r)))}finally{this.pendingNegotiationAborts.delete(r)}}))})}dataChannelForKind(e,t){return this.dataChannels.getHandle(e,t)}sendSyncState(e,t,n){if(!this.pcManager){this.log.warn(`sync state cannot be sent without peer connection setup`);return}let r=this.pcManager.publisher.getLocalDescription(),i=this.pcManager.publisher.getRemoteDescription(),a=this.pcManager.subscriber?.getRemoteDescription(),o=this.pcManager.subscriber?.getLocalDescription(),s=this.signalOpts?.autoSubscribe??!0,c=[],l=[];e.forEach(e=>{e.isDesired!==s&&c.push(e.trackSid),e.isEnabled||l.push(e.trackSid)}),this.client.sendSyncState(new si({answer:this.pcManager.mode===`publisher-only`?i?xu({sdp:i.sdp,type:i.type}):void 0:o?xu({sdp:o.sdp,type:o.type}):void 0,offer:this.pcManager.mode===`publisher-only`?r?xu({sdp:r.sdp,type:r.type}):void 0:a?xu({sdp:a.sdp,type:a.type}):void 0,subscription:new Mr({trackSids:c,subscribe:!s,participantTracks:[]}),publishTracks:$o(t),dataChannels:this.dataChannelsInfo(),trackSidsDisabled:l,datachannelReceiveStates:this.reliableReceivedState.map((e,t)=>new ci({publisherSid:t,lastSeq:e})),publishDataTracks:n.map(e=>new yr({info:Il.toProtobuf(e)}))}))}failNext(){this.shouldFailNext=!0}failNextV1Path(){this.shouldFailOnV1Path=!0}dataChannelsInfo(){let e=[],t=(t,n)=>{t?.id!==void 0&&t.id!==null&&e.push(new li({label:t.label,id:t.id,target:n}))};return t(this.dataChannelForKind(q.LOSSY),dr.PUBLISHER),t(this.dataChannelForKind(q.RELIABLE),dr.PUBLISHER),t(this.dataChannelForKind(q.LOSSY,!0),dr.SUBSCRIBER),t(this.dataChannelForKind(q.RELIABLE,!0),dr.SUBSCRIBER),e}clearReconnectTimeout(){this.reconnectTimeout&&F.clearTimeout(this.reconnectTimeout)}clearPendingReconnect(){this.clearReconnectTimeout(),this.reconnectAttempts=0}registerOnLineListener(){W()&&(window.addEventListener(`online`,this.handleBrowserOnLine),window.addEventListener(`offline`,this.handleBrowserOffline))}deregisterOnLineListener(){W()&&(window.removeEventListener(`online`,this.handleBrowserOnLine),window.removeEventListener(`offline`,this.handleBrowserOffline))}getTrackIdForReceiver(e){let t=this.pcManager?.getMidForReceiver(e);if(t){let e=Object.entries(this.midToTrackId).find(e=>_(e,1)[0]===t);if(e)return e[1]}}};function bf(e,t){let n=e.participantIdentity?e.participantIdentity:t.participantIdentity;e.participantIdentity=n,t.participantIdentity=n;let r=e.destinationIdentities.length===0?t.destinationIdentities:e.destinationIdentities;e.destinationIdentities=r,t.destinationIdentities=r}var xf=D(T.Region),Sf=5e3,Cf=3e4,wf=class e{static fetchRegionSettings(t,n,r){return O(this,void 0,void 0,function*(){let i=yield e.fetchLock.lock();try{let e=yield fetch(`${Tf(t)}/regions`,{headers:{authorization:`Bearer ${n}`},signal:r});if(e.ok){let t=kc(e.headers),n=t?t*1e3:Sf;return{regionSettings:yield e.json(),updatedAtInMs:Date.now(),maxAgeInMs:n}}throw e.status===401?j.notAllowed(`Could not fetch region settings: ${e.statusText}`,e.status):j.internal(`Could not fetch region settings: ${e.statusText}`)}catch(e){throw e instanceof j?e:r?.aborted?j.cancelled(`Region fetching was aborted`):j.serverUnreachable(`Could not fetch region settings, ${e instanceof Error?`${e.name}: ${e.message}`:e}`)}finally{i()}})}static scheduleRefetch(t,n,r){return O(this,void 0,void 0,function*(){let i=e.settingsTimeouts.get(t.hostname);clearTimeout(i),e.settingsTimeouts.set(t.hostname,setTimeout(()=>O(this,void 0,void 0,function*(){try{let r=yield e.fetchRegionSettings(t,n);e.updateCachedRegionSettings(t,n,r)}catch(i){if(i instanceof j&&i.reason===A.NotAllowed){xf.debug(`token is not valid, cancelling auto region refresh`);return}xf.debug(`auto refetching of region settings failed`,{error:i}),e.scheduleRefetch(t,n,r)}}),r))})}static updateCachedRegionSettings(t,n,r){e.cache.set(t.hostname,r),e.scheduleRefetch(t,n,r.maxAgeInMs)}static stopRefetch(t){let n=e.settingsTimeouts.get(t);n&&(clearTimeout(n),e.settingsTimeouts.delete(t))}static scheduleCleanup(t){let n=e.connectionTrackers.get(t);n&&(n.cleanupTimeout&&clearTimeout(n.cleanupTimeout),n.cleanupTimeout=setTimeout(()=>{let n=e.connectionTrackers.get(t);n&&n.connectionCount===0&&(xf.debug(`stopping region refetch after disconnect delay`,{hostname:t}),e.stopRefetch(t)),n&&(n.cleanupTimeout=void 0)},Cf))}static cancelCleanup(t){let n=e.connectionTrackers.get(t);n?.cleanupTimeout&&(clearTimeout(n.cleanupTimeout),n.cleanupTimeout=void 0)}notifyConnected(){let t=this.serverUrl.hostname,n=e.connectionTrackers.get(t);n||(n={connectionCount:0},e.connectionTrackers.set(t,n)),n.connectionCount++,e.cancelCleanup(t)}notifyDisconnected(){let t=this.serverUrl.hostname,n=e.connectionTrackers.get(t);n&&(n.connectionCount=Math.max(0,n.connectionCount-1),n.connectionCount===0&&e.scheduleCleanup(t))}constructor(e,t){this.attemptedRegions=[],this.serverUrl=new URL(e),this.token=t}updateToken(t){this.token=t;let n=this.getServerUrl(),r=e.cache.get(n.hostname);e.scheduleRefetch(this.serverUrl,this.token,r?.maxAgeInMs??Sf)}isCloud(){return zs(this.serverUrl)}getServerUrl(){return this.serverUrl}fetchRegionSettings(t){return O(this,void 0,void 0,function*(){return e.fetchRegionSettings(this.serverUrl,this.token,t)})}getNextBestRegionUrl(t){return O(this,void 0,void 0,function*(){if(!this.isCloud())throw Error(`region availability is only supported for LiveKit Cloud domains`);let n=e.cache.get(this.serverUrl.hostname);(!n||Date.now()-n.updatedAtInMs>n.maxAgeInMs)&&(n=yield this.fetchRegionSettings(t),e.updateCachedRegionSettings(this.serverUrl,this.token,n));let r=n.regionSettings.regions.filter(e=>!this.attemptedRegions.find(t=>t.url===e.url));if(r.length>0){let e=r[0];return this.attemptedRegions.push(e),xf.info(`switching to region: ${e.region}`,{region:e.region}),e.url}return null})}resetAttempts(){this.attemptedRegions=[]}setServerReportedRegions(t){e.updateCachedRegionSettings(this.serverUrl,this.token,t)}};wf.cache=new Map,wf.settingsTimeouts=new Map,wf.connectionTrackers=new Map,wf.fetchLock=new i;function Tf(e){return`${e.protocol.replace(`ws`,`http`)}//${e.host}/settings`}function Ef(){return new CompressionStream(`deflate-raw`)}function Df(){return new DecompressionStream(`deflate-raw`)}function Of(e,t){return O(this,void 0,void 0,function*(){let n=new DecompressionStream(`deflate-raw`),r=n.writable.getWriter();return r.write(e).catch(()=>{}),r.close().catch(()=>{}),kf(n.readable,t)})}function kf(e,t){return O(this,void 0,void 0,function*(){let n=e.getReader(),r=[],i=0;for(;;){let e=yield n.read(),a=e.done,o=e.value;if(a)break;if(r.push(o),i+=o.byteLength,typeof t==`number`&&i>t)throw yield n.cancel(),new P(`Decompressed payload exceeds the maximum payload size of ${t} bytes`,N.PayloadTooLarge)}let a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.byteLength;return a})}var Af=15e3,jf=5e9,Mf=class{get info(){return this._info}validateBytesReceived(){let e=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(typeof this.totalByteSize==`number`&&this.totalByteSize!==0){if(e&&this.bytesReceived<this.totalByteSize)throw new P(`Not enough chunk(s) received - expected ${this.totalByteSize} bytes of data total, only received ${this.bytesReceived} bytes`,N.Incomplete);if(this.bytesReceived>this.totalByteSize)throw new P(`Extra chunk(s) received - expected ${this.totalByteSize} bytes of data total, received ${this.bytesReceived} bytes`,N.LengthExceeded)}}constructor(e,t,n){this.reader=t,this.totalByteSize=n,this._info=e,this.bytesReceived=0}handleChunkReceived(e){var t;this.bytesReceived+=e.content.byteLength,this.validateBytesReceived();let n=this.totalByteSize?this.bytesReceived/this.totalByteSize:void 0;(t=this.onProgress)==null||t.call(this,n)}},Nf=class extends Mf{[Symbol.asyncIterator](){let e=this.reader.getReader();e.closed.catch(()=>{});let t=()=>{e.releaseLock(),this.signal=void 0};return{next:()=>O(this,void 0,void 0,function*(){var n;try{let t=this.signal;if(t?.aborted)throw t.reason;let r=yield new Promise((n,r)=>{if(t){let i=()=>r(t.reason);t.addEventListener(`abort`,i,{once:!0}),e.read().then(n,r).finally(()=>{t.removeEventListener(`abort`,i)})}else e.read().then(n,r)});return r.done?(this.validateBytesReceived(!0),typeof this.totalByteSize==`number`&&((n=this.onProgress)==null||n.call(this,1)),{done:!0,value:void 0}):(this.handleChunkReceived(r.value),{done:!1,value:r.value.content})}catch(e){throw t(),e}}),return(){return O(this,void 0,void 0,function*(){return t(),{done:!0,value:void 0}})}}}withAbortSignal(e){return this.signal=e,this}readAll(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function*(){var n,r,i,a;let o=new Set,s=t.signal?e.withAbortSignal(t.signal):e;try{for(var c=!0,l=Gi(s),u;u=yield l.next(),n=u.done,!n;c=!0){a=u.value,c=!1;let e=a;o.add(e)}}catch(e){r={error:e}}finally{try{!c&&!n&&(i=l.return)&&(yield i.call(l))}finally{if(r)throw r.error}}return Array.from(o)}()})}},Pf=class extends Mf{[Symbol.asyncIterator](){let e=this.reader.getReader();e.closed.catch(()=>{});let t=new TextDecoder(`utf-8`),n=this.signal,r=()=>{e.releaseLock(),this.signal=void 0};return{next:()=>O(this,void 0,void 0,function*(){var i;try{if(n?.aborted)throw n.reason;let r=yield new Promise((t,r)=>{if(n){let i=()=>r(n.reason);n.addEventListener(`abort`,i,{once:!0}),e.read().then(t,r).finally(()=>{n.removeEventListener(`abort`,i)})}else e.read().then(t,r)});if(r.done)return this.validateBytesReceived(!0),typeof this.totalByteSize==`number`&&((i=this.onProgress)==null||i.call(this,1)),{done:!0,value:void 0};{this.handleChunkReceived(r.value);let e;try{e=t.decode(r.value.content)}catch(e){throw new P(`Cannot decode datastream chunk ${r.value.chunkIndex} as text: ${e}`,N.DecodeFailed)}return{done:!1,value:e}}}catch(e){throw r(),e}}),return(){return O(this,void 0,void 0,function*(){return r(),{done:!0,value:void 0}})}}}withAbortSignal(e){return this.signal=e,this}readAll(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return function*(){var n,r,i,a;let o=``,s=t.signal?e.withAbortSignal(t.signal):e;try{for(var c=!0,l=Gi(s),u;u=yield l.next(),n=u.done,!n;c=!0)a=u.value,c=!1,o+=a}catch(e){r={error:e}}finally{try{!c&&!n&&(i=l.return)&&(yield i.call(l))}finally{if(r)throw r.error}}return o}()})}},Ff=class{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:jf;this.log=E,this.byteStreamControllers=new Map,this.textStreamControllers=new Map,this.byteStreamHandlers=new Map,this.textStreamHandlers=new Map,this.isConnected=!1,this.bufferedPackets=[],this.maxPayloadByteLength=e}setConnected(e){this.isConnected=e,e&&this.flushBufferedPackets()}flushBufferedPackets(){let e=this.bufferedPackets;this.bufferedPackets=[];for(let t of e){let e=t.packet,n=t.encryptionType;this.handleDataStreamPacket(e,n)}}registerTextStreamHandler(e,t){if(this.textStreamHandlers.has(e))throw new P(`A text stream handler for topic "${e}" has already been set.`,N.HandlerAlreadyRegistered);this.textStreamHandlers.set(e,t)}unregisterTextStreamHandler(e){this.textStreamHandlers.delete(e)}registerByteStreamHandler(e,t){if(this.byteStreamHandlers.has(e))throw new P(`A byte stream handler for topic "${e}" has already been set.`,N.HandlerAlreadyRegistered);this.byteStreamHandlers.set(e,t)}unregisterByteStreamHandler(e){this.byteStreamHandlers.delete(e)}clearControllers(){let e=new P(`Room disconnected in the middle of receiving data`,N.AbnormalEnd);for(let t of this.byteStreamControllers.values())t.controller.error(e);for(let t of this.textStreamControllers.values())t.controller.error(e);this.byteStreamControllers.clear(),this.textStreamControllers.clear(),this.bufferedPackets=[]}validateParticipantHasNoActiveDataStreams(e){let t=Array.from(this.textStreamControllers.entries()).filter(t=>t[1].sendingParticipantIdentity===e),n=Array.from(this.byteStreamControllers.entries()).filter(t=>t[1].sendingParticipantIdentity===e);if(t.length>0||n.length>0){let a=new P(`Participant ${e} unexpectedly disconnected in the middle of sending data`,N.AbnormalEnd);for(let e of n){var r=_(e,2);let t=r[0];r[1].controller.error(a),this.byteStreamControllers.delete(t)}for(let e of t){var i=_(e,2);let t=i[0];i[1].controller.error(a),this.textStreamControllers.delete(t)}}}handleDataStreamPacket(e,t){if(!this.isConnected)this.bufferedPackets.push({packet:e,encryptionType:t});else switch(e.value.case){case`streamHeader`:return this.handleStreamHeader(e.value.value,e.participantIdentity,t);case`streamChunk`:return this.handleStreamChunk(e.value.value,t);case`streamTrailer`:return this.handleStreamTrailer(e.value.value,t);default:throw Error(`DataPacket of value "${e.value.case}" is not data stream related!`)}}handleStreamHeader(e,t,n){switch(e.contentHeader.case){case`byteHeader`:{let r=this.byteStreamHandlers.get(e.topic);if(!r){this.log.debug(`ignoring incoming byte stream due to no handler for topic`,e.topic);return}let i,a={id:e.streamId,name:e.contentHeader.value.name??`unknown`,mimeType:e.mimeType,size:e.totalLength?Number(e.totalLength):void 0,topic:e.topic,timestamp:hc(e.timestamp),attributes:e.attributes,encryptionType:n},o;switch(e.compression){case w.DEFLATE_RAW:if(!Mc()){E.warn(`Data stream ${e.streamId} received with deflate-raw compression, but this browser does not support deflate-raw decompression. Dropping...`);return}o=!0;break;case w.NONE:o=!1;break;default:E.warn(`Data stream ${e.streamId} received with unknown compression type ${e.compression}, dropping...`);return}let s=e.inlineContent;if(s!==void 0){r(new Nf(a,If(e.streamId,o?Of(s,this.maxPayloadByteLength):s),hc(e.totalLength)),{identity:t});return}let c=new ReadableStream({start:n=>{if(i=n,this.byteStreamControllers.has(e.streamId))throw new P(`A data stream read is already in progress for a stream with id ${e.streamId}.`,N.AlreadyOpened);this.byteStreamControllers.set(e.streamId,{info:a,controller:i,startTime:Date.now(),sendingParticipantIdentity:t})}});r(new Nf(a,o?Vf(c,e.streamId,this.maxPayloadByteLength):c.pipeThrough(Lf(e.streamId)),hc(e.totalLength)),{identity:t});return}case`textHeader`:{let r=this.textStreamHandlers.get(e.topic);if(!r){this.log.debug(`ignoring incoming text stream due to no handler for topic`,e.topic);return}let i,a={id:e.streamId,mimeType:e.mimeType,size:e.totalLength?Number(e.totalLength):void 0,topic:e.topic,timestamp:Number(e.timestamp),attributes:e.attributes,encryptionType:n,attachedStreamIds:e.contentHeader.value.attachedStreamIds},o;switch(e.compression){case w.DEFLATE_RAW:if(!Mc()){E.warn(`Data stream ${e.streamId} received with deflate-raw compression, but this browser does not support deflate-raw decompression. Dropping...`);return}o=!0;break;case w.NONE:o=!1;break;default:E.warn(`Data stream ${e.streamId} received with unknown compression type ${e.compression}, dropping...`);return}let s=e.inlineContent;if(s!==void 0){let n=o?Of(s,this.maxPayloadByteLength):s;r(new Pf(a,If(e.streamId,n),hc(e.totalLength)),{identity:t});return}let c=new ReadableStream({start:n=>{if(i=n,this.textStreamControllers.has(e.streamId))throw new P(`A data stream read is already in progress for a stream with id ${e.streamId}.`,N.AlreadyOpened);this.textStreamControllers.set(e.streamId,{info:a,controller:i,startTime:Date.now(),sendingParticipantIdentity:t})}});r(new Pf(a,o?Hf(c,e.streamId,this.maxPayloadByteLength):c.pipeThrough(Lf(e.streamId)),hc(e.totalLength)),{identity:t});return}}}handleStreamChunk(e,t){let n=this.byteStreamControllers.get(e.streamId);n&&(n.info.encryptionType===t?n.controller.enqueue(e):(n.controller.error(new P(`Encryption type mismatch for stream ${e.streamId}. Expected ${t}, got ${n.info.encryptionType}`,N.EncryptionTypeMismatch)),this.byteStreamControllers.delete(e.streamId)));let r=this.textStreamControllers.get(e.streamId);r&&(r.info.encryptionType===t?r.controller.enqueue(e):(r.controller.error(new P(`Encryption type mismatch for stream ${e.streamId}. Expected ${t}, got ${r.info.encryptionType}`,N.EncryptionTypeMismatch)),this.textStreamControllers.delete(e.streamId)))}handleStreamTrailer(e,t){let n=this.textStreamControllers.get(e.streamId);n&&(n.info.encryptionType===t?(n.info.attributes=Object.assign(Object.assign({},n.info.attributes),e.attributes),e.reason?n.controller.error(new P(`Data stream ${e.streamId} closed abnormally: ${e.reason}`,N.AbnormalEnd)):n.controller.close()):n.controller.error(new P(`Encryption type mismatch for stream ${e.streamId}. Expected ${t}, got ${n.info.encryptionType}`,N.EncryptionTypeMismatch)),this.textStreamControllers.delete(e.streamId));let r=this.byteStreamControllers.get(e.streamId);r&&(r.info.encryptionType===t?(r.info.attributes=Object.assign(Object.assign({},r.info.attributes),e.attributes),e.reason?r.controller.error(new P(`Data stream ${e.streamId} closed abnormally: ${e.reason}`,N.AbnormalEnd)):r.controller.close()):r.controller.error(new P(`Encryption type mismatch for stream ${e.streamId}. Expected ${t}, got ${r.info.encryptionType}`,N.EncryptionTypeMismatch)),this.byteStreamControllers.delete(e.streamId))}};function If(e,t){return new ReadableStream({start:n=>O(this,void 0,void 0,function*(){let r=yield t;n.enqueue(new cr({streamId:e,chunkIndex:BigInt(0),content:r})),n.close()})})}function Lf(e){let t=-1;return new TransformStream({transform:(n,r)=>{let i=hc(n.chunkIndex);if(i<=t)E.warn(`ignoring duplicate chunk ${i} ${n.version>0?`(version ${n.version})`:``} for data stream ${e} (last processed: ${t})`);else{if(i>t+1)throw new P(`Missing chunk(s) ${t+1}..${i-1} for data stream ${e} - cannot reassemble payload`,N.Incomplete);t=i,n.content.length!==0&&r.enqueue(n)}}})}function Rf(){return new TransformStream({transform:(e,t)=>{t.enqueue(e.content)}})}function zf(e){let t=0;return new TransformStream({transform:(n,r)=>{n.byteLength>0&&(r.enqueue(new cr({streamId:e,chunkIndex:gc(t),content:n})),t+=1)}})}function Bf(e){let t=new TextDecoder(`utf-8`),n=new TextEncoder,r=0,i=n=>{try{return n?t.decode(n,{stream:!0}):t.decode()}catch(t){throw new P(`Cannot decode compressed data stream ${e} as text: ${t}`,N.DecodeFailed)}};return new TransformStream({transform:(t,a)=>{let o=i(t);o.length>0&&(a.enqueue(new cr({streamId:e,chunkIndex:gc(r),content:n.encode(o)})),r+=1)},flush:t=>{let a=i();a.length>0&&(t.enqueue(new cr({streamId:e,chunkIndex:gc(r),content:n.encode(a)})),r+=1)}})}function Vf(e,t,n){return e.pipeThrough(Lf(t)).pipeThrough(Rf()).pipeThrough(Df()).pipeThrough(Uf(t,n)).pipeThrough(zf(t))}function Hf(e,t,n){return e.pipeThrough(Lf(t)).pipeThrough(Rf()).pipeThrough(Df()).pipeThrough(Uf(t,n)).pipeThrough(Bf(t))}function Uf(e,t){let n=0;return new TransformStream({transform:(r,i)=>{if(n+=r.byteLength,n>t)throw new P(`Data stream ${e} exceeds the maximum payload size of ${t} bytes`,N.PayloadTooLarge);i.enqueue(r)}})}var Wf=class{constructor(e,t,n){this.writableStream=e,this.defaultWriter=e.getWriter(),this.onClose=n,this.info=t}write(e){return this.defaultWriter.write(e)}close(){return O(this,void 0,void 0,function*(){var e;yield this.defaultWriter.close(),this.defaultWriter.releaseLock(),(e=this.onClose)==null||e.call(this)})}},Gf=class extends Wf{},Kf=class extends Wf{};function qf(e,t,n){return new sr({streamId:e.id,mimeType:e.mimeType,topic:e.topic,timestamp:gc(e.timestamp),totalLength:gc(e.size),attributes:e.attributes,compression:n?.compression??w.NONE,inlineContent:n?.inlineContent,contentHeader:{case:`textHeader`,value:new ar({version:t?.version,attachedStreamIds:e.attachedStreamIds,replyToStreamId:t?.replyToStreamId,operationType:t?.type===`update`?ir.UPDATE:ir.CREATE})}})}function Jf(e,t){return new sr({streamId:e.id,mimeType:e.mimeType,topic:e.topic,timestamp:gc(e.timestamp),totalLength:gc(e.size),attributes:e.attributes,compression:t?.compression??w.NONE,inlineContent:t?.inlineContent,contentHeader:{case:`byteHeader`,value:new or({name:e.name})}})}function Yf(e,t){return new C({destinationIdentities:t,value:{case:`streamHeader`,value:e}})}var Xf=new TextEncoder,Zf=class{constructor(e,t,n,r,i){this.engine=e,this.log=t,this.getRemoteParticipantClientProtocol=n,this.getRemoteParticipantCapabilities=r,this.getAllRemoteParticipantIdentities=i}setupEngine(e){this.engine=e}sendText(e,t){return O(this,void 0,void 0,function*(){var n;let r=crypto.randomUUID(),i=Xf.encode(e),a=i.byteLength,o=t?.compress??!0,s={id:r,mimeType:`text/plain`,timestamp:Date.now(),topic:t?.topic??``,size:a,attributes:t?.attributes,encryptionType:this.engine.e2eeManager?.isDataChannelEncryptionEnabled?S.GCM:S.NONE},c=o&&Mc()&&this.allRecipientsSupportV2(t?.destinationIdentities)&&this.allRecipientsSupportCompression(t?.destinationIdentities)?Qf.fromStream(Dc(i).pipeThrough(Ef())):null;if((!t?.attachments||t.attachments.length===0)&&this.allRecipientsSupportV2(t?.destinationIdentities)){let e=i,r=w.NONE;if(c){let t=yield c.collect();t.byteLength<i.byteLength&&(e=t,r=w.DEFLATE_RAW)}let a=Yf(qf(s,void 0,{compression:r,inlineContent:e}),t?.destinationIdentities);if(a.toBinary().byteLength<=Af)return yield this.engine.sendDataPacket(a,q.RELIABLE),(n=t?.onProgress)==null||n.call(t,1),s}let l=(t?.attachments)?.map(()=>crypto.randomUUID()),u=l?l.length+1:1,d=Array(u).fill(0),f=(e,n)=>{var r;d[n]=e,(r=t?.onProgress)==null||r.call(t,d.reduce((e,t)=>e+t,0)/u)};if(c){s.attachedStreamIds=l;let e=Yf(qf(s,void 0,{compression:w.DEFLATE_RAW}),t?.destinationIdentities);yield this.sendChunkedByteStream(e,r,t?.destinationIdentities,c.stream().pipeThrough($f(i.length,e=>f(e,0)))),i.length===0&&f(1,0)}else{let n=yield this.streamText({streamId:r,totalSize:a,destinationIdentities:t?.destinationIdentities,topic:t?.topic,attachedStreamIds:l,attributes:t?.attributes});yield n.write(e),f(1,0),yield n.close(),s=n.info}return t?.attachments&&l&&(yield Promise.all(t.attachments.map((e,n)=>O(this,void 0,void 0,function*(){return this._sendFile(l[n],e,{topic:t.topic,mimeType:e.type,destinationIdentities:t.destinationIdentities,compress:t.compress,onProgress:e=>{f(e,n+1)}})})))),s})}sendBytes(e,t){return O(this,void 0,void 0,function*(){var n,r;let i=crypto.randomUUID(),a=t?.destinationIdentities,o=t?.compress??!0,s={id:i,name:t?.name??`unknown`,mimeType:t?.mimeType??`application/octet-stream`,timestamp:Date.now(),topic:t?.topic??``,size:e.byteLength,attributes:t?.attributes,encryptionType:this.engine.e2eeManager?.isDataChannelEncryptionEnabled?S.GCM:S.NONE},c=$f(e.length,t?.onProgress),l=o&&Mc()&&this.allRecipientsSupportV2(a)&&this.allRecipientsSupportCompression(a)?Qf.fromStream(Dc(e).pipeThrough(c).pipeThrough(Ef())):null;if(this.allRecipientsSupportV2(a)){let r=e,i=w.NONE;if(l){let t=yield l.collect();t.byteLength<e.byteLength&&(r=t,i=w.DEFLATE_RAW)}let o=Yf(Jf(s,{compression:i,inlineContent:r}),a);if(o.toBinary().byteLength<=Af)return yield this.engine.sendDataPacket(o,q.RELIABLE),(n=t?.onProgress)==null||n.call(t,1),s}let u=Yf(Jf(s,{compression:l?w.DEFLATE_RAW:w.NONE}),a),d=l?l.stream():Dc(e).pipeThrough(c);return yield this.sendChunkedByteStream(u,i,a,d),e.length===0&&((r=t?.onProgress)==null||r.call(t,1)),s})}allRecipientsSupportV2(e){return(e&&e.length>0?e:this.getAllRemoteParticipantIdentities()).every(e=>this.getRemoteParticipantClientProtocol(e)>=2)}allRecipientsSupportCompression(e){return(e&&e.length>0?e:this.getAllRemoteParticipantIdentities()).every(e=>this.getRemoteParticipantCapabilities(e).includes($n.CAP_COMPRESSION_DEFLATE_RAW))}sendChunkedByteStream(e,t,n,r){return O(this,void 0,void 0,function*(){var i,a,o,s;let c=this.engine;yield ep(c,e);let l=0;try{for(var u=!0,d=Gi(Oc(r,Af)),f;f=yield d.next(),i=f.done,!i;u=!0){s=f.value,u=!1;let e=new C({destinationIdentities:n,value:{case:`streamChunk`,value:new cr({content:s,streamId:t,chunkIndex:gc(l)})}});yield c.sendDataPacket(e,q.RELIABLE),l+=1}}catch(e){a={error:e}}finally{try{!u&&!i&&(o=d.return)&&(yield o.call(d))}finally{if(a)throw a.error}}yield tp(t,n,c)})}streamText(e){return O(this,void 0,void 0,function*(){let t=e?.streamId??crypto.randomUUID(),n=e?.destinationIdentities,r={id:t,mimeType:`text/plain`,timestamp:Date.now(),topic:e?.topic??``,size:e?.totalSize,attributes:e?.attributes,encryptionType:this.engine.e2eeManager?.isDataChannelEncryptionEnabled?S.GCM:S.NONE,attachedStreamIds:e?.attachedStreamIds},i=Yf(qf(r,e),n);yield ep(this.engine,i);let a=0,o=this.engine,s=new WritableStream({write(e){return O(this,void 0,void 0,function*(){for(let r of Ec(e,Af)){let e=new cr({content:r,streamId:t,chunkIndex:gc(a)}),i=new C({destinationIdentities:n,value:{case:`streamChunk`,value:e}});yield o.sendDataPacket(i,q.RELIABLE),a+=1}})},close(){return O(this,void 0,void 0,function*(){yield tp(t,n,o)})},abort(e){console.log(`Sink error:`,e)}}),c=()=>O(this,void 0,void 0,function*(){yield l.close()});o.once(R.Closing,c);let l=new Gf(s,r,()=>this.engine.off(R.Closing,c));return l})}sendFile(e,t){return O(this,void 0,void 0,function*(){let n=crypto.randomUUID();return yield this._sendFile(n,e,t),{id:n}})}_sendFile(e,t,n){return O(this,void 0,void 0,function*(){var r;let i=n?.destinationIdentities,a=(n?.compress??!0)&&Mc()&&this.allRecipientsSupportV2(i)&&this.allRecipientsSupportCompression(i),o={id:e,name:t.name,mimeType:n?.mimeType??t.type,topic:n?.topic??``,timestamp:Date.now(),size:t.size,encryptionType:this.engine.e2eeManager?.isDataChannelEncryptionEnabled?S.GCM:S.NONE},s=Yf(Jf(o,{compression:a?w.DEFLATE_RAW:w.NONE}),i),c=t.stream().pipeThrough($f(t.size,n?.onProgress)),l=a?c.pipeThrough(Ef()):c;return yield this.sendChunkedByteStream(s,e,i,l),t.size===0&&((r=n?.onProgress)==null||r.call(n,1)),o})}streamBytes(e){return O(this,void 0,void 0,function*(){let t=e?.streamId??crypto.randomUUID(),n=e?.destinationIdentities,r={id:t,mimeType:e?.mimeType??`application/octet-stream`,topic:e?.topic??``,timestamp:Date.now(),attributes:e?.attributes,size:e?.totalSize,name:e?.name??`unknown`,encryptionType:this.engine.e2eeManager?.isDataChannelEncryptionEnabled?S.GCM:S.NONE},a=Yf(Jf(r),n);yield ep(this.engine,a);let o=0,s=new i,c=this.engine,l=this.log;return new Kf(new WritableStream({write(e){return O(this,void 0,void 0,function*(){let r=yield s.lock(),i=0;try{for(;i<e.byteLength;){let r=e.slice(i,i+Af),a=new C({destinationIdentities:n,value:{case:`streamChunk`,value:new cr({content:r,streamId:t,chunkIndex:gc(o)})}});yield c.sendDataPacket(a,q.RELIABLE),o+=1,i+=r.byteLength}}finally{r()}})},close(){return O(this,void 0,void 0,function*(){yield tp(t,n,c)})},abort(e){l.error(`Sink error:`,e)}}),r)})}},Qf=class e{constructor(e){this.state=e}static fromStream(t){return new e({type:`stream`,stream:t})}collect(){return O(this,void 0,void 0,function*(){switch(this.state.type){case`stream`:let e=yield kf(this.state.stream);return this.state={type:`collected`,bytes:e},e;case`collected`:return this.state.bytes}})}stream(){switch(this.state.type){case`stream`:return this.state.stream;case`collected`:return Dc(this.state.bytes)}}};function $f(e,t){let n=0;return new TransformStream({transform(r,i){n+=r.byteLength,t&&typeof e==`number`&&e>0&&t(Math.min(n/e,1)),i.enqueue(r)}})}function ep(e,t){return O(this,void 0,void 0,function*(){if(t.toBinary().byteLength>Af)throw new P(`data stream header exceeds the ${Af}-byte limit; reduce attribute size`,N.HeaderTooLarge);yield e.sendDataPacket(t,q.RELIABLE)})}function tp(e,t,n){return O(this,void 0,void 0,function*(){let r=new C({destinationIdentities:t,value:{case:`streamTrailer`,value:new lr({streamId:e})}});yield n.sendDataPacket(r,q.RELIABLE)})}var J=1,np=2,rp=4,ip=8,ap=0,op=12,sp=5,cp=7,lp=3,up=3,dp=2,fp=1,pp=0,mp=3,hp=2,gp=2,_p=1,vp=0,yp;(function(e){e[e.TooShort=0]=`TooShort`,e[e.HeaderOverrun=1]=`HeaderOverrun`,e[e.MissingExtWords=2]=`MissingExtWords`,e[e.UnsupportedVersion=3]=`UnsupportedVersion`,e[e.InvalidHandle=4]=`InvalidHandle`,e[e.MalformedExt=5]=`MalformedExt`})(yp||={});var bp=class e extends _o{constructor(e,t,n){super(19,e,n),this.name=`DataTrackDeserializeError`,this.reason=t,this.reasonName=yp[t]}static tooShort(){return new e(`Too short to contain a valid header`,yp.TooShort)}static headerOverrun(){return new e(`Header exceeds total packet length`,yp.HeaderOverrun)}static missingExtWords(){return new e(`Extension word indicator is missing`,yp.MissingExtWords)}static unsupportedVersion(t){return new e(`Unsupported version ${t}`,yp.UnsupportedVersion)}static invalidHandle(t){return new e(`invalid track handle: ${t.message}`,yp.InvalidHandle,{cause:t})}static malformedExt(t){return new e(`Extension with tag ${t} is malformed`,yp.MalformedExt)}},xp;(function(e){e[e.TooSmallForHeader=0]=`TooSmallForHeader`,e[e.TooSmallForPayload=1]=`TooSmallForPayload`})(xp||={});var Sp=class e extends _o{constructor(e,t,n){super(19,e,n),this.name=`DataTrackSerializeError`,this.reason=t,this.reasonName=xp[t]}static tooSmallForHeader(){return new e(`Buffer cannot fit header`,xp.TooSmallForHeader)}static tooSmallForPayload(){return new e(`Buffer cannot fit payload`,xp.TooSmallForPayload)}},Cp=class{toBinary(){let e=this.toBinaryLengthBytes(),t=new ArrayBuffer(e),n=new DataView(t),r=this.toBinaryInto(n);if(e!==r)throw Error(`${this.constructor.name}.toBinary: written bytes (${r} bytes) not equal to allocated array buffer length (${e} bytes).`);return new Uint8Array(t)}},wp;(function(e){e[e.UserTimestamp=2]=`UserTimestamp`,e[e.E2ee=1]=`E2ee`})(wp||={});var Tp=class extends Cp{},Ep=class e extends Tp{constructor(e){super(),this.timestamp=e}toBinaryLengthBytes(){return 2+e.lengthBytes}toBinaryInto(t){let n=0;t.setUint8(n,e.tag),n+=J,t.setUint8(n,e.lengthBytes),n+=J,t.setBigUint64(n,this.timestamp),n+=ip;let r=this.toBinaryLengthBytes();if(n!==r)throw Error(`DataTrackUserTimestampExtension.toBinaryInto: Wrote ${n} bytes but expected length was ${r} bytes`);return n}toJSON(){return{tag:e.tag,lengthBytes:e.lengthBytes,timestamp:this.timestamp}}};Ep.tag=wp.UserTimestamp,Ep.lengthBytes=8;var Dp=class e extends Tp{constructor(e,t){super(),this.keyIndex=e,this.iv=t}toBinaryLengthBytes(){return 2+e.lengthBytes}toBinaryInto(t){let n=0;t.setUint8(n,e.tag),n+=J,t.setUint8(n,e.lengthBytes),n+=J,t.setUint8(n,this.keyIndex),n+=J;for(let e=0;e<this.iv.length;e+=1)t.setUint8(n,this.iv[e]),n+=J;let r=this.toBinaryLengthBytes();if(n!==r)throw Error(`DataTrackE2eeExtension.toBinaryInto: Wrote ${n} bytes but expected length was ${r} bytes`);return n}toJSON(){return{tag:e.tag,lengthBytes:e.lengthBytes,keyIndex:this.keyIndex,iv:this.iv}}};Dp.tag=wp.E2ee,Dp.lengthBytes=13;var Op=class e extends Cp{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(),this.userTimestamp=e.userTimestamp,this.e2ee=e.e2ee}toBinaryLengthBytes(){let e=0;return this.userTimestamp&&(e+=this.userTimestamp.toBinaryLengthBytes()),this.e2ee&&(e+=this.e2ee.toBinaryLengthBytes()),e}toBinaryInto(e){let t=0;if(this.e2ee){let n=this.e2ee.toBinaryInto(e);t+=n}if(this.userTimestamp){let n=this.userTimestamp.toBinaryInto(new DataView(e.buffer,e.byteOffset+t));t+=n}let n=this.toBinaryLengthBytes();if(t!==n)throw Error(`DataTrackExtensions.toBinaryInto: Wrote ${t} bytes but expected length was ${n} bytes`);return t}static fromBinary(t){let n=jl(t),r,i,a=0;for(;n.byteLength-a>=2;){let e=n.getUint8(a);a+=J;let t=n.getUint8(a);if(a+=J,e!==vp)switch(e){case wp.UserTimestamp:if(n.byteLength-a<Ep.lengthBytes)throw bp.malformedExt(e);r=new Ep(n.getBigUint64(a)),a+=t;break;case wp.E2ee:if(n.byteLength-a<Dp.lengthBytes)throw bp.malformedExt(e);let o=n.getUint8(a),s=new Uint8Array(12);for(let e=0;e<s.length;e+=1){let t=a;t+=J,t+=e*J,s[e]=n.getUint8(t)}i=new Dp(o,s),a+=t;break;default:if(n.byteLength-a<t)throw bp.malformedExt(e);a+=t}}return[new e({userTimestamp:r,e2ee:i}),n.byteLength]}toJSON(){return{userTimestamp:this.userTimestamp?.toJSON()??null,e2ee:this.e2ee?.toJSON()??null}}},kp={from(e){return{payload:e.payload,extensions:new Op({userTimestamp:e.userTimestamp?new Ep(e.userTimestamp):void 0})}},lossyIntoFrame(e){return{payload:e.payload,userTimestamp:e.extensions.userTimestamp?.timestamp}}},Ap=Symbol.for(`lk.track`),jp=Symbol.for(`lk.data-track`),Mp=class{constructor(e,t,n){this.trackSymbol=Ap,this.isLocal=!1,this.typeSymbol=jp,this.info=e,this.manager=t,this.publisherIdentity=n.publisherIdentity}subscribe(e){try{let t=_(this.manager.openSubscriptionStream(this.info.sid,e?.signal,e?.bufferSize),2),n=t[0];return t[1].catch(()=>{}),n}catch(e){throw e}}setPipelineOptions(e){this.manager.setPipelineOptions(this.info.sid,e)}},Np=class e extends Cp{constructor(e){super(),this.marker=e.marker,this.trackHandle=e.trackHandle,this.sequence=e.sequence,this.frameNumber=e.frameNumber,this.timestamp=e.timestamp,this.extensions=e.extensions??new Op}extensionsMetrics(){let e=this.extensions.toBinaryLengthBytes(),t=Math.ceil((hp+e)/4);return{lengthBytes:e,lengthWords:t,paddingLengthBytes:t*4-hp-e}}toBinaryLengthBytes(){let e=this.extensionsMetrics(),t=e.lengthBytes,n=e.paddingLengthBytes,r=op;return t>0&&(r+=hp+t+n),r}toBinaryInto(e){if(e.byteLength<this.toBinaryLengthBytes())throw Sp.tooSmallForHeader();let t=0,n;switch(this.marker){case Y.Inter:n=pp;break;case Y.Final:n=fp;break;case Y.Start:n=dp;break;case Y.Single:n=mp}t|=n<<lp;let r=this.extensionsMetrics(),i=r.lengthBytes,a=r.lengthWords,o=r.paddingLengthBytes;i>0&&(t|=4);let s=0;if(e.setUint8(s,t),s+=J,e.setUint8(s,0),s+=J,e.setUint16(s,this.trackHandle),s+=np,e.setUint16(s,this.sequence.value),s+=np,e.setUint16(s,this.frameNumber.value),s+=np,e.setUint32(s,this.timestamp.asTicks()),s+=rp,i>0){let t=a-1;e.setUint16(s,t),s+=np;let n=this.extensions.toBinaryInto(new DataView(e.buffer,e.byteOffset+s));s+=n;for(let t=0;t<o;t+=1)e.setUint8(s,0),s+=J}let c=this.toBinaryLengthBytes();if(s!==c)throw Error(`DataTrackPacketHeader.toBinaryInto: Wrote ${s} bytes but expected length was ${c} bytes`);return c}static fromBinary(t){let n=jl(t);if(n.byteLength<op)throw bp.tooShort();let r=0,i=n.getUint8(r);r+=J;let a=i>>sp&cp;if(a>ap)throw bp.unsupportedVersion(a);let o;switch(i>>lp&up){case dp:o=Y.Start;break;case fp:o=Y.Final;break;case mp:o=Y.Single;break;case pp:default:o=Y.Inter}let s=(i>>gp&_p)>0;r+=J;let c;try{c=Pl.fromNumber(n.getUint16(r))}catch(e){throw e instanceof Nl&&(e.isReason(Ml.Reserved)||e.isReason(Ml.TooLarge))?bp.invalidHandle(e):e}r+=np;let l=Ol.u16(n.getUint16(r));r+=np;let u=Ol.u16(n.getUint16(r));r+=np;let d=kl.fromRtpTicks(n.getUint32(r));r+=rp;let f=new Op;if(s){if(n.byteLength-r<np)throw bp.missingExtWords();let e=n.getUint16(r);r+=np;let t=4*(e+1)-hp;if(r+t>n.byteLength)throw bp.headerOverrun();let i=new DataView(n.buffer,n.byteOffset+r,t),a=_(Op.fromBinary(i),2),o=a[0],s=a[1];f=o,r+=s}return[new e({marker:o,trackHandle:c,sequence:l,frameNumber:u,timestamp:d,extensions:f}),r]}toJSON(){return{marker:this.marker,trackHandle:this.trackHandle,sequence:this.sequence.value,frameNumber:this.frameNumber.value,timestamp:this.timestamp.asTicks(),extensions:this.extensions.toJSON()}}},Y;(function(e){e[e.Start=0]=`Start`,e[e.Inter=1]=`Inter`,e[e.Final=2]=`Final`,e[e.Single=3]=`Single`})(Y||={});var Pp=class e extends Cp{constructor(e,t){super(),this.header=e,this.payload=t}toBinaryLengthBytes(){return this.header.toBinaryLengthBytes()+this.payload.byteLength}toBinaryInto(e){let t=0,n=this.header.toBinaryInto(e);if(t+=n,e.byteLength-t<this.payload.byteLength)throw Sp.tooSmallForPayload();for(let n=0;n<this.payload.length;n+=1)e.setUint8(t,this.payload[n]),t+=J;let r=this.toBinaryLengthBytes();if(t!==r)throw Error(`DataTrackPacket.toBinaryInto: Wrote ${t} bytes but expected length was ${r} bytes`);return r}static fromBinary(t){let n=jl(t),r=_(Np.fromBinary(n),2),i=r[0],a=r[1],o=n.buffer.slice(n.byteOffset+a,n.byteOffset+n.byteLength);return[new e(i,new Uint8Array(o)),n.byteLength]}toJSON(){return{header:this.header.toJSON(),payload:this.payload}}},Fp=D(T.DataTracks),Ip=class e extends _o{constructor(e,t,n,r){super(19,`Frame ${n} dropped: ${e}`,r),this.name=`DataTrackDepacketizerDropError`,this.reason=t,this.reasonName=Lp[t],this.frameNumber=n}static interrupted(t,n){return new e(`Interrupted by the start of a new frame ${n}`,Lp.Interrupted,t)}static unknownFrame(t){return new e(`Initial packet was never received.`,Lp.UnknownFrame,t)}static bufferFull(t){return new e(`Reorder buffer is full.`,Lp.BufferFull,t)}static incomplete(t,n,r){return new e(`Not all packets received before final packet. Received ${n} packets, expected ${r} packets.`,Lp.Incomplete,t)}},Lp;(function(e){e[e.Interrupted=0]=`Interrupted`,e[e.UnknownFrame=1]=`UnknownFrame`,e[e.BufferFull=2]=`BufferFull`,e[e.Incomplete=3]=`Incomplete`})(Lp||={});var Rp=class e{constructor(){this.partials=new Map}push(e,t){switch(e.header.marker){case Y.Single:return this.frameFromSingle(e,t);case Y.Start:return this.beginPartial(e,t);case Y.Inter:case Y.Final:return this.pushToPartial(e)}}reset(){this.partials.clear()}peekOldestPartialFrameNumber(){let e=this.partials.keys().next();return e.done?null:e.value}frameFromSingle(e,t){if(e.header.marker!==Y.Single)throw Error(`Depacketizer.frameFromSingle: packet.header.marker was not FrameMarker.Single, found ${e.header.marker}.`);let n=t?.maxPartialFrames??1;if(this.partials.size>=n){let n=this.peekOldestPartialFrameNumber();if(typeof n!=`number`)throw Error(`Depacketizer.frameFromSingle: no oldest frame number found, but partials.size is ${this.partials.size}.`);if(this.partials.delete(n),t?.throwOnInterruption)throw Ip.interrupted(n,e.header.frameNumber.value);Fp.warn(`Data track frame ${n} was interrupted by single-packet frame ${e.header.frameNumber.value}, dropping.`)}return{payload:e.payload,extensions:e.header.extensions}}beginPartial(e,t){if(e.header.marker!==Y.Start)throw Error(`Depacketizer.beginPartial: packet.header.marker was not FrameMarker.Start, found ${e.header.marker}.`);let n=e.header.sequence,r=e.header.frameNumber.value,i={startSequence:n,extensions:e.header.extensions,payloads:new Map([[n.value,e.payload]])},a=t?.maxPartialFrames??1;for(;this.partials.size>=a;){let e=this.peekOldestPartialFrameNumber();if(typeof e!=`number`)break;if(this.partials.delete(e),t?.throwOnInterruption)throw Ip.interrupted(e,r);Fp.warn(`Data track partials full (max ${a}), evicted oldest frame ${e} to make room for new frame ${r}.`)}return this.partials.set(r,i),null}pushToPartial(t){if(t.header.marker!==Y.Inter&&t.header.marker!==Y.Final)throw Error(`Depacketizer.pushToPartial: packet.header.marker was not FrameMarker.Inter or FrameMarker.Final, found ${t.header.marker}.`);let n=t.header.frameNumber.value,r=this.partials.get(n);if(!r)throw this.partials.delete(n),Ip.unknownFrame(n);if(r.payloads.size>=e.MAX_BUFFER_PACKETS)throw this.partials.delete(n),Ip.bufferFull(n);return r.payloads.has(t.header.sequence.value)&&Fp.warn(`Data track frame ${n} received duplicate packet for sequence ${t.header.sequence.value}, so replacing with newly received packet.`),r.payloads.set(t.header.sequence.value,t.payload),t.header.marker===Y.Final?this.finalize(n,r,t.header.sequence.value):null}finalize(e,t,n){let r=t.payloads.size,i=0;for(let e of t.payloads.values())i+=e.length;let a=new Uint8Array(i),o=t.startSequence.clone(),s=0;for(;;){let r=t.payloads.get(o.value);if(!r)break;t.payloads.delete(o.value);let i=a.length-s;if(r.length>i)throw Error(`Depacketizer.finalize: Expected at least ${r.length} more bytes left in the payload buffer, only got ${i} bytes.`);if(a.set(r,s),s+=r.length,o.value!=n)o.increment();else return this.partials.delete(e),{payload:a,extensions:t.extensions}}throw this.partials.delete(e),Ip.incomplete(e,r,n-t.startSequence.value+1)}};Rp.MAX_BUFFER_PACKETS=128;var zp;(function(e){e[e.Unpublished=0]=`Unpublished`,e[e.Timeout=1]=`Timeout`,e[e.Disconnected=2]=`Disconnected`,e[e.Cancelled=4]=`Cancelled`})(zp||={});var Bp=class e extends _o{constructor(e,t,n){super(22,e,n),this.name=`DataTrackSubscribeError`,this.reason=t,this.reasonName=zp[t]}static unpublished(){return new e(`The track has been unpublished and is no longer available`,zp.Unpublished)}static timeout(){return new e(`Request to subscribe to data track timed-out`,zp.Timeout)}static disconnected(){return new e(`Cannot subscribe to data track when disconnected`,zp.Disconnected)}static cancelled(){return new e(`Subscription to data track cancelled by caller`,zp.Cancelled)}},Vp=D(T.DataTracks),Hp=class{constructor(e){let t=e.e2eeManager!==null;if(e.info.usesE2ee!==t)throw Error(`IncomingDataTrackPipeline: DataTrackInfo.usesE2ee must match presence of decryptionProvider`);let n=new Rp;this.publisherIdentity=e.publisherIdentity,this.e2eeManager=e.e2eeManager??null,this.depacketizer=n,this.options=e.pipelineOptions??{}}updateE2eeManager(e){this.e2eeManager=e}setOptions(e){this.options=e}processPacket(e){return O(this,void 0,void 0,function*(){let t=this.depacketize(e);return t&&(yield this.decryptIfNeeded(t))||null})}depacketize(e){let t;try{t=this.depacketizer.push(e,{throwOnInterruption:!1,maxPartialFrames:this.options.maxPartialFrames})}catch(e){return Vp.warn(`Data frame depacketize error: ${e}`),null}return t}decryptIfNeeded(e){return O(this,void 0,void 0,function*(){let t=this.e2eeManager;if(!t)return e;let n=e.extensions?.e2ee??null;if(!n)return Vp.error(`Missing E2EE meta`),null;let r;try{r=yield t.handleEncryptedData(e.payload,n.iv,this.publisherIdentity,n.keyIndex)}catch(e){return Vp.error(`Error decrypting packet: ${e}`),null}return e.payload=r.payload,e})}},X=D(T.DataTracks),Up=1e4,Wp=16,Gp=class extends Yi.EventEmitter{constructor(e){super(),this.descriptors=new Map,this.subscriptionHandles=new Map,this.e2eeManager=e?.e2eeManager??null}updateE2eeManager(e){this.e2eeManager=e;for(let t of this.descriptors.values())t.subscription.type===`active`&&t.subscription.pipeline.updateE2eeManager(e)}setPipelineOptions(e,t){let n=this.descriptors.get(e);n?(n.pipelineOptions=t,n.subscription.type===`active`&&n.subscription.pipeline.setOptions(t)):X.warn(`Unknown track ${e}, cannot set pipeline options.`)}openSubscriptionStream(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Wp,r=null,i=new G,a=this.descriptors.get(e),o=()=>{t?.removeEventListener(`abort`,c)},s=()=>{o(),r?!a||this.descriptors.get(a.info.sid)!==a?X.warn(`Unknown track ${e}, skipping cancel...`):a.subscription.type===`active`?(a.subscription.streamControllers.delete(r),a.subscription.streamControllers.size===0&&this.unSubscribeRequest(a.info.sid)):X.warn(`Subscription for track ${e} is not active, skipping cancel...`):X.warn(`ReadableStream subscribed to ${e} was not started.`)},c=()=>{var e;r&&(a?.subscription.type===`active`&&a.subscription.streamControllers.delete(r),r.error(Bp.cancelled()),(e=i.reject)==null||e.call(i,Bp.cancelled()),s())};return[new ReadableStream({start:n=>{r=n,this.subscribeRequest(e,t).then(()=>O(this,void 0,void 0,function*(){var r,s,l;if(!a||this.descriptors.get(a.info.sid)!==a){X.error(`Unknown track ${e}`);let t=Bp.disconnected();n.error(t),(r=i.reject)==null||r.call(i,t)}else if(a.subscription.type!==`active`){X.error(`Subscription for track ${e} is not active`);let t=Bp.disconnected();n.error(t),(s=i.reject)==null||s.call(i,t)}else t?.aborted?c():(t?.addEventListener(`abort`,c),a.subscription.streamControllers.set(n,o),(l=i.resolve)==null||l.call(i))})).catch(e=>{var t;n.error(e),(t=i.reject)==null||t.call(i,e)})},cancel:()=>{s()}},new CountQueuingStrategy({highWaterMark:n})),i.promise]}subscribeRequest(e,t){return O(this,void 0,void 0,function*(){let n=this.descriptors.get(e);if(!n)throw Error(`Cannot subscribe to unknown track`);let r=(t,n,r)=>O(this,void 0,void 0,function*(){if(t.subscription.type===`active`)return;if(t.subscription.type!==`pending`)throw Error(`Descriptor for track ${e} is not pending, found ${t.subscription.type}`);let i=zl([n,r].filter(e=>e!==void 0)),a=new G;t.subscription.completionFuture.promise.then(()=>a.resolve?.call(a)).catch(e=>a.reject?.call(a,e));let o=()=>{var e;t.subscription.type===`pending`&&(--t.subscription.pendingRequestCount,r?.aborted||t.subscription.pendingRequestCount<=0?t.subscription.cancel():(e=a.reject)==null||e.call(a,Bp.cancelled()))};i.aborted&&o(),i.addEventListener(`abort`,o),yield a.promise,i.removeEventListener(`abort`,o)});switch(n.subscription.type){case`none`:{n.subscription={type:`pending`,completionFuture:new G,pendingRequestCount:1,cancel:()=>{var e,t;let r=n.subscription;n.subscription={type:`none`},this.emit(`sfuUpdateSubscription`,{sid:n.info.sid,subscribe:!1}),r.type===`pending`&&((t=(e=r.completionFuture).reject)==null||t.call(e,i.aborted?Bp.timeout():Bp.cancelled()))}},this.emit(`sfuUpdateSubscription`,{sid:e,subscribe:!0});let i=Bl(Up);yield r(n,t,i);return}case`pending`:n.subscription.pendingRequestCount+=1,yield r(n,t);return;case`active`:return}})}querySubscribed(){return O(this,void 0,void 0,function*(){return Array.from(this.descriptors.values()).filter(e=>e.subscription.type===`active`).map(e=>[e.info,e.publisherIdentity])})}unSubscribeRequest(e){let t=this.descriptors.get(e);if(!t)throw Error(`Cannot subscribe to unknown track`);if(t.subscription.type!==`active`){X.warn(`Unexpected descriptor state in unSubscribeRequest, expected active, found ${t.subscription?.type}`);return}this.closeStreamControllers(t.subscription.streamControllers,e);let n=t.subscription;t.subscription={type:`none`},this.subscriptionHandles.delete(n.subcriptionHandle),this.emit(`sfuUpdateSubscription`,{sid:e,subscribe:!1})}closeStreamControllers(e,t){for(let r of e){var n=_(r,2);let e=n[0],i=n[1];i();try{e.close()}catch(e){X.warn(`Failed to close readable stream for track ${t}: ${e}`)}}}receiveSfuPublicationUpdates(e){return O(this,void 0,void 0,function*(){if(e.size===0)return;let t=new Map;for(let r of e.entries()){var n=_(r,2);let e=n[0],i=n[1],a=new Set;for(let t of i)a.add(t.sid),this.descriptors.has(t.sid)||this.handleSidReassigned(e,t)||(yield this.handleTrackPublished(e,t));t.set(e,a)}for(let e of t.entries()){var r=_(e,2);let t=r[0],n=r[1],i=Array.from(this.descriptors.entries()).filter(e=>{let n=_(e,2);return n[0],n[1].publisherIdentity===t}).map(e=>_(e,1)[0]).filter(e=>!n.has(e));for(let e of i)this.handleTrackUnpublished(e)}})}queryPublications(){return O(this,void 0,void 0,function*(){return Array.from(this.descriptors.values()).map(e=>e.info)})}handleTrackPublished(e,t){return O(this,void 0,void 0,function*(){if(this.descriptors.has(t.sid)){X.error(`Existing descriptor for track ${t.sid}`);return}let n={info:t,publisherIdentity:e,subscription:{type:`none`},pipelineOptions:{}};this.descriptors.set(n.info.sid,n);let r=new Mp(n.info,this,{publisherIdentity:e});this.emit(`trackPublished`,{track:r})})}handleSidReassigned(e,t){let n=Array.from(this.descriptors.entries()).find(n=>{let r=_(n,2);r[0];let i=r[1];return i.publisherIdentity===e&&i.info.pubHandle===t.pubHandle});if(!n)return!1;let r=_(n,2),i=r[0],a=r[1],o=a.info,s=o.name,c=o.usesE2ee;if(s!==t.name||c!==t.usesE2ee)return X.warn(`Info mismatch for ${i}, treating as new publication`),!1;let l=t.sid;if(X.debug(`SID reassigned: ${i} -> ${l}`),!this.descriptors.delete(i))return!1;switch(a.info.sid=l,a.subscription.type){case`none`:break;case`pending`:case`active`:this.emit(`sfuUpdateSubscription`,{sid:l,subscribe:!0})}return a.subscription.type===`active`&&this.subscriptionHandles.set(a.subscription.subcriptionHandle,l),this.descriptors.set(l,a),!0}handleTrackUnpublished(e){let t=this.descriptors.get(e);t?(this.descriptors.delete(e),t.subscription.type===`active`&&(this.closeStreamControllers(t.subscription.streamControllers,e),this.subscriptionHandles.delete(t.subscription.subcriptionHandle)),this.emit(`trackUnpublished`,{sid:e,publisherIdentity:t.publisherIdentity})):X.error(`Unknown track ${e}`)}receivedSfuSubscriberHandles(e){for(let n of e.entries()){var t=_(n,2);let e=t[0],r=t[1];this.registerSubscriberHandle(e,r)}}registerSubscriberHandle(e,t){var n,r;let i=this.descriptors.get(t);if(!i)X.error(`Unknown track ${t}`);else switch(i.subscription.type){case`none`:X.warn(`No subscription for ${t}`);return;case`active`:this.subscriptionHandles.delete(i.subscription.subcriptionHandle),i.subscription.subcriptionHandle=e,this.subscriptionHandles.set(e,t);return;case`pending`:{X.debug(`data track subscription activated`,{sid:t,handle:e});let a=new Hp({info:i.info,publisherIdentity:i.publisherIdentity,e2eeManager:this.e2eeManager,pipelineOptions:i.pipelineOptions}),o=i.subscription;i.subscription={type:`active`,subcriptionHandle:e,pipeline:a,streamControllers:new Map},this.subscriptionHandles.set(e,t),(r=(n=o.completionFuture).resolve)==null||r.call(n)}}}packetReceived(e){return O(this,void 0,void 0,function*(){let t;try{t=_(Pp.fromBinary(e),1)[0]}catch(e){X.error(`Failed to deserialize packet: ${e}`);return}let n=this.subscriptionHandles.get(t.header.trackHandle);if(!n){X.warn(`Unknown subscriber handle ${t.header.trackHandle}`);return}let r=this.descriptors.get(n);if(!r){X.error(`Missing descriptor for track ${n}`);return}if(r.subscription.type!==`active`){X.warn(`Received packet for track ${n} without active subscription`);return}let i=yield r.subscription.pipeline.processPacket(t);if(i)for(let e of r.subscription.streamControllers.keys()){if(e.desiredSize!==null&&e.desiredSize<=0){X.warn(`Cannot send frame to subscribers: readable stream is full (desiredSize is ${e.desiredSize}). To increase this threshold, set a higher 'options.highWaterMark' when calling .subscribe().`);continue}let t=kp.lossyIntoFrame(i);e.enqueue(t)}})}resendSubscriptionUpdates(){for(let t of this.descriptors){var e=_(t,2);let n=e[0];e[1].subscription.type!==`none`&&this.emit(`sfuUpdateSubscription`,{sid:n,subscribe:!0})}}handleRemoteParticipantDisconnected(e){var t,n;for(let r of this.descriptors.values())if(r.publisherIdentity===e)switch(r.subscription.type){case`none`:break;case`pending`:(n=(t=r.subscription.completionFuture).reject)==null||n.call(t,Bp.disconnected());break;case`active`:this.unSubscribeRequest(r.info.sid)}}reset(){var e,t;for(let n of this.descriptors.values())this.emit(`trackUnpublished`,{sid:n.info.sid,publisherIdentity:n.publisherIdentity}),n.subscription.type===`pending`&&((t=(e=n.subscription.completionFuture).reject)==null||t.call(e,Bp.disconnected())),n.subscription.type===`active`&&this.closeStreamControllers(n.subscription.streamControllers,n.info.sid);this.descriptors.clear(),this.subscriptionHandles.clear()}},Kp=class e extends _o{constructor(e,t,n){super(19,e,n),this.name=`DataTrackPacketizerError`,this.reason=t,this.reasonName=qp[t]}static mtuTooShort(){return new e(`MTU is too short to send frame`,qp.MtuTooShort)}},qp;(function(e){e[e.MtuTooShort=0]=`MtuTooShort`})(qp||={});var Jp=class e{constructor(e,t){this.sequence=Ol.u16(0),this.frameNumber=Ol.u16(0),this.clock=Al.rtpStartingNow(kl.rtpRandom()),this.handle=e,this.mtuSizeBytes=t}static computeFrameMarker(e,t){return t<=1?Y.Single:e===0?Y.Start:e===t-1?Y.Final:Y.Inter}*packetize(t,n){let r=this.frameNumber.getThenIncrement(),i={marker:Y.Inter,trackHandle:this.handle,sequence:Ol.u16(0),frameNumber:r,timestamp:n?.now??this.clock.now(),extensions:t.extensions},a=new Np(i).toBinaryLengthBytes();if(a>=this.mtuSizeBytes)throw Kp.mtuTooShort();let o=this.mtuSizeBytes-a,s=Math.ceil(t.payload.byteLength/o);for(let n=0,r=0;r<t.payload.byteLength;c=[n+1,r+o],n=c[0],r=c[1]){var c;let a=this.sequence.getThenIncrement(),l=new Np(Object.assign(Object.assign({},i),{marker:e.computeFrameMarker(n,s),sequence:a})),u=Math.min(o,t.payload.byteLength-r);yield new Pp(l,new Uint8Array(t.payload.buffer,t.payload.byteOffset+r,u))}}},Yp;(function(e){e[e.NotAllowed=0]=`NotAllowed`,e[e.DuplicateName=1]=`DuplicateName`,e[e.Timeout=2]=`Timeout`,e[e.LimitReached=3]=`LimitReached`,e[e.Disconnected=4]=`Disconnected`,e[e.Cancelled=5]=`Cancelled`,e[e.InvalidName=6]=`InvalidName`,e[e.Unknown=7]=`Unknown`})(Yp||={});var Xp=class e extends _o{constructor(e,t,n){super(21,e,n),this.name=`DataTrackPublishError`,this.reason=t,this.reasonName=Yp[t],this.rawMessage=n?.rawMessage}static notAllowed(t){return new e(`Data track publishing unauthorized`,Yp.NotAllowed,{rawMessage:t})}static duplicateName(t){return new e(`Track name already taken`,Yp.DuplicateName,{rawMessage:t})}static invalidName(t){return new e(`Track name is invalid`,Yp.InvalidName,{rawMessage:t})}static timeout(){return new e(`Publish data track timed-out. Does the LiveKit server support data tracks?`,Yp.Timeout)}static limitReached(t){return new e(`Data track publication limit reached`,Yp.LimitReached,{rawMessage:t})}static unknown(t,n){return new e(`Received RequestResponse for publishDataTrack, but reason was unrecognised (${t}, ${n})`,Yp.Unknown)}static disconnected(){return new e(`Room disconnected`,Yp.Disconnected)}static cancelled(){return new e(`Publish data track cancelled by caller`,Yp.Cancelled)}},Zp;(function(e){e[e.TrackUnpublished=0]=`TrackUnpublished`,e[e.Dropped=1]=`Dropped`})(Zp||={});var Qp=class e extends _o{constructor(e,t,n){super(22,e,n),this.name=`DataTrackPushFrameError`,this.reason=t,this.reasonName=Zp[t]}static trackUnpublished(){return new e(`Track is no longer published`,Zp.TrackUnpublished)}static dropped(t){return new e(`Frame was dropped`,Zp.Dropped,{cause:t})}},$p;(function(e){e[e.Packetizer=0]=`Packetizer`,e[e.Encryption=1]=`Encryption`})($p||={});var em=class e extends _o{constructor(e,t,n){super(21,e,n),this.name=`DataTrackOutgoingPipelineError`,this.reason=t,this.reasonName=$p[t]}static packetizer(t){return new e(`Error packetizing frame`,$p.Packetizer,{cause:t})}static encryption(t){return new e(`Error encrypting frame`,$p.Encryption,{cause:t})}},tm=class e{constructor(e,t){this.trackSymbol=Ap,this.isLocal=!0,this.typeSymbol=jp,this.handle=null,this.log=E,this.flushedFuture=new G,this.isFlushed=!0,this.handleManagerReset=()=>{var e,t;(t=(e=this.flushedFuture).resolve)==null||t.call(e),this.manager.off(`packetsFlushedChange`,this.handleManagerPacketsFlushedChange),this.manager.off(`reset`,this.handleManagerReset)},this.handleManagerPacketsFlushedChange=e=>{var t,n;this.isFlushed=e.isFlushed,e.isFlushed&&((n=(t=this.flushedFuture).resolve)==null||n.call(t),this.flushedFuture=new G)},this.options=e,this.manager=t,this.log=D(T.DataTracks),this.manager.on(`packetsFlushedChange`,this.handleManagerPacketsFlushedChange),this.manager.on(`reset`,this.handleManagerReset)}static withExplicitHandle(t,n,r){let i=new e(t,n);return i.handle=r,i}get info(){let e=this.descriptor;if(e?.type===`active`)return e.info}get descriptor(){return this.handle?this.manager.getDescriptor(this.handle):null}publish(e){return O(this,void 0,void 0,function*(){try{this.handle=yield this.manager.publishRequest(this.options,e)}catch(e){throw e}})}isPublished(){return this.descriptor?.type===`active`&&this.descriptor.publishState!==`unpublished`}tryPush(e){if(!this.handle)throw Qp.trackUnpublished();let t=kp.from(e);try{return this.manager.tryProcessAndSend(this.handle,t)}catch(e){throw e}}flush(){return O(this,void 0,void 0,function*(){if(!this.isFlushed)return this.flushedFuture.promise})}unpublish(){return O(this,void 0,void 0,function*(){if(!this.handle)E.warn(`Data track "${this.options.name}" is not published, so unpublishing has no effect.`);else try{yield this.manager.unpublishRequest(this.handle)}catch(e){throw e}})}},nm=class e{constructor(t){this.e2eeManager=t.e2eeManager,this.packetizer=new Jp(t.info.pubHandle,e.TRANSPORT_MTU_BYTES)}updateE2eeManager(e){this.e2eeManager=e}processFrame(e){return Ui(this,arguments,function*(){let t=yield Hi(this.encryptIfNeeded(e));try{yield Hi(yield*Wi(Gi(this.packetizer.packetize(t))))}catch(e){throw e instanceof Kp?em.packetizer(e):e}})}encryptIfNeeded(e){return O(this,void 0,void 0,function*(){if(!this.e2eeManager)return e;let t;try{t=yield this.e2eeManager.encryptData(e.payload)}catch(e){throw em.encryption(e)}return e.payload=t.payload,e.extensions.e2ee=new Dp(t.keyIndex,t.iv),e})}};nm.TRANSPORT_MTU_BYTES=16e3;var rm=D(T.DataTracks),im={pending(){return{type:`pending`,completionFuture:new G}},active(e,t){return{type:`active`,info:e,publishState:`published`,pipeline:new nm({info:e,e2eeManager:t}),unpublishingFuture:new G}}},am=1e4,om=class e extends Yi.EventEmitter{constructor(e){super(),this.handleAllocator=new Fl,this.descriptors=new Map,this.inFlightPacketCounter=new Map,this.e2eeManager=e?.e2eeManager??null}static withDescriptors(t){let n=new e;return n.descriptors=t,n}updateE2eeManager(e){this.e2eeManager=e;for(let t of this.descriptors.values())t.type===`active`&&t.pipeline.updateE2eeManager(e)}getDescriptor(e){return this.descriptors.get(e)??null}tryProcessAndSend(e,t){return O(this,void 0,void 0,function*(){var n,r,i,a;let o=this.getDescriptor(e);if(o?.type!==`active`||o.publishState===`unpublished`)throw Qp.trackUnpublished();if(o.publishState===`republishing`)throw Qp.dropped(`Data track republishing`);try{try{for(var s=!0,c=Gi(o.pipeline.processFrame(t)),l;l=yield c.next(),n=l.done,!n;s=!0){a=l.value,s=!1;let t=a,n=this.inFlightPacketCounter.get(e)??0;this.inFlightPacketCounter.set(e,n+1),n===0&&this.emit(`packetsFlushedChange`,{handle:e,isFlushed:!1}),this.emit(`packetAvailable`,{handle:e,bytes:t.toBinary()})}}catch(e){r={error:e}}finally{try{!s&&!n&&(i=c.return)&&(yield i.call(c))}finally{if(r)throw r.error}}}catch(e){throw Qp.dropped(e)}})}handlePacketSendComplete(e){let t=(this.inFlightPacketCounter.get(e)??0)-1;t<0&&(rm.warn(`OutgoingDataTrackManager.handlePacketSendComplete: inFlightPacketCounter was decremented below 0 (got ${this.inFlightPacketCounter} - resetting to 0. Were more packets send than were emitted?`),t=0),this.inFlightPacketCounter.set(e,t),t===0&&this.emit(`packetsFlushedChange`,{handle:e,isFlushed:!0})}publishRequest(e,t){return O(this,void 0,void 0,function*(){let n=this.handleAllocator.get();if(!n)throw Xp.limitReached();let r=Bl(am),i=t?zl([t,r]):r;if(this.descriptors.has(n))throw Error(`Descriptor for handle already exists`);let a=im.pending();this.descriptors.set(n,a);let o=()=>{var e,t;let i=this.descriptors.get(n);i?(this.descriptors.delete(n),this.emit(`sfuUnpublishRequest`,{handle:n}),i.type===`pending`&&((t=(e=i.completionFuture).reject)==null||t.call(e,r.aborted?Xp.timeout():Xp.cancelled()))):rm.warn(`No descriptor for ${n}`)};return i.aborted?(o(),a.completionFuture.promise.then(()=>n)):(i.addEventListener(`abort`,o),this.emit(`sfuPublishRequest`,{handle:n,name:e.name,usesE2ee:this.e2eeManager!==null}),yield a.completionFuture.promise,i.removeEventListener(`abort`,o),this.emit(`trackPublished`,{track:tm.withExplicitHandle(e,this,n)}),n)})}queryPublished(){return Array.from(this.descriptors.values()).filter(e=>e.type===`active`).map(e=>e.info)}unpublishRequest(e){return O(this,void 0,void 0,function*(){let t=this.descriptors.get(e);t?t.type===`active`?(this.emit(`sfuUnpublishRequest`,{handle:e}),yield t.unpublishingFuture.promise,this.inFlightPacketCounter.delete(e),this.emit(`trackUnpublished`,{sid:t.info.sid})):rm.warn(`Track ${e} not active`):rm.warn(`No descriptor for ${e}`)})}receivedSfuPublishResponse(e,t){var n,r,i,a;let o=this.descriptors.get(e);if(!o)rm.warn(`No descriptor for ${e}`);else switch(this.descriptors.delete(e),o.type){case`pending`:if(t.type===`ok`){let i=t.data;rm.debug(`SFU accepted publish request for handle ${e}`,{sid:i.sid});let a=i.usesE2ee?this.e2eeManager:null;this.descriptors.set(i.pubHandle,im.active(i,a)),(r=(n=o.completionFuture).resolve)==null||r.call(n)}else rm.debug(`SFU rejected publish request for handle ${e}`,{error:t.error}),(a=(i=o.completionFuture).reject)==null||a.call(i,t.error);return;case`active`:if(o.publishState!==`republishing`){rm.warn(`Track ${e} already active`);return}if(t.type===`error`){rm.warn(`Republish failed for track ${e}`);return}rm.debug(`Track ${e} republished`),o.info.sid=t.data.sid,o.publishState=`published`,this.descriptors.set(o.info.pubHandle,o)}}receivedSfuUnpublishResponse(e){var t,n;let r=this.descriptors.get(e);r?(this.descriptors.delete(e),r.type===`active`?(r.publishState=`unpublished`,(n=(t=r.unpublishingFuture).resolve)==null||n.call(t)):rm.warn(`Track ${e} not active`)):rm.warn(`No descriptor for ${e}`)}sfuWillRepublishTracks(){var e,t;for(let r of this.descriptors.entries()){var n=_(r,2);let i=n[0],a=n[1];switch(a.type){case`pending`:this.descriptors.delete(i),(t=(e=a.completionFuture).reject)==null||t.call(e,Xp.disconnected());break;case`active`:a.publishState=`republishing`,this.emit(`sfuPublishRequest`,{handle:a.info.pubHandle,name:a.info.name,usesE2ee:a.info.usesE2ee})}}}reset(){return O(this,void 0,void 0,function*(){var e,t,n,r;this.handleAllocator.reset();for(let i of this.descriptors.values())switch(i.type){case`pending`:(t=(e=i.completionFuture).reject)==null||t.call(e,Xp.disconnected());break;case`active`:(r=(n=i.unpublishingFuture).resolve)==null||r.call(n),yield this.unpublishRequest(i.info.pubHandle)}this.descriptors.clear(),this.inFlightPacketCounter.clear(),this.emit(`reset`)})}},Z=class e extends Error{constructor(t,n,r,i){super(n),this.code=t,this.message=pm(n,e.MAX_MESSAGE_BYTES),this.data=r?pm(r,e.MAX_DATA_BYTES):void 0,i?.cause!==void 0&&(this.cause=i?.cause)}static fromProto(t){return new e(t.code,t.message,t.data)}toProto(){return new qn({code:this.code,message:this.message,data:this.data})}static builtIn(t,n,r){return new e(e.ErrorCode[t],e.ErrorMessage[t],n,r)}};Z.MAX_MESSAGE_BYTES=256,Z.MAX_DATA_BYTES=15360,Z.ErrorCode={APPLICATION_ERROR:1500,CONNECTION_TIMEOUT:1501,RESPONSE_TIMEOUT:1502,RECIPIENT_DISCONNECTED:1503,RESPONSE_PAYLOAD_TOO_LARGE:1504,SEND_FAILED:1505,UNSUPPORTED_METHOD:1400,RECIPIENT_NOT_FOUND:1401,REQUEST_PAYLOAD_TOO_LARGE:1402,UNSUPPORTED_SERVER:1403,UNSUPPORTED_VERSION:1404},Z.ErrorMessage={APPLICATION_ERROR:`Application error in method handler`,CONNECTION_TIMEOUT:`Connection timeout`,RESPONSE_TIMEOUT:`Response timeout`,RECIPIENT_DISCONNECTED:`Recipient disconnected`,RESPONSE_PAYLOAD_TOO_LARGE:`Response payload too large`,SEND_FAILED:`Failed to send`,UNSUPPORTED_METHOD:`Method not supported at destination`,RECIPIENT_NOT_FOUND:`Recipient not found`,REQUEST_PAYLOAD_TOO_LARGE:`Request payload too large`,UNSUPPORTED_SERVER:`RPC not supported by server`,UNSUPPORTED_VERSION:`Unsupported RPC version`};var sm=15360,cm=`lk.rpc_request`,lm=`lk.rpc_response`,Q;(function(e){e.RPC_REQUEST_ID=`lk.rpc_request_id`,e.RPC_REQUEST_METHOD=`lk.rpc_request_method`,e.RPC_REQUEST_RESPONSE_TIMEOUT_MS=`lk.rpc_request_response_timeout_ms`,e.RPC_REQUEST_VERSION=`lk.rpc_request_version`})(Q||={});var um=1,dm=2;function fm(e){return new TextEncoder().encode(e).length}function pm(e,t){if(fm(e)<=t)return e;let n=0,r=e.length,i=new TextEncoder;for(;n<r;){let a=Math.floor((n+r+1)/2);i.encode(e.slice(0,a)).length<=t?n=a:r=a-1}let a=n>0?e.charCodeAt(n-1):0;return a>=55296&&a<=56319&&--n,e.slice(0,n)}var mm=class extends Yi.EventEmitter{constructor(e,t,n,r){super(),this.pendingAcks=new Map,this.pendingResponses=new Map,this.log=e,this.outgoingDataStreamManager=t,this.getRemoteParticipantClientProtocol=n,this.getServerVersion=r}performRpc(e){return O(this,arguments,void 0,function(e){var t=this;let n=e.destinationIdentity,r=e.method,i=e.payload,a=e.responseTimeout,o=a===void 0?15e3:a;return function*(){let e=t.getRemoteParticipantClientProtocol(n);if(fm(i)>sm&&e<1)throw Z.builtIn(`REQUEST_PAYLOAD_TOO_LARGE`);let a=t.getServerVersion();if(a&&Ws(a,`1.8.0`)<0)throw Z.builtIn(`UNSUPPORTED_SERVER`);let s=Math.max(o,8e3),c=crypto.randomUUID(),l=new G,u=null,d=setTimeout(()=>{var e;t.pendingAcks.delete(c),(e=l.reject)==null||e.call(l,Z.builtIn(`CONNECTION_TIMEOUT`)),t.pendingResponses.delete(c),u!==null&&clearTimeout(u)},7e3);t.pendingAcks.set(c,{resolve:()=>{clearTimeout(d)},participantIdentity:n}),t.pendingResponses.set(c,{completionFuture:l,participantIdentity:n});let f=l.promise.finally(()=>{u!==null&&clearTimeout(u),t.pendingAcks.has(c)&&(t.log.warn(`RPC response received before ack`,c),t.pendingAcks.delete(c),clearTimeout(d))});f.catch(()=>{});try{yield t.publishRpcRequest(n,c,r,i,s,e)}catch(e){throw clearTimeout(d),t.pendingAcks.delete(c),t.pendingResponses.delete(c),e}return t.pendingResponses.has(c)&&(u=setTimeout(()=>{var e;t.pendingResponses.delete(c),(e=l.reject)==null||e.call(l,Z.builtIn(`RESPONSE_TIMEOUT`))},o)),[c,f]}()})}publishRpcRequest(e,t,n,r,i,a){return O(this,void 0,void 0,function*(){a>=1?yield this.outgoingDataStreamManager.sendText(r,{topic:cm,destinationIdentities:[e],attributes:{[Q.RPC_REQUEST_ID]:t,[Q.RPC_REQUEST_METHOD]:n,[Q.RPC_REQUEST_RESPONSE_TIMEOUT_MS]:`${i}`,[Q.RPC_REQUEST_VERSION]:`${dm}`}}):this.emit(`sendDataPacket`,{packet:new C({destinationIdentities:[e],kind:Pn.RELIABLE,value:{case:`rpcRequest`,value:new Wn({id:t,method:n,payload:r,responseTimeoutMs:i,version:um})}})})})}handleIncomingDataStream(e,t,n){return O(this,void 0,void 0,function*(){let r=n[Q.RPC_REQUEST_ID];if(!r){this.log.warn(`RPC data stream malformed: ${Q.RPC_REQUEST_ID} not set.`);return}let i=this.pendingResponses.get(r);if(i&&i.participantIdentity!==t){this.log.warn(`RPC response stream for ${r} arrived from unexpected sender ${t}, expected ${i.participantIdentity}. Ignoring.`);return}let a;try{a=yield e.readAll()}catch(e){this.log.warn(`Error reading RPC response payload: ${e}`),this.handleIncomingRpcResponseFailure(r,Z.builtIn(`APPLICATION_ERROR`,`Error reading RPC response payload`,{cause:e}));return}this.handleIncomingRpcResponseSuccess(r,a)})}handleIncomingRpcResponseSuccess(e,t){var n,r;let i=this.pendingResponses.get(e);i?((r=(n=i.completionFuture).resolve)==null||r.call(n,t),this.pendingResponses.delete(e)):this.log.error(`Response received for unexpected RPC request`,e)}handleIncomingRpcResponseFailure(e,t){var n,r;let i=this.pendingResponses.get(e);i?((r=(n=i.completionFuture).reject)==null||r.call(n,t),this.pendingResponses.delete(e)):this.log.error(`Response received for unexpected RPC request`,e)}handleIncomingRpcAck(e){let t=this.pendingAcks.get(e);t?(t.resolve(),this.pendingAcks.delete(e)):this.log.error(`Ack received for unexpected RPC request: ${e}`)}handleParticipantDisconnected(e){var t;for(let t of this.pendingAcks){var n=_(t,2);let r=n[0];n[1].participantIdentity===e&&this.pendingAcks.delete(r)}for(let n of this.pendingResponses){var r=_(n,2);let a=r[0];var i=r[1];let o=i.participantIdentity,s=i.completionFuture;o===e&&((t=s.reject)==null||t.call(s,Z.builtIn(`RECIPIENT_DISCONNECTED`)),this.pendingResponses.delete(a))}}},hm=class extends Yi.EventEmitter{constructor(e,t,n){super(),this.rpcHandlers=new Map,this.log=e,this.outgoingDataStreamManager=t,this.getRemoteParticipantClientProtocol=n}registerRpcMethod(e,t){if(this.rpcHandlers.has(e))throw Error(`RPC handler already registered for method ${e}, unregisterRpcMethod before trying to register again`);this.rpcHandlers.set(e,t)}unregisterRpcMethod(e){this.rpcHandlers.delete(e)}handleIncomingRpcRequest(e,t){return O(this,void 0,void 0,function*(){if(this.publishRpcAck(e,t.id),t.version!==1){this.publishRpcResponsePacket(e,t.id,null,Z.builtIn(`UNSUPPORTED_VERSION`));return}let n=this.rpcHandlers.get(t.method);if(!n){this.publishRpcResponsePacket(e,t.id,null,Z.builtIn(`UNSUPPORTED_METHOD`));return}let r;try{r=yield n({requestId:t.id,callerIdentity:e,payload:t.payload,responseTimeout:t.responseTimeoutMs})}catch(n){let r;n instanceof Z?r=n:(this.log.warn(`Uncaught error returned by RPC handler for ${t.method}. Returning APPLICATION_ERROR instead.`,n),r=Z.builtIn(`APPLICATION_ERROR`,`Uncaught error: ${n?.message??n}`,{cause:n})),this.publishRpcResponsePacket(e,t.id,null,r);return}yield this.publishRpcResponse(e,t.id,r??``)})}handleIncomingDataStream(e,t,n){return O(this,void 0,void 0,function*(){let r=n[Q.RPC_REQUEST_ID],i=n[Q.RPC_REQUEST_METHOD],a=parseInt(n[Q.RPC_REQUEST_RESPONSE_TIMEOUT_MS],10),o=parseInt(n[Q.RPC_REQUEST_VERSION],10);if(!r||!i||Number.isNaN(a)||Number.isNaN(o)){this.log.warn(`RPC data stream malformed: ${Q.RPC_REQUEST_ID} / ${Q.RPC_REQUEST_METHOD} / ${Q.RPC_REQUEST_RESPONSE_TIMEOUT_MS} / ${Q.RPC_REQUEST_VERSION} not set.`),this.publishRpcResponsePacket(t,r,null,Z.builtIn(`APPLICATION_ERROR`,`RPC data stream malformed`));return}if(this.publishRpcAck(t,r),o!==dm){this.publishRpcResponsePacket(t,r,null,Z.builtIn(`UNSUPPORTED_VERSION`));return}let s;try{s=yield e.readAll()}catch(e){this.log.warn(`Error reading RPC request payload: ${e}`),this.publishRpcResponsePacket(t,r,null,Z.builtIn(`APPLICATION_ERROR`,`Error reading RPC request payload`,{cause:e}));return}let c=this.rpcHandlers.get(i);if(!c){this.publishRpcResponsePacket(t,r,null,Z.builtIn(`UNSUPPORTED_METHOD`));return}let l;try{l=yield c({requestId:r,callerIdentity:t,payload:s,responseTimeout:a})}catch(e){let n;e instanceof Z?n=e:(this.log.warn(`Uncaught error returned by RPC handler for ${i}. Returning APPLICATION_ERROR instead.`,e),n=Z.builtIn(`APPLICATION_ERROR`)),this.publishRpcResponsePacket(t,r,null,n);return}yield this.publishRpcResponse(t,r,l??``)})}publishRpcAck(e,t){this.emit(`sendDataPacket`,{packet:new C({destinationIdentities:[e],kind:Pn.RELIABLE,value:{case:`rpcAck`,value:new Gn({requestId:t})}})})}publishRpcResponsePacket(e,t,n,r){this.emit(`sendDataPacket`,{packet:new C({destinationIdentities:[e],kind:Pn.RELIABLE,value:{case:`rpcResponse`,value:new Kn({requestId:t,value:r?{case:`error`,value:r.toProto()}:{case:`payload`,value:n??``}})}})})}publishRpcResponse(e,t,n){return O(this,void 0,void 0,function*(){this.getRemoteParticipantClientProtocol(e)>=1?yield this.outgoingDataStreamManager.sendText(n,{topic:lm,destinationIdentities:[e],attributes:{[Q.RPC_REQUEST_ID]:t}}):fm(n)>sm?(this.log.warn(`RPC Response payload too large for request ${t}. To send larger responses, consider updating the sending client.`),this.publishRpcResponsePacket(e,t,null,Z.builtIn(`RESPONSE_PAYLOAD_TOO_LARGE`))):this.publishRpcResponsePacket(e,t,n,null)})}},gm=class extends ul{constructor(e,t,n,r,i,a){super(e,t,H.Kind.Audio,n,a),this.connectedNodes=[],this.monitorReceiver=()=>O(this,void 0,void 0,function*(){if(!this.receiver){this._currentBitrate=0;return}let e=yield this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=ll(e,this.prevStats)),this.prevStats=e}),this.audioContext=r,this.webAudioPluginNodes=[],i&&(this.sinkId=i.deviceId)}setVolume(e){var t;if(this.audioContext)(t=this.gainNode)==null||t.gain.setTargetAtTime(e,0,.1);else for(let t of this.attachedElements)t.volume=e;Rs()&&this._mediaStreamTrack._setVolume(e),this.elementVolume=e}getVolume(){if(this.elementVolume!==void 0)return this.elementVolume;if(Rs())return 1;let e=0;return this.attachedElements.forEach(t=>{t.volume>e&&(e=t.volume)}),e}setSinkId(e){return O(this,void 0,void 0,function*(){this.sinkId=e,yield Promise.all(this.attachedElements.map(t=>{if(Ts(t))return t.setSinkId(e)}))})}attach(e){let t=!this.sourceNode;return e?super.attach(e):e=super.attach(),this.sinkId&&Ts(e)&&e.setSinkId(this.sinkId).catch(e=>{this.log.error(`Failed to set sink id on remote audio track`,e,this.logContext)}),this.audioContext&&(e.volume=0,e.muted=!0,t&&(this.log.debug(`using audio context mapping`,this.logContext),this.connectWebAudio(this.audioContext,e))),this.elementVolume!==void 0&&this.setVolume(this.elementVolume),e}detach(e){let t;return e?(t=super.detach(e),this.audioContext&&(this.attachedElements.length>0?this.connectWebAudio(this.audioContext,this.attachedElements[0]):this.disconnectWebAudio())):(t=super.detach(),this.disconnectWebAudio()),t}setAudioContext(e){if(this.audioContext!==e){if(this.audioContext=e,e){for(let e of this.attachedElements)e.volume=0,e.muted=!0;this.attachedElements.length>0&&this.connectWebAudio(e,this.attachedElements[0])}else{this.disconnectWebAudio();for(let e of this.attachedElements)e.muted=!1,e.volume=this.elementVolume??1}}}setWebAudioPlugins(e){this.webAudioPluginNodes=e,this.attachedElements.length>0&&this.audioContext&&this.connectWebAudio(this.audioContext,this.attachedElements[0])}connectWebAudio(e,t){this.disconnectWebAudio(),this.sourceNode=e.createMediaStreamSource(t.srcObject);let n=this.sourceNode;this.connectedNodes=[this.sourceNode],this.webAudioPluginNodes.forEach(e=>{n.connect(e),n=e,this.connectedNodes.push(e)}),this.gainNode=e.createGain(),n.connect(this.gainNode),this.connectedNodes.push(this.gainNode),this.gainNode.connect(e.destination),this.elementVolume!==void 0&&this.gainNode.gain.setTargetAtTime(this.elementVolume,0,.1),e.state!==`running`&&e.resume().then(()=>{e.state!==`running`&&this.emit(z.AudioPlaybackFailed,Error(`Audio Context couldn't be started automatically`))}).catch(e=>{this.emit(z.AudioPlaybackFailed,e)})}disconnectWebAudio(){var e,t;for(let e=0;e<this.connectedNodes.length-1;e+=1)try{this.connectedNodes[e].disconnect(this.connectedNodes[e+1])}catch{}this.connectedNodes=[],(e=this.gainNode)==null||e.disconnect(),(t=this.sourceNode)==null||t.disconnect(),this.gainNode=void 0,this.sourceNode=void 0}getReceiverStats(){return O(this,void 0,void 0,function*(){if(!this.receiver||!this.receiver.getStats)return;let e=yield this.receiver.getStats(),t;return e.forEach(e=>{e.type===`inbound-rtp`&&(t={type:`audio`,streamId:e.id,timestamp:e.timestamp,jitter:e.jitter,bytesReceived:e.bytesReceived,concealedSamples:e.concealedSamples,concealmentEvents:e.concealmentEvents,silentConcealedSamples:e.silentConcealedSamples,silentConcealmentEvents:e.silentConcealmentEvents,totalAudioEnergy:e.totalAudioEnergy,totalSamplesDuration:e.totalSamplesDuration})}),t})}},_m=class extends Yi.EventEmitter{constructor(e,t,n,r){super(),this.metadataMuted=!1,this.encryption=S.NONE,this.log=E,this.handleMuted=()=>{this.emit(z.Muted)},this.handleUnmuted=()=>{this.emit(z.Unmuted)},this.log=D(r?.loggerName??T.Publication),this.loggerContextCb=this.loggerContextCb,this.setMaxListeners(100),this.kind=e,this.trackSid=t,this.trackName=n,this.source=H.Source.Unknown}setTrack(e){this.track&&(this.track.off(z.Muted,this.handleMuted),this.track.off(z.Unmuted,this.handleUnmuted)),this.track=e,e&&(e.on(z.Muted,this.handleMuted),e.on(z.Unmuted,this.handleUnmuted))}get logContext(){return Object.assign(Object.assign({},this.loggerContextCb?.call(this)),V(this))}get isMuted(){return this.metadataMuted}get isEnabled(){return!0}get isSubscribed(){return this.track!==void 0}get isEncrypted(){return this.encryption!==S.NONE}get audioTrack(){if(vc(this.track))return this.track}get videoTrack(){if(yc(this.track))return this.track}updateInfo(e){this.trackSid=e.sid,this.trackName=e.name,this.source=H.sourceFromProto(e.source),this.mimeType=e.mimeType,this.kind===H.Kind.Video&&e.width>0&&(this.dimensions={width:e.width,height:e.height},this.simulcasted=e.simulcast),this.encryption=e.encryption,this.trackInfo=e,this.log.debug(`update publication info`,Object.assign(Object.assign({},this.logContext),{info:e}))}};(function(e){(function(e){e.Desired=`desired`,e.Subscribed=`subscribed`,e.Unsubscribed=`unsubscribed`})(e.SubscriptionStatus||={}),(function(e){e.Allowed=`allowed`,e.NotAllowed=`not_allowed`})(e.PermissionStatus||={})})(_m||={});var vm=class extends _m{get isUpstreamPaused(){return this.track?.isUpstreamPaused}constructor(e,t,n,r){super(e,t.sid,t.name,r),this.track=void 0,this.handleTrackEnded=()=>{this.emit(z.Ended)},this.handleCpuConstrained=()=>{this.track&&yc(this.track)&&this.emit(z.CpuConstrained,this.track)},this.updateInfo(t),this.setTrack(n)}setTrack(e){this.track&&(this.track.off(z.Ended,this.handleTrackEnded),this.track.off(z.CpuConstrained,this.handleCpuConstrained)),super.setTrack(e),e&&(e.on(z.Ended,this.handleTrackEnded),e.on(z.CpuConstrained,this.handleCpuConstrained))}get isMuted(){return this.track?this.track.isMuted:super.isMuted}get audioTrack(){return super.audioTrack}get videoTrack(){return super.videoTrack}get isLocal(){return!0}mute(){return O(this,void 0,void 0,function*(){return this.track?.mute()})}unmute(){return O(this,void 0,void 0,function*(){return this.track?.unmute()})}pauseUpstream(){return O(this,void 0,void 0,function*(){yield this.track?.pauseUpstream()})}resumeUpstream(){return O(this,void 0,void 0,function*(){yield this.track?.resumeUpstream()})}getTrackFeatures(){if(vc(this.track)){let e=this.track.getSourceTrackSettings(),t=new Set;return e.autoGainControl&&t.add(x.TF_AUTO_GAIN_CONTROL),e.echoCancellation&&t.add(x.TF_ECHO_CANCELLATION),e.noiseSuppression&&t.add(x.TF_NOISE_SUPPRESSION),e.channelCount&&e.channelCount>1&&t.add(x.TF_STEREO),this.options?.dtx||t.add(x.TF_NO_DTX),this.track.enhancedNoiseCancellation&&t.add(x.TF_ENHANCED_NOISE_CANCELLATION),Array.from(t.values())}return[]}};function ym(e,t){return O(this,void 0,void 0,function*(){e??={};let n=!1,r=ns(e),i=r.audioProcessor,a=r.videoProcessor,o=r.optionsWithoutProcessor,s=o.audio,c=o.video;if(i&&typeof o.audio==`object`&&(o.audio.processor=i),a&&typeof o.video==`object`&&(o.video.processor=a),e.audio&&typeof o.audio==`object`&&typeof o.audio.deviceId==`string`){let e=o.audio.deviceId;o.audio.deviceId={exact:e},n=!0,s=Object.assign(Object.assign({},o.audio),{deviceId:{ideal:e}})}if(o.video&&typeof o.video==`object`&&typeof o.video.deviceId==`string`){let e=o.video.deviceId;o.video.deviceId={exact:e},n=!0,c=Object.assign(Object.assign({},o.video),{deviceId:{ideal:e}})}o.audio===!0?o.audio={deviceId:`default`}:typeof o.audio==`object`&&o.audio!==null&&(o.audio=Object.assign(Object.assign({},o.audio),{deviceId:o.audio.deviceId||`default`})),o.video===!0?o.video={deviceId:`default`}:typeof o.video==`object`&&!o.video.deviceId&&(o.video.deviceId=`default`);let l=Ko(Wo(o,pd,md)),u=navigator.mediaDevices.getUserMedia(l);o.audio&&(Tl.userMediaPromiseMap.set(`audioinput`,u),u.catch(()=>Tl.userMediaPromiseMap.delete(`audioinput`))),o.video&&(Tl.userMediaPromiseMap.set(`videoinput`,u),u.catch(()=>Tl.userMediaPromiseMap.delete(`videoinput`)));try{let e=yield u;return yield Promise.all(e.getTracks().map(n=>O(this,void 0,void 0,function*(){let r=n.kind===`audio`,o,s=r?l.audio:l.video;typeof s!=`boolean`&&(o=s);let c=n.getSettings().deviceId;o?.deviceId&&ac(o.deviceId)!==c?o.deviceId=c:o||={deviceId:c};let u=Vd(n,o,t);return u.kind===H.Kind.Video?u.source=H.Source.Camera:u.kind===H.Kind.Audio&&(u.source=H.Source.Microphone),u.mediaStream=e,vc(u)&&i?yield u.setProcessor(i):yc(u)&&a&&(yield u.setProcessor(a)),u})))}catch(r){if(!n)throw r;return ym(Object.assign(Object.assign({},e),{audio:s,video:c}),t)}})}var bm;(function(e){e.Excellent=`excellent`,e.Good=`good`,e.Poor=`poor`,e.Lost=`lost`,e.Unknown=`unknown`})(bm||={});function xm(e){switch(e){case cn.EXCELLENT:return bm.Excellent;case cn.GOOD:return bm.Good;case cn.POOR:return bm.Poor;case cn.LOST:return bm.Lost;default:return bm.Unknown}}var Sm=class extends Yi.EventEmitter{get logContext(){var e;return Object.assign({},((e=this.loggerOptions)?.loggerContextCb)?.call(e))}get isEncrypted(){return this.trackPublications.size>0&&Array.from(this.trackPublications.values()).every(e=>e.isEncrypted)}get isAgent(){return this.permissions?.agent||this.kind===yn.AGENT}get isActive(){return this.participantInfo?.state===vn.ACTIVE}get kind(){return this._kind}get attributes(){return Object.freeze(Object.assign({},this._attributes))}constructor(e,t,n,r,i,a){let o=arguments.length>6&&arguments[6]!==void 0?arguments[6]:yn.STANDARD;super(),this.audioLevel=0,this.isSpeaking=!1,this._connectionQuality=bm.Unknown,this.log=E,this.loggerOptions=a,this.log=D(a?.loggerName??T.Participant,()=>this.logContext),this.setMaxListeners(100),this.sid=e,this.identity=t,this.name=n,this.metadata=r,this.audioTrackPublications=new Map,this.videoTrackPublications=new Map,this.trackPublications=new Map,this._kind=o,this._attributes=i??{}}getTrackPublications(){return Array.from(this.trackPublications.values())}getTrackPublication(e){for(let t of this.trackPublications){let n=_(t,2)[1];if(n.source===e)return n}}getTrackPublicationByName(e){for(let t of this.trackPublications){let n=_(t,2)[1];if(n.trackName===e)return n}}waitUntilActive(){return this.isActive?Promise.resolve():(this.activeFuture||(this.activeFuture=new G,this.once(L.Active,()=>{var e,t;(t=(e=this.activeFuture)?.resolve)==null||t.call(e),this.activeFuture=void 0})),this.activeFuture.promise)}get connectionQuality(){return this._connectionQuality}get isCameraEnabled(){return!(this.getTrackPublication(H.Source.Camera)?.isMuted??!0)}get isMicrophoneEnabled(){return!(this.getTrackPublication(H.Source.Microphone)?.isMuted??!0)}get isScreenShareEnabled(){return!!this.getTrackPublication(H.Source.ScreenShare)}get isLocal(){return!1}get joinedAt(){return this.participantInfo?new Date(Number.parseInt(this.participantInfo.joinedAt.toString())*1e3):new Date}updateInfo(e){return this.participantInfo&&this.participantInfo.sid===e.sid&&this.participantInfo.version>e.version?!1:(this.identity=e.identity,this.sid=e.sid,this._setName(e.name),this._setMetadata(e.metadata),this._setAttributes(e.attributes),e.state===vn.ACTIVE&&this.participantInfo?.state!==vn.ACTIVE&&this.emit(L.Active),e.permission&&this.setPermissions(e.permission),this.participantInfo=e,!0)}_setMetadata(e){let t=this.metadata!==e,n=this.metadata;this.metadata=e,t&&this.emit(L.ParticipantMetadataChanged,n)}_setName(e){let t=this.name!==e;this.name=e,t&&this.emit(L.ParticipantNameChanged,e)}_setAttributes(e){let t=ts(this.attributes,e);this._attributes=e,Object.keys(t).length>0&&this.emit(L.AttributesChanged,t)}setPermissions(e){let t=this.permissions,n=e.canPublish!==this.permissions?.canPublish||e.canSubscribe!==this.permissions?.canSubscribe||e.canPublishData!==this.permissions?.canPublishData||e.hidden!==this.permissions?.hidden||e.recorder!==this.permissions?.recorder||e.canPublishSources.length!==this.permissions.canPublishSources.length||e.canPublishSources.some((e,t)=>e!==this.permissions?.canPublishSources[t])||e.canSubscribeMetrics!==this.permissions?.canSubscribeMetrics;return this.permissions=e,n&&this.emit(L.ParticipantPermissionsChanged,t),n}setIsSpeaking(e){e!==this.isSpeaking&&(this.isSpeaking=e,e&&(this.lastSpokeAt=new Date),this.emit(L.IsSpeakingChanged,e))}setConnectionQuality(e){let t=this._connectionQuality;this._connectionQuality=xm(e),t!==this._connectionQuality&&this.emit(L.ConnectionQualityChanged,this._connectionQuality)}setDisconnected(){var e,t;this.activeFuture&&=((t=(e=this.activeFuture).reject)==null||t.call(e,Error(`Participant disconnected`)),void 0)}setAudioContext(e){return O(this,void 0,void 0,function*(){this.audioContext=e,yield Promise.all(Array.from(this.audioTrackPublications.values()).map(e=>e.track).filter(vc).map(t=>t.setAudioContext(e)))})}addTrackPublication(e){this.log.debug(`adding track publication`,{trackSid:e.trackSid,source:e.source,kind:e.kind}),e.on(z.Muted,()=>{this.emit(L.TrackMuted,e)}),e.on(z.Unmuted,()=>{this.emit(L.TrackUnmuted,e)});let t=e;switch(t.track&&(t.track.sid=e.trackSid),this.trackPublications.set(e.trackSid,e),e.kind){case H.Kind.Audio:this.audioTrackPublications.set(e.trackSid,e);break;case H.Kind.Video:this.videoTrackPublications.set(e.trackSid,e)}}};function Cm(e){if(!e.participantSid&&!e.participantIdentity)throw Error(`Invalid track permission, must provide at least one of participantIdentity and participantSid`);return new ri({participantIdentity:e.participantIdentity??``,participantSid:e.participantSid??``,allTracks:e.allowAll??!1,trackSids:e.allowedTrackSids||[]})}var wm=class extends Sm{constructor(e,t,n,r,a,o,s,c){super(e,t,void 0,void 0,void 0,{loggerName:r.loggerName,loggerContextCb:()=>this.engine.logContext}),this.pendingPublishing=new Set,this.pendingPublishPromises=new Map,this.participantTrackPermissions=[],this.allParticipantsAllowedToSubscribe=!0,this.encryptionType=S.NONE,this.e2eeStateMutex=new i,this.enabledPublishVideoCodecs=[],this.handleReconnecting=()=>{this.reconnectFuture||=new G},this.handleReconnected=()=>{var e,t;(t=(e=this.reconnectFuture)?.resolve)==null||t.call(e),this.reconnectFuture=void 0,this.updateTrackSubscriptionPermissions()},this.handleClosing=()=>{var e,t,n,r,i,a;this.reconnectFuture&&=(this.reconnectFuture.promise.catch(e=>this.log.warn(e.message)),(t=(e=this.reconnectFuture)?.reject)==null||t.call(e,Error(`Got disconnected during reconnection attempt`)),void 0),this.signalConnectedFuture&&=((r=(n=this.signalConnectedFuture).reject)==null||r.call(n,Error(`Got disconnected without signal connected`)),void 0),(a=(i=this.activeAgentFuture)?.reject)==null||a.call(i,Error(`Got disconnected without active agent present`)),this.activeAgentFuture=void 0,this.firstActiveAgent=void 0},this.handleSignalConnected=e=>{var t,n;e.participant&&this.updateInfo(e.participant),this.signalConnectedFuture||=new G,(n=(t=this.signalConnectedFuture).resolve)==null||n.call(t)},this.handleSignalRequestResponse=e=>{let t=e.requestId,n=e.reason,r=e.message,i=this.pendingSignalRequests.get(t);switch(i&&(n!==_i.OK&&i.reject(new To(r,n)),this.pendingSignalRequests.delete(t)),e.request.case){case`publishDataTrack`:{let t;switch(e.reason){case _i.NOT_ALLOWED:t=Xp.notAllowed(e.message);break;case _i.DUPLICATE_NAME:t=Xp.duplicateName(e.message);break;case _i.INVALID_NAME:t=Xp.invalidName(e.message);break;case _i.LIMIT_EXCEEDED:t=Xp.limitReached(e.message);break;default:t=Xp.unknown(e.reason,e.message)}this.roomOutgoingDataTrackManager.receivedSfuPublishResponse(e.request.value.pubHandle,{type:`error`,error:t});break}}},this.updateTrackSubscriptionPermissions=()=>{this.log.debug(`updating track subscription permissions`,{allParticipantsAllowed:this.allParticipantsAllowedToSubscribe,participantTrackPermissions:this.participantTrackPermissions}),this.engine.client.sendUpdateSubscriptionPermissions(this.allParticipantsAllowedToSubscribe,this.participantTrackPermissions.map(e=>Cm(e)))},this.onTrackUnmuted=e=>{this.onTrackMuted(e,e.isUpstreamPaused)},this.onTrackMuted=(e,t)=>{t===void 0&&(t=!0),e.sid?this.engine.updateMuteStatus(e.sid,t):this.log.error(`could not update mute status for unpublished track`,V(e))},this.onTrackUpstreamPaused=e=>{this.log.debug(`upstream paused`,V(e)),this.onTrackMuted(e,!0)},this.onTrackUpstreamResumed=e=>{this.log.debug(`upstream resumed`,V(e)),this.onTrackMuted(e,e.isMuted)},this.onTrackFeatureUpdate=e=>{let t=this.audioTrackPublications.get(e.sid);t?this.engine.client.sendUpdateLocalAudioTrack(t.trackSid,t.getTrackFeatures()):this.log.warn(`Could not update local audio track settings, missing publication for track ${e.sid}`)},this.onTrackCpuConstrained=(e,t)=>{this.log.debug(`track cpu constrained`,V(t)),this.emit(L.LocalTrackCpuConstrained,e,t)},this.handleSubscribedQualityUpdate=e=>O(this,void 0,void 0,function*(){var t,n,r,i;if(!this.roomOptions?.dynacast)return;let a=this.videoTrackPublications.get(e.trackSid);if(!a){this.log.warn(`received subscribed quality update for unknown track`,{trackSid:e.trackSid});return}if(!a.videoTrack)return;let o=yield a.videoTrack.setPublishingCodecs(e.subscribedCodecs);try{for(var s=!0,c=Gi(o),l;l=yield c.next(),t=l.done,!t;s=!0){i=l.value,s=!1;let e=i;Ro(e)&&(this.log.debug(`publish ${e} for ${a.videoTrack.sid}`,V(a)),yield this.publishAdditionalCodecForTrack(a.videoTrack,e,a.options))}}catch(e){n={error:e}}finally{try{!s&&!t&&(r=c.return)&&(yield r.call(c))}finally{if(n)throw n.error}}}),this.handleLocalTrackUnpublished=e=>{let t=this.trackPublications.get(e.trackSid);t?this.unpublishTrack(t.track):this.log.warn(`received unpublished event for unknown track`,{trackSid:e.trackSid})},this.handleTrackEnded=e=>O(this,void 0,void 0,function*(){if(e.source===H.Source.ScreenShare||e.source===H.Source.ScreenShareAudio)this.log.debug(`unpublishing local track due to TrackEnded`,V(e)),this.unpublishTrack(e);else if(e.isUserProvided)yield e.mute();else if(xc(e)||bc(e))try{if(W())try{let t=yield navigator==null?void 0:navigator.permissions.query({name:e.source===H.Source.Camera?`camera`:`microphone`});if(t&&t.state===`denied`)throw this.log.warn(`user has revoked access to ${e.source}`,V(e)),t.onchange=()=>{t.state!==`denied`&&(e.isMuted||e.restartTrack(),t.onchange=null)},Error(`GetUserMedia Permission denied`)}catch{}e.isMuted||(this.log.debug(`track ended, attempting to use a different device`,V(e)),xc(e)?yield this.restartOnDefaultAudioDevice(e):yield e.restartTrack())}catch{this.log.warn(`could not restart track, muting instead`,V(e)),yield e.mute()}}),this.audioTrackPublications=new Map,this.videoTrackPublications=new Map,this.trackPublications=new Map,this.engine=n,this.roomOptions=r,this.setupEngine(n),this.activeDeviceMap=new Map([[`audioinput`,`default`],[`videoinput`,`default`],[`audiooutput`,`default`]]),this.pendingSignalRequests=new Map,this.roomOutgoingDataStreamManager=a,this.roomOutgoingDataTrackManager=o,this.rpcClientManager=s,this.rpcServerManager=c}get lastCameraError(){return this.cameraError}get lastMicrophoneError(){return this.microphoneError}get isE2EEEnabled(){return this.encryptionType!==S.NONE}getTrackPublication(e){let t=super.getTrackPublication(e);if(t)return t}getTrackPublicationByName(e){let t=super.getTrackPublicationByName(e);if(t)return t}setupEngine(e){this.engine=e,this.engine.on(R.RemoteMute,(e,t)=>{let n=this.trackPublications.get(e);n&&n.track&&(t?n.mute():n.unmute())}),this.signalConnectedFuture?.isResolved&&(this.signalConnectedFuture=void 0),this.engine.on(R.Connected,this.handleReconnected).on(R.SignalConnected,this.handleSignalConnected).on(R.SignalRestarted,this.handleReconnected).on(R.SignalResumed,this.handleReconnected).on(R.Restarting,this.handleReconnecting).on(R.Resuming,this.handleReconnecting).on(R.LocalTrackUnpublished,this.handleLocalTrackUnpublished).on(R.SubscribedQualityUpdate,this.handleSubscribedQualityUpdate).on(R.Closing,this.handleClosing).on(R.SignalRequestResponse,this.handleSignalRequestResponse)}setMetadata(e){return O(this,void 0,void 0,function*(){yield this.requestMetadataUpdate({metadata:e})})}setName(e){return O(this,void 0,void 0,function*(){yield this.requestMetadataUpdate({name:e})})}setAttributes(e){return O(this,void 0,void 0,function*(){yield this.requestMetadataUpdate({attributes:e})})}requestMetadataUpdate(e){return O(this,arguments,void 0,function(e){var t=this;let n=e.metadata,r=e.name,i=e.attributes;return function*(){return new co((e,a)=>O(t,void 0,void 0,function*(){try{let t=!1,o=yield this.engine.client.sendUpdateLocalMetadata(n??this.metadata??``,r??this.name??``,i),s=performance.now();for(this.pendingSignalRequests.set(o,{resolve:e,reject:e=>{a(e),t=!0},values:{name:r,metadata:n,attributes:i}});performance.now()-s<5e3&&!t;){if((!r||this.name===r)&&(!n||this.metadata===n)&&(!i||Object.entries(i).every(e=>{let t=_(e,2),n=t[0],r=t[1];return this.attributes[n]===r||r===``&&!this.attributes[n]}))){this.pendingSignalRequests.delete(o),e();return}yield U(50)}a(new To(`Request to update local metadata timed out`,`TimeoutError`))}catch(e){e instanceof Error?a(e):a(Error(String(e)))}}))}()})}setCameraEnabled(e,t,n){return this.setTrackEnabled(H.Source.Camera,e,t,n)}setMicrophoneEnabled(e,t,n){return this.setTrackEnabled(H.Source.Microphone,e,t,n)}setScreenShareEnabled(e,t,n){return this.setTrackEnabled(H.Source.ScreenShare,e,t,n)}setE2EEEnabled(e){return O(this,void 0,void 0,function*(){let t=yield this.e2eeStateMutex.lock();try{if(this.encryptionType=e?S.GCM:S.NONE,yield Promise.all(this.pendingPublishPromises.values()),this.trackPublications.size===0||Array.from(this.trackPublications.values()).every(t=>t.isEncrypted===e))return;yield this.republishAllTracks(void 0,!1)}finally{t()}})}setTrackEnabled(e,t,n,r){return O(this,void 0,void 0,function*(){this.log.debug(`setTrackEnabled`,{source:e,enabled:t}),this.republishPromise&&(yield this.republishPromise);let i=this.getTrackPublication(e);if(t){if(i)yield i.unmute();else{let t;if(this.pendingPublishing.has(e)){let t=yield this.waitForPendingPublicationOfSource(e);return t||this.log.info(`waiting for pending publication promise timed out`,{source:e}),yield t?.unmute(),t}this.pendingPublishing.add(e);try{switch(e){case H.Source.Camera:t=yield this.createTracks({video:n??!0});break;case H.Source.Microphone:t=yield this.createTracks({audio:n??!0});break;case H.Source.ScreenShare:t=yield this.createScreenTracks(Object.assign({},n));break;default:throw new bo(e)}}catch(n){throw t?.forEach(e=>{e.stop()}),n instanceof Error&&this.emit(L.MediaDevicesError,n,Xo(e)),this.pendingPublishing.delete(e),n}for(let r of t){let t=Object.assign(Object.assign({},this.roomOptions.publishDefaults),n);e===H.Source.Microphone&&vc(r)&&t.preConnectBuffer&&(this.log.info(`starting preconnect buffer for microphone`),r.startPreConnectBuffer())}try{let e=[];for(let n of t)this.log.info(`publishing track`,V(n)),e.push(this.publishTrack(n,r));i=_(yield Promise.all(e),1)[0]}catch(e){throw t?.forEach(e=>{e.stop()}),e}finally{this.pendingPublishing.delete(e)}}}else if(!i?.track&&this.pendingPublishing.has(e)&&(i=yield this.waitForPendingPublicationOfSource(e),i||this.log.info(`waiting for pending publication promise timed out`,{source:e})),i&&i.track){if(e===H.Source.ScreenShare){let e=[this.unpublishTrack(i.track)],t=this.getTrackPublication(H.Source.ScreenShareAudio);t&&t.track&&e.push(this.unpublishTrack(t.track)),i=_(yield Promise.all(e),1)[0]}else yield i.mute()}return i})}enableCameraAndMicrophone(){return O(this,void 0,void 0,function*(){if(!(this.pendingPublishing.has(H.Source.Camera)||this.pendingPublishing.has(H.Source.Microphone))){this.pendingPublishing.add(H.Source.Camera),this.pendingPublishing.add(H.Source.Microphone);try{let e=yield this.createTracks({audio:!0,video:!0});yield Promise.all(e.map(e=>this.publishTrack(e)))}finally{this.pendingPublishing.delete(H.Source.Camera),this.pendingPublishing.delete(H.Source.Microphone)}}})}createTracks(e){return O(this,void 0,void 0,function*(){e??={};let t=Wo(e,this.roomOptions?.audioCaptureDefaults,this.roomOptions?.videoCaptureDefaults);try{let e=yield ym(t,{loggerName:this.roomOptions.loggerName,loggerContextCb:()=>this.logContext});return yield Promise.all(e.map(e=>O(this,void 0,void 0,function*(){return vc(e)&&(this.microphoneError=void 0,yield e.setAudioContext(this.audioContext),e.source=H.Source.Microphone,this.emit(L.AudioStreamAcquired)),yc(e)&&(this.cameraError=void 0,e.source=H.Source.Camera),e})))}catch(t){throw t instanceof Error&&(e.audio&&(this.microphoneError=t),e.video&&(this.cameraError=t)),t}})}createScreenTracks(e){return O(this,void 0,void 0,function*(){if(e===void 0&&(e={}),navigator.mediaDevices.getDisplayMedia===void 0)throw new yo(`getDisplayMedia not supported`);e.resolution===void 0&&!Ps()&&(e.resolution=Uo.h1080fps30.resolution);let t=Zo(e),n=yield navigator.mediaDevices.getDisplayMedia(t),r=n.getVideoTracks();if(r.length===0)throw new bo(`no video track found`);let i=new sf(r[0],void 0,!1,{loggerName:this.roomOptions.loggerName,loggerContextCb:()=>this.logContext});i.source=H.Source.ScreenShare,e.contentHint&&(i.mediaStreamTrack.contentHint=e.contentHint);let a=[i];if(n.getAudioTracks().length>0){this.emit(L.AudioStreamAcquired);let e=new Bd(n.getAudioTracks()[0],void 0,!1,this.audioContext,{loggerName:this.roomOptions.loggerName,loggerContextCb:()=>this.logContext});e.source=H.Source.ScreenShareAudio,a.push(e)}return a})}publishTrack(e,t){return O(this,void 0,void 0,function*(){return this.publishOrRepublishTrack(e,t)})}waitForNextEngineRestart(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:15e3;return new Promise((t,n)=>{let r=()=>{clearTimeout(o),this.engine.off(R.Restarted,i),this.engine.off(R.Closing,a)},i=()=>{r(),t()},a=()=>{r(),n(Error(`engine closed before restart completed`))},o=setTimeout(()=>{r(),n(Error(`timed out waiting for engine restart`))},e);this.engine.once(R.Restarted,i),this.engine.once(R.Closing,a)})}publishOrRepublishTrack(e,t){return O(this,arguments,void 0,function(e,t){var n=this;let r=arguments.length>2&&arguments[2]!==void 0&&arguments[2],i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return function*(){xc(e)&&(yield e.setAudioContext(n.audioContext)),yield n.reconnectFuture?.promise,n.republishPromise&&!r&&(yield n.republishPromise),_c(e)&&n.pendingPublishPromises.has(e)&&(yield n.pendingPublishPromises.get(e));let a;if(e instanceof MediaStreamTrack)a=e.getConstraints();else{a=e.constraints;let t;switch(e.source){case H.Source.Microphone:t=`audioinput`;break;case H.Source.Camera:t=`videoinput`}t&&n.activeDeviceMap.has(t)&&(a=Object.assign(Object.assign({},a),{deviceId:n.activeDeviceMap.get(t)}))}if(e instanceof MediaStreamTrack)switch(e.kind){case`audio`:e=new Bd(e,a,!0,n.audioContext,{loggerName:n.roomOptions.loggerName,loggerContextCb:()=>n.logContext});break;case`video`:e=new sf(e,a,!0,{loggerName:n.roomOptions.loggerName,loggerContextCb:()=>n.logContext});break;default:throw new bo(`unsupported MediaStreamTrack kind ${e.kind}`)}else e.updateLoggerOptions({loggerName:n.roomOptions.loggerName,loggerContextCb:()=>n.logContext});let o;if(n.trackPublications.forEach(t=>{t.track&&t.track===e&&(o=t)}),o)return n.log.warn(`track has already been published, skipping`,V(o)),o;let s=Object.assign(Object.assign({},n.roomOptions.publishDefaults),t),c=`channelCount`in e.mediaStreamTrack.getSettings()&&e.mediaStreamTrack.getSettings().channelCount===2||e.mediaStreamTrack.getConstraints().channelCount===2,l=s.forceStereo??c;l&&(s.dtx===void 0&&n.log.debug(`Opus DTX will be disabled for stereo tracks by default. Enable them explicitly to make it work.`,V(e)),s.red===void 0&&n.log.debug(`Opus RED will be disabled for stereo tracks by default. Enable them explicitly to make it work.`),s.dtx??=!1,s.red??=!1),!Ls()&&n.roomOptions.e2ee&&(n.log.info(`End-to-end encryption is set up, simulcast publishing will be disabled on Safari versions and iOS browsers running iOS < v17.2`),s.simulcast=!1),s.source&&(e.source=s.source);let u=new Promise((t,r)=>O(n,void 0,void 0,function*(){try{if(this.engine.client.currentState!==hu.CONNECTED){this.log.debug(`deferring track publication until signal is connected`,{track:V(e)});let n=!1,i=setTimeout(()=>{n=!0,e.stop(),r(new wo(`publishing rejected as engine not connected within timeout`,408))},15e3);if(yield this.waitUntilEngineConnected(),clearTimeout(i),n)return;t(yield this.publish(e,s,l))}else try{t(yield this.publish(e,s,l))}catch(e){r(e)}}catch(e){r(e)}}));n.pendingPublishPromises.set(e,u);try{return yield u}catch(a){if(!i&&a instanceof So)return n.log.warn(`negotiation due to track publish failed, retrying after reconnect`,{error:a}),n.pendingPublishPromises.delete(e),yield n.waitForNextEngineRestart(),yield n.publishOrRepublishTrack(e,t,r,!0);throw a}finally{n.pendingPublishPromises.delete(e)}}()})}waitUntilEngineConnected(){return this.signalConnectedFuture||=new G,this.signalConnectedFuture.promise}hasPermissionsToPublish(e){if(!this.permissions)return this.log.warn(`no permissions present for publishing track`,V(e)),!1;let t=this.permissions,n=t.canPublish,r=t.canPublishSources;return n&&(r.length===0||r.map(e=>rs(e)).includes(e.source))?!0:(this.log.warn(`insufficient permissions to publish`,V(e)),!1)}publish(e,t,n){return O(this,void 0,void 0,function*(){if(!this.hasPermissionsToPublish(e))throw new wo(`failed to publish track, insufficient permissions`,403);Array.from(this.trackPublications.values()).find(t=>_c(e)&&t.source===e.source)&&e.source!==H.Source.Unknown&&this.log.info(`publishing a second track with the same source: ${e.source}`,V(e)),t.stopMicTrackOnMute&&vc(e)&&(e.stopOnMute=!0),e.source===H.Source.ScreenShare&&Ds()&&(t.simulcast=!1),t.videoCodec===`av1`&&!_s()&&(t.videoCodec=void 0),t.videoCodec===`vp9`&&!vs()&&(t.videoCodec=void 0),t.videoCodec===void 0&&(t.videoCodec=dd),this.enabledPublishVideoCodecs.length>0&&(this.enabledPublishVideoCodecs.some(e=>t.videoCodec===Qo(e.mime))||(t.videoCodec=Qo(this.enabledPublishVideoCodecs[0].mime)));let r=t.videoCodec;e.on(z.Muted,this.onTrackMuted),e.on(z.Unmuted,this.onTrackUnmuted),e.on(z.Ended,this.handleTrackEnded),e.on(z.UpstreamPaused,this.onTrackUpstreamPaused),e.on(z.UpstreamResumed,this.onTrackUpstreamResumed),e.on(z.AudioTrackFeatureUpdate,this.onTrackFeatureUpdate);let i=[],a=!(t.dtx??!0),o=e.getSourceTrackSettings();o.autoGainControl&&i.push(x.TF_AUTO_GAIN_CONTROL),o.echoCancellation&&i.push(x.TF_ECHO_CANCELLATION),o.noiseSuppression&&i.push(x.TF_NOISE_SUPPRESSION),o.channelCount&&o.channelCount>1&&i.push(x.TF_STEREO),a&&i.push(x.TF_NO_DTX),xc(e)&&e.hasPreConnectBuffer&&i.push(x.TF_PRECONNECT_BUFFER);let s=this.normalizeRequestedFrameMetadataOptions(e,t),c=new _r({cid:e.mediaStreamTrack.id,name:t.name,type:H.kindToProto(e.kind),muted:e.isMuted,source:H.sourceToProto(e.source),disableDtx:a,encryption:this.encryptionType,stereo:n,disableRed:this.isE2EEEnabled||!(t.red??!0),stream:t?.stream,backupCodecPolicy:t?.backupCodecPolicy,audioFeatures:i,packetTrailerFeatures:s}),l;if(e.kind===H.Kind.Video){let n;try{n=yield e.waitForDimensions()}catch{let t=this.roomOptions.videoCaptureDefaults?.resolution??Vo.h720.resolution;n={width:t.width,height:t.height},this.log.error(`could not determine track dimensions, using defaults`,Object.assign(Object.assign({},V(e)),{dims:n}))}if(c.width=n.width,c.height=n.height,bc(e)){xs(r,t)&&(Ss()||!ws(this.engine?.serverVersion))&&(t.simulcast=!1,this.log.info(`SVC simulcast is not supported, disabling simulcast.`,V(e)));let n=xs(r,t);ys(r)&&!n&&(e.source===H.Source.ScreenShare&&(t.scalabilityMode=`L1T3`,`contentHint`in e.mediaStreamTrack&&(e.mediaStreamTrack.contentHint=`motion`,this.log.debug(`forcing contentHint to motion for screenshare with SVC codecs`,V(e)))),t.scalabilityMode=t.scalabilityMode??`L3T3_KEY`);let i=new gr({codec:r,cid:e.mediaStreamTrack.id});n&&(i.videoLayerMode=Nn.ONE_SPATIAL_LAYER_PER_STREAM),c.simulcastCodecs=[i],t.backupCodec===!0&&(t.backupCodec={codec:dd}),t.backupCodec&&r!==t.backupCodec.codec&&c.encryption===S.NONE&&(this.roomOptions.dynacast||(this.roomOptions.dynacast=!0),c.simulcastCodecs.push(new gr({codec:t.backupCodec.codec,cid:``})))}l=Yd(e.source===H.Source.ScreenShare,c.width,c.height,t),c.layers=uf(c.width,c.height,l,ys(t.videoCodec)&&!xs(t.videoCodec,t))}else e.kind===H.Kind.Audio&&(l=[{maxBitrate:t.audioPreset?.maxBitrate,priority:t.audioPreset?.priority??`high`,networkPriority:t.audioPreset?.priority??`high`}]);if(!this.engine||this.engine.isClosed)throw new M(`cannot publish track when not connected`);let u=()=>O(this,void 0,void 0,function*(){if(!this.engine.pcManager)throw new M(`pcManager is not ready`);if(e.sender=yield this.engine.createSender(e,t,l),bc(e)&&(e.publishOptions=t),this.emit(L.LocalSenderCreated,e.sender,e),bc(e)&&(t.degradationPreference??=af(e),e.setDegradationPreference(t.degradationPreference)),l){if(Ds()&&e.kind===H.Kind.Audio){let t;for(let n of this.engine.pcManager.publisher.getTransceivers())if(n.sender===e.sender){t=n;break}t&&this.engine.pcManager.publisher.setTrackCodecBitrate({transceiver:t,codec:`opus`,maxbr:l[0]?.maxBitrate?l[0].maxBitrate/1e3:0})}else if(e.codec&&ic(e.codec)){let n=Xd(e.codec,t,l);n>0&&this.engine.pcManager.publisher.setTrackCodecBitrate({cid:c.cid,codec:e.codec,maxbr:n/1e3,isScreenShare:e.source===H.Source.ScreenShare})}}yield this.engine.negotiate()}),d,f=new Promise((t,n)=>O(this,void 0,void 0,function*(){try{d=yield this.engine.addTrack(c),t(d)}catch(t){if(e.sender&&this.engine.pcManager?.publisher){try{this.engine.pcManager.publisher.removeTrack(e.sender)}catch(e){this.log.error(e)}yield this.engine.negotiate().catch(t=>{this.log.error(`failed to negotiate after removing track due to failed add track request`,Object.assign(Object.assign({},V(e)),{error:t}))})}n(t)}}));if(this.enabledPublishVideoCodecs.length>0&&s.length===0)d=(yield Promise.all([f,u()]))[0];else{d=yield f;let n;if(d.codecs.forEach(e=>{n===void 0&&(n=e.mimeType)}),n&&e.kind===H.Kind.Video){let i=Qo(n);i!==r&&(this.log.debug(`falling back to server selected codec`,Object.assign(Object.assign({},V(e)),{codec:i})),t.videoCodec=i,l=Yd(e.source===H.Source.ScreenShare,c.width,c.height,t))}yield u()}let p=new vm(e.kind,d,e,{loggerName:this.roomOptions.loggerName,loggerContextCb:()=>this.logContext});if(p.on(z.CpuConstrained,e=>this.onTrackCpuConstrained(e,p)),p.options=t,e.sid=d.sid,bc(e)&&(e.publishOptions=t,c.width&&c.height&&(e.lastEncodedDimensions={width:c.width,height:c.height})),this.log.debug(`publishing ${e.kind} with encodings`,{encodings:l,trackInfo:d}),bc(e)?e.startMonitor(this.engine.client):xc(e)&&e.startMonitor(),this.addTrackPublication(p),this.emit(L.LocalTrackPublished,p),xc(e)&&d.audioFeatures.includes(x.TF_PRECONNECT_BUFFER)){let t=e.getPreConnectBuffer(),n=e.getPreConnectBufferMimeType();this.on(L.LocalTrackSubscribed,t=>{if(t.trackSid===d.sid){if(!e.hasPreConnectBuffer){this.log.warn(`subscribe event came to late, buffer already closed`);return}this.log.debug(`finished recording preconnect buffer`,V(e)),e.stopPreConnectBuffer()}}),t&&new Promise((r,i)=>O(this,void 0,void 0,function*(){var a,s,c,l;try{this.log.debug(`waiting for agent`,V(e));let ee=setTimeout(()=>{i(Error(`agent not active within 10 seconds`))},1e4),te=yield this.waitUntilActiveAgentPresent();clearTimeout(ee),this.log.debug(`sending preconnect buffer`,V(e));let ne=yield this.streamBytes({name:`preconnect-buffer`,mimeType:n,topic:`lk.agent.pre-connect-audio-buffer`,destinationIdentities:[te.identity],attributes:{trackId:p.trackSid,sampleRate:String(o.sampleRate??`48000`),channels:String(o.channelCount??`1`)}});try{for(var u=!0,d=Gi(t),f;f=yield d.next(),a=f.done,!a;u=!0){l=f.value,u=!1;let e=l;yield ne.write(e)}}catch(e){s={error:e}}finally{try{!u&&!a&&(c=d.return)&&(yield c.call(d))}finally{if(s)throw s.error}}yield ne.close(),r()}catch(e){i(e)}})).then(()=>{this.log.debug(`preconnect buffer sent successfully`,V(e))}).catch(t=>{this.log.error(`error sending preconnect buffer`,Object.assign(Object.assign({},V(e)),{error:t}))})}return p})}canPublishFrameMetadata(){return!!(this.roomOptions.e2ee||this.roomOptions.encryption||rl(this.roomOptions.frameMetadata??this.roomOptions.packetTrailer))}normalizeRequestedFrameMetadataOptions(e,t){let n=t.frameMetadata??t.packetTrailer;if(e.kind!==H.Kind.Video||!il(n))return t.frameMetadata=void 0,t.packetTrailer=void 0,[];if(!this.canPublishFrameMetadata())return this.log.warn(`frame metadata transform not supported; not advertising features`,Object.assign(Object.assign({},this.logContext),V(e))),t.frameMetadata=void 0,t.packetTrailer=void 0,[];let r=al(n),i=ol(r);return t.frameMetadata=i,t.packetTrailer=i,r}get isLocal(){return!0}publishAdditionalCodecForTrack(e,t,n){return O(this,void 0,void 0,function*(){if(this.encryptionType!==S.NONE)return;let r;if(this.trackPublications.forEach(t=>{t.track&&t.track===e&&(r=t)}),!r)throw new bo(`track is not published`);if(!bc(e))throw new bo(`track is not a video track`);let i=Object.assign(Object.assign({},this.roomOptions?.publishDefaults),n),a=Zd(e,t,i);if(!a){this.log.info(`backup codec has been disabled, ignoring request to add additional codec for track`,V(e));return}let o=e.addSimulcastTrack(t,a);if(!o)return;let s=this.normalizeRequestedFrameMetadataOptions(e,i),c=e.mediaStreamTrack.getSettings(),l=c.width,u=c.height,d=l&&u?{width:l,height:u}:void 0;d||this.log.warn(`could not determine track dimensions, publishing backup codec without layers`,V(e));let f=d?uf(d.width,d.height,a):[],p=new _r({cid:o.mediaStreamTrack.id,type:H.kindToProto(e.kind),muted:e.isMuted,source:H.sourceToProto(e.source),sid:e.sid,width:d?.width,height:d?.height,packetTrailerFeatures:s,layers:f,simulcastCodecs:[{codec:i.videoCodec,cid:o.mediaStreamTrack.id,layers:f}]});if(!this.engine||this.engine.isClosed)throw new M(`cannot publish track when not connected`);let ee=(yield Promise.all([this.engine.addTrack(p),O(this,void 0,void 0,function*(){yield this.engine.createSimulcastSender(e,o,i,a),yield this.engine.negotiate()})]))[0];this.log.debug(`published ${t} for track ${e.sid}`,{encodings:a,trackInfo:ee})})}unpublishTrack(e,t){return O(this,void 0,void 0,function*(){if(_c(e)){let t=this.pendingPublishPromises.get(e);t&&(this.log.debug(`awaiting publish promise before attempting to unpublish`,V(e)),yield t)}let n=this.getPublicationForTrack(e),r=n?V(n):void 0;if(this.log.info(`unpublishing track`,r),!n||!n.track){this.log.warn(`track was not unpublished because no publication was found`,r);return}e=n.track,e.off(z.Muted,this.onTrackMuted),e.off(z.Unmuted,this.onTrackUnmuted),e.off(z.Ended,this.handleTrackEnded),e.off(z.UpstreamPaused,this.onTrackUpstreamPaused),e.off(z.UpstreamResumed,this.onTrackUpstreamResumed),e.off(z.AudioTrackFeatureUpdate,this.onTrackFeatureUpdate),t===void 0&&(t=this.roomOptions?.stopLocalTrackOnUnpublish??!0),t?e.stop():e.stopMonitor();let i=!1,a=e.sender;if(e.sender=void 0,this.engine.pcManager&&this.engine.pcManager.currentState<K.FAILED&&a)try{for(let e of this.engine.pcManager.publisher.getTransceivers())e.sender===a&&(e.direction=`inactive`,i=!0);try{i=this.engine.removeTrack(a)}catch(e){this.log.warn(e),i=!0}if(bc(e)){for(let t of e.simulcastCodecs){let e=_(t,2)[1];if(e.sender){try{i=this.engine.removeTrack(e.sender)}catch(e){this.log.warn(e),i=!0}e.sender=void 0}}e.simulcastCodecs.clear()}}catch(e){this.log.warn(`failed to unpublish track`,Object.assign(Object.assign({},r),{error:e}))}switch(this.trackPublications.delete(n.trackSid),n.kind){case H.Kind.Audio:this.audioTrackPublications.delete(n.trackSid);break;case H.Kind.Video:this.videoTrackPublications.delete(n.trackSid)}return this.emit(L.LocalTrackUnpublished,n),n.setTrack(void 0),i&&(yield this.engine.negotiate()),n})}unpublishTracks(e){return O(this,void 0,void 0,function*(){return(yield Promise.all(e.map(e=>this.unpublishTrack(e)))).filter(e=>!!e)})}republishAllTracks(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return function*(){t.republishPromise&&(yield t.republishPromise),t.republishPromise=new co((r,i)=>O(t,void 0,void 0,function*(){try{let t=[];this.trackPublications.forEach(n=>{n.track&&(e&&(n.options=Object.assign(Object.assign({},n.options),e)),t.push(n))}),yield Promise.all(t.map(e=>O(this,void 0,void 0,function*(){let t=e.track;yield this.unpublishTrack(t,!1),n&&!t.isMuted&&t.source!==H.Source.ScreenShare&&t.source!==H.Source.ScreenShareAudio&&(xc(t)||bc(t))&&!t.isUserProvided&&(this.log.debug(`restarting existing track`,{track:e.trackSid}),yield t.restartTrack()),yield this.publishOrRepublishTrack(t,e.options,!0)}))),r()}catch(e){e instanceof Error?i(e):i(Error(String(e)))}finally{this.republishPromise=void 0}})),yield t.republishPromise}()})}publishData(e){return O(this,arguments,void 0,function(e){var t=this;let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return function*(){let r=n.reliable?q.RELIABLE:q.LOSSY,i=n.reliable?Pn.RELIABLE:Pn.LOSSY,a=n.destinationIdentities,o=n.topic,s=new C({kind:i,value:{case:`user`,value:new zn({participantIdentity:t.identity,payload:e,destinationIdentities:a,topic:o})}});yield t.engine.sendDataPacket(s,r)}()})}publishDtmf(e,t){return O(this,void 0,void 0,function*(){let n=new C({kind:Pn.RELIABLE,value:{case:`sipDtmf`,value:new Bn({code:e,digit:t})}});yield this.engine.sendDataPacket(n,q.RELIABLE)})}sendChatMessage(e,t){return O(this,void 0,void 0,function*(){let n={id:crypto.randomUUID(),message:e,timestamp:Date.now(),attachedFiles:t?.attachments},r=new C({value:{case:`chatMessage`,value:new Un(Object.assign(Object.assign({},n),{timestamp:m.parse(n.timestamp)}))}});return yield this.engine.sendDataPacket(r,q.RELIABLE),this.emit(L.ChatMessage,n),n})}editChatMessage(e,t){return O(this,void 0,void 0,function*(){let n=Object.assign(Object.assign({},t),{message:e,editTimestamp:Date.now()}),r=new C({value:{case:`chatMessage`,value:new Un(Object.assign(Object.assign({},n),{timestamp:m.parse(n.timestamp),editTimestamp:m.parse(n.editTimestamp)}))}});return yield this.engine.sendDataPacket(r,q.RELIABLE),this.emit(L.ChatMessage,n),n})}sendText(e,t){return O(this,void 0,void 0,function*(){return this.roomOutgoingDataStreamManager.sendText(e,t)})}streamText(e){return O(this,void 0,void 0,function*(){return this.roomOutgoingDataStreamManager.streamText(e)})}sendFile(e,t){return O(this,void 0,void 0,function*(){return this.roomOutgoingDataStreamManager.sendFile(e,t)})}sendBytes(e,t){return O(this,void 0,void 0,function*(){return this.roomOutgoingDataStreamManager.sendBytes(e,t)})}streamBytes(e){return O(this,void 0,void 0,function*(){return this.roomOutgoingDataStreamManager.streamBytes(e)})}performRpc(e){return this.rpcClientManager.performRpc(e).then(e=>{let t=_(e,2);return t[0],t[1]})}registerRpcMethod(e,t){this.rpcServerManager.registerRpcMethod(e,t)}unregisterRpcMethod(e){this.rpcServerManager.unregisterRpcMethod(e)}setTrackSubscriptionPermissions(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];this.participantTrackPermissions=t,this.allParticipantsAllowedToSubscribe=e,this.engine.client.isDisconnected||this.updateTrackSubscriptionPermissions()}setEnabledPublishCodecs(e){this.enabledPublishVideoCodecs=e.filter(e=>e.mime.split(`/`)[0].toLowerCase()===`video`)}updateInfo(e){return super.updateInfo(e)?(e.tracks.forEach(e=>{let t=this.trackPublications.get(e.sid);if(t){let n=t.isMuted||(t.track?.isUpstreamPaused??!1);n!==e.muted&&(this.log.debug(`updating server mute state after reconcile`,Object.assign(Object.assign({},V(t)),{mutedOnServer:n})),this.engine.client.sendMuteTrack(e.sid,n))}}),!0):!1}setActiveAgent(e){var t,n,r,i;this.firstActiveAgent=e,e&&!this.firstActiveAgent&&(this.firstActiveAgent=e),e?(n=(t=this.activeAgentFuture)?.resolve)==null||n.call(t,e):(i=(r=this.activeAgentFuture)?.reject)==null||i.call(r,Error(`Agent disconnected`)),this.activeAgentFuture=void 0}waitUntilActiveAgentPresent(){return this.firstActiveAgent?Promise.resolve(this.firstActiveAgent):(this.activeAgentFuture||=new G,this.activeAgentFuture.promise)}restartOnDefaultAudioDevice(e){return O(this,void 0,void 0,function*(){try{Os()?yield e.setDeviceId({exact:`default`}):yield e.restartTrack()}catch(t){if(!lc(t)||oc(t)||e.isStopped)throw t;this.log.debug(`could not reacquire the audio device, retrying with an enumerated device`,V(e));let n=yield Tl.getInstance().getDevices(`audioinput`,!1);yield e.setDeviceId(n?.[0]?.deviceId??`default`)}})}getPublicationForTrack(e){let t;return this.trackPublications.forEach(n=>{let r=n.track;r&&(e instanceof MediaStreamTrack?(xc(r)||bc(r))&&r.mediaStreamTrack===e&&(t=n):e===r&&(t=n))}),t}waitForPendingPublicationOfSource(e){return O(this,void 0,void 0,function*(){let t=Date.now();for(;Date.now()<t+1e4;){let t=Array.from(this.pendingPublishPromises.entries()).find(t=>_(t,1)[0].source===e);if(t)return t[1];yield U(20)}})}publishDataTrack(e){return O(this,void 0,void 0,function*(){let t=new tm(e,this.roomOutgoingDataTrackManager);return yield t.publish(),t})}},Tm=class extends DOMException{constructor(e,t){super(e,`AbortError`),this.reason=t}},Em=class extends Map{constructor(){super(...arguments),this.pending=new Map}set(e,t){var n;super.set(e,t);let r=this.pending?.get(e);if(r){for(let e of r)e.isResolved||(n=e.resolve)==null||n.call(e,t);this.pending.delete(e)}return this}get[Symbol.toStringTag](){return`DeferrableMap`}getDeferred(e,t){return O(this,void 0,void 0,function*(){let n=this.get(e);if(n!==void 0)return n;if(t?.aborted)throw new Tm(`The operation was aborted.`,t.reason);let r=new G(void 0,()=>{let t=this.pending.get(e);if(!t)return;let n=t.indexOf(r);n!==-1&&t.splice(n,1),t.length===0&&this.pending.delete(e)}),i=this.pending.get(e);if(i?i.push(r):this.pending.set(e,[r]),t){let e=()=>{var e;r.isResolved||(e=r.reject)==null||e.call(r,new Tm(`The operation was aborted.`,t.reason))};t.addEventListener(`abort`,e,{once:!0}),r.promise.finally(()=>{t.removeEventListener(`abort`,e)})}return r.promise})}},Dm=class extends _m{constructor(e,t,n,r){super(e,t.sid,t.name,r),this.track=void 0,this.allowed=!0,this.requestedDisabled=void 0,this.visible=!0,this.handleEnded=e=>{this.setTrack(void 0),this.emit(z.Ended,e)},this.handleVisibilityChange=e=>{this.log.debug(`adaptivestream video visibility ${this.trackSid}, visible=${e}`,this.logContext),this.visible=e,this.emitTrackUpdate()},this.handleVideoDimensionsChange=e=>{this.log.debug(`adaptivestream video dimensions ${e.width}x${e.height}`,this.logContext),this.videoDimensionsAdaptiveStream=e,this.emitTrackUpdate()},this.subscribed=n,this.updateInfo(t)}setSubscribed(e){let t=this.subscriptionStatus,n=this.permissionStatus;this.subscribed=e,e&&(this.allowed=!0);let r=new Mr({trackSids:[this.trackSid],subscribe:this.subscribed,participantTracks:[new Jn({participantSid:``,trackSids:[this.trackSid]})]});this.emit(z.UpdateSubscription,r),this.emitSubscriptionUpdateIfChanged(t),this.emitPermissionUpdateIfChanged(n)}get subscriptionStatus(){return this.subscribed===!1?_m.SubscriptionStatus.Unsubscribed:super.isSubscribed?_m.SubscriptionStatus.Subscribed:_m.SubscriptionStatus.Desired}get permissionStatus(){return this.allowed?_m.PermissionStatus.Allowed:_m.PermissionStatus.NotAllowed}get isSubscribed(){return this.subscribed!==!1&&super.isSubscribed}get isDesired(){return this.subscribed!==!1}get isEnabled(){return this.requestedDisabled===void 0?!this.isAdaptiveStream||this.visible:!this.requestedDisabled}get isLocal(){return!1}setEnabled(e){this.isManualOperationAllowed()&&this.requestedDisabled!==!e&&(this.requestedDisabled=!e,this.emitTrackUpdate())}setVideoQuality(e){this.isManualOperationAllowed()&&this.requestedMaxQuality!==e&&(this.requestedMaxQuality=e,this.requestedVideoDimensions=void 0,this.emitTrackUpdate())}setVideoDimensions(e){this.isManualOperationAllowed()&&(this.requestedVideoDimensions?.width!==e.width||this.requestedVideoDimensions?.height!==e.height)&&(wc(this.track)&&(this.requestedVideoDimensions=e),this.requestedMaxQuality=void 0,this.emitTrackUpdate())}setVideoFPS(e){this.isManualOperationAllowed()&&wc(this.track)&&this.fps!==e&&(this.fps=e,this.emitTrackUpdate())}get videoQuality(){return this.requestedMaxQuality??ls.HIGH}setTrack(e){let t=this.subscriptionStatus,n=this.permissionStatus,r=this.track;r!==e&&(r&&(r.off(z.VideoDimensionsChanged,this.handleVideoDimensionsChange),r.off(z.VisibilityChanged,this.handleVisibilityChange),r.off(z.Ended,this.handleEnded),r.detach(),r.stopMonitor(),this.emit(z.Unsubscribed,r)),super.setTrack(e),e&&(e.sid=this.trackSid,e.on(z.VideoDimensionsChanged,this.handleVideoDimensionsChange),e.on(z.VisibilityChanged,this.handleVisibilityChange),e.on(z.Ended,this.handleEnded),this.emit(z.Subscribed,e)),this.emitPermissionUpdateIfChanged(n),this.emitSubscriptionUpdateIfChanged(t))}setAllowed(e){let t=this.subscriptionStatus,n=this.permissionStatus;this.allowed=e,this.emitPermissionUpdateIfChanged(n),this.emitSubscriptionUpdateIfChanged(t)}setSubscriptionError(e){this.emit(z.SubscriptionFailed,e)}updateInfo(e){super.updateInfo(e);let t=this.metadataMuted;this.metadataMuted=e.muted,this.track?this.track.setMuted(e.muted):t!==e.muted&&this.emit(e.muted?z.Muted:z.Unmuted)}emitSubscriptionUpdateIfChanged(e){let t=this.subscriptionStatus;e!==t&&this.emit(z.SubscriptionStatusChanged,t,e)}emitPermissionUpdateIfChanged(e){this.permissionStatus!==e&&this.emit(z.SubscriptionPermissionChanged,this.permissionStatus,e)}isManualOperationAllowed(){return this.isDesired?!0:(this.log.warn(`cannot update track settings when not subscribed`,this.logContext),!1)}get isAdaptiveStream(){return wc(this.track)&&this.track.isAdaptiveStream}emitTrackUpdate(){let e=new zr({trackSids:[this.trackSid],disabled:!this.isEnabled,fps:this.fps});if(this.kind===H.Kind.Video){let t=this.requestedVideoDimensions;if(this.videoDimensionsAdaptiveStream!==void 0){if(t)is(this.videoDimensionsAdaptiveStream,t)&&(this.log.debug(`using adaptive stream dimensions instead of requested`,Object.assign(Object.assign({},this.logContext),this.videoDimensionsAdaptiveStream)),t=this.videoDimensionsAdaptiveStream);else if(this.requestedMaxQuality!==void 0&&this.trackInfo){let e=as(this.trackInfo,this.requestedMaxQuality);e&&is(this.videoDimensionsAdaptiveStream,e)&&(this.log.debug(`using adaptive stream dimensions instead of max quality layer`,Object.assign(Object.assign({},this.logContext),this.videoDimensionsAdaptiveStream)),t=this.videoDimensionsAdaptiveStream)}else this.log.debug(`using adaptive stream dimensions`,Object.assign(Object.assign({},this.logContext),this.videoDimensionsAdaptiveStream)),t=this.videoDimensionsAdaptiveStream}t?(e.width=Math.ceil(t.width),e.height=Math.ceil(t.height)):this.requestedMaxQuality===void 0?(this.log.debug(`using default quality`,Object.assign(Object.assign({},this.logContext),{quality:ls.HIGH})),e.quality=ls.HIGH):(this.log.debug(`using requested max quality`,Object.assign(Object.assign({},this.logContext),{quality:this.requestedMaxQuality})),e.quality=this.requestedMaxQuality)}this.emit(z.UpdateSettings,e)}},Om=class e extends Sm{static fromParticipantInfo(t,n,r,i){return new e(t,n.sid,n.identity,n.name,n.metadata,n.attributes,r,n.kind,n.dataTracks.map(e=>new Mp(Il.from(e),i,{publisherIdentity:n.identity})),n.clientProtocol,n.capabilities)}get logContext(){return Object.assign(Object.assign({},super.logContext),{remoteParticipantID:this.sid,remoteParticipant:this.identity})}constructor(e,t,n,r,i,a,o){let s=arguments.length>7&&arguments[7]!==void 0?arguments[7]:yn.STANDARD,c=arguments.length>8&&arguments[8]!==void 0?arguments[8]:[],l=arguments.length>9&&arguments[9]!==void 0?arguments[9]:0,u=arguments.length>10&&arguments[10]!==void 0?arguments[10]:[];super(t,n||``,r,i,a,o,s),this.signalClient=e,this.trackPublications=new Map,this.audioTrackPublications=new Map,this.videoTrackPublications=new Map,this.dataTracks=new Em(c.map(e=>[e.info.name,e])),this.volumeMap=new Map,this.clientProtocol=l,this.capabilities=u}addTrackPublication(e){super.addTrackPublication(e),e.on(z.UpdateSettings,t=>{this.log.debug(`send update settings`,Object.assign(Object.assign(Object.assign({},this.logContext),V(e)),{settings:t})),this.signalClient.sendUpdateTrackSettings(t)}),e.on(z.UpdateSubscription,e=>{e.participantTracks.forEach(e=>{e.participantSid=this.sid}),this.signalClient.sendUpdateSubscription(e)}),e.on(z.SubscriptionPermissionChanged,t=>{this.emit(L.TrackSubscriptionPermissionChanged,e,t)}),e.on(z.SubscriptionStatusChanged,t=>{this.emit(L.TrackSubscriptionStatusChanged,e,t)}),e.on(z.Subscribed,t=>{this.emit(L.TrackSubscribed,t,e)}),e.on(z.Unsubscribed,t=>{this.emit(L.TrackUnsubscribed,t,e)}),e.on(z.SubscriptionFailed,t=>{this.emit(L.TrackSubscriptionFailed,e.trackSid,t)})}getTrackPublication(e){let t=super.getTrackPublication(e);if(t)return t}getTrackPublicationByName(e){let t=super.getTrackPublicationByName(e);if(t)return t}setVolume(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:H.Source.Microphone;this.volumeMap.set(t,e);let n=this.getTrackPublication(t);n&&n.track&&n.track.setVolume(e)}getVolume(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:H.Source.Microphone,t=this.getTrackPublication(e);return t&&t.track?t.track.getVolume():this.volumeMap.get(e)}addSubscribedMediaTrack(e,t,n,r,i,a){let o=this.getTrackPublicationBySid(t);if(o||t.startsWith(`TR`)||this.trackPublications.forEach(t=>{!o&&e.kind===t.kind.toString()&&(o=t)}),!o){if(a===0){this.log.error(`could not find published track`,Object.assign(Object.assign({},this.logContext),{trackSid:t})),this.emit(L.TrackSubscriptionFailed,t);return}a===void 0&&(a=20),setTimeout(()=>{this.addSubscribedMediaTrack(e,t,n,r,i,a-1)},150);return}if(e.readyState===`ended`){this.log.error(`unable to subscribe because MediaStreamTrack is ended. Do not call MediaStreamTrack.stop()`,Object.assign(Object.assign({},this.logContext),V(o))),this.emit(L.TrackSubscriptionFailed,t);return}let s=e.kind===`video`,c;return c=s?new fl(e,t,r,i):new gm(e,t,r,this.audioContext,this.audioOutput),c.source=o.source,c.isMuted=o.isMuted,c.setMediaStream(n),c.start(),o.setTrack(c),this.volumeMap.has(o.source)&&Sc(c)&&vc(c)&&c.setVolume(this.volumeMap.get(o.source)),o}get hasMetadata(){return!!this.participantInfo}getTrackPublicationBySid(e){return this.trackPublications.get(e)}updateInfo(e){if(!super.updateInfo(e))return!1;let t=new Map,n=new Map;return e.tracks.forEach(e=>{let r=this.getTrackPublicationBySid(e.sid);if(r)r.updateInfo(e);else{let t=H.kindFromProto(e.type);if(!t)return;r=new Dm(t,e,this.signalClient.connectOptions?.autoSubscribe,{loggerContextCb:()=>this.logContext,loggerName:this.loggerOptions?.loggerName}),r.updateInfo(e),n.set(e.sid,r);let i=Array.from(this.trackPublications.values()).find(e=>e.source===r?.source);i&&r.source!==H.Source.Unknown&&this.log.debug(`received a second track publication for ${this.identity} with the same source: ${r.source}`,Object.assign(Object.assign({},this.logContext),{oldTrack:V(i),newTrack:V(r)})),this.addTrackPublication(r)}t.set(e.sid,r)}),this.trackPublications.forEach(e=>{t.has(e.trackSid)||(this.log.trace(`detected removed track on remote participant, unpublishing`,Object.assign(Object.assign({},this.logContext),V(e))),this.unpublishTrack(e.trackSid,!0))}),n.forEach(e=>{this.emit(L.TrackPublished,e)}),!0}unpublishTrack(e,t){let n=this.trackPublications.get(e);if(!n)return;let r=n.track;switch(r&&(r.stop(),n.setTrack(void 0)),this.trackPublications.delete(e),n.kind){case H.Kind.Audio:this.audioTrackPublications.delete(e);break;case H.Kind.Video:this.videoTrackPublications.delete(e)}t&&this.emit(L.TrackUnpublished,n)}setAudioOutput(e){return O(this,void 0,void 0,function*(){this.audioOutput=e;let t=[];this.audioTrackPublications.forEach(n=>{vc(n.track)&&Sc(n.track)&&t.push(n.track.setSinkId(e.deviceId??`default`))}),yield Promise.all(t)})}addRemoteDataTrack(e){this.dataTracks.set(e.info.name,e)}removeRemoteDataTrack(e){for(let n of this.dataTracks.entries()){var t=_(n,2);let r=t[0];e===t[1].info.sid&&this.dataTracks.delete(r)}}emit(e){var t=[...arguments].slice(1);return this.log.trace(`participant event`,Object.assign(Object.assign({},this.logContext),{event:e,args:t})),super.emit(e,...t)}},$;(function(e){e.Disconnected=`disconnected`,e.Connecting=`connecting`,e.Connected=`connected`,e.Reconnecting=`reconnecting`,e.SignalReconnecting=`signalReconnecting`})($||={});var km=4e3,Am=3e4,jm=`livekit-dummy-audio-el`,Mm;function Nm(){let e=document.createElement(`audio`);e.id=jm,e.autoplay=!0,e.hidden=!0;let t=nc();t.enabled=!0;let n=new MediaStream([t]);return e.srcObject=n,document.body.append(e),{element:e,stream:n,track:t,refCount:0}}var Pm=class e extends Yi.EventEmitter{get hasE2EESetup(){return this.e2eeManager!==void 0}constructor(t){var n,r,a;if(super(),n=this,this.state=$.Disconnected,this.activeSpeakers=[],this.isE2EEEnabled=!1,this.audioEnabled=!0,this.ownsAudioContext=!1,this.audioContextReleased=!1,this.audioContextMutex=new i,this.acquiredEmptyAudioTracks=new Set,this.e2eeStateMutex=new i,this.isVideoPlaybackBlocked=!1,this.log=E,this.statsLog=E,this.bufferedEvents=[],this.isResuming=!1,this.pendingTrackAddedCallbacks=new Map,this.connect=(e,t,n)=>O(this,void 0,void 0,function*(){if(!Es())throw Rs()?Error(`WebRTC isn't detected, have you called registerGlobals?`):Error(`LiveKit doesn't seem to be supported on this browser. Try to update your browser and make sure no browser extensions are disabling webRTC.`);let r=yield this.disconnectLock.lock();if(this.state===$.Connected)return this.log.info(`already connected to room ${this.name}`),r(),Promise.resolve();if(this.connectFuture)return r(),this.connectFuture.promise;this.setAndEmitConnectionState($.Connecting),this.regionUrlProvider?.getServerUrl().toString()!==zc(e)&&(this.regionUrl=void 0,this.regionUrlProvider=void 0),zs(new URL(e))&&(this.regionUrlProvider===void 0?this.regionUrlProvider=new wf(e,t):this.regionUrlProvider.updateToken(t),this.regionUrlProvider.fetchRegionSettings().then(e=>{var t;(t=this.regionUrlProvider)==null||t.setServerReportedRegions(e)}).catch(e=>{this.log.warn(`could not fetch region settings`,{error:e})}));let i=(a,o,s)=>O(this,void 0,void 0,function*(){this.abortController&&this.abortController.abort();let c=new AbortController;this.abortController=c,r?.();try{if(yield Cl.getInstance().getBackOffPromise(e),c.signal.aborted)throw j.cancelled(`Connection attempt aborted`);yield this.attemptConnection(s??e,t,n,c),this.abortController=void 0,a()}catch(t){if(this.regionUrlProvider&&t instanceof j&&vo(t)){let n=null;try{this.log.debug(`Fetching next region`),n=yield this.regionUrlProvider.getNextBestRegionUrl(this.abortController?.signal)}catch(e){if(e instanceof j&&(e.status===401||e.reason===A.Cancelled)){this.handleDisconnect(this.options.stopLocalTrackOnUnpublish),o(e);return}}[A.InternalError,A.ServerUnreachable,A.Timeout].includes(t.reason)&&(this.log.debug(`Adding failed connection attempt to back off`),Cl.getInstance().addFailedConnectionAttempt(e)),n&&!this.abortController?.signal.aborted?(this.log.info(`Initial connection failed with ConnectionError: ${t.message}. Retrying with another region: ${n}`),this.recreateEngine(!0),yield i(a,o,n)):(this.handleDisconnect(this.options.stopLocalTrackOnUnpublish,mc(t)),o(t))}else{let e=un.UNKNOWN_REASON;t instanceof j&&(e=mc(t)),this.handleDisconnect(this.options.stopLocalTrackOnUnpublish,e),o(t)}}}),a=this.regionUrl;return this.regionUrl=void 0,this.connectFuture=new G((e,t)=>{i(e,t,a)},()=>{this.clearConnectionFutures()}),this.connectFuture.promise}),this.connectSignal=(e,t,n,r,i,a)=>O(this,void 0,void 0,function*(){let o=yield n.join(e,t,{autoSubscribe:r.autoSubscribe,adaptiveStream:typeof i.adaptiveStream==`object`||i.adaptiveStream,disableIceLite:r.disableIceLite,subscriberAllowPause:r.subscriberAllowPause,clientInfoCapabilities:this.getClientInfoCapabilities(i),maxRetries:r.maxRetries,e2eeEnabled:!!this.e2eeManager,websocketTimeout:r.websocketTimeout},a.signal,!i.singlePeerConnection),s=o.joinResponse,c=o.serverInfo;if(this.serverInfo=c,!c.version)throw new xo(`unknown server version`);return c.version===`0.15.1`&&this.options.dynacast&&(this.log.debug(`disabling dynacast due to server version`),i.dynacast=!1),s}),this.applyJoinResponse=e=>{let t=e.participant;if(this.localParticipant.sid=t.sid,this.localParticipant.identity=t.identity,this.localParticipant.setEnabledPublishCodecs(e.enabledPublishCodecs),this.e2eeManager)try{this.e2eeManager.setSifTrailer(e.sifTrailer)}catch(e){this.log.error(e instanceof Error?e.message:`Could not set SifTrailer`,{error:e})}this.handleParticipantUpdates([t,...e.otherParticipants]),e.room&&this.handleRoomUpdate(e.room)},this.attemptConnection=(e,t,n,r)=>O(this,void 0,void 0,function*(){this.state===$.Reconnecting||this.isResuming||this.engine?.pendingReconnect?(this.log.info(`Reconnection attempt replaced by new connection attempt`),this.recreateEngine(!0)):this.maybeCreateEngine(),this.regionUrlProvider?.isCloud()&&this.engine.setRegionStrategy(this.createRegionStrategy()),this.acquireAudioContext(!0).catch(e=>this.log.warn(`Could not acquire audio context`,Object.assign(Object.assign({},this.logContext),{error:e}))),this.connOptions=Object.assign(Object.assign({},gd),n),this.connOptions.rtcConfig&&(this.engine.rtcConfig=this.connOptions.rtcConfig),this.connOptions.peerConnectionTimeout&&(this.engine.peerConnectionTimeout=this.connOptions.peerConnectionTimeout);try{let n=yield this.connectSignal(e,t,this.engine,this.connOptions,this.options,r);this.applyJoinResponse(n),this.setupLocalParticipantEvents(),this.emit(I.SignalConnected)}catch(e){yield this.engine.close(),this.recreateEngine();let t=r.signal.aborted?j.cancelled(`Signal connection aborted`):j.serverUnreachable(`could not establish signal connection`);throw e instanceof Error&&(t.message=`${t.message}: ${e.message}`),e instanceof j&&(t.reason=e.reason,t.status=e.status),this.log.debug(`error trying to establish signal connection`,{error:e}),t}if(r.signal.aborted)throw yield this.engine.close(),this.recreateEngine(),j.cancelled(`Connection attempt aborted`);try{yield this.engine.waitForPCInitialConnection(this.connOptions.peerConnectionTimeout,r)}catch(e){throw yield this.engine.close(),this.recreateEngine(),e}W()&&this.options.disconnectOnPageLeave&&(window.addEventListener(`pagehide`,this.onPageLeave),window.addEventListener(`beforeunload`,this.onPageLeave)),W()&&window.addEventListener(`freeze`,this.onPageLeave),this.setAndEmitConnectionState($.Connected),this.emit(I.Connected),Cl.getInstance().resetFailedConnectionAttempts(e),this.registerConnectionReconcile(),this.regionUrlProvider&&this.regionUrlProvider.notifyConnected()}),this.disconnect=function(){return O(n,[...arguments],void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;return function*(){var n,r,i;let a=yield e.disconnectLock.lock();try{if(e.state===$.Disconnected){e.log.debug(`already disconnected`);return}if(e.log.info(`disconnect from room`),e.state===$.Connecting||e.state===$.Reconnecting||e.isResuming){let t=`Abort connection attempt due to user initiated disconnect`;e.log.warn(t),(n=e.abortController)==null||n.abort(t),(i=(r=e.connectFuture)?.reject)==null||i.call(r,j.cancelled(`Client initiated disconnect`)),e.connectFuture=void 0}e.engine&&(e.engine.client.isDisconnected||(yield e.engine.client.sendLeave()),yield e.engine.close()),e.handleDisconnect(t,un.CLIENT_INITIATED),e.engine=void 0}finally{a()}}()})},this.onPageLeave=()=>O(this,void 0,void 0,function*(){this.log.info(`Page leave detected, disconnecting`),yield this.disconnect()}),this.startAudio=()=>O(this,void 0,void 0,function*(){let e=[],t=k();t&&t.os===`iOS`&&!this.audioContextReleased&&e.push(this.acquireDummyAudioElement()),this.remoteParticipants.forEach(t=>{t.audioTrackPublications.forEach(t=>{t.track&&t.track.attachedElements.forEach(t=>{e.push(t)})})});try{yield Promise.all([...this.audioContextReleased?[]:[this.acquireAudioContext()],...e.map(e=>(this.options.webAudioMix||(e.muted=!1),e.play()))]),this.handleAudioPlaybackStarted()}catch(e){throw this.handleAudioPlaybackFailed(e),e}}),this.startVideo=()=>O(this,void 0,void 0,function*(){let e=[];for(let t of this.remoteParticipants.values())t.videoTrackPublications.forEach(t=>{var n;(n=t.track)==null||n.attachedElements.forEach(t=>{e.includes(t)||e.push(t)})});yield Promise.all(e.map(e=>e.play())).then(()=>{this.handleVideoPlaybackStarted()}).catch(e=>{e.name===`NotAllowedError`?this.handleVideoPlaybackFailed():this.log.warn("Resuming video playback failed, make sure you call `startVideo` directly in a user gesture handler")})}),this.handleRestarting=()=>{this.clearConnectionReconcile(),this.isResuming=!1;for(let e of this.remoteParticipants.values())this.handleParticipantDisconnected(e.identity,e);this.setAndEmitConnectionState($.Reconnecting)&&this.emit(I.Reconnecting)},this.handleRestarted=()=>{this.outgoingDataTrackManager.sfuWillRepublishTracks(),this.incomingDataTrackManager.resendSubscriptionUpdates()},this.handleSignalRestarted=e=>O(this,void 0,void 0,function*(){this.log.debug(`signal reconnected to server, region ${e.serverRegion}`,{region:e.serverRegion}),this.bufferedEvents=[],this.applyJoinResponse(e);try{yield this.localParticipant.republishAllTracks(void 0,!0)}catch(e){this.log.error(`error trying to re-publish tracks after reconnection`,{error:e})}try{yield this.engine.waitForRestarted(),this.log.debug(`fully reconnected to server`,{region:e.serverRegion})}catch{return}this.setAndEmitConnectionState($.Connected),this.emit(I.Reconnected),this.registerConnectionReconcile(),this.emitBufferedEvents()}),this.handleParticipantUpdates=e=>{for(let t of e){if(t.identity===this.localParticipant.identity){this.localParticipant.updateInfo(t);continue}t.identity===``&&(t.identity=this.sidToIdentity.get(t.sid)??``);let e=this.remoteParticipants.get(t.identity);t.state===vn.DISCONNECTED?this.handleParticipantDisconnected(t.identity,e,t.disconnectReason===un.UNKNOWN_REASON?void 0:t.disconnectReason):this.getOrCreateParticipant(t.identity,t)}let t=new Map(e.filter(e=>e.identity!==this.localParticipant.identity).map(e=>[e.identity,e.dataTracks.map(e=>Il.from(e))]));this.incomingDataTrackManager.receiveSfuPublicationUpdates(t)},this.handleActiveSpeakersUpdate=e=>{let t=[],n={};e.forEach(e=>{if(n[e.sid]=!0,e.sid===this.localParticipant.sid)this.localParticipant.audioLevel=e.level,this.localParticipant.setIsSpeaking(!0),t.push(this.localParticipant);else{let n=this.getRemoteParticipantBySid(e.sid);n&&(n.audioLevel=e.level,n.setIsSpeaking(!0),t.push(n))}}),n[this.localParticipant.sid]||(this.localParticipant.audioLevel=0,this.localParticipant.setIsSpeaking(!1)),this.remoteParticipants.forEach(e=>{n[e.sid]||(e.audioLevel=0,e.setIsSpeaking(!1))}),this.activeSpeakers=t,this.emitWhenConnected(I.ActiveSpeakersChanged,t)},this.handleSpeakersChanged=e=>{let t=new Map;this.activeSpeakers.forEach(e=>{let n=this.remoteParticipants.get(e.identity);n&&n.sid!==e.sid||t.set(e.sid,e)}),e.forEach(e=>{let n=this.getRemoteParticipantBySid(e.sid);e.sid===this.localParticipant.sid&&(n=this.localParticipant),n&&(n.audioLevel=e.level,n.setIsSpeaking(e.active),e.active?t.set(e.sid,n):t.delete(e.sid))});let n=Array.from(t.values());n.sort((e,t)=>t.audioLevel-e.audioLevel),this.activeSpeakers=n,this.emitWhenConnected(I.ActiveSpeakersChanged,n)},this.handleStreamStateUpdate=e=>{e.streamStates.forEach(e=>{let t=this.getRemoteParticipantBySid(e.participantSid);if(!t)return;let n=t.getTrackPublicationBySid(e.trackSid);if(!n||!n.track)return;let r=H.streamStateFromProto(e.state),i=n.track.streamState;n.track.setStreamState(r),r!==i&&(t.emit(L.TrackStreamStateChanged,n,n.track.streamState),this.emitWhenConnected(I.TrackStreamStateChanged,n,n.track.streamState,t))})},this.handleSubscriptionPermissionUpdate=e=>{let t=this.getRemoteParticipantBySid(e.participantSid);if(!t)return;let n=t.getTrackPublicationBySid(e.trackSid);n&&n.setAllowed(e.allowed)},this.handleSubscriptionError=e=>{this.cancelPendingTrackAdded(e.trackSid);let t=Array.from(this.remoteParticipants.values()).find(t=>t.trackPublications.has(e.trackSid));if(!t)return;let n=t.getTrackPublicationBySid(e.trackSid);n&&n.setSubscriptionError(e.err)},this.handleDataPacket=(e,t)=>{let n=this.remoteParticipants.get(e.participantIdentity);if(e.value.case===`user`)this.handleUserPacket(n,e.value.value,e.kind,t,e.participantIdentity);else if(e.value.case===`transcription`)this.handleTranscription(n,e.value.value);else if(e.value.case===`sipDtmf`)this.handleSipDtmf(n,e.value.value);else if(e.value.case===`chatMessage`)this.handleChatMessage(n,e.value.value);else if(e.value.case===`metrics`)this.handleMetrics(e.value.value,n);else if(e.value.case===`streamHeader`||e.value.case===`streamChunk`||e.value.case===`streamTrailer`)this.handleDataStream(e,t);else if(e.value.case===`rpcRequest`){let t=e.value.value;this.rpcServerManager.handleIncomingRpcRequest(e.participantIdentity,t)}else if(e.value.case===`rpcResponse`){let t=e.value.value;switch(t.value.case){case`payload`:this.rpcClientManager.handleIncomingRpcResponseSuccess(t.requestId,t.value.value);break;case`error`:this.rpcClientManager.handleIncomingRpcResponseFailure(t.requestId,Z.fromProto(t.value.value));break;default:this.log.warn(`Unknown rpcResponse.value.case: ${t.value.case}`,this.logContext)}}else e.value.case===`rpcAck`&&this.rpcClientManager.handleIncomingRpcAck(e.value.value.requestId)},this.handleUserPacket=(e,t,n,r,i)=>{this.emit(I.DataReceived,t.payload,e,n,t.topic,r,i),e?.emit(L.DataReceived,t.payload,n,r)},this.handleSipDtmf=(e,t)=>{this.emit(I.SipDTMFReceived,t,e),e?.emit(L.SipDTMFReceived,t)},this.handleTranscription=(e,t)=>{let n=t.transcribedParticipantIdentity===this.localParticipant.identity?this.localParticipant:this.getParticipantByIdentity(t.transcribedParticipantIdentity),r=n?.trackPublications.get(t.trackId),i=fc(t,this.transcriptionReceivedTimes);r?.emit(z.TranscriptionReceived,i),n?.emit(L.TranscriptionReceived,i,r),this.emit(I.TranscriptionReceived,i,n,r)},this.handleChatMessage=(e,t)=>{let n=pc(t);this.emit(I.ChatMessage,n,e)},this.handleMetrics=(e,t)=>{this.emit(I.MetricsReceived,e,t)},this.handleDataStream=(e,t)=>{this.incomingDataStreamManager.handleDataStreamPacket(e,t)},this.bufferedSegments=new Map,this.handleAudioPlaybackStarted=()=>{this.canPlaybackAudio||(this.audioEnabled=!0,this.emit(I.AudioPlaybackStatusChanged,!0))},this.handleAudioPlaybackFailed=e=>{this.log.warn(`could not playback audio`,{error:e}),this.canPlaybackAudio&&(this.audioEnabled=!1,this.emit(I.AudioPlaybackStatusChanged,!1))},this.handleVideoPlaybackStarted=()=>{this.isVideoPlaybackBlocked&&(this.isVideoPlaybackBlocked=!1,this.emit(I.VideoPlaybackStatusChanged,!0))},this.handleVideoPlaybackFailed=()=>{this.isVideoPlaybackBlocked||(this.isVideoPlaybackBlocked=!0,this.emit(I.VideoPlaybackStatusChanged,!1))},this.handleDeviceChange=()=>O(this,void 0,void 0,function*(){k()?.os!==`iOS`&&(yield this.selectDefaultDevices()),this.emit(I.MediaDevicesChanged)}),this.handleRoomUpdate=e=>{let t=this.roomInfo;this.roomInfo=e,t&&t.metadata!==e.metadata&&this.emitWhenConnected(I.RoomMetadataChanged,e.metadata),t?.activeRecording!==e.activeRecording&&this.emitWhenConnected(I.RecordingStatusChanged,e.activeRecording)},this.handleConnectionQualityUpdate=e=>{e.updates.forEach(e=>{if(e.participantSid===this.localParticipant.sid){this.localParticipant.setConnectionQuality(e.quality);return}let t=this.getRemoteParticipantBySid(e.participantSid);t&&t.setConnectionQuality(e.quality)})},this.getRemoteParticipantClientProtocol=e=>this.remoteParticipants.get(e)?.clientProtocol??0,this.getRemoteParticipantCapabilities=e=>this.remoteParticipants.get(e)?.capabilities??[],this.getAllRemoteParticipantIdentities=()=>Array.from(this.remoteParticipants.keys()),this.logWebRTCStats=()=>O(this,void 0,void 0,function*(){let e=this.engine?.pcManager;if(e)try{let t=_(yield Promise.all([e.publisher.getStats(),e.subscriber?.getStats()]),2),n=t[0],r=t[1],i=n&&No(n),a=r&&No(r);this.statsLog.info(`webrtc stats`,{publisher:i?.connection,subscriber:a?.connection,inbound:[...i?.inbound??[],...a?.inbound??[]],outbound:i?.outbound})}catch(e){this.statsLog.debug(`could not collect webrtc stats`,{error:e})}}),this.onLocalParticipantMetadataChanged=e=>{this.emit(I.ParticipantMetadataChanged,e,this.localParticipant)},this.onLocalParticipantNameChanged=e=>{this.emit(I.ParticipantNameChanged,e,this.localParticipant)},this.onLocalAttributesChanged=e=>{this.emit(I.ParticipantAttributesChanged,e,this.localParticipant)},this.onLocalTrackMuted=e=>{this.emit(I.TrackMuted,e,this.localParticipant)},this.onLocalTrackUnmuted=e=>{this.emit(I.TrackUnmuted,e,this.localParticipant)},this.onTrackProcessorUpdate=e=>{var t;(t=e?.onPublish)==null||t.call(e,this)},this.onLocalTrackPublished=e=>O(this,void 0,void 0,function*(){var t,n,r,i;(t=e.track)==null||t.on(z.TrackProcessorUpdate,this.onTrackProcessorUpdate),(n=e.track)==null||n.on(z.Restarted,this.onLocalTrackRestarted),(i=(r=e.track?.getProcessor())?.onPublish)==null||i.call(r,this),this.emit(I.LocalTrackPublished,e,this.localParticipant),xc(e.track)&&(yield e.track.checkForSilence())&&this.emit(I.LocalAudioSilenceDetected,e);let a=yield e.track?.getDeviceId(!1),o=Xo(e.source);o&&a&&a!==this.localParticipant.activeDeviceMap.get(o)&&(this.localParticipant.activeDeviceMap.set(o,a),this.emit(I.ActiveDeviceChanged,o,a))}),this.onLocalTrackUnpublished=e=>{var t,n;(t=e.track)==null||t.off(z.TrackProcessorUpdate,this.onTrackProcessorUpdate),(n=e.track)==null||n.off(z.Restarted,this.onLocalTrackRestarted),this.emit(I.LocalTrackUnpublished,e,this.localParticipant)},this.onLocalTrackRestarted=e=>O(this,void 0,void 0,function*(){let t=yield e.getDeviceId(!1),n=Xo(e.source);n&&t&&t!==this.localParticipant.activeDeviceMap.get(n)&&(this.log.debug(`local track restarted, setting ${n} ${t} active`),this.localParticipant.activeDeviceMap.set(n,t),this.emit(I.ActiveDeviceChanged,n,t))}),this.onLocalConnectionQualityChanged=e=>{this.emit(I.ConnectionQualityChanged,e,this.localParticipant)},this.onMediaDevicesError=(e,t)=>{this.emit(I.MediaDevicesError,e,t)},this.onLocalParticipantPermissionsChanged=e=>{this.emit(I.ParticipantPermissionsChanged,e,this.localParticipant)},this.onLocalChatMessageSent=e=>{this.emit(I.ChatMessage,e,this.localParticipant)},this.setMaxListeners(100),this.remoteParticipants=new Map,this.sidToIdentity=new Map,this.options=Object.assign(Object.assign({},hd),t),this.log=D(this.options.loggerName??T.Room,()=>this.logContext),this.statsLog=D(T.Stats,()=>this.logContext),this.transcriptionReceivedTimes=new Map,this.options.audioCaptureDefaults=Object.assign(Object.assign({},pd),t?.audioCaptureDefaults),this.options.videoCaptureDefaults=Object.assign(Object.assign({},md),t?.videoCaptureDefaults),this.options.publishDefaults=Object.assign(Object.assign({},fd),t?.publishDefaults),this.maybeCreateEngine(),this.incomingDataStreamManager=new Ff(this.options.dataStream?.maxPayloadByteLength),this.outgoingDataStreamManager=new Zf(this.engine,this.log,this.getRemoteParticipantClientProtocol,this.getRemoteParticipantCapabilities,this.getAllRemoteParticipantIdentities),this.incomingDataTrackManager=new Gp({e2eeManager:this.e2eeManager}),this.incomingDataTrackManager.on(`sfuUpdateSubscription`,e=>{this.engine.client.sendUpdateDataSubscription(e.sid,e.subscribe)}).on(`trackPublished`,e=>{var t;e.track.publisherIdentity!==this.localParticipant.identity&&(this.emit(I.DataTrackPublished,e.track),(t=this.remoteParticipants.get(e.track.publisherIdentity))==null||t.addRemoteDataTrack(e.track))}).on(`trackUnpublished`,e=>{var t;e.publisherIdentity!==this.localParticipant.identity&&(this.emit(I.DataTrackUnpublished,e.sid),(t=this.remoteParticipants.get(e.publisherIdentity))==null||t.removeRemoteDataTrack(e.sid))}),this.outgoingDataTrackManager=new om({e2eeManager:this.e2eeManager}),this.outgoingDataTrackManager.on(`sfuPublishRequest`,e=>{this.engine.client.sendPublishDataTrackRequest(e.handle,e.name,e.usesE2ee)}).on(`sfuUnpublishRequest`,e=>{this.engine.client.sendUnPublishDataTrackRequest(e.handle)}).on(`trackPublished`,e=>{this.emit(I.LocalDataTrackPublished,e.track)}).on(`trackUnpublished`,e=>{this.emit(I.LocalDataTrackUnpublished,e.sid)}).on(`packetAvailable`,e=>{let t=e.handle,n=e.bytes;this.engine.sendDataTrackFrame(n).finally(()=>this.outgoingDataTrackManager.handlePacketSendComplete(t))}),this.registerRpcDataStreamHandler(),this.rpcClientManager=new mm(this.log,this.outgoingDataStreamManager,this.getRemoteParticipantClientProtocol,()=>this.engine?.serverVersion),this.rpcClientManager.on(`sendDataPacket`,e=>{let t=e.packet;var n;(n=this.engine)==null||n.sendDataPacket(t,q.RELIABLE)}),this.rpcServerManager=new hm(this.log,this.outgoingDataStreamManager,this.getRemoteParticipantClientProtocol),this.rpcServerManager.on(`sendDataPacket`,e=>{let t=e.packet;var n;(n=this.engine)==null||n.sendDataPacket(t,q.RELIABLE)}),this.disconnectLock=new i,this.localParticipant=new wm(``,``,this.engine,this.options,this.outgoingDataStreamManager,this.outgoingDataTrackManager,this.rpcClientManager,this.rpcServerManager),this.setupFrameMetadata(),(this.options.e2ee||this.options.encryption)&&this.setupE2EE(),this.engine.e2eeManager=this.e2eeManager,this.incomingDataTrackManager.updateE2eeManager(this.e2eeManager??null),this.outgoingDataTrackManager.updateE2eeManager(this.e2eeManager??null),this.options.videoCaptureDefaults.deviceId&&this.localParticipant.activeDeviceMap.set(`videoinput`,ac(this.options.videoCaptureDefaults.deviceId)),this.options.audioCaptureDefaults.deviceId&&this.localParticipant.activeDeviceMap.set(`audioinput`,ac(this.options.audioCaptureDefaults.deviceId)),this.options.audioOutput?.deviceId&&this.switchActiveDevice(`audiooutput`,ac(this.options.audioOutput.deviceId)).catch(e=>this.log.warn(`Could not set audio output: ${e.message}`)),W()){let t=new AbortController,n;if(e.cleanupRegistry){let r=new WeakRef(this);n=()=>{let e=r.deref();e&&e.handleDeviceChange()},e.cleanupRegistry.register(this,()=>{t.abort()})}else n=this.handleDeviceChange;(a=(r=navigator.mediaDevices)?.addEventListener)==null||a.call(r,`devicechange`,n,{signal:t.signal})}}registerTextStreamHandler(e,t){return this.incomingDataStreamManager.registerTextStreamHandler(e,t)}unregisterTextStreamHandler(e){return this.incomingDataStreamManager.unregisterTextStreamHandler(e)}registerByteStreamHandler(e,t){return this.incomingDataStreamManager.registerByteStreamHandler(e,t)}unregisterByteStreamHandler(e){return this.incomingDataStreamManager.unregisterByteStreamHandler(e)}registerRpcMethod(e,t){this.rpcServerManager.registerRpcMethod(e,t)}unregisterRpcMethod(e){this.rpcServerManager.unregisterRpcMethod(e)}setE2EEEnabled(e){return O(this,void 0,void 0,function*(){let t=yield this.e2eeStateMutex.lock();try{if(this.e2eeManager)this.isE2EEEnabled!==e&&(yield this.localParticipant.setE2EEEnabled(e),this.localParticipant.identity!==``&&this.e2eeManager.setParticipantCryptorEnabled(e,this.localParticipant.identity));else throw Error(`e2ee not configured, please set e2ee settings within the room options`)}finally{t()}})}setupE2EE(){var e,t;let n=!!this.options.encryption,r=this.options.encryption||this.options.e2ee;r&&(`e2eeManager`in r?(this.e2eeManager=r.e2eeManager,this.e2eeManager.isDataChannelEncryptionEnabled=n):this.e2eeManager=new _l(r,n),this.e2eeManager.on(Jc.ParticipantEncryptionStatusChanged,(e,t)=>{Tc(t)&&(this.isE2EEEnabled=e),this.emit(I.ParticipantEncryptionStatusChanged,e,t)}),this.e2eeManager.on(Jc.EncryptionError,(e,t)=>{let n=t?this.getParticipantByIdentity(t):void 0;this.emit(I.EncryptionError,e,n)}),(e=this.e2eeManager)==null||e.setup(this),(t=this.e2eeManager)==null||t.setupEngine(this.engine))}setupFrameMetadata(){let e=this.options.frameMetadata??this.options.packetTrailer;this.frameMetadataManager=new bl(e),this.frameMetadataManager.setup(this)}get logContext(){return{room:this.name,roomID:this.roomInfo?.sid,participant:this.localParticipant?.identity,participantID:this.localParticipant?.sid}}get isRecording(){return this.roomInfo?.activeRecording??!1}getSid(){return this.state===$.Disconnected?co.resolve(``):this.roomInfo&&this.roomInfo.sid!==``?co.resolve(this.roomInfo.sid):new co((e,t)=>{let n=t=>{t.sid!==``&&(this.engine.off(R.RoomUpdate,n),e(t.sid))};this.engine.on(R.RoomUpdate,n),this.once(I.Disconnected,()=>{this.engine.off(R.RoomUpdate,n),t(new M(`Room disconnected before room server id was available`))})})}get name(){return this.roomInfo?.name??``}get metadata(){return this.roomInfo?.metadata}get numParticipants(){return this.roomInfo?.numParticipants??0}get numPublishers(){return this.roomInfo?.numPublishers??0}maybeCreateEngine(){(!this.engine||!this.engine.isNewlyCreated&&this.engine.isClosed)&&(this.engine=new yf(this.options),this.engine.e2eeManager=this.e2eeManager,this.engine.on(R.ParticipantUpdate,this.handleParticipantUpdates).on(R.RoomUpdate,this.handleRoomUpdate).on(R.SpeakersChanged,this.handleSpeakersChanged).on(R.StreamStateChanged,this.handleStreamStateUpdate).on(R.ConnectionQualityUpdate,this.handleConnectionQualityUpdate).on(R.SubscriptionError,this.handleSubscriptionError).on(R.SubscriptionPermissionUpdate,this.handleSubscriptionPermissionUpdate).on(R.MediaTrackAdded,(e,t,n)=>{this.onTrackAdded(e,t,n)}).on(R.Disconnected,e=>{this.handleDisconnect(this.options.stopLocalTrackOnUnpublish,e)}).on(R.ActiveSpeakersUpdate,this.handleActiveSpeakersUpdate).on(R.DataPacketReceived,this.handleDataPacket).on(R.Resuming,()=>{this.clearConnectionReconcile(),this.isResuming=!0,this.log.debug(`Resuming signal connection`),this.setAndEmitConnectionState($.SignalReconnecting)&&this.emit(I.SignalReconnecting)}).on(R.Resumed,()=>{this.registerConnectionReconcile(),this.isResuming=!1,this.log.debug(`Resumed signal connection`),this.updateSubscriptions(),this.setAndEmitConnectionState($.Connected)&&this.emit(I.Reconnected),this.emitBufferedEvents()}).on(R.SignalResumed,()=>{(this.state===$.Reconnecting||this.isResuming)&&this.sendSyncState(),this.emitBufferedEvents()}).on(R.Restarting,this.handleRestarting).on(R.Restarted,this.handleRestarted).on(R.SignalRestarted,this.handleSignalRestarted).on(R.Offline,()=>{this.setAndEmitConnectionState($.Reconnecting)&&this.emit(I.Reconnecting)}).on(R.DCBufferStatusChanged,(e,t)=>{this.emit(I.DCBufferStatusChanged,e,t)}).on(R.LocalTrackSubscribed,e=>{this.handleLocalTrackSubscribed(e)}).on(R.RoomMoved,e=>{this.log.debug(`room moved`,e),e.room&&this.handleRoomUpdate(e.room),this.remoteParticipants.forEach((e,t)=>{this.handleParticipantDisconnected(t,e)}),this.emit(I.Moved,e.room.name),e.participant?this.handleParticipantUpdates([e.participant,...e.otherParticipants]):this.handleParticipantUpdates(e.otherParticipants)}).on(R.PublishDataTrackResponse,e=>{e.info?this.outgoingDataTrackManager.receivedSfuPublishResponse(e.info.pubHandle,{type:`ok`,data:{sid:e.info.sid,pubHandle:e.info.pubHandle,name:e.info.name,usesE2ee:e.info.encryption!==S.NONE}}):this.log.warn(`received PublishDataTrackResponse, but event.info was ${e.info}, so skipping.`)}).on(R.UnPublishDataTrackResponse,e=>{e.info?this.outgoingDataTrackManager.receivedSfuUnpublishResponse(e.info.pubHandle):this.log.warn(`received UnPublishDataTrackResponse, but event.info was ${e.info}, so skipping.`)}).on(R.DataTrackSubscriberHandles,e=>{let t=new Map(Object.entries(e.subHandles).map(e=>{let t=_(e,2),n=t[0],r=t[1];return[parseInt(n,10),r.trackSid]}));this.incomingDataTrackManager.receivedSfuSubscriberHandles(t)}).on(R.DataTrackPacketReceived,e=>{try{this.incomingDataTrackManager.packetReceived(e)}catch(e){throw e}}).on(R.Joined,e=>{let t=new Map(e.otherParticipants.map(e=>[e.identity,e.dataTracks.map(e=>Il.from(e))]));this.incomingDataTrackManager.receiveSfuPublicationUpdates(t)}).on(R.TokenRefreshed,e=>{var t;(t=this.regionUrlProvider)==null||t.updateToken(e)}).on(R.ServerRegionsReported,e=>{var t;(t=this.regionUrlProvider)==null||t.setServerReportedRegions({regionSettings:e,updatedAtInMs:Date.now(),maxAgeInMs:Sf})}).on(R.RequestSubscribedCodecRefresh,()=>{for(let e of this.localParticipant.videoTrackPublications.values())bc(e.track)&&e.track.refreshSubscribedCodecs()}),this.localParticipant&&this.localParticipant.setupEngine(this.engine),this.e2eeManager&&this.e2eeManager.setupEngine(this.engine),this.outgoingDataStreamManager&&this.outgoingDataStreamManager.setupEngine(this.engine))}createRegionStrategy(){return{getNextUrl:e=>O(this,void 0,void 0,function*(){return this.regionUrlProvider?this.regionUrlProvider.getNextBestRegionUrl(e):null}),resetAttempts:()=>this.regionUrlProvider?.resetAttempts()}}static getLocalDevices(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return Tl.getInstance().getDevices(e,t)}prepareConnection(e,t){return O(this,void 0,void 0,function*(){if(this.state===$.Disconnected){this.log.debug(`prepareConnection to ${e}`);try{if(zs(new URL(e))&&t){this.regionUrlProvider=new wf(e,t);let n=yield this.regionUrlProvider.getNextBestRegionUrl();n&&this.state===$.Disconnected&&(this.regionUrl=n,yield fetch(dc(n),{method:`HEAD`}),this.log.debug(`prepared connection to ${n}`))}else yield fetch(dc(e),{method:`HEAD`})}catch(e){this.log.warn(`could not prepare connection`,{error:e})}}})}getParticipantByIdentity(e){return this.localParticipant.identity===e?this.localParticipant:this.remoteParticipants.get(e)}clearConnectionFutures(){this.connectFuture=void 0}simulateScenario(e,t){return O(this,void 0,void 0,function*(){let n=()=>O(this,void 0,void 0,function*(){}),r;switch(e){case`signal-reconnect`:let i=typeof t==`number`?t:0;yield this.engine.client.handleOnClose(`simulate disconnect`,void 0,i);break;case`fail-on-v1-path`:this.engine.failNextV1Path();break;case`speaker`:r=new ui({scenario:{case:`speakerUpdate`,value:3}});break;case`node-failure`:r=new ui({scenario:{case:`nodeFailure`,value:!0}});break;case`server-leave`:r=new ui({scenario:{case:`serverLeave`,value:!0}});break;case`migration`:r=new ui({scenario:{case:`migration`,value:!0}});break;case`resume-reconnect`:this.engine.failNext(),yield this.engine.client.handleOnClose(`simulate resume-disconnect`);break;case`disconnect-signal-on-resume`:n=()=>O(this,void 0,void 0,function*(){yield this.engine.client.handleOnClose(`simulate resume-disconnect`)}),r=new ui({scenario:{case:`disconnectSignalOnResume`,value:!0}});break;case`disconnect-signal-on-resume-no-messages`:n=()=>O(this,void 0,void 0,function*(){yield this.engine.client.handleOnClose(`simulate resume-disconnect`)}),r=new ui({scenario:{case:`disconnectSignalOnResumeNoMessages`,value:!0}});break;case`full-reconnect`:this.engine.fullReconnectOnNext=!0,yield this.engine.client.handleOnClose(`simulate full-reconnect`);break;case`force-tcp`:case`force-tls`:r=new ui({scenario:{case:`switchCandidateProtocol`,value:e===`force-tls`?2:1}}),n=()=>O(this,void 0,void 0,function*(){let e=this.engine.client.onLeave;e&&e(new Hr({reason:un.CLIENT_INITIATED,action:Ur.RECONNECT}))});break;case`subscriber-bandwidth`:if(t===void 0||typeof t!=`number`)throw Error(`subscriber-bandwidth requires a number as argument`);r=new ui({scenario:{case:`subscriberBandwidth`,value:gc(t)}});break;case`leave-full-reconnect`:r=new ui({scenario:{case:`leaveRequestFullReconnect`,value:!0}})}r&&(yield this.engine.client.sendSimulateScenario(r),yield n())})}acquireDummyAudioElement(){Mm||=Nm();let e=Mm;if(this.releaseDummyAudioElement)return e.element;e.refCount+=1;let t=()=>{e.element.srcObject=document.hidden?null:e.stream,document.hidden||(this.log.debug(`page visible again, triggering startAudio to resume playback and update playback status`),this.startAudio().catch(e=>this.log.warn(`Could not restart audio on page becoming visible`,Object.assign(Object.assign({},this.logContext),{error:e}))))};return document.addEventListener(`visibilitychange`,t),this.releaseDummyAudioElement=()=>{this.releaseDummyAudioElement=void 0,document.removeEventListener(`visibilitychange`,t),--e.refCount,!(e.refCount>0)&&(e.element.srcObject=null,e.element.remove(),Mm=void 0,rc(e.track).catch(e=>this.log.warn(`Could not release the dummy audio element track`,Object.assign(Object.assign({},this.logContext),{error:e}))))},e.element}acquireEmptyAudioStreamTrack(){let e=nc();return this.acquiredEmptyAudioTracks.add(e),e}releaseAcquiredEmptyAudioTrack(e){this.acquiredEmptyAudioTracks.delete(e)&&rc(e).catch(e=>this.log.warn(`Could not release empty audio stream track`,Object.assign(Object.assign({},this.logContext),{error:e})))}releaseAcquiredEmptyAudioTracks(){for(let e of this.acquiredEmptyAudioTracks)this.releaseAcquiredEmptyAudioTrack(e)}get canPlaybackAudio(){return this.audioEnabled}get canPlaybackVideo(){return!this.isVideoPlaybackBlocked}getActiveDevice(e){return this.localParticipant.activeDeviceMap.get(e)}switchActiveDevice(e,t){return O(this,arguments,void 0,function(e,t){var n=this;let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;return function*(){var i,a;let o=!0,s=!1,c=r?{exact:t}:t;if(e===`audioinput`){s=n.localParticipant.audioTrackPublications.size===0;let t=n.getActiveDevice(e)??n.options.audioCaptureDefaults.deviceId;n.options.audioCaptureDefaults.deviceId=c;let r=Array.from(n.localParticipant.audioTrackPublications.values()).filter(e=>e.source===H.Source.Microphone);try{o=(yield Promise.all(r.map(e=>e.audioTrack?.setDeviceId(c)))).every(e=>e===!0)}catch(e){throw n.options.audioCaptureDefaults.deviceId=t,e}let i=r.some(e=>e.track?.isMuted??!1);o&&i&&(s=!0)}else if(e===`videoinput`){s=n.localParticipant.videoTrackPublications.size===0;let t=n.getActiveDevice(e)??n.options.videoCaptureDefaults.deviceId;n.options.videoCaptureDefaults.deviceId=c;let r=Array.from(n.localParticipant.videoTrackPublications.values()).filter(e=>e.source===H.Source.Camera);try{o=(yield Promise.all(r.map(e=>e.videoTrack?.setDeviceId(c)))).every(e=>e===!0)}catch(e){throw n.options.videoCaptureDefaults.deviceId=t,e}let i=r.some(e=>e.track?.isMuted??!1);o&&i&&(s=!0)}else if(e===`audiooutput`){if(s=!0,!Ts()&&!n.options.webAudioMix||n.options.webAudioMix&&n.audioContext&&!(`setSinkId`in n.audioContext))throw Error(`cannot switch audio output, the current browser does not support it`);n.options.webAudioMix&&(t=(yield Tl.getInstance().normalizeDeviceId(`audiooutput`,t))??``),(a=n.options).audioOutput??(a.audioOutput={});let r=n.getActiveDevice(e)??n.options.audioOutput.deviceId;n.options.audioOutput.deviceId=t;try{n.options.webAudioMix&&((i=n.audioContext)==null||i.setSinkId(t)),yield Promise.all(Array.from(n.remoteParticipants.values()).map(e=>e.setAudioOutput({deviceId:t})))}catch(e){throw n.options.audioOutput.deviceId=r,e}}return s&&(n.localParticipant.activeDeviceMap.set(e,t),n.emit(I.ActiveDeviceChanged,e,t)),o}()})}setupLocalParticipantEvents(){this.localParticipant.on(L.ParticipantMetadataChanged,this.onLocalParticipantMetadataChanged).on(L.ParticipantNameChanged,this.onLocalParticipantNameChanged).on(L.AttributesChanged,this.onLocalAttributesChanged).on(L.TrackMuted,this.onLocalTrackMuted).on(L.TrackUnmuted,this.onLocalTrackUnmuted).on(L.LocalTrackPublished,this.onLocalTrackPublished).on(L.LocalTrackUnpublished,this.onLocalTrackUnpublished).on(L.ConnectionQualityChanged,this.onLocalConnectionQualityChanged).on(L.MediaDevicesError,this.onMediaDevicesError).on(L.AudioStreamAcquired,this.startAudio).on(L.ChatMessage,this.onLocalChatMessageSent).on(L.ParticipantPermissionsChanged,this.onLocalParticipantPermissionsChanged)}recreateEngine(e){let t=this.engine;e&&t&&!t.client.isDisconnected?t.client.sendLeave().finally(()=>t.close()):t?.close(),this.engine=void 0,this.isResuming=!1,this.remoteParticipants.clear(),this.sidToIdentity.clear(),this.bufferedEvents=[],this.maybeCreateEngine()}onTrackAdded(e,t,n){if([$.Connecting,$.Reconnecting].includes(this.state)){let r=Fc(e,t);this.log.debug(`deferring on track for later`,{mediaTrackId:e.id,mediaStreamId:t.id,tracksInStream:t.getTracks().map(e=>e.id)});let i=()=>{a(),this.onTrackAdded(e,t,n)},a=()=>{if(this.off(I.Reconnected,i),this.off(I.Connected,i),this.off(I.Disconnected,a),r){let e=this.pendingTrackAddedCallbacks.get(r);e?.delete(a),e?.size===0&&this.pendingTrackAddedCallbacks.delete(r)}};if(this.once(I.Reconnected,i),this.once(I.Connected,i),this.once(I.Disconnected,a),r){let e=this.pendingTrackAddedCallbacks.get(r)??new Set;e.add(a),this.pendingTrackAddedCallbacks.set(r,e)}return}if(this.state===$.Disconnected){this.log.warn(`skipping incoming track after Room disconnected`);return}if(e.readyState===`ended`){this.log.debug(`skipping incoming track as it already ended`);return}let r=ms(t.id),i=r[0],a=r[1],o=Fc(e,t)??e.id;if(i===this.localParticipant.sid){this.log.warn(`tried to create RemoteParticipant for local participant`);return}let s=Array.from(this.remoteParticipants.values()).find(e=>e.sid===i);if(!s){i.startsWith(`PA`)&&this.log.error(`Tried to add a track for a participant, that's not present. Sid: ${i}`);return}if(!o.startsWith(`TR`)){let e=this.engine.getTrackIdForReceiver(n);if(!e){this.log.error(`Tried to add a track whose 'sid' could not be found for a participant, that's not present. Sid: ${i}`);return}o=e}o.startsWith(`TR`)||this.log.warn(`Tried to add a track whose 'sid' could not be determined for a participant, that's not present. Sid: ${i}, streamId: ${a}, trackId: ${o}`,{remoteParticipantID:i,streamId:a,trackId:o});let c;this.options.adaptiveStream&&(c=typeof this.options.adaptiveStream==`object`?this.options.adaptiveStream:{});let l=s.addSubscribedMediaTrack(e,o,t,n,c);l?.isEncrypted&&!this.e2eeManager&&this.emit(I.EncryptionError,Error(`Encrypted ${l.source} track received from participant ${s.sid}, but room does not have encryption enabled!`))}cancelPendingTrackAdded(e){var t;(t=this.pendingTrackAddedCallbacks.get(e))==null||t.forEach(e=>e())}handleLocalTrackSubscribed(e){let t=()=>this.localParticipant.getTrackPublications().find(t=>t.trackSid===e),n=t();if(n){this.emitLocalTrackSubscribed(n);return}this.log.debug(`deferring LocalTrackSubscribed, publication not yet available`,{subscribedSid:e});let r,i=t=>{t.trackSid===e&&(a(),this.emitLocalTrackSubscribed(t))},a=()=>{clearTimeout(r),this.localParticipant.off(L.LocalTrackPublished,i),this.off(I.Disconnected,a)};this.localParticipant.on(L.LocalTrackPublished,i),this.once(I.Disconnected,a),r=setTimeout(()=>{a();let n=t();n?this.emitLocalTrackSubscribed(n):this.log.warn(`could not find local track publication for LocalTrackSubscribed event after timeout`,{subscribedSid:e})},1e4)}emitLocalTrackSubscribed(e){this.localParticipant.emit(L.LocalTrackSubscribed,e),this.emitWhenConnected(I.LocalTrackSubscribed,e,this.localParticipant)}handleDisconnect(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0,t=arguments.length>1?arguments[1]:void 0;var n,r,i;if(this.clearConnectionReconcile(),this.isResuming=!1,this.bufferedEvents=[],this.transcriptionReceivedTimes.clear(),this.incomingDataStreamManager.clearControllers(),this.incomingDataTrackManager.reset(),this.outgoingDataTrackManager.reset(),this.state!==$.Disconnected){this.regionUrl=void 0,this.regionUrlProvider&&this.regionUrlProvider.notifyDisconnected();try{let t=e?[]:Array.from(this.localParticipant.audioTrackPublications.values()).map(e=>e.track).filter(xc);this.remoteParticipants.forEach(e=>{e.trackPublications.forEach(t=>{e.unpublishTrack(t.trackSid)})}),this.localParticipant.trackPublications.forEach(t=>{var n,r,i;t.track&&this.localParticipant.unpublishTrack(t.track,e),e?((n=t.track)==null||n.detach(),(r=t.track)==null||r.stop()):(i=t.track)==null||i.stopMonitor()}),this.localParticipant.off(L.ParticipantMetadataChanged,this.onLocalParticipantMetadataChanged).off(L.ParticipantNameChanged,this.onLocalParticipantNameChanged).off(L.AttributesChanged,this.onLocalAttributesChanged).off(L.TrackMuted,this.onLocalTrackMuted).off(L.TrackUnmuted,this.onLocalTrackUnmuted).off(L.LocalTrackPublished,this.onLocalTrackPublished).off(L.LocalTrackUnpublished,this.onLocalTrackUnpublished).off(L.ConnectionQualityChanged,this.onLocalConnectionQualityChanged).off(L.MediaDevicesError,this.onMediaDevicesError).off(L.AudioStreamAcquired,this.startAudio).off(L.ChatMessage,this.onLocalChatMessageSent).off(L.ParticipantPermissionsChanged,this.onLocalParticipantPermissionsChanged),this.localParticipant.trackPublications.clear(),this.localParticipant.videoTrackPublications.clear(),this.localParticipant.audioTrackPublications.clear(),this.remoteParticipants.clear(),this.sidToIdentity.clear(),this.activeSpeakers=[],(n=this.releaseDummyAudioElement)==null||n.call(this),this.releaseAcquiredEmptyAudioTracks(),this.releaseAudioContext(t).catch(e=>this.log.warn(`Could not release audio context`,Object.assign(Object.assign({},this.logContext),{error:e}))),W()&&(window.removeEventListener(`beforeunload`,this.onPageLeave),window.removeEventListener(`pagehide`,this.onPageLeave),window.removeEventListener(`freeze`,this.onPageLeave),(i=(r=navigator.mediaDevices)?.removeEventListener)==null||i.call(r,`devicechange`,this.handleDeviceChange))}finally{this.setAndEmitConnectionState($.Disconnected),this.emit(I.Disconnected,t)}}}handleParticipantDisconnected(e,t,n){this.remoteParticipants.delete(e),t&&(this.incomingDataStreamManager.validateParticipantHasNoActiveDataStreams(e),this.incomingDataTrackManager.handleRemoteParticipantDisconnected(e),t.trackPublications.forEach(e=>{t.unpublishTrack(e.trackSid,!0)}),this.emit(I.ParticipantDisconnected,t,n),t.setDisconnected(),this.rpcClientManager.handleParticipantDisconnected(t.identity))}selectDefaultDevices(){return O(this,void 0,void 0,function*(){let e=Tl.getInstance().previousDevices,t=yield Tl.getInstance().getDevices(void 0,!1),n=k();if(n?.name===`Chrome`&&n.os!==`iOS`)for(let n of t){let t=e.find(e=>e.deviceId===n.deviceId);t&&t.label!==``&&t.kind===n.kind&&t.label!==n.label&&this.getActiveDevice(n.kind)==="default"&&this.emit(I.ActiveDeviceChanged,n.kind,n.deviceId)}for(let n of[`audiooutput`,`audioinput`,`videoinput`]){let r=Yo(n),i=this.localParticipant.getTrackPublication(r);if(i&&i.track?.isUserProvided)continue;let a=t.filter(e=>e.kind===n),o=this.getActiveDevice(n);o===e.filter(e=>e.kind===n)[0]?.deviceId&&a.length>0&&a[0]?.deviceId!==o?yield this.switchActiveDevice(n,a[0].deviceId):n===`audioinput`&&!js()||n===`videoinput`||a.length>0&&!a.find(e=>e.deviceId===this.getActiveDevice(n))&&(n!==`audiooutput`||!js())&&(yield this.switchActiveDevice(n,a[0].deviceId))}})}acquireAudioContext(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];return function*(){let n=yield e.audioContextMutex.lock();try{if(e.audioContextReleased&&!t)return;e.audioContextReleased=!1;let n=typeof e.options.webAudioMix==`boolean`?void 0:e.options.webAudioMix.audioContext;if(n?yield e.setRoomAudioContext(n,!1):e.audioContext&&e.audioContext.state!==`closed`||(yield e.setRoomAudioContext(Jo()??void 0,!0)),e.audioContext&&e.audioContext.state===`suspended`)try{yield Promise.race([e.audioContext.resume(),U(200)])}catch(t){e.log.warn(`Could not resume audio context`,{error:t})}let r=e.audioContext?.state===`running`;r!==e.canPlaybackAudio&&(e.audioEnabled=r,e.emit(I.AudioPlaybackStatusChanged,r))}finally{n()}}()})}setRoomAudioContext(e,t){return O(this,void 0,void 0,function*(){let n=!!e&&t;if(this.audioContext===e){this.ownsAudioContext=n;return}let r=this.ownsAudioContext?this.audioContext:void 0;this.audioContext=e,this.ownsAudioContext=n;try{this.options.webAudioMix&&(yield Promise.all(Array.from(this.remoteParticipants.values()).map(t=>t.setAudioContext(e)))),yield this.localParticipant.setAudioContext(e)}catch(e){this.log.warn(`Could not move audio tracks to the new audio context`,Object.assign(Object.assign({},this.logContext),{error:e}))}finally{if(r&&r.state!==`closed`)try{yield r.close()}catch(e){this.log.warn(`Could not close audio context`,Object.assign(Object.assign({},this.logContext),{error:e}))}}})}releaseAudioContext(){return O(this,arguments,void 0,function(){var e=this;let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return function*(){e.audioContextReleased=!0;let n=e.audioContext,r=yield e.audioContextMutex.lock();try{if(!e.audioContextReleased||e.audioContext!==n||!e.ownsAudioContext)return;try{yield Promise.all(t.map(e=>e.setAudioContext(void 0)))}catch(t){e.log.warn(`Could not detach retained audio tracks from the audio context`,Object.assign(Object.assign({},e.logContext),{error:t}))}yield e.setRoomAudioContext(void 0,!1)}finally{r()}}()})}createParticipant(e,t){let n;return n=t?Om.fromParticipantInfo(this.engine.client,t,{loggerContextCb:()=>this.logContext,loggerName:this.options.loggerName},this.incomingDataTrackManager):new Om(this.engine.client,``,e,void 0,void 0,void 0,{loggerContextCb:()=>this.logContext,loggerName:this.options.loggerName}),this.options.webAudioMix&&n.setAudioContext(this.audioContext).catch(e=>this.log.warn(`Could not set audio context`,Object.assign(Object.assign({},this.logContext),{error:e}))),this.options.audioOutput?.deviceId&&n.setAudioOutput(this.options.audioOutput).catch(e=>this.log.warn(`Could not set audio output: ${e.message}`)),n}getOrCreateParticipant(e,t){if(this.remoteParticipants.has(e)){let n=this.remoteParticipants.get(e);return t&&n.updateInfo(t)&&this.sidToIdentity.set(t.sid,t.identity),n}let n=this.createParticipant(e,t);return this.remoteParticipants.set(e,n),this.sidToIdentity.set(t.sid,t.identity),this.emitWhenConnected(I.ParticipantConnected,n),n.on(L.TrackPublished,e=>{this.emitWhenConnected(I.TrackPublished,e,n)}).on(L.TrackSubscribed,(e,t)=>{e.kind===H.Kind.Audio?(e.on(z.AudioPlaybackStarted,this.handleAudioPlaybackStarted),e.on(z.AudioPlaybackFailed,this.handleAudioPlaybackFailed)):e.kind===H.Kind.Video&&(e.on(z.VideoPlaybackFailed,this.handleVideoPlaybackFailed),e.on(z.VideoPlaybackStarted,this.handleVideoPlaybackStarted)),this.emitWhenConnected(I.TrackSubscribed,e,t,n)}).on(L.TrackUnpublished,e=>{this.cancelPendingTrackAdded(e.trackSid),this.emit(I.TrackUnpublished,e,n)}).on(L.TrackUnsubscribed,(e,t)=>{this.emit(I.TrackUnsubscribed,e,t,n)}).on(L.TrackMuted,e=>{this.emitWhenConnected(I.TrackMuted,e,n)}).on(L.TrackUnmuted,e=>{this.emitWhenConnected(I.TrackUnmuted,e,n)}).on(L.ParticipantMetadataChanged,e=>{this.emitWhenConnected(I.ParticipantMetadataChanged,e,n)}).on(L.ParticipantNameChanged,e=>{this.emitWhenConnected(I.ParticipantNameChanged,e,n)}).on(L.AttributesChanged,e=>{this.emitWhenConnected(I.ParticipantAttributesChanged,e,n)}).on(L.ConnectionQualityChanged,e=>{this.emitWhenConnected(I.ConnectionQualityChanged,e,n)}).on(L.ParticipantPermissionsChanged,e=>{this.emitWhenConnected(I.ParticipantPermissionsChanged,e,n)}).on(L.TrackSubscriptionStatusChanged,(e,t)=>{this.emitWhenConnected(I.TrackSubscriptionStatusChanged,e,t,n)}).on(L.TrackSubscriptionFailed,(e,t)=>{this.emit(I.TrackSubscriptionFailed,e,n,t)}).on(L.TrackSubscriptionPermissionChanged,(e,t)=>{this.emitWhenConnected(I.TrackSubscriptionPermissionChanged,e,t,n)}).on(L.Active,()=>{this.emitWhenConnected(I.ParticipantActive,n),n.kind===yn.AGENT&&this.localParticipant.setActiveAgent(n)}),t&&n.updateInfo(t),n}sendSyncState(){let e=Array.from(this.remoteParticipants.values()).reduce((e,t)=>(e.push(...t.getTrackPublications()),e),[]),t=this.localParticipant.getTrackPublications(),n=this.outgoingDataTrackManager.queryPublished();this.engine.sendSyncState(e,t,n)}updateSubscriptions(){for(let e of this.remoteParticipants.values())for(let t of e.videoTrackPublications.values())t.isSubscribed&&Cc(t)&&t.emitTrackUpdate()}getRemoteParticipantBySid(e){let t=this.sidToIdentity.get(e);if(t)return this.remoteParticipants.get(t)}getClientInfoCapabilities(e){let t=[];return(rl(e.frameMetadata??e.packetTrailer)||this.e2eeManager)&&t.push($n.CAP_PACKET_TRAILER),Mc()&&t.push($n.CAP_COMPRESSION_DEFLATE_RAW),t}registerRpcDataStreamHandler(){this.incomingDataStreamManager.registerTextStreamHandler(cm,(e,t)=>O(this,[e,t],void 0,function(e,t){var n=this;let r=t.identity;return function*(){let t=e.info.attributes??{};yield n.rpcServerManager.handleIncomingDataStream(e,r,t)}()})),this.incomingDataStreamManager.registerTextStreamHandler(lm,(e,t)=>O(this,[e,t],void 0,function(e,t){var n=this;let r=t.identity;return function*(){let t=e.info.attributes??{};yield n.rpcClientManager.handleIncomingDataStream(e,r,t)}()}))}setStatsLogging(e){e?this.statsLogInterval||=F.setInterval(()=>{this.logWebRTCStats()},Am):this.statsLogInterval&&=(F.clearInterval(this.statsLogInterval),void 0)}registerConnectionReconcile(){this.clearConnectionReconcile();let e=0;this.connectionReconcileInterval=F.setInterval(()=>{!this.engine||this.engine.isClosed||!this.engine.verifyTransport()?(e++,this.log.warn(`detected connection state mismatch`,{numFailures:e,engine:this.engine?{closed:this.engine.isClosed,transportsConnectedOrConnecting:this.engine.verifyTransport()}:void 0}),e>=3&&(this.clearConnectionReconcile(),this.engine&&!this.engine.isClosed?(this.log.warn(`detected connection state mismatch, attempting full reconnect`),this.engine.reconnect()):(this.recreateEngine(),this.handleDisconnect(this.options.stopLocalTrackOnUnpublish,un.STATE_MISMATCH)))):e=0},km)}clearConnectionReconcile(){this.connectionReconcileInterval&&F.clearInterval(this.connectionReconcileInterval)}setAndEmitConnectionState(e){return e!==this.state&&(this.log.info(`connection state changed: ${this.state} -> ${e}`),this.state=e,this.incomingDataStreamManager.setConnected(e===$.Connected),this.setStatsLogging(e===$.Connected),this.emit(I.ConnectionStateChanged,this.state),!0)}emitBufferedEvents(){this.bufferedEvents.forEach(e=>{let t=_(e,2),n=t[0],r=t[1];this.emit(n,...r)}),this.bufferedEvents=[]}emitWhenConnected(e){var t=[...arguments].slice(1);if(this.state===$.Reconnecting||this.isResuming||!this.engine||this.engine.pendingReconnect)this.bufferedEvents.push([e,t]);else if(this.state===$.Connected)return this.emit(e,...t);return!1}simulateParticipants(e){return O(this,void 0,void 0,function*(){let t=Object.assign({audio:!0,video:!0,useRealTracks:!1},e.publish),n=Object.assign({count:9,audio:!1,video:!0,aspectRatios:[1.66,1.7,1.3]},e.participants);if(this.handleDisconnect(),this.roomInfo=new mn({sid:`RM_SIMULATED`,name:`simulated-room`,emptyTimeout:0,maxParticipants:0,creationTime:m.parse(new Date().getTime()),metadata:``,numParticipants:1,numPublishers:1,turnPassword:``,enabledCodecs:[],activeRecording:!1}),this.localParticipant.updateInfo(new _n({identity:`simulated-local`,name:`local-name`})),this.setupLocalParticipantEvents(),this.emit(I.SignalConnected),this.emit(I.Connected),this.setAndEmitConnectionState($.Connected),t.video){let e=new vm(H.Kind.Video,new Sn({source:b.CAMERA,sid:Math.floor(Math.random()*1e4).toString(),type:on.AUDIO,name:`video-dummy`}),new sf(t.useRealTracks&&window.navigator.mediaDevices?.getUserMedia?(yield window.navigator.mediaDevices.getUserMedia({video:!0})).getVideoTracks()[0]:Qs(160*(n.aspectRatios[0]??1),160,!0,!0),void 0,!1,{loggerName:this.options.loggerName,loggerContextCb:()=>this.logContext}),{loggerName:this.options.loggerName,loggerContextCb:()=>this.logContext});this.localParticipant.addTrackPublication(e),this.localParticipant.emit(L.LocalTrackPublished,e)}if(t.audio){let e=new vm(H.Kind.Audio,new Sn({source:b.MICROPHONE,sid:Math.floor(Math.random()*1e4).toString(),type:on.AUDIO}),new Bd(t.useRealTracks&&navigator.mediaDevices?.getUserMedia?(yield navigator.mediaDevices.getUserMedia({audio:!0})).getAudioTracks()[0]:this.acquireEmptyAudioStreamTrack(),void 0,!1,this.audioContext,{loggerName:this.options.loggerName,loggerContextCb:()=>this.logContext}),{loggerName:this.options.loggerName,loggerContextCb:()=>this.logContext});this.localParticipant.addTrackPublication(e),this.localParticipant.emit(L.LocalTrackPublished,e)}for(let e=0;e<n.count-1;e+=1){let t=new _n({sid:Math.floor(Math.random()*1e4).toString(),identity:`simulated-${e}`,state:vn.ACTIVE,tracks:[],joinedAt:m.parse(Date.now())}),r=this.getOrCreateParticipant(t.identity,t);if(n.video){let i=Qs(160*(n.aspectRatios[e%n.aspectRatios.length]??1),160,!1,!0),a=new Sn({source:b.CAMERA,sid:Math.floor(Math.random()*1e4).toString(),type:on.AUDIO});r.addSubscribedMediaTrack(i,a.sid,new MediaStream([i]),new RTCRtpReceiver),t.tracks=[...t.tracks,a]}if(n.audio){let e=this.acquireEmptyAudioStreamTrack(),n=new Sn({source:b.MICROPHONE,sid:Math.floor(Math.random()*1e4).toString(),type:on.AUDIO});r.addSubscribedMediaTrack(e,n.sid,new MediaStream([e]),new RTCRtpReceiver),t.tracks=[...t.tracks,n]}r.updateInfo(t)}})}emit(e){var t=[...arguments].slice(1);if(e!==I.ActiveSpeakersChanged&&e!==I.TranscriptionReceived){let n=Fm(t).filter(e=>e!==void 0);(e===I.TrackSubscribed||e===I.TrackUnsubscribed)&&this.log.trace(`subscribe trace: ${e}`,{event:e,args:n}),this.log.debug(`room event ${e}`,{event:e,args:n})}return super.emit(e,...t)}};Pm.cleanupRegistry=typeof FinalizationRegistry<`u`&&typeof WeakRef<`u`&&new FinalizationRegistry(e=>{e()});function Fm(e){return e.map(e=>{if(e)return Array.isArray(e)?Fm(e):typeof e==`object`?`logContext`in e?e.logContext:void 0:e})}var Im;(function(e){e[e.IDLE=0]=`IDLE`,e[e.RUNNING=1]=`RUNNING`,e[e.SKIPPED=2]=`SKIPPED`,e[e.SUCCESS=3]=`SUCCESS`,e[e.FAILED=4]=`FAILED`})(Im||={}),Yi.EventEmitter,Yi.EventEmitter,new TextEncoder,new TextDecoder,new TextDecoder(`utf-8`,{fatal:!0});var Lm=class extends Error{constructor(e,t){var n;super(e,t),g(this,`code`,`ERR_JOSE_GENERIC`),this.name=this.constructor.name,(n=Error.captureStackTrace)==null||n.call(Error,this,this.constructor)}};g(Lm,`code`,`ERR_JOSE_GENERIC`),g(class extends Lm{constructor(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:`unspecified`,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:`unspecified`;super(e,{cause:{claim:n,reason:r,payload:t}}),g(this,`code`,`ERR_JWT_CLAIM_VALIDATION_FAILED`),g(this,`claim`,void 0),g(this,`reason`,void 0),g(this,`payload`,void 0),this.claim=n,this.reason=r,this.payload=t}},`code`,`ERR_JWT_CLAIM_VALIDATION_FAILED`),g(class extends Lm{constructor(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:`unspecified`,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:`unspecified`;super(e,{cause:{claim:n,reason:r,payload:t}}),g(this,`code`,`ERR_JWT_EXPIRED`),g(this,`claim`,void 0),g(this,`reason`,void 0),g(this,`payload`,void 0),this.claim=n,this.reason=r,this.payload=t}},`code`,`ERR_JWT_EXPIRED`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JOSE_ALG_NOT_ALLOWED`)}},`code`,`ERR_JOSE_ALG_NOT_ALLOWED`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JOSE_NOT_SUPPORTED`)}},`code`,`ERR_JOSE_NOT_SUPPORTED`),g(class extends Lm{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`decryption operation failed`,t=arguments.length>1?arguments[1]:void 0;super(e,t),g(this,`code`,`ERR_JWE_DECRYPTION_FAILED`)}},`code`,`ERR_JWE_DECRYPTION_FAILED`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JWE_INVALID`)}},`code`,`ERR_JWE_INVALID`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JWS_INVALID`)}},`code`,`ERR_JWS_INVALID`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JWT_INVALID`)}},`code`,`ERR_JWT_INVALID`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JWK_INVALID`)}},`code`,`ERR_JWK_INVALID`),g(class extends Lm{constructor(){super(...arguments),g(this,`code`,`ERR_JWKS_INVALID`)}},`code`,`ERR_JWKS_INVALID`),g(class extends Lm{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`no applicable key found in the JSON Web Key Set`,t=arguments.length>1?arguments[1]:void 0;super(e,t),g(this,`code`,`ERR_JWKS_NO_MATCHING_KEY`)}},`code`,`ERR_JWKS_NO_MATCHING_KEY`),g(class extends Lm{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`multiple matching keys found in the JSON Web Key Set`,t=arguments.length>1?arguments[1]:void 0;super(e,t),g(this,Symbol.asyncIterator,ze(function*(){})),g(this,`code`,`ERR_JWKS_MULTIPLE_MATCHING_KEYS`)}},`code`,`ERR_JWKS_MULTIPLE_MATCHING_KEYS`),g(class extends Lm{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`request timed out`,t=arguments.length>1?arguments[1]:void 0;super(e,t),g(this,`code`,`ERR_JWKS_TIMEOUT`)}},`code`,`ERR_JWKS_TIMEOUT`),g(class extends Lm{constructor(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:`signature verification failed`,t=arguments.length>1?arguments[1]:void 0;super(e,t),g(this,`code`,`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`)}},`code`,`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`);export{Pm as Room,I as RoomEvent,H as Track};
|