livekit-client 0.18.2 → 0.18.4-RC2

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.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LivekitClient={})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(i){if("default"!==i&&!(i in e)){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}}))})),Object.freeze(e)}var i,n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}};!function(e){var t,i;t=n,i=function(){var e=function(){},t="undefined",i=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"];function r(e,t){var i=e[t];if("function"==typeof i.bind)return i.bind(e);try{return Function.prototype.bind.call(i,e)}catch(t){return function(){return Function.prototype.apply.apply(i,[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 a(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&i?s:void 0!==console[n]?r(console,n):void 0!==console.log?r(console,"log"):e)}function o(t,i){for(var r=0;r<n.length;r++){var s=n[r];this[s]=r<t?e:this.methodFactory(s,t,i)}this.log=this.debug}function c(e,i,n){return function(){typeof console!==t&&(o.call(this,i,n),this[e].apply(this,arguments))}}function d(e,t,i){return a(e)||c.apply(this,arguments)}function u(e,i,r){var s,a=this;i=null==i?"WARN":i;var c="loglevel";function u(){var e;if(typeof window!==t&&c){try{e=window.localStorage[c]}catch(e){}if(typeof e===t)try{var i=window.document.cookie,n=i.indexOf(encodeURIComponent(c)+"=");-1!==n&&(e=/^([^;]+)/.exec(i.slice(n))[1])}catch(e){}return void 0===a.levels[e]&&(e=void 0),e}}"string"==typeof e?c+=":"+e:"symbol"==typeof e&&(c=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=r||d,a.getLevel=function(){return s},a.setLevel=function(i,r){if("string"==typeof i&&void 0!==a.levels[i.toUpperCase()]&&(i=a.levels[i.toUpperCase()]),!("number"==typeof i&&i>=0&&i<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+i;if(s=i,!1!==r&&function(e){var i=(n[e]||"silent").toUpperCase();if(typeof window!==t&&c){try{return void(window.localStorage[c]=i)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"="+i+";"}catch(e){}}}(i),o.call(a,i,e),typeof console===t&&i<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){i=e,u()||a.setLevel(e,!1)},a.resetLevel=function(){a.setLevel(i,!1),function(){if(typeof window!==t&&c){try{return void window.localStorage.removeItem(c)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var l=u();null==l&&(l=i),a.setLevel(l,!1)}var l=new u,h={};l.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=h[e];return t||(t=h[e]=new u(e,l.getLevel(),l.methodFactory)),t};var p=typeof window!==t?window.log:void 0;return l.noConflict=function(){return typeof window!==t&&window.log===l&&(window.log=p),l},l.getLoggers=function(){return h},l.default=l,l},e.exports?e.exports=i():t.log=i()}(r),e.LogLevel=void 0,(i=e.LogLevel||(e.LogLevel={}))[i.trace=0]="trace",i[i.debug=1]="debug",i[i.info=2]="info",i[i.warn=3]="warn",i[i.error=4]="error",i[i.silent=5]="silent";const s=r.exports.getLogger("livekit");function a(e){s.setLevel(e)}s.setLevel(e.LogLevel.info);var o=d,c=null;try{c=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function d(e,t,i){this.low=0|e,this.high=0|t,this.unsigned=!!i}function u(e){return!0===(e&&e.__isLong__)}d.prototype.__isLong__,Object.defineProperty(d.prototype,"__isLong__",{value:!0}),d.isLong=u;var l={},h={};function p(e,t){var i,n,r;return t?(r=0<=(e>>>=0)&&e<256)&&(n=h[e])?n:(i=m(e,(0|e)<0?-1:0,!0),r&&(h[e]=i),i):(r=-128<=(e|=0)&&e<128)&&(n=l[e])?n:(i=m(e,e<0?-1:0,!1),r&&(l[e]=i),i)}function f(e,t){if(isNaN(e))return t?T:C;if(t){if(e<0)return T;if(e>=S)return N}else{if(e<=-y)return D;if(e+1>=y)return O}return e<0?f(-e,t).neg():m(e%k|0,e/k|0,t)}function m(e,t,i){return new d(e,t,i)}d.fromInt=p,d.fromNumber=f,d.fromBits=m;var v=Math.pow;function g(e,t,i){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return C;if("number"==typeof t?(i=t,t=!1):t=!!t,(i=i||10)<2||36<i)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return g(e.substring(1),t,i).neg();for(var r=f(v(i,8)),s=C,a=0;a<e.length;a+=8){var o=Math.min(8,e.length-a),c=parseInt(e.substring(a,a+o),i);if(o<8){var d=f(v(i,o));s=s.mul(d).add(f(c))}else s=(s=s.mul(r)).add(f(c))}return s.unsigned=t,s}function b(e,t){return"number"==typeof e?f(e,t):"string"==typeof e?g(e,t):m(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}d.fromString=g,d.fromValue=b;var k=4294967296,S=k*k,y=S/2,w=p(1<<24),C=p(0);d.ZERO=C;var T=p(0,!0);d.UZERO=T;var E=p(1);d.ONE=E;var P=p(1,!0);d.UONE=P;var R=p(-1);d.NEG_ONE=R;var O=m(-1,2147483647,!1);d.MAX_VALUE=O;var N=m(-1,-1,!0);d.MAX_UNSIGNED_VALUE=N;var D=m(0,-2147483648,!1);d.MIN_VALUE=D;var A=d.prototype;A.toInt=function(){return this.unsigned?this.low>>>0:this.low},A.toNumber=function(){return this.unsigned?(this.high>>>0)*k+(this.low>>>0):this.high*k+(this.low>>>0)},A.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(D)){var t=f(e),i=this.div(t),n=i.mul(t).sub(this);return i.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var r=f(v(e,6),this.unsigned),s=this,a="";;){var o=s.div(r),c=(s.sub(o.mul(r)).toInt()>>>0).toString(e);if((s=o).isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},A.getHighBits=function(){return this.high},A.getHighBitsUnsigned=function(){return this.high>>>0},A.getLowBits=function(){return this.low},A.getLowBitsUnsigned=function(){return this.low>>>0},A.getNumBitsAbs=function(){if(this.isNegative())return this.eq(D)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},A.isZero=function(){return 0===this.high&&0===this.low},A.eqz=A.isZero,A.isNegative=function(){return!this.unsigned&&this.high<0},A.isPositive=function(){return this.unsigned||this.high>=0},A.isOdd=function(){return 1==(1&this.low)},A.isEven=function(){return 0==(1&this.low)},A.equals=function(e){return u(e)||(e=b(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},A.eq=A.equals,A.notEquals=function(e){return!this.eq(e)},A.neq=A.notEquals,A.ne=A.notEquals,A.lessThan=function(e){return this.comp(e)<0},A.lt=A.lessThan,A.lessThanOrEqual=function(e){return this.comp(e)<=0},A.lte=A.lessThanOrEqual,A.le=A.lessThanOrEqual,A.greaterThan=function(e){return this.comp(e)>0},A.gt=A.greaterThan,A.greaterThanOrEqual=function(e){return this.comp(e)>=0},A.gte=A.greaterThanOrEqual,A.ge=A.greaterThanOrEqual,A.compare=function(e){if(u(e)||(e=b(e)),this.eq(e))return 0;var t=this.isNegative(),i=e.isNegative();return t&&!i?-1:!t&&i?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},A.comp=A.compare,A.negate=function(){return!this.unsigned&&this.eq(D)?D:this.not().add(E)},A.neg=A.negate,A.add=function(e){u(e)||(e=b(e));var t=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,s=e.high>>>16,a=65535&e.high,o=e.low>>>16,c=0,d=0,l=0,h=0;return l+=(h+=r+(65535&e.low))>>>16,d+=(l+=n+o)>>>16,c+=(d+=i+a)>>>16,c+=t+s,m((l&=65535)<<16|(h&=65535),(c&=65535)<<16|(d&=65535),this.unsigned)},A.subtract=function(e){return u(e)||(e=b(e)),this.add(e.neg())},A.sub=A.subtract,A.multiply=function(e){if(this.isZero())return C;if(u(e)||(e=b(e)),c)return m(c.mul(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned);if(e.isZero())return C;if(this.eq(D))return e.isOdd()?D:C;if(e.eq(D))return this.isOdd()?D:C;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(w)&&e.lt(w))return f(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,s=e.high>>>16,a=65535&e.high,o=e.low>>>16,d=65535&e.low,l=0,h=0,p=0,v=0;return p+=(v+=r*d)>>>16,h+=(p+=n*d)>>>16,p&=65535,h+=(p+=r*o)>>>16,l+=(h+=i*d)>>>16,h&=65535,l+=(h+=n*o)>>>16,h&=65535,l+=(h+=r*a)>>>16,l+=t*d+i*o+n*a+r*s,m((p&=65535)<<16|(v&=65535),(l&=65535)<<16|(h&=65535),this.unsigned)},A.mul=A.multiply,A.divide=function(e){if(u(e)||(e=b(e)),e.isZero())throw Error("division by zero");var t,i,n;if(c)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?m((this.unsigned?c.div_u:c.div_s)(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?T:C;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return T;if(e.gt(this.shru(1)))return P;n=T}else{if(this.eq(D))return e.eq(E)||e.eq(R)?D:e.eq(D)?E:(t=this.shr(1).div(e).shl(1)).eq(C)?e.isNegative()?E:R:(i=this.sub(e.mul(t)),n=t.add(i.div(e)));if(e.eq(D))return this.unsigned?T:C;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=C}for(i=this;i.gte(e);){t=Math.max(1,Math.floor(i.toNumber()/e.toNumber()));for(var r=Math.ceil(Math.log(t)/Math.LN2),s=r<=48?1:v(2,r-48),a=f(t),o=a.mul(e);o.isNegative()||o.gt(i);)o=(a=f(t-=s,this.unsigned)).mul(e);a.isZero()&&(a=E),n=n.add(a),i=i.sub(o)}return n},A.div=A.divide,A.modulo=function(e){return u(e)||(e=b(e)),c?m((this.unsigned?c.rem_u:c.rem_s)(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},A.mod=A.modulo,A.rem=A.modulo,A.not=function(){return m(~this.low,~this.high,this.unsigned)},A.and=function(e){return u(e)||(e=b(e)),m(this.low&e.low,this.high&e.high,this.unsigned)},A.or=function(e){return u(e)||(e=b(e)),m(this.low|e.low,this.high|e.high,this.unsigned)},A.xor=function(e){return u(e)||(e=b(e)),m(this.low^e.low,this.high^e.high,this.unsigned)},A.shiftLeft=function(e){return u(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?m(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):m(0,this.low<<e-32,this.unsigned)},A.shl=A.shiftLeft,A.shiftRight=function(e){return u(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?m(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):m(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},A.shr=A.shiftRight,A.shiftRightUnsigned=function(e){if(u(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?m(this.low>>>e|t<<32-e,t>>>e,this.unsigned):m(32===e?t:t>>>e-32,0,this.unsigned)},A.shru=A.shiftRightUnsigned,A.shr_u=A.shiftRightUnsigned,A.toSigned=function(){return this.unsigned?m(this.low,this.high,!1):this},A.toUnsigned=function(){return this.unsigned?this:m(this.low,this.high,!0)},A.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},A.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},A.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},d.fromBytes=function(e,t,i){return i?d.fromBytesLE(e,t):d.fromBytesBE(e,t)},d.fromBytesLE=function(e,t){return new d(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},d.fromBytesBE=function(e,t){return new d(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};var U={},I={},L=function(e,t){var i=new Array(arguments.length-1),n=0,r=2,s=!0;for(;r<arguments.length;)i[n++]=arguments[r++];return new Promise((function(r,a){i[n]=function(e){if(s)if(s=!1,e)a(e);else{for(var t=new Array(arguments.length-1),i=0;i<t.length;)t[i++]=arguments[i];r.apply(null,t)}};try{e.apply(t||null,i)}catch(e){s&&(s=!1,a(e))}}))};var M={};!function(e){var t=e;t.length=function(e){var t=e.length;if(!t)return 0;for(var i=0;--t%4>1&&"="===e.charAt(t);)++i;return Math.ceil(3*e.length)/4-i};for(var i=new Array(64),n=new Array(123),r=0;r<64;)n[i[r]=r<26?r+65:r<52?r+71:r<62?r-4:r-59|43]=r++;t.encode=function(e,t,n){for(var r,s=null,a=[],o=0,c=0;t<n;){var d=e[t++];switch(c){case 0:a[o++]=i[d>>2],r=(3&d)<<4,c=1;break;case 1:a[o++]=i[r|d>>4],r=(15&d)<<2,c=2;break;case 2:a[o++]=i[r|d>>6],a[o++]=i[63&d],c=0}o>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,a)),o=0)}return c&&(a[o++]=i[r],a[o++]=61,1===c&&(a[o++]=61)),s?(o&&s.push(String.fromCharCode.apply(String,a.slice(0,o))),s.join("")):String.fromCharCode.apply(String,a.slice(0,o))};var s="invalid encoding";t.decode=function(e,t,i){for(var r,a=i,o=0,c=0;c<e.length;){var d=e.charCodeAt(c++);if(61===d&&o>1)break;if(void 0===(d=n[d]))throw Error(s);switch(o){case 0:r=d,o=1;break;case 1:t[i++]=r<<2|(48&d)>>4,r=d,o=2;break;case 2:t[i++]=(15&r)<<4|(60&d)>>2,r=d,o=3;break;case 3:t[i++]=(3&r)<<6|d,o=0}}if(1===o)throw Error(s);return i-a},t.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}}(M);var _=x;function x(){this._listeners={}}x.prototype.on=function(e,t,i){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:i||this}),this},x.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var i=this._listeners[e],n=0;n<i.length;)i[n].fn===t?i.splice(n,1):++n;return this},x.prototype.emit=function(e){var t=this._listeners[e];if(t){for(var i=[],n=1;n<arguments.length;)i.push(arguments[n++]);for(n=0;n<t.length;)t[n].fn.apply(t[n++].ctx,i)}return this};var J=B(B);function B(e){return"undefined"!=typeof Float32Array?function(){var t=new Float32Array([-0]),i=new Uint8Array(t.buffer),n=128===i[3];function r(e,n,r){t[0]=e,n[r]=i[0],n[r+1]=i[1],n[r+2]=i[2],n[r+3]=i[3]}function s(e,n,r){t[0]=e,n[r]=i[3],n[r+1]=i[2],n[r+2]=i[1],n[r+3]=i[0]}function a(e,n){return i[0]=e[n],i[1]=e[n+1],i[2]=e[n+2],i[3]=e[n+3],t[0]}function o(e,n){return i[3]=e[n],i[2]=e[n+1],i[1]=e[n+2],i[0]=e[n+3],t[0]}e.writeFloatLE=n?r:s,e.writeFloatBE=n?s:r,e.readFloatLE=n?a:o,e.readFloatBE=n?o:a}():function(){function t(e,t,i,n){var r=t<0?1:0;if(r&&(t=-t),0===t)e(1/t>0?0:2147483648,i,n);else if(isNaN(t))e(2143289344,i,n);else if(t>34028234663852886e22)e((r<<31|2139095040)>>>0,i,n);else if(t<11754943508222875e-54)e((r<<31|Math.round(t/1401298464324817e-60))>>>0,i,n);else{var s=Math.floor(Math.log(t)/Math.LN2);e((r<<31|s+127<<23|8388607&Math.round(t*Math.pow(2,-s)*8388608))>>>0,i,n)}}function i(e,t,i){var n=e(t,i),r=2*(n>>31)+1,s=n>>>23&255,a=8388607&n;return 255===s?a?NaN:r*(1/0):0===s?1401298464324817e-60*r*a:r*Math.pow(2,s-150)*(a+8388608)}e.writeFloatLE=t.bind(null,j),e.writeFloatBE=t.bind(null,V),e.readFloatLE=i.bind(null,F),e.readFloatBE=i.bind(null,q)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),i=new Uint8Array(t.buffer),n=128===i[7];function r(e,n,r){t[0]=e,n[r]=i[0],n[r+1]=i[1],n[r+2]=i[2],n[r+3]=i[3],n[r+4]=i[4],n[r+5]=i[5],n[r+6]=i[6],n[r+7]=i[7]}function s(e,n,r){t[0]=e,n[r]=i[7],n[r+1]=i[6],n[r+2]=i[5],n[r+3]=i[4],n[r+4]=i[3],n[r+5]=i[2],n[r+6]=i[1],n[r+7]=i[0]}function a(e,n){return i[0]=e[n],i[1]=e[n+1],i[2]=e[n+2],i[3]=e[n+3],i[4]=e[n+4],i[5]=e[n+5],i[6]=e[n+6],i[7]=e[n+7],t[0]}function o(e,n){return i[7]=e[n],i[6]=e[n+1],i[5]=e[n+2],i[4]=e[n+3],i[3]=e[n+4],i[2]=e[n+5],i[1]=e[n+6],i[0]=e[n+7],t[0]}e.writeDoubleLE=n?r:s,e.writeDoubleBE=n?s:r,e.readDoubleLE=n?a:o,e.readDoubleBE=n?o:a}():function(){function t(e,t,i,n,r,s){var a=n<0?1:0;if(a&&(n=-n),0===n)e(0,r,s+t),e(1/n>0?0:2147483648,r,s+i);else if(isNaN(n))e(0,r,s+t),e(2146959360,r,s+i);else if(n>17976931348623157e292)e(0,r,s+t),e((a<<31|2146435072)>>>0,r,s+i);else{var o;if(n<22250738585072014e-324)e((o=n/5e-324)>>>0,r,s+t),e((a<<31|o/4294967296)>>>0,r,s+i);else{var c=Math.floor(Math.log(n)/Math.LN2);1024===c&&(c=1023),e(4503599627370496*(o=n*Math.pow(2,-c))>>>0,r,s+t),e((a<<31|c+1023<<20|1048576*o&1048575)>>>0,r,s+i)}}}function i(e,t,i,n,r){var s=e(n,r+t),a=e(n,r+i),o=2*(a>>31)+1,c=a>>>20&2047,d=4294967296*(1048575&a)+s;return 2047===c?d?NaN:o*(1/0):0===c?5e-324*o*d:o*Math.pow(2,c-1075)*(d+4503599627370496)}e.writeDoubleLE=t.bind(null,j,0,4),e.writeDoubleBE=t.bind(null,V,4,0),e.readDoubleLE=i.bind(null,F,0,4),e.readDoubleBE=i.bind(null,q,4,0)}(),e}function j(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}function V(e,t,i){t[i]=e>>>24,t[i+1]=e>>>16&255,t[i+2]=e>>>8&255,t[i+3]=255&e}function F(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function q(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}var Q=function(e){try{var t=void 0;t}catch(e){}return null};var W={};!function(e){var t=e;t.length=function(e){for(var t=0,i=0,n=0;n<e.length;++n)(i=e.charCodeAt(n))<128?t+=1:i<2048?t+=2:55296==(64512&i)&&56320==(64512&e.charCodeAt(n+1))?(++n,t+=4):t+=3;return t},t.read=function(e,t,i){if(i-t<1)return"";for(var n,r=null,s=[],a=0;t<i;)(n=e[t++])<128?s[a++]=n:n>191&&n<224?s[a++]=(31&n)<<6|63&e[t++]:n>239&&n<365?(n=((7&n)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,s[a++]=55296+(n>>10),s[a++]=56320+(1023&n)):s[a++]=(15&n)<<12|(63&e[t++])<<6|63&e[t++],a>8191&&((r||(r=[])).push(String.fromCharCode.apply(String,s)),a=0);return r?(a&&r.push(String.fromCharCode.apply(String,s.slice(0,a))),r.join("")):String.fromCharCode.apply(String,s.slice(0,a))},t.write=function(e,t,i){for(var n,r,s=i,a=0;a<e.length;++a)(n=e.charCodeAt(a))<128?t[i++]=n:n<2048?(t[i++]=n>>6|192,t[i++]=63&n|128):55296==(64512&n)&&56320==(64512&(r=e.charCodeAt(a+1)))?(n=65536+((1023&n)<<10)+(1023&r),++a,t[i++]=n>>18|240,t[i++]=n>>12&63|128,t[i++]=n>>6&63|128,t[i++]=63&n|128):(t[i++]=n>>12|224,t[i++]=n>>6&63|128,t[i++]=63&n|128);return i-s}}(W);var G=function(e,t,i){var n=i||8192,r=n>>>1,s=null,a=n;return function(i){if(i<1||i>r)return e(i);a+i>n&&(s=e(n),a=0);var o=t.call(s,a,a+=i);return 7&a&&(a=1+(7|a)),o}};var K=z,H=I;function z(e,t){this.lo=e>>>0,this.hi=t>>>0}var Z=z.zero=new z(0,0);Z.toNumber=function(){return 0},Z.zzEncode=Z.zzDecode=function(){return this},Z.length=function(){return 1};var $=z.zeroHash="\0\0\0\0\0\0\0\0";z.fromNumber=function(e){if(0===e)return Z;var t=e<0;t&&(e=-e);var i=e>>>0,n=(e-i)/4294967296>>>0;return t&&(n=~n>>>0,i=~i>>>0,++i>4294967295&&(i=0,++n>4294967295&&(n=0))),new z(i,n)},z.from=function(e){if("number"==typeof e)return z.fromNumber(e);if(H.isString(e)){if(!H.Long)return z.fromNumber(parseInt(e,10));e=H.Long.fromString(e)}return e.low||e.high?new z(e.low>>>0,e.high>>>0):Z},z.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,i=~this.hi>>>0;return t||(i=i+1>>>0),-(t+4294967296*i)}return this.lo+4294967296*this.hi},z.prototype.toLong=function(e){return H.Long?new H.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var Y=String.prototype.charCodeAt;z.fromHash=function(e){return e===$?Z:new z((Y.call(e,0)|Y.call(e,1)<<8|Y.call(e,2)<<16|Y.call(e,3)<<24)>>>0,(Y.call(e,4)|Y.call(e,5)<<8|Y.call(e,6)<<16|Y.call(e,7)<<24)>>>0)},z.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},z.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},z.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},z.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return 0===i?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:i<128?9:10},function(e){var t=e;function i(e,t,i){for(var n=Object.keys(t),r=0;r<n.length;++r)void 0!==e[n[r]]&&i||(e[n[r]]=t[n[r]]);return e}function r(e){function t(e,n){if(!(this instanceof t))return new t(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),n&&i(this,n)}return(t.prototype=Object.create(Error.prototype)).constructor=t,Object.defineProperty(t.prototype,"name",{get:function(){return e}}),t.prototype.toString=function(){return this.name+": "+this.message},t}t.asPromise=L,t.base64=M,t.EventEmitter=_,t.float=J,t.inquire=Q,t.utf8=W,t.pool=G,t.LongBits=K,t.isNode=Boolean(void 0!==n&&n&&n.process&&n.process.versions&&n.process.versions.node),t.global=t.isNode&&n||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||n,t.emptyArray=Object.freeze?Object.freeze([]):[],t.emptyObject=Object.freeze?Object.freeze({}):{},t.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},t.isString=function(e){return"string"==typeof e||e instanceof String},t.isObject=function(e){return e&&"object"==typeof e},t.isset=t.isSet=function(e,t){var i=e[t];return!(null==i||!e.hasOwnProperty(t))&&("object"!=typeof i||(Array.isArray(i)?i.length:Object.keys(i).length)>0)},t.Buffer=function(){try{var e=t.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),t._Buffer_from=null,t._Buffer_allocUnsafe=null,t.newBuffer=function(e){return"number"==typeof e?t.Buffer?t._Buffer_allocUnsafe(e):new t.Array(e):t.Buffer?t._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},t.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,t.Long=t.global.dcodeIO&&t.global.dcodeIO.Long||t.global.Long||t.inquire("long"),t.key2Re=/^true|false|0|1$/,t.key32Re=/^-?(?:0|[1-9][0-9]*)$/,t.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,t.longToHash=function(e){return e?t.LongBits.from(e).toHash():t.LongBits.zeroHash},t.longFromHash=function(e,i){var n=t.LongBits.fromHash(e);return t.Long?t.Long.fromBits(n.lo,n.hi,i):n.toNumber(Boolean(i))},t.merge=i,t.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},t.newError=r,t.ProtocolError=r("ProtocolError"),t.oneOfGetter=function(e){for(var t={},i=0;i<e.length;++i)t[e[i]]=1;return function(){for(var e=Object.keys(this),i=e.length-1;i>-1;--i)if(1===t[e[i]]&&void 0!==this[e[i]]&&null!==this[e[i]])return e[i]}},t.oneOfSetter=function(e){return function(t){for(var i=0;i<e.length;++i)e[i]!==t&&delete this[e[i]]}},t.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},t._configure=function(){var e=t.Buffer;e?(t._Buffer_from=e.from!==Uint8Array.from&&e.from||function(t,i){return new e(t,i)},t._Buffer_allocUnsafe=e.allocUnsafe||function(t){return new e(t)}):t._Buffer_from=t._Buffer_allocUnsafe=null}}(I);var X,ee=ce,te=I,ie=te.LongBits,ne=te.base64,re=te.utf8;function se(e,t,i){this.fn=e,this.len=t,this.next=void 0,this.val=i}function ae(){}function oe(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}function ce(){this.len=0,this.head=new se(ae,0,0),this.tail=this.head,this.states=null}var de=function(){return te.Buffer?function(){return(ce.create=function(){return new X})()}:function(){return new ce}};function ue(e,t,i){t[i]=255&e}function le(e,t){this.len=e,this.next=void 0,this.val=t}function he(e,t,i){for(;e.hi;)t[i++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[i++]=127&e.lo|128,e.lo=e.lo>>>7;t[i++]=e.lo}function pe(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}ce.create=de(),ce.alloc=function(e){return new te.Array(e)},te.Array!==Array&&(ce.alloc=te.pool(ce.alloc,te.Array.prototype.subarray)),ce.prototype._push=function(e,t,i){return this.tail=this.tail.next=new se(e,t,i),this.len+=t,this},le.prototype=Object.create(se.prototype),le.prototype.fn=function(e,t,i){for(;e>127;)t[i++]=127&e|128,e>>>=7;t[i]=e},ce.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new le((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},ce.prototype.int32=function(e){return e<0?this._push(he,10,ie.fromNumber(e)):this.uint32(e)},ce.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},ce.prototype.uint64=function(e){var t=ie.from(e);return this._push(he,t.length(),t)},ce.prototype.int64=ce.prototype.uint64,ce.prototype.sint64=function(e){var t=ie.from(e).zzEncode();return this._push(he,t.length(),t)},ce.prototype.bool=function(e){return this._push(ue,1,e?1:0)},ce.prototype.fixed32=function(e){return this._push(pe,4,e>>>0)},ce.prototype.sfixed32=ce.prototype.fixed32,ce.prototype.fixed64=function(e){var t=ie.from(e);return this._push(pe,4,t.lo)._push(pe,4,t.hi)},ce.prototype.sfixed64=ce.prototype.fixed64,ce.prototype.float=function(e){return this._push(te.float.writeFloatLE,4,e)},ce.prototype.double=function(e){return this._push(te.float.writeDoubleLE,8,e)};var fe=te.Array.prototype.set?function(e,t,i){t.set(e,i)}:function(e,t,i){for(var n=0;n<e.length;++n)t[i+n]=e[n]};ce.prototype.bytes=function(e){var t=e.length>>>0;if(!t)return this._push(ue,1,0);if(te.isString(e)){var i=ce.alloc(t=ne.length(e));ne.decode(e,i,0),e=i}return this.uint32(t)._push(fe,t,e)},ce.prototype.string=function(e){var t=re.length(e);return t?this.uint32(t)._push(re.write,t,e):this._push(ue,1,0)},ce.prototype.fork=function(){return this.states=new oe(this),this.head=this.tail=new se(ae,0,0),this.len=0,this},ce.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new se(ae,0,0),this.len=0),this},ce.prototype.ldelim=function(){var e=this.head,t=this.tail,i=this.len;return this.reset().uint32(i),i&&(this.tail.next=e.next,this.tail=t,this.len+=i),this},ce.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),i=0;e;)e.fn(e.val,t,i),i+=e.len,e=e.next;return t},ce._configure=function(e){X=e,ce.create=de(),X._configure()};var me=be,ve=ee;(be.prototype=Object.create(ve.prototype)).constructor=be;var ge=I;function be(){ve.call(this)}function ke(e,t,i){e.length<40?ge.utf8.write(e,t,i):t.utf8Write?t.utf8Write(e,i):t.write(e,i)}be._configure=function(){be.alloc=ge._Buffer_allocUnsafe,be.writeBytesBuffer=ge.Buffer&&ge.Buffer.prototype instanceof Uint8Array&&"set"===ge.Buffer.prototype.set.name?function(e,t,i){t.set(e,i)}:function(e,t,i){if(e.copy)e.copy(t,i,0,e.length);else for(var n=0;n<e.length;)t[i++]=e[n++]}},be.prototype.bytes=function(e){ge.isString(e)&&(e=ge._Buffer_from(e,"base64"));var t=e.length>>>0;return this.uint32(t),t&&this._push(be.writeBytesBuffer,t,e),this},be.prototype.string=function(e){var t=ge.Buffer.byteLength(e);return this.uint32(t),t&&this._push(ke,t,e),this},be._configure();var Se,ye=Pe,we=I,Ce=we.LongBits,Te=we.utf8;function Ee(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function Pe(e){this.buf=e,this.pos=0,this.len=e.length}var Re,Oe="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new Pe(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new Pe(e);throw Error("illegal buffer")},Ne=function(){return we.Buffer?function(e){return(Pe.create=function(e){return we.Buffer.isBuffer(e)?new Se(e):Oe(e)})(e)}:Oe};function De(){var e=new Ce(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw Ee(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ee(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function Ae(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function Ue(){if(this.pos+8>this.len)throw Ee(this,8);return new Ce(Ae(this.buf,this.pos+=4),Ae(this.buf,this.pos+=4))}Pe.create=Ne(),Pe.prototype._slice=we.Array.prototype.subarray||we.Array.prototype.slice,Pe.prototype.uint32=(Re=4294967295,function(){if(Re=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return Re;if((this.pos+=5)>this.len)throw this.pos=this.len,Ee(this,10);return Re}),Pe.prototype.int32=function(){return 0|this.uint32()},Pe.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},Pe.prototype.bool=function(){return 0!==this.uint32()},Pe.prototype.fixed32=function(){if(this.pos+4>this.len)throw Ee(this,4);return Ae(this.buf,this.pos+=4)},Pe.prototype.sfixed32=function(){if(this.pos+4>this.len)throw Ee(this,4);return 0|Ae(this.buf,this.pos+=4)},Pe.prototype.float=function(){if(this.pos+4>this.len)throw Ee(this,4);var e=we.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},Pe.prototype.double=function(){if(this.pos+8>this.len)throw Ee(this,4);var e=we.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},Pe.prototype.bytes=function(){var e=this.uint32(),t=this.pos,i=this.pos+e;if(i>this.len)throw Ee(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,i):t===i?new this.buf.constructor(0):this._slice.call(this.buf,t,i)},Pe.prototype.string=function(){var e=this.bytes();return Te.read(e,0,e.length)},Pe.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw Ee(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw Ee(this)}while(128&this.buf[this.pos++]);return this},Pe.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},Pe._configure=function(e){Se=e,Pe.create=Ne(),Se._configure();var t=we.Long?"toLong":"toNumber";we.merge(Pe.prototype,{int64:function(){return De.call(this)[t](!1)},uint64:function(){return De.call(this)[t](!0)},sint64:function(){return De.call(this).zzDecode()[t](!1)},fixed64:function(){return Ue.call(this)[t](!0)},sfixed64:function(){return Ue.call(this)[t](!1)}})};var Ie=_e,Le=ye;(_e.prototype=Object.create(Le.prototype)).constructor=_e;var Me=I;function _e(e){Le.call(this,e)}_e._configure=function(){Me.Buffer&&(_e.prototype._slice=Me.Buffer.prototype.slice)},_e.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},_e._configure();var xe={},Je=je,Be=I;function je(e,t,i){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");Be.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(i)}(je.prototype=Object.create(Be.EventEmitter.prototype)).constructor=je,je.prototype.rpcCall=function e(t,i,n,r,s){if(!r)throw TypeError("request must be specified");var a=this;if(!s)return Be.asPromise(e,a,t,i,n,r);if(a.rpcImpl)try{return a.rpcImpl(t,i[a.requestDelimited?"encodeDelimited":"encode"](r).finish(),(function(e,i){if(e)return a.emit("error",e,t),s(e);if(null!==i){if(!(i instanceof n))try{i=n[a.responseDelimited?"decodeDelimited":"decode"](i)}catch(e){return a.emit("error",e,t),s(e)}return a.emit("data",i,t),s(null,i)}a.end(!0)}))}catch(e){return a.emit("error",e,t),void setTimeout((function(){s(e)}),0)}else setTimeout((function(){s(Error("already ended"))}),0)},je.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this},function(e){e.Service=Je}(xe);var Ve={};!function(e){var t=e;function i(){t.util._configure(),t.Writer._configure(t.BufferWriter),t.Reader._configure(t.BufferReader)}t.build="minimal",t.Writer=ee,t.BufferWriter=me,t.Reader=ye,t.BufferReader=Ie,t.util=I,t.rpc=xe,t.roots=Ve,t.configure=i,i()}(U);var Fe,qe,Qe,We,Ge,Ke,He,ze,Ze=U,$e=(()=>{if(void 0!==$e)return $e;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw"Unable to locate global object"})();function Ye(e){switch(e){case 0:case"AUDIO":return Fe.AUDIO;case 1:case"VIDEO":return Fe.VIDEO;case 2:case"DATA":return Fe.DATA;default:return Fe.UNRECOGNIZED}}function Xe(e){switch(e){case Fe.AUDIO:return"AUDIO";case Fe.VIDEO:return"VIDEO";case Fe.DATA:return"DATA";default:return"UNKNOWN"}}function et(e){switch(e){case 0:case"UNKNOWN":return qe.UNKNOWN;case 1:case"CAMERA":return qe.CAMERA;case 2:case"MICROPHONE":return qe.MICROPHONE;case 3:case"SCREEN_SHARE":return qe.SCREEN_SHARE;case 4:case"SCREEN_SHARE_AUDIO":return qe.SCREEN_SHARE_AUDIO;default:return qe.UNRECOGNIZED}}function tt(e){switch(e){case qe.UNKNOWN:return"UNKNOWN";case qe.CAMERA:return"CAMERA";case qe.MICROPHONE:return"MICROPHONE";case qe.SCREEN_SHARE:return"SCREEN_SHARE";case qe.SCREEN_SHARE_AUDIO:return"SCREEN_SHARE_AUDIO";default:return"UNKNOWN"}}function it(t){switch(t){case 0:case"LOW":return e.VideoQuality.LOW;case 1:case"MEDIUM":return e.VideoQuality.MEDIUM;case 2:case"HIGH":return e.VideoQuality.HIGH;case 3:case"OFF":return e.VideoQuality.OFF;default:return e.VideoQuality.UNRECOGNIZED}}function nt(t){switch(t){case e.VideoQuality.LOW:return"LOW";case e.VideoQuality.MEDIUM:return"MEDIUM";case e.VideoQuality.HIGH:return"HIGH";case e.VideoQuality.OFF:return"OFF";default:return"UNKNOWN"}}function rt(e){switch(e){case 0:case"POOR":return We.POOR;case 1:case"GOOD":return We.GOOD;case 2:case"EXCELLENT":return We.EXCELLENT;default:return We.UNRECOGNIZED}}function st(e){switch(e){case 0:case"UNSET":return Ge.UNSET;case 1:case"DISABLED":return Ge.DISABLED;case 2:case"ENABLED":return Ge.ENABLED;default:return Ge.UNRECOGNIZED}}function at(e){switch(e){case Ge.UNSET:return"UNSET";case Ge.DISABLED:return"DISABLED";case Ge.ENABLED:return"ENABLED";default:return"UNKNOWN"}}function ot(e){switch(e){case 0:case"JOINING":return Ke.JOINING;case 1:case"JOINED":return Ke.JOINED;case 2:case"ACTIVE":return Ke.ACTIVE;case 3:case"DISCONNECTED":return Ke.DISCONNECTED;default:return Ke.UNRECOGNIZED}}function ct(t){switch(t){case 0:case"RELIABLE":return e.DataPacket_Kind.RELIABLE;case 1:case"LOSSY":return e.DataPacket_Kind.LOSSY;default:return e.DataPacket_Kind.UNRECOGNIZED}}function dt(e){switch(e){case 0:case"UNKNOWN":return ze.UNKNOWN;case 1:case"JS":return ze.JS;case 2:case"SWIFT":return ze.SWIFT;case 3:case"ANDROID":return ze.ANDROID;case 4:case"FLUTTER":return ze.FLUTTER;case 5:case"GO":return ze.GO;case 6:case"UNITY":return ze.UNITY;default:return ze.UNRECOGNIZED}}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure()),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.DATA=2]="DATA",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Fe||(Fe={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.CAMERA=1]="CAMERA",e[e.MICROPHONE=2]="MICROPHONE",e[e.SCREEN_SHARE=3]="SCREEN_SHARE",e[e.SCREEN_SHARE_AUDIO=4]="SCREEN_SHARE_AUDIO",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(qe||(qe={})),e.VideoQuality=void 0,(Qe=e.VideoQuality||(e.VideoQuality={}))[Qe.LOW=0]="LOW",Qe[Qe.MEDIUM=1]="MEDIUM",Qe[Qe.HIGH=2]="HIGH",Qe[Qe.OFF=3]="OFF",Qe[Qe.UNRECOGNIZED=-1]="UNRECOGNIZED",function(e){e[e.POOR=0]="POOR",e[e.GOOD=1]="GOOD",e[e.EXCELLENT=2]="EXCELLENT",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(We||(We={})),function(e){e[e.UNSET=0]="UNSET",e[e.DISABLED=1]="DISABLED",e[e.ENABLED=2]="ENABLED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ge||(Ge={})),function(e){e[e.JOINING=0]="JOINING",e[e.JOINED=1]="JOINED",e[e.ACTIVE=2]="ACTIVE",e[e.DISCONNECTED=3]="DISCONNECTED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ke||(Ke={})),e.DataPacket_Kind=void 0,(He=e.DataPacket_Kind||(e.DataPacket_Kind={}))[He.RELIABLE=0]="RELIABLE",He[He.LOSSY=1]="LOSSY",He[He.UNRECOGNIZED=-1]="UNRECOGNIZED",function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.JS=1]="JS",e[e.SWIFT=2]="SWIFT",e[e.ANDROID=3]="ANDROID",e[e.FLUTTER=4]="FLUTTER",e[e.GO=5]="GO",e[e.UNITY=6]="UNITY",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(ze||(ze={}));const ut={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),""!==e.name&&t.uint32(18).string(e.name),0!==e.emptyTimeout&&t.uint32(24).uint32(e.emptyTimeout),0!==e.maxParticipants&&t.uint32(32).uint32(e.maxParticipants),0!==e.creationTime&&t.uint32(40).int64(e.creationTime),""!==e.turnPassword&&t.uint32(50).string(e.turnPassword);for(const i of e.enabledCodecs)lt.encode(i,t.uint32(58).fork()).ldelim();return""!==e.metadata&&t.uint32(66).string(e.metadata),0!==e.numParticipants&&t.uint32(72).uint32(e.numParticipants),!0===e.activeRecording&&t.uint32(80).bool(e.activeRecording),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",name:"",emptyTimeout:0,maxParticipants:0,creationTime:0,turnPassword:"",enabledCodecs:[],metadata:"",numParticipants:0,activeRecording:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.name=i.string();break;case 3:r.emptyTimeout=i.uint32();break;case 4:r.maxParticipants=i.uint32();break;case 5:r.creationTime=Nt(i.int64());break;case 6:r.turnPassword=i.string();break;case 7:r.enabledCodecs.push(lt.decode(i,i.uint32()));break;case 8:r.metadata=i.string();break;case 9:r.numParticipants=i.uint32();break;case 10:r.activeRecording=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",name:Dt(e.name)?String(e.name):"",emptyTimeout:Dt(e.emptyTimeout)?Number(e.emptyTimeout):0,maxParticipants:Dt(e.maxParticipants)?Number(e.maxParticipants):0,creationTime:Dt(e.creationTime)?Number(e.creationTime):0,turnPassword:Dt(e.turnPassword)?String(e.turnPassword):"",enabledCodecs:Array.isArray(e?.enabledCodecs)?e.enabledCodecs.map((e=>lt.fromJSON(e))):[],metadata:Dt(e.metadata)?String(e.metadata):"",numParticipants:Dt(e.numParticipants)?Number(e.numParticipants):0,activeRecording:!!Dt(e.activeRecording)&&Boolean(e.activeRecording)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.name&&(t.name=e.name),void 0!==e.emptyTimeout&&(t.emptyTimeout=Math.round(e.emptyTimeout)),void 0!==e.maxParticipants&&(t.maxParticipants=Math.round(e.maxParticipants)),void 0!==e.creationTime&&(t.creationTime=Math.round(e.creationTime)),void 0!==e.turnPassword&&(t.turnPassword=e.turnPassword),e.enabledCodecs?t.enabledCodecs=e.enabledCodecs.map((e=>e?lt.toJSON(e):void 0)):t.enabledCodecs=[],void 0!==e.metadata&&(t.metadata=e.metadata),void 0!==e.numParticipants&&(t.numParticipants=Math.round(e.numParticipants)),void 0!==e.activeRecording&&(t.activeRecording=e.activeRecording),t},fromPartial(e){const t={sid:"",name:"",emptyTimeout:0,maxParticipants:0,creationTime:0,turnPassword:"",enabledCodecs:[],metadata:"",numParticipants:0,activeRecording:!1};return t.sid=e.sid??"",t.name=e.name??"",t.emptyTimeout=e.emptyTimeout??0,t.maxParticipants=e.maxParticipants??0,t.creationTime=e.creationTime??0,t.turnPassword=e.turnPassword??"",t.enabledCodecs=e.enabledCodecs?.map((e=>lt.fromPartial(e)))||[],t.metadata=e.metadata??"",t.numParticipants=e.numParticipants??0,t.activeRecording=e.activeRecording??!1,t}};const lt={encode:(e,t=Ze.Writer.create())=>(""!==e.mime&&t.uint32(10).string(e.mime),""!==e.fmtpLine&&t.uint32(18).string(e.fmtpLine),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={mime:"",fmtpLine:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.mime=i.string();break;case 2:r.fmtpLine=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({mime:Dt(e.mime)?String(e.mime):"",fmtpLine:Dt(e.fmtpLine)?String(e.fmtpLine):""}),toJSON(e){const t={};return void 0!==e.mime&&(t.mime=e.mime),void 0!==e.fmtpLine&&(t.fmtpLine=e.fmtpLine),t},fromPartial(e){const t={mime:"",fmtpLine:""};return t.mime=e.mime??"",t.fmtpLine=e.fmtpLine??"",t}};const ht={encode:(e,t=Ze.Writer.create())=>(!0===e.canSubscribe&&t.uint32(8).bool(e.canSubscribe),!0===e.canPublish&&t.uint32(16).bool(e.canPublish),!0===e.canPublishData&&t.uint32(24).bool(e.canPublishData),!0===e.hidden&&t.uint32(56).bool(e.hidden),!0===e.recorder&&t.uint32(64).bool(e.recorder),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={canSubscribe:!1,canPublish:!1,canPublishData:!1,hidden:!1,recorder:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.canSubscribe=i.bool();break;case 2:r.canPublish=i.bool();break;case 3:r.canPublishData=i.bool();break;case 7:r.hidden=i.bool();break;case 8:r.recorder=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({canSubscribe:!!Dt(e.canSubscribe)&&Boolean(e.canSubscribe),canPublish:!!Dt(e.canPublish)&&Boolean(e.canPublish),canPublishData:!!Dt(e.canPublishData)&&Boolean(e.canPublishData),hidden:!!Dt(e.hidden)&&Boolean(e.hidden),recorder:!!Dt(e.recorder)&&Boolean(e.recorder)}),toJSON(e){const t={};return void 0!==e.canSubscribe&&(t.canSubscribe=e.canSubscribe),void 0!==e.canPublish&&(t.canPublish=e.canPublish),void 0!==e.canPublishData&&(t.canPublishData=e.canPublishData),void 0!==e.hidden&&(t.hidden=e.hidden),void 0!==e.recorder&&(t.recorder=e.recorder),t},fromPartial(e){const t={canSubscribe:!1,canPublish:!1,canPublishData:!1,hidden:!1,recorder:!1};return t.canSubscribe=e.canSubscribe??!1,t.canPublish=e.canPublish??!1,t.canPublishData=e.canPublishData??!1,t.hidden=e.hidden??!1,t.recorder=e.recorder??!1,t}};const pt={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),""!==e.identity&&t.uint32(18).string(e.identity),0!==e.state&&t.uint32(24).int32(e.state);for(const i of e.tracks)ft.encode(i,t.uint32(34).fork()).ldelim();return""!==e.metadata&&t.uint32(42).string(e.metadata),0!==e.joinedAt&&t.uint32(48).int64(e.joinedAt),""!==e.name&&t.uint32(74).string(e.name),0!==e.version&&t.uint32(80).uint32(e.version),void 0!==e.permission&&ht.encode(e.permission,t.uint32(90).fork()).ldelim(),""!==e.region&&t.uint32(98).string(e.region),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",identity:"",state:0,tracks:[],metadata:"",joinedAt:0,name:"",version:0,permission:void 0,region:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.identity=i.string();break;case 3:r.state=i.int32();break;case 4:r.tracks.push(ft.decode(i,i.uint32()));break;case 5:r.metadata=i.string();break;case 6:r.joinedAt=Nt(i.int64());break;case 9:r.name=i.string();break;case 10:r.version=i.uint32();break;case 11:r.permission=ht.decode(i,i.uint32());break;case 12:r.region=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",identity:Dt(e.identity)?String(e.identity):"",state:Dt(e.state)?ot(e.state):0,tracks:Array.isArray(e?.tracks)?e.tracks.map((e=>ft.fromJSON(e))):[],metadata:Dt(e.metadata)?String(e.metadata):"",joinedAt:Dt(e.joinedAt)?Number(e.joinedAt):0,name:Dt(e.name)?String(e.name):"",version:Dt(e.version)?Number(e.version):0,permission:Dt(e.permission)?ht.fromJSON(e.permission):void 0,region:Dt(e.region)?String(e.region):""}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.identity&&(t.identity=e.identity),void 0!==e.state&&(t.state=function(e){switch(e){case Ke.JOINING:return"JOINING";case Ke.JOINED:return"JOINED";case Ke.ACTIVE:return"ACTIVE";case Ke.DISCONNECTED:return"DISCONNECTED";default:return"UNKNOWN"}}(e.state)),e.tracks?t.tracks=e.tracks.map((e=>e?ft.toJSON(e):void 0)):t.tracks=[],void 0!==e.metadata&&(t.metadata=e.metadata),void 0!==e.joinedAt&&(t.joinedAt=Math.round(e.joinedAt)),void 0!==e.name&&(t.name=e.name),void 0!==e.version&&(t.version=Math.round(e.version)),void 0!==e.permission&&(t.permission=e.permission?ht.toJSON(e.permission):void 0),void 0!==e.region&&(t.region=e.region),t},fromPartial(e){const t={sid:"",identity:"",state:0,tracks:[],metadata:"",joinedAt:0,name:"",version:0,permission:void 0,region:""};return t.sid=e.sid??"",t.identity=e.identity??"",t.state=e.state??0,t.tracks=e.tracks?.map((e=>ft.fromPartial(e)))||[],t.metadata=e.metadata??"",t.joinedAt=e.joinedAt??0,t.name=e.name??"",t.version=e.version??0,t.permission=void 0!==e.permission&&null!==e.permission?ht.fromPartial(e.permission):void 0,t.region=e.region??"",t}};const ft={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),0!==e.type&&t.uint32(16).int32(e.type),""!==e.name&&t.uint32(26).string(e.name),!0===e.muted&&t.uint32(32).bool(e.muted),0!==e.width&&t.uint32(40).uint32(e.width),0!==e.height&&t.uint32(48).uint32(e.height),!0===e.simulcast&&t.uint32(56).bool(e.simulcast),!0===e.disableDtx&&t.uint32(64).bool(e.disableDtx),0!==e.source&&t.uint32(72).int32(e.source);for(const i of e.layers)mt.encode(i,t.uint32(82).fork()).ldelim();return""!==e.mimeType&&t.uint32(90).string(e.mimeType),""!==e.mid&&t.uint32(98).string(e.mid),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",type:0,name:"",muted:!1,width:0,height:0,simulcast:!1,disableDtx:!1,source:0,layers:[],mimeType:"",mid:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.type=i.int32();break;case 3:r.name=i.string();break;case 4:r.muted=i.bool();break;case 5:r.width=i.uint32();break;case 6:r.height=i.uint32();break;case 7:r.simulcast=i.bool();break;case 8:r.disableDtx=i.bool();break;case 9:r.source=i.int32();break;case 10:r.layers.push(mt.decode(i,i.uint32()));break;case 11:r.mimeType=i.string();break;case 12:r.mid=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",type:Dt(e.type)?Ye(e.type):0,name:Dt(e.name)?String(e.name):"",muted:!!Dt(e.muted)&&Boolean(e.muted),width:Dt(e.width)?Number(e.width):0,height:Dt(e.height)?Number(e.height):0,simulcast:!!Dt(e.simulcast)&&Boolean(e.simulcast),disableDtx:!!Dt(e.disableDtx)&&Boolean(e.disableDtx),source:Dt(e.source)?et(e.source):0,layers:Array.isArray(e?.layers)?e.layers.map((e=>mt.fromJSON(e))):[],mimeType:Dt(e.mimeType)?String(e.mimeType):"",mid:Dt(e.mid)?String(e.mid):""}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.type&&(t.type=Xe(e.type)),void 0!==e.name&&(t.name=e.name),void 0!==e.muted&&(t.muted=e.muted),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.simulcast&&(t.simulcast=e.simulcast),void 0!==e.disableDtx&&(t.disableDtx=e.disableDtx),void 0!==e.source&&(t.source=tt(e.source)),e.layers?t.layers=e.layers.map((e=>e?mt.toJSON(e):void 0)):t.layers=[],void 0!==e.mimeType&&(t.mimeType=e.mimeType),void 0!==e.mid&&(t.mid=e.mid),t},fromPartial(e){const t={sid:"",type:0,name:"",muted:!1,width:0,height:0,simulcast:!1,disableDtx:!1,source:0,layers:[],mimeType:"",mid:""};return t.sid=e.sid??"",t.type=e.type??0,t.name=e.name??"",t.muted=e.muted??!1,t.width=e.width??0,t.height=e.height??0,t.simulcast=e.simulcast??!1,t.disableDtx=e.disableDtx??!1,t.source=e.source??0,t.layers=e.layers?.map((e=>mt.fromPartial(e)))||[],t.mimeType=e.mimeType??"",t.mid=e.mid??"",t}};const mt={encode:(e,t=Ze.Writer.create())=>(0!==e.quality&&t.uint32(8).int32(e.quality),0!==e.width&&t.uint32(16).uint32(e.width),0!==e.height&&t.uint32(24).uint32(e.height),0!==e.bitrate&&t.uint32(32).uint32(e.bitrate),0!==e.ssrc&&t.uint32(40).uint32(e.ssrc),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={quality:0,width:0,height:0,bitrate:0,ssrc:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.quality=i.int32();break;case 2:r.width=i.uint32();break;case 3:r.height=i.uint32();break;case 4:r.bitrate=i.uint32();break;case 5:r.ssrc=i.uint32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({quality:Dt(e.quality)?it(e.quality):0,width:Dt(e.width)?Number(e.width):0,height:Dt(e.height)?Number(e.height):0,bitrate:Dt(e.bitrate)?Number(e.bitrate):0,ssrc:Dt(e.ssrc)?Number(e.ssrc):0}),toJSON(e){const t={};return void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.bitrate&&(t.bitrate=Math.round(e.bitrate)),void 0!==e.ssrc&&(t.ssrc=Math.round(e.ssrc)),t},fromPartial(e){const t={quality:0,width:0,height:0,bitrate:0,ssrc:0};return t.quality=e.quality??0,t.width=e.width??0,t.height=e.height??0,t.bitrate=e.bitrate??0,t.ssrc=e.ssrc??0,t}};const vt={encode:(e,t=Ze.Writer.create())=>(0!==e.kind&&t.uint32(8).int32(e.kind),void 0!==e.user&&St.encode(e.user,t.uint32(18).fork()).ldelim(),void 0!==e.speaker&&gt.encode(e.speaker,t.uint32(26).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={kind:0,user:void 0,speaker:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.kind=i.int32();break;case 2:r.user=St.decode(i,i.uint32());break;case 3:r.speaker=gt.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({kind:Dt(e.kind)?ct(e.kind):0,user:Dt(e.user)?St.fromJSON(e.user):void 0,speaker:Dt(e.speaker)?gt.fromJSON(e.speaker):void 0}),toJSON(t){const i={};return void 0!==t.kind&&(i.kind=function(t){switch(t){case e.DataPacket_Kind.RELIABLE:return"RELIABLE";case e.DataPacket_Kind.LOSSY:return"LOSSY";default:return"UNKNOWN"}}(t.kind)),void 0!==t.user&&(i.user=t.user?St.toJSON(t.user):void 0),void 0!==t.speaker&&(i.speaker=t.speaker?gt.toJSON(t.speaker):void 0),i},fromPartial(e){const t={kind:0,user:void 0,speaker:void 0};return t.kind=e.kind??0,t.user=void 0!==e.user&&null!==e.user?St.fromPartial(e.user):void 0,t.speaker=void 0!==e.speaker&&null!==e.speaker?gt.fromPartial(e.speaker):void 0,t}};const gt={encode(e,t=Ze.Writer.create()){for(const i of e.speakers)bt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakers:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.speakers.push(bt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({speakers:Array.isArray(e?.speakers)?e.speakers.map((e=>bt.fromJSON(e))):[]}),toJSON(e){const t={};return e.speakers?t.speakers=e.speakers.map((e=>e?bt.toJSON(e):void 0)):t.speakers=[],t},fromPartial(e){const t={speakers:[]};return t.speakers=e.speakers?.map((e=>bt.fromPartial(e)))||[],t}};const bt={encode:(e,t=Ze.Writer.create())=>(""!==e.sid&&t.uint32(10).string(e.sid),0!==e.level&&t.uint32(21).float(e.level),!0===e.active&&t.uint32(24).bool(e.active),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",level:0,active:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.level=i.float();break;case 3:r.active=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",level:Dt(e.level)?Number(e.level):0,active:!!Dt(e.active)&&Boolean(e.active)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.level&&(t.level=e.level),void 0!==e.active&&(t.active=e.active),t},fromPartial(e){const t={sid:"",level:0,active:!1};return t.sid=e.sid??"",t.level=e.level??0,t.active=e.active??!1,t}};function kt(){return{participantSid:"",payload:new Uint8Array,destinationSids:[]}}const St={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid),0!==e.payload.length&&t.uint32(18).bytes(e.payload);for(const i of e.destinationSids)t.uint32(26).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r=kt();for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.payload=i.bytes();break;case 3:r.destinationSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:Dt(e.participantSid)?String(e.participantSid):"",payload:Dt(e.payload)?Rt(e.payload):new Uint8Array,destinationSids:Array.isArray(e?.destinationSids)?e.destinationSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.payload&&(t.payload=function(e){const t=[];for(const i of e)t.push(String.fromCharCode(i));return Ot(t.join(""))}(void 0!==e.payload?e.payload:new Uint8Array)),e.destinationSids?t.destinationSids=e.destinationSids.map((e=>e)):t.destinationSids=[],t},fromPartial(e){const t=kt();return t.participantSid=e.participantSid??"",t.payload=e.payload??new Uint8Array,t.destinationSids=e.destinationSids?.map((e=>e))||[],t}};const yt={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid);for(const i of e.trackSids)t.uint32(18).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSids:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:Dt(e.participantSid)?String(e.participantSid):"",trackSids:Array.isArray(e?.trackSids)?e.trackSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],t},fromPartial(e){const t={participantSid:"",trackSids:[]};return t.participantSid=e.participantSid??"",t.trackSids=e.trackSids?.map((e=>e))||[],t}};const wt={encode:(e,t=Ze.Writer.create())=>(0!==e.sdk&&t.uint32(8).int32(e.sdk),""!==e.version&&t.uint32(18).string(e.version),0!==e.protocol&&t.uint32(24).int32(e.protocol),""!==e.os&&t.uint32(34).string(e.os),""!==e.osVersion&&t.uint32(42).string(e.osVersion),""!==e.deviceModel&&t.uint32(50).string(e.deviceModel),""!==e.browser&&t.uint32(58).string(e.browser),""!==e.browserVersion&&t.uint32(66).string(e.browserVersion),""!==e.address&&t.uint32(74).string(e.address),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sdk:0,version:"",protocol:0,os:"",osVersion:"",deviceModel:"",browser:"",browserVersion:"",address:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sdk=i.int32();break;case 2:r.version=i.string();break;case 3:r.protocol=i.int32();break;case 4:r.os=i.string();break;case 5:r.osVersion=i.string();break;case 6:r.deviceModel=i.string();break;case 7:r.browser=i.string();break;case 8:r.browserVersion=i.string();break;case 9:r.address=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sdk:Dt(e.sdk)?dt(e.sdk):0,version:Dt(e.version)?String(e.version):"",protocol:Dt(e.protocol)?Number(e.protocol):0,os:Dt(e.os)?String(e.os):"",osVersion:Dt(e.osVersion)?String(e.osVersion):"",deviceModel:Dt(e.deviceModel)?String(e.deviceModel):"",browser:Dt(e.browser)?String(e.browser):"",browserVersion:Dt(e.browserVersion)?String(e.browserVersion):"",address:Dt(e.address)?String(e.address):""}),toJSON(e){const t={};return void 0!==e.sdk&&(t.sdk=function(e){switch(e){case ze.UNKNOWN:return"UNKNOWN";case ze.JS:return"JS";case ze.SWIFT:return"SWIFT";case ze.ANDROID:return"ANDROID";case ze.FLUTTER:return"FLUTTER";case ze.GO:return"GO";case ze.UNITY:return"UNITY";default:return"UNKNOWN"}}(e.sdk)),void 0!==e.version&&(t.version=e.version),void 0!==e.protocol&&(t.protocol=Math.round(e.protocol)),void 0!==e.os&&(t.os=e.os),void 0!==e.osVersion&&(t.osVersion=e.osVersion),void 0!==e.deviceModel&&(t.deviceModel=e.deviceModel),void 0!==e.browser&&(t.browser=e.browser),void 0!==e.browserVersion&&(t.browserVersion=e.browserVersion),void 0!==e.address&&(t.address=e.address),t},fromPartial(e){const t={sdk:0,version:"",protocol:0,os:"",osVersion:"",deviceModel:"",browser:"",browserVersion:"",address:""};return t.sdk=e.sdk??0,t.version=e.version??"",t.protocol=e.protocol??0,t.os=e.os??"",t.osVersion=e.osVersion??"",t.deviceModel=e.deviceModel??"",t.browser=e.browser??"",t.browserVersion=e.browserVersion??"",t.address=e.address??"",t}};const Ct={encode:(e,t=Ze.Writer.create())=>(void 0!==e.video&&Tt.encode(e.video,t.uint32(10).fork()).ldelim(),void 0!==e.screen&&Tt.encode(e.screen,t.uint32(18).fork()).ldelim(),0!==e.resumeConnection&&t.uint32(24).int32(e.resumeConnection),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={video:void 0,screen:void 0,resumeConnection:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.video=Tt.decode(i,i.uint32());break;case 2:r.screen=Tt.decode(i,i.uint32());break;case 3:r.resumeConnection=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({video:Dt(e.video)?Tt.fromJSON(e.video):void 0,screen:Dt(e.screen)?Tt.fromJSON(e.screen):void 0,resumeConnection:Dt(e.resumeConnection)?st(e.resumeConnection):0}),toJSON(e){const t={};return void 0!==e.video&&(t.video=e.video?Tt.toJSON(e.video):void 0),void 0!==e.screen&&(t.screen=e.screen?Tt.toJSON(e.screen):void 0),void 0!==e.resumeConnection&&(t.resumeConnection=at(e.resumeConnection)),t},fromPartial(e){const t={video:void 0,screen:void 0,resumeConnection:0};return t.video=void 0!==e.video&&null!==e.video?Tt.fromPartial(e.video):void 0,t.screen=void 0!==e.screen&&null!==e.screen?Tt.fromPartial(e.screen):void 0,t.resumeConnection=e.resumeConnection??0,t}};const Tt={encode:(e,t=Ze.Writer.create())=>(0!==e.hardwareEncoder&&t.uint32(8).int32(e.hardwareEncoder),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={hardwareEncoder:0};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.hardwareEncoder=i.int32();else i.skipType(7&e)}return r},fromJSON:e=>({hardwareEncoder:Dt(e.hardwareEncoder)?st(e.hardwareEncoder):0}),toJSON(e){const t={};return void 0!==e.hardwareEncoder&&(t.hardwareEncoder=at(e.hardwareEncoder)),t},fromPartial(e){const t={hardwareEncoder:0};return t.hardwareEncoder=e.hardwareEncoder??0,t}};var Et=(()=>{if(void 0!==Et)return Et;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw"Unable to locate global object"})();const Pt=Et.atob||(e=>Et.Buffer.from(e,"base64").toString("binary"));function Rt(e){const t=Pt(e),i=new Uint8Array(t.length);for(let e=0;e<t.length;++e)i[e]=t.charCodeAt(e);return i}const Ot=Et.btoa||(e=>Et.Buffer.from(e,"binary").toString("base64"));function Nt(e){if(e.gt(Number.MAX_SAFE_INTEGER))throw new Et.Error("Value is larger than Number.MAX_SAFE_INTEGER");return e.toNumber()}function Dt(e){return null!=e}var At,Ut;function It(e){switch(e){case 0:case"PUBLISHER":return At.PUBLISHER;case 1:case"SUBSCRIBER":return At.SUBSCRIBER;default:return At.UNRECOGNIZED}}function Lt(e){switch(e){case At.PUBLISHER:return"PUBLISHER";case At.SUBSCRIBER:return"SUBSCRIBER";default:return"UNKNOWN"}}function Mt(e){switch(e){case 0:case"ACTIVE":return Ut.ACTIVE;case 1:case"PAUSED":return Ut.PAUSED;default:return Ut.UNRECOGNIZED}}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure()),function(e){e[e.PUBLISHER=0]="PUBLISHER",e[e.SUBSCRIBER=1]="SUBSCRIBER",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(At||(At={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PAUSED=1]="PAUSED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ut||(Ut={}));const _t={encode:(e,t=Ze.Writer.create())=>(void 0!==e.offer&&Qt.encode(e.offer,t.uint32(10).fork()).ldelim(),void 0!==e.answer&&Qt.encode(e.answer,t.uint32(18).fork()).ldelim(),void 0!==e.trickle&&Bt.encode(e.trickle,t.uint32(26).fork()).ldelim(),void 0!==e.addTrack&&Jt.encode(e.addTrack,t.uint32(34).fork()).ldelim(),void 0!==e.mute&&jt.encode(e.mute,t.uint32(42).fork()).ldelim(),void 0!==e.subscription&&Gt.encode(e.subscription,t.uint32(50).fork()).ldelim(),void 0!==e.trackSetting&&Kt.encode(e.trackSetting,t.uint32(58).fork()).ldelim(),void 0!==e.leave&&Ht.encode(e.leave,t.uint32(66).fork()).ldelim(),void 0!==e.updateLayers&&zt.encode(e.updateLayers,t.uint32(82).fork()).ldelim(),void 0!==e.subscriptionPermission&&ai.encode(e.subscriptionPermission,t.uint32(90).fork()).ldelim(),void 0!==e.syncState&&ci.encode(e.syncState,t.uint32(98).fork()).ldelim(),void 0!==e.simulate&&ui.encode(e.simulate,t.uint32(106).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={offer:void 0,answer:void 0,trickle:void 0,addTrack:void 0,mute:void 0,subscription:void 0,trackSetting:void 0,leave:void 0,updateLayers:void 0,subscriptionPermission:void 0,syncState:void 0,simulate:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.offer=Qt.decode(i,i.uint32());break;case 2:r.answer=Qt.decode(i,i.uint32());break;case 3:r.trickle=Bt.decode(i,i.uint32());break;case 4:r.addTrack=Jt.decode(i,i.uint32());break;case 5:r.mute=jt.decode(i,i.uint32());break;case 6:r.subscription=Gt.decode(i,i.uint32());break;case 7:r.trackSetting=Kt.decode(i,i.uint32());break;case 8:r.leave=Ht.decode(i,i.uint32());break;case 10:r.updateLayers=zt.decode(i,i.uint32());break;case 11:r.subscriptionPermission=ai.decode(i,i.uint32());break;case 12:r.syncState=ci.decode(i,i.uint32());break;case 13:r.simulate=ui.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({offer:li(e.offer)?Qt.fromJSON(e.offer):void 0,answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,trickle:li(e.trickle)?Bt.fromJSON(e.trickle):void 0,addTrack:li(e.addTrack)?Jt.fromJSON(e.addTrack):void 0,mute:li(e.mute)?jt.fromJSON(e.mute):void 0,subscription:li(e.subscription)?Gt.fromJSON(e.subscription):void 0,trackSetting:li(e.trackSetting)?Kt.fromJSON(e.trackSetting):void 0,leave:li(e.leave)?Ht.fromJSON(e.leave):void 0,updateLayers:li(e.updateLayers)?zt.fromJSON(e.updateLayers):void 0,subscriptionPermission:li(e.subscriptionPermission)?ai.fromJSON(e.subscriptionPermission):void 0,syncState:li(e.syncState)?ci.fromJSON(e.syncState):void 0,simulate:li(e.simulate)?ui.fromJSON(e.simulate):void 0}),toJSON(e){const t={};return void 0!==e.offer&&(t.offer=e.offer?Qt.toJSON(e.offer):void 0),void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.trickle&&(t.trickle=e.trickle?Bt.toJSON(e.trickle):void 0),void 0!==e.addTrack&&(t.addTrack=e.addTrack?Jt.toJSON(e.addTrack):void 0),void 0!==e.mute&&(t.mute=e.mute?jt.toJSON(e.mute):void 0),void 0!==e.subscription&&(t.subscription=e.subscription?Gt.toJSON(e.subscription):void 0),void 0!==e.trackSetting&&(t.trackSetting=e.trackSetting?Kt.toJSON(e.trackSetting):void 0),void 0!==e.leave&&(t.leave=e.leave?Ht.toJSON(e.leave):void 0),void 0!==e.updateLayers&&(t.updateLayers=e.updateLayers?zt.toJSON(e.updateLayers):void 0),void 0!==e.subscriptionPermission&&(t.subscriptionPermission=e.subscriptionPermission?ai.toJSON(e.subscriptionPermission):void 0),void 0!==e.syncState&&(t.syncState=e.syncState?ci.toJSON(e.syncState):void 0),void 0!==e.simulate&&(t.simulate=e.simulate?ui.toJSON(e.simulate):void 0),t},fromPartial(e){const t={offer:void 0,answer:void 0,trickle:void 0,addTrack:void 0,mute:void 0,subscription:void 0,trackSetting:void 0,leave:void 0,updateLayers:void 0,subscriptionPermission:void 0,syncState:void 0,simulate:void 0};return t.offer=void 0!==e.offer&&null!==e.offer?Qt.fromPartial(e.offer):void 0,t.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,t.trickle=void 0!==e.trickle&&null!==e.trickle?Bt.fromPartial(e.trickle):void 0,t.addTrack=void 0!==e.addTrack&&null!==e.addTrack?Jt.fromPartial(e.addTrack):void 0,t.mute=void 0!==e.mute&&null!==e.mute?jt.fromPartial(e.mute):void 0,t.subscription=void 0!==e.subscription&&null!==e.subscription?Gt.fromPartial(e.subscription):void 0,t.trackSetting=void 0!==e.trackSetting&&null!==e.trackSetting?Kt.fromPartial(e.trackSetting):void 0,t.leave=void 0!==e.leave&&null!==e.leave?Ht.fromPartial(e.leave):void 0,t.updateLayers=void 0!==e.updateLayers&&null!==e.updateLayers?zt.fromPartial(e.updateLayers):void 0,t.subscriptionPermission=void 0!==e.subscriptionPermission&&null!==e.subscriptionPermission?ai.fromPartial(e.subscriptionPermission):void 0,t.syncState=void 0!==e.syncState&&null!==e.syncState?ci.fromPartial(e.syncState):void 0,t.simulate=void 0!==e.simulate&&null!==e.simulate?ui.fromPartial(e.simulate):void 0,t}};const xt={encode:(e,t=Ze.Writer.create())=>(void 0!==e.join&&Vt.encode(e.join,t.uint32(10).fork()).ldelim(),void 0!==e.answer&&Qt.encode(e.answer,t.uint32(18).fork()).ldelim(),void 0!==e.offer&&Qt.encode(e.offer,t.uint32(26).fork()).ldelim(),void 0!==e.trickle&&Bt.encode(e.trickle,t.uint32(34).fork()).ldelim(),void 0!==e.update&&Wt.encode(e.update,t.uint32(42).fork()).ldelim(),void 0!==e.trackPublished&&Ft.encode(e.trackPublished,t.uint32(50).fork()).ldelim(),void 0!==e.leave&&Ht.encode(e.leave,t.uint32(66).fork()).ldelim(),void 0!==e.mute&&jt.encode(e.mute,t.uint32(74).fork()).ldelim(),void 0!==e.speakersChanged&&$t.encode(e.speakersChanged,t.uint32(82).fork()).ldelim(),void 0!==e.roomUpdate&&Yt.encode(e.roomUpdate,t.uint32(90).fork()).ldelim(),void 0!==e.connectionQuality&&ei.encode(e.connectionQuality,t.uint32(98).fork()).ldelim(),void 0!==e.streamStateUpdate&&ii.encode(e.streamStateUpdate,t.uint32(106).fork()).ldelim(),void 0!==e.subscribedQualityUpdate&&ri.encode(e.subscribedQualityUpdate,t.uint32(114).fork()).ldelim(),void 0!==e.subscriptionPermissionUpdate&&oi.encode(e.subscriptionPermissionUpdate,t.uint32(122).fork()).ldelim(),void 0!==e.refreshToken&&t.uint32(130).string(e.refreshToken),void 0!==e.trackUnpublished&&qt.encode(e.trackUnpublished,t.uint32(138).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={join:void 0,answer:void 0,offer:void 0,trickle:void 0,update:void 0,trackPublished:void 0,leave:void 0,mute:void 0,speakersChanged:void 0,roomUpdate:void 0,connectionQuality:void 0,streamStateUpdate:void 0,subscribedQualityUpdate:void 0,subscriptionPermissionUpdate:void 0,refreshToken:void 0,trackUnpublished:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.join=Vt.decode(i,i.uint32());break;case 2:r.answer=Qt.decode(i,i.uint32());break;case 3:r.offer=Qt.decode(i,i.uint32());break;case 4:r.trickle=Bt.decode(i,i.uint32());break;case 5:r.update=Wt.decode(i,i.uint32());break;case 6:r.trackPublished=Ft.decode(i,i.uint32());break;case 8:r.leave=Ht.decode(i,i.uint32());break;case 9:r.mute=jt.decode(i,i.uint32());break;case 10:r.speakersChanged=$t.decode(i,i.uint32());break;case 11:r.roomUpdate=Yt.decode(i,i.uint32());break;case 12:r.connectionQuality=ei.decode(i,i.uint32());break;case 13:r.streamStateUpdate=ii.decode(i,i.uint32());break;case 14:r.subscribedQualityUpdate=ri.decode(i,i.uint32());break;case 15:r.subscriptionPermissionUpdate=oi.decode(i,i.uint32());break;case 16:r.refreshToken=i.string();break;case 17:r.trackUnpublished=qt.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({join:li(e.join)?Vt.fromJSON(e.join):void 0,answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,offer:li(e.offer)?Qt.fromJSON(e.offer):void 0,trickle:li(e.trickle)?Bt.fromJSON(e.trickle):void 0,update:li(e.update)?Wt.fromJSON(e.update):void 0,trackPublished:li(e.trackPublished)?Ft.fromJSON(e.trackPublished):void 0,leave:li(e.leave)?Ht.fromJSON(e.leave):void 0,mute:li(e.mute)?jt.fromJSON(e.mute):void 0,speakersChanged:li(e.speakersChanged)?$t.fromJSON(e.speakersChanged):void 0,roomUpdate:li(e.roomUpdate)?Yt.fromJSON(e.roomUpdate):void 0,connectionQuality:li(e.connectionQuality)?ei.fromJSON(e.connectionQuality):void 0,streamStateUpdate:li(e.streamStateUpdate)?ii.fromJSON(e.streamStateUpdate):void 0,subscribedQualityUpdate:li(e.subscribedQualityUpdate)?ri.fromJSON(e.subscribedQualityUpdate):void 0,subscriptionPermissionUpdate:li(e.subscriptionPermissionUpdate)?oi.fromJSON(e.subscriptionPermissionUpdate):void 0,refreshToken:li(e.refreshToken)?String(e.refreshToken):void 0,trackUnpublished:li(e.trackUnpublished)?qt.fromJSON(e.trackUnpublished):void 0}),toJSON(e){const t={};return void 0!==e.join&&(t.join=e.join?Vt.toJSON(e.join):void 0),void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.offer&&(t.offer=e.offer?Qt.toJSON(e.offer):void 0),void 0!==e.trickle&&(t.trickle=e.trickle?Bt.toJSON(e.trickle):void 0),void 0!==e.update&&(t.update=e.update?Wt.toJSON(e.update):void 0),void 0!==e.trackPublished&&(t.trackPublished=e.trackPublished?Ft.toJSON(e.trackPublished):void 0),void 0!==e.leave&&(t.leave=e.leave?Ht.toJSON(e.leave):void 0),void 0!==e.mute&&(t.mute=e.mute?jt.toJSON(e.mute):void 0),void 0!==e.speakersChanged&&(t.speakersChanged=e.speakersChanged?$t.toJSON(e.speakersChanged):void 0),void 0!==e.roomUpdate&&(t.roomUpdate=e.roomUpdate?Yt.toJSON(e.roomUpdate):void 0),void 0!==e.connectionQuality&&(t.connectionQuality=e.connectionQuality?ei.toJSON(e.connectionQuality):void 0),void 0!==e.streamStateUpdate&&(t.streamStateUpdate=e.streamStateUpdate?ii.toJSON(e.streamStateUpdate):void 0),void 0!==e.subscribedQualityUpdate&&(t.subscribedQualityUpdate=e.subscribedQualityUpdate?ri.toJSON(e.subscribedQualityUpdate):void 0),void 0!==e.subscriptionPermissionUpdate&&(t.subscriptionPermissionUpdate=e.subscriptionPermissionUpdate?oi.toJSON(e.subscriptionPermissionUpdate):void 0),void 0!==e.refreshToken&&(t.refreshToken=e.refreshToken),void 0!==e.trackUnpublished&&(t.trackUnpublished=e.trackUnpublished?qt.toJSON(e.trackUnpublished):void 0),t},fromPartial(e){const t={join:void 0,answer:void 0,offer:void 0,trickle:void 0,update:void 0,trackPublished:void 0,leave:void 0,mute:void 0,speakersChanged:void 0,roomUpdate:void 0,connectionQuality:void 0,streamStateUpdate:void 0,subscribedQualityUpdate:void 0,subscriptionPermissionUpdate:void 0,refreshToken:void 0,trackUnpublished:void 0};return t.join=void 0!==e.join&&null!==e.join?Vt.fromPartial(e.join):void 0,t.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,t.offer=void 0!==e.offer&&null!==e.offer?Qt.fromPartial(e.offer):void 0,t.trickle=void 0!==e.trickle&&null!==e.trickle?Bt.fromPartial(e.trickle):void 0,t.update=void 0!==e.update&&null!==e.update?Wt.fromPartial(e.update):void 0,t.trackPublished=void 0!==e.trackPublished&&null!==e.trackPublished?Ft.fromPartial(e.trackPublished):void 0,t.leave=void 0!==e.leave&&null!==e.leave?Ht.fromPartial(e.leave):void 0,t.mute=void 0!==e.mute&&null!==e.mute?jt.fromPartial(e.mute):void 0,t.speakersChanged=void 0!==e.speakersChanged&&null!==e.speakersChanged?$t.fromPartial(e.speakersChanged):void 0,t.roomUpdate=void 0!==e.roomUpdate&&null!==e.roomUpdate?Yt.fromPartial(e.roomUpdate):void 0,t.connectionQuality=void 0!==e.connectionQuality&&null!==e.connectionQuality?ei.fromPartial(e.connectionQuality):void 0,t.streamStateUpdate=void 0!==e.streamStateUpdate&&null!==e.streamStateUpdate?ii.fromPartial(e.streamStateUpdate):void 0,t.subscribedQualityUpdate=void 0!==e.subscribedQualityUpdate&&null!==e.subscribedQualityUpdate?ri.fromPartial(e.subscribedQualityUpdate):void 0,t.subscriptionPermissionUpdate=void 0!==e.subscriptionPermissionUpdate&&null!==e.subscriptionPermissionUpdate?oi.fromPartial(e.subscriptionPermissionUpdate):void 0,t.refreshToken=e.refreshToken??void 0,t.trackUnpublished=void 0!==e.trackUnpublished&&null!==e.trackUnpublished?qt.fromPartial(e.trackUnpublished):void 0,t}};const Jt={encode(e,t=Ze.Writer.create()){""!==e.cid&&t.uint32(10).string(e.cid),""!==e.name&&t.uint32(18).string(e.name),0!==e.type&&t.uint32(24).int32(e.type),0!==e.width&&t.uint32(32).uint32(e.width),0!==e.height&&t.uint32(40).uint32(e.height),!0===e.muted&&t.uint32(48).bool(e.muted),!0===e.disableDtx&&t.uint32(56).bool(e.disableDtx),0!==e.source&&t.uint32(64).int32(e.source);for(const i of e.layers)mt.encode(i,t.uint32(74).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={cid:"",name:"",type:0,width:0,height:0,muted:!1,disableDtx:!1,source:0,layers:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.cid=i.string();break;case 2:r.name=i.string();break;case 3:r.type=i.int32();break;case 4:r.width=i.uint32();break;case 5:r.height=i.uint32();break;case 6:r.muted=i.bool();break;case 7:r.disableDtx=i.bool();break;case 8:r.source=i.int32();break;case 9:r.layers.push(mt.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({cid:li(e.cid)?String(e.cid):"",name:li(e.name)?String(e.name):"",type:li(e.type)?Ye(e.type):0,width:li(e.width)?Number(e.width):0,height:li(e.height)?Number(e.height):0,muted:!!li(e.muted)&&Boolean(e.muted),disableDtx:!!li(e.disableDtx)&&Boolean(e.disableDtx),source:li(e.source)?et(e.source):0,layers:Array.isArray(e?.layers)?e.layers.map((e=>mt.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.cid&&(t.cid=e.cid),void 0!==e.name&&(t.name=e.name),void 0!==e.type&&(t.type=Xe(e.type)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.muted&&(t.muted=e.muted),void 0!==e.disableDtx&&(t.disableDtx=e.disableDtx),void 0!==e.source&&(t.source=tt(e.source)),e.layers?t.layers=e.layers.map((e=>e?mt.toJSON(e):void 0)):t.layers=[],t},fromPartial(e){const t={cid:"",name:"",type:0,width:0,height:0,muted:!1,disableDtx:!1,source:0,layers:[]};return t.cid=e.cid??"",t.name=e.name??"",t.type=e.type??0,t.width=e.width??0,t.height=e.height??0,t.muted=e.muted??!1,t.disableDtx=e.disableDtx??!1,t.source=e.source??0,t.layers=e.layers?.map((e=>mt.fromPartial(e)))||[],t}};const Bt={encode:(e,t=Ze.Writer.create())=>(""!==e.candidateInit&&t.uint32(10).string(e.candidateInit),0!==e.target&&t.uint32(16).int32(e.target),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={candidateInit:"",target:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.candidateInit=i.string();break;case 2:r.target=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({candidateInit:li(e.candidateInit)?String(e.candidateInit):"",target:li(e.target)?It(e.target):0}),toJSON(e){const t={};return void 0!==e.candidateInit&&(t.candidateInit=e.candidateInit),void 0!==e.target&&(t.target=Lt(e.target)),t},fromPartial(e){const t={candidateInit:"",target:0};return t.candidateInit=e.candidateInit??"",t.target=e.target??0,t}};const jt={encode:(e,t=Ze.Writer.create())=>(""!==e.sid&&t.uint32(10).string(e.sid),!0===e.muted&&t.uint32(16).bool(e.muted),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",muted:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.muted=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:li(e.sid)?String(e.sid):"",muted:!!li(e.muted)&&Boolean(e.muted)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.muted&&(t.muted=e.muted),t},fromPartial(e){const t={sid:"",muted:!1};return t.sid=e.sid??"",t.muted=e.muted??!1,t}};const Vt={encode(e,t=Ze.Writer.create()){void 0!==e.room&&ut.encode(e.room,t.uint32(10).fork()).ldelim(),void 0!==e.participant&&pt.encode(e.participant,t.uint32(18).fork()).ldelim();for(const i of e.otherParticipants)pt.encode(i,t.uint32(26).fork()).ldelim();""!==e.serverVersion&&t.uint32(34).string(e.serverVersion);for(const i of e.iceServers)Zt.encode(i,t.uint32(42).fork()).ldelim();return!0===e.subscriberPrimary&&t.uint32(48).bool(e.subscriberPrimary),""!==e.alternativeUrl&&t.uint32(58).string(e.alternativeUrl),void 0!==e.clientConfiguration&&Ct.encode(e.clientConfiguration,t.uint32(66).fork()).ldelim(),""!==e.serverRegion&&t.uint32(74).string(e.serverRegion),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={room:void 0,participant:void 0,otherParticipants:[],serverVersion:"",iceServers:[],subscriberPrimary:!1,alternativeUrl:"",clientConfiguration:void 0,serverRegion:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.room=ut.decode(i,i.uint32());break;case 2:r.participant=pt.decode(i,i.uint32());break;case 3:r.otherParticipants.push(pt.decode(i,i.uint32()));break;case 4:r.serverVersion=i.string();break;case 5:r.iceServers.push(Zt.decode(i,i.uint32()));break;case 6:r.subscriberPrimary=i.bool();break;case 7:r.alternativeUrl=i.string();break;case 8:r.clientConfiguration=Ct.decode(i,i.uint32());break;case 9:r.serverRegion=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({room:li(e.room)?ut.fromJSON(e.room):void 0,participant:li(e.participant)?pt.fromJSON(e.participant):void 0,otherParticipants:Array.isArray(e?.otherParticipants)?e.otherParticipants.map((e=>pt.fromJSON(e))):[],serverVersion:li(e.serverVersion)?String(e.serverVersion):"",iceServers:Array.isArray(e?.iceServers)?e.iceServers.map((e=>Zt.fromJSON(e))):[],subscriberPrimary:!!li(e.subscriberPrimary)&&Boolean(e.subscriberPrimary),alternativeUrl:li(e.alternativeUrl)?String(e.alternativeUrl):"",clientConfiguration:li(e.clientConfiguration)?Ct.fromJSON(e.clientConfiguration):void 0,serverRegion:li(e.serverRegion)?String(e.serverRegion):""}),toJSON(e){const t={};return void 0!==e.room&&(t.room=e.room?ut.toJSON(e.room):void 0),void 0!==e.participant&&(t.participant=e.participant?pt.toJSON(e.participant):void 0),e.otherParticipants?t.otherParticipants=e.otherParticipants.map((e=>e?pt.toJSON(e):void 0)):t.otherParticipants=[],void 0!==e.serverVersion&&(t.serverVersion=e.serverVersion),e.iceServers?t.iceServers=e.iceServers.map((e=>e?Zt.toJSON(e):void 0)):t.iceServers=[],void 0!==e.subscriberPrimary&&(t.subscriberPrimary=e.subscriberPrimary),void 0!==e.alternativeUrl&&(t.alternativeUrl=e.alternativeUrl),void 0!==e.clientConfiguration&&(t.clientConfiguration=e.clientConfiguration?Ct.toJSON(e.clientConfiguration):void 0),void 0!==e.serverRegion&&(t.serverRegion=e.serverRegion),t},fromPartial(e){const t={room:void 0,participant:void 0,otherParticipants:[],serverVersion:"",iceServers:[],subscriberPrimary:!1,alternativeUrl:"",clientConfiguration:void 0,serverRegion:""};return t.room=void 0!==e.room&&null!==e.room?ut.fromPartial(e.room):void 0,t.participant=void 0!==e.participant&&null!==e.participant?pt.fromPartial(e.participant):void 0,t.otherParticipants=e.otherParticipants?.map((e=>pt.fromPartial(e)))||[],t.serverVersion=e.serverVersion??"",t.iceServers=e.iceServers?.map((e=>Zt.fromPartial(e)))||[],t.subscriberPrimary=e.subscriberPrimary??!1,t.alternativeUrl=e.alternativeUrl??"",t.clientConfiguration=void 0!==e.clientConfiguration&&null!==e.clientConfiguration?Ct.fromPartial(e.clientConfiguration):void 0,t.serverRegion=e.serverRegion??"",t}};const Ft={encode:(e,t=Ze.Writer.create())=>(""!==e.cid&&t.uint32(10).string(e.cid),void 0!==e.track&&ft.encode(e.track,t.uint32(18).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={cid:"",track:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.cid=i.string();break;case 2:r.track=ft.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({cid:li(e.cid)?String(e.cid):"",track:li(e.track)?ft.fromJSON(e.track):void 0}),toJSON(e){const t={};return void 0!==e.cid&&(t.cid=e.cid),void 0!==e.track&&(t.track=e.track?ft.toJSON(e.track):void 0),t},fromPartial(e){const t={cid:"",track:void 0};return t.cid=e.cid??"",t.track=void 0!==e.track&&null!==e.track?ft.fromPartial(e.track):void 0,t}};const qt={encode:(e,t=Ze.Writer.create())=>(""!==e.trackSid&&t.uint32(10).string(e.trackSid),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:""};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.trackSid=i.string();else i.skipType(7&e)}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):""}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),t},fromPartial(e){const t={trackSid:""};return t.trackSid=e.trackSid??"",t}};const Qt={encode:(e,t=Ze.Writer.create())=>(""!==e.type&&t.uint32(10).string(e.type),""!==e.sdp&&t.uint32(18).string(e.sdp),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={type:"",sdp:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.type=i.string();break;case 2:r.sdp=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({type:li(e.type)?String(e.type):"",sdp:li(e.sdp)?String(e.sdp):""}),toJSON(e){const t={};return void 0!==e.type&&(t.type=e.type),void 0!==e.sdp&&(t.sdp=e.sdp),t},fromPartial(e){const t={type:"",sdp:""};return t.type=e.type??"",t.sdp=e.sdp??"",t}};const Wt={encode(e,t=Ze.Writer.create()){for(const i of e.participants)pt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participants:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.participants.push(pt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({participants:Array.isArray(e?.participants)?e.participants.map((e=>pt.fromJSON(e))):[]}),toJSON(e){const t={};return e.participants?t.participants=e.participants.map((e=>e?pt.toJSON(e):void 0)):t.participants=[],t},fromPartial(e){const t={participants:[]};return t.participants=e.participants?.map((e=>pt.fromPartial(e)))||[],t}};const Gt={encode(e,t=Ze.Writer.create()){for(const i of e.trackSids)t.uint32(10).string(i);!0===e.subscribe&&t.uint32(16).bool(e.subscribe);for(const i of e.participantTracks)yt.encode(i,t.uint32(26).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSids:[],subscribe:!1,participantTracks:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSids.push(i.string());break;case 2:r.subscribe=i.bool();break;case 3:r.participantTracks.push(yt.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSids:Array.isArray(e?.trackSids)?e.trackSids.map((e=>String(e))):[],subscribe:!!li(e.subscribe)&&Boolean(e.subscribe),participantTracks:Array.isArray(e?.participantTracks)?e.participantTracks.map((e=>yt.fromJSON(e))):[]}),toJSON(e){const t={};return e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],void 0!==e.subscribe&&(t.subscribe=e.subscribe),e.participantTracks?t.participantTracks=e.participantTracks.map((e=>e?yt.toJSON(e):void 0)):t.participantTracks=[],t},fromPartial(e){const t={trackSids:[],subscribe:!1,participantTracks:[]};return t.trackSids=e.trackSids?.map((e=>e))||[],t.subscribe=e.subscribe??!1,t.participantTracks=e.participantTracks?.map((e=>yt.fromPartial(e)))||[],t}};const Kt={encode(e,t=Ze.Writer.create()){for(const i of e.trackSids)t.uint32(10).string(i);return!0===e.disabled&&t.uint32(24).bool(e.disabled),0!==e.quality&&t.uint32(32).int32(e.quality),0!==e.width&&t.uint32(40).uint32(e.width),0!==e.height&&t.uint32(48).uint32(e.height),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSids:[],disabled:!1,quality:0,width:0,height:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSids.push(i.string());break;case 3:r.disabled=i.bool();break;case 4:r.quality=i.int32();break;case 5:r.width=i.uint32();break;case 6:r.height=i.uint32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSids:Array.isArray(e?.trackSids)?e.trackSids.map((e=>String(e))):[],disabled:!!li(e.disabled)&&Boolean(e.disabled),quality:li(e.quality)?it(e.quality):0,width:li(e.width)?Number(e.width):0,height:li(e.height)?Number(e.height):0}),toJSON(e){const t={};return e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],void 0!==e.disabled&&(t.disabled=e.disabled),void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),t},fromPartial(e){const t={trackSids:[],disabled:!1,quality:0,width:0,height:0};return t.trackSids=e.trackSids?.map((e=>e))||[],t.disabled=e.disabled??!1,t.quality=e.quality??0,t.width=e.width??0,t.height=e.height??0,t}};const Ht={encode:(e,t=Ze.Writer.create())=>(!0===e.canReconnect&&t.uint32(8).bool(e.canReconnect),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={canReconnect:!1};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.canReconnect=i.bool();else i.skipType(7&e)}return r},fromJSON:e=>({canReconnect:!!li(e.canReconnect)&&Boolean(e.canReconnect)}),toJSON(e){const t={};return void 0!==e.canReconnect&&(t.canReconnect=e.canReconnect),t},fromPartial(e){const t={canReconnect:!1};return t.canReconnect=e.canReconnect??!1,t}};const zt={encode(e,t=Ze.Writer.create()){""!==e.trackSid&&t.uint32(10).string(e.trackSid);for(const i of e.layers)mt.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:"",layers:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSid=i.string();break;case 2:r.layers.push(mt.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):"",layers:Array.isArray(e?.layers)?e.layers.map((e=>mt.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),e.layers?t.layers=e.layers.map((e=>e?mt.toJSON(e):void 0)):t.layers=[],t},fromPartial(e){const t={trackSid:"",layers:[]};return t.trackSid=e.trackSid??"",t.layers=e.layers?.map((e=>mt.fromPartial(e)))||[],t}};const Zt={encode(e,t=Ze.Writer.create()){for(const i of e.urls)t.uint32(10).string(i);return""!==e.username&&t.uint32(18).string(e.username),""!==e.credential&&t.uint32(26).string(e.credential),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={urls:[],username:"",credential:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.urls.push(i.string());break;case 2:r.username=i.string();break;case 3:r.credential=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({urls:Array.isArray(e?.urls)?e.urls.map((e=>String(e))):[],username:li(e.username)?String(e.username):"",credential:li(e.credential)?String(e.credential):""}),toJSON(e){const t={};return e.urls?t.urls=e.urls.map((e=>e)):t.urls=[],void 0!==e.username&&(t.username=e.username),void 0!==e.credential&&(t.credential=e.credential),t},fromPartial(e){const t={urls:[],username:"",credential:""};return t.urls=e.urls?.map((e=>e))||[],t.username=e.username??"",t.credential=e.credential??"",t}};const $t={encode(e,t=Ze.Writer.create()){for(const i of e.speakers)bt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakers:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.speakers.push(bt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({speakers:Array.isArray(e?.speakers)?e.speakers.map((e=>bt.fromJSON(e))):[]}),toJSON(e){const t={};return e.speakers?t.speakers=e.speakers.map((e=>e?bt.toJSON(e):void 0)):t.speakers=[],t},fromPartial(e){const t={speakers:[]};return t.speakers=e.speakers?.map((e=>bt.fromPartial(e)))||[],t}};const Yt={encode:(e,t=Ze.Writer.create())=>(void 0!==e.room&&ut.encode(e.room,t.uint32(10).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={room:void 0};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.room=ut.decode(i,i.uint32());else i.skipType(7&e)}return r},fromJSON:e=>({room:li(e.room)?ut.fromJSON(e.room):void 0}),toJSON(e){const t={};return void 0!==e.room&&(t.room=e.room?ut.toJSON(e.room):void 0),t},fromPartial(e){const t={room:void 0};return t.room=void 0!==e.room&&null!==e.room?ut.fromPartial(e.room):void 0,t}};const Xt={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),0!==e.quality&&t.uint32(16).int32(e.quality),0!==e.score&&t.uint32(29).float(e.score),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",quality:0,score:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.quality=i.int32();break;case 3:r.score=i.float();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",quality:li(e.quality)?rt(e.quality):0,score:li(e.score)?Number(e.score):0}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.quality&&(t.quality=function(e){switch(e){case We.POOR:return"POOR";case We.GOOD:return"GOOD";case We.EXCELLENT:return"EXCELLENT";default:return"UNKNOWN"}}(e.quality)),void 0!==e.score&&(t.score=e.score),t},fromPartial(e){const t={participantSid:"",quality:0,score:0};return t.participantSid=e.participantSid??"",t.quality=e.quality??0,t.score=e.score??0,t}};const ei={encode(e,t=Ze.Writer.create()){for(const i of e.updates)Xt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={updates:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.updates.push(Xt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({updates:Array.isArray(e?.updates)?e.updates.map((e=>Xt.fromJSON(e))):[]}),toJSON(e){const t={};return e.updates?t.updates=e.updates.map((e=>e?Xt.toJSON(e):void 0)):t.updates=[],t},fromPartial(e){const t={updates:[]};return t.updates=e.updates?.map((e=>Xt.fromPartial(e)))||[],t}};const ti={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),""!==e.trackSid&&t.uint32(18).string(e.trackSid),0!==e.state&&t.uint32(24).int32(e.state),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSid:"",state:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSid=i.string();break;case 3:r.state=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",trackSid:li(e.trackSid)?String(e.trackSid):"",state:li(e.state)?Mt(e.state):0}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.trackSid&&(t.trackSid=e.trackSid),void 0!==e.state&&(t.state=function(e){switch(e){case Ut.ACTIVE:return"ACTIVE";case Ut.PAUSED:return"PAUSED";default:return"UNKNOWN"}}(e.state)),t},fromPartial(e){const t={participantSid:"",trackSid:"",state:0};return t.participantSid=e.participantSid??"",t.trackSid=e.trackSid??"",t.state=e.state??0,t}};const ii={encode(e,t=Ze.Writer.create()){for(const i of e.streamStates)ti.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={streamStates:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.streamStates.push(ti.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({streamStates:Array.isArray(e?.streamStates)?e.streamStates.map((e=>ti.fromJSON(e))):[]}),toJSON(e){const t={};return e.streamStates?t.streamStates=e.streamStates.map((e=>e?ti.toJSON(e):void 0)):t.streamStates=[],t},fromPartial(e){const t={streamStates:[]};return t.streamStates=e.streamStates?.map((e=>ti.fromPartial(e)))||[],t}};const ni={encode:(e,t=Ze.Writer.create())=>(0!==e.quality&&t.uint32(8).int32(e.quality),!0===e.enabled&&t.uint32(16).bool(e.enabled),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={quality:0,enabled:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.quality=i.int32();break;case 2:r.enabled=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({quality:li(e.quality)?it(e.quality):0,enabled:!!li(e.enabled)&&Boolean(e.enabled)}),toJSON(e){const t={};return void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.enabled&&(t.enabled=e.enabled),t},fromPartial(e){const t={quality:0,enabled:!1};return t.quality=e.quality??0,t.enabled=e.enabled??!1,t}};const ri={encode(e,t=Ze.Writer.create()){""!==e.trackSid&&t.uint32(10).string(e.trackSid);for(const i of e.subscribedQualities)ni.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:"",subscribedQualities:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSid=i.string();break;case 2:r.subscribedQualities.push(ni.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):"",subscribedQualities:Array.isArray(e?.subscribedQualities)?e.subscribedQualities.map((e=>ni.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),e.subscribedQualities?t.subscribedQualities=e.subscribedQualities.map((e=>e?ni.toJSON(e):void 0)):t.subscribedQualities=[],t},fromPartial(e){const t={trackSid:"",subscribedQualities:[]};return t.trackSid=e.trackSid??"",t.subscribedQualities=e.subscribedQualities?.map((e=>ni.fromPartial(e)))||[],t}};const si={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid),!0===e.allTracks&&t.uint32(16).bool(e.allTracks);for(const i of e.trackSids)t.uint32(26).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",allTracks:!1,trackSids:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.allTracks=i.bool();break;case 3:r.trackSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",allTracks:!!li(e.allTracks)&&Boolean(e.allTracks),trackSids:Array.isArray(e?.trackSids)?e.trackSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.allTracks&&(t.allTracks=e.allTracks),e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],t},fromPartial(e){const t={participantSid:"",allTracks:!1,trackSids:[]};return t.participantSid=e.participantSid??"",t.allTracks=e.allTracks??!1,t.trackSids=e.trackSids?.map((e=>e))||[],t}};const ai={encode(e,t=Ze.Writer.create()){!0===e.allParticipants&&t.uint32(8).bool(e.allParticipants);for(const i of e.trackPermissions)si.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={allParticipants:!1,trackPermissions:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.allParticipants=i.bool();break;case 2:r.trackPermissions.push(si.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({allParticipants:!!li(e.allParticipants)&&Boolean(e.allParticipants),trackPermissions:Array.isArray(e?.trackPermissions)?e.trackPermissions.map((e=>si.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.allParticipants&&(t.allParticipants=e.allParticipants),e.trackPermissions?t.trackPermissions=e.trackPermissions.map((e=>e?si.toJSON(e):void 0)):t.trackPermissions=[],t},fromPartial(e){const t={allParticipants:!1,trackPermissions:[]};return t.allParticipants=e.allParticipants??!1,t.trackPermissions=e.trackPermissions?.map((e=>si.fromPartial(e)))||[],t}};const oi={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),""!==e.trackSid&&t.uint32(18).string(e.trackSid),!0===e.allowed&&t.uint32(24).bool(e.allowed),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSid:"",allowed:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSid=i.string();break;case 3:r.allowed=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",trackSid:li(e.trackSid)?String(e.trackSid):"",allowed:!!li(e.allowed)&&Boolean(e.allowed)}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.trackSid&&(t.trackSid=e.trackSid),void 0!==e.allowed&&(t.allowed=e.allowed),t},fromPartial(e){const t={participantSid:"",trackSid:"",allowed:!1};return t.participantSid=e.participantSid??"",t.trackSid=e.trackSid??"",t.allowed=e.allowed??!1,t}};const ci={encode(e,t=Ze.Writer.create()){void 0!==e.answer&&Qt.encode(e.answer,t.uint32(10).fork()).ldelim(),void 0!==e.subscription&&Gt.encode(e.subscription,t.uint32(18).fork()).ldelim();for(const i of e.publishTracks)Ft.encode(i,t.uint32(26).fork()).ldelim();for(const i of e.dataChannels)di.encode(i,t.uint32(34).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={answer:void 0,subscription:void 0,publishTracks:[],dataChannels:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.answer=Qt.decode(i,i.uint32());break;case 2:r.subscription=Gt.decode(i,i.uint32());break;case 3:r.publishTracks.push(Ft.decode(i,i.uint32()));break;case 4:r.dataChannels.push(di.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,subscription:li(e.subscription)?Gt.fromJSON(e.subscription):void 0,publishTracks:Array.isArray(e?.publishTracks)?e.publishTracks.map((e=>Ft.fromJSON(e))):[],dataChannels:Array.isArray(e?.dataChannels)?e.dataChannels.map((e=>di.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.subscription&&(t.subscription=e.subscription?Gt.toJSON(e.subscription):void 0),e.publishTracks?t.publishTracks=e.publishTracks.map((e=>e?Ft.toJSON(e):void 0)):t.publishTracks=[],e.dataChannels?t.dataChannels=e.dataChannels.map((e=>e?di.toJSON(e):void 0)):t.dataChannels=[],t},fromPartial(e){const t={answer:void 0,subscription:void 0,publishTracks:[],dataChannels:[]};return t.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,t.subscription=void 0!==e.subscription&&null!==e.subscription?Gt.fromPartial(e.subscription):void 0,t.publishTracks=e.publishTracks?.map((e=>Ft.fromPartial(e)))||[],t.dataChannels=e.dataChannels?.map((e=>di.fromPartial(e)))||[],t}};const di={encode:(e,t=Ze.Writer.create())=>(""!==e.label&&t.uint32(10).string(e.label),0!==e.id&&t.uint32(16).uint32(e.id),0!==e.target&&t.uint32(24).int32(e.target),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={label:"",id:0,target:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.label=i.string();break;case 2:r.id=i.uint32();break;case 3:r.target=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({label:li(e.label)?String(e.label):"",id:li(e.id)?Number(e.id):0,target:li(e.target)?It(e.target):0}),toJSON(e){const t={};return void 0!==e.label&&(t.label=e.label),void 0!==e.id&&(t.id=Math.round(e.id)),void 0!==e.target&&(t.target=Lt(e.target)),t},fromPartial(e){const t={label:"",id:0,target:0};return t.label=e.label??"",t.id=e.id??0,t.target=e.target??0,t}};const ui={encode:(e,t=Ze.Writer.create())=>(void 0!==e.speakerUpdate&&t.uint32(8).int32(e.speakerUpdate),void 0!==e.nodeFailure&&t.uint32(16).bool(e.nodeFailure),void 0!==e.migration&&t.uint32(24).bool(e.migration),void 0!==e.serverLeave&&t.uint32(32).bool(e.serverLeave),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakerUpdate:void 0,nodeFailure:void 0,migration:void 0,serverLeave:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.speakerUpdate=i.int32();break;case 2:r.nodeFailure=i.bool();break;case 3:r.migration=i.bool();break;case 4:r.serverLeave=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({speakerUpdate:li(e.speakerUpdate)?Number(e.speakerUpdate):void 0,nodeFailure:li(e.nodeFailure)?Boolean(e.nodeFailure):void 0,migration:li(e.migration)?Boolean(e.migration):void 0,serverLeave:li(e.serverLeave)?Boolean(e.serverLeave):void 0}),toJSON(e){const t={};return void 0!==e.speakerUpdate&&(t.speakerUpdate=Math.round(e.speakerUpdate)),void 0!==e.nodeFailure&&(t.nodeFailure=e.nodeFailure),void 0!==e.migration&&(t.migration=e.migration),void 0!==e.serverLeave&&(t.serverLeave=e.serverLeave),t},fromPartial(e){const t={speakerUpdate:void 0,nodeFailure:void 0,migration:void 0,serverLeave:void 0};return t.speakerUpdate=e.speakerUpdate??void 0,t.nodeFailure=e.nodeFailure??void 0,t.migration=e.migration??void 0,t.serverLeave=e.serverLeave??void 0,t}};function li(e){return null!=e}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure());class hi extends Error{constructor(e,t){super(t||"an error has occured"),this.code=e}}class pi extends hi{constructor(e){super(1,e)}}class fi extends hi{constructor(e){super(20,e||"Track is invalid")}}class mi extends hi{constructor(e){super(10,e||"Unsupported server")}}class vi extends hi{constructor(e){super(12,e||"Unexpected connection state")}}var gi,bi,ki,Si,yi;e.MediaDeviceFailure=void 0,(gi=e.MediaDeviceFailure||(e.MediaDeviceFailure={})).PermissionDenied="PermissionDenied",gi.NotFound="NotFound",gi.DeviceInUse="DeviceInUse",gi.Other="Other",function(e){e.getFailure=function(t){if(t&&"name"in t)return"NotFoundError"===t.name||"DevicesNotFoundError"===t.name?e.NotFound:"NotAllowedError"===t.name||"PermissionDeniedError"===t.name?e.PermissionDenied:"NotReadableError"===t.name||"TrackStartError"===t.name?e.DeviceInUse:e.Other}}(e.MediaDeviceFailure||(e.MediaDeviceFailure={})),e.RoomEvent=void 0,(bi=e.RoomEvent||(e.RoomEvent={})).Reconnecting="reconnecting",bi.Reconnected="reconnected",bi.Disconnected="disconnected",bi.StateChanged="stateChanged",bi.MediaDevicesChanged="mediaDevicesChanged",bi.ParticipantConnected="participantConnected",bi.ParticipantDisconnected="participantDisconnected",bi.TrackPublished="trackPublished",bi.TrackSubscribed="trackSubscribed",bi.TrackSubscriptionFailed="trackSubscriptionFailed",bi.TrackUnpublished="trackUnpublished",bi.TrackUnsubscribed="trackUnsubscribed",bi.TrackMuted="trackMuted",bi.TrackUnmuted="trackUnmuted",bi.LocalTrackPublished="localTrackPublished",bi.LocalTrackUnpublished="localTrackUnpublished",bi.ActiveSpeakersChanged="activeSpeakersChanged",bi.MetadataChanged="metadataChanged",bi.ParticipantMetadataChanged="participantMetadataChanged",bi.RoomMetadataChanged="roomMetadataChanged",bi.DataReceived="dataReceived",bi.ConnectionQualityChanged="connectionQualityChanged",bi.TrackStreamStateChanged="trackStreamStateChanged",bi.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",bi.AudioPlaybackStatusChanged="audioPlaybackChanged",bi.MediaDevicesError="mediaDevicesError",bi.ParticipantPermissionsChanged="participantPermissionsChanged",e.ParticipantEvent=void 0,(ki=e.ParticipantEvent||(e.ParticipantEvent={})).TrackPublished="trackPublished",ki.TrackSubscribed="trackSubscribed",ki.TrackSubscriptionFailed="trackSubscriptionFailed",ki.TrackUnpublished="trackUnpublished",ki.TrackUnsubscribed="trackUnsubscribed",ki.TrackMuted="trackMuted",ki.TrackUnmuted="trackUnmuted",ki.LocalTrackPublished="localTrackPublished",ki.LocalTrackUnpublished="localTrackUnpublished",ki.MetadataChanged="metadataChanged",ki.ParticipantMetadataChanged="participantMetadataChanged",ki.DataReceived="dataReceived",ki.IsSpeakingChanged="isSpeakingChanged",ki.ConnectionQualityChanged="connectionQualityChanged",ki.TrackStreamStateChanged="trackStreamStateChanged",ki.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",ki.MediaDevicesError="mediaDevicesError",ki.ParticipantPermissionsChanged="participantPermissionsChanged",e.EngineEvent=void 0,(Si=e.EngineEvent||(e.EngineEvent={})).TransportsCreated="transportsCreated",Si.Connected="connected",Si.Disconnected="disconnected",Si.Resuming="resuming",Si.Resumed="resumed",Si.Restarting="restarting",Si.Restarted="restarted",Si.SignalResumed="signalResumed",Si.MediaTrackAdded="mediaTrackAdded",Si.ActiveSpeakersUpdate="activeSpeakersUpdate",Si.DataPacketReceived="dataPacketReceived",e.TrackEvent=void 0,(yi=e.TrackEvent||(e.TrackEvent={})).Message="message",yi.Muted="muted",yi.Unmuted="unmuted",yi.Ended="ended",yi.UpdateSettings="updateSettings",yi.UpdateSubscription="updateSubscription",yi.AudioPlaybackStarted="audioPlaybackStarted",yi.AudioPlaybackFailed="audioPlaybackFailed",yi.AudioSilenceDetected="audioSilenceDetected",yi.VisibilityChanged="visibilityChanged",yi.VideoDimensionsChanged="videoDimensionsChanged",yi.ElementAttached="elementAttached",yi.ElementDetached="elementDetached";const wi=2e3;function Ci(e,t){if(!t)return 0;let i,n;return"bytesReceived"in e?(i=e.bytesReceived,n=t.bytesReceived):"bytesSent"in e&&(i=e.bytesSent,n=t.bytesSent),void 0===i||void 0===n||void 0===e.timestamp||void 0===t.timestamp?0:8*(i-n)*1e3/(e.timestamp-t.timestamp)}const Ti="default";class Ei{static getInstance(){return void 0===this.instance&&(this.instance=new Ei),this.instance}async getDevices(e,t=!0){let i=await navigator.mediaDevices.enumerateDevices();if(t){if(0===i.length||i.some((t=>{const i=""===t.label,n=!e||t.kind===e;return i&&n}))){const t={video:"audioinput"!==e&&"audiooutput"!==e,audio:"videoinput"!==e};await navigator.mediaDevices.getUserMedia(t),i=await navigator.mediaDevices.enumerateDevices()}}if(e&&(i=i.filter((t=>t.kind===e))),i.length>1&&i[0].deviceId===Ti){const e=i[0];for(let t=1;t<i.length;t+=1)if(i[t].groupId===e.groupId){const e=i[0];i[0]=i[t],i[t]=e;break}return i.filter((t=>t!==e))}return i}async normalizeDeviceId(e,t,i){if(t!==Ti)return t;return(await this.getDevices(e)).find((e=>e.groupId===i&&e.deviceId!==Ti))?.deviceId}}Ei.mediaDeviceKinds=["audioinput","audiooutput","videoinput"];const Pi="0.18.2";async function Ri(e){return new Promise((t=>setTimeout(t,e)))}function Oi(){return!!Di()&&-1!==navigator.userAgent.indexOf("Firefox")}function Ni(){return!!Di()&&/Tablet|iPad|Mobile|Android|BlackBerry/.test(navigator.userAgent)}function Di(){return"undefined"!=typeof document}function Ai(e){for(const t of e)t.target.handleResize(t)}function Ui(e){for(const t of e)t.target.handleVisibilityChanged(t)}let Ii=null;const Li=()=>(Ii||(Ii=new ResizeObserver(Ai)),Ii);let Mi=null;const _i=()=>(Mi||(Mi=new IntersectionObserver(Ui,{root:document,rootMargin:"0px"})),Mi);var xi,Ji={exports:{}},Bi="object"==typeof Reflect?Reflect:null,ji=Bi&&"function"==typeof Bi.apply?Bi.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)};xi=Bi&&"function"==typeof Bi.ownKeys?Bi.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var Vi=Number.isNaN||function(e){return e!=e};function Fi(){Fi.init.call(this)}Ji.exports=Fi,Ji.exports.once=function(e,t){return new Promise((function(i,n){function r(i){e.removeListener(t,s),n(i)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",r),i([].slice.call(arguments))}Yi(e,t,s,{once:!0}),"error"!==t&&function(e,t,i){"function"==typeof e.on&&Yi(e,"error",t,i)}(e,r,{once:!0})}))},Fi.EventEmitter=Fi,Fi.prototype._events=void 0,Fi.prototype._eventsCount=0,Fi.prototype._maxListeners=void 0;var qi=10;function Qi(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function Wi(e){return void 0===e._maxListeners?Fi.defaultMaxListeners:e._maxListeners}function Gi(e,t,i,n){var r,s,a,o;if(Qi(i),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),a=s[t]),void 0===a)a=s[t]=i,++e._eventsCount;else if("function"==typeof a?a=s[t]=n?[i,a]:[a,i]:n?a.unshift(i):a.push(i),(r=Wi(e))>0&&a.length>r&&!a.warned){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,o=c,console&&console.warn&&console.warn(o)}return e}function Ki(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Hi(e,t,i){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},r=Ki.bind(n);return r.listener=i,n.wrapFn=r,r}function zi(e,t,i){var n=e._events;if(void 0===n)return[];var r=n[t];return void 0===r?[]:"function"==typeof r?i?[r.listener||r]:[r]:i?function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(r):$i(r,r.length)}function Zi(e){var t=this._events;if(void 0!==t){var i=t[e];if("function"==typeof i)return 1;if(void 0!==i)return i.length}return 0}function $i(e,t){for(var i=new Array(t),n=0;n<t;++n)i[n]=e[n];return i}function Yi(e,t,i,n){if("function"==typeof e.on)n.once?e.once(t,i):e.on(t,i);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function r(s){n.once&&e.removeEventListener(t,r),i(s)}))}}Object.defineProperty(Fi,"defaultMaxListeners",{enumerable:!0,get:function(){return qi},set:function(e){if("number"!=typeof e||e<0||Vi(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");qi=e}}),Fi.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Fi.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||Vi(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},Fi.prototype.getMaxListeners=function(){return Wi(this)},Fi.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var n="error"===e,r=this._events;if(void 0!==r)n=n&&void 0===r.error;else if(!n)return!1;if(n){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var o=r[e];if(void 0===o)return!1;if("function"==typeof o)ji(o,this,t);else{var c=o.length,d=$i(o,c);for(i=0;i<c;++i)ji(d[i],this,t)}return!0},Fi.prototype.addListener=function(e,t){return Gi(this,e,t,!1)},Fi.prototype.on=Fi.prototype.addListener,Fi.prototype.prependListener=function(e,t){return Gi(this,e,t,!0)},Fi.prototype.once=function(e,t){return Qi(t),this.on(e,Hi(this,e,t)),this},Fi.prototype.prependOnceListener=function(e,t){return Qi(t),this.prependListener(e,Hi(this,e,t)),this},Fi.prototype.removeListener=function(e,t){var i,n,r,s,a;if(Qi(t),void 0===(n=this._events))return this;if(void 0===(i=n[e]))return this;if(i===t||i.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(r=-1,s=i.length-1;s>=0;s--)if(i[s]===t||i[s].listener===t){a=i[s].listener,r=s;break}if(r<0)return this;0===r?i.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(i,r),1===i.length&&(n[e]=i[0]),void 0!==n.removeListener&&this.emit("removeListener",e,a||t)}return this},Fi.prototype.off=Fi.prototype.removeListener,Fi.prototype.removeAllListeners=function(e){var t,i,n;if(void 0===(i=this._events))return this;if(void 0===i.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==i[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete i[e]),this;if(0===arguments.length){var r,s=Object.keys(i);for(n=0;n<s.length;++n)"removeListener"!==(r=s[n])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},Fi.prototype.listeners=function(e){return zi(this,e,!0)},Fi.prototype.rawListeners=function(e){return zi(this,e,!1)},Fi.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Zi.call(e,t)},Fi.prototype.listenerCount=Zi,Fi.prototype.eventNames=function(){return this._eventsCount>0?xi(this._events):[]};const Xi=[];class en extends Ji.exports.EventEmitter{constructor(e,t){super(),this.attachedElements=[],this.isMuted=!1,this._currentBitrate=0,this.appVisibilityChangedListener=()=>{this.handleAppVisibilityChanged()},this.kind=t,this.mediaStreamTrack=e,this.source=en.Source.Unknown,Di()?(this.isInBackground="hidden"===document.visibilityState,document.addEventListener("visibilitychange",this.appVisibilityChangedListener)):this.isInBackground=!1}get currentBitrate(){return this._currentBitrate}attach(t){let i="audio";return this.kind===en.Kind.Video&&(i="video"),t||("audio"===i&&(Xi.forEach((e=>{null!==e.parentElement||t||(t=e)})),t&&Xi.splice(Xi.indexOf(t),1)),t||(t=document.createElement(i))),this.attachedElements.includes(t)||this.attachedElements.push(t),tn(this.mediaStreamTrack,t),t instanceof HTMLAudioElement&&t.play().then((()=>{this.emit(e.TrackEvent.AudioPlaybackStarted)})).catch((t=>{this.emit(e.TrackEvent.AudioPlaybackFailed,t)})),this.emit(e.TrackEvent.ElementAttached,t),t}detach(t){if(t){nn(this.mediaStreamTrack,t);const i=this.attachedElements.indexOf(t);return i>=0&&(this.attachedElements.splice(i,1),this.recycleElement(t),this.emit(e.TrackEvent.ElementDetached,t)),t}const i=[];return this.attachedElements.forEach((t=>{nn(this.mediaStreamTrack,t),i.push(t),this.recycleElement(t),this.emit(e.TrackEvent.ElementDetached,t)})),this.attachedElements=[],i}stop(){this.mediaStreamTrack.stop(),Di()&&document.removeEventListener("visibilitychange",this.appVisibilityChangedListener)}enable(){this.mediaStreamTrack.enabled=!0}disable(){this.mediaStreamTrack.enabled=!1}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),Xi.forEach((e=>{e.parentElement||(t=!1)})),t&&Xi.push(e)}}async handleAppVisibilityChanged(){this.isInBackground="hidden"===document.visibilityState}}function tn(e,t){let i,n;i=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream,n="audio"===e.kind?i.getAudioTracks():i.getVideoTracks(),n.includes(e)||(n.forEach((e=>{i.removeTrack(e)})),i.addTrack(e)),t.srcObject!==i&&(t.srcObject=i,(Di()&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||Oi())&&t instanceof HTMLVideoElement&&setTimeout((()=>{t.srcObject=i,t.play().catch((()=>{}))}),0)),t.autoplay=!0,t instanceof HTMLVideoElement&&(t.playsInline=!0)}function nn(e,t){if(t.srcObject instanceof MediaStream){t.srcObject.removeTrack(e),t.srcObject=null}}!function(e){let t,i,n;!function(e){e.Audio="audio",e.Video="video",e.Unknown="unknown"}(t=e.Kind||(e.Kind={})),function(e){e.Camera="camera",e.Microphone="microphone",e.ScreenShare="screen_share",e.ScreenShareAudio="screen_share_audio",e.Unknown="unknown"}(i=e.Source||(e.Source={})),function(e){e.Active="active",e.Paused="paused",e.Unknown="unknown"}(n=e.StreamState||(e.StreamState={})),e.kindToProto=function(e){switch(e){case t.Audio:return Fe.AUDIO;case t.Video:return Fe.VIDEO;default:return Fe.UNRECOGNIZED}},e.kindFromProto=function(e){switch(e){case Fe.AUDIO:return t.Audio;case Fe.VIDEO:return t.Video;default:return t.Unknown}},e.sourceToProto=function(e){switch(e){case i.Camera:return qe.CAMERA;case i.Microphone:return qe.MICROPHONE;case i.ScreenShare:return qe.SCREEN_SHARE;case i.ScreenShareAudio:return qe.SCREEN_SHARE_AUDIO;default:return qe.UNRECOGNIZED}},e.sourceFromProto=function(e){switch(e){case qe.CAMERA:return i.Camera;case qe.MICROPHONE:return i.Microphone;case qe.SCREEN_SHARE:return i.ScreenShare;case qe.SCREEN_SHARE_AUDIO:return i.ScreenShareAudio;default:return i.Unknown}},e.streamStateFromProto=function(e){switch(e){case Ut.ACTIVE:return n.Active;case Ut.PAUSED:return n.Paused;default:return n.Unknown}}}(en||(en={}));class rn extends en{constructor(t,i,n){super(t,i),this.handleEnded=()=>{this.isInBackground&&(this.reacquireTrack=!0),this.emit(e.TrackEvent.Ended,this)},this.mediaStreamTrack.addEventListener("ended",this.handleEnded),this.constraints=n??t.getConstraints(),this.reacquireTrack=!1,this.wasMuted=!1}get id(){return this.mediaStreamTrack.id}get dimensions(){if(this.kind!==en.Kind.Video)return;const{width:e,height:t}=this.mediaStreamTrack.getSettings();return e&&t?{width:e,height:t}:void 0}async getDeviceId(){if(this.source===en.Source.ScreenShare)return;const{deviceId:e,groupId:t}=this.mediaStreamTrack.getSettings(),i=this.kind===en.Kind.Audio?"audioinput":"videoinput";return Ei.getInstance().normalizeDeviceId(i,e,t)}async mute(){return this.setTrackMuted(!0),this}async unmute(){return this.setTrackMuted(!1),this}async restart(e){if(!this.sender)throw new fi("unable to restart an unpublished track");e||(e=this.constraints),s.debug("restarting track with constraints",e);const t={audio:!1,video:!1};this.kind===en.Kind.Video?t.video=e:t.audio=e,this.attachedElements.forEach((e=>{nn(this.mediaStreamTrack,e)})),this.mediaStreamTrack.removeEventListener("ended",this.handleEnded),this.mediaStreamTrack.stop();const i=await navigator.mediaDevices.getUserMedia(t),n=i.getTracks()[0];return n.addEventListener("ended",this.handleEnded),s.debug("re-acquired MediaStreamTrack"),await this.sender.replaceTrack(n),this.mediaStreamTrack=n,this.attachedElements.forEach((e=>{tn(n,e)})),this.mediaStream=i,this.constraints=e,this}setTrackMuted(t){this.isMuted!==t&&(this.isMuted=t,this.mediaStreamTrack.enabled=!t,this.emit(t?e.TrackEvent.Muted:e.TrackEvent.Unmuted,this))}get needsReAcquisition(){return"live"!==this.mediaStreamTrack.readyState||this.mediaStreamTrack.muted||!this.mediaStreamTrack.enabled||this.reacquireTrack}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),Ni()&&(s.debug(`visibility changed, is in Background: ${this.isInBackground}`),!this.isInBackground&&this.needsReAcquisition&&(s.debug(`track needs to be reaquired, restarting ${this.source}`),await this.restart(),this.reacquireTrack=!1,this.setTrackMuted(this.wasMuted)),this.isInBackground&&(this.wasMuted=this.isMuted))}}function sn(e,t,i){const n={...e};return!0===n.audio&&(n.audio={}),!0===n.video&&(n.video={}),n.audio&&an(n.audio,t),n.video&&an(n.video,i),n}function an(e,t){return Object.keys(t).forEach((i=>{void 0===e[i]&&(e[i]=t[i])})),e}function on(e){const t={};if(e.video)if("object"==typeof e.video){const i={},n=i,r=e.video;Object.keys(r).forEach((e=>{if("resolution"===e)an(n,r.resolution);else n[e]=r[e]})),t.video=i}else t.video=e.video;else t.video=!1;return e.audio?"object"==typeof e.audio?t.audio=e.audio:t.audio=!0:t.audio=!1,t}function cn(){const e=window.AudioContext||window.webkitAudioContext;if(e)return new e}class dn extends rn{constructor(e,t){super(e,en.Kind.Audio,t),this.stopOnMute=!1,this.monitorSender=async()=>{if(!this.sender)return void(this._currentBitrate=0);let e;try{e=await this.getSenderStats()}catch(e){return void s.error("could not get audio sender stats",e)}e&&this.prevStats&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorSender()}),wi)},this.checkForSilence()}async setDeviceId(e){this.constraints.deviceId!==e&&(this.constraints.deviceId=e,this.isMuted||await this.restartTrack())}async mute(){return this.source===en.Source.Microphone&&this.stopOnMute&&(s.debug("stopping mic track"),this.mediaStreamTrack.stop()),await super.mute(),this}async unmute(){return this.source===en.Source.Microphone&&this.stopOnMute&&(s.debug("reacquiring mic track"),await this.restartTrack()),await super.unmute(),this}async restartTrack(e){let t;if(e){const i=on({audio:e});"boolean"!=typeof i.audio&&(t=i.audio)}await this.restart(t)}async restart(e){const t=await super.restart(e);return this.checkForSilence(),t}startMonitor(){setTimeout((()=>{this.monitorSender()}),wi)}async getSenderStats(){if(!this.sender)return;let e;return(await this.sender.getStats()).forEach((t=>{"outbound-rtp"===t.type&&(e={type:"audio",streamId:t.id,packetsSent:t.packetsSent,packetsLost:t.packetsLost,bytesSent:t.bytesSent,timestamp:t.timestamp,roundTripTime:t.roundTripTime,jitter:t.jitter})})),e}async checkForSilence(){await async function(e,t=200){const i=cn();if(i){const n=i.createAnalyser();n.fftSize=2048;const r=n.frequencyBinCount,s=new Uint8Array(r);i.createMediaStreamSource(new MediaStream([e.mediaStreamTrack])).connect(n),await Ri(t),n.getByteTimeDomainData(s);const a=s.some((e=>128!==e&&0!==e));return i.close(),!a}return!1}(this)&&(this.isMuted||s.warn("silence detected on local audio track"),this.emit(e.TrackEvent.AudioSilenceDetected))}}class un extends rn{constructor(e,t){super(e,en.Kind.Video,t),this.monitorSender=async()=>{if(!this.sender)return void(this._currentBitrate=0);let e;try{e=await this.getSenderStats()}catch(e){return void s.error("could not get audio sender stats",{error:e})}const t=new Map(e.map((e=>[e.rid,e])));if(this.prevStats){let e=0;t.forEach(((t,i)=>{const n=this.prevStats?.get(i);e+=Ci(t,n)})),this._currentBitrate=e}this.prevStats=t,setTimeout((()=>{this.monitorSender()}),wi)}}get isSimulcast(){return!!(this.sender&&this.sender.getParameters().encodings.length>1)}startMonitor(e){this.signalClient=e;const t=this.sender?.getParameters();t&&(this.encodings=t.encodings),setTimeout((()=>{this.monitorSender()}),wi)}stop(){this.sender=void 0,this.mediaStreamTrack.getConstraints(),super.stop()}async mute(){return this.source===en.Source.Camera&&(s.debug("stopping camera track"),this.mediaStreamTrack.stop()),await super.mute(),this}async unmute(){return this.source===en.Source.Camera&&(s.debug("reacquiring camera track"),await this.restartTrack()),await super.unmute(),this}async getSenderStats(){if(!this.sender)return[];const e=[],t=await this.sender.getStats();return t.forEach((i=>{if("outbound-rtp"===i.type){const n={type:"video",streamId:i.id,frameHeight:i.frameHeight,frameWidth:i.frameWidth,firCount:i.firCount,pliCount:i.pliCount,nackCount:i.nackCount,packetsSent:i.packetsSent,bytesSent:i.bytesSent,framesSent:i.framesSent,timestamp:i.timestamp,rid:i.rid??"",retransmittedPacketsSent:i.retransmittedPacketsSent,qualityLimitationReason:i.qualityLimitationReason,qualityLimitationResolutionChanges:i.qualityLimitationResolutionChanges},r=t.get(i.remoteId);r&&(n.jitter=r.jitter,n.packetsLost=r.packetsLost,n.roundTripTime=r.roundTripTime),e.push(n)}})),e}setPublishingQuality(t){const i=[];for(let n=e.VideoQuality.LOW;n<=e.VideoQuality.HIGH;n+=1)i.push({quality:n,enabled:n<=t});s.debug(`setting publishing quality. max quality ${t}`),this.setPublishingLayers(i)}async setDeviceId(e){this.constraints.deviceId!==e&&(this.constraints.deviceId=e,this.isMuted||await this.restartTrack())}async restartTrack(e){let t;if(e){const i=on({video:e});"boolean"!=typeof i.video&&(t=i.video)}await this.restart(t)}async setPublishingLayers(e){if(s.debug("setting publishing layers",e),!this.sender||!this.encodings)return;const t=this.sender.getParameters(),{encodings:i}=t;if(!i)return;if(i.length!==this.encodings.length)return void s.warn("cannot set publishing layers, encodings mismatch");let n=!1;i.forEach(((t,i)=>{let r=t.rid??"";""===r&&(r="q");const a=ln(r),o=e.find((e=>e.quality===a));o&&t.active!==o.enabled&&(n=!0,t.active=o.enabled,s.debug(`setting layer ${o.quality} to ${t.active?"enabled":"disabled"}`),Oi()&&(o.enabled?(t.scaleResolutionDownBy=this.encodings[i].scaleResolutionDownBy,t.maxBitrate=this.encodings[i].maxBitrate,t.maxFrameRate=this.encodings[i].maxFrameRate):(t.scaleResolutionDownBy=4,t.maxBitrate=10,t.maxFrameRate=2)))})),n&&(t.encodings=i,await this.sender.setParameters(t))}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),Ni()&&this.isInBackground&&this.source===en.Source.Camera&&(this.mediaStreamTrack.enabled=!1)}}function ln(t){switch(t){case"f":return e.VideoQuality.HIGH;case"h":return e.VideoQuality.MEDIUM;case"q":return e.VideoQuality.LOW;default:return e.VideoQuality.UNRECOGNIZED}}class hn extends en{constructor(e,t,i,n){super(e,i),this.streamState=en.StreamState.Active,this.sid=t,this.receiver=n}setMuted(t){this.isMuted!==t&&(this.isMuted=t,this.emit(t?e.TrackEvent.Muted:e.TrackEvent.Unmuted,this))}setMediaStream(t){this.mediaStream=t,t.onremovetrack=()=>{this.receiver=void 0,this._currentBitrate=0,this.emit(e.TrackEvent.Ended,this)}}start(){this.startMonitor(),super.enable()}stop(){super.disable()}startMonitor(){setTimeout((()=>{this.monitorReceiver()}),wi)}}class pn extends hn{constructor(e,t,i){super(e,t,en.Kind.Audio,i),this.monitorReceiver=async()=>{if(!this.receiver)return void(this._currentBitrate=0);const e=await this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorReceiver()}),wi)},this.elementVolume=1}setVolume(e){for(const t of this.attachedElements)t.volume=e;this.elementVolume=e}getVolume(){return this.elementVolume}attach(e){return e?super.attach(e):e=super.attach(),e.volume=this.elementVolume,e}async getReceiverStats(){if(!this.receiver)return;let e;return(await this.receiver.getStats()).forEach((t=>{"inbound-rtp"===t.type&&(e={type:"audio",timestamp:t.timestamp,jitter:t.jitter,bytesReceived:t.bytesReceived,concealedSamples:t.concealedSamples,concealmentEvents:t.concealmentEvents,silentConcealedSamples:t.silentConcealedSamples,silentConcealmentEvents:t.silentConcealmentEvents,totalAudioEnergy:t.totalAudioEnergy,totalSamplesDuration:t.totalSamplesDuration})})),e}}function fn(e,t,i){var n,r,s;void 0===t&&(t=50),void 0===i&&(i={});var a=null!=(n=i.isImmediate)&&n,o=null!=(r=i.callback)&&r,c=i.maxWait,d=Date.now(),u=[];function l(){if(void 0!==c){var e=Date.now()-d;if(e+t>=c)return c-e}return t}var h=function(){var t=[].slice.call(arguments),i=this;return new Promise((function(n,r){var c=a&&void 0===s;if(void 0!==s&&clearTimeout(s),s=setTimeout((function(){if(s=void 0,d=Date.now(),!a){var n=e.apply(i,t);o&&o(n),u.forEach((function(e){return(0,e.resolve)(n)})),u=[]}}),l()),c){var h=e.apply(i,t);return o&&o(h),n(h)}u.push({resolve:n,reject:r})}))};return h.cancel=function(e){void 0!==s&&clearTimeout(s),u.forEach((function(t){return(0,t.reject)(e)})),u=[]},h}class mn extends hn{constructor(e,t,i,n){super(e,t,en.Kind.Video,i),this.elementInfos=[],this.monitorReceiver=async()=>{if(!this.receiver)return void(this._currentBitrate=0);const e=await this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorReceiver()}),wi)},this.handleVisibilityChanged=e=>{const{target:t,isIntersecting:i}=e,n=this.elementInfos.find((e=>e.element===t));n&&(n.visible=i,n.visibilityChangedAt=Date.now()),this.updateVisibility()},this.debouncedHandleResize=fn((()=>{this.updateDimensions()}),100),this.adaptiveStreamSettings=n}get isAdaptiveStream(){return void 0!==this.adaptiveStreamSettings}setMuted(e){super.setMuted(e),this.attachedElements.forEach((t=>{e?nn(this.mediaStreamTrack,t):tn(this.mediaStreamTrack,t)}))}attach(e){return e?super.attach(e):e=super.attach(),this.adaptiveStreamSettings&&void 0===this.elementInfos.find((t=>t.element===e))&&(this.elementInfos.push({element:e,visible:!0}),e.handleResize=this.debouncedHandleResize,e.handleVisibilityChanged=this.handleVisibilityChanged,_i().observe(e),Li().observe(e),this.debouncedHandleResize()),e}detach(e){let t=[];if(e)return this.stopObservingElement(e),super.detach(e);t=super.detach();for(const e of t)this.stopObservingElement(e);return t}async getReceiverStats(){if(!this.receiver)return;let e;return(await this.receiver.getStats()).forEach((t=>{"inbound-rtp"===t.type&&(e={type:"video",framesDecoded:t.framesDecoded,framesDropped:t.framesDropped,framesReceived:t.framesReceived,packetsReceived:t.packetsReceived,packetsLost:t.packetsLost,frameWidth:t.frameWidth,frameHeight:t.frameHeight,pliCount:t.pliCount,firCount:t.firCount,nackCount:t.nackCount,jitter:t.jitter,timestamp:t.timestamp,bytesReceived:t.bytesReceived})})),e}stopObservingElement(e){_i()?.unobserve(e),Li()?.unobserve(e),this.elementInfos=this.elementInfos.filter((t=>t.element!==e))}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),this.isAdaptiveStream&&Ni()&&this.updateVisibility()}updateVisibility(){const t=this.elementInfos.reduce(((e,t)=>Math.max(e,t.visibilityChangedAt||0)),0),i=this.elementInfos.some((e=>e.visible))&&!this.isInBackground;this.lastVisible!==i&&(!i&&Date.now()-t<100?setTimeout((()=>{this.updateVisibility()}),100):(this.lastVisible=i,this.emit(e.TrackEvent.VisibilityChanged,i,this)))}updateDimensions(){let t=0,i=0;for(const e of this.elementInfos){const n=this.adaptiveStreamSettings?.pixelDensity??1,r="screen"===n?window.devicePixelRatio:n,s=e.element.clientWidth*r,a=e.element.clientHeight*r;s+a>t+i&&(t=s,i=a)}this.lastDimensions?.width===t&&this.lastDimensions?.height===i||(this.lastDimensions={width:t,height:i},this.emit(e.TrackEvent.VideoDimensionsChanged,this.lastDimensions,this))}}class vn extends Ji.exports.EventEmitter{constructor(t,i,n){super(),this.metadataMuted=!1,this.handleMuted=()=>{this.emit(e.TrackEvent.Muted)},this.handleUnmuted=()=>{this.emit(e.TrackEvent.Unmuted)},this.kind=t,this.trackSid=i,this.trackName=n,this.source=en.Source.Unknown}setTrack(t){this.track&&(this.track.off(e.TrackEvent.Muted,this.handleMuted),this.track.off(e.TrackEvent.Unmuted,this.handleUnmuted)),this.track=t,t&&(t.on(e.TrackEvent.Muted,this.handleMuted),t.on(e.TrackEvent.Unmuted,this.handleUnmuted))}get isMuted(){return this.metadataMuted}get isEnabled(){return!0}get isSubscribed(){return void 0!==this.track}get audioTrack(){if(this.track instanceof dn||this.track instanceof pn)return this.track}get videoTrack(){if(this.track instanceof un||this.track instanceof mn)return this.track}updateInfo(e){this.trackSid=e.sid,this.trackName=e.name,this.source=en.sourceFromProto(e.source),this.mimeType=e.mimeType,this.kind===en.Kind.Video&&e.width>0&&(this.dimensions={width:e.width,height:e.height},this.simulcasted=e.simulcast),this.trackInfo=e}}!function(e){var t;(t=e.SubscriptionStatus||(e.SubscriptionStatus={})).Subscribed="subscribed",t.NotAllowed="not_allowed",t.Unsubscribed="unsubscribed"}(vn||(vn={}));class gn extends vn{constructor(t,i,n){super(t,i.sid,i.name),this.handleTrackEnded=t=>{this.emit(e.TrackEvent.Ended,t)},this.updateInfo(i),this.setTrack(n)}setTrack(t){this.track&&this.track.off(e.TrackEvent.Ended,this.handleTrackEnded),super.setTrack(t),t&&t.on(e.TrackEvent.Ended,this.handleTrackEnded)}get isMuted(){return this.track?this.track.isMuted:super.isMuted}get audioTrack(){return super.audioTrack}get videoTrack(){return super.videoTrack}async mute(){return this.track?.mute()}async unmute(){return this.track?.unmute()}}class bn{constructor(e,t,i,n){this.width=e,this.height=t,this.encoding={maxBitrate:i,maxFramerate:n}}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.width/this.height}}}var kn;e.AudioPresets=void 0,(kn=e.AudioPresets||(e.AudioPresets={})).telephone={maxBitrate:12e3},kn.speech={maxBitrate:2e4},kn.music={maxBitrate:32e3};const Sn={h90:new bn(160,90,6e4,15),h180:new bn(320,180,12e4,15),h216:new bn(384,216,18e4,15),h360:new bn(640,360,3e5,20),h540:new bn(960,540,6e5,25),h720:new bn(1280,720,2e6,30),h1080:new bn(1920,1080,3e6,30),h1440:new bn(2560,1440,5e6,30),h2160:new bn(3840,2160,8e6,30),qvga:new bn(320,180,12e4,10),vga:new bn(640,360,3e5,20),qhd:new bn(960,540,6e5,25),hd:new bn(1280,720,2e6,30),fhd:new bn(1920,1080,3e6,30)},yn={h120:new bn(160,120,8e4,15),h180:new bn(240,180,1e5,15),h240:new bn(320,240,15e4,15),h360:new bn(480,360,225e3,20),h480:new bn(640,480,3e5,20),h540:new bn(720,540,45e4,25),h720:new bn(960,720,15e5,30),h1080:new bn(1440,1080,25e5,30),h1440:new bn(1920,1440,35e5,30),qvga:new bn(240,180,9e4,10),vga:new bn(480,360,225e3,20),qhd:new bn(720,540,45e4,25),hd:new bn(960,720,15e5,30),fhd:new bn(1440,1080,28e5,30)},wn={h360fps3:new bn(640,360,2e5,3),h720fps5:new bn(1280,720,4e5,5),h720fps15:new bn(1280,720,1e6,15),h1080fps15:new bn(1920,1080,15e5,15),h1080fps30:new bn(1920,1080,3e6,30),vga:new bn(640,360,2e5,3),hd_8:new bn(1280,720,4e5,5),hd_15:new bn(1280,720,1e6,15),fhd_15:new bn(1920,1080,15e5,15),fhd_30:new bn(1920,1080,3e6,30)};e.ConnectionQuality=void 0,function(e){e.Excellent="excellent",e.Good="good",e.Poor="poor",e.Unknown="unknown"}(e.ConnectionQuality||(e.ConnectionQuality={}));class Cn extends Ji.exports.EventEmitter{constructor(t,i){super(),this.audioLevel=0,this.isSpeaking=!1,this._connectionQuality=e.ConnectionQuality.Unknown,this.sid=t,this.identity=i,this.audioTracks=new Map,this.videoTracks=new Map,this.tracks=new Map}getTracks(){return Array.from(this.tracks.values())}getTrack(e){if(e!==en.Source.Unknown)for(const[,t]of this.tracks){if(t.source===e)return t;if(t.source===en.Source.Unknown){if(e===en.Source.Microphone&&t.kind===en.Kind.Audio&&"screen"!==t.trackName)return t;if(e===en.Source.Camera&&t.kind===en.Kind.Video&&"screen"!==t.trackName)return t;if(e===en.Source.ScreenShare&&t.kind===en.Kind.Video&&"screen"===t.trackName)return t;if(e===en.Source.ScreenShareAudio&&t.kind===en.Kind.Audio&&"screen"===t.trackName)return t}}}getTrackByName(e){for(const[,t]of this.tracks)if(t.trackName===e)return t}get connectionQuality(){return this._connectionQuality}get isCameraEnabled(){return!(this.getTrack(en.Source.Camera)?.isMuted??1)}get isMicrophoneEnabled(){return!(this.getTrack(en.Source.Microphone)?.isMuted??1)}get isScreenShareEnabled(){return!!this.getTrack(en.Source.ScreenShare)}get joinedAt(){return this.participantInfo?new Date(1e3*this.participantInfo.joinedAt):new Date}updateInfo(e){this.identity=e.identity,this.sid=e.sid,this.name=e.name,this.setMetadata(e.metadata),e.permission&&this.setPermissions(e.permission),this.participantInfo=e}setMetadata(t){const i=this.metadata!==t,n=this.metadata;this.metadata=t,i&&(this.emit(e.ParticipantEvent.MetadataChanged,n),this.emit(e.ParticipantEvent.ParticipantMetadataChanged,n))}setPermissions(e){const t=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;return this.permissions=e,t}setIsSpeaking(t){t!==this.isSpeaking&&(this.isSpeaking=t,t&&(this.lastSpokeAt=new Date),this.emit(e.ParticipantEvent.IsSpeakingChanged,t))}setConnectionQuality(t){const i=this._connectionQuality;this._connectionQuality=function(t){switch(t){case We.EXCELLENT:return e.ConnectionQuality.Excellent;case We.GOOD:return e.ConnectionQuality.Good;case We.POOR:return e.ConnectionQuality.Poor;default:return e.ConnectionQuality.Unknown}}(t),i!==this._connectionQuality&&this.emit(e.ParticipantEvent.ConnectionQualityChanged,this._connectionQuality)}addTrackPublication(t){t.on(e.TrackEvent.Muted,(()=>{this.emit(e.ParticipantEvent.TrackMuted,t)})),t.on(e.TrackEvent.Unmuted,(()=>{this.emit(e.ParticipantEvent.TrackUnmuted,t)}));const i=t;switch(i.track&&(i.track.sid=t.trackSid),this.tracks.set(t.trackSid,t),t.kind){case en.Kind.Audio:this.audioTracks.set(t.trackSid,t);break;case en.Kind.Video:this.videoTracks.set(t.trackSid,t)}}}function Tn(e,t){switch(e.kind){case"audio":return new dn(e,t);case"video":return new un(e,t);default:throw new fi(`unsupported track type: ${e.kind}`)}}const En=Object.values(Sn),Pn=Object.values(yn),Rn=Object.values(wn),On=[Sn.h180,Sn.h360],Nn=[yn.h180,yn.h360],Dn=["q","h","f"];function An(e,t,i,n){let r=n?.videoEncoding;e&&(r=n?.screenShareEncoding);const a=n?.simulcast;if(!r&&!a||!t||!i)return[{}];if(r||(r=function(e,t,i){const n=function(e,t,i){if(e)return Rn;const n=t>i?t/i:i/t;if(Math.abs(n-16/9)<Math.abs(n-4/3))return En;return Pn}(e,t,i);let{encoding:r}=n[0];const s=Math.max(t,i);for(let e=0;e<n.length;e+=1){const t=n[e];if(r=t.encoding,t.width>=s)break}return r}(e,t,i),s.debug("using video encoding",r)),!a)return[r];const o=new bn(t,i,r.maxBitrate,r.maxFramerate);let c,d=[];d=e?Ln(n?.screenShareSimulcastLayers)??Un(e,o):Ln(n?.videoSimulcastLayers)??Un(e,o);const u=d[0];d.length>1&&([,c]=d);const l=Math.max(t,i);return In(t,i,l>=960&&c?[u,c,o]:l>=480?[u,o]:[o])}function Un(e,t){if(e)return i=t,[{scaleResolutionDownBy:2,fps:3}].map((e=>new bn(Math.floor(i.width/e.scaleResolutionDownBy),Math.floor(i.height/e.scaleResolutionDownBy),Math.max(15e4,Math.floor(i.encoding.maxBitrate/(e.scaleResolutionDownBy**2*((i.encoding.maxFramerate??30)/e.fps)))),e.fps)));var i;const{width:n,height:r}=t,s=n>r?n/r:r/n;return Math.abs(s-16/9)<Math.abs(s-4/3)?On:Nn}function In(e,t,i){const n=[];return i.forEach(((i,r)=>{if(r>=Dn.length)return;const s=Math.min(e,t),a=Dn[r];n.push({rid:a,scaleResolutionDownBy:s/Math.min(i.width,i.height),maxBitrate:i.encoding.maxBitrate,maxFramerate:i.encoding.maxFramerate})})),n}function Ln(e){if(e)return e.sort(((e,t)=>{const{encoding:i}=e,{encoding:n}=t;return i.maxBitrate>n.maxBitrate?1:i.maxBitrate<n.maxBitrate?-1:i.maxBitrate===n.maxBitrate&&i.maxFramerate&&n.maxFramerate?i.maxFramerate>n.maxFramerate?1:-1:0}))}class Mn extends vn{constructor(){super(...arguments),this._allowed=!0,this.disabled=!1,this.currentVideoQuality=e.VideoQuality.HIGH,this.handleEnded=t=>{this.emit(e.TrackEvent.Ended,t)},this.handleVisibilityChange=e=>{s.debug(`adaptivestream video visibility ${this.trackSid}, visible=${e}`,{trackSid:this.trackSid}),this.disabled=!e,this.emitTrackUpdate()},this.handleVideoDimensionsChange=e=>{s.debug(`adaptivestream video dimensions ${e.width}x${e.height}`,{trackSid:this.trackSid}),this.videoDimensions=e,this.emitTrackUpdate()}}setSubscribed(t){this.subscribed=t;const i={trackSids:[this.trackSid],subscribe:this.subscribed,participantTracks:[{participantSid:"",trackSids:[this.trackSid]}]};this.emit(e.TrackEvent.UpdateSubscription,i)}get subscriptionStatus(){return!1!==this.subscribed&&super.isSubscribed?this._allowed?vn.SubscriptionStatus.Subscribed:vn.SubscriptionStatus.NotAllowed:vn.SubscriptionStatus.Unsubscribed}get isSubscribed(){return!1!==this.subscribed&&(!!this._allowed&&super.isSubscribed)}get isEnabled(){return!this.disabled}setEnabled(e){this.isManualOperationAllowed()&&this.disabled!==!e&&(this.disabled=!e,this.emitTrackUpdate())}setVideoQuality(e){this.isManualOperationAllowed()&&this.currentVideoQuality!==e&&(this.currentVideoQuality=e,this.videoDimensions=void 0,this.emitTrackUpdate())}setVideoDimensions(e){this.isManualOperationAllowed()&&(this.videoDimensions?.width===e.width&&this.videoDimensions?.height===e.height||(this.track instanceof mn&&(this.videoDimensions=e),this.currentVideoQuality=void 0,this.emitTrackUpdate()))}get videoQuality(){return this.currentVideoQuality}setTrack(t){this.track&&(this.track.off(e.TrackEvent.VideoDimensionsChanged,this.handleVideoDimensionsChange),this.track.off(e.TrackEvent.VisibilityChanged,this.handleVisibilityChange),this.track.off(e.TrackEvent.Ended,this.handleEnded)),super.setTrack(t),t&&(t.sid=this.trackSid,t.on(e.TrackEvent.VideoDimensionsChanged,this.handleVideoDimensionsChange),t.on(e.TrackEvent.VisibilityChanged,this.handleVisibilityChange),t.on(e.TrackEvent.Ended,this.handleEnded))}updateInfo(e){super.updateInfo(e),this.metadataMuted=e.muted,this.track?.setMuted(e.muted)}isManualOperationAllowed(){return this.isAdaptiveStream?(s.warn("adaptive stream is enabled, cannot change track settings",{trackSid:this.trackSid}),!1):!!this.isSubscribed||(s.warn("cannot update track settings when not subscribed",{trackSid:this.trackSid}),!1)}get isAdaptiveStream(){return this.track instanceof mn&&this.track.isAdaptiveStream}emitTrackUpdate(){const t=Kt.fromPartial({trackSids:[this.trackSid],disabled:this.disabled});this.videoDimensions?(t.width=this.videoDimensions.width,t.height=this.videoDimensions.height):void 0!==this.currentVideoQuality?t.quality=this.currentVideoQuality:t.quality=e.VideoQuality.HIGH,this.emit(e.TrackEvent.UpdateSettings,t)}}class _n extends Cn{constructor(e,t,i){super(t,i||""),this.signalClient=e,this.tracks=new Map,this.audioTracks=new Map,this.videoTracks=new Map}static fromParticipantInfo(e,t){const i=new _n(e,t.sid,t.identity);return i.updateInfo(t),i}addTrackPublication(t){super.addTrackPublication(t),t.on(e.TrackEvent.UpdateSettings,(e=>{this.signalClient.sendUpdateTrackSettings(e)})),t.on(e.TrackEvent.UpdateSubscription,(e=>{e.participantTracks.forEach((e=>{e.participantSid=this.sid})),this.signalClient.sendUpdateSubscription(e)})),t.on(e.TrackEvent.Ended,(i=>{this.emit(e.ParticipantEvent.TrackUnsubscribed,i,t)}))}getTrack(e){const t=super.getTrack(e);if(t)return t}getTrackByName(e){const t=super.getTrackByName(e);if(t)return t}setVolume(e){const t=this.getTrack(en.Source.Microphone);t&&t.track.setVolume(e)}getVolume(){const e=this.getTrack(en.Source.Microphone);if(e)return e.track.getVolume()}addSubscribedMediaTrack(t,i,n,r,a,o){let c=this.getTrackPublication(i);if(c||i.startsWith("TR")||this.tracks.forEach((e=>{c||t.kind!==e.kind.toString()||(c=e)})),!c)return 0===o?(s.error("could not find published track",{participant:this.sid,trackSid:i}),void this.emit(e.ParticipantEvent.TrackSubscriptionFailed,i)):(void 0===o&&(o=20),void setTimeout((()=>{this.addSubscribedMediaTrack(t,i,n,r,a,o-1)}),150));let d;return d="video"===t.kind?new mn(t,i,r,a):new pn(t,i,r),d.source=c.source,d.isMuted=c.isMuted,d.setMediaStream(n),d.start(),c.setTrack(d),this.emit(e.ParticipantEvent.TrackSubscribed,d,c),c}get hasMetadata(){return!!this.participantInfo}getTrackPublication(e){return this.tracks.get(e)}updateInfo(t){const i=this.hasMetadata;super.updateInfo(t);const n=new Map,r=new Map;t.tracks.forEach((e=>{let t=this.getTrackPublication(e.sid);if(t)t.updateInfo(e);else{const i=en.kindFromProto(e.type);if(!i)return;t=new Mn(i,e.sid,e.name),t.updateInfo(e),r.set(e.sid,t),this.addTrackPublication(t)}n.set(e.sid,t)})),i&&r.forEach((t=>{this.emit(e.ParticipantEvent.TrackPublished,t)})),this.tracks.forEach((e=>{n.has(e.trackSid)||this.unpublishTrack(e.trackSid,!0)}))}unpublishTrack(t,i){const n=this.tracks.get(t);if(!n)return;switch(this.tracks.delete(t),n.kind){case en.Kind.Audio:this.audioTracks.delete(t);break;case en.Kind.Video:this.videoTracks.delete(t)}const{track:r}=n;if(r){const{isSubscribed:t}=n;r.stop(),n.setTrack(void 0),t&&this.emit(e.ParticipantEvent.TrackUnsubscribed,r,n)}i&&this.emit(e.ParticipantEvent.TrackUnpublished,n)}emit(e,...t){return s.trace("participant event",{participant:this.sid,event:e,args:t}),super.emit(e,...t)}}class xn extends Cn{constructor(e,t,i,n){super(e,t),this.pendingPublishing=new Set,this.onTrackUnmuted=e=>{this.onTrackMuted(e,!1)},this.onTrackMuted=(e,t)=>{void 0===t&&(t=!0),e.sid?this.engine.updateMuteStatus(e.sid,t):s.error("could not update mute status for unpublished track",e)},this.handleSubscribedQualityUpdate=e=>{if(!this.roomOptions?.dynacast)return;const t=this.videoTracks.get(e.trackSid);t?t.videoTrack?.setPublishingLayers(e.subscribedQualities):s.warn("received subscribed quality update for unknown track",{method:"handleSubscribedQualityUpdate",sid:e.trackSid})},this.handleLocalTrackUnpublished=e=>{const t=this.tracks.get(e.trackSid);t?this.unpublishTrack(t.track):s.warn("received unpublished event for unknown track",{method:"handleLocalTrackUnpublished",trackSid:e.trackSid})},this.onTrackUnpublish=e=>{this.unpublishTrack(e)},this.audioTracks=new Map,this.videoTracks=new Map,this.tracks=new Map,this.engine=i,this.roomOptions=n,this.engine.client.onRemoteMuteChanged=(e,t)=>{const i=this.tracks.get(e);i&&i.track&&(t?i.mute():i.unmute())},this.engine.client.onSubscribedQualityUpdate=this.handleSubscribedQualityUpdate,this.engine.client.onLocalTrackUnpublished=this.handleLocalTrackUnpublished}get lastCameraError(){return this.cameraError}get lastMicrophoneError(){return this.microphoneError}getTrack(e){const t=super.getTrack(e);if(t)return t}getTrackByName(e){const t=super.getTrackByName(e);if(t)return t}setCameraEnabled(e){return this.setTrackEnabled(en.Source.Camera,e)}setMicrophoneEnabled(e){return this.setTrackEnabled(en.Source.Microphone,e)}setScreenShareEnabled(e){return this.setTrackEnabled(en.Source.ScreenShare,e)}setPermissions(t){const i=this.permissions,n=super.setPermissions(t);return n&&i&&this.emit(e.ParticipantEvent.ParticipantPermissionsChanged,i),n}async setTrackEnabled(t,i){s.debug("setTrackEnabled",{source:t,enabled:i});let n=this.getTrack(t);if(i)if(n)await n.unmute();else{let i;if(this.pendingPublishing.has(t))return void s.info("skipping duplicate published source",{source:t});this.pendingPublishing.add(t);try{switch(t){case en.Source.Camera:[i]=await this.createTracks({video:!0});break;case en.Source.Microphone:[i]=await this.createTracks({audio:!0});break;case en.Source.ScreenShare:[i]=await this.createScreenTracks({audio:!1});break;default:throw new fi(t)}n=await this.publishTrack(i)}catch(t){throw t instanceof Error&&!(t instanceof fi)&&this.emit(e.ParticipantEvent.MediaDevicesError,t),t}finally{this.pendingPublishing.delete(t)}}else n&&n.track&&(t===en.Source.ScreenShare?n=this.unpublishTrack(n.track):await n.mute());return n}async enableCameraAndMicrophone(){if(!this.pendingPublishing.has(en.Source.Camera)&&!this.pendingPublishing.has(en.Source.Microphone)){this.pendingPublishing.add(en.Source.Camera),this.pendingPublishing.add(en.Source.Microphone);try{const e=await this.createTracks({audio:!0,video:!0});await Promise.all(e.map((e=>this.publishTrack(e))))}finally{this.pendingPublishing.delete(en.Source.Camera),this.pendingPublishing.delete(en.Source.Microphone)}}}async createTracks(e){const t=on(sn(e,this.roomOptions?.audioCaptureDefaults,this.roomOptions?.videoCaptureDefaults));let i;try{i=await navigator.mediaDevices.getUserMedia(t)}catch(e){throw e instanceof Error&&(t.audio&&(this.microphoneError=e),t.video&&(this.cameraError=e)),e}return t.audio&&(this.microphoneError=void 0),t.video&&(this.cameraError=void 0),i.getTracks().map((n=>{const r="audio"===n.kind;let s;r?e.audio:e.video;const a=r?t.audio:t.video;"boolean"!=typeof a&&(s=a);const o=Tn(n,s);return o.kind===en.Kind.Video?o.source=en.Source.Camera:o.kind===en.Kind.Audio&&(o.source=en.Source.Microphone),o.mediaStream=i,o}))}async createScreenTracks(e){void 0===e&&(e={}),void 0===e.resolution&&(e.resolution=wn.h1080fps15.resolution);let t=!0;e.resolution&&(t={width:e.resolution.width,height:e.resolution.height,frameRate:e.resolution.frameRate});const i=await navigator.mediaDevices.getDisplayMedia({audio:e.audio??!1,video:t}),n=i.getVideoTracks();if(0===n.length)throw new fi("no video track found");const r=new un(n[0]);r.source=en.Source.ScreenShare;const s=[r];if(i.getAudioTracks().length>0){const e=new dn(i.getAudioTracks()[0]);e.source=en.Source.ScreenShareAudio,s.push(e)}return s}async publishTrack(t,i){const n={...this.roomOptions?.publishDefaults,...i};if(t instanceof MediaStreamTrack)switch(t.kind){case"audio":t=new dn(t);break;case"video":t=new un(t);break;default:throw new fi(`unsupported MediaStreamTrack kind ${t.kind}`)}let r;if(this.tracks.forEach((e=>{e.track&&e.track===t&&(r=e)})),r)return r;n.source&&(t.source=n.source),n.stopMicTrackOnMute&&t instanceof dn&&(t.stopOnMute=!0),t.source===en.Source.ScreenShare&&Oi()&&(n.simulcast=!1),t.on(e.TrackEvent.Muted,this.onTrackMuted),t.on(e.TrackEvent.Unmuted,this.onTrackUnmuted),t.on(e.TrackEvent.Ended,this.onTrackUnpublish);const a=Jt.fromPartial({cid:t.mediaStreamTrack.id,name:i?.name,type:en.kindToProto(t.kind),muted:t.isMuted,source:en.sourceToProto(t.source),disableDtx:!(n?.dtx??1)});let o;if(t.kind===en.Kind.Video){const i=t.mediaStreamTrack.getSettings(),r=i.width??t.dimensions?.width,s=i.height??t.dimensions?.height;a.width=r??0,a.height=s??0,o=An(t.source===en.Source.ScreenShare,r,s,n),a.layers=function(t,i,n){return n?n.map((r=>{const s=r.scaleResolutionDownBy??1;let a=ln(r.rid??"");return a===e.VideoQuality.UNRECOGNIZED&&1===n.length&&(a=e.VideoQuality.HIGH),{quality:a,width:t/s,height:i/s,bitrate:r.maxBitrate??0,ssrc:0}})):[{quality:e.VideoQuality.HIGH,width:t,height:i,bitrate:0,ssrc:0}]}(a.width,a.height,o)}else t.kind===en.Kind.Audio&&n.audioBitrate&&(o=[{maxBitrate:n.audioBitrate}]);const c=await this.engine.addTrack(a),d=new gn(t.kind,c,t);if(t.sid=c.sid,!this.engine.publisher)throw new vi("publisher is closed");s.debug(`publishing ${t.kind} with encodings`,{encodings:o,trackInfo:c});const u={direction:"sendonly"};o&&(u.sendEncodings=o);const l=this.engine.publisher.pc.addTransceiver(t.mediaStreamTrack,u);return this.engine.negotiate(),t.sender=l.sender,t instanceof un?t.startMonitor(this.engine.client):t instanceof dn&&t.startMonitor(),n.videoCodec&&this.setPreferredCodec(l,t.kind,n.videoCodec),this.addTrackPublication(d),this.emit(e.ParticipantEvent.LocalTrackPublished,d),d}unpublishTrack(t,i){const n=this.getPublicationForTrack(t);if(s.debug("unpublishing track",{track:t,method:"unpublishTrack"}),!n||!n.track)return void s.warn("track was not unpublished because no publication was found",{track:t,method:"unpublishTrack"});(t=n.track).off(e.TrackEvent.Muted,this.onTrackMuted),t.off(e.TrackEvent.Unmuted,this.onTrackUnmuted),t.off(e.TrackEvent.Ended,this.onTrackUnpublish),void 0===i&&(i=this.roomOptions?.stopLocalTrackOnUnpublish??!0),i&&t.stop();const{mediaStreamTrack:r}=t;if(this.engine.publisher){this.engine.publisher.pc.getSenders().forEach((e=>{if(e.track===r)try{this.engine.publisher?.pc.removeTrack(e),this.engine.negotiate()}catch(e){s.warn("failed to remove track",{error:e,method:"unpublishTrack"})}}))}switch(this.tracks.delete(n.trackSid),n.kind){case en.Kind.Audio:this.audioTracks.delete(n.trackSid);break;case en.Kind.Video:this.videoTracks.delete(n.trackSid)}return this.emit(e.ParticipantEvent.LocalTrackUnpublished,n),n.setTrack(void 0),n}unpublishTracks(e){const t=[];return e.forEach((e=>{const i=this.unpublishTrack(e);i&&t.push(i)})),t}async publishData(e,t,i){const n=[];void 0!==i&&i.forEach((e=>{e instanceof _n?n.push(e.sid):n.push(e)}));const r={kind:t,user:{participantSid:this.sid,payload:e,destinationSids:n}};await this.engine.sendDataPacket(r,t)}setTrackSubscriptionPermissions(e,t=[]){this.engine.client.sendUpdateSubscriptionPermissions(e,t.map((e=>function(e){if(!e.participantSid)throw new Error("Invalid track permission, missing participantSid");return{participantSid:e.participantSid,allTracks:e.allowAll??!1,trackSids:e.allowedTrackSids||[]}}(e))))}getPublicationForTrack(e){let t;return this.tracks.forEach((i=>{const n=i.track;n&&(e instanceof MediaStreamTrack?(n instanceof dn||n instanceof un)&&n.mediaStreamTrack===e&&(t=i):e===n&&(t=i))})),t}setPreferredCodec(e,t,i){if(!("getCapabilities"in RTCRtpSender))return;const n=RTCRtpSender.getCapabilities(t);if(!n)return;const r=n.codecs.find((e=>{const t=e.mimeType.toLowerCase(),n=t===`video/${i}`;return"h264"===i&&e.sdpFmtpLine?n&&e.sdpFmtpLine.includes("profile-level-id=42e01f"):n||"audio/opus"===t}));r&&"setCodecPreferences"in e&&e.setCodecPreferences([r])}publishedTracksInfo(){const e=[];return this.tracks.forEach((t=>{void 0!==t.track&&e.push({cid:t.track.mediaStreamTrack.id,track:t.trackInfo})})),e}dataChannelsInfo(){const t=[],i=(e,i)=>{void 0!==e?.id&&null!==e.id&&t.push({label:e.label,id:e.id,target:i})};return i(this.engine.dataChannelForKind(e.DataPacket_Kind.LOSSY),At.PUBLISHER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.RELIABLE),At.PUBLISHER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.LOSSY,!0),At.SUBSCRIBER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.RELIABLE,!0),At.SUBSCRIBER),t}}class Jn{constructor(){this.queue=[],this.running=!1}enqueue(e){s.trace("enqueuing request to fire later"),this.queue.push(e)}dequeue(){const e=this.queue.shift();e&&e(),s.trace("firing request from queue")}async run(){if(!this.running){for(s.trace("start queue"),this.running=!0;this.running&&this.queue.length>0;)this.dequeue();this.running=!1,s.trace("queue finished")}}pause(){s.trace("pausing queue"),this.running=!1}reset(){s.trace("resetting queue"),this.running=!1,this.queue=[]}isRunning(){return this.running}isEmpty(){return 0===this.queue.length}}let Bn=!0,jn=!0;function Vn(e,t,i){const n=e.match(t);return n&&n.length>=i&&parseInt(n[i],10)}function Fn(e,t,i){if(!e.RTCPeerConnection)return;const n=e.RTCPeerConnection.prototype,r=n.addEventListener;n.addEventListener=function(e,n){if(e!==t)return r.apply(this,arguments);const s=e=>{const t=i(e);t&&(n.handleEvent?n.handleEvent(t):n(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(n,s),r.apply(this,[e,s])};const s=n.removeEventListener;n.removeEventListener=function(e,i){if(e!==t||!this._eventMap||!this._eventMap[t])return s.apply(this,arguments);if(!this._eventMap[t].has(i))return s.apply(this,arguments);const n=this._eventMap[t].get(i);return this._eventMap[t].delete(i),0===this._eventMap[t].size&&delete this._eventMap[t],0===Object.keys(this._eventMap).length&&delete this._eventMap,s.apply(this,[e,n])},Object.defineProperty(n,"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 qn(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(Bn=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function Qn(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(jn=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function Wn(){if("object"==typeof window){if(Bn)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}}function Gn(e,t){jn&&console.warn(e+" is deprecated, please use "+t+" instead.")}function Kn(e){const t={browser:null,version:null};if(void 0===e||!e.navigator)return t.browser="Not a browser.",t;const{navigator:i}=e;if(i.mozGetUserMedia)t.browser="firefox",t.version=Vn(i.userAgent,/Firefox\/(\d+)\./,1);else if(i.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=Vn(i.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else{if(!e.RTCPeerConnection||!i.userAgent.match(/AppleWebKit\/(\d+)\./))return t.browser="Not a supported browser.",t;t.browser="safari",t.version=Vn(i.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}function Hn(e){return"[object Object]"===Object.prototype.toString.call(e)}function zn(e){return Hn(e)?Object.keys(e).reduce((function(t,i){const n=Hn(e[i]),r=n?zn(e[i]):e[i],s=n&&!Object.keys(r).length;return void 0===r||s?t:Object.assign(t,{[i]:r})}),{}):e}function Zn(e,t,i){t&&!i.has(t.id)&&(i.set(t.id,t),Object.keys(t).forEach((n=>{n.endsWith("Id")?Zn(e,e.get(t[n]),i):n.endsWith("Ids")&&t[n].forEach((t=>{Zn(e,e.get(t),i)}))})))}function $n(e,t,i){const n=i?"outbound-rtp":"inbound-rtp",r=new Map;if(null===t)return r;const s=[];return e.forEach((e=>{"track"===e.type&&e.trackIdentifier===t.id&&s.push(e)})),s.forEach((t=>{e.forEach((i=>{i.type===n&&i.trackId===t.id&&Zn(e,i,r)}))})),r}const Yn=Wn;function Xn(e,t){const i=e&&e.navigator;if(!i.mediaDevices)return;const n=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;const t={};return Object.keys(e).forEach((i=>{if("require"===i||"advanced"===i||"mediaSource"===i)return;const n="object"==typeof e[i]?e[i]:{ideal:e[i]};void 0!==n.exact&&"number"==typeof n.exact&&(n.min=n.max=n.exact);const r=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==n.ideal){t.optional=t.optional||[];let e={};"number"==typeof n.ideal?(e[r("min",i)]=n.ideal,t.optional.push(e),e={},e[r("max",i)]=n.ideal,t.optional.push(e)):(e[r("",i)]=n.ideal,t.optional.push(e))}void 0!==n.exact&&"number"!=typeof n.exact?(t.mandatory=t.mandatory||{},t.mandatory[r("",i)]=n.exact):["min","max"].forEach((e=>{void 0!==n[e]&&(t.mandatory=t.mandatory||{},t.mandatory[r(e,i)]=n[e])}))})),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},r=function(e,r){if(t.version>=61)return r(e);if((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof e.audio){const t=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])};t((e=JSON.parse(JSON.stringify(e))).audio,"autoGainControl","googAutoGainControl"),t(e.audio,"noiseSuppression","googNoiseSuppression"),e.audio=n(e.audio)}if(e&&"object"==typeof e.video){let s=e.video.facingMode;s=s&&("object"==typeof s?s:{ideal:s});const a=t.version<66;if(s&&("user"===s.exact||"environment"===s.exact||"user"===s.ideal||"environment"===s.ideal)&&(!i.mediaDevices.getSupportedConstraints||!i.mediaDevices.getSupportedConstraints().facingMode||a)){let t;if(delete e.video.facingMode,"environment"===s.exact||"environment"===s.ideal?t=["back","rear"]:"user"!==s.exact&&"user"!==s.ideal||(t=["front"]),t)return i.mediaDevices.enumerateDevices().then((i=>{let a=(i=i.filter((e=>"videoinput"===e.kind))).find((e=>t.some((t=>e.label.toLowerCase().includes(t)))));return!a&&i.length&&t.includes("back")&&(a=i[i.length-1]),a&&(e.video.deviceId=s.exact?{exact:a.deviceId}:{ideal:a.deviceId}),e.video=n(e.video),Yn("chrome: "+JSON.stringify(e)),r(e)}))}e.video=n(e.video)}return Yn("chrome: "+JSON.stringify(e)),r(e)},s=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(i.getUserMedia=function(e,t,n){r(e,(e=>{i.webkitGetUserMedia(e,t,(e=>{n&&n(s(e))}))}))}.bind(i),i.mediaDevices.getUserMedia){const e=i.mediaDevices.getUserMedia.bind(i.mediaDevices);i.mediaDevices.getUserMedia=function(t){return r(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(s(e))))))}}}function er(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function tr(e){if("object"==typeof e&&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});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",(i=>{let n;n=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.track.id)):{track:i.track};const r=new Event("track");r.track=i.track,r.receiver=n,r.transceiver={receiver:n},r.streams=[t.stream],this.dispatchEvent(r)})),t.stream.getTracks().forEach((i=>{let n;n=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.id)):{track:i};const r=new Event("track");r.track=i,r.receiver=n,r.transceiver={receiver:n},r.streams=[t.stream],this.dispatchEvent(r)}))},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else Fn(e,"track",(e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e)))}function ir(e){if("object"==typeof e&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){const t=function(e,t){return{track:t,get dtmf(){return void 0===this._dtmf&&("audio"===t.kind?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,n){let r=i.apply(this,arguments);return r||(r=t(this,e),this._senders.push(r)),r};const n=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){n.apply(this,arguments);const t=this._senders.indexOf(e);-1!==t&&this._senders.splice(t,1)}}const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],i.apply(this,[e]),e.getTracks().forEach((e=>{this._senders.push(t(this,e))}))};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],n.apply(this,[e]),e.getTracks().forEach((e=>{const t=this._senders.find((t=>t.track===e));t&&this._senders.splice(this._senders.indexOf(t),1)}))}}else if("object"==typeof e&&e.RTCPeerConnection&&"getSenders"in e.RTCPeerConnection.prototype&&"createDTMFSender"in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function nr(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,i,n]=arguments;if(arguments.length>0&&"function"==typeof e)return t.apply(this,arguments);if(0===t.length&&(0===arguments.length||"function"!=typeof e))return t.apply(this,[]);const r=function(e){const t={};return e.result().forEach((e=>{const i={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach((t=>{i[t]=e.stat(t)})),t[i.id]=i})),t},s=function(e){return new Map(Object.keys(e).map((t=>[t,e[t]])))};if(arguments.length>=2){const n=function(e){i(s(r(e)))};return t.apply(this,[n,e])}return new Promise(((e,i)=>{t.apply(this,[function(t){e(s(r(t)))},i])})).then(i,n)}}function rr(e){if(!("object"==typeof e&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!("getStats"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>$n(t,e.track,!0)))}}if(!("getStats"in e.RTCRtpReceiver.prototype)){const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),Fn(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>$n(t,e.track,!1)))}}if(!("getStats"in e.RTCRtpSender.prototype)||!("getStats"in e.RTCRtpReceiver.prototype))return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){const e=arguments[0];let t,i,n;return this.getSenders().forEach((i=>{i.track===e&&(t?n=!0:t=i)})),this.getReceivers().forEach((t=>(t.track===e&&(i?n=!0:i=t),t.track===e))),n||t&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):t?t.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return t.apply(this,arguments)}}function sr(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map((e=>this._shimmedLocalStreams[e][0]))};const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,i){if(!i)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const n=t.apply(this,arguments);return this._shimmedLocalStreams[i.id]?-1===this._shimmedLocalStreams[i.id].indexOf(n)&&this._shimmedLocalStreams[i.id].push(n):this._shimmedLocalStreams[i.id]=[i,n],n};const i=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")}));const t=this.getSenders();i.apply(this,arguments);const n=this.getSenders().filter((e=>-1===t.indexOf(e)));this._shimmedLocalStreams[e.id]=[e].concat(n)};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],n.apply(this,arguments)};const r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach((t=>{const i=this._shimmedLocalStreams[t].indexOf(e);-1!==i&&this._shimmedLocalStreams[t].splice(i,1),1===this._shimmedLocalStreams[t].length&&delete this._shimmedLocalStreams[t]})),r.apply(this,arguments)}}function ar(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return sr(e);const i=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){const e=i.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map((e=>this._reverseStreams[e.id]))};const n=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]){const i=new e.MediaStream(t.getTracks());this._streams[t.id]=i,this._reverseStreams[i.id]=t,t=i}n.apply(this,[t])};const r=e.RTCPeerConnection.prototype.removeStream;function s(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const n=e._reverseStreams[t],r=e._streams[n.id];i=i.replace(new RegExp(r.id,"g"),n.id)})),new RTCSessionDescription({type:t.type,sdp:i})}function a(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const n=e._reverseStreams[t],r=e._streams[n.id];i=i.replace(new RegExp(n.id,"g"),r.id)})),new RTCSessionDescription({type:t.type,sdp:i})}e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},r.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,i){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const n=[].slice.call(arguments,1);if(1!==n.length||!n[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");const r=this.getSenders().find((e=>e.track===t));if(r)throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const s=this._streams[i.id];if(s)s.addTrack(t),Promise.resolve().then((()=>{this.dispatchEvent(new Event("negotiationneeded"))}));else{const n=new e.MediaStream([t]);this._streams[i.id]=n,this._reverseStreams[n.id]=i,this.addStream(n)}return this.getSenders().find((e=>e.track===t))},["createOffer","createAnswer"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){const e=arguments;return arguments.length&&"function"==typeof arguments[0]?i.apply(this,[t=>{const i=s(this,t);e[0].apply(null,[i])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):i.apply(this,arguments).then((e=>s(this,e)))}};e.RTCPeerConnection.prototype[t]=n[t]}));const o=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=a(this,arguments[0]),o.apply(this,arguments)):o.apply(this,arguments)};const c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const e=c.get.apply(this);return""===e.type?e:s(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if("closed"===this.signalingState)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");let t;this._streams=this._streams||{},Object.keys(this._streams).forEach((i=>{this._streams[i].getTracks().find((t=>e.track===t))&&(t=this._streams[i])})),t&&(1===t.getTracks().length?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event("negotiationneeded")))}}function or(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=n[t]}))}function cr(e,t){Fn(e,"negotiationneeded",(e=>{const i=e.target;if(!(t.version<72||i.getConfiguration&&"plan-b"===i.getConfiguration().sdpSemantics)||"stable"===i.signalingState)return e}))}var dr=Object.freeze({__proto__:null,shimMediaStream:er,shimOnTrack:tr,shimGetSendersWithDtmf:ir,shimGetStats:nr,shimSenderReceiverGetStats:rr,shimAddTrackRemoveTrackWithNative:sr,shimAddTrackRemoveTrack:ar,shimPeerConnection:or,fixNegotiationNeeded:cr,shimGetUserMedia:Xn,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&("function"==typeof t?e.navigator.mediaDevices.getDisplayMedia=function(i){return t(i).then((t=>{const n=i.video&&i.video.width,r=i.video&&i.video.height,s=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:t,maxFrameRate:s||3}},n&&(i.video.mandatory.maxWidth=n),r&&(i.video.mandatory.maxHeight=r),e.navigator.mediaDevices.getUserMedia(i)}))}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}});function ur(e,t){const i=e&&e.navigator,n=e&&e.MediaStreamTrack;if(i.getUserMedia=function(e,t,n){Gn("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),i.mediaDevices.getUserMedia(e).then(t,n)},!(t.version>55&&"autoGainControl"in i.mediaDevices.getSupportedConstraints())){const e=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])},t=i.mediaDevices.getUserMedia.bind(i.mediaDevices);if(i.mediaDevices.getUserMedia=function(i){return"object"==typeof i&&"object"==typeof i.audio&&(i=JSON.parse(JSON.stringify(i)),e(i.audio,"autoGainControl","mozAutoGainControl"),e(i.audio,"noiseSuppression","mozNoiseSuppression")),t(i)},n&&n.prototype.getSettings){const t=n.prototype.getSettings;n.prototype.getSettings=function(){const i=t.apply(this,arguments);return e(i,"mozAutoGainControl","autoGainControl"),e(i,"mozNoiseSuppression","noiseSuppression"),i}}if(n&&n.prototype.applyConstraints){const t=n.prototype.applyConstraints;n.prototype.applyConstraints=function(i){return"audio"===this.kind&&"object"==typeof i&&(i=JSON.parse(JSON.stringify(i)),e(i,"autoGainControl","mozAutoGainControl"),e(i,"noiseSuppression","mozNoiseSuppression")),t.apply(this,[i])}}}}function lr(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function hr(e,t){if("object"!=typeof e||!e.RTCPeerConnection&&!e.mozRTCPeerConnection)return;!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=n[t]}));const i={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,r,s]=arguments;return n.apply(this,[e||null]).then((e=>{if(t.version<53&&!r)try{e.forEach((e=>{e.type=i[e.type]||e.type}))}catch(t){if("TypeError"!==t.name)throw t;e.forEach(((t,n)=>{e.set(n,Object.assign({},t,{type:i[t.type]||t.type}))}))}return e})).then(r,s)}}function pr(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpSender.prototype)return;const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.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 fr(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpReceiver.prototype)return;const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),Fn(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function mr(e){e.RTCPeerConnection&&!("removeStream"in e.RTCPeerConnection.prototype)&&(e.RTCPeerConnection.prototype.removeStream=function(e){Gn("removeStream","removeTrack"),this.getSenders().forEach((t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)}))})}function vr(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function gr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const e=arguments[1],i=e&&"sendEncodings"in e;i&&e.sendEncodings.forEach((e=>{if("rid"in e){if(!/^[a-z0-9]{0,16}$/i.test(e.rid))throw new TypeError("Invalid RID value provided.")}if("scaleResolutionDownBy"in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in e&&!(parseFloat(e.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")}));const n=t.apply(this,arguments);if(i){const{sender:t}=n,i=t.getParameters();(!("encodings"in i)||1===i.encodings.length&&0===Object.keys(i.encodings[0]).length)&&(i.encodings=e.sendEncodings,t.sendEncodings=e.sendEncodings,this.setParametersPromises.push(t.setParameters(i).then((()=>{delete t.sendEncodings})).catch((()=>{delete t.sendEncodings}))))}return n})}function br(e){if("object"!=typeof e||!e.RTCRtpSender)return;const t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){const e=t.apply(this,arguments);return"encodings"in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function kr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}function Sr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}var yr=Object.freeze({__proto__:null,shimOnTrack:lr,shimPeerConnection:hr,shimSenderGetStats:pr,shimReceiverGetStats:fr,shimRemoveStream:mr,shimRTCDataChannel:vr,shimAddTransceiver:gr,shimGetParameters:br,shimCreateOffer:kr,shimCreateAnswer:Sr,shimGetUserMedia:ur,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(i){if(!i||!i.video){const e=new DOMException("getDisplayMedia without video constraints is undefined");return e.name="NotFoundError",e.code=8,Promise.reject(e)}return!0===i.video?i.video={mediaSource:t}:i.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(i)})}});function wr(e){if("object"==typeof e&&e.RTCPeerConnection){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in e.RTCPeerConnection.prototype)){const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||(this._localStreams=[]),this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach((i=>t.call(this,i,e))),e.getVideoTracks().forEach((i=>t.call(this,i,e)))},e.RTCPeerConnection.prototype.addTrack=function(e){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];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||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(-1===t)return;this._localStreams.splice(t,1);const i=e.getTracks();this.getSenders().forEach((e=>{i.includes(e.track)&&this.removeTrack(e)}))})}}function Cr(e){if("object"==typeof e&&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=[]),this._remoteStreams.includes(e))return;this._remoteStreams.push(e);const t=new Event("addstream");t.stream=e,this.dispatchEvent(t)}))})}});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){const e=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(t){t.streams.forEach((t=>{if(e._remoteStreams||(e._remoteStreams=[]),e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);const i=new Event("addstream");i.stream=t,e.dispatchEvent(i)}))}),t.apply(e,arguments)}}}function Tr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,i=t.createOffer,n=t.createAnswer,r=t.setLocalDescription,s=t.setRemoteDescription,a=t.addIceCandidate;t.createOffer=function(e,t){const n=arguments.length>=2?arguments[2]:arguments[0],r=i.apply(this,[n]);return t?(r.then(e,t),Promise.resolve()):r},t.createAnswer=function(e,t){const i=arguments.length>=2?arguments[2]:arguments[0],r=n.apply(this,[i]);return t?(r.then(e,t),Promise.resolve()):r};let o=function(e,t,i){const n=r.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n};t.setLocalDescription=o,o=function(e,t,i){const n=s.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n},t.setRemoteDescription=o,o=function(e,t,i){const n=a.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n},t.addIceCandidate=o}function Er(e){const t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){const e=t.mediaDevices,i=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>i(Pr(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,i,n){t.mediaDevices.getUserMedia(e).then(i,n)}.bind(t))}function Pr(e){return e&&void 0!==e.video?Object.assign({},e,{video:zn(e.video)}):e}function Rr(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,i){if(e&&e.iceServers){const t=[];for(let i=0;i<e.iceServers.length;i++){let n=e.iceServers[i];!n.hasOwnProperty("urls")&&n.hasOwnProperty("url")?(Gn("RTCIceServer.url","RTCIceServer.urls"),n=JSON.parse(JSON.stringify(n)),n.urls=n.url,delete n.url,t.push(n)):t.push(e.iceServers[i])}e.iceServers=t}return new t(e,i)},e.RTCPeerConnection.prototype=t.prototype,"generateCertificate"in t&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:()=>t.generateCertificate})}function Or(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Nr(e){const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){void 0!==e.offerToReceiveAudio&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);const t=this.getTransceivers().find((e=>"audio"===e.receiver.track.kind));!1===e.offerToReceiveAudio&&t?"sendrecv"===t.direction?t.setDirection?t.setDirection("sendonly"):t.direction="sendonly":"recvonly"===t.direction&&(t.setDirection?t.setDirection("inactive"):t.direction="inactive"):!0!==e.offerToReceiveAudio||t||this.addTransceiver("audio",{direction:"recvonly"}),void 0!==e.offerToReceiveVideo&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);const i=this.getTransceivers().find((e=>"video"===e.receiver.track.kind));!1===e.offerToReceiveVideo&&i?"sendrecv"===i.direction?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":"recvonly"===i.direction&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):!0!==e.offerToReceiveVideo||i||this.addTransceiver("video",{direction:"recvonly"})}return t.apply(this,arguments)}}function Dr(e){"object"!=typeof e||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var Ar=Object.freeze({__proto__:null,shimLocalStreamsAPI:wr,shimRemoteStreamsAPI:Cr,shimCallbacksAPI:Tr,shimGetUserMedia:Er,shimConstraints:Pr,shimRTCIceServerUrls:Rr,shimTrackEventTransceiver:Or,shimCreateOfferLegacy:Nr,shimAudioContext:Dr}),Ur={exports:{}};!function(e){const t={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((e=>e.trim()))},t.splitSections=function(e){return e.split("\nm=").map(((e,t)=>(t>0?"m="+e:e).trim()+"\r\n"))},t.getDescription=function(e){const i=t.splitSections(e);return i&&i[0]},t.getMediaSections=function(e){const i=t.splitSections(e);return i.shift(),i},t.matchPrefix=function(e,i){return t.splitLines(e).filter((e=>0===e.indexOf(i)))},t.parseCandidate=function(e){let t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");const i={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":i.relatedAddress=t[e+1];break;case"rport":i.relatedPort=parseInt(t[e+1],10);break;case"tcptype":i.tcpType=t[e+1];break;case"ufrag":i.ufrag=t[e+1],i.usernameFragment=t[e+1];break;default:void 0===i[t[e]]&&(i[t[e]]=t[e+1])}return i},t.writeCandidate=function(e){const t=[];t.push(e.foundation);const i=e.component;"rtp"===i?t.push(1):"rtcp"===i?t.push(2):t.push(i),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);const n=e.type;return t.push("typ"),t.push(n),"host"!==n&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(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.substr(14).split(" ")},t.parseRtpMap=function(e){let t=e.substr(9).split(" ");const i={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),i.name=t[0],i.clockRate=parseInt(t[1],10),i.channels=3===t.length?parseInt(t[2],10):1,i.numChannels=i.channels,i},t.writeRtpMap=function(e){let t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);const i=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==i?"/"+i:"")+"\r\n"},t.parseExtmap=function(e){const t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},t.parseFmtp=function(e){const t={};let i;const n=e.substr(e.indexOf(" ")+1).split(";");for(let e=0;e<n.length;e++)i=n[e].trim().split("="),t[i[0].trim()]=i[1];return t},t.writeFmtp=function(e){let t="",i=e.payloadType;if(void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){const n=[];Object.keys(e.parameters).forEach((t=>{void 0!==e.parameters[t]?n.push(t+"="+e.parameters[t]):n.push(t)})),t+="a=fmtp:"+i+" "+n.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){const t=e.substr(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){let t="",i=e.payloadType;return void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((e=>{t+="a=rtcp-fb:"+i+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){const t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},n=e.indexOf(":",t);return n>-1?(i.attribute=e.substr(t+1,n-t-1),i.value=e.substr(n+1)):i.attribute=e.substr(t+1),i},t.parseSsrcGroup=function(e){const t=e.substr(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((e=>parseInt(e,10)))}},t.getMid=function(e){const i=t.matchPrefix(e,"a=mid:")[0];if(i)return i.substr(6)},t.parseFingerprint=function(e){const t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,i){return{role:"auto",fingerprints:t.matchPrefix(e+i,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let i="a=setup:"+t+"\r\n";return e.fingerprints.forEach((e=>{i+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),i},t.parseCryptoLine=function(e){const t=e.substr(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+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;const t=e.substr(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,i){return t.matchPrefix(e+i,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,i){const n=t.matchPrefix(e+i,"a=ice-ufrag:")[0],r=t.matchPrefix(e+i,"a=ice-pwd:")[0];return n&&r?{usernameFragment:n.substr(12),password:r.substr(10)}:null},t.writeIceParameters=function(e){let t="a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n";return e.iceLite&&(t+="a=ice-lite\r\n"),t},t.parseRtpParameters=function(e){const i={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},n=t.splitLines(e)[0].split(" ");for(let r=3;r<n.length;r++){const s=n[r],a=t.matchPrefix(e,"a=rtpmap:"+s+" ")[0];if(a){const n=t.parseRtpMap(a),r=t.matchPrefix(e,"a=fmtp:"+s+" ");switch(n.parameters=r.length?t.parseFmtp(r[0]):{},n.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+s+" ").map(t.parseRtcpFb),i.codecs.push(n),n.name.toUpperCase()){case"RED":case"ULPFEC":i.fecMechanisms.push(n.name.toUpperCase())}}}return t.matchPrefix(e,"a=extmap:").forEach((e=>{i.headerExtensions.push(t.parseExtmap(e))})),i},t.writeRtpDescription=function(e,i){let n="";n+="m="+e+" ",n+=i.codecs.length>0?"9":"0",n+=" UDP/TLS/RTP/SAVPF ",n+=i.codecs.map((e=>void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType)).join(" ")+"\r\n",n+="c=IN IP4 0.0.0.0\r\n",n+="a=rtcp:9 IN IP4 0.0.0.0\r\n",i.codecs.forEach((e=>{n+=t.writeRtpMap(e),n+=t.writeFmtp(e),n+=t.writeRtcpFb(e)}));let r=0;return i.codecs.forEach((e=>{e.maxptime>r&&(r=e.maxptime)})),r>0&&(n+="a=maxptime:"+r+"\r\n"),i.headerExtensions&&i.headerExtensions.forEach((e=>{n+=t.writeExtmap(e)})),n},t.parseRtpEncodingParameters=function(e){const i=[],n=t.parseRtpParameters(e),r=-1!==n.fecMechanisms.indexOf("RED"),s=-1!==n.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute)),o=a.length>0&&a[0].ssrc;let c;const d=t.matchPrefix(e,"a=ssrc-group:FID").map((e=>e.substr(17).split(" ").map((e=>parseInt(e,10)))));d.length>0&&d[0].length>1&&d[0][0]===o&&(c=d[0][1]),n.codecs.forEach((e=>{if("RTX"===e.name.toUpperCase()&&e.parameters.apt){let t={ssrc:o,codecPayloadType:parseInt(e.parameters.apt,10)};o&&c&&(t.rtx={ssrc:c}),i.push(t),r&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:o,mechanism:s?"red+ulpfec":"red"},i.push(t))}})),0===i.length&&o&&i.push({ssrc:o});let u=t.matchPrefix(e,"b=");return u.length&&(u=0===u[0].indexOf("b=TIAS:")?parseInt(u[0].substr(7),10):0===u[0].indexOf("b=AS:")?1e3*parseInt(u[0].substr(5),10)*.95-16e3:void 0,i.forEach((e=>{e.maxBitrate=u}))),i},t.parseRtcpParameters=function(e){const i={},n=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute))[0];n&&(i.cname=n.value,i.ssrc=n.ssrc);const r=t.matchPrefix(e,"a=rtcp-rsize");i.reducedSize=r.length>0,i.compound=0===r.length;const s=t.matchPrefix(e,"a=rtcp-mux");return i.mux=s.length>0,i},t.writeRtcpParameters=function(e){let t="";return e.reducedSize&&(t+="a=rtcp-rsize\r\n"),e.mux&&(t+="a=rtcp-mux\r\n"),void 0!==e.ssrc&&e.cname&&(t+="a=ssrc:"+e.ssrc+" cname:"+e.cname+"\r\n"),t},t.parseMsid=function(e){let i;const n=t.matchPrefix(e,"a=msid:");if(1===n.length)return i=n[0].substr(7).split(" "),{stream:i[0],track:i[1]};const r=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return r.length>0?(i=r[0].value.split(" "),{stream:i[0],track:i[1]}):void 0},t.parseSctpDescription=function(e){const i=t.parseMLine(e),n=t.matchPrefix(e,"a=max-message-size:");let r;n.length>0&&(r=parseInt(n[0].substr(19),10)),isNaN(r)&&(r=65536);const s=t.matchPrefix(e,"a=sctp-port:");if(s.length>0)return{port:parseInt(s[0].substr(12),10),protocol:i.fmt,maxMessageSize:r};const a=t.matchPrefix(e,"a=sctpmap:");if(a.length>0){const e=a[0].substr(10).split(" ");return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:r}}},t.writeSctpDescription=function(e,t){let i=[];return i="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&i.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),i.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,21)},t.writeSessionBoilerplate=function(e,i,n){let r;const s=void 0!==i?i:2;r=e||t.generateSessionId();return"v=0\r\no="+(n||"thisisadapterortc")+" "+r+" "+s+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.getDirection=function(e,i){const n=t.splitLines(e);for(let e=0;e<n.length;e++)switch(n[e]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return n[e].substr(2)}return i?t.getDirection(i):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substr(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){const i=t.splitLines(e)[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},t.parseOLine=function(e){const i=t.matchPrefix(e,"o=")[0].substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;const i=t.splitLines(e);for(let e=0;e<i.length;e++)if(i[e].length<2||"="!==i[e].charAt(1))return!1;return!0},e.exports=t}(Ur);var Ir=Ur.exports,Lr=t({__proto__:null,default:Ir},[Ur.exports]);function Mr(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)return;const t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"==typeof e&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){const i=new t(e),n=Ir.parseCandidate(e.candidate),r=Object.assign(i,n);return r.toJSON=function(){return{candidate:r.candidate,sdpMid:r.sdpMid,sdpMLineIndex:r.sdpMLineIndex,usernameFragment:r.usernameFragment}},r}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,Fn(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function _r(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return void 0===this._sctp?null:this._sctp}});const i=function(e){if(!e||!e.sdp)return!1;const t=Ir.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=Ir.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")}))},n=function(e){const t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;const i=parseInt(t[1],10);return i!=i?-1:i},r=function(e){let i=65536;return"firefox"===t.browser&&(i=t.version<57?-1===e?16384:2147483637:t.version<60?57===t.version?65535:65536:2147483637),i},s=function(e,i){let n=65536;"firefox"===t.browser&&57===t.version&&(n=65535);const r=Ir.matchPrefix(e.sdp,"a=max-message-size:");return r.length>0?n=parseInt(r[0].substr(19),10):"firefox"===t.browser&&-1!==i&&(n=2147483637),n},a=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===t.browser&&t.version>=76){const{sdpSemantics:e}=this.getConfiguration();"plan-b"===e&&Object.defineProperty(this,"sctp",{get(){return void 0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(i(arguments[0])){const e=n(arguments[0]),t=r(e),i=s(arguments[0],e);let a;a=0===t&&0===i?Number.POSITIVE_INFINITY:0===t||0===i?Math.max(t,i):Math.min(t,i);const o={};Object.defineProperty(o,"maxMessageSize",{get:()=>a}),this._sctp=o}return a.apply(this,arguments)}}function xr(e){if(!e.RTCPeerConnection||!("createDataChannel"in e.RTCPeerConnection.prototype))return;function t(e,t){const i=e.send;e.send=function(){const n=arguments[0],r=n.length||n.size||n.byteLength;if("open"===e.readyState&&t.sctp&&r>t.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");return i.apply(e,arguments)}}const i=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const e=i.apply(this,arguments);return t(e,this),e},Fn(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function Jr(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const 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=>{const i=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{const t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;const i=new Event("connectionstatechange",e);t.dispatchEvent(i)}return e},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),i.apply(this,arguments)}}))}function Br(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t.version>=605)return;const i=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&-1!==t.sdp.indexOf("\na=extmap-allow-mixed")){const i=t.sdp.split("\n").filter((e=>"a=extmap-allow-mixed"!==e.trim())).join("\n");e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:i}):t.sdp=i}return i.apply(this,arguments)}}function jr(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.addIceCandidate;i&&0!==i.length&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?("chrome"===t.browser&&t.version<78||"firefox"===t.browser&&t.version<68||"safari"===t.browser)&&arguments[0]&&""===arguments[0].candidate?Promise.resolve():i.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Vr(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.setLocalDescription;i&&0!==i.length&&(e.RTCPeerConnection.prototype.setLocalDescription=function(){let e=arguments[0]||{};if("object"!=typeof e||e.type&&e.sdp)return i.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"}if(e.sdp||"offer"!==e.type&&"answer"!==e.type)return i.apply(this,[e]);const t="offer"===e.type?this.createOffer:this.createAnswer;return t.apply(this).then((e=>i.apply(this,[e])))})}var Fr=Object.freeze({__proto__:null,shimRTCIceCandidate:Mr,shimMaxMessageSize:_r,shimSendThrowTypeError:xr,shimConnectionState:Jr,removeExtmapAllowMixed:Br,shimAddIceCandidateNullOrEmpty:jr,shimParameterlessSetLocalDescription:Vr});!function(){let{window:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{shimChrome:!0,shimFirefox:!0,shimSafari:!0};const i=Wn,n=Kn(e),r={browserDetails:n,commonShim:Fr,extractVersion:Vn,disableLog:qn,disableWarnings:Qn,sdp:Lr};switch(n.browser){case"chrome":if(!dr||!or||!t.shimChrome)return i("Chrome shim is not included in this adapter release."),r;if(null===n.version)return i("Chrome shim can not determine version, not shimming."),r;i("adapter.js shimming chrome."),r.browserShim=dr,jr(e,n),Vr(e),Xn(e,n),er(e),or(e,n),tr(e),ar(e,n),ir(e),nr(e),rr(e),cr(e,n),Mr(e),Jr(e),_r(e,n),xr(e),Br(e,n);break;case"firefox":if(!yr||!hr||!t.shimFirefox)return i("Firefox shim is not included in this adapter release."),r;i("adapter.js shimming firefox."),r.browserShim=yr,jr(e,n),Vr(e),ur(e,n),hr(e,n),lr(e),mr(e),pr(e),fr(e),vr(e),gr(e),br(e),kr(e),Sr(e),Mr(e),Jr(e),_r(e,n),xr(e);break;case"safari":if(!Ar||!t.shimSafari)return i("Safari shim is not included in this adapter release."),r;i("adapter.js shimming safari."),r.browserShim=Ar,jr(e,n),Vr(e),Rr(e),Nr(e),Tr(e),wr(e),Cr(e),Or(e),Er(e),Dr(e),Mr(e),_r(e,n),xr(e),Br(e,n);break;default:i("Unsupported browser!")}}({window:"undefined"==typeof window?void 0:window});const qr=["syncState","trickle","offer","answer","simulate","leave"];class Qr{constructor(e=!1){this.isConnected=!1,this.isReconnecting=!1,this.useJSON=e,this.requestQueue=new Jn}async join(e,t,i){this.isConnected=!1;return await this.connect(e,t,{autoSubscribe:i?.autoSubscribe,publishOnly:i?.publishOnly,adaptiveStream:i?.adaptiveStream})}async reconnect(e,t){this.isReconnecting=!0,await this.connect(e,t,{reconnect:!0})}connect(e,t,i){e.startsWith("http")&&(e=e.replace("http","ws")),e=e.replace(/\/$/,""),e+="/rtc";const n=function(e,t,i){const n=new URLSearchParams;n.set("access_token",e),i?.reconnect&&n.set("reconnect","1");void 0!==i?.autoSubscribe&&n.set("auto_subscribe",i.autoSubscribe?"1":"0");n.set("sdk","js"),n.set("version",t.version),n.set("protocol",t.protocol.toString()),t.deviceModel&&n.set("device_model",t.deviceModel);t.os&&n.set("os",t.os);t.osVersion&&n.set("os_version",t.osVersion);t.browser&&n.set("browser",t.browser);t.browserVersion&&n.set("browser_version",t.browserVersion);void 0!==i?.publishOnly&&n.set("publish",i.publishOnly);i?.adaptiveStream&&n.set("adaptive_stream","1");return`?${n.toString()}`}(t,wt.fromPartial({sdk:ze.JS,protocol:7,version:Pi}),i);return new Promise(((t,r)=>{s.debug(`connecting to ${e+n}`),this.ws=void 0;const a=new WebSocket(e+n);a.binaryType="arraybuffer",a.onerror=async t=>{if(this.ws)this.handleWSError(t);else try{const t=await fetch(`http${e.substring(2)}/validate${n}`);if(t.ok)r(new pi("Internal error"));else{const e=await t.text();r(new pi(e))}}catch(e){r(new pi("server was not reachable"))}},a.onopen=()=>{this.ws=a,i.reconnect&&(this.isConnected=!0,t())},a.onmessage=async e=>{let i;if("string"==typeof e.data){const t=JSON.parse(e.data);i=xt.fromJSON(t)}else{if(!(e.data instanceof ArrayBuffer))return void s.error("could not decode websocket message: "+typeof e.data);i=xt.decode(new Uint8Array(e.data))}this.isConnected?(this.signalLatency&&await Ri(this.signalLatency),this.handleSignalResponse(i)):i.join?(this.isConnected=!0,t(i.join)):r(new pi("did not receive join response"))},a.onclose=e=>{this.isConnected&&this.ws===a&&(s.debug(`websocket connection closed: ${e.reason}`),this.isConnected=!1,this.onClose&&this.onClose(e.reason),this.ws===a&&(this.ws=void 0))}}))}close(){this.isConnected=!1,this.ws&&(this.ws.onclose=null),this.ws?.close(),this.ws=void 0}sendOffer(e){s.debug("sending offer",e),this.sendRequest({offer:Gr(e)})}sendAnswer(e){s.debug("sending answer"),this.sendRequest({answer:Gr(e)})}sendIceCandidate(e,t){s.trace("sending ice candidate",e),this.sendRequest({trickle:{candidateInit:JSON.stringify(e),target:t}})}sendMuteTrack(e,t){this.sendRequest({mute:{sid:e,muted:t}})}sendAddTrack(e){this.sendRequest({addTrack:Jt.fromPartial(e)})}sendUpdateTrackSettings(e){this.sendRequest({trackSetting:e})}sendUpdateSubscription(e){this.sendRequest({subscription:e})}sendSyncState(e){this.sendRequest({syncState:e})}sendUpdateVideoLayers(e,t){this.sendRequest({updateLayers:{trackSid:e,layers:t}})}sendUpdateSubscriptionPermissions(e,t){this.sendRequest({subscriptionPermission:{allParticipants:e,trackPermissions:t}})}sendSimulateScenario(e){this.sendRequest({simulate:e})}sendLeave(){this.sendRequest(_t.fromPartial({leave:{}}))}async sendRequest(e,t=!1){const i=!t&&!function(e){const t=void 0!==Object.keys(e).find((e=>qr.includes(e)));return s.trace("request allowed to bypass queue:",{canPass:t,req:e}),t}(e);if(!i||!this.isReconnecting&&this.requestQueue.isEmpty())if(this.signalLatency&&await Ri(this.signalLatency),this.ws)try{this.useJSON?this.ws.send(JSON.stringify(_t.toJSON(e))):this.ws.send(_t.encode(e).finish())}catch(e){s.error("error sending signal message",{error:e})}else s.error("cannot send signal request before connected");else this.requestQueue.enqueue((()=>this.sendRequest(e,!0)))}handleSignalResponse(e){if(e.answer){const t=Wr(e.answer);this.onAnswer&&this.onAnswer(t)}else if(e.offer){const t=Wr(e.offer);this.onOffer&&this.onOffer(t)}else if(e.trickle){const t=JSON.parse(e.trickle.candidateInit);this.onTrickle&&this.onTrickle(t,e.trickle.target)}else e.update?this.onParticipantUpdate&&this.onParticipantUpdate(e.update.participants):e.trackPublished?this.onLocalTrackPublished&&this.onLocalTrackPublished(e.trackPublished):e.speakersChanged?this.onSpeakersChanged&&this.onSpeakersChanged(e.speakersChanged.speakers):e.leave?this.onLeave&&this.onLeave(e.leave):e.mute?this.onRemoteMuteChanged&&this.onRemoteMuteChanged(e.mute.sid,e.mute.muted):e.roomUpdate?this.onRoomUpdate&&this.onRoomUpdate(e.roomUpdate.room):e.connectionQuality?this.onConnectionQuality&&this.onConnectionQuality(e.connectionQuality):e.streamStateUpdate?this.onStreamStateUpdate&&this.onStreamStateUpdate(e.streamStateUpdate):e.subscribedQualityUpdate?this.onSubscribedQualityUpdate&&this.onSubscribedQualityUpdate(e.subscribedQualityUpdate):e.subscriptionPermissionUpdate?this.onSubscriptionPermissionUpdate&&this.onSubscriptionPermissionUpdate(e.subscriptionPermissionUpdate):e.refreshToken?this.onTokenRefresh&&this.onTokenRefresh(e.refreshToken):e.trackUnpublished?this.onLocalTrackUnpublished&&this.onLocalTrackUnpublished(e.trackUnpublished):s.debug("unsupported message",e)}setReconnected(){this.isReconnecting=!1,this.requestQueue.run()}handleWSError(e){s.error("websocket error",e)}}function Wr(e){const t={type:"offer",sdp:e.sdp};switch(e.type){case"answer":case"offer":case"pranswer":case"rollback":t.type=e.type}return t}function Gr(e){return{sdp:e.sdp,type:e.type}}class Kr{constructor(e){this.pendingCandidates=[],this.restartingIce=!1,this.renegotiate=!1,this.negotiate=fn((()=>{this.createAndSendOffer()}),100),this.pc=new RTCPeerConnection(e)}get isICEConnected(){return"connected"===this.pc.iceConnectionState||"completed"===this.pc.iceConnectionState}async addIceCandidate(e){if(this.pc.remoteDescription&&!this.restartingIce)return this.pc.addIceCandidate(e);this.pendingCandidates.push(e)}async setRemoteDescription(e){await this.pc.setRemoteDescription(e),this.pendingCandidates.forEach((e=>{this.pc.addIceCandidate(e)})),this.pendingCandidates=[],this.restartingIce=!1,this.renegotiate&&(this.renegotiate=!1,this.createAndSendOffer())}async createAndSendOffer(e){if(void 0===this.onOffer)return;if(e?.iceRestart&&(s.debug("restarting ICE"),this.restartingIce=!0),"have-local-offer"===this.pc.signalingState){const t=this.pc.remoteDescription;if(!e?.iceRestart||!t)return void(this.renegotiate=!0);await this.pc.setRemoteDescription(t)}else if("closed"===this.pc.signalingState)return void s.warn("could not createOffer with closed peer connection");s.debug("starting to negotiate");const t=await this.pc.createOffer(e);await this.pc.setLocalDescription(t),this.onOffer(t)}close(){this.pc.close()}}const Hr="_lossy",zr="_reliable",Zr=15e3;class $r extends Ji.exports.EventEmitter{constructor(){super(),this.rtcConfig={},this.subscriberPrimary=!1,this.pcConnected=!1,this.isClosed=!0,this.pendingTrackResolvers={},this.hasPublished=!1,this.reconnectAttempts=0,this.reconnectStart=0,this.fullReconnectOnNext=!1,this.handleDataChannel=async({channel:e})=>{if(e){if(e.label===zr)this.reliableDCSub=e;else{if(e.label!==Hr)return;this.lossyDCSub=e}s.debug(`on data channel ${e.id}, ${e.label}`),e.onmessage=this.handleDataMessage}},this.handleDataMessage=async t=>{let i;if(t.data instanceof ArrayBuffer)i=t.data;else{if(!(t.data instanceof Blob))return void s.error("unsupported data type",t.data);i=await t.data.arrayBuffer()}const n=vt.decode(new Uint8Array(i));n.speaker?this.emit(e.EngineEvent.ActiveSpeakersUpdate,n.speaker.speakers):n.user&&this.emit(e.EngineEvent.DataPacketReceived,n.user,n.kind)},this.handleDataError=e=>{const t=0===e.currentTarget.maxRetransmits?"lossy":"reliable";if(e instanceof ErrorEvent){const{error:i}=e.error;s.error(`DataChannel error on ${t}: ${e.message}`,i)}else s.error(`Unknown DataChannel Error on ${t}`,e)},this.handleDisconnect=t=>{if(this.isClosed)return;s.debug(`${t} disconnected`),0===this.reconnectAttempts&&(this.reconnectStart=Date.now());const i=this.reconnectAttempts*this.reconnectAttempts*300;setTimeout((async()=>{if(!this.isClosed){(Oi()||this.clientConfiguration?.resumeConnection===Ge.DISABLED)&&(this.fullReconnectOnNext=!0);try{this.fullReconnectOnNext?await this.restartConnection():await this.resumeConnection(),this.reconnectAttempts=0,this.fullReconnectOnNext=!1}catch(t){this.reconnectAttempts+=1;let i=!0;t instanceof vi?(s.debug("received unrecoverable error",{error:t}),i=!1):t instanceof Yr||(this.fullReconnectOnNext=!0);const n=Date.now()-this.reconnectStart;(this.reconnectAttempts>=10||n>6e4)&&(i=!1),i?this.handleDisconnect("reconnect"):(s.info(`could not recover connection after 10 attempts, ${n}ms. giving up`),this.emit(e.EngineEvent.Disconnected),this.close())}}}),i)},this.client=new Qr}async join(e,t,i){this.url=e,this.token=t,this.signalOpts=i;const n=await this.client.join(e,t,i);return this.isClosed=!1,this.subscriberPrimary=n.subscriberPrimary,this.publisher||this.configure(n),this.subscriberPrimary||this.negotiate(),this.clientConfiguration=n.clientConfiguration,n}close(){this.isClosed=!0,this.removeAllListeners(),this.publisher&&"closed"!==this.publisher.pc.signalingState&&(this.publisher.pc.getSenders().forEach((e=>{try{this.publisher?.pc.removeTrack&&this.publisher?.pc.removeTrack(e)}catch(e){s.warn("could not removeTrack",{error:e})}})),this.publisher.close(),this.publisher=void 0),this.subscriber&&(this.subscriber.close(),this.subscriber=void 0),this.client.close()}addTrack(e){if(this.pendingTrackResolvers[e.cid])throw new fi("a track with the same ID has already been published");return new Promise((t=>{this.pendingTrackResolvers[e.cid]=t,this.client.sendAddTrack(e)}))}updateMuteStatus(e,t){this.client.sendMuteTrack(e,t)}get dataSubscriberReadyState(){return this.reliableDCSub?.readyState}get connectedServerAddress(){return this.connectedServerAddr}configure(t){if(this.publisher||this.subscriber)return;if(t.iceServers&&!this.rtcConfig.iceServers){const e=[];t.iceServers.forEach((t=>{const i={urls:t.urls};t.username&&(i.username=t.username),t.credential&&(i.credential=t.credential),e.push(i)})),this.rtcConfig.iceServers=e}this.rtcConfig.sdpSemantics="unified-plan",this.rtcConfig.continualGatheringPolicy="gather_continually",this.publisher=new Kr(this.rtcConfig),this.subscriber=new Kr(this.rtcConfig),this.emit(e.EngineEvent.TransportsCreated,this.publisher,this.subscriber),this.publisher.pc.onicecandidate=e=>{e.candidate&&(s.trace("adding ICE candidate for peer",e.candidate),this.client.sendIceCandidate(e.candidate,At.PUBLISHER))},this.subscriber.pc.onicecandidate=e=>{e.candidate&&this.client.sendIceCandidate(e.candidate,At.SUBSCRIBER)},this.publisher.onOffer=e=>{this.client.sendOffer(e)};let i=this.publisher.pc;t.subscriberPrimary&&(i=this.subscriber.pc,this.subscriber.pc.ondatachannel=this.handleDataChannel),this.primaryPC=i,i.onconnectionstatechange=async()=>{if("connected"===i.connectionState){s.trace("pc connected");try{this.connectedServerAddr=await async function(e){let t="";const i=new Map,n=new Map;if((await e.getStats()).forEach((e=>{switch(e.type){case"transport":t=e.selectedCandidatePairId;break;case"candidate-pair":""===t&&e.selected&&(t=e.id),i.set(e.id,e);break;case"remote-candidate":n.set(e.id,`${e.address}:${e.port}`)}})),""===t)return;const r=i.get(t)?.remoteCandidateId;if(void 0===r)return;return n.get(r)}(i)}catch(e){s.warn("could not get connected server address",{error:e})}this.pcConnected||(this.pcConnected=!0,this.emit(e.EngineEvent.Connected))}else"failed"===i.connectionState&&(s.trace("pc disconnected"),this.pcConnected&&(this.pcConnected=!1,this.handleDisconnect("peerconnection")))},Di()?this.subscriber.pc.ontrack=t=>{this.emit(e.EngineEvent.MediaTrackAdded,t.track,t.streams[0],t.receiver)}:this.subscriber.pc.onaddstream=t=>{const i=t.stream.getTracks()[0];this.emit(e.EngineEvent.MediaTrackAdded,i,t.stream)},this.lossyDC=this.publisher.pc.createDataChannel(Hr,{ordered:!0,maxRetransmits:0}),this.reliableDC=this.publisher.pc.createDataChannel(zr,{ordered:!0}),this.lossyDC.onmessage=this.handleDataMessage,this.reliableDC.onmessage=this.handleDataMessage,this.lossyDC.onerror=this.handleDataError,this.reliableDC.onerror=this.handleDataError,this.client.onAnswer=async e=>{this.publisher&&(s.debug("received server answer",{RTCSdpType:e.type,signalingState:this.publisher.pc.signalingState}),await this.publisher.setRemoteDescription(e))},this.client.onTrickle=(e,t)=>{this.publisher&&this.subscriber&&(s.trace("got ICE candidate from peer",{candidate:e,target:t}),t===At.PUBLISHER?this.publisher.addIceCandidate(e):this.subscriber.addIceCandidate(e))},this.client.onOffer=async e=>{if(!this.subscriber)return;s.debug("received server offer",{RTCSdpType:e.type,signalingState:this.subscriber.pc.signalingState}),await this.subscriber.setRemoteDescription(e);const t=await this.subscriber.pc.createAnswer();await this.subscriber.pc.setLocalDescription(t),this.client.sendAnswer(t)},this.client.onLocalTrackPublished=e=>{s.debug("received trackPublishedResponse",e);const t=this.pendingTrackResolvers[e.cid];t?(delete this.pendingTrackResolvers[e.cid],t(e.track)):s.error(`missing track resolver for ${e.cid}`)},this.client.onTokenRefresh=e=>{this.token=e},this.client.onClose=()=>{this.handleDisconnect("signal")},this.client.onLeave=t=>{t?.canReconnect?(this.fullReconnectOnNext=!0,this.primaryPC=void 0):(this.emit(e.EngineEvent.Disconnected),this.close())}}async restartConnection(){if(!this.url||!this.token)throw new vi("could not reconnect, url or token not saved");let t;s.info(`reconnecting, attempt: ${this.reconnectAttempts}`),0===this.reconnectAttempts&&this.emit(e.EngineEvent.Restarting),this.primaryPC=void 0,this.publisher?.close(),this.publisher=void 0,this.subscriber?.close(),this.subscriber=void 0;try{t=await this.join(this.url,this.token,this.signalOpts)}catch(e){throw new Yr}await this.waitForPCConnected(),this.client.setReconnected(),this.emit(e.EngineEvent.Restarted,t)}async resumeConnection(){if(!this.url||!this.token)throw new vi("could not reconnect, url or token not saved");if(!this.publisher||!this.subscriber)throw new vi("publisher and subscriber connections unset");s.info(`resuming signal connection, attempt ${this.reconnectAttempts}`),0===this.reconnectAttempts&&this.emit(e.EngineEvent.Resuming);try{await this.client.reconnect(this.url,this.token)}catch(e){throw new Yr}this.emit(e.EngineEvent.SignalResumed),this.subscriber.restartingIce=!0,this.hasPublished&&await this.publisher.createAndSendOffer({iceRestart:!0}),await this.waitForPCConnected(),this.client.setReconnected(),this.emit(e.EngineEvent.Resumed)}async waitForPCConnected(){const e=(new Date).getTime();let t=e;for(this.pcConnected=!1;t-e<Zr&&void 0!==this.primaryPC;){if(t-e>1e3&&"connected"===this.primaryPC?.connectionState&&(this.pcConnected=!0),this.pcConnected)return;await Ri(100),t=(new Date).getTime()}throw new pi("could not establish PC connection")}async sendDataPacket(t,i){const n=vt.encode(t).finish();await this.ensurePublisherConnected(i),i===e.DataPacket_Kind.LOSSY&&this.lossyDC?this.lossyDC.send(n):i===e.DataPacket_Kind.RELIABLE&&this.reliableDC&&this.reliableDC.send(n)}async ensurePublisherConnected(e){if(!this.subscriberPrimary)return;if(!this.publisher)throw new pi("publisher connection not set");this.publisher.isICEConnected||"checking"===this.publisher.pc.iceConnectionState||this.negotiate();if("open"===this.dataChannelForKind(e)?.readyState)return;const t=(new Date).getTime()+Zr;for(;(new Date).getTime()<t;){if(this.publisher.isICEConnected&&"open"===this.dataChannelForKind(e)?.readyState)return;await Ri(50)}throw new pi(`could not establish publisher connection, state ${this.publisher?.pc.iceConnectionState}`)}negotiate(){this.publisher&&(this.hasPublished=!0,this.publisher.negotiate())}dataChannelForKind(t,i){if(i){if(t===e.DataPacket_Kind.LOSSY)return this.lossyDCSub;if(t===e.DataPacket_Kind.RELIABLE)return this.reliableDCSub}else{if(t===e.DataPacket_Kind.LOSSY)return this.lossyDC;if(t===e.DataPacket_Kind.RELIABLE)return this.reliableDC}}}class Yr extends Error{}const Xr={audioBitrate:e.AudioPresets.speech.maxBitrate,dtx:!0,simulcast:!0,screenShareEncoding:wn.h1080fps15.encoding,stopMicTrackOnMute:!1},es={autoGainControl:!0,channelCount:1,echoCancellation:!0,noiseSuppression:!0},ts={resolution:Sn.h540.resolution};var is;e.RoomState=void 0,(is=e.RoomState||(e.RoomState={})).Disconnected="disconnected",is.Connected="connected",is.Reconnecting="reconnecting";class ns extends Ji.exports.EventEmitter{constructor(t){switch(super(),this.state=e.RoomState.Disconnected,this.activeSpeakers=[],this.sid="",this.name="",this.metadata=void 0,this.audioEnabled=!0,this.connect=async(t,i,n)=>{if(this.state===e.RoomState.Disconnected){this.createEngine(),this.acquireAudioContext(),n?.rtcConfig&&(this.engine.rtcConfig=n.rtcConfig),this.connOptions=n;try{const r=await this.engine.join(t,i,{autoSubscribe:n?.autoSubscribe,publishOnly:n?.publishOnly,adaptiveStream:"object"==typeof this.options?.adaptiveStream||this.options?.adaptiveStream});if(s.debug(`connected to Livekit Server version: ${r.serverVersion}, region: ${r.serverRegion}`),!r.serverVersion)throw new mi("unknown server version");"0.15.1"===r.serverVersion&&this.options.dynacast&&(s.debug("disabling dynacast due to server version"),this.options.dynacast=!1),this.state=e.RoomState.Connected;const a=r.participant;this.localParticipant.sid=a.sid,this.localParticipant.identity=a.identity,this.localParticipant.updateInfo(a),this.localParticipant.on(e.ParticipantEvent.MetadataChanged,(t=>{this.emit(e.RoomEvent.MetadataChanged,t,this.localParticipant)})).on(e.ParticipantEvent.ParticipantMetadataChanged,(t=>{this.emit(e.RoomEvent.ParticipantMetadataChanged,t,this.localParticipant)})).on(e.ParticipantEvent.TrackMuted,(t=>{this.emit(e.RoomEvent.TrackMuted,t,this.localParticipant)})).on(e.ParticipantEvent.TrackUnmuted,(t=>{this.emit(e.RoomEvent.TrackUnmuted,t,this.localParticipant)})).on(e.ParticipantEvent.LocalTrackPublished,(t=>{this.emit(e.RoomEvent.LocalTrackPublished,t,this.localParticipant)})).on(e.ParticipantEvent.LocalTrackUnpublished,(t=>{this.emit(e.RoomEvent.LocalTrackUnpublished,t,this.localParticipant)})).on(e.ParticipantEvent.ConnectionQualityChanged,(t=>{this.emit(e.RoomEvent.ConnectionQualityChanged,t,this.localParticipant)})).on(e.ParticipantEvent.MediaDevicesError,(t=>{this.emit(e.RoomEvent.MediaDevicesError,t)})).on(e.ParticipantEvent.ParticipantPermissionsChanged,(t=>{this.emit(e.RoomEvent.ParticipantPermissionsChanged,t,this.localParticipant)})),r.otherParticipants.forEach((e=>{this.getOrCreateParticipant(e.sid,e)})),this.name=r.room.name,this.sid=r.room.sid,this.metadata=r.room.metadata,this.emit(e.RoomEvent.StateChanged,this.state)}catch(e){throw this.engine.close(),e}return new Promise(((t,i)=>{const n=setTimeout((()=>{this.engine.close(),i(new pi("could not connect after timeout"))}),Zr);this.engine.once(e.EngineEvent.Connected,(()=>{clearTimeout(n),Di()&&(window.addEventListener("beforeunload",this.onBeforeUnload),navigator.mediaDevices?.addEventListener("devicechange",this.handleDeviceChange)),t(this)}))}))}s.warn(`already connected to room ${this.name}`)},this.disconnect=(e=!0)=>{this.engine&&(this.engine.client.sendLeave(),this.engine.close()),this.handleDisconnect(e),this.engine=void 0},this.onBeforeUnload=()=>{this.disconnect()},this.handleRestarting=()=>{this.state=e.RoomState.Reconnecting,this.emit(e.RoomEvent.Reconnecting),this.emit(e.RoomEvent.StateChanged,this.state);for(const e of this.participants.values())this.handleParticipantDisconnected(e.sid,e)},this.handleRestarted=async t=>{s.debug(`reconnected to server region ${t.serverRegion}`),this.state=e.RoomState.Connected,this.emit(e.RoomEvent.Reconnected),this.emit(e.RoomEvent.StateChanged,this.state),t.participant&&(this.localParticipant.sid=t.participant.sid,this.handleParticipantUpdates([t.participant])),this.handleParticipantUpdates(t.otherParticipants);const i=[];this.localParticipant.tracks.forEach((e=>{e.track&&i.push(e)})),await Promise.all(i.map((async e=>{const t=e.track;this.localParticipant.unpublishTrack(t,!1),this.localParticipant.publishTrack(t,e.options)})))},this.handleParticipantUpdates=t=>{t.forEach((t=>{if(t.sid===this.localParticipant.sid||t.identity===this.localParticipant.identity)return void this.localParticipant.updateInfo(t);let i=this.participants.get(t.sid);const n=!i;i=this.getOrCreateParticipant(t.sid,t),t.state===Ke.DISCONNECTED?this.handleParticipantDisconnected(t.sid,i):n?this.emit(e.RoomEvent.ParticipantConnected,i):i.updateInfo(t)}))},this.handleActiveSpeakersUpdate=t=>{const i=[],n={};t.forEach((e=>{if(n[e.sid]=!0,e.sid===this.localParticipant.sid)this.localParticipant.audioLevel=e.level,this.localParticipant.setIsSpeaking(!0),i.push(this.localParticipant);else{const t=this.participants.get(e.sid);t&&(t.audioLevel=e.level,t.setIsSpeaking(!0),i.push(t))}})),n[this.localParticipant.sid]||(this.localParticipant.audioLevel=0,this.localParticipant.setIsSpeaking(!1)),this.participants.forEach((e=>{n[e.sid]||(e.audioLevel=0,e.setIsSpeaking(!1))})),this.activeSpeakers=i,this.emit(e.RoomEvent.ActiveSpeakersChanged,i)},this.handleSpeakersChanged=t=>{const i=new Map;this.activeSpeakers.forEach((e=>{i.set(e.sid,e)})),t.forEach((e=>{let t=this.participants.get(e.sid);e.sid===this.localParticipant.sid&&(t=this.localParticipant),t&&(t.audioLevel=e.level,t.setIsSpeaking(e.active),e.active?i.set(e.sid,t):i.delete(e.sid))}));const n=Array.from(i.values());n.sort(((e,t)=>t.audioLevel-e.audioLevel)),this.activeSpeakers=n,this.emit(e.RoomEvent.ActiveSpeakersChanged,n)},this.handleStreamStateUpdate=t=>{t.streamStates.forEach((t=>{const i=this.participants.get(t.participantSid);if(!i)return;const n=i.getTrackPublication(t.trackSid);n&&n.track&&(n.track.streamState=en.streamStateFromProto(t.state),i.emit(e.ParticipantEvent.TrackStreamStateChanged,n,n.track.streamState),this.emit(e.ParticipantEvent.TrackStreamStateChanged,n,n.track.streamState,i))}))},this.handleSubscriptionPermissionUpdate=t=>{const i=this.participants.get(t.participantSid);if(!i)return;const n=i.getTrackPublication(t.trackSid);n&&(n._allowed=t.allowed,i.emit(e.ParticipantEvent.TrackSubscriptionPermissionChanged,n,n.subscriptionStatus),this.emit(e.ParticipantEvent.TrackSubscriptionPermissionChanged,n,n.subscriptionStatus,i))},this.handleDataPacket=(t,i)=>{const n=this.participants.get(t.participantSid);this.emit(e.RoomEvent.DataReceived,t.payload,n,i),n?.emit(e.ParticipantEvent.DataReceived,t.payload,i)},this.handleAudioPlaybackStarted=()=>{this.canPlaybackAudio||(this.audioEnabled=!0,this.emit(e.RoomEvent.AudioPlaybackStatusChanged,!0))},this.handleAudioPlaybackFailed=t=>{s.warn("could not playback audio",t),this.canPlaybackAudio&&(this.audioEnabled=!1,this.emit(e.RoomEvent.AudioPlaybackStatusChanged,!1))},this.handleDeviceChange=async()=>{this.emit(e.RoomEvent.MediaDevicesChanged)},this.handleRoomUpdate=t=>{this.metadata=t.metadata,this.emit(e.RoomEvent.RoomMetadataChanged,t.metadata)},this.handleConnectionQualityUpdate=e=>{e.updates.forEach((e=>{if(e.participantSid===this.localParticipant.sid)return void this.localParticipant.setConnectionQuality(e.quality);const t=this.participants.get(e.participantSid);t&&t.setConnectionQuality(e.quality)}))},this.participants=new Map,this.options=t||{},this.options?.publishDefaults?.videoCodec){case"av1":case"vp9":this.options.publishDefaults.simulcast=void 0}this.options.audioCaptureDefaults={...es,...t?.audioCaptureDefaults},this.options.videoCaptureDefaults={...ts,...t?.videoCaptureDefaults},this.options.publishDefaults={...Xr,...t?.publishDefaults},this.createEngine(),this.localParticipant=new xn("","",this.engine,this.options)}createEngine(){this.engine||(this.engine=new $r,this.engine.client.signalLatency=this.options.expSignalLatency,this.engine.client.onParticipantUpdate=this.handleParticipantUpdates,this.engine.client.onRoomUpdate=this.handleRoomUpdate,this.engine.client.onSpeakersChanged=this.handleSpeakersChanged,this.engine.client.onStreamStateUpdate=this.handleStreamStateUpdate,this.engine.client.onSubscriptionPermissionUpdate=this.handleSubscriptionPermissionUpdate,this.engine.client.onConnectionQuality=this.handleConnectionQualityUpdate,this.engine.on(e.EngineEvent.MediaTrackAdded,((e,t,i)=>{this.onTrackAdded(e,t,i)})).on(e.EngineEvent.Disconnected,(()=>{this.handleDisconnect()})).on(e.EngineEvent.ActiveSpeakersUpdate,this.handleActiveSpeakersUpdate).on(e.EngineEvent.DataPacketReceived,this.handleDataPacket).on(e.EngineEvent.Resuming,(()=>{this.state=e.RoomState.Reconnecting,this.emit(e.RoomEvent.Reconnecting),this.emit(e.RoomEvent.StateChanged,this.state)})).on(e.EngineEvent.Resumed,(()=>{this.state=e.RoomState.Connected,this.emit(e.RoomEvent.Reconnected),this.emit(e.RoomEvent.StateChanged,this.state),this.updateSubscriptions()})).on(e.EngineEvent.SignalResumed,(()=>{this.state===e.RoomState.Reconnecting&&this.sendSyncState()})).on(e.EngineEvent.Restarting,this.handleRestarting).on(e.EngineEvent.Restarted,this.handleRestarted))}static getLocalDevices(e,t=!0){return Ei.getInstance().getDevices(e,t)}getParticipantByIdentity(e){for(const[,t]of this.participants)if(t.identity===e)return t;if(this.localParticipant.identity===e)return this.localParticipant}simulateScenario(e){let t;switch(e){case"speaker":t=ui.fromPartial({speakerUpdate:3});break;case"node-failure":t=ui.fromPartial({nodeFailure:!0});break;case"server-leave":t=ui.fromPartial({serverLeave:!0});break;case"migration":t=ui.fromPartial({migration:!0})}t&&this.engine.client.sendSimulateScenario(t)}async startAudio(){this.acquireAudioContext();const e=[];this.participants.forEach((t=>{t.audioTracks.forEach((t=>{t.track&&t.track.attachedElements.forEach((t=>{e.push(t)}))}))}));try{await Promise.all(e.map((e=>e.play()))),this.handleAudioPlaybackStarted()}catch(e){throw this.handleAudioPlaybackFailed(e),e}}get canPlaybackAudio(){return this.audioEnabled}async switchActiveDevice(e,t){if("audioinput"===e){const e=Array.from(this.localParticipant.audioTracks.values()).filter((e=>e.source===en.Source.Microphone));await Promise.all(e.map((e=>e.audioTrack?.setDeviceId(t)))),this.options.audioCaptureDefaults.deviceId=t}else if("videoinput"===e){const e=Array.from(this.localParticipant.videoTracks.values()).filter((e=>e.source===en.Source.Camera));await Promise.all(e.map((e=>e.videoTrack?.setDeviceId(t)))),this.options.videoCaptureDefaults.deviceId=t}else if("audiooutput"===e){const e=[];this.participants.forEach((t=>{t.audioTracks.forEach((t=>{t.isSubscribed&&t.track&&t.track.attachedElements.forEach((t=>{e.push(t)}))}))})),await Promise.all(e.map((async e=>{"setSinkId"in e&&await e.setSinkId(t)})))}}onTrackAdded(e,t,i){const n=function(e){const t=e.split("|");return t.length>1?[t[0],e.substr(t[0].length+1)]:[e,""]}(t.id),r=n[0];let s=n[1];s&&""!==s||(s=e.id);const a=this.getOrCreateParticipant(r);let o;this.options.adaptiveStream&&(o="object"==typeof this.options.adaptiveStream?this.options.adaptiveStream:{}),a.addSubscribedMediaTrack(e,s,t,i,o)}handleDisconnect(t=!0){this.state!==e.RoomState.Disconnected&&(this.participants.forEach((e=>{e.tracks.forEach((t=>{e.unpublishTrack(t.trackSid)}))})),this.localParticipant.tracks.forEach((e=>{e.track&&this.localParticipant.unpublishTrack(e.track),t&&(e.track?.detach(),e.track?.stop())})),this.participants.clear(),this.activeSpeakers=[],this.audioContext&&(this.audioContext.close(),this.audioContext=void 0),Di()&&(window.removeEventListener("beforeunload",this.onBeforeUnload),navigator.mediaDevices?.removeEventListener("devicechange",this.handleDeviceChange)),this.state=e.RoomState.Disconnected,this.emit(e.RoomEvent.Disconnected),this.emit(e.RoomEvent.StateChanged,this.state))}handleParticipantDisconnected(t,i){this.participants.delete(t),i&&(i.tracks.forEach((e=>{i.unpublishTrack(e.trackSid)})),this.emit(e.RoomEvent.ParticipantDisconnected,i))}acquireAudioContext(){this.audioContext&&this.audioContext.close();const e=cn();e&&(this.audioContext=e)}createParticipant(e,t){let i;return i=t?_n.fromParticipantInfo(this.engine.client,t):new _n(this.engine.client,e,""),i}getOrCreateParticipant(t,i){if(this.participants.has(t))return this.participants.get(t);const n=this.createParticipant(t,i);return this.participants.set(t,n),n.on(e.ParticipantEvent.TrackPublished,(t=>{this.emit(e.RoomEvent.TrackPublished,t,n)})).on(e.ParticipantEvent.TrackSubscribed,((t,i)=>{t.kind===en.Kind.Audio&&(t.on(e.TrackEvent.AudioPlaybackStarted,this.handleAudioPlaybackStarted),t.on(e.TrackEvent.AudioPlaybackFailed,this.handleAudioPlaybackFailed)),this.emit(e.RoomEvent.TrackSubscribed,t,i,n)})).on(e.ParticipantEvent.TrackUnpublished,(t=>{this.emit(e.RoomEvent.TrackUnpublished,t,n)})).on(e.ParticipantEvent.TrackUnsubscribed,((t,i)=>{this.emit(e.RoomEvent.TrackUnsubscribed,t,i,n)})).on(e.ParticipantEvent.TrackSubscriptionFailed,(t=>{this.emit(e.RoomEvent.TrackSubscriptionFailed,t,n)})).on(e.ParticipantEvent.TrackMuted,(t=>{this.emit(e.RoomEvent.TrackMuted,t,n)})).on(e.ParticipantEvent.TrackUnmuted,(t=>{this.emit(e.RoomEvent.TrackUnmuted,t,n)})).on(e.ParticipantEvent.MetadataChanged,(t=>{this.emit(e.RoomEvent.MetadataChanged,t,n)})).on(e.ParticipantEvent.ParticipantMetadataChanged,(t=>{this.emit(e.RoomEvent.ParticipantMetadataChanged,t,n)})).on(e.ParticipantEvent.ConnectionQualityChanged,(t=>{this.emit(e.RoomEvent.ConnectionQualityChanged,t,n)})).on(e.ParticipantEvent.ParticipantPermissionsChanged,(t=>{this.emit(e.RoomEvent.ParticipantPermissionsChanged,t,n)})),n}sendSyncState(){if(void 0===this.engine.subscriber||null===this.engine.subscriber.pc.localDescription)return;const e=this.engine.subscriber.pc.localDescription,t=this.connOptions?.autoSubscribe||!1,i=new Array;this.participants.forEach((e=>{e.tracks.forEach((e=>{e.isSubscribed!==t&&i.push(e.trackSid)}))})),this.engine.client.sendSyncState({answer:Gr({sdp:e.sdp,type:e.type}),subscription:{trackSids:i,subscribe:!t,participantTracks:[]},publishTracks:this.localParticipant.publishedTracksInfo(),dataChannels:this.localParticipant.dataChannelsInfo()})}updateSubscriptions(){for(const e of this.participants.values())for(const t of e.videoTracks.values())t.isSubscribed&&t instanceof Mn&&t.emitTrackUpdate()}emit(e,...t){return s.debug("room event",{event:e,args:t}),super.emit(e,...t)}}async function rs(e){e??={},e.audio??=!0,e.video??=!0;const t=on(sn(e,es,ts)),i=await navigator.mediaDevices.getUserMedia(t);return i.getTracks().map((n=>{const r="audio"===n.kind;let s;r?e.audio:e.video;const a=r?t.audio:t.video;"boolean"!=typeof a&&(s=a);const o=Tn(n,s);return o.kind===en.Kind.Video?o.source=en.Source.Camera:o.kind===en.Kind.Audio&&(o.source=en.Source.Microphone),o.mediaStream=i,o}))}e.ConnectionError=pi,e.LivekitError=hi,e.LocalAudioTrack=dn,e.LocalParticipant=xn,e.LocalTrack=rn,e.LocalTrackPublication=gn,e.LocalVideoTrack=un,e.Participant=Cn,e.PublishDataError=class extends hi{constructor(e){super(13,e||"Unable to publish data")}},e.RemoteAudioTrack=pn,e.RemoteParticipant=_n,e.RemoteTrack=hn,e.RemoteTrackPublication=Mn,e.RemoteVideoTrack=mn,e.Room=ns,e.ScreenSharePresets=wn,e.Track=en,e.TrackInvalidError=fi,e.TrackPublication=vn,e.UnexpectedConnectionState=vi,e.UnsupportedServer=mi,e.VideoPreset=bn,e.VideoPresets=Sn,e.VideoPresets43=yn,e.attachToElement=tn,e.connect=async function(t,i,n){n??={},void 0===n.adaptiveStream&&(n.adaptiveStream=!0===n.autoManageVideo?{}:void 0),a(n.logLevel??e.LogLevel.warn);const r=n.rtcConfig??{};n.iceServers&&(r.iceServers=n.iceServers);const o=new ns(n);await o.connect(t,i,n);const c=n.audio??!1,d=n.video??!1;return(c||d)&&setTimeout((async()=>{let t;if(c&&d)try{await o.localParticipant.enableCameraAndMicrophone()}catch(i){const n=e.MediaDeviceFailure.getFailure(i);if(s.warn("received error while creating media",{error:n}),i instanceof Error&&s.warn(i.message),n===e.MediaDeviceFailure.NotFound||n===e.MediaDeviceFailure.DeviceInUse)try{await o.localParticipant.setMicrophoneEnabled(!0)}catch(e){t=e}else t=i}else if(c)try{await o.localParticipant.setMicrophoneEnabled(!0)}catch(e){t=e}else if(d)try{await o.localParticipant.setCameraEnabled(!0)}catch(e){t=e}t&&(o.emit(e.RoomEvent.MediaDevicesError,t),s.error("could not create media",t))})),o},e.createLocalAudioTrack=async function(e){return(await rs({audio:e,video:!1}))[0]},e.createLocalScreenTracks=async function(e){void 0===e&&(e={}),void 0===e.resolution&&(e.resolution=Sn.fhd.resolution);let t=!0;e.resolution&&(t={width:e.resolution.width,height:e.resolution.height});const i=await navigator.mediaDevices.getDisplayMedia({audio:e.audio??!1,video:t}),n=i.getVideoTracks();if(0===n.length)throw new fi("no video track found");const r=new un(n[0]);r.source=en.Source.ScreenShare;const s=[r];if(i.getAudioTracks().length>0){const e=new dn(i.getAudioTracks()[0]);e.source=en.Source.ScreenShareAudio,s.push(e)}return s},e.createLocalTracks=rs,e.createLocalVideoTrack=async function(e){return(await rs({audio:!1,video:e}))[0]},e.detachTrack=nn,e.protocolVersion=7,e.setLogExtension=function(t){const i=s.methodFactory;s.methodFactory=(n,r,a)=>{const o=i(n,r,a),c=s.getLevel(),d=r>=c&&r<e.LogLevel.silent;return(e,i)=>{i?o(e,i):o(e),d&&t(r,e,i)}},s.setLevel(s.getLevel())},e.setLogLevel=a,e.version=Pi,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LivekitClient={})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(i){if("default"!==i&&!(i in e)){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}}))})),Object.freeze(e)}var i,n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}};!function(e){var t,i;t=n,i=function(){var e=function(){},t="undefined",i=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"];function r(e,t){var i=e[t];if("function"==typeof i.bind)return i.bind(e);try{return Function.prototype.bind.call(i,e)}catch(t){return function(){return Function.prototype.apply.apply(i,[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 a(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&i?s:void 0!==console[n]?r(console,n):void 0!==console.log?r(console,"log"):e)}function o(t,i){for(var r=0;r<n.length;r++){var s=n[r];this[s]=r<t?e:this.methodFactory(s,t,i)}this.log=this.debug}function c(e,i,n){return function(){typeof console!==t&&(o.call(this,i,n),this[e].apply(this,arguments))}}function d(e,t,i){return a(e)||c.apply(this,arguments)}function u(e,i,r){var s,a=this;i=null==i?"WARN":i;var c="loglevel";function u(){var e;if(typeof window!==t&&c){try{e=window.localStorage[c]}catch(e){}if(typeof e===t)try{var i=window.document.cookie,n=i.indexOf(encodeURIComponent(c)+"=");-1!==n&&(e=/^([^;]+)/.exec(i.slice(n))[1])}catch(e){}return void 0===a.levels[e]&&(e=void 0),e}}"string"==typeof e?c+=":"+e:"symbol"==typeof e&&(c=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=r||d,a.getLevel=function(){return s},a.setLevel=function(i,r){if("string"==typeof i&&void 0!==a.levels[i.toUpperCase()]&&(i=a.levels[i.toUpperCase()]),!("number"==typeof i&&i>=0&&i<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+i;if(s=i,!1!==r&&function(e){var i=(n[e]||"silent").toUpperCase();if(typeof window!==t&&c){try{return void(window.localStorage[c]=i)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"="+i+";"}catch(e){}}}(i),o.call(a,i,e),typeof console===t&&i<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){i=e,u()||a.setLevel(e,!1)},a.resetLevel=function(){a.setLevel(i,!1),function(){if(typeof window!==t&&c){try{return void window.localStorage.removeItem(c)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var l=u();null==l&&(l=i),a.setLevel(l,!1)}var l=new u,h={};l.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=h[e];return t||(t=h[e]=new u(e,l.getLevel(),l.methodFactory)),t};var p=typeof window!==t?window.log:void 0;return l.noConflict=function(){return typeof window!==t&&window.log===l&&(window.log=p),l},l.getLoggers=function(){return h},l.default=l,l},e.exports?e.exports=i():t.log=i()}(r),e.LogLevel=void 0,(i=e.LogLevel||(e.LogLevel={}))[i.trace=0]="trace",i[i.debug=1]="debug",i[i.info=2]="info",i[i.warn=3]="warn",i[i.error=4]="error",i[i.silent=5]="silent";const s=r.exports.getLogger("livekit");function a(e){s.setLevel(e)}s.setLevel(e.LogLevel.info);var o=d,c=null;try{c=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function d(e,t,i){this.low=0|e,this.high=0|t,this.unsigned=!!i}function u(e){return!0===(e&&e.__isLong__)}d.prototype.__isLong__,Object.defineProperty(d.prototype,"__isLong__",{value:!0}),d.isLong=u;var l={},h={};function p(e,t){var i,n,r;return t?(r=0<=(e>>>=0)&&e<256)&&(n=h[e])?n:(i=f(e,(0|e)<0?-1:0,!0),r&&(h[e]=i),i):(r=-128<=(e|=0)&&e<128)&&(n=l[e])?n:(i=f(e,e<0?-1:0,!1),r&&(l[e]=i),i)}function m(e,t){if(isNaN(e))return t?T:C;if(t){if(e<0)return T;if(e>=S)return N}else{if(e<=-y)return D;if(e+1>=y)return O}return e<0?m(-e,t).neg():f(e%k|0,e/k|0,t)}function f(e,t,i){return new d(e,t,i)}d.fromInt=p,d.fromNumber=m,d.fromBits=f;var v=Math.pow;function g(e,t,i){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return C;if("number"==typeof t?(i=t,t=!1):t=!!t,(i=i||10)<2||36<i)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return g(e.substring(1),t,i).neg();for(var r=m(v(i,8)),s=C,a=0;a<e.length;a+=8){var o=Math.min(8,e.length-a),c=parseInt(e.substring(a,a+o),i);if(o<8){var d=m(v(i,o));s=s.mul(d).add(m(c))}else s=(s=s.mul(r)).add(m(c))}return s.unsigned=t,s}function b(e,t){return"number"==typeof e?m(e,t):"string"==typeof e?g(e,t):f(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}d.fromString=g,d.fromValue=b;var k=4294967296,S=k*k,y=S/2,w=p(1<<24),C=p(0);d.ZERO=C;var T=p(0,!0);d.UZERO=T;var E=p(1);d.ONE=E;var P=p(1,!0);d.UONE=P;var R=p(-1);d.NEG_ONE=R;var O=f(-1,2147483647,!1);d.MAX_VALUE=O;var N=f(-1,-1,!0);d.MAX_UNSIGNED_VALUE=N;var D=f(0,-2147483648,!1);d.MIN_VALUE=D;var U=d.prototype;U.toInt=function(){return this.unsigned?this.low>>>0:this.low},U.toNumber=function(){return this.unsigned?(this.high>>>0)*k+(this.low>>>0):this.high*k+(this.low>>>0)},U.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(D)){var t=m(e),i=this.div(t),n=i.mul(t).sub(this);return i.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var r=m(v(e,6),this.unsigned),s=this,a="";;){var o=s.div(r),c=(s.sub(o.mul(r)).toInt()>>>0).toString(e);if((s=o).isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},U.getHighBits=function(){return this.high},U.getHighBitsUnsigned=function(){return this.high>>>0},U.getLowBits=function(){return this.low},U.getLowBitsUnsigned=function(){return this.low>>>0},U.getNumBitsAbs=function(){if(this.isNegative())return this.eq(D)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},U.isZero=function(){return 0===this.high&&0===this.low},U.eqz=U.isZero,U.isNegative=function(){return!this.unsigned&&this.high<0},U.isPositive=function(){return this.unsigned||this.high>=0},U.isOdd=function(){return 1==(1&this.low)},U.isEven=function(){return 0==(1&this.low)},U.equals=function(e){return u(e)||(e=b(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},U.eq=U.equals,U.notEquals=function(e){return!this.eq(e)},U.neq=U.notEquals,U.ne=U.notEquals,U.lessThan=function(e){return this.comp(e)<0},U.lt=U.lessThan,U.lessThanOrEqual=function(e){return this.comp(e)<=0},U.lte=U.lessThanOrEqual,U.le=U.lessThanOrEqual,U.greaterThan=function(e){return this.comp(e)>0},U.gt=U.greaterThan,U.greaterThanOrEqual=function(e){return this.comp(e)>=0},U.gte=U.greaterThanOrEqual,U.ge=U.greaterThanOrEqual,U.compare=function(e){if(u(e)||(e=b(e)),this.eq(e))return 0;var t=this.isNegative(),i=e.isNegative();return t&&!i?-1:!t&&i?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},U.comp=U.compare,U.negate=function(){return!this.unsigned&&this.eq(D)?D:this.not().add(E)},U.neg=U.negate,U.add=function(e){u(e)||(e=b(e));var t=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,s=e.high>>>16,a=65535&e.high,o=e.low>>>16,c=0,d=0,l=0,h=0;return l+=(h+=r+(65535&e.low))>>>16,d+=(l+=n+o)>>>16,c+=(d+=i+a)>>>16,c+=t+s,f((l&=65535)<<16|(h&=65535),(c&=65535)<<16|(d&=65535),this.unsigned)},U.subtract=function(e){return u(e)||(e=b(e)),this.add(e.neg())},U.sub=U.subtract,U.multiply=function(e){if(this.isZero())return C;if(u(e)||(e=b(e)),c)return f(c.mul(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned);if(e.isZero())return C;if(this.eq(D))return e.isOdd()?D:C;if(e.eq(D))return this.isOdd()?D:C;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(w)&&e.lt(w))return m(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,s=e.high>>>16,a=65535&e.high,o=e.low>>>16,d=65535&e.low,l=0,h=0,p=0,v=0;return p+=(v+=r*d)>>>16,h+=(p+=n*d)>>>16,p&=65535,h+=(p+=r*o)>>>16,l+=(h+=i*d)>>>16,h&=65535,l+=(h+=n*o)>>>16,h&=65535,l+=(h+=r*a)>>>16,l+=t*d+i*o+n*a+r*s,f((p&=65535)<<16|(v&=65535),(l&=65535)<<16|(h&=65535),this.unsigned)},U.mul=U.multiply,U.divide=function(e){if(u(e)||(e=b(e)),e.isZero())throw Error("division by zero");var t,i,n;if(c)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?f((this.unsigned?c.div_u:c.div_s)(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?T:C;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return T;if(e.gt(this.shru(1)))return P;n=T}else{if(this.eq(D))return e.eq(E)||e.eq(R)?D:e.eq(D)?E:(t=this.shr(1).div(e).shl(1)).eq(C)?e.isNegative()?E:R:(i=this.sub(e.mul(t)),n=t.add(i.div(e)));if(e.eq(D))return this.unsigned?T:C;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=C}for(i=this;i.gte(e);){t=Math.max(1,Math.floor(i.toNumber()/e.toNumber()));for(var r=Math.ceil(Math.log(t)/Math.LN2),s=r<=48?1:v(2,r-48),a=m(t),o=a.mul(e);o.isNegative()||o.gt(i);)o=(a=m(t-=s,this.unsigned)).mul(e);a.isZero()&&(a=E),n=n.add(a),i=i.sub(o)}return n},U.div=U.divide,U.modulo=function(e){return u(e)||(e=b(e)),c?f((this.unsigned?c.rem_u:c.rem_s)(this.low,this.high,e.low,e.high),c.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},U.mod=U.modulo,U.rem=U.modulo,U.not=function(){return f(~this.low,~this.high,this.unsigned)},U.and=function(e){return u(e)||(e=b(e)),f(this.low&e.low,this.high&e.high,this.unsigned)},U.or=function(e){return u(e)||(e=b(e)),f(this.low|e.low,this.high|e.high,this.unsigned)},U.xor=function(e){return u(e)||(e=b(e)),f(this.low^e.low,this.high^e.high,this.unsigned)},U.shiftLeft=function(e){return u(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?f(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):f(0,this.low<<e-32,this.unsigned)},U.shl=U.shiftLeft,U.shiftRight=function(e){return u(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?f(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):f(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},U.shr=U.shiftRight,U.shiftRightUnsigned=function(e){if(u(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?f(this.low>>>e|t<<32-e,t>>>e,this.unsigned):f(32===e?t:t>>>e-32,0,this.unsigned)},U.shru=U.shiftRightUnsigned,U.shr_u=U.shiftRightUnsigned,U.toSigned=function(){return this.unsigned?f(this.low,this.high,!1):this},U.toUnsigned=function(){return this.unsigned?this:f(this.low,this.high,!0)},U.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},U.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},U.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},d.fromBytes=function(e,t,i){return i?d.fromBytesLE(e,t):d.fromBytesBE(e,t)},d.fromBytesLE=function(e,t){return new d(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},d.fromBytesBE=function(e,t){return new d(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};var A={},I={},L=function(e,t){var i=new Array(arguments.length-1),n=0,r=2,s=!0;for(;r<arguments.length;)i[n++]=arguments[r++];return new Promise((function(r,a){i[n]=function(e){if(s)if(s=!1,e)a(e);else{for(var t=new Array(arguments.length-1),i=0;i<t.length;)t[i++]=arguments[i];r.apply(null,t)}};try{e.apply(t||null,i)}catch(e){s&&(s=!1,a(e))}}))};var M={};!function(e){var t=e;t.length=function(e){var t=e.length;if(!t)return 0;for(var i=0;--t%4>1&&"="===e.charAt(t);)++i;return Math.ceil(3*e.length)/4-i};for(var i=new Array(64),n=new Array(123),r=0;r<64;)n[i[r]=r<26?r+65:r<52?r+71:r<62?r-4:r-59|43]=r++;t.encode=function(e,t,n){for(var r,s=null,a=[],o=0,c=0;t<n;){var d=e[t++];switch(c){case 0:a[o++]=i[d>>2],r=(3&d)<<4,c=1;break;case 1:a[o++]=i[r|d>>4],r=(15&d)<<2,c=2;break;case 2:a[o++]=i[r|d>>6],a[o++]=i[63&d],c=0}o>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,a)),o=0)}return c&&(a[o++]=i[r],a[o++]=61,1===c&&(a[o++]=61)),s?(o&&s.push(String.fromCharCode.apply(String,a.slice(0,o))),s.join("")):String.fromCharCode.apply(String,a.slice(0,o))};var s="invalid encoding";t.decode=function(e,t,i){for(var r,a=i,o=0,c=0;c<e.length;){var d=e.charCodeAt(c++);if(61===d&&o>1)break;if(void 0===(d=n[d]))throw Error(s);switch(o){case 0:r=d,o=1;break;case 1:t[i++]=r<<2|(48&d)>>4,r=d,o=2;break;case 2:t[i++]=(15&r)<<4|(60&d)>>2,r=d,o=3;break;case 3:t[i++]=(3&r)<<6|d,o=0}}if(1===o)throw Error(s);return i-a},t.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}}(M);var _=x;function x(){this._listeners={}}x.prototype.on=function(e,t,i){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:i||this}),this},x.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var i=this._listeners[e],n=0;n<i.length;)i[n].fn===t?i.splice(n,1):++n;return this},x.prototype.emit=function(e){var t=this._listeners[e];if(t){for(var i=[],n=1;n<arguments.length;)i.push(arguments[n++]);for(n=0;n<t.length;)t[n].fn.apply(t[n++].ctx,i)}return this};var J=B(B);function B(e){return"undefined"!=typeof Float32Array?function(){var t=new Float32Array([-0]),i=new Uint8Array(t.buffer),n=128===i[3];function r(e,n,r){t[0]=e,n[r]=i[0],n[r+1]=i[1],n[r+2]=i[2],n[r+3]=i[3]}function s(e,n,r){t[0]=e,n[r]=i[3],n[r+1]=i[2],n[r+2]=i[1],n[r+3]=i[0]}function a(e,n){return i[0]=e[n],i[1]=e[n+1],i[2]=e[n+2],i[3]=e[n+3],t[0]}function o(e,n){return i[3]=e[n],i[2]=e[n+1],i[1]=e[n+2],i[0]=e[n+3],t[0]}e.writeFloatLE=n?r:s,e.writeFloatBE=n?s:r,e.readFloatLE=n?a:o,e.readFloatBE=n?o:a}():function(){function t(e,t,i,n){var r=t<0?1:0;if(r&&(t=-t),0===t)e(1/t>0?0:2147483648,i,n);else if(isNaN(t))e(2143289344,i,n);else if(t>34028234663852886e22)e((r<<31|2139095040)>>>0,i,n);else if(t<11754943508222875e-54)e((r<<31|Math.round(t/1401298464324817e-60))>>>0,i,n);else{var s=Math.floor(Math.log(t)/Math.LN2);e((r<<31|s+127<<23|8388607&Math.round(t*Math.pow(2,-s)*8388608))>>>0,i,n)}}function i(e,t,i){var n=e(t,i),r=2*(n>>31)+1,s=n>>>23&255,a=8388607&n;return 255===s?a?NaN:r*(1/0):0===s?1401298464324817e-60*r*a:r*Math.pow(2,s-150)*(a+8388608)}e.writeFloatLE=t.bind(null,j),e.writeFloatBE=t.bind(null,V),e.readFloatLE=i.bind(null,F),e.readFloatBE=i.bind(null,q)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),i=new Uint8Array(t.buffer),n=128===i[7];function r(e,n,r){t[0]=e,n[r]=i[0],n[r+1]=i[1],n[r+2]=i[2],n[r+3]=i[3],n[r+4]=i[4],n[r+5]=i[5],n[r+6]=i[6],n[r+7]=i[7]}function s(e,n,r){t[0]=e,n[r]=i[7],n[r+1]=i[6],n[r+2]=i[5],n[r+3]=i[4],n[r+4]=i[3],n[r+5]=i[2],n[r+6]=i[1],n[r+7]=i[0]}function a(e,n){return i[0]=e[n],i[1]=e[n+1],i[2]=e[n+2],i[3]=e[n+3],i[4]=e[n+4],i[5]=e[n+5],i[6]=e[n+6],i[7]=e[n+7],t[0]}function o(e,n){return i[7]=e[n],i[6]=e[n+1],i[5]=e[n+2],i[4]=e[n+3],i[3]=e[n+4],i[2]=e[n+5],i[1]=e[n+6],i[0]=e[n+7],t[0]}e.writeDoubleLE=n?r:s,e.writeDoubleBE=n?s:r,e.readDoubleLE=n?a:o,e.readDoubleBE=n?o:a}():function(){function t(e,t,i,n,r,s){var a=n<0?1:0;if(a&&(n=-n),0===n)e(0,r,s+t),e(1/n>0?0:2147483648,r,s+i);else if(isNaN(n))e(0,r,s+t),e(2146959360,r,s+i);else if(n>17976931348623157e292)e(0,r,s+t),e((a<<31|2146435072)>>>0,r,s+i);else{var o;if(n<22250738585072014e-324)e((o=n/5e-324)>>>0,r,s+t),e((a<<31|o/4294967296)>>>0,r,s+i);else{var c=Math.floor(Math.log(n)/Math.LN2);1024===c&&(c=1023),e(4503599627370496*(o=n*Math.pow(2,-c))>>>0,r,s+t),e((a<<31|c+1023<<20|1048576*o&1048575)>>>0,r,s+i)}}}function i(e,t,i,n,r){var s=e(n,r+t),a=e(n,r+i),o=2*(a>>31)+1,c=a>>>20&2047,d=4294967296*(1048575&a)+s;return 2047===c?d?NaN:o*(1/0):0===c?5e-324*o*d:o*Math.pow(2,c-1075)*(d+4503599627370496)}e.writeDoubleLE=t.bind(null,j,0,4),e.writeDoubleBE=t.bind(null,V,4,0),e.readDoubleLE=i.bind(null,F,0,4),e.readDoubleBE=i.bind(null,q,4,0)}(),e}function j(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}function V(e,t,i){t[i]=e>>>24,t[i+1]=e>>>16&255,t[i+2]=e>>>8&255,t[i+3]=255&e}function F(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function q(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}var Q=function(e){try{var t=void 0;t}catch(e){}return null};var W={};!function(e){var t=e;t.length=function(e){for(var t=0,i=0,n=0;n<e.length;++n)(i=e.charCodeAt(n))<128?t+=1:i<2048?t+=2:55296==(64512&i)&&56320==(64512&e.charCodeAt(n+1))?(++n,t+=4):t+=3;return t},t.read=function(e,t,i){if(i-t<1)return"";for(var n,r=null,s=[],a=0;t<i;)(n=e[t++])<128?s[a++]=n:n>191&&n<224?s[a++]=(31&n)<<6|63&e[t++]:n>239&&n<365?(n=((7&n)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,s[a++]=55296+(n>>10),s[a++]=56320+(1023&n)):s[a++]=(15&n)<<12|(63&e[t++])<<6|63&e[t++],a>8191&&((r||(r=[])).push(String.fromCharCode.apply(String,s)),a=0);return r?(a&&r.push(String.fromCharCode.apply(String,s.slice(0,a))),r.join("")):String.fromCharCode.apply(String,s.slice(0,a))},t.write=function(e,t,i){for(var n,r,s=i,a=0;a<e.length;++a)(n=e.charCodeAt(a))<128?t[i++]=n:n<2048?(t[i++]=n>>6|192,t[i++]=63&n|128):55296==(64512&n)&&56320==(64512&(r=e.charCodeAt(a+1)))?(n=65536+((1023&n)<<10)+(1023&r),++a,t[i++]=n>>18|240,t[i++]=n>>12&63|128,t[i++]=n>>6&63|128,t[i++]=63&n|128):(t[i++]=n>>12|224,t[i++]=n>>6&63|128,t[i++]=63&n|128);return i-s}}(W);var G=function(e,t,i){var n=i||8192,r=n>>>1,s=null,a=n;return function(i){if(i<1||i>r)return e(i);a+i>n&&(s=e(n),a=0);var o=t.call(s,a,a+=i);return 7&a&&(a=1+(7|a)),o}};var K=z,H=I;function z(e,t){this.lo=e>>>0,this.hi=t>>>0}var Z=z.zero=new z(0,0);Z.toNumber=function(){return 0},Z.zzEncode=Z.zzDecode=function(){return this},Z.length=function(){return 1};var $=z.zeroHash="\0\0\0\0\0\0\0\0";z.fromNumber=function(e){if(0===e)return Z;var t=e<0;t&&(e=-e);var i=e>>>0,n=(e-i)/4294967296>>>0;return t&&(n=~n>>>0,i=~i>>>0,++i>4294967295&&(i=0,++n>4294967295&&(n=0))),new z(i,n)},z.from=function(e){if("number"==typeof e)return z.fromNumber(e);if(H.isString(e)){if(!H.Long)return z.fromNumber(parseInt(e,10));e=H.Long.fromString(e)}return e.low||e.high?new z(e.low>>>0,e.high>>>0):Z},z.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,i=~this.hi>>>0;return t||(i=i+1>>>0),-(t+4294967296*i)}return this.lo+4294967296*this.hi},z.prototype.toLong=function(e){return H.Long?new H.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var Y=String.prototype.charCodeAt;z.fromHash=function(e){return e===$?Z:new z((Y.call(e,0)|Y.call(e,1)<<8|Y.call(e,2)<<16|Y.call(e,3)<<24)>>>0,(Y.call(e,4)|Y.call(e,5)<<8|Y.call(e,6)<<16|Y.call(e,7)<<24)>>>0)},z.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},z.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},z.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},z.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return 0===i?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:i<128?9:10},function(e){var t=e;function i(e,t,i){for(var n=Object.keys(t),r=0;r<n.length;++r)void 0!==e[n[r]]&&i||(e[n[r]]=t[n[r]]);return e}function r(e){function t(e,n){if(!(this instanceof t))return new t(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),n&&i(this,n)}return(t.prototype=Object.create(Error.prototype)).constructor=t,Object.defineProperty(t.prototype,"name",{get:function(){return e}}),t.prototype.toString=function(){return this.name+": "+this.message},t}t.asPromise=L,t.base64=M,t.EventEmitter=_,t.float=J,t.inquire=Q,t.utf8=W,t.pool=G,t.LongBits=K,t.isNode=Boolean(void 0!==n&&n&&n.process&&n.process.versions&&n.process.versions.node),t.global=t.isNode&&n||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||n,t.emptyArray=Object.freeze?Object.freeze([]):[],t.emptyObject=Object.freeze?Object.freeze({}):{},t.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},t.isString=function(e){return"string"==typeof e||e instanceof String},t.isObject=function(e){return e&&"object"==typeof e},t.isset=t.isSet=function(e,t){var i=e[t];return!(null==i||!e.hasOwnProperty(t))&&("object"!=typeof i||(Array.isArray(i)?i.length:Object.keys(i).length)>0)},t.Buffer=function(){try{var e=t.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),t._Buffer_from=null,t._Buffer_allocUnsafe=null,t.newBuffer=function(e){return"number"==typeof e?t.Buffer?t._Buffer_allocUnsafe(e):new t.Array(e):t.Buffer?t._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},t.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,t.Long=t.global.dcodeIO&&t.global.dcodeIO.Long||t.global.Long||t.inquire("long"),t.key2Re=/^true|false|0|1$/,t.key32Re=/^-?(?:0|[1-9][0-9]*)$/,t.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,t.longToHash=function(e){return e?t.LongBits.from(e).toHash():t.LongBits.zeroHash},t.longFromHash=function(e,i){var n=t.LongBits.fromHash(e);return t.Long?t.Long.fromBits(n.lo,n.hi,i):n.toNumber(Boolean(i))},t.merge=i,t.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},t.newError=r,t.ProtocolError=r("ProtocolError"),t.oneOfGetter=function(e){for(var t={},i=0;i<e.length;++i)t[e[i]]=1;return function(){for(var e=Object.keys(this),i=e.length-1;i>-1;--i)if(1===t[e[i]]&&void 0!==this[e[i]]&&null!==this[e[i]])return e[i]}},t.oneOfSetter=function(e){return function(t){for(var i=0;i<e.length;++i)e[i]!==t&&delete this[e[i]]}},t.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},t._configure=function(){var e=t.Buffer;e?(t._Buffer_from=e.from!==Uint8Array.from&&e.from||function(t,i){return new e(t,i)},t._Buffer_allocUnsafe=e.allocUnsafe||function(t){return new e(t)}):t._Buffer_from=t._Buffer_allocUnsafe=null}}(I);var X,ee=ce,te=I,ie=te.LongBits,ne=te.base64,re=te.utf8;function se(e,t,i){this.fn=e,this.len=t,this.next=void 0,this.val=i}function ae(){}function oe(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}function ce(){this.len=0,this.head=new se(ae,0,0),this.tail=this.head,this.states=null}var de=function(){return te.Buffer?function(){return(ce.create=function(){return new X})()}:function(){return new ce}};function ue(e,t,i){t[i]=255&e}function le(e,t){this.len=e,this.next=void 0,this.val=t}function he(e,t,i){for(;e.hi;)t[i++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[i++]=127&e.lo|128,e.lo=e.lo>>>7;t[i++]=e.lo}function pe(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}ce.create=de(),ce.alloc=function(e){return new te.Array(e)},te.Array!==Array&&(ce.alloc=te.pool(ce.alloc,te.Array.prototype.subarray)),ce.prototype._push=function(e,t,i){return this.tail=this.tail.next=new se(e,t,i),this.len+=t,this},le.prototype=Object.create(se.prototype),le.prototype.fn=function(e,t,i){for(;e>127;)t[i++]=127&e|128,e>>>=7;t[i]=e},ce.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new le((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},ce.prototype.int32=function(e){return e<0?this._push(he,10,ie.fromNumber(e)):this.uint32(e)},ce.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},ce.prototype.uint64=function(e){var t=ie.from(e);return this._push(he,t.length(),t)},ce.prototype.int64=ce.prototype.uint64,ce.prototype.sint64=function(e){var t=ie.from(e).zzEncode();return this._push(he,t.length(),t)},ce.prototype.bool=function(e){return this._push(ue,1,e?1:0)},ce.prototype.fixed32=function(e){return this._push(pe,4,e>>>0)},ce.prototype.sfixed32=ce.prototype.fixed32,ce.prototype.fixed64=function(e){var t=ie.from(e);return this._push(pe,4,t.lo)._push(pe,4,t.hi)},ce.prototype.sfixed64=ce.prototype.fixed64,ce.prototype.float=function(e){return this._push(te.float.writeFloatLE,4,e)},ce.prototype.double=function(e){return this._push(te.float.writeDoubleLE,8,e)};var me=te.Array.prototype.set?function(e,t,i){t.set(e,i)}:function(e,t,i){for(var n=0;n<e.length;++n)t[i+n]=e[n]};ce.prototype.bytes=function(e){var t=e.length>>>0;if(!t)return this._push(ue,1,0);if(te.isString(e)){var i=ce.alloc(t=ne.length(e));ne.decode(e,i,0),e=i}return this.uint32(t)._push(me,t,e)},ce.prototype.string=function(e){var t=re.length(e);return t?this.uint32(t)._push(re.write,t,e):this._push(ue,1,0)},ce.prototype.fork=function(){return this.states=new oe(this),this.head=this.tail=new se(ae,0,0),this.len=0,this},ce.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new se(ae,0,0),this.len=0),this},ce.prototype.ldelim=function(){var e=this.head,t=this.tail,i=this.len;return this.reset().uint32(i),i&&(this.tail.next=e.next,this.tail=t,this.len+=i),this},ce.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),i=0;e;)e.fn(e.val,t,i),i+=e.len,e=e.next;return t},ce._configure=function(e){X=e,ce.create=de(),X._configure()};var fe=be,ve=ee;(be.prototype=Object.create(ve.prototype)).constructor=be;var ge=I;function be(){ve.call(this)}function ke(e,t,i){e.length<40?ge.utf8.write(e,t,i):t.utf8Write?t.utf8Write(e,i):t.write(e,i)}be._configure=function(){be.alloc=ge._Buffer_allocUnsafe,be.writeBytesBuffer=ge.Buffer&&ge.Buffer.prototype instanceof Uint8Array&&"set"===ge.Buffer.prototype.set.name?function(e,t,i){t.set(e,i)}:function(e,t,i){if(e.copy)e.copy(t,i,0,e.length);else for(var n=0;n<e.length;)t[i++]=e[n++]}},be.prototype.bytes=function(e){ge.isString(e)&&(e=ge._Buffer_from(e,"base64"));var t=e.length>>>0;return this.uint32(t),t&&this._push(be.writeBytesBuffer,t,e),this},be.prototype.string=function(e){var t=ge.Buffer.byteLength(e);return this.uint32(t),t&&this._push(ke,t,e),this},be._configure();var Se,ye=Pe,we=I,Ce=we.LongBits,Te=we.utf8;function Ee(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function Pe(e){this.buf=e,this.pos=0,this.len=e.length}var Re,Oe="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new Pe(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new Pe(e);throw Error("illegal buffer")},Ne=function(){return we.Buffer?function(e){return(Pe.create=function(e){return we.Buffer.isBuffer(e)?new Se(e):Oe(e)})(e)}:Oe};function De(){var e=new Ce(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw Ee(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ee(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function Ue(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function Ae(){if(this.pos+8>this.len)throw Ee(this,8);return new Ce(Ue(this.buf,this.pos+=4),Ue(this.buf,this.pos+=4))}Pe.create=Ne(),Pe.prototype._slice=we.Array.prototype.subarray||we.Array.prototype.slice,Pe.prototype.uint32=(Re=4294967295,function(){if(Re=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return Re;if(Re=(Re|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return Re;if((this.pos+=5)>this.len)throw this.pos=this.len,Ee(this,10);return Re}),Pe.prototype.int32=function(){return 0|this.uint32()},Pe.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},Pe.prototype.bool=function(){return 0!==this.uint32()},Pe.prototype.fixed32=function(){if(this.pos+4>this.len)throw Ee(this,4);return Ue(this.buf,this.pos+=4)},Pe.prototype.sfixed32=function(){if(this.pos+4>this.len)throw Ee(this,4);return 0|Ue(this.buf,this.pos+=4)},Pe.prototype.float=function(){if(this.pos+4>this.len)throw Ee(this,4);var e=we.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},Pe.prototype.double=function(){if(this.pos+8>this.len)throw Ee(this,4);var e=we.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},Pe.prototype.bytes=function(){var e=this.uint32(),t=this.pos,i=this.pos+e;if(i>this.len)throw Ee(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,i):t===i?new this.buf.constructor(0):this._slice.call(this.buf,t,i)},Pe.prototype.string=function(){var e=this.bytes();return Te.read(e,0,e.length)},Pe.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw Ee(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw Ee(this)}while(128&this.buf[this.pos++]);return this},Pe.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},Pe._configure=function(e){Se=e,Pe.create=Ne(),Se._configure();var t=we.Long?"toLong":"toNumber";we.merge(Pe.prototype,{int64:function(){return De.call(this)[t](!1)},uint64:function(){return De.call(this)[t](!0)},sint64:function(){return De.call(this).zzDecode()[t](!1)},fixed64:function(){return Ae.call(this)[t](!0)},sfixed64:function(){return Ae.call(this)[t](!1)}})};var Ie=_e,Le=ye;(_e.prototype=Object.create(Le.prototype)).constructor=_e;var Me=I;function _e(e){Le.call(this,e)}_e._configure=function(){Me.Buffer&&(_e.prototype._slice=Me.Buffer.prototype.slice)},_e.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},_e._configure();var xe={},Je=je,Be=I;function je(e,t,i){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");Be.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(i)}(je.prototype=Object.create(Be.EventEmitter.prototype)).constructor=je,je.prototype.rpcCall=function e(t,i,n,r,s){if(!r)throw TypeError("request must be specified");var a=this;if(!s)return Be.asPromise(e,a,t,i,n,r);if(a.rpcImpl)try{return a.rpcImpl(t,i[a.requestDelimited?"encodeDelimited":"encode"](r).finish(),(function(e,i){if(e)return a.emit("error",e,t),s(e);if(null!==i){if(!(i instanceof n))try{i=n[a.responseDelimited?"decodeDelimited":"decode"](i)}catch(e){return a.emit("error",e,t),s(e)}return a.emit("data",i,t),s(null,i)}a.end(!0)}))}catch(e){return a.emit("error",e,t),void setTimeout((function(){s(e)}),0)}else setTimeout((function(){s(Error("already ended"))}),0)},je.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this},function(e){e.Service=Je}(xe);var Ve={};!function(e){var t=e;function i(){t.util._configure(),t.Writer._configure(t.BufferWriter),t.Reader._configure(t.BufferReader)}t.build="minimal",t.Writer=ee,t.BufferWriter=fe,t.Reader=ye,t.BufferReader=Ie,t.util=I,t.rpc=xe,t.roots=Ve,t.configure=i,i()}(A);var Fe,qe,Qe,We,Ge,Ke,He,ze,Ze=A,$e=(()=>{if(void 0!==$e)return $e;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw"Unable to locate global object"})();function Ye(e){switch(e){case 0:case"AUDIO":return Fe.AUDIO;case 1:case"VIDEO":return Fe.VIDEO;case 2:case"DATA":return Fe.DATA;default:return Fe.UNRECOGNIZED}}function Xe(e){switch(e){case Fe.AUDIO:return"AUDIO";case Fe.VIDEO:return"VIDEO";case Fe.DATA:return"DATA";default:return"UNKNOWN"}}function et(e){switch(e){case 0:case"UNKNOWN":return qe.UNKNOWN;case 1:case"CAMERA":return qe.CAMERA;case 2:case"MICROPHONE":return qe.MICROPHONE;case 3:case"SCREEN_SHARE":return qe.SCREEN_SHARE;case 4:case"SCREEN_SHARE_AUDIO":return qe.SCREEN_SHARE_AUDIO;default:return qe.UNRECOGNIZED}}function tt(e){switch(e){case qe.UNKNOWN:return"UNKNOWN";case qe.CAMERA:return"CAMERA";case qe.MICROPHONE:return"MICROPHONE";case qe.SCREEN_SHARE:return"SCREEN_SHARE";case qe.SCREEN_SHARE_AUDIO:return"SCREEN_SHARE_AUDIO";default:return"UNKNOWN"}}function it(t){switch(t){case 0:case"LOW":return e.VideoQuality.LOW;case 1:case"MEDIUM":return e.VideoQuality.MEDIUM;case 2:case"HIGH":return e.VideoQuality.HIGH;case 3:case"OFF":return e.VideoQuality.OFF;default:return e.VideoQuality.UNRECOGNIZED}}function nt(t){switch(t){case e.VideoQuality.LOW:return"LOW";case e.VideoQuality.MEDIUM:return"MEDIUM";case e.VideoQuality.HIGH:return"HIGH";case e.VideoQuality.OFF:return"OFF";default:return"UNKNOWN"}}function rt(e){switch(e){case 0:case"POOR":return We.POOR;case 1:case"GOOD":return We.GOOD;case 2:case"EXCELLENT":return We.EXCELLENT;default:return We.UNRECOGNIZED}}function st(e){switch(e){case 0:case"UNSET":return Ge.UNSET;case 1:case"DISABLED":return Ge.DISABLED;case 2:case"ENABLED":return Ge.ENABLED;default:return Ge.UNRECOGNIZED}}function at(e){switch(e){case Ge.UNSET:return"UNSET";case Ge.DISABLED:return"DISABLED";case Ge.ENABLED:return"ENABLED";default:return"UNKNOWN"}}function ot(e){switch(e){case 0:case"JOINING":return Ke.JOINING;case 1:case"JOINED":return Ke.JOINED;case 2:case"ACTIVE":return Ke.ACTIVE;case 3:case"DISCONNECTED":return Ke.DISCONNECTED;default:return Ke.UNRECOGNIZED}}function ct(t){switch(t){case 0:case"RELIABLE":return e.DataPacket_Kind.RELIABLE;case 1:case"LOSSY":return e.DataPacket_Kind.LOSSY;default:return e.DataPacket_Kind.UNRECOGNIZED}}function dt(e){switch(e){case 0:case"UNKNOWN":return ze.UNKNOWN;case 1:case"JS":return ze.JS;case 2:case"SWIFT":return ze.SWIFT;case 3:case"ANDROID":return ze.ANDROID;case 4:case"FLUTTER":return ze.FLUTTER;case 5:case"GO":return ze.GO;case 6:case"UNITY":return ze.UNITY;default:return ze.UNRECOGNIZED}}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure()),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.DATA=2]="DATA",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Fe||(Fe={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.CAMERA=1]="CAMERA",e[e.MICROPHONE=2]="MICROPHONE",e[e.SCREEN_SHARE=3]="SCREEN_SHARE",e[e.SCREEN_SHARE_AUDIO=4]="SCREEN_SHARE_AUDIO",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(qe||(qe={})),e.VideoQuality=void 0,(Qe=e.VideoQuality||(e.VideoQuality={}))[Qe.LOW=0]="LOW",Qe[Qe.MEDIUM=1]="MEDIUM",Qe[Qe.HIGH=2]="HIGH",Qe[Qe.OFF=3]="OFF",Qe[Qe.UNRECOGNIZED=-1]="UNRECOGNIZED",function(e){e[e.POOR=0]="POOR",e[e.GOOD=1]="GOOD",e[e.EXCELLENT=2]="EXCELLENT",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(We||(We={})),function(e){e[e.UNSET=0]="UNSET",e[e.DISABLED=1]="DISABLED",e[e.ENABLED=2]="ENABLED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ge||(Ge={})),function(e){e[e.JOINING=0]="JOINING",e[e.JOINED=1]="JOINED",e[e.ACTIVE=2]="ACTIVE",e[e.DISCONNECTED=3]="DISCONNECTED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ke||(Ke={})),e.DataPacket_Kind=void 0,(He=e.DataPacket_Kind||(e.DataPacket_Kind={}))[He.RELIABLE=0]="RELIABLE",He[He.LOSSY=1]="LOSSY",He[He.UNRECOGNIZED=-1]="UNRECOGNIZED",function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.JS=1]="JS",e[e.SWIFT=2]="SWIFT",e[e.ANDROID=3]="ANDROID",e[e.FLUTTER=4]="FLUTTER",e[e.GO=5]="GO",e[e.UNITY=6]="UNITY",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(ze||(ze={}));const ut={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),""!==e.name&&t.uint32(18).string(e.name),0!==e.emptyTimeout&&t.uint32(24).uint32(e.emptyTimeout),0!==e.maxParticipants&&t.uint32(32).uint32(e.maxParticipants),0!==e.creationTime&&t.uint32(40).int64(e.creationTime),""!==e.turnPassword&&t.uint32(50).string(e.turnPassword);for(const i of e.enabledCodecs)lt.encode(i,t.uint32(58).fork()).ldelim();return""!==e.metadata&&t.uint32(66).string(e.metadata),0!==e.numParticipants&&t.uint32(72).uint32(e.numParticipants),!0===e.activeRecording&&t.uint32(80).bool(e.activeRecording),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",name:"",emptyTimeout:0,maxParticipants:0,creationTime:0,turnPassword:"",enabledCodecs:[],metadata:"",numParticipants:0,activeRecording:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.name=i.string();break;case 3:r.emptyTimeout=i.uint32();break;case 4:r.maxParticipants=i.uint32();break;case 5:r.creationTime=Nt(i.int64());break;case 6:r.turnPassword=i.string();break;case 7:r.enabledCodecs.push(lt.decode(i,i.uint32()));break;case 8:r.metadata=i.string();break;case 9:r.numParticipants=i.uint32();break;case 10:r.activeRecording=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",name:Dt(e.name)?String(e.name):"",emptyTimeout:Dt(e.emptyTimeout)?Number(e.emptyTimeout):0,maxParticipants:Dt(e.maxParticipants)?Number(e.maxParticipants):0,creationTime:Dt(e.creationTime)?Number(e.creationTime):0,turnPassword:Dt(e.turnPassword)?String(e.turnPassword):"",enabledCodecs:Array.isArray(null==e?void 0:e.enabledCodecs)?e.enabledCodecs.map((e=>lt.fromJSON(e))):[],metadata:Dt(e.metadata)?String(e.metadata):"",numParticipants:Dt(e.numParticipants)?Number(e.numParticipants):0,activeRecording:!!Dt(e.activeRecording)&&Boolean(e.activeRecording)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.name&&(t.name=e.name),void 0!==e.emptyTimeout&&(t.emptyTimeout=Math.round(e.emptyTimeout)),void 0!==e.maxParticipants&&(t.maxParticipants=Math.round(e.maxParticipants)),void 0!==e.creationTime&&(t.creationTime=Math.round(e.creationTime)),void 0!==e.turnPassword&&(t.turnPassword=e.turnPassword),e.enabledCodecs?t.enabledCodecs=e.enabledCodecs.map((e=>e?lt.toJSON(e):void 0)):t.enabledCodecs=[],void 0!==e.metadata&&(t.metadata=e.metadata),void 0!==e.numParticipants&&(t.numParticipants=Math.round(e.numParticipants)),void 0!==e.activeRecording&&(t.activeRecording=e.activeRecording),t},fromPartial(e){var t,i,n,r,s,a,o,c,d,u;const l={sid:"",name:"",emptyTimeout:0,maxParticipants:0,creationTime:0,turnPassword:"",enabledCodecs:[],metadata:"",numParticipants:0,activeRecording:!1};return l.sid=null!==(t=e.sid)&&void 0!==t?t:"",l.name=null!==(i=e.name)&&void 0!==i?i:"",l.emptyTimeout=null!==(n=e.emptyTimeout)&&void 0!==n?n:0,l.maxParticipants=null!==(r=e.maxParticipants)&&void 0!==r?r:0,l.creationTime=null!==(s=e.creationTime)&&void 0!==s?s:0,l.turnPassword=null!==(a=e.turnPassword)&&void 0!==a?a:"",l.enabledCodecs=(null===(o=e.enabledCodecs)||void 0===o?void 0:o.map((e=>lt.fromPartial(e))))||[],l.metadata=null!==(c=e.metadata)&&void 0!==c?c:"",l.numParticipants=null!==(d=e.numParticipants)&&void 0!==d?d:0,l.activeRecording=null!==(u=e.activeRecording)&&void 0!==u&&u,l}};const lt={encode:(e,t=Ze.Writer.create())=>(""!==e.mime&&t.uint32(10).string(e.mime),""!==e.fmtpLine&&t.uint32(18).string(e.fmtpLine),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={mime:"",fmtpLine:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.mime=i.string();break;case 2:r.fmtpLine=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({mime:Dt(e.mime)?String(e.mime):"",fmtpLine:Dt(e.fmtpLine)?String(e.fmtpLine):""}),toJSON(e){const t={};return void 0!==e.mime&&(t.mime=e.mime),void 0!==e.fmtpLine&&(t.fmtpLine=e.fmtpLine),t},fromPartial(e){var t,i;const n={mime:"",fmtpLine:""};return n.mime=null!==(t=e.mime)&&void 0!==t?t:"",n.fmtpLine=null!==(i=e.fmtpLine)&&void 0!==i?i:"",n}};const ht={encode:(e,t=Ze.Writer.create())=>(!0===e.canSubscribe&&t.uint32(8).bool(e.canSubscribe),!0===e.canPublish&&t.uint32(16).bool(e.canPublish),!0===e.canPublishData&&t.uint32(24).bool(e.canPublishData),!0===e.hidden&&t.uint32(56).bool(e.hidden),!0===e.recorder&&t.uint32(64).bool(e.recorder),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={canSubscribe:!1,canPublish:!1,canPublishData:!1,hidden:!1,recorder:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.canSubscribe=i.bool();break;case 2:r.canPublish=i.bool();break;case 3:r.canPublishData=i.bool();break;case 7:r.hidden=i.bool();break;case 8:r.recorder=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({canSubscribe:!!Dt(e.canSubscribe)&&Boolean(e.canSubscribe),canPublish:!!Dt(e.canPublish)&&Boolean(e.canPublish),canPublishData:!!Dt(e.canPublishData)&&Boolean(e.canPublishData),hidden:!!Dt(e.hidden)&&Boolean(e.hidden),recorder:!!Dt(e.recorder)&&Boolean(e.recorder)}),toJSON(e){const t={};return void 0!==e.canSubscribe&&(t.canSubscribe=e.canSubscribe),void 0!==e.canPublish&&(t.canPublish=e.canPublish),void 0!==e.canPublishData&&(t.canPublishData=e.canPublishData),void 0!==e.hidden&&(t.hidden=e.hidden),void 0!==e.recorder&&(t.recorder=e.recorder),t},fromPartial(e){var t,i,n,r,s;const a={canSubscribe:!1,canPublish:!1,canPublishData:!1,hidden:!1,recorder:!1};return a.canSubscribe=null!==(t=e.canSubscribe)&&void 0!==t&&t,a.canPublish=null!==(i=e.canPublish)&&void 0!==i&&i,a.canPublishData=null!==(n=e.canPublishData)&&void 0!==n&&n,a.hidden=null!==(r=e.hidden)&&void 0!==r&&r,a.recorder=null!==(s=e.recorder)&&void 0!==s&&s,a}};const pt={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),""!==e.identity&&t.uint32(18).string(e.identity),0!==e.state&&t.uint32(24).int32(e.state);for(const i of e.tracks)mt.encode(i,t.uint32(34).fork()).ldelim();return""!==e.metadata&&t.uint32(42).string(e.metadata),0!==e.joinedAt&&t.uint32(48).int64(e.joinedAt),""!==e.name&&t.uint32(74).string(e.name),0!==e.version&&t.uint32(80).uint32(e.version),void 0!==e.permission&&ht.encode(e.permission,t.uint32(90).fork()).ldelim(),""!==e.region&&t.uint32(98).string(e.region),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",identity:"",state:0,tracks:[],metadata:"",joinedAt:0,name:"",version:0,permission:void 0,region:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.identity=i.string();break;case 3:r.state=i.int32();break;case 4:r.tracks.push(mt.decode(i,i.uint32()));break;case 5:r.metadata=i.string();break;case 6:r.joinedAt=Nt(i.int64());break;case 9:r.name=i.string();break;case 10:r.version=i.uint32();break;case 11:r.permission=ht.decode(i,i.uint32());break;case 12:r.region=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",identity:Dt(e.identity)?String(e.identity):"",state:Dt(e.state)?ot(e.state):0,tracks:Array.isArray(null==e?void 0:e.tracks)?e.tracks.map((e=>mt.fromJSON(e))):[],metadata:Dt(e.metadata)?String(e.metadata):"",joinedAt:Dt(e.joinedAt)?Number(e.joinedAt):0,name:Dt(e.name)?String(e.name):"",version:Dt(e.version)?Number(e.version):0,permission:Dt(e.permission)?ht.fromJSON(e.permission):void 0,region:Dt(e.region)?String(e.region):""}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.identity&&(t.identity=e.identity),void 0!==e.state&&(t.state=function(e){switch(e){case Ke.JOINING:return"JOINING";case Ke.JOINED:return"JOINED";case Ke.ACTIVE:return"ACTIVE";case Ke.DISCONNECTED:return"DISCONNECTED";default:return"UNKNOWN"}}(e.state)),e.tracks?t.tracks=e.tracks.map((e=>e?mt.toJSON(e):void 0)):t.tracks=[],void 0!==e.metadata&&(t.metadata=e.metadata),void 0!==e.joinedAt&&(t.joinedAt=Math.round(e.joinedAt)),void 0!==e.name&&(t.name=e.name),void 0!==e.version&&(t.version=Math.round(e.version)),void 0!==e.permission&&(t.permission=e.permission?ht.toJSON(e.permission):void 0),void 0!==e.region&&(t.region=e.region),t},fromPartial(e){var t,i,n,r,s,a,o,c,d;const u={sid:"",identity:"",state:0,tracks:[],metadata:"",joinedAt:0,name:"",version:0,permission:void 0,region:""};return u.sid=null!==(t=e.sid)&&void 0!==t?t:"",u.identity=null!==(i=e.identity)&&void 0!==i?i:"",u.state=null!==(n=e.state)&&void 0!==n?n:0,u.tracks=(null===(r=e.tracks)||void 0===r?void 0:r.map((e=>mt.fromPartial(e))))||[],u.metadata=null!==(s=e.metadata)&&void 0!==s?s:"",u.joinedAt=null!==(a=e.joinedAt)&&void 0!==a?a:0,u.name=null!==(o=e.name)&&void 0!==o?o:"",u.version=null!==(c=e.version)&&void 0!==c?c:0,u.permission=void 0!==e.permission&&null!==e.permission?ht.fromPartial(e.permission):void 0,u.region=null!==(d=e.region)&&void 0!==d?d:"",u}};const mt={encode(e,t=Ze.Writer.create()){""!==e.sid&&t.uint32(10).string(e.sid),0!==e.type&&t.uint32(16).int32(e.type),""!==e.name&&t.uint32(26).string(e.name),!0===e.muted&&t.uint32(32).bool(e.muted),0!==e.width&&t.uint32(40).uint32(e.width),0!==e.height&&t.uint32(48).uint32(e.height),!0===e.simulcast&&t.uint32(56).bool(e.simulcast),!0===e.disableDtx&&t.uint32(64).bool(e.disableDtx),0!==e.source&&t.uint32(72).int32(e.source);for(const i of e.layers)ft.encode(i,t.uint32(82).fork()).ldelim();return""!==e.mimeType&&t.uint32(90).string(e.mimeType),""!==e.mid&&t.uint32(98).string(e.mid),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",type:0,name:"",muted:!1,width:0,height:0,simulcast:!1,disableDtx:!1,source:0,layers:[],mimeType:"",mid:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.type=i.int32();break;case 3:r.name=i.string();break;case 4:r.muted=i.bool();break;case 5:r.width=i.uint32();break;case 6:r.height=i.uint32();break;case 7:r.simulcast=i.bool();break;case 8:r.disableDtx=i.bool();break;case 9:r.source=i.int32();break;case 10:r.layers.push(ft.decode(i,i.uint32()));break;case 11:r.mimeType=i.string();break;case 12:r.mid=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",type:Dt(e.type)?Ye(e.type):0,name:Dt(e.name)?String(e.name):"",muted:!!Dt(e.muted)&&Boolean(e.muted),width:Dt(e.width)?Number(e.width):0,height:Dt(e.height)?Number(e.height):0,simulcast:!!Dt(e.simulcast)&&Boolean(e.simulcast),disableDtx:!!Dt(e.disableDtx)&&Boolean(e.disableDtx),source:Dt(e.source)?et(e.source):0,layers:Array.isArray(null==e?void 0:e.layers)?e.layers.map((e=>ft.fromJSON(e))):[],mimeType:Dt(e.mimeType)?String(e.mimeType):"",mid:Dt(e.mid)?String(e.mid):""}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.type&&(t.type=Xe(e.type)),void 0!==e.name&&(t.name=e.name),void 0!==e.muted&&(t.muted=e.muted),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.simulcast&&(t.simulcast=e.simulcast),void 0!==e.disableDtx&&(t.disableDtx=e.disableDtx),void 0!==e.source&&(t.source=tt(e.source)),e.layers?t.layers=e.layers.map((e=>e?ft.toJSON(e):void 0)):t.layers=[],void 0!==e.mimeType&&(t.mimeType=e.mimeType),void 0!==e.mid&&(t.mid=e.mid),t},fromPartial(e){var t,i,n,r,s,a,o,c,d,u,l,h;const p={sid:"",type:0,name:"",muted:!1,width:0,height:0,simulcast:!1,disableDtx:!1,source:0,layers:[],mimeType:"",mid:""};return p.sid=null!==(t=e.sid)&&void 0!==t?t:"",p.type=null!==(i=e.type)&&void 0!==i?i:0,p.name=null!==(n=e.name)&&void 0!==n?n:"",p.muted=null!==(r=e.muted)&&void 0!==r&&r,p.width=null!==(s=e.width)&&void 0!==s?s:0,p.height=null!==(a=e.height)&&void 0!==a?a:0,p.simulcast=null!==(o=e.simulcast)&&void 0!==o&&o,p.disableDtx=null!==(c=e.disableDtx)&&void 0!==c&&c,p.source=null!==(d=e.source)&&void 0!==d?d:0,p.layers=(null===(u=e.layers)||void 0===u?void 0:u.map((e=>ft.fromPartial(e))))||[],p.mimeType=null!==(l=e.mimeType)&&void 0!==l?l:"",p.mid=null!==(h=e.mid)&&void 0!==h?h:"",p}};const ft={encode:(e,t=Ze.Writer.create())=>(0!==e.quality&&t.uint32(8).int32(e.quality),0!==e.width&&t.uint32(16).uint32(e.width),0!==e.height&&t.uint32(24).uint32(e.height),0!==e.bitrate&&t.uint32(32).uint32(e.bitrate),0!==e.ssrc&&t.uint32(40).uint32(e.ssrc),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={quality:0,width:0,height:0,bitrate:0,ssrc:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.quality=i.int32();break;case 2:r.width=i.uint32();break;case 3:r.height=i.uint32();break;case 4:r.bitrate=i.uint32();break;case 5:r.ssrc=i.uint32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({quality:Dt(e.quality)?it(e.quality):0,width:Dt(e.width)?Number(e.width):0,height:Dt(e.height)?Number(e.height):0,bitrate:Dt(e.bitrate)?Number(e.bitrate):0,ssrc:Dt(e.ssrc)?Number(e.ssrc):0}),toJSON(e){const t={};return void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.bitrate&&(t.bitrate=Math.round(e.bitrate)),void 0!==e.ssrc&&(t.ssrc=Math.round(e.ssrc)),t},fromPartial(e){var t,i,n,r,s;const a={quality:0,width:0,height:0,bitrate:0,ssrc:0};return a.quality=null!==(t=e.quality)&&void 0!==t?t:0,a.width=null!==(i=e.width)&&void 0!==i?i:0,a.height=null!==(n=e.height)&&void 0!==n?n:0,a.bitrate=null!==(r=e.bitrate)&&void 0!==r?r:0,a.ssrc=null!==(s=e.ssrc)&&void 0!==s?s:0,a}};const vt={encode:(e,t=Ze.Writer.create())=>(0!==e.kind&&t.uint32(8).int32(e.kind),void 0!==e.user&&St.encode(e.user,t.uint32(18).fork()).ldelim(),void 0!==e.speaker&&gt.encode(e.speaker,t.uint32(26).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={kind:0,user:void 0,speaker:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.kind=i.int32();break;case 2:r.user=St.decode(i,i.uint32());break;case 3:r.speaker=gt.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({kind:Dt(e.kind)?ct(e.kind):0,user:Dt(e.user)?St.fromJSON(e.user):void 0,speaker:Dt(e.speaker)?gt.fromJSON(e.speaker):void 0}),toJSON(t){const i={};return void 0!==t.kind&&(i.kind=function(t){switch(t){case e.DataPacket_Kind.RELIABLE:return"RELIABLE";case e.DataPacket_Kind.LOSSY:return"LOSSY";default:return"UNKNOWN"}}(t.kind)),void 0!==t.user&&(i.user=t.user?St.toJSON(t.user):void 0),void 0!==t.speaker&&(i.speaker=t.speaker?gt.toJSON(t.speaker):void 0),i},fromPartial(e){var t;const i={kind:0,user:void 0,speaker:void 0};return i.kind=null!==(t=e.kind)&&void 0!==t?t:0,i.user=void 0!==e.user&&null!==e.user?St.fromPartial(e.user):void 0,i.speaker=void 0!==e.speaker&&null!==e.speaker?gt.fromPartial(e.speaker):void 0,i}};const gt={encode(e,t=Ze.Writer.create()){for(const i of e.speakers)bt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakers:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.speakers.push(bt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({speakers:Array.isArray(null==e?void 0:e.speakers)?e.speakers.map((e=>bt.fromJSON(e))):[]}),toJSON(e){const t={};return e.speakers?t.speakers=e.speakers.map((e=>e?bt.toJSON(e):void 0)):t.speakers=[],t},fromPartial(e){var t;const i={speakers:[]};return i.speakers=(null===(t=e.speakers)||void 0===t?void 0:t.map((e=>bt.fromPartial(e))))||[],i}};const bt={encode:(e,t=Ze.Writer.create())=>(""!==e.sid&&t.uint32(10).string(e.sid),0!==e.level&&t.uint32(21).float(e.level),!0===e.active&&t.uint32(24).bool(e.active),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",level:0,active:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.level=i.float();break;case 3:r.active=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:Dt(e.sid)?String(e.sid):"",level:Dt(e.level)?Number(e.level):0,active:!!Dt(e.active)&&Boolean(e.active)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.level&&(t.level=e.level),void 0!==e.active&&(t.active=e.active),t},fromPartial(e){var t,i,n;const r={sid:"",level:0,active:!1};return r.sid=null!==(t=e.sid)&&void 0!==t?t:"",r.level=null!==(i=e.level)&&void 0!==i?i:0,r.active=null!==(n=e.active)&&void 0!==n&&n,r}};function kt(){return{participantSid:"",payload:new Uint8Array,destinationSids:[]}}const St={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid),0!==e.payload.length&&t.uint32(18).bytes(e.payload);for(const i of e.destinationSids)t.uint32(26).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r=kt();for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.payload=i.bytes();break;case 3:r.destinationSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:Dt(e.participantSid)?String(e.participantSid):"",payload:Dt(e.payload)?Rt(e.payload):new Uint8Array,destinationSids:Array.isArray(null==e?void 0:e.destinationSids)?e.destinationSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.payload&&(t.payload=function(e){const t=[];for(const i of e)t.push(String.fromCharCode(i));return Ot(t.join(""))}(void 0!==e.payload?e.payload:new Uint8Array)),e.destinationSids?t.destinationSids=e.destinationSids.map((e=>e)):t.destinationSids=[],t},fromPartial(e){var t,i,n;const r=kt();return r.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",r.payload=null!==(i=e.payload)&&void 0!==i?i:new Uint8Array,r.destinationSids=(null===(n=e.destinationSids)||void 0===n?void 0:n.map((e=>e)))||[],r}};const yt={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid);for(const i of e.trackSids)t.uint32(18).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSids:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:Dt(e.participantSid)?String(e.participantSid):"",trackSids:Array.isArray(null==e?void 0:e.trackSids)?e.trackSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],t},fromPartial(e){var t,i;const n={participantSid:"",trackSids:[]};return n.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",n.trackSids=(null===(i=e.trackSids)||void 0===i?void 0:i.map((e=>e)))||[],n}};const wt={encode:(e,t=Ze.Writer.create())=>(0!==e.sdk&&t.uint32(8).int32(e.sdk),""!==e.version&&t.uint32(18).string(e.version),0!==e.protocol&&t.uint32(24).int32(e.protocol),""!==e.os&&t.uint32(34).string(e.os),""!==e.osVersion&&t.uint32(42).string(e.osVersion),""!==e.deviceModel&&t.uint32(50).string(e.deviceModel),""!==e.browser&&t.uint32(58).string(e.browser),""!==e.browserVersion&&t.uint32(66).string(e.browserVersion),""!==e.address&&t.uint32(74).string(e.address),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sdk:0,version:"",protocol:0,os:"",osVersion:"",deviceModel:"",browser:"",browserVersion:"",address:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sdk=i.int32();break;case 2:r.version=i.string();break;case 3:r.protocol=i.int32();break;case 4:r.os=i.string();break;case 5:r.osVersion=i.string();break;case 6:r.deviceModel=i.string();break;case 7:r.browser=i.string();break;case 8:r.browserVersion=i.string();break;case 9:r.address=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sdk:Dt(e.sdk)?dt(e.sdk):0,version:Dt(e.version)?String(e.version):"",protocol:Dt(e.protocol)?Number(e.protocol):0,os:Dt(e.os)?String(e.os):"",osVersion:Dt(e.osVersion)?String(e.osVersion):"",deviceModel:Dt(e.deviceModel)?String(e.deviceModel):"",browser:Dt(e.browser)?String(e.browser):"",browserVersion:Dt(e.browserVersion)?String(e.browserVersion):"",address:Dt(e.address)?String(e.address):""}),toJSON(e){const t={};return void 0!==e.sdk&&(t.sdk=function(e){switch(e){case ze.UNKNOWN:return"UNKNOWN";case ze.JS:return"JS";case ze.SWIFT:return"SWIFT";case ze.ANDROID:return"ANDROID";case ze.FLUTTER:return"FLUTTER";case ze.GO:return"GO";case ze.UNITY:return"UNITY";default:return"UNKNOWN"}}(e.sdk)),void 0!==e.version&&(t.version=e.version),void 0!==e.protocol&&(t.protocol=Math.round(e.protocol)),void 0!==e.os&&(t.os=e.os),void 0!==e.osVersion&&(t.osVersion=e.osVersion),void 0!==e.deviceModel&&(t.deviceModel=e.deviceModel),void 0!==e.browser&&(t.browser=e.browser),void 0!==e.browserVersion&&(t.browserVersion=e.browserVersion),void 0!==e.address&&(t.address=e.address),t},fromPartial(e){var t,i,n,r,s,a,o,c,d;const u={sdk:0,version:"",protocol:0,os:"",osVersion:"",deviceModel:"",browser:"",browserVersion:"",address:""};return u.sdk=null!==(t=e.sdk)&&void 0!==t?t:0,u.version=null!==(i=e.version)&&void 0!==i?i:"",u.protocol=null!==(n=e.protocol)&&void 0!==n?n:0,u.os=null!==(r=e.os)&&void 0!==r?r:"",u.osVersion=null!==(s=e.osVersion)&&void 0!==s?s:"",u.deviceModel=null!==(a=e.deviceModel)&&void 0!==a?a:"",u.browser=null!==(o=e.browser)&&void 0!==o?o:"",u.browserVersion=null!==(c=e.browserVersion)&&void 0!==c?c:"",u.address=null!==(d=e.address)&&void 0!==d?d:"",u}};const Ct={encode:(e,t=Ze.Writer.create())=>(void 0!==e.video&&Tt.encode(e.video,t.uint32(10).fork()).ldelim(),void 0!==e.screen&&Tt.encode(e.screen,t.uint32(18).fork()).ldelim(),0!==e.resumeConnection&&t.uint32(24).int32(e.resumeConnection),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={video:void 0,screen:void 0,resumeConnection:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.video=Tt.decode(i,i.uint32());break;case 2:r.screen=Tt.decode(i,i.uint32());break;case 3:r.resumeConnection=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({video:Dt(e.video)?Tt.fromJSON(e.video):void 0,screen:Dt(e.screen)?Tt.fromJSON(e.screen):void 0,resumeConnection:Dt(e.resumeConnection)?st(e.resumeConnection):0}),toJSON(e){const t={};return void 0!==e.video&&(t.video=e.video?Tt.toJSON(e.video):void 0),void 0!==e.screen&&(t.screen=e.screen?Tt.toJSON(e.screen):void 0),void 0!==e.resumeConnection&&(t.resumeConnection=at(e.resumeConnection)),t},fromPartial(e){var t;const i={video:void 0,screen:void 0,resumeConnection:0};return i.video=void 0!==e.video&&null!==e.video?Tt.fromPartial(e.video):void 0,i.screen=void 0!==e.screen&&null!==e.screen?Tt.fromPartial(e.screen):void 0,i.resumeConnection=null!==(t=e.resumeConnection)&&void 0!==t?t:0,i}};const Tt={encode:(e,t=Ze.Writer.create())=>(0!==e.hardwareEncoder&&t.uint32(8).int32(e.hardwareEncoder),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={hardwareEncoder:0};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.hardwareEncoder=i.int32();else i.skipType(7&e)}return r},fromJSON:e=>({hardwareEncoder:Dt(e.hardwareEncoder)?st(e.hardwareEncoder):0}),toJSON(e){const t={};return void 0!==e.hardwareEncoder&&(t.hardwareEncoder=at(e.hardwareEncoder)),t},fromPartial(e){var t;const i={hardwareEncoder:0};return i.hardwareEncoder=null!==(t=e.hardwareEncoder)&&void 0!==t?t:0,i}};var Et=(()=>{if(void 0!==Et)return Et;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw"Unable to locate global object"})();const Pt=Et.atob||(e=>Et.Buffer.from(e,"base64").toString("binary"));function Rt(e){const t=Pt(e),i=new Uint8Array(t.length);for(let e=0;e<t.length;++e)i[e]=t.charCodeAt(e);return i}const Ot=Et.btoa||(e=>Et.Buffer.from(e,"binary").toString("base64"));function Nt(e){if(e.gt(Number.MAX_SAFE_INTEGER))throw new Et.Error("Value is larger than Number.MAX_SAFE_INTEGER");return e.toNumber()}function Dt(e){return null!=e}var Ut,At;function It(e){switch(e){case 0:case"PUBLISHER":return Ut.PUBLISHER;case 1:case"SUBSCRIBER":return Ut.SUBSCRIBER;default:return Ut.UNRECOGNIZED}}function Lt(e){switch(e){case Ut.PUBLISHER:return"PUBLISHER";case Ut.SUBSCRIBER:return"SUBSCRIBER";default:return"UNKNOWN"}}function Mt(e){switch(e){case 0:case"ACTIVE":return At.ACTIVE;case 1:case"PAUSED":return At.PAUSED;default:return At.UNRECOGNIZED}}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure()),function(e){e[e.PUBLISHER=0]="PUBLISHER",e[e.SUBSCRIBER=1]="SUBSCRIBER",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ut||(Ut={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PAUSED=1]="PAUSED",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED"}(At||(At={}));const _t={encode:(e,t=Ze.Writer.create())=>(void 0!==e.offer&&Qt.encode(e.offer,t.uint32(10).fork()).ldelim(),void 0!==e.answer&&Qt.encode(e.answer,t.uint32(18).fork()).ldelim(),void 0!==e.trickle&&Bt.encode(e.trickle,t.uint32(26).fork()).ldelim(),void 0!==e.addTrack&&Jt.encode(e.addTrack,t.uint32(34).fork()).ldelim(),void 0!==e.mute&&jt.encode(e.mute,t.uint32(42).fork()).ldelim(),void 0!==e.subscription&&Gt.encode(e.subscription,t.uint32(50).fork()).ldelim(),void 0!==e.trackSetting&&Kt.encode(e.trackSetting,t.uint32(58).fork()).ldelim(),void 0!==e.leave&&Ht.encode(e.leave,t.uint32(66).fork()).ldelim(),void 0!==e.updateLayers&&zt.encode(e.updateLayers,t.uint32(82).fork()).ldelim(),void 0!==e.subscriptionPermission&&ai.encode(e.subscriptionPermission,t.uint32(90).fork()).ldelim(),void 0!==e.syncState&&ci.encode(e.syncState,t.uint32(98).fork()).ldelim(),void 0!==e.simulate&&ui.encode(e.simulate,t.uint32(106).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={offer:void 0,answer:void 0,trickle:void 0,addTrack:void 0,mute:void 0,subscription:void 0,trackSetting:void 0,leave:void 0,updateLayers:void 0,subscriptionPermission:void 0,syncState:void 0,simulate:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.offer=Qt.decode(i,i.uint32());break;case 2:r.answer=Qt.decode(i,i.uint32());break;case 3:r.trickle=Bt.decode(i,i.uint32());break;case 4:r.addTrack=Jt.decode(i,i.uint32());break;case 5:r.mute=jt.decode(i,i.uint32());break;case 6:r.subscription=Gt.decode(i,i.uint32());break;case 7:r.trackSetting=Kt.decode(i,i.uint32());break;case 8:r.leave=Ht.decode(i,i.uint32());break;case 10:r.updateLayers=zt.decode(i,i.uint32());break;case 11:r.subscriptionPermission=ai.decode(i,i.uint32());break;case 12:r.syncState=ci.decode(i,i.uint32());break;case 13:r.simulate=ui.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({offer:li(e.offer)?Qt.fromJSON(e.offer):void 0,answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,trickle:li(e.trickle)?Bt.fromJSON(e.trickle):void 0,addTrack:li(e.addTrack)?Jt.fromJSON(e.addTrack):void 0,mute:li(e.mute)?jt.fromJSON(e.mute):void 0,subscription:li(e.subscription)?Gt.fromJSON(e.subscription):void 0,trackSetting:li(e.trackSetting)?Kt.fromJSON(e.trackSetting):void 0,leave:li(e.leave)?Ht.fromJSON(e.leave):void 0,updateLayers:li(e.updateLayers)?zt.fromJSON(e.updateLayers):void 0,subscriptionPermission:li(e.subscriptionPermission)?ai.fromJSON(e.subscriptionPermission):void 0,syncState:li(e.syncState)?ci.fromJSON(e.syncState):void 0,simulate:li(e.simulate)?ui.fromJSON(e.simulate):void 0}),toJSON(e){const t={};return void 0!==e.offer&&(t.offer=e.offer?Qt.toJSON(e.offer):void 0),void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.trickle&&(t.trickle=e.trickle?Bt.toJSON(e.trickle):void 0),void 0!==e.addTrack&&(t.addTrack=e.addTrack?Jt.toJSON(e.addTrack):void 0),void 0!==e.mute&&(t.mute=e.mute?jt.toJSON(e.mute):void 0),void 0!==e.subscription&&(t.subscription=e.subscription?Gt.toJSON(e.subscription):void 0),void 0!==e.trackSetting&&(t.trackSetting=e.trackSetting?Kt.toJSON(e.trackSetting):void 0),void 0!==e.leave&&(t.leave=e.leave?Ht.toJSON(e.leave):void 0),void 0!==e.updateLayers&&(t.updateLayers=e.updateLayers?zt.toJSON(e.updateLayers):void 0),void 0!==e.subscriptionPermission&&(t.subscriptionPermission=e.subscriptionPermission?ai.toJSON(e.subscriptionPermission):void 0),void 0!==e.syncState&&(t.syncState=e.syncState?ci.toJSON(e.syncState):void 0),void 0!==e.simulate&&(t.simulate=e.simulate?ui.toJSON(e.simulate):void 0),t},fromPartial(e){const t={offer:void 0,answer:void 0,trickle:void 0,addTrack:void 0,mute:void 0,subscription:void 0,trackSetting:void 0,leave:void 0,updateLayers:void 0,subscriptionPermission:void 0,syncState:void 0,simulate:void 0};return t.offer=void 0!==e.offer&&null!==e.offer?Qt.fromPartial(e.offer):void 0,t.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,t.trickle=void 0!==e.trickle&&null!==e.trickle?Bt.fromPartial(e.trickle):void 0,t.addTrack=void 0!==e.addTrack&&null!==e.addTrack?Jt.fromPartial(e.addTrack):void 0,t.mute=void 0!==e.mute&&null!==e.mute?jt.fromPartial(e.mute):void 0,t.subscription=void 0!==e.subscription&&null!==e.subscription?Gt.fromPartial(e.subscription):void 0,t.trackSetting=void 0!==e.trackSetting&&null!==e.trackSetting?Kt.fromPartial(e.trackSetting):void 0,t.leave=void 0!==e.leave&&null!==e.leave?Ht.fromPartial(e.leave):void 0,t.updateLayers=void 0!==e.updateLayers&&null!==e.updateLayers?zt.fromPartial(e.updateLayers):void 0,t.subscriptionPermission=void 0!==e.subscriptionPermission&&null!==e.subscriptionPermission?ai.fromPartial(e.subscriptionPermission):void 0,t.syncState=void 0!==e.syncState&&null!==e.syncState?ci.fromPartial(e.syncState):void 0,t.simulate=void 0!==e.simulate&&null!==e.simulate?ui.fromPartial(e.simulate):void 0,t}};const xt={encode:(e,t=Ze.Writer.create())=>(void 0!==e.join&&Vt.encode(e.join,t.uint32(10).fork()).ldelim(),void 0!==e.answer&&Qt.encode(e.answer,t.uint32(18).fork()).ldelim(),void 0!==e.offer&&Qt.encode(e.offer,t.uint32(26).fork()).ldelim(),void 0!==e.trickle&&Bt.encode(e.trickle,t.uint32(34).fork()).ldelim(),void 0!==e.update&&Wt.encode(e.update,t.uint32(42).fork()).ldelim(),void 0!==e.trackPublished&&Ft.encode(e.trackPublished,t.uint32(50).fork()).ldelim(),void 0!==e.leave&&Ht.encode(e.leave,t.uint32(66).fork()).ldelim(),void 0!==e.mute&&jt.encode(e.mute,t.uint32(74).fork()).ldelim(),void 0!==e.speakersChanged&&$t.encode(e.speakersChanged,t.uint32(82).fork()).ldelim(),void 0!==e.roomUpdate&&Yt.encode(e.roomUpdate,t.uint32(90).fork()).ldelim(),void 0!==e.connectionQuality&&ei.encode(e.connectionQuality,t.uint32(98).fork()).ldelim(),void 0!==e.streamStateUpdate&&ii.encode(e.streamStateUpdate,t.uint32(106).fork()).ldelim(),void 0!==e.subscribedQualityUpdate&&ri.encode(e.subscribedQualityUpdate,t.uint32(114).fork()).ldelim(),void 0!==e.subscriptionPermissionUpdate&&oi.encode(e.subscriptionPermissionUpdate,t.uint32(122).fork()).ldelim(),void 0!==e.refreshToken&&t.uint32(130).string(e.refreshToken),void 0!==e.trackUnpublished&&qt.encode(e.trackUnpublished,t.uint32(138).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={join:void 0,answer:void 0,offer:void 0,trickle:void 0,update:void 0,trackPublished:void 0,leave:void 0,mute:void 0,speakersChanged:void 0,roomUpdate:void 0,connectionQuality:void 0,streamStateUpdate:void 0,subscribedQualityUpdate:void 0,subscriptionPermissionUpdate:void 0,refreshToken:void 0,trackUnpublished:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.join=Vt.decode(i,i.uint32());break;case 2:r.answer=Qt.decode(i,i.uint32());break;case 3:r.offer=Qt.decode(i,i.uint32());break;case 4:r.trickle=Bt.decode(i,i.uint32());break;case 5:r.update=Wt.decode(i,i.uint32());break;case 6:r.trackPublished=Ft.decode(i,i.uint32());break;case 8:r.leave=Ht.decode(i,i.uint32());break;case 9:r.mute=jt.decode(i,i.uint32());break;case 10:r.speakersChanged=$t.decode(i,i.uint32());break;case 11:r.roomUpdate=Yt.decode(i,i.uint32());break;case 12:r.connectionQuality=ei.decode(i,i.uint32());break;case 13:r.streamStateUpdate=ii.decode(i,i.uint32());break;case 14:r.subscribedQualityUpdate=ri.decode(i,i.uint32());break;case 15:r.subscriptionPermissionUpdate=oi.decode(i,i.uint32());break;case 16:r.refreshToken=i.string();break;case 17:r.trackUnpublished=qt.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({join:li(e.join)?Vt.fromJSON(e.join):void 0,answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,offer:li(e.offer)?Qt.fromJSON(e.offer):void 0,trickle:li(e.trickle)?Bt.fromJSON(e.trickle):void 0,update:li(e.update)?Wt.fromJSON(e.update):void 0,trackPublished:li(e.trackPublished)?Ft.fromJSON(e.trackPublished):void 0,leave:li(e.leave)?Ht.fromJSON(e.leave):void 0,mute:li(e.mute)?jt.fromJSON(e.mute):void 0,speakersChanged:li(e.speakersChanged)?$t.fromJSON(e.speakersChanged):void 0,roomUpdate:li(e.roomUpdate)?Yt.fromJSON(e.roomUpdate):void 0,connectionQuality:li(e.connectionQuality)?ei.fromJSON(e.connectionQuality):void 0,streamStateUpdate:li(e.streamStateUpdate)?ii.fromJSON(e.streamStateUpdate):void 0,subscribedQualityUpdate:li(e.subscribedQualityUpdate)?ri.fromJSON(e.subscribedQualityUpdate):void 0,subscriptionPermissionUpdate:li(e.subscriptionPermissionUpdate)?oi.fromJSON(e.subscriptionPermissionUpdate):void 0,refreshToken:li(e.refreshToken)?String(e.refreshToken):void 0,trackUnpublished:li(e.trackUnpublished)?qt.fromJSON(e.trackUnpublished):void 0}),toJSON(e){const t={};return void 0!==e.join&&(t.join=e.join?Vt.toJSON(e.join):void 0),void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.offer&&(t.offer=e.offer?Qt.toJSON(e.offer):void 0),void 0!==e.trickle&&(t.trickle=e.trickle?Bt.toJSON(e.trickle):void 0),void 0!==e.update&&(t.update=e.update?Wt.toJSON(e.update):void 0),void 0!==e.trackPublished&&(t.trackPublished=e.trackPublished?Ft.toJSON(e.trackPublished):void 0),void 0!==e.leave&&(t.leave=e.leave?Ht.toJSON(e.leave):void 0),void 0!==e.mute&&(t.mute=e.mute?jt.toJSON(e.mute):void 0),void 0!==e.speakersChanged&&(t.speakersChanged=e.speakersChanged?$t.toJSON(e.speakersChanged):void 0),void 0!==e.roomUpdate&&(t.roomUpdate=e.roomUpdate?Yt.toJSON(e.roomUpdate):void 0),void 0!==e.connectionQuality&&(t.connectionQuality=e.connectionQuality?ei.toJSON(e.connectionQuality):void 0),void 0!==e.streamStateUpdate&&(t.streamStateUpdate=e.streamStateUpdate?ii.toJSON(e.streamStateUpdate):void 0),void 0!==e.subscribedQualityUpdate&&(t.subscribedQualityUpdate=e.subscribedQualityUpdate?ri.toJSON(e.subscribedQualityUpdate):void 0),void 0!==e.subscriptionPermissionUpdate&&(t.subscriptionPermissionUpdate=e.subscriptionPermissionUpdate?oi.toJSON(e.subscriptionPermissionUpdate):void 0),void 0!==e.refreshToken&&(t.refreshToken=e.refreshToken),void 0!==e.trackUnpublished&&(t.trackUnpublished=e.trackUnpublished?qt.toJSON(e.trackUnpublished):void 0),t},fromPartial(e){var t;const i={join:void 0,answer:void 0,offer:void 0,trickle:void 0,update:void 0,trackPublished:void 0,leave:void 0,mute:void 0,speakersChanged:void 0,roomUpdate:void 0,connectionQuality:void 0,streamStateUpdate:void 0,subscribedQualityUpdate:void 0,subscriptionPermissionUpdate:void 0,refreshToken:void 0,trackUnpublished:void 0};return i.join=void 0!==e.join&&null!==e.join?Vt.fromPartial(e.join):void 0,i.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,i.offer=void 0!==e.offer&&null!==e.offer?Qt.fromPartial(e.offer):void 0,i.trickle=void 0!==e.trickle&&null!==e.trickle?Bt.fromPartial(e.trickle):void 0,i.update=void 0!==e.update&&null!==e.update?Wt.fromPartial(e.update):void 0,i.trackPublished=void 0!==e.trackPublished&&null!==e.trackPublished?Ft.fromPartial(e.trackPublished):void 0,i.leave=void 0!==e.leave&&null!==e.leave?Ht.fromPartial(e.leave):void 0,i.mute=void 0!==e.mute&&null!==e.mute?jt.fromPartial(e.mute):void 0,i.speakersChanged=void 0!==e.speakersChanged&&null!==e.speakersChanged?$t.fromPartial(e.speakersChanged):void 0,i.roomUpdate=void 0!==e.roomUpdate&&null!==e.roomUpdate?Yt.fromPartial(e.roomUpdate):void 0,i.connectionQuality=void 0!==e.connectionQuality&&null!==e.connectionQuality?ei.fromPartial(e.connectionQuality):void 0,i.streamStateUpdate=void 0!==e.streamStateUpdate&&null!==e.streamStateUpdate?ii.fromPartial(e.streamStateUpdate):void 0,i.subscribedQualityUpdate=void 0!==e.subscribedQualityUpdate&&null!==e.subscribedQualityUpdate?ri.fromPartial(e.subscribedQualityUpdate):void 0,i.subscriptionPermissionUpdate=void 0!==e.subscriptionPermissionUpdate&&null!==e.subscriptionPermissionUpdate?oi.fromPartial(e.subscriptionPermissionUpdate):void 0,i.refreshToken=null!==(t=e.refreshToken)&&void 0!==t?t:void 0,i.trackUnpublished=void 0!==e.trackUnpublished&&null!==e.trackUnpublished?qt.fromPartial(e.trackUnpublished):void 0,i}};const Jt={encode(e,t=Ze.Writer.create()){""!==e.cid&&t.uint32(10).string(e.cid),""!==e.name&&t.uint32(18).string(e.name),0!==e.type&&t.uint32(24).int32(e.type),0!==e.width&&t.uint32(32).uint32(e.width),0!==e.height&&t.uint32(40).uint32(e.height),!0===e.muted&&t.uint32(48).bool(e.muted),!0===e.disableDtx&&t.uint32(56).bool(e.disableDtx),0!==e.source&&t.uint32(64).int32(e.source);for(const i of e.layers)ft.encode(i,t.uint32(74).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={cid:"",name:"",type:0,width:0,height:0,muted:!1,disableDtx:!1,source:0,layers:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.cid=i.string();break;case 2:r.name=i.string();break;case 3:r.type=i.int32();break;case 4:r.width=i.uint32();break;case 5:r.height=i.uint32();break;case 6:r.muted=i.bool();break;case 7:r.disableDtx=i.bool();break;case 8:r.source=i.int32();break;case 9:r.layers.push(ft.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({cid:li(e.cid)?String(e.cid):"",name:li(e.name)?String(e.name):"",type:li(e.type)?Ye(e.type):0,width:li(e.width)?Number(e.width):0,height:li(e.height)?Number(e.height):0,muted:!!li(e.muted)&&Boolean(e.muted),disableDtx:!!li(e.disableDtx)&&Boolean(e.disableDtx),source:li(e.source)?et(e.source):0,layers:Array.isArray(null==e?void 0:e.layers)?e.layers.map((e=>ft.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.cid&&(t.cid=e.cid),void 0!==e.name&&(t.name=e.name),void 0!==e.type&&(t.type=Xe(e.type)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),void 0!==e.muted&&(t.muted=e.muted),void 0!==e.disableDtx&&(t.disableDtx=e.disableDtx),void 0!==e.source&&(t.source=tt(e.source)),e.layers?t.layers=e.layers.map((e=>e?ft.toJSON(e):void 0)):t.layers=[],t},fromPartial(e){var t,i,n,r,s,a,o,c,d;const u={cid:"",name:"",type:0,width:0,height:0,muted:!1,disableDtx:!1,source:0,layers:[]};return u.cid=null!==(t=e.cid)&&void 0!==t?t:"",u.name=null!==(i=e.name)&&void 0!==i?i:"",u.type=null!==(n=e.type)&&void 0!==n?n:0,u.width=null!==(r=e.width)&&void 0!==r?r:0,u.height=null!==(s=e.height)&&void 0!==s?s:0,u.muted=null!==(a=e.muted)&&void 0!==a&&a,u.disableDtx=null!==(o=e.disableDtx)&&void 0!==o&&o,u.source=null!==(c=e.source)&&void 0!==c?c:0,u.layers=(null===(d=e.layers)||void 0===d?void 0:d.map((e=>ft.fromPartial(e))))||[],u}};const Bt={encode:(e,t=Ze.Writer.create())=>(""!==e.candidateInit&&t.uint32(10).string(e.candidateInit),0!==e.target&&t.uint32(16).int32(e.target),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={candidateInit:"",target:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.candidateInit=i.string();break;case 2:r.target=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({candidateInit:li(e.candidateInit)?String(e.candidateInit):"",target:li(e.target)?It(e.target):0}),toJSON(e){const t={};return void 0!==e.candidateInit&&(t.candidateInit=e.candidateInit),void 0!==e.target&&(t.target=Lt(e.target)),t},fromPartial(e){var t,i;const n={candidateInit:"",target:0};return n.candidateInit=null!==(t=e.candidateInit)&&void 0!==t?t:"",n.target=null!==(i=e.target)&&void 0!==i?i:0,n}};const jt={encode:(e,t=Ze.Writer.create())=>(""!==e.sid&&t.uint32(10).string(e.sid),!0===e.muted&&t.uint32(16).bool(e.muted),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={sid:"",muted:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.sid=i.string();break;case 2:r.muted=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({sid:li(e.sid)?String(e.sid):"",muted:!!li(e.muted)&&Boolean(e.muted)}),toJSON(e){const t={};return void 0!==e.sid&&(t.sid=e.sid),void 0!==e.muted&&(t.muted=e.muted),t},fromPartial(e){var t,i;const n={sid:"",muted:!1};return n.sid=null!==(t=e.sid)&&void 0!==t?t:"",n.muted=null!==(i=e.muted)&&void 0!==i&&i,n}};const Vt={encode(e,t=Ze.Writer.create()){void 0!==e.room&&ut.encode(e.room,t.uint32(10).fork()).ldelim(),void 0!==e.participant&&pt.encode(e.participant,t.uint32(18).fork()).ldelim();for(const i of e.otherParticipants)pt.encode(i,t.uint32(26).fork()).ldelim();""!==e.serverVersion&&t.uint32(34).string(e.serverVersion);for(const i of e.iceServers)Zt.encode(i,t.uint32(42).fork()).ldelim();return!0===e.subscriberPrimary&&t.uint32(48).bool(e.subscriberPrimary),""!==e.alternativeUrl&&t.uint32(58).string(e.alternativeUrl),void 0!==e.clientConfiguration&&Ct.encode(e.clientConfiguration,t.uint32(66).fork()).ldelim(),""!==e.serverRegion&&t.uint32(74).string(e.serverRegion),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={room:void 0,participant:void 0,otherParticipants:[],serverVersion:"",iceServers:[],subscriberPrimary:!1,alternativeUrl:"",clientConfiguration:void 0,serverRegion:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.room=ut.decode(i,i.uint32());break;case 2:r.participant=pt.decode(i,i.uint32());break;case 3:r.otherParticipants.push(pt.decode(i,i.uint32()));break;case 4:r.serverVersion=i.string();break;case 5:r.iceServers.push(Zt.decode(i,i.uint32()));break;case 6:r.subscriberPrimary=i.bool();break;case 7:r.alternativeUrl=i.string();break;case 8:r.clientConfiguration=Ct.decode(i,i.uint32());break;case 9:r.serverRegion=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({room:li(e.room)?ut.fromJSON(e.room):void 0,participant:li(e.participant)?pt.fromJSON(e.participant):void 0,otherParticipants:Array.isArray(null==e?void 0:e.otherParticipants)?e.otherParticipants.map((e=>pt.fromJSON(e))):[],serverVersion:li(e.serverVersion)?String(e.serverVersion):"",iceServers:Array.isArray(null==e?void 0:e.iceServers)?e.iceServers.map((e=>Zt.fromJSON(e))):[],subscriberPrimary:!!li(e.subscriberPrimary)&&Boolean(e.subscriberPrimary),alternativeUrl:li(e.alternativeUrl)?String(e.alternativeUrl):"",clientConfiguration:li(e.clientConfiguration)?Ct.fromJSON(e.clientConfiguration):void 0,serverRegion:li(e.serverRegion)?String(e.serverRegion):""}),toJSON(e){const t={};return void 0!==e.room&&(t.room=e.room?ut.toJSON(e.room):void 0),void 0!==e.participant&&(t.participant=e.participant?pt.toJSON(e.participant):void 0),e.otherParticipants?t.otherParticipants=e.otherParticipants.map((e=>e?pt.toJSON(e):void 0)):t.otherParticipants=[],void 0!==e.serverVersion&&(t.serverVersion=e.serverVersion),e.iceServers?t.iceServers=e.iceServers.map((e=>e?Zt.toJSON(e):void 0)):t.iceServers=[],void 0!==e.subscriberPrimary&&(t.subscriberPrimary=e.subscriberPrimary),void 0!==e.alternativeUrl&&(t.alternativeUrl=e.alternativeUrl),void 0!==e.clientConfiguration&&(t.clientConfiguration=e.clientConfiguration?Ct.toJSON(e.clientConfiguration):void 0),void 0!==e.serverRegion&&(t.serverRegion=e.serverRegion),t},fromPartial(e){var t,i,n,r,s,a;const o={room:void 0,participant:void 0,otherParticipants:[],serverVersion:"",iceServers:[],subscriberPrimary:!1,alternativeUrl:"",clientConfiguration:void 0,serverRegion:""};return o.room=void 0!==e.room&&null!==e.room?ut.fromPartial(e.room):void 0,o.participant=void 0!==e.participant&&null!==e.participant?pt.fromPartial(e.participant):void 0,o.otherParticipants=(null===(t=e.otherParticipants)||void 0===t?void 0:t.map((e=>pt.fromPartial(e))))||[],o.serverVersion=null!==(i=e.serverVersion)&&void 0!==i?i:"",o.iceServers=(null===(n=e.iceServers)||void 0===n?void 0:n.map((e=>Zt.fromPartial(e))))||[],o.subscriberPrimary=null!==(r=e.subscriberPrimary)&&void 0!==r&&r,o.alternativeUrl=null!==(s=e.alternativeUrl)&&void 0!==s?s:"",o.clientConfiguration=void 0!==e.clientConfiguration&&null!==e.clientConfiguration?Ct.fromPartial(e.clientConfiguration):void 0,o.serverRegion=null!==(a=e.serverRegion)&&void 0!==a?a:"",o}};const Ft={encode:(e,t=Ze.Writer.create())=>(""!==e.cid&&t.uint32(10).string(e.cid),void 0!==e.track&&mt.encode(e.track,t.uint32(18).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={cid:"",track:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.cid=i.string();break;case 2:r.track=mt.decode(i,i.uint32());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({cid:li(e.cid)?String(e.cid):"",track:li(e.track)?mt.fromJSON(e.track):void 0}),toJSON(e){const t={};return void 0!==e.cid&&(t.cid=e.cid),void 0!==e.track&&(t.track=e.track?mt.toJSON(e.track):void 0),t},fromPartial(e){var t;const i={cid:"",track:void 0};return i.cid=null!==(t=e.cid)&&void 0!==t?t:"",i.track=void 0!==e.track&&null!==e.track?mt.fromPartial(e.track):void 0,i}};const qt={encode:(e,t=Ze.Writer.create())=>(""!==e.trackSid&&t.uint32(10).string(e.trackSid),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:""};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.trackSid=i.string();else i.skipType(7&e)}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):""}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),t},fromPartial(e){var t;const i={trackSid:""};return i.trackSid=null!==(t=e.trackSid)&&void 0!==t?t:"",i}};const Qt={encode:(e,t=Ze.Writer.create())=>(""!==e.type&&t.uint32(10).string(e.type),""!==e.sdp&&t.uint32(18).string(e.sdp),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={type:"",sdp:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.type=i.string();break;case 2:r.sdp=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({type:li(e.type)?String(e.type):"",sdp:li(e.sdp)?String(e.sdp):""}),toJSON(e){const t={};return void 0!==e.type&&(t.type=e.type),void 0!==e.sdp&&(t.sdp=e.sdp),t},fromPartial(e){var t,i;const n={type:"",sdp:""};return n.type=null!==(t=e.type)&&void 0!==t?t:"",n.sdp=null!==(i=e.sdp)&&void 0!==i?i:"",n}};const Wt={encode(e,t=Ze.Writer.create()){for(const i of e.participants)pt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participants:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.participants.push(pt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({participants:Array.isArray(null==e?void 0:e.participants)?e.participants.map((e=>pt.fromJSON(e))):[]}),toJSON(e){const t={};return e.participants?t.participants=e.participants.map((e=>e?pt.toJSON(e):void 0)):t.participants=[],t},fromPartial(e){var t;const i={participants:[]};return i.participants=(null===(t=e.participants)||void 0===t?void 0:t.map((e=>pt.fromPartial(e))))||[],i}};const Gt={encode(e,t=Ze.Writer.create()){for(const i of e.trackSids)t.uint32(10).string(i);!0===e.subscribe&&t.uint32(16).bool(e.subscribe);for(const i of e.participantTracks)yt.encode(i,t.uint32(26).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSids:[],subscribe:!1,participantTracks:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSids.push(i.string());break;case 2:r.subscribe=i.bool();break;case 3:r.participantTracks.push(yt.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSids:Array.isArray(null==e?void 0:e.trackSids)?e.trackSids.map((e=>String(e))):[],subscribe:!!li(e.subscribe)&&Boolean(e.subscribe),participantTracks:Array.isArray(null==e?void 0:e.participantTracks)?e.participantTracks.map((e=>yt.fromJSON(e))):[]}),toJSON(e){const t={};return e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],void 0!==e.subscribe&&(t.subscribe=e.subscribe),e.participantTracks?t.participantTracks=e.participantTracks.map((e=>e?yt.toJSON(e):void 0)):t.participantTracks=[],t},fromPartial(e){var t,i,n;const r={trackSids:[],subscribe:!1,participantTracks:[]};return r.trackSids=(null===(t=e.trackSids)||void 0===t?void 0:t.map((e=>e)))||[],r.subscribe=null!==(i=e.subscribe)&&void 0!==i&&i,r.participantTracks=(null===(n=e.participantTracks)||void 0===n?void 0:n.map((e=>yt.fromPartial(e))))||[],r}};const Kt={encode(e,t=Ze.Writer.create()){for(const i of e.trackSids)t.uint32(10).string(i);return!0===e.disabled&&t.uint32(24).bool(e.disabled),0!==e.quality&&t.uint32(32).int32(e.quality),0!==e.width&&t.uint32(40).uint32(e.width),0!==e.height&&t.uint32(48).uint32(e.height),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSids:[],disabled:!1,quality:0,width:0,height:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSids.push(i.string());break;case 3:r.disabled=i.bool();break;case 4:r.quality=i.int32();break;case 5:r.width=i.uint32();break;case 6:r.height=i.uint32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSids:Array.isArray(null==e?void 0:e.trackSids)?e.trackSids.map((e=>String(e))):[],disabled:!!li(e.disabled)&&Boolean(e.disabled),quality:li(e.quality)?it(e.quality):0,width:li(e.width)?Number(e.width):0,height:li(e.height)?Number(e.height):0}),toJSON(e){const t={};return e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],void 0!==e.disabled&&(t.disabled=e.disabled),void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.width&&(t.width=Math.round(e.width)),void 0!==e.height&&(t.height=Math.round(e.height)),t},fromPartial(e){var t,i,n,r,s;const a={trackSids:[],disabled:!1,quality:0,width:0,height:0};return a.trackSids=(null===(t=e.trackSids)||void 0===t?void 0:t.map((e=>e)))||[],a.disabled=null!==(i=e.disabled)&&void 0!==i&&i,a.quality=null!==(n=e.quality)&&void 0!==n?n:0,a.width=null!==(r=e.width)&&void 0!==r?r:0,a.height=null!==(s=e.height)&&void 0!==s?s:0,a}};const Ht={encode:(e,t=Ze.Writer.create())=>(!0===e.canReconnect&&t.uint32(8).bool(e.canReconnect),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={canReconnect:!1};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.canReconnect=i.bool();else i.skipType(7&e)}return r},fromJSON:e=>({canReconnect:!!li(e.canReconnect)&&Boolean(e.canReconnect)}),toJSON(e){const t={};return void 0!==e.canReconnect&&(t.canReconnect=e.canReconnect),t},fromPartial(e){var t;const i={canReconnect:!1};return i.canReconnect=null!==(t=e.canReconnect)&&void 0!==t&&t,i}};const zt={encode(e,t=Ze.Writer.create()){""!==e.trackSid&&t.uint32(10).string(e.trackSid);for(const i of e.layers)ft.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:"",layers:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSid=i.string();break;case 2:r.layers.push(ft.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):"",layers:Array.isArray(null==e?void 0:e.layers)?e.layers.map((e=>ft.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),e.layers?t.layers=e.layers.map((e=>e?ft.toJSON(e):void 0)):t.layers=[],t},fromPartial(e){var t,i;const n={trackSid:"",layers:[]};return n.trackSid=null!==(t=e.trackSid)&&void 0!==t?t:"",n.layers=(null===(i=e.layers)||void 0===i?void 0:i.map((e=>ft.fromPartial(e))))||[],n}};const Zt={encode(e,t=Ze.Writer.create()){for(const i of e.urls)t.uint32(10).string(i);return""!==e.username&&t.uint32(18).string(e.username),""!==e.credential&&t.uint32(26).string(e.credential),t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={urls:[],username:"",credential:""};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.urls.push(i.string());break;case 2:r.username=i.string();break;case 3:r.credential=i.string();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({urls:Array.isArray(null==e?void 0:e.urls)?e.urls.map((e=>String(e))):[],username:li(e.username)?String(e.username):"",credential:li(e.credential)?String(e.credential):""}),toJSON(e){const t={};return e.urls?t.urls=e.urls.map((e=>e)):t.urls=[],void 0!==e.username&&(t.username=e.username),void 0!==e.credential&&(t.credential=e.credential),t},fromPartial(e){var t,i,n;const r={urls:[],username:"",credential:""};return r.urls=(null===(t=e.urls)||void 0===t?void 0:t.map((e=>e)))||[],r.username=null!==(i=e.username)&&void 0!==i?i:"",r.credential=null!==(n=e.credential)&&void 0!==n?n:"",r}};const $t={encode(e,t=Ze.Writer.create()){for(const i of e.speakers)bt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakers:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.speakers.push(bt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({speakers:Array.isArray(null==e?void 0:e.speakers)?e.speakers.map((e=>bt.fromJSON(e))):[]}),toJSON(e){const t={};return e.speakers?t.speakers=e.speakers.map((e=>e?bt.toJSON(e):void 0)):t.speakers=[],t},fromPartial(e){var t;const i={speakers:[]};return i.speakers=(null===(t=e.speakers)||void 0===t?void 0:t.map((e=>bt.fromPartial(e))))||[],i}};const Yt={encode:(e,t=Ze.Writer.create())=>(void 0!==e.room&&ut.encode(e.room,t.uint32(10).fork()).ldelim(),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={room:void 0};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.room=ut.decode(i,i.uint32());else i.skipType(7&e)}return r},fromJSON:e=>({room:li(e.room)?ut.fromJSON(e.room):void 0}),toJSON(e){const t={};return void 0!==e.room&&(t.room=e.room?ut.toJSON(e.room):void 0),t},fromPartial(e){const t={room:void 0};return t.room=void 0!==e.room&&null!==e.room?ut.fromPartial(e.room):void 0,t}};const Xt={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),0!==e.quality&&t.uint32(16).int32(e.quality),0!==e.score&&t.uint32(29).float(e.score),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",quality:0,score:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.quality=i.int32();break;case 3:r.score=i.float();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",quality:li(e.quality)?rt(e.quality):0,score:li(e.score)?Number(e.score):0}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.quality&&(t.quality=function(e){switch(e){case We.POOR:return"POOR";case We.GOOD:return"GOOD";case We.EXCELLENT:return"EXCELLENT";default:return"UNKNOWN"}}(e.quality)),void 0!==e.score&&(t.score=e.score),t},fromPartial(e){var t,i,n;const r={participantSid:"",quality:0,score:0};return r.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",r.quality=null!==(i=e.quality)&&void 0!==i?i:0,r.score=null!==(n=e.score)&&void 0!==n?n:0,r}};const ei={encode(e,t=Ze.Writer.create()){for(const i of e.updates)Xt.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={updates:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.updates.push(Xt.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({updates:Array.isArray(null==e?void 0:e.updates)?e.updates.map((e=>Xt.fromJSON(e))):[]}),toJSON(e){const t={};return e.updates?t.updates=e.updates.map((e=>e?Xt.toJSON(e):void 0)):t.updates=[],t},fromPartial(e){var t;const i={updates:[]};return i.updates=(null===(t=e.updates)||void 0===t?void 0:t.map((e=>Xt.fromPartial(e))))||[],i}};const ti={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),""!==e.trackSid&&t.uint32(18).string(e.trackSid),0!==e.state&&t.uint32(24).int32(e.state),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSid:"",state:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSid=i.string();break;case 3:r.state=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",trackSid:li(e.trackSid)?String(e.trackSid):"",state:li(e.state)?Mt(e.state):0}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.trackSid&&(t.trackSid=e.trackSid),void 0!==e.state&&(t.state=function(e){switch(e){case At.ACTIVE:return"ACTIVE";case At.PAUSED:return"PAUSED";default:return"UNKNOWN"}}(e.state)),t},fromPartial(e){var t,i,n;const r={participantSid:"",trackSid:"",state:0};return r.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",r.trackSid=null!==(i=e.trackSid)&&void 0!==i?i:"",r.state=null!==(n=e.state)&&void 0!==n?n:0,r}};const ii={encode(e,t=Ze.Writer.create()){for(const i of e.streamStates)ti.encode(i,t.uint32(10).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={streamStates:[]};for(;i.pos<n;){const e=i.uint32();if(e>>>3==1)r.streamStates.push(ti.decode(i,i.uint32()));else i.skipType(7&e)}return r},fromJSON:e=>({streamStates:Array.isArray(null==e?void 0:e.streamStates)?e.streamStates.map((e=>ti.fromJSON(e))):[]}),toJSON(e){const t={};return e.streamStates?t.streamStates=e.streamStates.map((e=>e?ti.toJSON(e):void 0)):t.streamStates=[],t},fromPartial(e){var t;const i={streamStates:[]};return i.streamStates=(null===(t=e.streamStates)||void 0===t?void 0:t.map((e=>ti.fromPartial(e))))||[],i}};const ni={encode:(e,t=Ze.Writer.create())=>(0!==e.quality&&t.uint32(8).int32(e.quality),!0===e.enabled&&t.uint32(16).bool(e.enabled),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={quality:0,enabled:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.quality=i.int32();break;case 2:r.enabled=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({quality:li(e.quality)?it(e.quality):0,enabled:!!li(e.enabled)&&Boolean(e.enabled)}),toJSON(e){const t={};return void 0!==e.quality&&(t.quality=nt(e.quality)),void 0!==e.enabled&&(t.enabled=e.enabled),t},fromPartial(e){var t,i;const n={quality:0,enabled:!1};return n.quality=null!==(t=e.quality)&&void 0!==t?t:0,n.enabled=null!==(i=e.enabled)&&void 0!==i&&i,n}};const ri={encode(e,t=Ze.Writer.create()){""!==e.trackSid&&t.uint32(10).string(e.trackSid);for(const i of e.subscribedQualities)ni.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={trackSid:"",subscribedQualities:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.trackSid=i.string();break;case 2:r.subscribedQualities.push(ni.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({trackSid:li(e.trackSid)?String(e.trackSid):"",subscribedQualities:Array.isArray(null==e?void 0:e.subscribedQualities)?e.subscribedQualities.map((e=>ni.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.trackSid&&(t.trackSid=e.trackSid),e.subscribedQualities?t.subscribedQualities=e.subscribedQualities.map((e=>e?ni.toJSON(e):void 0)):t.subscribedQualities=[],t},fromPartial(e){var t,i;const n={trackSid:"",subscribedQualities:[]};return n.trackSid=null!==(t=e.trackSid)&&void 0!==t?t:"",n.subscribedQualities=(null===(i=e.subscribedQualities)||void 0===i?void 0:i.map((e=>ni.fromPartial(e))))||[],n}};const si={encode(e,t=Ze.Writer.create()){""!==e.participantSid&&t.uint32(10).string(e.participantSid),!0===e.allTracks&&t.uint32(16).bool(e.allTracks);for(const i of e.trackSids)t.uint32(26).string(i);return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",allTracks:!1,trackSids:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.allTracks=i.bool();break;case 3:r.trackSids.push(i.string());break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",allTracks:!!li(e.allTracks)&&Boolean(e.allTracks),trackSids:Array.isArray(null==e?void 0:e.trackSids)?e.trackSids.map((e=>String(e))):[]}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.allTracks&&(t.allTracks=e.allTracks),e.trackSids?t.trackSids=e.trackSids.map((e=>e)):t.trackSids=[],t},fromPartial(e){var t,i,n;const r={participantSid:"",allTracks:!1,trackSids:[]};return r.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",r.allTracks=null!==(i=e.allTracks)&&void 0!==i&&i,r.trackSids=(null===(n=e.trackSids)||void 0===n?void 0:n.map((e=>e)))||[],r}};const ai={encode(e,t=Ze.Writer.create()){!0===e.allParticipants&&t.uint32(8).bool(e.allParticipants);for(const i of e.trackPermissions)si.encode(i,t.uint32(18).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={allParticipants:!1,trackPermissions:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.allParticipants=i.bool();break;case 2:r.trackPermissions.push(si.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({allParticipants:!!li(e.allParticipants)&&Boolean(e.allParticipants),trackPermissions:Array.isArray(null==e?void 0:e.trackPermissions)?e.trackPermissions.map((e=>si.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.allParticipants&&(t.allParticipants=e.allParticipants),e.trackPermissions?t.trackPermissions=e.trackPermissions.map((e=>e?si.toJSON(e):void 0)):t.trackPermissions=[],t},fromPartial(e){var t,i;const n={allParticipants:!1,trackPermissions:[]};return n.allParticipants=null!==(t=e.allParticipants)&&void 0!==t&&t,n.trackPermissions=(null===(i=e.trackPermissions)||void 0===i?void 0:i.map((e=>si.fromPartial(e))))||[],n}};const oi={encode:(e,t=Ze.Writer.create())=>(""!==e.participantSid&&t.uint32(10).string(e.participantSid),""!==e.trackSid&&t.uint32(18).string(e.trackSid),!0===e.allowed&&t.uint32(24).bool(e.allowed),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={participantSid:"",trackSid:"",allowed:!1};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.participantSid=i.string();break;case 2:r.trackSid=i.string();break;case 3:r.allowed=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({participantSid:li(e.participantSid)?String(e.participantSid):"",trackSid:li(e.trackSid)?String(e.trackSid):"",allowed:!!li(e.allowed)&&Boolean(e.allowed)}),toJSON(e){const t={};return void 0!==e.participantSid&&(t.participantSid=e.participantSid),void 0!==e.trackSid&&(t.trackSid=e.trackSid),void 0!==e.allowed&&(t.allowed=e.allowed),t},fromPartial(e){var t,i,n;const r={participantSid:"",trackSid:"",allowed:!1};return r.participantSid=null!==(t=e.participantSid)&&void 0!==t?t:"",r.trackSid=null!==(i=e.trackSid)&&void 0!==i?i:"",r.allowed=null!==(n=e.allowed)&&void 0!==n&&n,r}};const ci={encode(e,t=Ze.Writer.create()){void 0!==e.answer&&Qt.encode(e.answer,t.uint32(10).fork()).ldelim(),void 0!==e.subscription&&Gt.encode(e.subscription,t.uint32(18).fork()).ldelim();for(const i of e.publishTracks)Ft.encode(i,t.uint32(26).fork()).ldelim();for(const i of e.dataChannels)di.encode(i,t.uint32(34).fork()).ldelim();return t},decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={answer:void 0,subscription:void 0,publishTracks:[],dataChannels:[]};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.answer=Qt.decode(i,i.uint32());break;case 2:r.subscription=Gt.decode(i,i.uint32());break;case 3:r.publishTracks.push(Ft.decode(i,i.uint32()));break;case 4:r.dataChannels.push(di.decode(i,i.uint32()));break;default:i.skipType(7&e)}}return r},fromJSON:e=>({answer:li(e.answer)?Qt.fromJSON(e.answer):void 0,subscription:li(e.subscription)?Gt.fromJSON(e.subscription):void 0,publishTracks:Array.isArray(null==e?void 0:e.publishTracks)?e.publishTracks.map((e=>Ft.fromJSON(e))):[],dataChannels:Array.isArray(null==e?void 0:e.dataChannels)?e.dataChannels.map((e=>di.fromJSON(e))):[]}),toJSON(e){const t={};return void 0!==e.answer&&(t.answer=e.answer?Qt.toJSON(e.answer):void 0),void 0!==e.subscription&&(t.subscription=e.subscription?Gt.toJSON(e.subscription):void 0),e.publishTracks?t.publishTracks=e.publishTracks.map((e=>e?Ft.toJSON(e):void 0)):t.publishTracks=[],e.dataChannels?t.dataChannels=e.dataChannels.map((e=>e?di.toJSON(e):void 0)):t.dataChannels=[],t},fromPartial(e){var t,i;const n={answer:void 0,subscription:void 0,publishTracks:[],dataChannels:[]};return n.answer=void 0!==e.answer&&null!==e.answer?Qt.fromPartial(e.answer):void 0,n.subscription=void 0!==e.subscription&&null!==e.subscription?Gt.fromPartial(e.subscription):void 0,n.publishTracks=(null===(t=e.publishTracks)||void 0===t?void 0:t.map((e=>Ft.fromPartial(e))))||[],n.dataChannels=(null===(i=e.dataChannels)||void 0===i?void 0:i.map((e=>di.fromPartial(e))))||[],n}};const di={encode:(e,t=Ze.Writer.create())=>(""!==e.label&&t.uint32(10).string(e.label),0!==e.id&&t.uint32(16).uint32(e.id),0!==e.target&&t.uint32(24).int32(e.target),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={label:"",id:0,target:0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.label=i.string();break;case 2:r.id=i.uint32();break;case 3:r.target=i.int32();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({label:li(e.label)?String(e.label):"",id:li(e.id)?Number(e.id):0,target:li(e.target)?It(e.target):0}),toJSON(e){const t={};return void 0!==e.label&&(t.label=e.label),void 0!==e.id&&(t.id=Math.round(e.id)),void 0!==e.target&&(t.target=Lt(e.target)),t},fromPartial(e){var t,i,n;const r={label:"",id:0,target:0};return r.label=null!==(t=e.label)&&void 0!==t?t:"",r.id=null!==(i=e.id)&&void 0!==i?i:0,r.target=null!==(n=e.target)&&void 0!==n?n:0,r}};const ui={encode:(e,t=Ze.Writer.create())=>(void 0!==e.speakerUpdate&&t.uint32(8).int32(e.speakerUpdate),void 0!==e.nodeFailure&&t.uint32(16).bool(e.nodeFailure),void 0!==e.migration&&t.uint32(24).bool(e.migration),void 0!==e.serverLeave&&t.uint32(32).bool(e.serverLeave),t),decode(e,t){const i=e instanceof Ze.Reader?e:new Ze.Reader(e);let n=void 0===t?i.len:i.pos+t;const r={speakerUpdate:void 0,nodeFailure:void 0,migration:void 0,serverLeave:void 0};for(;i.pos<n;){const e=i.uint32();switch(e>>>3){case 1:r.speakerUpdate=i.int32();break;case 2:r.nodeFailure=i.bool();break;case 3:r.migration=i.bool();break;case 4:r.serverLeave=i.bool();break;default:i.skipType(7&e)}}return r},fromJSON:e=>({speakerUpdate:li(e.speakerUpdate)?Number(e.speakerUpdate):void 0,nodeFailure:li(e.nodeFailure)?Boolean(e.nodeFailure):void 0,migration:li(e.migration)?Boolean(e.migration):void 0,serverLeave:li(e.serverLeave)?Boolean(e.serverLeave):void 0}),toJSON(e){const t={};return void 0!==e.speakerUpdate&&(t.speakerUpdate=Math.round(e.speakerUpdate)),void 0!==e.nodeFailure&&(t.nodeFailure=e.nodeFailure),void 0!==e.migration&&(t.migration=e.migration),void 0!==e.serverLeave&&(t.serverLeave=e.serverLeave),t},fromPartial(e){var t,i,n,r;const s={speakerUpdate:void 0,nodeFailure:void 0,migration:void 0,serverLeave:void 0};return s.speakerUpdate=null!==(t=e.speakerUpdate)&&void 0!==t?t:void 0,s.nodeFailure=null!==(i=e.nodeFailure)&&void 0!==i?i:void 0,s.migration=null!==(n=e.migration)&&void 0!==n?n:void 0,s.serverLeave=null!==(r=e.serverLeave)&&void 0!==r?r:void 0,s}};function li(e){return null!=e}Ze.util.Long!==o&&(Ze.util.Long=o,Ze.configure());class hi extends Error{constructor(e,t){super(t||"an error has occured"),this.code=e}}class pi extends hi{constructor(e){super(1,e)}}class mi extends hi{constructor(e){super(20,e||"Track is invalid")}}class fi extends hi{constructor(e){super(10,e||"Unsupported server")}}class vi extends hi{constructor(e){super(12,e||"Unexpected connection state")}}var gi,bi,ki,Si,yi;e.MediaDeviceFailure=void 0,(gi=e.MediaDeviceFailure||(e.MediaDeviceFailure={})).PermissionDenied="PermissionDenied",gi.NotFound="NotFound",gi.DeviceInUse="DeviceInUse",gi.Other="Other",function(e){e.getFailure=function(t){if(t&&"name"in t)return"NotFoundError"===t.name||"DevicesNotFoundError"===t.name?e.NotFound:"NotAllowedError"===t.name||"PermissionDeniedError"===t.name?e.PermissionDenied:"NotReadableError"===t.name||"TrackStartError"===t.name?e.DeviceInUse:e.Other}}(e.MediaDeviceFailure||(e.MediaDeviceFailure={})),e.RoomEvent=void 0,(bi=e.RoomEvent||(e.RoomEvent={})).Reconnecting="reconnecting",bi.Reconnected="reconnected",bi.Disconnected="disconnected",bi.StateChanged="stateChanged",bi.MediaDevicesChanged="mediaDevicesChanged",bi.ParticipantConnected="participantConnected",bi.ParticipantDisconnected="participantDisconnected",bi.TrackPublished="trackPublished",bi.TrackSubscribed="trackSubscribed",bi.TrackSubscriptionFailed="trackSubscriptionFailed",bi.TrackUnpublished="trackUnpublished",bi.TrackUnsubscribed="trackUnsubscribed",bi.TrackMuted="trackMuted",bi.TrackUnmuted="trackUnmuted",bi.LocalTrackPublished="localTrackPublished",bi.LocalTrackUnpublished="localTrackUnpublished",bi.ActiveSpeakersChanged="activeSpeakersChanged",bi.MetadataChanged="metadataChanged",bi.ParticipantMetadataChanged="participantMetadataChanged",bi.RoomMetadataChanged="roomMetadataChanged",bi.DataReceived="dataReceived",bi.ConnectionQualityChanged="connectionQualityChanged",bi.TrackStreamStateChanged="trackStreamStateChanged",bi.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",bi.AudioPlaybackStatusChanged="audioPlaybackChanged",bi.MediaDevicesError="mediaDevicesError",bi.ParticipantPermissionsChanged="participantPermissionsChanged",e.ParticipantEvent=void 0,(ki=e.ParticipantEvent||(e.ParticipantEvent={})).TrackPublished="trackPublished",ki.TrackSubscribed="trackSubscribed",ki.TrackSubscriptionFailed="trackSubscriptionFailed",ki.TrackUnpublished="trackUnpublished",ki.TrackUnsubscribed="trackUnsubscribed",ki.TrackMuted="trackMuted",ki.TrackUnmuted="trackUnmuted",ki.LocalTrackPublished="localTrackPublished",ki.LocalTrackUnpublished="localTrackUnpublished",ki.MetadataChanged="metadataChanged",ki.ParticipantMetadataChanged="participantMetadataChanged",ki.DataReceived="dataReceived",ki.IsSpeakingChanged="isSpeakingChanged",ki.ConnectionQualityChanged="connectionQualityChanged",ki.TrackStreamStateChanged="trackStreamStateChanged",ki.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",ki.MediaDevicesError="mediaDevicesError",ki.ParticipantPermissionsChanged="participantPermissionsChanged",e.EngineEvent=void 0,(Si=e.EngineEvent||(e.EngineEvent={})).TransportsCreated="transportsCreated",Si.Connected="connected",Si.Disconnected="disconnected",Si.Resuming="resuming",Si.Resumed="resumed",Si.Restarting="restarting",Si.Restarted="restarted",Si.SignalResumed="signalResumed",Si.MediaTrackAdded="mediaTrackAdded",Si.ActiveSpeakersUpdate="activeSpeakersUpdate",Si.DataPacketReceived="dataPacketReceived",e.TrackEvent=void 0,(yi=e.TrackEvent||(e.TrackEvent={})).Message="message",yi.Muted="muted",yi.Unmuted="unmuted",yi.Ended="ended",yi.UpdateSettings="updateSettings",yi.UpdateSubscription="updateSubscription",yi.AudioPlaybackStarted="audioPlaybackStarted",yi.AudioPlaybackFailed="audioPlaybackFailed",yi.AudioSilenceDetected="audioSilenceDetected",yi.VisibilityChanged="visibilityChanged",yi.VideoDimensionsChanged="videoDimensionsChanged",yi.ElementAttached="elementAttached",yi.ElementDetached="elementDetached",yi.UpstreamPaused="upstreamPaused",yi.UpstreamResumed="upstreamResumed";const wi=2e3;function Ci(e,t){if(!t)return 0;let i,n;return"bytesReceived"in e?(i=e.bytesReceived,n=t.bytesReceived):"bytesSent"in e&&(i=e.bytesSent,n=t.bytesSent),void 0===i||void 0===n||void 0===e.timestamp||void 0===t.timestamp?0:8*(i-n)*1e3/(e.timestamp-t.timestamp)}const Ti="default";class Ei{static getInstance(){return void 0===this.instance&&(this.instance=new Ei),this.instance}async getDevices(e,t=!0){let i=await navigator.mediaDevices.enumerateDevices();if(t){if(0===i.length||i.some((t=>{const i=""===t.label,n=!e||t.kind===e;return i&&n}))){const t={video:"audioinput"!==e&&"audiooutput"!==e,audio:"videoinput"!==e};await navigator.mediaDevices.getUserMedia(t),i=await navigator.mediaDevices.enumerateDevices()}}if(e&&(i=i.filter((t=>t.kind===e))),i.length>1&&i[0].deviceId===Ti){const e=i[0];for(let t=1;t<i.length;t+=1)if(i[t].groupId===e.groupId){const e=i[0];i[0]=i[t],i[t]=e;break}return i.filter((t=>t!==e))}return i}async normalizeDeviceId(e,t,i){if(t!==Ti)return t;const n=(await this.getDevices(e)).find((e=>e.groupId===i&&e.deviceId!==Ti));return null==n?void 0:n.deviceId}}Ei.mediaDeviceKinds=["audioinput","audiooutput","videoinput"];const Pi="0.18.2";async function Ri(e){return new Promise((t=>setTimeout(t,e)))}function Oi(){return!!Di()&&-1!==navigator.userAgent.indexOf("Firefox")}function Ni(){return!!Di()&&/Tablet|iPad|Mobile|Android|BlackBerry/.test(navigator.userAgent)}function Di(){return"undefined"!=typeof document}function Ui(e){for(const t of e)t.target.handleResize(t)}function Ai(e){for(const t of e)t.target.handleVisibilityChanged(t)}let Ii=null;const Li=()=>(Ii||(Ii=new ResizeObserver(Ui)),Ii);let Mi=null;const _i=()=>(Mi||(Mi=new IntersectionObserver(Ai,{root:document,rootMargin:"0px"})),Mi);let xi;var Ji,Bi={exports:{}},ji="object"==typeof Reflect?Reflect:null,Vi=ji&&"function"==typeof ji.apply?ji.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)};Ji=ji&&"function"==typeof ji.ownKeys?ji.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var Fi=Number.isNaN||function(e){return e!=e};function qi(){qi.init.call(this)}Bi.exports=qi,Bi.exports.once=function(e,t){return new Promise((function(i,n){function r(i){e.removeListener(t,s),n(i)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",r),i([].slice.call(arguments))}Xi(e,t,s,{once:!0}),"error"!==t&&function(e,t,i){"function"==typeof e.on&&Xi(e,"error",t,i)}(e,r,{once:!0})}))},qi.EventEmitter=qi,qi.prototype._events=void 0,qi.prototype._eventsCount=0,qi.prototype._maxListeners=void 0;var Qi=10;function Wi(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function Gi(e){return void 0===e._maxListeners?qi.defaultMaxListeners:e._maxListeners}function Ki(e,t,i,n){var r,s,a,o;if(Wi(i),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),a=s[t]),void 0===a)a=s[t]=i,++e._eventsCount;else if("function"==typeof a?a=s[t]=n?[i,a]:[a,i]:n?a.unshift(i):a.push(i),(r=Gi(e))>0&&a.length>r&&!a.warned){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,o=c,console&&console.warn&&console.warn(o)}return e}function Hi(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function zi(e,t,i){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},r=Hi.bind(n);return r.listener=i,n.wrapFn=r,r}function Zi(e,t,i){var n=e._events;if(void 0===n)return[];var r=n[t];return void 0===r?[]:"function"==typeof r?i?[r.listener||r]:[r]:i?function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(r):Yi(r,r.length)}function $i(e){var t=this._events;if(void 0!==t){var i=t[e];if("function"==typeof i)return 1;if(void 0!==i)return i.length}return 0}function Yi(e,t){for(var i=new Array(t),n=0;n<t;++n)i[n]=e[n];return i}function Xi(e,t,i,n){if("function"==typeof e.on)n.once?e.once(t,i):e.on(t,i);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function r(s){n.once&&e.removeEventListener(t,r),i(s)}))}}Object.defineProperty(qi,"defaultMaxListeners",{enumerable:!0,get:function(){return Qi},set:function(e){if("number"!=typeof e||e<0||Fi(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Qi=e}}),qi.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},qi.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||Fi(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},qi.prototype.getMaxListeners=function(){return Gi(this)},qi.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var n="error"===e,r=this._events;if(void 0!==r)n=n&&void 0===r.error;else if(!n)return!1;if(n){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var o=r[e];if(void 0===o)return!1;if("function"==typeof o)Vi(o,this,t);else{var c=o.length,d=Yi(o,c);for(i=0;i<c;++i)Vi(d[i],this,t)}return!0},qi.prototype.addListener=function(e,t){return Ki(this,e,t,!1)},qi.prototype.on=qi.prototype.addListener,qi.prototype.prependListener=function(e,t){return Ki(this,e,t,!0)},qi.prototype.once=function(e,t){return Wi(t),this.on(e,zi(this,e,t)),this},qi.prototype.prependOnceListener=function(e,t){return Wi(t),this.prependListener(e,zi(this,e,t)),this},qi.prototype.removeListener=function(e,t){var i,n,r,s,a;if(Wi(t),void 0===(n=this._events))return this;if(void 0===(i=n[e]))return this;if(i===t||i.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(r=-1,s=i.length-1;s>=0;s--)if(i[s]===t||i[s].listener===t){a=i[s].listener,r=s;break}if(r<0)return this;0===r?i.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(i,r),1===i.length&&(n[e]=i[0]),void 0!==n.removeListener&&this.emit("removeListener",e,a||t)}return this},qi.prototype.off=qi.prototype.removeListener,qi.prototype.removeAllListeners=function(e){var t,i,n;if(void 0===(i=this._events))return this;if(void 0===i.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==i[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete i[e]),this;if(0===arguments.length){var r,s=Object.keys(i);for(n=0;n<s.length;++n)"removeListener"!==(r=s[n])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},qi.prototype.listeners=function(e){return Zi(this,e,!0)},qi.prototype.rawListeners=function(e){return Zi(this,e,!1)},qi.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):$i.call(e,t)},qi.prototype.listenerCount=$i,qi.prototype.eventNames=function(){return this._eventsCount>0?Ji(this._events):[]};const en=[];class tn extends Bi.exports.EventEmitter{constructor(e,t){super(),this.attachedElements=[],this.isMuted=!1,this._currentBitrate=0,this.appVisibilityChangedListener=()=>{this.handleAppVisibilityChanged()},this.kind=t,this.mediaStreamTrack=e,this.source=tn.Source.Unknown,Di()?(this.isInBackground="hidden"===document.visibilityState,document.addEventListener("visibilitychange",this.appVisibilityChangedListener)):this.isInBackground=!1}get currentBitrate(){return this._currentBitrate}attach(t){let i="audio";return this.kind===tn.Kind.Video&&(i="video"),t||("audio"===i&&(en.forEach((e=>{null!==e.parentElement||t||(t=e)})),t&&en.splice(en.indexOf(t),1)),t||(t=document.createElement(i))),this.attachedElements.includes(t)||this.attachedElements.push(t),nn(this.mediaStreamTrack,t),t instanceof HTMLAudioElement&&t.play().then((()=>{this.emit(e.TrackEvent.AudioPlaybackStarted)})).catch((t=>{this.emit(e.TrackEvent.AudioPlaybackFailed,t)})),this.emit(e.TrackEvent.ElementAttached,t),t}detach(t){if(t){rn(this.mediaStreamTrack,t);const i=this.attachedElements.indexOf(t);return i>=0&&(this.attachedElements.splice(i,1),this.recycleElement(t),this.emit(e.TrackEvent.ElementDetached,t)),t}const i=[];return this.attachedElements.forEach((t=>{rn(this.mediaStreamTrack,t),i.push(t),this.recycleElement(t),this.emit(e.TrackEvent.ElementDetached,t)})),this.attachedElements=[],i}stop(){this.mediaStreamTrack.stop(),Di()&&document.removeEventListener("visibilitychange",this.appVisibilityChangedListener)}enable(){this.mediaStreamTrack.enabled=!0}disable(){this.mediaStreamTrack.enabled=!1}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),en.forEach((e=>{e.parentElement||(t=!1)})),t&&en.push(e)}}async handleAppVisibilityChanged(){this.isInBackground="hidden"===document.visibilityState}}function nn(e,t){let i,n;i=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream,n="audio"===e.kind?i.getAudioTracks():i.getVideoTracks(),n.includes(e)||(n.forEach((e=>{i.removeTrack(e)})),i.addTrack(e)),t.srcObject!==i&&(t.srcObject=i,(Di()&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||Oi())&&t instanceof HTMLVideoElement&&setTimeout((()=>{t.srcObject=i,t.play().catch((()=>{}))}),0)),t.autoplay=!0,t instanceof HTMLVideoElement&&(t.playsInline=!0)}function rn(e,t){if(t.srcObject instanceof MediaStream){t.srcObject.removeTrack(e),t.srcObject=null}}!function(e){let t,i,n;!function(e){e.Audio="audio",e.Video="video",e.Unknown="unknown"}(t=e.Kind||(e.Kind={})),function(e){e.Camera="camera",e.Microphone="microphone",e.ScreenShare="screen_share",e.ScreenShareAudio="screen_share_audio",e.Unknown="unknown"}(i=e.Source||(e.Source={})),function(e){e.Active="active",e.Paused="paused",e.Unknown="unknown"}(n=e.StreamState||(e.StreamState={})),e.kindToProto=function(e){switch(e){case t.Audio:return Fe.AUDIO;case t.Video:return Fe.VIDEO;default:return Fe.UNRECOGNIZED}},e.kindFromProto=function(e){switch(e){case Fe.AUDIO:return t.Audio;case Fe.VIDEO:return t.Video;default:return t.Unknown}},e.sourceToProto=function(e){switch(e){case i.Camera:return qe.CAMERA;case i.Microphone:return qe.MICROPHONE;case i.ScreenShare:return qe.SCREEN_SHARE;case i.ScreenShareAudio:return qe.SCREEN_SHARE_AUDIO;default:return qe.UNRECOGNIZED}},e.sourceFromProto=function(e){switch(e){case qe.CAMERA:return i.Camera;case qe.MICROPHONE:return i.Microphone;case qe.SCREEN_SHARE:return i.ScreenShare;case qe.SCREEN_SHARE_AUDIO:return i.ScreenShareAudio;default:return i.Unknown}},e.streamStateFromProto=function(e){switch(e){case At.ACTIVE:return n.Active;case At.PAUSED:return n.Paused;default:return n.Unknown}}}(tn||(tn={}));class sn extends tn{constructor(t,i,n){super(t,i),this._isUpstreamPaused=!1,this.handleEnded=()=>{this.isInBackground&&(this.reacquireTrack=!0),this.emit(e.TrackEvent.Ended,this)},this.mediaStreamTrack.addEventListener("ended",this.handleEnded),this.constraints=null!=n?n:t.getConstraints(),this.reacquireTrack=!1,this.wasMuted=!1}get id(){return this.mediaStreamTrack.id}get dimensions(){if(this.kind!==tn.Kind.Video)return;const{width:e,height:t}=this.mediaStreamTrack.getSettings();return e&&t?{width:e,height:t}:void 0}get isUpstreamPaused(){return this._isUpstreamPaused}async getDeviceId(){if(this.source===tn.Source.ScreenShare)return;const{deviceId:e,groupId:t}=this.mediaStreamTrack.getSettings(),i=this.kind===tn.Kind.Audio?"audioinput":"videoinput";return Ei.getInstance().normalizeDeviceId(i,e,t)}async mute(){return this.setTrackMuted(!0),this}async unmute(){return this.setTrackMuted(!1),this}async replaceTrack(e){if(!this.sender)throw new mi("unable to replace an unpublished track");return this.attachedElements.forEach((e=>{rn(this.mediaStreamTrack,e)})),this.mediaStreamTrack.removeEventListener("ended",this.handleEnded),this.mediaStreamTrack.stop(),e.addEventListener("ended",this.handleEnded),s.debug("re-acquired MediaStreamTrack"),await this.sender.replaceTrack(e),this.mediaStreamTrack=e,this.attachedElements.forEach((t=>{nn(e,t)})),this.mediaStream=new MediaStream([e]),this}async restart(e){if(!this.sender)throw new mi("unable to restart an unpublished track");e||(e=this.constraints),s.debug("restarting track with constraints",e);const t={audio:!1,video:!1};this.kind===tn.Kind.Video?t.video=e:t.audio=e,this.attachedElements.forEach((e=>{rn(this.mediaStreamTrack,e)})),this.mediaStreamTrack.removeEventListener("ended",this.handleEnded),this.mediaStreamTrack.stop();const i=await navigator.mediaDevices.getUserMedia(t),n=i.getTracks()[0];return n.addEventListener("ended",this.handleEnded),s.debug("re-acquired MediaStreamTrack"),await this.sender.replaceTrack(n),this.mediaStreamTrack=n,this.attachedElements.forEach((e=>{nn(n,e)})),this.mediaStream=i,this.constraints=e,this}setTrackMuted(t){this.isMuted!==t&&(this.isMuted=t,this.mediaStreamTrack.enabled=!t,this.emit(t?e.TrackEvent.Muted:e.TrackEvent.Unmuted,this))}get needsReAcquisition(){return"live"!==this.mediaStreamTrack.readyState||this.mediaStreamTrack.muted||!this.mediaStreamTrack.enabled||this.reacquireTrack}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),Ni()&&(s.debug(`visibility changed, is in Background: ${this.isInBackground}`),!this.isInBackground&&this.needsReAcquisition&&(s.debug(`track needs to be reaquired, restarting ${this.source}`),await this.restart(),this.reacquireTrack=!1,this.setTrackMuted(this.wasMuted)),this.isInBackground&&(this.wasMuted=this.isMuted))}async pauseUpstream(){!0!==this._isUpstreamPaused&&(this.sender?(this._isUpstreamPaused=!0,this.emit(e.TrackEvent.UpstreamPaused,this),await this.sender.replaceTrack(function(){if(!xi){const e=document.createElement("canvas");e.width=2,e.height=2;const t=e.captureStream();if([xi]=t.getTracks(),!xi)throw Error("Could not get empty media stream track");xi.enabled=!1}return xi}())):s.warn("unable to pause upstream for an unpublished track"))}async resumeUpstream(){!1!==this._isUpstreamPaused&&(this.sender?(this._isUpstreamPaused=!1,this.emit(e.TrackEvent.UpstreamResumed,this),await this.sender.replaceTrack(this.mediaStreamTrack)):s.warn("unable to resume upstream for an unpublished track"))}}function an(e,t,i){const n={...e};return!0===n.audio&&(n.audio={}),!0===n.video&&(n.video={}),n.audio&&on(n.audio,t),n.video&&on(n.video,i),n}function on(e,t){return Object.keys(t).forEach((i=>{void 0===e[i]&&(e[i]=t[i])})),e}function cn(e){const t={};if(e.video)if("object"==typeof e.video){const i={},n=i,r=e.video;Object.keys(r).forEach((e=>{if("resolution"===e)on(n,r.resolution);else n[e]=r[e]})),t.video=i}else t.video=e.video;else t.video=!1;return e.audio?"object"==typeof e.audio?t.audio=e.audio:t.audio=!0:t.audio=!1,t}function dn(){const e=window.AudioContext||window.webkitAudioContext;if(e)return new e}class un extends sn{constructor(e,t){super(e,tn.Kind.Audio,t),this.stopOnMute=!1,this.monitorSender=async()=>{if(!this.sender)return void(this._currentBitrate=0);let e;try{e=await this.getSenderStats()}catch(e){return void s.error("could not get audio sender stats",e)}e&&this.prevStats&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorSender()}),wi)},this.checkForSilence()}async setDeviceId(e){this.constraints.deviceId!==e&&(this.constraints.deviceId=e,this.isMuted||await this.restartTrack())}async mute(){return this.source===tn.Source.Microphone&&this.stopOnMute&&(s.debug("stopping mic track"),this.mediaStreamTrack.stop()),await super.mute(),this}async unmute(){return this.source===tn.Source.Microphone&&this.stopOnMute&&(s.debug("reacquiring mic track"),await this.restartTrack()),await super.unmute(),this}async restartTrack(e){let t;if(e){const i=cn({audio:e});"boolean"!=typeof i.audio&&(t=i.audio)}await this.restart(t)}async restart(e){const t=await super.restart(e);return this.checkForSilence(),t}startMonitor(){setTimeout((()=>{this.monitorSender()}),wi)}async getSenderStats(){if(!this.sender)return;let e;return(await this.sender.getStats()).forEach((t=>{"outbound-rtp"===t.type&&(e={type:"audio",streamId:t.id,packetsSent:t.packetsSent,packetsLost:t.packetsLost,bytesSent:t.bytesSent,timestamp:t.timestamp,roundTripTime:t.roundTripTime,jitter:t.jitter})})),e}async checkForSilence(){await async function(e,t=200){const i=dn();if(i){const n=i.createAnalyser();n.fftSize=2048;const r=n.frequencyBinCount,s=new Uint8Array(r);i.createMediaStreamSource(new MediaStream([e.mediaStreamTrack])).connect(n),await Ri(t),n.getByteTimeDomainData(s);const a=s.some((e=>128!==e&&0!==e));return i.close(),!a}return!1}(this)&&(this.isMuted||s.warn("silence detected on local audio track"),this.emit(e.TrackEvent.AudioSilenceDetected))}}class ln extends sn{constructor(e,t){super(e,tn.Kind.Video,t),this.monitorSender=async()=>{if(!this.sender)return void(this._currentBitrate=0);let e;try{e=await this.getSenderStats()}catch(e){return void s.error("could not get audio sender stats",{error:e})}const t=new Map(e.map((e=>[e.rid,e])));if(this.prevStats){let e=0;t.forEach(((t,i)=>{var n;const r=null===(n=this.prevStats)||void 0===n?void 0:n.get(i);e+=Ci(t,r)})),this._currentBitrate=e}this.prevStats=t,setTimeout((()=>{this.monitorSender()}),wi)}}get isSimulcast(){return!!(this.sender&&this.sender.getParameters().encodings.length>1)}startMonitor(e){var t;this.signalClient=e;const i=null===(t=this.sender)||void 0===t?void 0:t.getParameters();i&&(this.encodings=i.encodings),setTimeout((()=>{this.monitorSender()}),wi)}stop(){this.sender=void 0,this.mediaStreamTrack.getConstraints(),super.stop()}async mute(){return this.source===tn.Source.Camera&&(s.debug("stopping camera track"),this.mediaStreamTrack.stop()),await super.mute(),this}async unmute(){return this.source===tn.Source.Camera&&(s.debug("reacquiring camera track"),await this.restartTrack()),await super.unmute(),this}async getSenderStats(){if(!this.sender)return[];const e=[],t=await this.sender.getStats();return t.forEach((i=>{var n;if("outbound-rtp"===i.type){const r={type:"video",streamId:i.id,frameHeight:i.frameHeight,frameWidth:i.frameWidth,firCount:i.firCount,pliCount:i.pliCount,nackCount:i.nackCount,packetsSent:i.packetsSent,bytesSent:i.bytesSent,framesSent:i.framesSent,timestamp:i.timestamp,rid:null!==(n=i.rid)&&void 0!==n?n:"",retransmittedPacketsSent:i.retransmittedPacketsSent,qualityLimitationReason:i.qualityLimitationReason,qualityLimitationResolutionChanges:i.qualityLimitationResolutionChanges},s=t.get(i.remoteId);s&&(r.jitter=s.jitter,r.packetsLost=s.packetsLost,r.roundTripTime=s.roundTripTime),e.push(r)}})),e}setPublishingQuality(t){const i=[];for(let n=e.VideoQuality.LOW;n<=e.VideoQuality.HIGH;n+=1)i.push({quality:n,enabled:n<=t});s.debug(`setting publishing quality. max quality ${t}`),this.setPublishingLayers(i)}async setDeviceId(e){this.constraints.deviceId!==e&&(this.constraints.deviceId=e,this.isMuted||await this.restartTrack())}async restartTrack(e){let t;if(e){const i=cn({video:e});"boolean"!=typeof i.video&&(t=i.video)}await this.restart(t)}async setPublishingLayers(e){if(s.debug("setting publishing layers",e),!this.sender||!this.encodings)return;const t=this.sender.getParameters(),{encodings:i}=t;if(!i)return;if(i.length!==this.encodings.length)return void s.warn("cannot set publishing layers, encodings mismatch");let n=!1;i.forEach(((t,i)=>{var r;let a=null!==(r=t.rid)&&void 0!==r?r:"";""===a&&(a="q");const o=hn(a),c=e.find((e=>e.quality===o));c&&t.active!==c.enabled&&(n=!0,t.active=c.enabled,s.debug(`setting layer ${c.quality} to ${t.active?"enabled":"disabled"}`),Oi()&&(c.enabled?(t.scaleResolutionDownBy=this.encodings[i].scaleResolutionDownBy,t.maxBitrate=this.encodings[i].maxBitrate,t.maxFrameRate=this.encodings[i].maxFrameRate):(t.scaleResolutionDownBy=4,t.maxBitrate=10,t.maxFrameRate=2)))})),n&&(t.encodings=i,await this.sender.setParameters(t))}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),Ni()&&this.isInBackground&&this.source===tn.Source.Camera&&(this.mediaStreamTrack.enabled=!1)}}function hn(t){switch(t){case"f":return e.VideoQuality.HIGH;case"h":return e.VideoQuality.MEDIUM;case"q":return e.VideoQuality.LOW;default:return e.VideoQuality.UNRECOGNIZED}}class pn extends tn{constructor(e,t,i,n){super(e,i),this.streamState=tn.StreamState.Active,this.sid=t,this.receiver=n}setMuted(t){this.isMuted!==t&&(this.isMuted=t,this.emit(t?e.TrackEvent.Muted:e.TrackEvent.Unmuted,this))}setMediaStream(t){this.mediaStream=t,t.onremovetrack=()=>{this.receiver=void 0,this._currentBitrate=0,this.emit(e.TrackEvent.Ended,this)}}start(){this.startMonitor(),super.enable()}stop(){super.disable()}startMonitor(){setTimeout((()=>{this.monitorReceiver()}),wi)}}class mn extends pn{constructor(e,t,i){super(e,t,tn.Kind.Audio,i),this.monitorReceiver=async()=>{if(!this.receiver)return void(this._currentBitrate=0);const e=await this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorReceiver()}),wi)},this.elementVolume=1}setVolume(e){for(const t of this.attachedElements)t.volume=e;this.elementVolume=e}getVolume(){return this.elementVolume}attach(e){return e?super.attach(e):e=super.attach(),e.volume=this.elementVolume,e}async getReceiverStats(){if(!this.receiver)return;let e;return(await this.receiver.getStats()).forEach((t=>{"inbound-rtp"===t.type&&(e={type:"audio",timestamp:t.timestamp,jitter:t.jitter,bytesReceived:t.bytesReceived,concealedSamples:t.concealedSamples,concealmentEvents:t.concealmentEvents,silentConcealedSamples:t.silentConcealedSamples,silentConcealmentEvents:t.silentConcealmentEvents,totalAudioEnergy:t.totalAudioEnergy,totalSamplesDuration:t.totalSamplesDuration})})),e}}function fn(e,t,i){var n,r,s;void 0===t&&(t=50),void 0===i&&(i={});var a=null!=(n=i.isImmediate)&&n,o=null!=(r=i.callback)&&r,c=i.maxWait,d=Date.now(),u=[];function l(){if(void 0!==c){var e=Date.now()-d;if(e+t>=c)return c-e}return t}var h=function(){var t=[].slice.call(arguments),i=this;return new Promise((function(n,r){var c=a&&void 0===s;if(void 0!==s&&clearTimeout(s),s=setTimeout((function(){if(s=void 0,d=Date.now(),!a){var n=e.apply(i,t);o&&o(n),u.forEach((function(e){return(0,e.resolve)(n)})),u=[]}}),l()),c){var h=e.apply(i,t);return o&&o(h),n(h)}u.push({resolve:n,reject:r})}))};return h.cancel=function(e){void 0!==s&&clearTimeout(s),u.forEach((function(t){return(0,t.reject)(e)})),u=[]},h}class vn extends pn{constructor(e,t,i,n){super(e,t,tn.Kind.Video,i),this.elementInfos=[],this.monitorReceiver=async()=>{if(!this.receiver)return void(this._currentBitrate=0);const e=await this.getReceiverStats();e&&this.prevStats&&this.receiver&&(this._currentBitrate=Ci(e,this.prevStats)),this.prevStats=e,setTimeout((()=>{this.monitorReceiver()}),wi)},this.handleVisibilityChanged=e=>{const{target:t,isIntersecting:i}=e,n=this.elementInfos.find((e=>e.element===t));n&&(n.visible=i,n.visibilityChangedAt=Date.now()),this.updateVisibility()},this.debouncedHandleResize=fn((()=>{this.updateDimensions()}),100),this.adaptiveStreamSettings=n}get isAdaptiveStream(){return void 0!==this.adaptiveStreamSettings}setMuted(e){super.setMuted(e),this.attachedElements.forEach((t=>{e?rn(this.mediaStreamTrack,t):nn(this.mediaStreamTrack,t)}))}attach(e){return e?super.attach(e):e=super.attach(),this.adaptiveStreamSettings&&void 0===this.elementInfos.find((t=>t.element===e))&&(this.elementInfos.push({element:e,visible:!0}),e.handleResize=this.debouncedHandleResize,e.handleVisibilityChanged=this.handleVisibilityChanged,_i().observe(e),Li().observe(e),this.debouncedHandleResize()),e}detach(e){let t=[];if(e)return this.stopObservingElement(e),super.detach(e);t=super.detach();for(const e of t)this.stopObservingElement(e);return t}async getReceiverStats(){if(!this.receiver)return;let e;return(await this.receiver.getStats()).forEach((t=>{"inbound-rtp"===t.type&&(e={type:"video",framesDecoded:t.framesDecoded,framesDropped:t.framesDropped,framesReceived:t.framesReceived,packetsReceived:t.packetsReceived,packetsLost:t.packetsLost,frameWidth:t.frameWidth,frameHeight:t.frameHeight,pliCount:t.pliCount,firCount:t.firCount,nackCount:t.nackCount,jitter:t.jitter,timestamp:t.timestamp,bytesReceived:t.bytesReceived})})),e}stopObservingElement(e){var t,i;null===(t=_i())||void 0===t||t.unobserve(e),null===(i=Li())||void 0===i||i.unobserve(e),this.elementInfos=this.elementInfos.filter((t=>t.element!==e))}async handleAppVisibilityChanged(){await super.handleAppVisibilityChanged(),this.isAdaptiveStream&&Ni()&&this.updateVisibility()}updateVisibility(){const t=this.elementInfos.reduce(((e,t)=>Math.max(e,t.visibilityChangedAt||0)),0),i=this.elementInfos.some((e=>e.visible))&&!this.isInBackground;this.lastVisible!==i&&(!i&&Date.now()-t<100?setTimeout((()=>{this.updateVisibility()}),100):(this.lastVisible=i,this.emit(e.TrackEvent.VisibilityChanged,i,this)))}updateDimensions(){var t,i,n,r;let s=0,a=0;for(const e of this.elementInfos){const n=null!==(i=null===(t=this.adaptiveStreamSettings)||void 0===t?void 0:t.pixelDensity)&&void 0!==i?i:1,r="screen"===n?window.devicePixelRatio:n,o=e.element.clientWidth*r,c=e.element.clientHeight*r;o+c>s+a&&(s=o,a=c)}(null===(n=this.lastDimensions)||void 0===n?void 0:n.width)===s&&(null===(r=this.lastDimensions)||void 0===r?void 0:r.height)===a||(this.lastDimensions={width:s,height:a},this.emit(e.TrackEvent.VideoDimensionsChanged,this.lastDimensions,this))}}class gn extends Bi.exports.EventEmitter{constructor(t,i,n){super(),this.metadataMuted=!1,this.handleMuted=()=>{this.emit(e.TrackEvent.Muted)},this.handleUnmuted=()=>{this.emit(e.TrackEvent.Unmuted)},this.kind=t,this.trackSid=i,this.trackName=n,this.source=tn.Source.Unknown}setTrack(t){this.track&&(this.track.off(e.TrackEvent.Muted,this.handleMuted),this.track.off(e.TrackEvent.Unmuted,this.handleUnmuted)),this.track=t,t&&(t.on(e.TrackEvent.Muted,this.handleMuted),t.on(e.TrackEvent.Unmuted,this.handleUnmuted))}get isMuted(){return this.metadataMuted}get isEnabled(){return!0}get isSubscribed(){return void 0!==this.track}get audioTrack(){if(this.track instanceof un||this.track instanceof mn)return this.track}get videoTrack(){if(this.track instanceof ln||this.track instanceof vn)return this.track}updateInfo(e){this.trackSid=e.sid,this.trackName=e.name,this.source=tn.sourceFromProto(e.source),this.mimeType=e.mimeType,this.kind===tn.Kind.Video&&e.width>0&&(this.dimensions={width:e.width,height:e.height},this.simulcasted=e.simulcast),this.trackInfo=e}}!function(e){var t;(t=e.SubscriptionStatus||(e.SubscriptionStatus={})).Subscribed="subscribed",t.NotAllowed="not_allowed",t.Unsubscribed="unsubscribed"}(gn||(gn={}));class bn extends gn{constructor(t,i,n){super(t,i.sid,i.name),this.track=void 0,this.handleTrackEnded=()=>{this.emit(e.TrackEvent.Ended)},this.updateInfo(i),this.setTrack(n)}get isUpstreamPaused(){var e;return null===(e=this.track)||void 0===e?void 0:e.isUpstreamPaused}setTrack(t){this.track&&this.track.off(e.TrackEvent.Ended,this.handleTrackEnded),super.setTrack(t),t&&t.on(e.TrackEvent.Ended,this.handleTrackEnded)}get isMuted(){return this.track?this.track.isMuted:super.isMuted}get audioTrack(){return super.audioTrack}get videoTrack(){return super.videoTrack}async mute(){var e;return null===(e=this.track)||void 0===e?void 0:e.mute()}async unmute(){var e;return null===(e=this.track)||void 0===e?void 0:e.unmute()}async pauseUpstream(){var e;await(null===(e=this.track)||void 0===e?void 0:e.pauseUpstream())}async resumeUpstream(){var e;await(null===(e=this.track)||void 0===e?void 0:e.resumeUpstream())}}class kn{constructor(e,t,i,n){this.width=e,this.height=t,this.encoding={maxBitrate:i,maxFramerate:n}}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.width/this.height}}}var Sn;e.AudioPresets=void 0,(Sn=e.AudioPresets||(e.AudioPresets={})).telephone={maxBitrate:12e3},Sn.speech={maxBitrate:2e4},Sn.music={maxBitrate:32e3};const yn={h90:new kn(160,90,6e4,15),h180:new kn(320,180,12e4,15),h216:new kn(384,216,18e4,15),h360:new kn(640,360,3e5,20),h540:new kn(960,540,6e5,25),h720:new kn(1280,720,2e6,30),h1080:new kn(1920,1080,3e6,30),h1440:new kn(2560,1440,5e6,30),h2160:new kn(3840,2160,8e6,30),qvga:new kn(320,180,12e4,10),vga:new kn(640,360,3e5,20),qhd:new kn(960,540,6e5,25),hd:new kn(1280,720,2e6,30),fhd:new kn(1920,1080,3e6,30)},wn={h120:new kn(160,120,8e4,15),h180:new kn(240,180,1e5,15),h240:new kn(320,240,15e4,15),h360:new kn(480,360,225e3,20),h480:new kn(640,480,3e5,20),h540:new kn(720,540,45e4,25),h720:new kn(960,720,15e5,30),h1080:new kn(1440,1080,25e5,30),h1440:new kn(1920,1440,35e5,30),qvga:new kn(240,180,9e4,10),vga:new kn(480,360,225e3,20),qhd:new kn(720,540,45e4,25),hd:new kn(960,720,15e5,30),fhd:new kn(1440,1080,28e5,30)},Cn={h360fps3:new kn(640,360,2e5,3),h720fps5:new kn(1280,720,4e5,5),h720fps15:new kn(1280,720,1e6,15),h1080fps15:new kn(1920,1080,15e5,15),h1080fps30:new kn(1920,1080,3e6,30),vga:new kn(640,360,2e5,3),hd_8:new kn(1280,720,4e5,5),hd_15:new kn(1280,720,1e6,15),fhd_15:new kn(1920,1080,15e5,15),fhd_30:new kn(1920,1080,3e6,30)};e.ConnectionQuality=void 0,function(e){e.Excellent="excellent",e.Good="good",e.Poor="poor",e.Unknown="unknown"}(e.ConnectionQuality||(e.ConnectionQuality={}));class Tn extends Bi.exports.EventEmitter{constructor(t,i){super(),this.audioLevel=0,this.isSpeaking=!1,this._connectionQuality=e.ConnectionQuality.Unknown,this.sid=t,this.identity=i,this.audioTracks=new Map,this.videoTracks=new Map,this.tracks=new Map}getTracks(){return Array.from(this.tracks.values())}getTrack(e){if(e!==tn.Source.Unknown)for(const[,t]of this.tracks){if(t.source===e)return t;if(t.source===tn.Source.Unknown){if(e===tn.Source.Microphone&&t.kind===tn.Kind.Audio&&"screen"!==t.trackName)return t;if(e===tn.Source.Camera&&t.kind===tn.Kind.Video&&"screen"!==t.trackName)return t;if(e===tn.Source.ScreenShare&&t.kind===tn.Kind.Video&&"screen"===t.trackName)return t;if(e===tn.Source.ScreenShareAudio&&t.kind===tn.Kind.Audio&&"screen"===t.trackName)return t}}}getTrackByName(e){for(const[,t]of this.tracks)if(t.trackName===e)return t}get connectionQuality(){return this._connectionQuality}get isCameraEnabled(){var e;const t=this.getTrack(tn.Source.Camera);return!(null===(e=null==t?void 0:t.isMuted)||void 0===e||e)}get isMicrophoneEnabled(){var e;const t=this.getTrack(tn.Source.Microphone);return!(null===(e=null==t?void 0:t.isMuted)||void 0===e||e)}get isScreenShareEnabled(){return!!this.getTrack(tn.Source.ScreenShare)}get joinedAt(){return this.participantInfo?new Date(1e3*this.participantInfo.joinedAt):new Date}updateInfo(e){this.identity=e.identity,this.sid=e.sid,this.name=e.name,this.setMetadata(e.metadata),e.permission&&this.setPermissions(e.permission),this.participantInfo=e}setMetadata(t){const i=this.metadata!==t,n=this.metadata;this.metadata=t,i&&(this.emit(e.ParticipantEvent.MetadataChanged,n),this.emit(e.ParticipantEvent.ParticipantMetadataChanged,n))}setPermissions(e){var t,i,n,r,s;const a=e.canPublish!==(null===(t=this.permissions)||void 0===t?void 0:t.canPublish)||e.canSubscribe!==(null===(i=this.permissions)||void 0===i?void 0:i.canSubscribe)||e.canPublishData!==(null===(n=this.permissions)||void 0===n?void 0:n.canPublishData)||e.hidden!==(null===(r=this.permissions)||void 0===r?void 0:r.hidden)||e.recorder!==(null===(s=this.permissions)||void 0===s?void 0:s.recorder);return this.permissions=e,a}setIsSpeaking(t){t!==this.isSpeaking&&(this.isSpeaking=t,t&&(this.lastSpokeAt=new Date),this.emit(e.ParticipantEvent.IsSpeakingChanged,t))}setConnectionQuality(t){const i=this._connectionQuality;this._connectionQuality=function(t){switch(t){case We.EXCELLENT:return e.ConnectionQuality.Excellent;case We.GOOD:return e.ConnectionQuality.Good;case We.POOR:return e.ConnectionQuality.Poor;default:return e.ConnectionQuality.Unknown}}(t),i!==this._connectionQuality&&this.emit(e.ParticipantEvent.ConnectionQualityChanged,this._connectionQuality)}addTrackPublication(t){t.on(e.TrackEvent.Muted,(()=>{this.emit(e.ParticipantEvent.TrackMuted,t)})),t.on(e.TrackEvent.Unmuted,(()=>{this.emit(e.ParticipantEvent.TrackUnmuted,t)}));const i=t;switch(i.track&&(i.track.sid=t.trackSid),this.tracks.set(t.trackSid,t),t.kind){case tn.Kind.Audio:this.audioTracks.set(t.trackSid,t);break;case tn.Kind.Video:this.videoTracks.set(t.trackSid,t)}}}function En(e,t){switch(e.kind){case"audio":return new un(e,t);case"video":return new ln(e,t);default:throw new mi(`unsupported track type: ${e.kind}`)}}const Pn=Object.values(yn),Rn=Object.values(wn),On=Object.values(Cn),Nn=[yn.h180,yn.h360],Dn=[wn.h180,wn.h360],Un=["q","h","f"];function An(e,t,i,n){var r,a;let o=null==n?void 0:n.videoEncoding;e&&(o=null==n?void 0:n.screenShareEncoding);const c=null==n?void 0:n.simulcast;if(!o&&!c||!t||!i)return[{}];if(o||(o=function(e,t,i){const n=function(e,t,i){if(e)return On;const n=t>i?t/i:i/t;if(Math.abs(n-16/9)<Math.abs(n-4/3))return Pn;return Rn}(e,t,i);let{encoding:r}=n[0];const s=Math.max(t,i);for(let e=0;e<n.length;e+=1){const t=n[e];if(r=t.encoding,t.width>=s)break}return r}(e,t,i),s.debug("using video encoding",o)),!c)return[o];const d=new kn(t,i,o.maxBitrate,o.maxFramerate);let u,l=[];l=e?null!==(r=Mn(null==n?void 0:n.screenShareSimulcastLayers))&&void 0!==r?r:In(e,d):null!==(a=Mn(null==n?void 0:n.videoSimulcastLayers))&&void 0!==a?a:In(e,d);const h=l[0];l.length>1&&([,u]=l);const p=Math.max(t,i);return Ln(t,i,p>=960&&u?[h,u,d]:p>=480?[h,d]:[d])}function In(e,t){if(e)return i=t,[{scaleResolutionDownBy:2,fps:3}].map((e=>{var t;return new kn(Math.floor(i.width/e.scaleResolutionDownBy),Math.floor(i.height/e.scaleResolutionDownBy),Math.max(15e4,Math.floor(i.encoding.maxBitrate/(e.scaleResolutionDownBy**2*((null!==(t=i.encoding.maxFramerate)&&void 0!==t?t:30)/e.fps)))),e.fps)}));var i;const{width:n,height:r}=t,s=n>r?n/r:r/n;return Math.abs(s-16/9)<Math.abs(s-4/3)?Nn:Dn}function Ln(e,t,i){const n=[];return i.forEach(((i,r)=>{if(r>=Un.length)return;const s=Math.min(e,t),a=Un[r];n.push({rid:a,scaleResolutionDownBy:s/Math.min(i.width,i.height),maxBitrate:i.encoding.maxBitrate,maxFramerate:i.encoding.maxFramerate})})),n}function Mn(e){if(e)return e.sort(((e,t)=>{const{encoding:i}=e,{encoding:n}=t;return i.maxBitrate>n.maxBitrate?1:i.maxBitrate<n.maxBitrate?-1:i.maxBitrate===n.maxBitrate&&i.maxFramerate&&n.maxFramerate?i.maxFramerate>n.maxFramerate?1:-1:0}))}class _n extends gn{constructor(){super(...arguments),this._allowed=!0,this.disabled=!1,this.currentVideoQuality=e.VideoQuality.HIGH,this.handleEnded=t=>{this.emit(e.TrackEvent.Ended,t)},this.handleVisibilityChange=e=>{s.debug(`adaptivestream video visibility ${this.trackSid}, visible=${e}`,{trackSid:this.trackSid}),this.disabled=!e,this.emitTrackUpdate()},this.handleVideoDimensionsChange=e=>{s.debug(`adaptivestream video dimensions ${e.width}x${e.height}`,{trackSid:this.trackSid}),this.videoDimensions=e,this.emitTrackUpdate()}}setSubscribed(t){this.subscribed=t;const i={trackSids:[this.trackSid],subscribe:this.subscribed,participantTracks:[{participantSid:"",trackSids:[this.trackSid]}]};this.emit(e.TrackEvent.UpdateSubscription,i)}get subscriptionStatus(){return!1!==this.subscribed&&super.isSubscribed?this._allowed?gn.SubscriptionStatus.Subscribed:gn.SubscriptionStatus.NotAllowed:gn.SubscriptionStatus.Unsubscribed}get isSubscribed(){return!1!==this.subscribed&&(!!this._allowed&&super.isSubscribed)}get isEnabled(){return!this.disabled}setEnabled(e){this.isManualOperationAllowed()&&this.disabled!==!e&&(this.disabled=!e,this.emitTrackUpdate())}setVideoQuality(e){this.isManualOperationAllowed()&&this.currentVideoQuality!==e&&(this.currentVideoQuality=e,this.videoDimensions=void 0,this.emitTrackUpdate())}setVideoDimensions(e){var t,i;this.isManualOperationAllowed()&&((null===(t=this.videoDimensions)||void 0===t?void 0:t.width)===e.width&&(null===(i=this.videoDimensions)||void 0===i?void 0:i.height)===e.height||(this.track instanceof vn&&(this.videoDimensions=e),this.currentVideoQuality=void 0,this.emitTrackUpdate()))}get videoQuality(){return this.currentVideoQuality}setTrack(t){this.track&&(this.track.off(e.TrackEvent.VideoDimensionsChanged,this.handleVideoDimensionsChange),this.track.off(e.TrackEvent.VisibilityChanged,this.handleVisibilityChange),this.track.off(e.TrackEvent.Ended,this.handleEnded)),super.setTrack(t),t&&(t.sid=this.trackSid,t.on(e.TrackEvent.VideoDimensionsChanged,this.handleVideoDimensionsChange),t.on(e.TrackEvent.VisibilityChanged,this.handleVisibilityChange),t.on(e.TrackEvent.Ended,this.handleEnded))}updateInfo(e){var t;super.updateInfo(e),this.metadataMuted=e.muted,null===(t=this.track)||void 0===t||t.setMuted(e.muted)}isManualOperationAllowed(){return this.isAdaptiveStream?(s.warn("adaptive stream is enabled, cannot change track settings",{trackSid:this.trackSid}),!1):!!this.isSubscribed||(s.warn("cannot update track settings when not subscribed",{trackSid:this.trackSid}),!1)}get isAdaptiveStream(){return this.track instanceof vn&&this.track.isAdaptiveStream}emitTrackUpdate(){const t=Kt.fromPartial({trackSids:[this.trackSid],disabled:this.disabled});this.videoDimensions?(t.width=this.videoDimensions.width,t.height=this.videoDimensions.height):void 0!==this.currentVideoQuality?t.quality=this.currentVideoQuality:t.quality=e.VideoQuality.HIGH,this.emit(e.TrackEvent.UpdateSettings,t)}}class xn extends Tn{constructor(e,t,i){super(t,i||""),this.signalClient=e,this.tracks=new Map,this.audioTracks=new Map,this.videoTracks=new Map}static fromParticipantInfo(e,t){const i=new xn(e,t.sid,t.identity);return i.updateInfo(t),i}addTrackPublication(t){super.addTrackPublication(t),t.on(e.TrackEvent.UpdateSettings,(e=>{this.signalClient.sendUpdateTrackSettings(e)})),t.on(e.TrackEvent.UpdateSubscription,(e=>{e.participantTracks.forEach((e=>{e.participantSid=this.sid})),this.signalClient.sendUpdateSubscription(e)})),t.on(e.TrackEvent.Ended,(i=>{this.emit(e.ParticipantEvent.TrackUnsubscribed,i,t)}))}getTrack(e){const t=super.getTrack(e);if(t)return t}getTrackByName(e){const t=super.getTrackByName(e);if(t)return t}setVolume(e){const t=this.getTrack(tn.Source.Microphone);t&&t.track.setVolume(e)}getVolume(){const e=this.getTrack(tn.Source.Microphone);if(e)return e.track.getVolume()}addSubscribedMediaTrack(t,i,n,r,a,o){let c=this.getTrackPublication(i);if(c||i.startsWith("TR")||this.tracks.forEach((e=>{c||t.kind!==e.kind.toString()||(c=e)})),!c)return 0===o?(s.error("could not find published track",{participant:this.sid,trackSid:i}),void this.emit(e.ParticipantEvent.TrackSubscriptionFailed,i)):(void 0===o&&(o=20),void setTimeout((()=>{this.addSubscribedMediaTrack(t,i,n,r,a,o-1)}),150));let d;return d="video"===t.kind?new vn(t,i,r,a):new mn(t,i,r),d.source=c.source,d.isMuted=c.isMuted,d.setMediaStream(n),d.start(),c.setTrack(d),this.emit(e.ParticipantEvent.TrackSubscribed,d,c),c}get hasMetadata(){return!!this.participantInfo}getTrackPublication(e){return this.tracks.get(e)}updateInfo(t){const i=this.hasMetadata;super.updateInfo(t);const n=new Map,r=new Map;t.tracks.forEach((e=>{let t=this.getTrackPublication(e.sid);if(t)t.updateInfo(e);else{const i=tn.kindFromProto(e.type);if(!i)return;t=new _n(i,e.sid,e.name),t.updateInfo(e),r.set(e.sid,t),this.addTrackPublication(t)}n.set(e.sid,t)})),i&&r.forEach((t=>{this.emit(e.ParticipantEvent.TrackPublished,t)})),this.tracks.forEach((e=>{n.has(e.trackSid)||this.unpublishTrack(e.trackSid,!0)}))}unpublishTrack(t,i){const n=this.tracks.get(t);if(!n)return;switch(this.tracks.delete(t),n.kind){case tn.Kind.Audio:this.audioTracks.delete(t);break;case tn.Kind.Video:this.videoTracks.delete(t)}const{track:r}=n;if(r){const{isSubscribed:t}=n;r.stop(),n.setTrack(void 0),t&&this.emit(e.ParticipantEvent.TrackUnsubscribed,r,n)}i&&this.emit(e.ParticipantEvent.TrackUnpublished,n)}emit(e,...t){return s.trace("participant event",{participant:this.sid,event:e,args:t}),super.emit(e,...t)}}class Jn extends Tn{constructor(e,t,i,n){super(e,t),this.pendingPublishing=new Set,this.onTrackUnmuted=e=>{this.onTrackMuted(e,e.isUpstreamPaused)},this.onTrackMuted=(e,t)=>{void 0===t&&(t=!0),e.sid?this.engine.updateMuteStatus(e.sid,t):s.error("could not update mute status for unpublished track",e)},this.onTrackUpstreamPaused=e=>{s.debug("upstream paused"),this.onTrackMuted(e,!0)},this.onTrackUpstreamResumed=e=>{s.debug("upstream resumed"),this.onTrackMuted(e,e.isMuted)},this.handleSubscribedQualityUpdate=e=>{var t,i;if(!(null===(t=this.roomOptions)||void 0===t?void 0:t.dynacast))return;const n=this.videoTracks.get(e.trackSid);n?null===(i=n.videoTrack)||void 0===i||i.setPublishingLayers(e.subscribedQualities):s.warn("received subscribed quality update for unknown track",{method:"handleSubscribedQualityUpdate",sid:e.trackSid})},this.handleLocalTrackUnpublished=e=>{const t=this.tracks.get(e.trackSid);t?this.unpublishTrack(t.track):s.warn("received unpublished event for unknown track",{method:"handleLocalTrackUnpublished",trackSid:e.trackSid})},this.onTrackUnpublish=e=>{this.unpublishTrack(e)},this.audioTracks=new Map,this.videoTracks=new Map,this.tracks=new Map,this.engine=i,this.roomOptions=n,this.engine.client.onRemoteMuteChanged=(e,t)=>{const i=this.tracks.get(e);i&&i.track&&(t?i.mute():i.unmute())},this.engine.client.onSubscribedQualityUpdate=this.handleSubscribedQualityUpdate,this.engine.client.onLocalTrackUnpublished=this.handleLocalTrackUnpublished}get lastCameraError(){return this.cameraError}get lastMicrophoneError(){return this.microphoneError}getTrack(e){const t=super.getTrack(e);if(t)return t}getTrackByName(e){const t=super.getTrackByName(e);if(t)return t}setCameraEnabled(e){return this.setTrackEnabled(tn.Source.Camera,e)}setMicrophoneEnabled(e){return this.setTrackEnabled(tn.Source.Microphone,e)}setScreenShareEnabled(e){return this.setTrackEnabled(tn.Source.ScreenShare,e)}setPermissions(t){const i=this.permissions,n=super.setPermissions(t);return n&&i&&this.emit(e.ParticipantEvent.ParticipantPermissionsChanged,i),n}async setTrackEnabled(t,i){s.debug("setTrackEnabled",{source:t,enabled:i});let n=this.getTrack(t);if(i)if(n)await n.unmute();else{let i;if(this.pendingPublishing.has(t))return void s.info("skipping duplicate published source",{source:t});this.pendingPublishing.add(t);try{switch(t){case tn.Source.Camera:[i]=await this.createTracks({video:!0});break;case tn.Source.Microphone:[i]=await this.createTracks({audio:!0});break;case tn.Source.ScreenShare:[i]=await this.createScreenTracks({audio:!1});break;default:throw new mi(t)}n=await this.publishTrack(i)}catch(t){throw t instanceof Error&&!(t instanceof mi)&&this.emit(e.ParticipantEvent.MediaDevicesError,t),t}finally{this.pendingPublishing.delete(t)}}else n&&n.track&&(t===tn.Source.ScreenShare?n=this.unpublishTrack(n.track):await n.mute());return n}async enableCameraAndMicrophone(){if(!this.pendingPublishing.has(tn.Source.Camera)&&!this.pendingPublishing.has(tn.Source.Microphone)){this.pendingPublishing.add(tn.Source.Camera),this.pendingPublishing.add(tn.Source.Microphone);try{const e=await this.createTracks({audio:!0,video:!0});await Promise.all(e.map((e=>this.publishTrack(e))))}finally{this.pendingPublishing.delete(tn.Source.Camera),this.pendingPublishing.delete(tn.Source.Microphone)}}}async createTracks(e){var t,i;const n=cn(an(e,null===(t=this.roomOptions)||void 0===t?void 0:t.audioCaptureDefaults,null===(i=this.roomOptions)||void 0===i?void 0:i.videoCaptureDefaults));let r;try{r=await navigator.mediaDevices.getUserMedia(n)}catch(e){throw e instanceof Error&&(n.audio&&(this.microphoneError=e),n.video&&(this.cameraError=e)),e}return n.audio&&(this.microphoneError=void 0),n.video&&(this.cameraError=void 0),r.getTracks().map((t=>{const i="audio"===t.kind;let s;i?e.audio:e.video;const a=i?n.audio:n.video;"boolean"!=typeof a&&(s=a);const o=En(t,s);return o.kind===tn.Kind.Video?o.source=tn.Source.Camera:o.kind===tn.Kind.Audio&&(o.source=tn.Source.Microphone),o.mediaStream=r,o}))}async createScreenTracks(e){var t;void 0===e&&(e={}),void 0===e.resolution&&(e.resolution=Cn.h1080fps15.resolution);let i=!0;e.resolution&&(i={width:e.resolution.width,height:e.resolution.height,frameRate:e.resolution.frameRate});const n=await navigator.mediaDevices.getDisplayMedia({audio:null!==(t=e.audio)&&void 0!==t&&t,video:i}),r=n.getVideoTracks();if(0===r.length)throw new mi("no video track found");const s=new ln(r[0]);s.source=tn.Source.ScreenShare;const a=[s];if(n.getAudioTracks().length>0){const e=new un(n.getAudioTracks()[0]);e.source=tn.Source.ScreenShareAudio,a.push(e)}return a}async publishTrack(t,i){var n,r,a,o,c,d;const u={...null===(n=this.roomOptions)||void 0===n?void 0:n.publishDefaults,...i};if(t instanceof MediaStreamTrack)switch(t.kind){case"audio":t=new un(t);break;case"video":t=new ln(t);break;default:throw new mi(`unsupported MediaStreamTrack kind ${t.kind}`)}let l;if(this.tracks.forEach((e=>{e.track&&e.track===t&&(l=e)})),l)return l;u.source&&(t.source=u.source),u.stopMicTrackOnMute&&t instanceof un&&(t.stopOnMute=!0),t.source===tn.Source.ScreenShare&&Oi()&&(u.simulcast=!1),t.on(e.TrackEvent.Muted,this.onTrackMuted),t.on(e.TrackEvent.Unmuted,this.onTrackUnmuted),t.on(e.TrackEvent.Ended,this.onTrackUnpublish),t.on(e.TrackEvent.UpstreamPaused,this.onTrackUpstreamPaused),t.on(e.TrackEvent.UpstreamResumed,this.onTrackUpstreamResumed);const h=Jt.fromPartial({cid:t.mediaStreamTrack.id,name:null==i?void 0:i.name,type:tn.kindToProto(t.kind),muted:t.isMuted,source:tn.sourceToProto(t.source),disableDtx:!(null===(r=null==u?void 0:u.dtx)||void 0===r||r)});let p;if(t.kind===tn.Kind.Video){const i=t.mediaStreamTrack.getSettings(),n=null!==(a=i.width)&&void 0!==a?a:null===(o=t.dimensions)||void 0===o?void 0:o.width,r=null!==(c=i.height)&&void 0!==c?c:null===(d=t.dimensions)||void 0===d?void 0:d.height;h.width=null!=n?n:0,h.height=null!=r?r:0,p=An(t.source===tn.Source.ScreenShare,n,r,u),h.layers=function(t,i,n){return n?n.map((r=>{var s,a,o;const c=null!==(s=r.scaleResolutionDownBy)&&void 0!==s?s:1;let d=hn(null!==(a=r.rid)&&void 0!==a?a:"");return d===e.VideoQuality.UNRECOGNIZED&&1===n.length&&(d=e.VideoQuality.HIGH),{quality:d,width:t/c,height:i/c,bitrate:null!==(o=r.maxBitrate)&&void 0!==o?o:0,ssrc:0}})):[{quality:e.VideoQuality.HIGH,width:t,height:i,bitrate:0,ssrc:0}]}(h.width,h.height,p)}else t.kind===tn.Kind.Audio&&u.audioBitrate&&(p=[{maxBitrate:u.audioBitrate}]);const m=await this.engine.addTrack(h),f=new bn(t.kind,m,t);if(t.sid=m.sid,!this.engine.publisher)throw new vi("publisher is closed");s.debug(`publishing ${t.kind} with encodings`,{encodings:p,trackInfo:m});const v={direction:"sendonly"};p&&(v.sendEncodings=p);const g=this.engine.publisher.pc.addTransceiver(t.mediaStreamTrack,v);return this.engine.negotiate(),t.sender=g.sender,t instanceof ln?t.startMonitor(this.engine.client):t instanceof un&&t.startMonitor(),u.videoCodec&&this.setPreferredCodec(g,t.kind,u.videoCodec),this.addTrackPublication(f),this.emit(e.ParticipantEvent.LocalTrackPublished,f),f}unpublishTrack(t,i){var n,r;const a=this.getPublicationForTrack(t);if(s.debug("unpublishing track",{track:t,method:"unpublishTrack"}),!a||!a.track)return void s.warn("track was not unpublished because no publication was found",{track:t,method:"unpublishTrack"});(t=a.track).off(e.TrackEvent.Muted,this.onTrackMuted),t.off(e.TrackEvent.Unmuted,this.onTrackUnmuted),t.off(e.TrackEvent.Ended,this.onTrackUnpublish),t.off(e.TrackEvent.UpstreamPaused,this.onTrackUpstreamPaused),t.off(e.TrackEvent.UpstreamResumed,this.onTrackUpstreamResumed),void 0===i&&(i=null===(r=null===(n=this.roomOptions)||void 0===n?void 0:n.stopLocalTrackOnUnpublish)||void 0===r||r),i&&t.stop();const{mediaStreamTrack:o}=t;if(this.engine.publisher){this.engine.publisher.pc.getSenders().forEach((e=>{var t;if(e.track===o)try{null===(t=this.engine.publisher)||void 0===t||t.pc.removeTrack(e),this.engine.negotiate()}catch(e){s.warn("failed to remove track",{error:e,method:"unpublishTrack"})}}))}switch(this.tracks.delete(a.trackSid),a.kind){case tn.Kind.Audio:this.audioTracks.delete(a.trackSid);break;case tn.Kind.Video:this.videoTracks.delete(a.trackSid)}return this.emit(e.ParticipantEvent.LocalTrackUnpublished,a),a.setTrack(void 0),a}unpublishTracks(e){const t=[];return e.forEach((e=>{const i=this.unpublishTrack(e);i&&t.push(i)})),t}async publishData(e,t,i){const n=[];void 0!==i&&i.forEach((e=>{e instanceof xn?n.push(e.sid):n.push(e)}));const r={kind:t,user:{participantSid:this.sid,payload:e,destinationSids:n}};await this.engine.sendDataPacket(r,t)}setTrackSubscriptionPermissions(e,t=[]){this.engine.client.sendUpdateSubscriptionPermissions(e,t.map((e=>function(e){var t;if(!e.participantSid)throw new Error("Invalid track permission, missing participantSid");return{participantSid:e.participantSid,allTracks:null!==(t=e.allowAll)&&void 0!==t&&t,trackSids:e.allowedTrackSids||[]}}(e))))}getPublicationForTrack(e){let t;return this.tracks.forEach((i=>{const n=i.track;n&&(e instanceof MediaStreamTrack?(n instanceof un||n instanceof ln)&&n.mediaStreamTrack===e&&(t=i):e===n&&(t=i))})),t}setPreferredCodec(e,t,i){if(!("getCapabilities"in RTCRtpSender))return;const n=RTCRtpSender.getCapabilities(t);if(!n)return;const r=n.codecs.find((e=>{const t=e.mimeType.toLowerCase(),n=t===`video/${i}`;return"h264"===i&&e.sdpFmtpLine?n&&e.sdpFmtpLine.includes("profile-level-id=42e01f"):n||"audio/opus"===t}));r&&"setCodecPreferences"in e&&e.setCodecPreferences([r])}publishedTracksInfo(){const e=[];return this.tracks.forEach((t=>{void 0!==t.track&&e.push({cid:t.track.mediaStreamTrack.id,track:t.trackInfo})})),e}dataChannelsInfo(){const t=[],i=(e,i)=>{void 0!==(null==e?void 0:e.id)&&null!==e.id&&t.push({label:e.label,id:e.id,target:i})};return i(this.engine.dataChannelForKind(e.DataPacket_Kind.LOSSY),Ut.PUBLISHER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.RELIABLE),Ut.PUBLISHER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.LOSSY,!0),Ut.SUBSCRIBER),i(this.engine.dataChannelForKind(e.DataPacket_Kind.RELIABLE,!0),Ut.SUBSCRIBER),t}}class Bn{constructor(){this.queue=[],this.running=!1}enqueue(e){s.trace("enqueuing request to fire later"),this.queue.push(e)}dequeue(){const e=this.queue.shift();e&&e(),s.trace("firing request from queue")}async run(){if(!this.running){for(s.trace("start queue"),this.running=!0;this.running&&this.queue.length>0;)this.dequeue();this.running=!1,s.trace("queue finished")}}pause(){s.trace("pausing queue"),this.running=!1}reset(){s.trace("resetting queue"),this.running=!1,this.queue=[]}isRunning(){return this.running}isEmpty(){return 0===this.queue.length}}let jn=!0,Vn=!0;function Fn(e,t,i){const n=e.match(t);return n&&n.length>=i&&parseInt(n[i],10)}function qn(e,t,i){if(!e.RTCPeerConnection)return;const n=e.RTCPeerConnection.prototype,r=n.addEventListener;n.addEventListener=function(e,n){if(e!==t)return r.apply(this,arguments);const s=e=>{const t=i(e);t&&(n.handleEvent?n.handleEvent(t):n(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(n,s),r.apply(this,[e,s])};const s=n.removeEventListener;n.removeEventListener=function(e,i){if(e!==t||!this._eventMap||!this._eventMap[t])return s.apply(this,arguments);if(!this._eventMap[t].has(i))return s.apply(this,arguments);const n=this._eventMap[t].get(i);return this._eventMap[t].delete(i),0===this._eventMap[t].size&&delete this._eventMap[t],0===Object.keys(this._eventMap).length&&delete this._eventMap,s.apply(this,[e,n])},Object.defineProperty(n,"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 Qn(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(jn=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function Wn(e){return"boolean"!=typeof e?new Error("Argument type: "+typeof e+". Please use a boolean."):(Vn=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function Gn(){if("object"==typeof window){if(jn)return;"undefined"!=typeof console&&"function"==typeof console.log&&console.log.apply(console,arguments)}}function Kn(e,t){Vn&&console.warn(e+" is deprecated, please use "+t+" instead.")}function Hn(e){const t={browser:null,version:null};if(void 0===e||!e.navigator)return t.browser="Not a browser.",t;const{navigator:i}=e;if(i.mozGetUserMedia)t.browser="firefox",t.version=Fn(i.userAgent,/Firefox\/(\d+)\./,1);else if(i.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=Fn(i.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else{if(!e.RTCPeerConnection||!i.userAgent.match(/AppleWebKit\/(\d+)\./))return t.browser="Not a supported browser.",t;t.browser="safari",t.version=Fn(i.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}function zn(e){return"[object Object]"===Object.prototype.toString.call(e)}function Zn(e){return zn(e)?Object.keys(e).reduce((function(t,i){const n=zn(e[i]),r=n?Zn(e[i]):e[i],s=n&&!Object.keys(r).length;return void 0===r||s?t:Object.assign(t,{[i]:r})}),{}):e}function $n(e,t,i){t&&!i.has(t.id)&&(i.set(t.id,t),Object.keys(t).forEach((n=>{n.endsWith("Id")?$n(e,e.get(t[n]),i):n.endsWith("Ids")&&t[n].forEach((t=>{$n(e,e.get(t),i)}))})))}function Yn(e,t,i){const n=i?"outbound-rtp":"inbound-rtp",r=new Map;if(null===t)return r;const s=[];return e.forEach((e=>{"track"===e.type&&e.trackIdentifier===t.id&&s.push(e)})),s.forEach((t=>{e.forEach((i=>{i.type===n&&i.trackId===t.id&&$n(e,i,r)}))})),r}const Xn=Gn;function er(e,t){const i=e&&e.navigator;if(!i.mediaDevices)return;const n=function(e){if("object"!=typeof e||e.mandatory||e.optional)return e;const t={};return Object.keys(e).forEach((i=>{if("require"===i||"advanced"===i||"mediaSource"===i)return;const n="object"==typeof e[i]?e[i]:{ideal:e[i]};void 0!==n.exact&&"number"==typeof n.exact&&(n.min=n.max=n.exact);const r=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):"deviceId"===t?"sourceId":t};if(void 0!==n.ideal){t.optional=t.optional||[];let e={};"number"==typeof n.ideal?(e[r("min",i)]=n.ideal,t.optional.push(e),e={},e[r("max",i)]=n.ideal,t.optional.push(e)):(e[r("",i)]=n.ideal,t.optional.push(e))}void 0!==n.exact&&"number"!=typeof n.exact?(t.mandatory=t.mandatory||{},t.mandatory[r("",i)]=n.exact):["min","max"].forEach((e=>{void 0!==n[e]&&(t.mandatory=t.mandatory||{},t.mandatory[r(e,i)]=n[e])}))})),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},r=function(e,r){if(t.version>=61)return r(e);if((e=JSON.parse(JSON.stringify(e)))&&"object"==typeof e.audio){const t=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])};t((e=JSON.parse(JSON.stringify(e))).audio,"autoGainControl","googAutoGainControl"),t(e.audio,"noiseSuppression","googNoiseSuppression"),e.audio=n(e.audio)}if(e&&"object"==typeof e.video){let s=e.video.facingMode;s=s&&("object"==typeof s?s:{ideal:s});const a=t.version<66;if(s&&("user"===s.exact||"environment"===s.exact||"user"===s.ideal||"environment"===s.ideal)&&(!i.mediaDevices.getSupportedConstraints||!i.mediaDevices.getSupportedConstraints().facingMode||a)){let t;if(delete e.video.facingMode,"environment"===s.exact||"environment"===s.ideal?t=["back","rear"]:"user"!==s.exact&&"user"!==s.ideal||(t=["front"]),t)return i.mediaDevices.enumerateDevices().then((i=>{let a=(i=i.filter((e=>"videoinput"===e.kind))).find((e=>t.some((t=>e.label.toLowerCase().includes(t)))));return!a&&i.length&&t.includes("back")&&(a=i[i.length-1]),a&&(e.video.deviceId=s.exact?{exact:a.deviceId}:{ideal:a.deviceId}),e.video=n(e.video),Xn("chrome: "+JSON.stringify(e)),r(e)}))}e.video=n(e.video)}return Xn("chrome: "+JSON.stringify(e)),r(e)},s=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(i.getUserMedia=function(e,t,n){r(e,(e=>{i.webkitGetUserMedia(e,t,(e=>{n&&n(s(e))}))}))}.bind(i),i.mediaDevices.getUserMedia){const e=i.mediaDevices.getUserMedia.bind(i.mediaDevices);i.mediaDevices.getUserMedia=function(t){return r(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(s(e))))))}}}function tr(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function ir(e){if("object"==typeof e&&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});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",(i=>{let n;n=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.track.id)):{track:i.track};const r=new Event("track");r.track=i.track,r.receiver=n,r.transceiver={receiver:n},r.streams=[t.stream],this.dispatchEvent(r)})),t.stream.getTracks().forEach((i=>{let n;n=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find((e=>e.track&&e.track.id===i.id)):{track:i};const r=new Event("track");r.track=i,r.receiver=n,r.transceiver={receiver:n},r.streams=[t.stream],this.dispatchEvent(r)}))},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else qn(e,"track",(e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e)))}function nr(e){if("object"==typeof e&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){const t=function(e,t){return{track:t,get dtmf(){return void 0===this._dtmf&&("audio"===t.kind?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,n){let r=i.apply(this,arguments);return r||(r=t(this,e),this._senders.push(r)),r};const n=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){n.apply(this,arguments);const t=this._senders.indexOf(e);-1!==t&&this._senders.splice(t,1)}}const i=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],i.apply(this,[e]),e.getTracks().forEach((e=>{this._senders.push(t(this,e))}))};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],n.apply(this,[e]),e.getTracks().forEach((e=>{const t=this._senders.find((t=>t.track===e));t&&this._senders.splice(this._senders.indexOf(t),1)}))}}else if("object"==typeof e&&e.RTCPeerConnection&&"getSenders"in e.RTCPeerConnection.prototype&&"createDTMFSender"in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!("dtmf"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e},Object.defineProperty(e.RTCRtpSender.prototype,"dtmf",{get(){return void 0===this._dtmf&&("audio"===this.track.kind?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function rr(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,i,n]=arguments;if(arguments.length>0&&"function"==typeof e)return t.apply(this,arguments);if(0===t.length&&(0===arguments.length||"function"!=typeof e))return t.apply(this,[]);const r=function(e){const t={};return e.result().forEach((e=>{const i={id:e.id,timestamp:e.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[e.type]||e.type};e.names().forEach((t=>{i[t]=e.stat(t)})),t[i.id]=i})),t},s=function(e){return new Map(Object.keys(e).map((t=>[t,e[t]])))};if(arguments.length>=2){const n=function(e){i(s(r(e)))};return t.apply(this,[n,e])}return new Promise(((e,i)=>{t.apply(this,[function(t){e(s(r(t)))},i])})).then(i,n)}}function sr(e){if(!("object"==typeof e&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!("getStats"in e.RTCRtpSender.prototype)){const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>Yn(t,e.track,!0)))}}if(!("getStats"in e.RTCRtpReceiver.prototype)){const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),qn(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){const e=this;return this._pc.getStats().then((t=>Yn(t,e.track,!1)))}}if(!("getStats"in e.RTCRtpSender.prototype)||!("getStats"in e.RTCRtpReceiver.prototype))return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){const e=arguments[0];let t,i,n;return this.getSenders().forEach((i=>{i.track===e&&(t?n=!0:t=i)})),this.getReceivers().forEach((t=>(t.track===e&&(i?n=!0:i=t),t.track===e))),n||t&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):t?t.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return t.apply(this,arguments)}}function ar(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map((e=>this._shimmedLocalStreams[e][0]))};const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,i){if(!i)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const n=t.apply(this,arguments);return this._shimmedLocalStreams[i.id]?-1===this._shimmedLocalStreams[i.id].indexOf(n)&&this._shimmedLocalStreams[i.id].push(n):this._shimmedLocalStreams[i.id]=[i,n],n};const i=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")}));const t=this.getSenders();i.apply(this,arguments);const n=this.getSenders().filter((e=>-1===t.indexOf(e)));this._shimmedLocalStreams[e.id]=[e].concat(n)};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],n.apply(this,arguments)};const r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach((t=>{const i=this._shimmedLocalStreams[t].indexOf(e);-1!==i&&this._shimmedLocalStreams[t].splice(i,1),1===this._shimmedLocalStreams[t].length&&delete this._shimmedLocalStreams[t]})),r.apply(this,arguments)}}function or(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return ar(e);const i=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){const e=i.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map((e=>this._reverseStreams[e.id]))};const n=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]){const i=new e.MediaStream(t.getTracks());this._streams[t.id]=i,this._reverseStreams[i.id]=t,t=i}n.apply(this,[t])};const r=e.RTCPeerConnection.prototype.removeStream;function s(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const n=e._reverseStreams[t],r=e._streams[n.id];i=i.replace(new RegExp(r.id,"g"),n.id)})),new RTCSessionDescription({type:t.type,sdp:i})}function a(e,t){let i=t.sdp;return Object.keys(e._reverseStreams||[]).forEach((t=>{const n=e._reverseStreams[t],r=e._streams[n.id];i=i.replace(new RegExp(n.id,"g"),r.id)})),new RTCSessionDescription({type:t.type,sdp:i})}e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},r.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,i){if("closed"===this.signalingState)throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const n=[].slice.call(arguments,1);if(1!==n.length||!n[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");const r=this.getSenders().find((e=>e.track===t));if(r)throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const s=this._streams[i.id];if(s)s.addTrack(t),Promise.resolve().then((()=>{this.dispatchEvent(new Event("negotiationneeded"))}));else{const n=new e.MediaStream([t]);this._streams[i.id]=n,this._reverseStreams[n.id]=i,this.addStream(n)}return this.getSenders().find((e=>e.track===t))},["createOffer","createAnswer"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){const e=arguments;return arguments.length&&"function"==typeof arguments[0]?i.apply(this,[t=>{const i=s(this,t);e[0].apply(null,[i])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):i.apply(this,arguments).then((e=>s(this,e)))}};e.RTCPeerConnection.prototype[t]=n[t]}));const o=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return arguments.length&&arguments[0].type?(arguments[0]=a(this,arguments[0]),o.apply(this,arguments)):o.apply(this,arguments)};const c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const e=c.get.apply(this);return""===e.type?e:s(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if("closed"===this.signalingState)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");let t;this._streams=this._streams||{},Object.keys(this._streams).forEach((i=>{this._streams[i].getTracks().find((t=>e.track===t))&&(t=this._streams[i])})),t&&(1===t.getTracks().length?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event("negotiationneeded")))}}function cr(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=n[t]}))}function dr(e,t){qn(e,"negotiationneeded",(e=>{const i=e.target;if(!(t.version<72||i.getConfiguration&&"plan-b"===i.getConfiguration().sdpSemantics)||"stable"===i.signalingState)return e}))}var ur=Object.freeze({__proto__:null,shimMediaStream:tr,shimOnTrack:ir,shimGetSendersWithDtmf:nr,shimGetStats:rr,shimSenderReceiverGetStats:sr,shimAddTrackRemoveTrackWithNative:ar,shimAddTrackRemoveTrack:or,shimPeerConnection:cr,fixNegotiationNeeded:dr,shimGetUserMedia:er,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&("function"==typeof t?e.navigator.mediaDevices.getDisplayMedia=function(i){return t(i).then((t=>{const n=i.video&&i.video.width,r=i.video&&i.video.height,s=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:t,maxFrameRate:s||3}},n&&(i.video.mandatory.maxWidth=n),r&&(i.video.mandatory.maxHeight=r),e.navigator.mediaDevices.getUserMedia(i)}))}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}});function lr(e,t){const i=e&&e.navigator,n=e&&e.MediaStreamTrack;if(i.getUserMedia=function(e,t,n){Kn("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),i.mediaDevices.getUserMedia(e).then(t,n)},!(t.version>55&&"autoGainControl"in i.mediaDevices.getSupportedConstraints())){const e=function(e,t,i){t in e&&!(i in e)&&(e[i]=e[t],delete e[t])},t=i.mediaDevices.getUserMedia.bind(i.mediaDevices);if(i.mediaDevices.getUserMedia=function(i){return"object"==typeof i&&"object"==typeof i.audio&&(i=JSON.parse(JSON.stringify(i)),e(i.audio,"autoGainControl","mozAutoGainControl"),e(i.audio,"noiseSuppression","mozNoiseSuppression")),t(i)},n&&n.prototype.getSettings){const t=n.prototype.getSettings;n.prototype.getSettings=function(){const i=t.apply(this,arguments);return e(i,"mozAutoGainControl","autoGainControl"),e(i,"mozNoiseSuppression","noiseSuppression"),i}}if(n&&n.prototype.applyConstraints){const t=n.prototype.applyConstraints;n.prototype.applyConstraints=function(i){return"audio"===this.kind&&"object"==typeof i&&(i=JSON.parse(JSON.stringify(i)),e(i,"autoGainControl","mozAutoGainControl"),e(i,"noiseSuppression","mozNoiseSuppression")),t.apply(this,[i])}}}}function hr(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function pr(e,t){if("object"!=typeof e||!e.RTCPeerConnection&&!e.mozRTCPeerConnection)return;!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(t){const i=e.RTCPeerConnection.prototype[t],n={[t](){return arguments[0]=new("addIceCandidate"===t?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=n[t]}));const i={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[e,r,s]=arguments;return n.apply(this,[e||null]).then((e=>{if(t.version<53&&!r)try{e.forEach((e=>{e.type=i[e.type]||e.type}))}catch(t){if("TypeError"!==t.name)throw t;e.forEach(((t,n)=>{e.set(n,Object.assign({},t,{type:i[t.type]||t.type}))}))}return e})).then(r,s)}}function mr(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpSender.prototype)return;const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e});const i=e.RTCPeerConnection.prototype.addTrack;i&&(e.RTCPeerConnection.prototype.addTrack=function(){const e=i.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 fr(e){if("object"!=typeof e||!e.RTCPeerConnection||!e.RTCRtpSender)return;if(e.RTCRtpSender&&"getStats"in e.RTCRtpReceiver.prototype)return;const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const e=t.apply(this,[]);return e.forEach((e=>e._pc=this)),e}),qn(e,"track",(e=>(e.receiver._pc=e.srcElement,e))),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function vr(e){e.RTCPeerConnection&&!("removeStream"in e.RTCPeerConnection.prototype)&&(e.RTCPeerConnection.prototype.removeStream=function(e){Kn("removeStream","removeTrack"),this.getSenders().forEach((t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)}))})}function gr(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function br(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const e=arguments[1],i=e&&"sendEncodings"in e;i&&e.sendEncodings.forEach((e=>{if("rid"in e){if(!/^[a-z0-9]{0,16}$/i.test(e.rid))throw new TypeError("Invalid RID value provided.")}if("scaleResolutionDownBy"in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in e&&!(parseFloat(e.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")}));const n=t.apply(this,arguments);if(i){const{sender:t}=n,i=t.getParameters();(!("encodings"in i)||1===i.encodings.length&&0===Object.keys(i.encodings[0]).length)&&(i.encodings=e.sendEncodings,t.sendEncodings=e.sendEncodings,this.setParametersPromises.push(t.setParameters(i).then((()=>{delete t.sendEncodings})).catch((()=>{delete t.sendEncodings}))))}return n})}function kr(e){if("object"!=typeof e||!e.RTCRtpSender)return;const t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){const e=t.apply(this,arguments);return"encodings"in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function Sr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}function yr(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then((()=>t.apply(this,arguments))).finally((()=>{this.setParametersPromises=[]})):t.apply(this,arguments)}}var wr=Object.freeze({__proto__:null,shimOnTrack:hr,shimPeerConnection:pr,shimSenderGetStats:mr,shimReceiverGetStats:fr,shimRemoveStream:vr,shimRTCDataChannel:gr,shimAddTransceiver:br,shimGetParameters:kr,shimCreateOffer:Sr,shimCreateAnswer:yr,shimGetUserMedia:lr,shimGetDisplayMedia:function(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(i){if(!i||!i.video){const e=new DOMException("getDisplayMedia without video constraints is undefined");return e.name="NotFoundError",e.code=8,Promise.reject(e)}return!0===i.video?i.video={mediaSource:t}:i.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(i)})}});function Cr(e){if("object"==typeof e&&e.RTCPeerConnection){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in e.RTCPeerConnection.prototype)){const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||(this._localStreams=[]),this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach((i=>t.call(this,i,e))),e.getVideoTracks().forEach((i=>t.call(this,i,e)))},e.RTCPeerConnection.prototype.addTrack=function(e){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];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||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(-1===t)return;this._localStreams.splice(t,1);const i=e.getTracks();this.getSenders().forEach((e=>{i.includes(e.track)&&this.removeTrack(e)}))})}}function Tr(e){if("object"==typeof e&&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=[]),this._remoteStreams.includes(e))return;this._remoteStreams.push(e);const t=new Event("addstream");t.stream=e,this.dispatchEvent(t)}))})}});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){const e=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(t){t.streams.forEach((t=>{if(e._remoteStreams||(e._remoteStreams=[]),e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);const i=new Event("addstream");i.stream=t,e.dispatchEvent(i)}))}),t.apply(e,arguments)}}}function Er(e){if("object"!=typeof e||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,i=t.createOffer,n=t.createAnswer,r=t.setLocalDescription,s=t.setRemoteDescription,a=t.addIceCandidate;t.createOffer=function(e,t){const n=arguments.length>=2?arguments[2]:arguments[0],r=i.apply(this,[n]);return t?(r.then(e,t),Promise.resolve()):r},t.createAnswer=function(e,t){const i=arguments.length>=2?arguments[2]:arguments[0],r=n.apply(this,[i]);return t?(r.then(e,t),Promise.resolve()):r};let o=function(e,t,i){const n=r.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n};t.setLocalDescription=o,o=function(e,t,i){const n=s.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n},t.setRemoteDescription=o,o=function(e,t,i){const n=a.apply(this,[e]);return i?(n.then(t,i),Promise.resolve()):n},t.addIceCandidate=o}function Pr(e){const t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){const e=t.mediaDevices,i=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>i(Rr(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,i,n){t.mediaDevices.getUserMedia(e).then(i,n)}.bind(t))}function Rr(e){return e&&void 0!==e.video?Object.assign({},e,{video:Zn(e.video)}):e}function Or(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,i){if(e&&e.iceServers){const t=[];for(let i=0;i<e.iceServers.length;i++){let n=e.iceServers[i];!n.hasOwnProperty("urls")&&n.hasOwnProperty("url")?(Kn("RTCIceServer.url","RTCIceServer.urls"),n=JSON.parse(JSON.stringify(n)),n.urls=n.url,delete n.url,t.push(n)):t.push(e.iceServers[i])}e.iceServers=t}return new t(e,i)},e.RTCPeerConnection.prototype=t.prototype,"generateCertificate"in t&&Object.defineProperty(e.RTCPeerConnection,"generateCertificate",{get:()=>t.generateCertificate})}function Nr(e){"object"==typeof e&&e.RTCTrackEvent&&"receiver"in e.RTCTrackEvent.prototype&&!("transceiver"in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Dr(e){const t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){void 0!==e.offerToReceiveAudio&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);const t=this.getTransceivers().find((e=>"audio"===e.receiver.track.kind));!1===e.offerToReceiveAudio&&t?"sendrecv"===t.direction?t.setDirection?t.setDirection("sendonly"):t.direction="sendonly":"recvonly"===t.direction&&(t.setDirection?t.setDirection("inactive"):t.direction="inactive"):!0!==e.offerToReceiveAudio||t||this.addTransceiver("audio",{direction:"recvonly"}),void 0!==e.offerToReceiveVideo&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);const i=this.getTransceivers().find((e=>"video"===e.receiver.track.kind));!1===e.offerToReceiveVideo&&i?"sendrecv"===i.direction?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":"recvonly"===i.direction&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):!0!==e.offerToReceiveVideo||i||this.addTransceiver("video",{direction:"recvonly"})}return t.apply(this,arguments)}}function Ur(e){"object"!=typeof e||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var Ar=Object.freeze({__proto__:null,shimLocalStreamsAPI:Cr,shimRemoteStreamsAPI:Tr,shimCallbacksAPI:Er,shimGetUserMedia:Pr,shimConstraints:Rr,shimRTCIceServerUrls:Or,shimTrackEventTransceiver:Nr,shimCreateOfferLegacy:Dr,shimAudioContext:Ur}),Ir={exports:{}};!function(e){const t={generateIdentifier:function(){return Math.random().toString(36).substr(2,10)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((e=>e.trim()))},t.splitSections=function(e){return e.split("\nm=").map(((e,t)=>(t>0?"m="+e:e).trim()+"\r\n"))},t.getDescription=function(e){const i=t.splitSections(e);return i&&i[0]},t.getMediaSections=function(e){const i=t.splitSections(e);return i.shift(),i},t.matchPrefix=function(e,i){return t.splitLines(e).filter((e=>0===e.indexOf(i)))},t.parseCandidate=function(e){let t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");const i={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":i.relatedAddress=t[e+1];break;case"rport":i.relatedPort=parseInt(t[e+1],10);break;case"tcptype":i.tcpType=t[e+1];break;case"ufrag":i.ufrag=t[e+1],i.usernameFragment=t[e+1];break;default:void 0===i[t[e]]&&(i[t[e]]=t[e+1])}return i},t.writeCandidate=function(e){const t=[];t.push(e.foundation);const i=e.component;"rtp"===i?t.push(1):"rtcp"===i?t.push(2):t.push(i),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);const n=e.type;return t.push("typ"),t.push(n),"host"!==n&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(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.substr(14).split(" ")},t.parseRtpMap=function(e){let t=e.substr(9).split(" ");const i={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),i.name=t[0],i.clockRate=parseInt(t[1],10),i.channels=3===t.length?parseInt(t[2],10):1,i.numChannels=i.channels,i},t.writeRtpMap=function(e){let t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);const i=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==i?"/"+i:"")+"\r\n"},t.parseExtmap=function(e){const t=e.substr(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1]}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+"\r\n"},t.parseFmtp=function(e){const t={};let i;const n=e.substr(e.indexOf(" ")+1).split(";");for(let e=0;e<n.length;e++)i=n[e].trim().split("="),t[i[0].trim()]=i[1];return t},t.writeFmtp=function(e){let t="",i=e.payloadType;if(void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){const n=[];Object.keys(e.parameters).forEach((t=>{void 0!==e.parameters[t]?n.push(t+"="+e.parameters[t]):n.push(t)})),t+="a=fmtp:"+i+" "+n.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){const t=e.substr(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){let t="",i=e.payloadType;return void 0!==e.preferredPayloadType&&(i=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((e=>{t+="a=rtcp-fb:"+i+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){const t=e.indexOf(" "),i={ssrc:parseInt(e.substr(7,t-7),10)},n=e.indexOf(":",t);return n>-1?(i.attribute=e.substr(t+1,n-t-1),i.value=e.substr(n+1)):i.attribute=e.substr(t+1),i},t.parseSsrcGroup=function(e){const t=e.substr(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((e=>parseInt(e,10)))}},t.getMid=function(e){const i=t.matchPrefix(e,"a=mid:")[0];if(i)return i.substr(6)},t.parseFingerprint=function(e){const t=e.substr(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,i){return{role:"auto",fingerprints:t.matchPrefix(e+i,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let i="a=setup:"+t+"\r\n";return e.fingerprints.forEach((e=>{i+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),i},t.parseCryptoLine=function(e){const t=e.substr(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+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;const t=e.substr(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,i){return t.matchPrefix(e+i,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,i){const n=t.matchPrefix(e+i,"a=ice-ufrag:")[0],r=t.matchPrefix(e+i,"a=ice-pwd:")[0];return n&&r?{usernameFragment:n.substr(12),password:r.substr(10)}:null},t.writeIceParameters=function(e){let t="a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n";return e.iceLite&&(t+="a=ice-lite\r\n"),t},t.parseRtpParameters=function(e){const i={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},n=t.splitLines(e)[0].split(" ");for(let r=3;r<n.length;r++){const s=n[r],a=t.matchPrefix(e,"a=rtpmap:"+s+" ")[0];if(a){const n=t.parseRtpMap(a),r=t.matchPrefix(e,"a=fmtp:"+s+" ");switch(n.parameters=r.length?t.parseFmtp(r[0]):{},n.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+s+" ").map(t.parseRtcpFb),i.codecs.push(n),n.name.toUpperCase()){case"RED":case"ULPFEC":i.fecMechanisms.push(n.name.toUpperCase())}}}return t.matchPrefix(e,"a=extmap:").forEach((e=>{i.headerExtensions.push(t.parseExtmap(e))})),i},t.writeRtpDescription=function(e,i){let n="";n+="m="+e+" ",n+=i.codecs.length>0?"9":"0",n+=" UDP/TLS/RTP/SAVPF ",n+=i.codecs.map((e=>void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType)).join(" ")+"\r\n",n+="c=IN IP4 0.0.0.0\r\n",n+="a=rtcp:9 IN IP4 0.0.0.0\r\n",i.codecs.forEach((e=>{n+=t.writeRtpMap(e),n+=t.writeFmtp(e),n+=t.writeRtcpFb(e)}));let r=0;return i.codecs.forEach((e=>{e.maxptime>r&&(r=e.maxptime)})),r>0&&(n+="a=maxptime:"+r+"\r\n"),i.headerExtensions&&i.headerExtensions.forEach((e=>{n+=t.writeExtmap(e)})),n},t.parseRtpEncodingParameters=function(e){const i=[],n=t.parseRtpParameters(e),r=-1!==n.fecMechanisms.indexOf("RED"),s=-1!==n.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute)),o=a.length>0&&a[0].ssrc;let c;const d=t.matchPrefix(e,"a=ssrc-group:FID").map((e=>e.substr(17).split(" ").map((e=>parseInt(e,10)))));d.length>0&&d[0].length>1&&d[0][0]===o&&(c=d[0][1]),n.codecs.forEach((e=>{if("RTX"===e.name.toUpperCase()&&e.parameters.apt){let t={ssrc:o,codecPayloadType:parseInt(e.parameters.apt,10)};o&&c&&(t.rtx={ssrc:c}),i.push(t),r&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:o,mechanism:s?"red+ulpfec":"red"},i.push(t))}})),0===i.length&&o&&i.push({ssrc:o});let u=t.matchPrefix(e,"b=");return u.length&&(u=0===u[0].indexOf("b=TIAS:")?parseInt(u[0].substr(7),10):0===u[0].indexOf("b=AS:")?1e3*parseInt(u[0].substr(5),10)*.95-16e3:void 0,i.forEach((e=>{e.maxBitrate=u}))),i},t.parseRtcpParameters=function(e){const i={},n=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute))[0];n&&(i.cname=n.value,i.ssrc=n.ssrc);const r=t.matchPrefix(e,"a=rtcp-rsize");i.reducedSize=r.length>0,i.compound=0===r.length;const s=t.matchPrefix(e,"a=rtcp-mux");return i.mux=s.length>0,i},t.writeRtcpParameters=function(e){let t="";return e.reducedSize&&(t+="a=rtcp-rsize\r\n"),e.mux&&(t+="a=rtcp-mux\r\n"),void 0!==e.ssrc&&e.cname&&(t+="a=ssrc:"+e.ssrc+" cname:"+e.cname+"\r\n"),t},t.parseMsid=function(e){let i;const n=t.matchPrefix(e,"a=msid:");if(1===n.length)return i=n[0].substr(7).split(" "),{stream:i[0],track:i[1]};const r=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return r.length>0?(i=r[0].value.split(" "),{stream:i[0],track:i[1]}):void 0},t.parseSctpDescription=function(e){const i=t.parseMLine(e),n=t.matchPrefix(e,"a=max-message-size:");let r;n.length>0&&(r=parseInt(n[0].substr(19),10)),isNaN(r)&&(r=65536);const s=t.matchPrefix(e,"a=sctp-port:");if(s.length>0)return{port:parseInt(s[0].substr(12),10),protocol:i.fmt,maxMessageSize:r};const a=t.matchPrefix(e,"a=sctpmap:");if(a.length>0){const e=a[0].substr(10).split(" ");return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:r}}},t.writeSctpDescription=function(e,t){let i=[];return i="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&i.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),i.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,21)},t.writeSessionBoilerplate=function(e,i,n){let r;const s=void 0!==i?i:2;r=e||t.generateSessionId();return"v=0\r\no="+(n||"thisisadapterortc")+" "+r+" "+s+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.getDirection=function(e,i){const n=t.splitLines(e);for(let e=0;e<n.length;e++)switch(n[e]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return n[e].substr(2)}return i?t.getDirection(i):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substr(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){const i=t.splitLines(e)[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},t.parseOLine=function(e){const i=t.matchPrefix(e,"o=")[0].substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;const i=t.splitLines(e);for(let e=0;e<i.length;e++)if(i[e].length<2||"="!==i[e].charAt(1))return!1;return!0},e.exports=t}(Ir);var Lr=Ir.exports,Mr=t({__proto__:null,default:Lr},[Ir.exports]);function _r(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)return;const t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"==typeof e&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){const i=new t(e),n=Lr.parseCandidate(e.candidate),r=Object.assign(i,n);return r.toJSON=function(){return{candidate:r.candidate,sdpMid:r.sdpMid,sdpMLineIndex:r.sdpMLineIndex,usernameFragment:r.usernameFragment}},r}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,qn(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function xr(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return void 0===this._sctp?null:this._sctp}});const i=function(e){if(!e||!e.sdp)return!1;const t=Lr.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=Lr.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")}))},n=function(e){const t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;const i=parseInt(t[1],10);return i!=i?-1:i},r=function(e){let i=65536;return"firefox"===t.browser&&(i=t.version<57?-1===e?16384:2147483637:t.version<60?57===t.version?65535:65536:2147483637),i},s=function(e,i){let n=65536;"firefox"===t.browser&&57===t.version&&(n=65535);const r=Lr.matchPrefix(e.sdp,"a=max-message-size:");return r.length>0?n=parseInt(r[0].substr(19),10):"firefox"===t.browser&&-1!==i&&(n=2147483637),n},a=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===t.browser&&t.version>=76){const{sdpSemantics:e}=this.getConfiguration();"plan-b"===e&&Object.defineProperty(this,"sctp",{get(){return void 0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(i(arguments[0])){const e=n(arguments[0]),t=r(e),i=s(arguments[0],e);let a;a=0===t&&0===i?Number.POSITIVE_INFINITY:0===t||0===i?Math.max(t,i):Math.min(t,i);const o={};Object.defineProperty(o,"maxMessageSize",{get:()=>a}),this._sctp=o}return a.apply(this,arguments)}}function Jr(e){if(!e.RTCPeerConnection||!("createDataChannel"in e.RTCPeerConnection.prototype))return;function t(e,t){const i=e.send;e.send=function(){const n=arguments[0],r=n.length||n.size||n.byteLength;if("open"===e.readyState&&t.sctp&&r>t.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");return i.apply(e,arguments)}}const i=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const e=i.apply(this,arguments);return t(e,this),e},qn(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function Br(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const 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=>{const i=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{const t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;const i=new Event("connectionstatechange",e);t.dispatchEvent(i)}return e},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),i.apply(this,arguments)}}))}function jr(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t.version>=605)return;const i=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&-1!==t.sdp.indexOf("\na=extmap-allow-mixed")){const i=t.sdp.split("\n").filter((e=>"a=extmap-allow-mixed"!==e.trim())).join("\n");e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:i}):t.sdp=i}return i.apply(this,arguments)}}function Vr(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.addIceCandidate;i&&0!==i.length&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?("chrome"===t.browser&&t.version<78||"firefox"===t.browser&&t.version<68||"safari"===t.browser)&&arguments[0]&&""===arguments[0].candidate?Promise.resolve():i.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Fr(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const i=e.RTCPeerConnection.prototype.setLocalDescription;i&&0!==i.length&&(e.RTCPeerConnection.prototype.setLocalDescription=function(){let e=arguments[0]||{};if("object"!=typeof e||e.type&&e.sdp)return i.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"}if(e.sdp||"offer"!==e.type&&"answer"!==e.type)return i.apply(this,[e]);const t="offer"===e.type?this.createOffer:this.createAnswer;return t.apply(this).then((e=>i.apply(this,[e])))})}var qr=Object.freeze({__proto__:null,shimRTCIceCandidate:_r,shimMaxMessageSize:xr,shimSendThrowTypeError:Jr,shimConnectionState:Br,removeExtmapAllowMixed:jr,shimAddIceCandidateNullOrEmpty:Vr,shimParameterlessSetLocalDescription:Fr});!function(){let{window:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{shimChrome:!0,shimFirefox:!0,shimSafari:!0};const i=Gn,n=Hn(e),r={browserDetails:n,commonShim:qr,extractVersion:Fn,disableLog:Qn,disableWarnings:Wn,sdp:Mr};switch(n.browser){case"chrome":if(!ur||!cr||!t.shimChrome)return i("Chrome shim is not included in this adapter release."),r;if(null===n.version)return i("Chrome shim can not determine version, not shimming."),r;i("adapter.js shimming chrome."),r.browserShim=ur,Vr(e,n),Fr(e),er(e,n),tr(e),cr(e,n),ir(e),or(e,n),nr(e),rr(e),sr(e),dr(e,n),_r(e),Br(e),xr(e,n),Jr(e),jr(e,n);break;case"firefox":if(!wr||!pr||!t.shimFirefox)return i("Firefox shim is not included in this adapter release."),r;i("adapter.js shimming firefox."),r.browserShim=wr,Vr(e,n),Fr(e),lr(e,n),pr(e,n),hr(e),vr(e),mr(e),fr(e),gr(e),br(e),kr(e),Sr(e),yr(e),_r(e),Br(e),xr(e,n),Jr(e);break;case"safari":if(!Ar||!t.shimSafari)return i("Safari shim is not included in this adapter release."),r;i("adapter.js shimming safari."),r.browserShim=Ar,Vr(e,n),Fr(e),Or(e),Dr(e),Er(e),Cr(e),Tr(e),Nr(e),Pr(e),Ur(e),_r(e),xr(e,n),Jr(e),jr(e,n);break;default:i("Unsupported browser!")}}({window:"undefined"==typeof window?void 0:window});const Qr=["syncState","trickle","offer","answer","simulate","leave"];class Wr{constructor(e=!1){this.isConnected=!1,this.isReconnecting=!1,this.useJSON=e,this.requestQueue=new Bn}async join(e,t,i){this.isConnected=!1;return await this.connect(e,t,{autoSubscribe:null==i?void 0:i.autoSubscribe,publishOnly:null==i?void 0:i.publishOnly,adaptiveStream:null==i?void 0:i.adaptiveStream})}async reconnect(e,t){this.isReconnecting=!0,await this.connect(e,t,{reconnect:!0})}connect(e,t,i){e.startsWith("http")&&(e=e.replace("http","ws")),e=e.replace(/\/$/,""),e+="/rtc";const n=function(e,t,i){const n=new URLSearchParams;n.set("access_token",e),(null==i?void 0:i.reconnect)&&n.set("reconnect","1");void 0!==(null==i?void 0:i.autoSubscribe)&&n.set("auto_subscribe",i.autoSubscribe?"1":"0");n.set("sdk","js"),n.set("version",t.version),n.set("protocol",t.protocol.toString()),t.deviceModel&&n.set("device_model",t.deviceModel);t.os&&n.set("os",t.os);t.osVersion&&n.set("os_version",t.osVersion);t.browser&&n.set("browser",t.browser);t.browserVersion&&n.set("browser_version",t.browserVersion);void 0!==(null==i?void 0:i.publishOnly)&&n.set("publish",i.publishOnly);(null==i?void 0:i.adaptiveStream)&&n.set("adaptive_stream","1");return`?${n.toString()}`}(t,wt.fromPartial({sdk:ze.JS,protocol:7,version:Pi}),i);return new Promise(((t,r)=>{s.debug(`connecting to ${e+n}`),this.ws=void 0;const a=new WebSocket(e+n);a.binaryType="arraybuffer",a.onerror=async t=>{if(this.ws)this.handleWSError(t);else try{const t=await fetch(`http${e.substring(2)}/validate${n}`);if(t.ok)r(new pi("Internal error"));else{const e=await t.text();r(new pi(e))}}catch(e){r(new pi("server was not reachable"))}},a.onopen=()=>{this.ws=a,i.reconnect&&(this.isConnected=!0,t())},a.onmessage=async e=>{let i;if("string"==typeof e.data){const t=JSON.parse(e.data);i=xt.fromJSON(t)}else{if(!(e.data instanceof ArrayBuffer))return void s.error("could not decode websocket message: "+typeof e.data);i=xt.decode(new Uint8Array(e.data))}this.isConnected?(this.signalLatency&&await Ri(this.signalLatency),this.handleSignalResponse(i)):i.join?(this.isConnected=!0,t(i.join)):r(new pi("did not receive join response"))},a.onclose=e=>{this.isConnected&&this.ws===a&&(s.debug(`websocket connection closed: ${e.reason}`),this.isConnected=!1,this.onClose&&this.onClose(e.reason),this.ws===a&&(this.ws=void 0))}}))}close(){var e;this.isConnected=!1,this.ws&&(this.ws.onclose=null),null===(e=this.ws)||void 0===e||e.close(),this.ws=void 0}sendOffer(e){s.debug("sending offer",e),this.sendRequest({offer:Kr(e)})}sendAnswer(e){s.debug("sending answer"),this.sendRequest({answer:Kr(e)})}sendIceCandidate(e,t){s.trace("sending ice candidate",e),this.sendRequest({trickle:{candidateInit:JSON.stringify(e),target:t}})}sendMuteTrack(e,t){this.sendRequest({mute:{sid:e,muted:t}})}sendAddTrack(e){this.sendRequest({addTrack:Jt.fromPartial(e)})}sendUpdateTrackSettings(e){this.sendRequest({trackSetting:e})}sendUpdateSubscription(e){this.sendRequest({subscription:e})}sendSyncState(e){this.sendRequest({syncState:e})}sendUpdateVideoLayers(e,t){this.sendRequest({updateLayers:{trackSid:e,layers:t}})}sendUpdateSubscriptionPermissions(e,t){this.sendRequest({subscriptionPermission:{allParticipants:e,trackPermissions:t}})}sendSimulateScenario(e){this.sendRequest({simulate:e})}sendLeave(){this.sendRequest(_t.fromPartial({leave:{}}))}async sendRequest(e,t=!1){const i=!t&&!function(e){const t=void 0!==Object.keys(e).find((e=>Qr.includes(e)));return s.trace("request allowed to bypass queue:",{canPass:t,req:e}),t}(e);if(!i||!this.isReconnecting&&this.requestQueue.isEmpty())if(this.signalLatency&&await Ri(this.signalLatency),this.ws)try{this.useJSON?this.ws.send(JSON.stringify(_t.toJSON(e))):this.ws.send(_t.encode(e).finish())}catch(e){s.error("error sending signal message",{error:e})}else s.error("cannot send signal request before connected");else this.requestQueue.enqueue((()=>this.sendRequest(e,!0)))}handleSignalResponse(e){if(e.answer){const t=Gr(e.answer);this.onAnswer&&this.onAnswer(t)}else if(e.offer){const t=Gr(e.offer);this.onOffer&&this.onOffer(t)}else if(e.trickle){const t=JSON.parse(e.trickle.candidateInit);this.onTrickle&&this.onTrickle(t,e.trickle.target)}else e.update?this.onParticipantUpdate&&this.onParticipantUpdate(e.update.participants):e.trackPublished?this.onLocalTrackPublished&&this.onLocalTrackPublished(e.trackPublished):e.speakersChanged?this.onSpeakersChanged&&this.onSpeakersChanged(e.speakersChanged.speakers):e.leave?this.onLeave&&this.onLeave(e.leave):e.mute?this.onRemoteMuteChanged&&this.onRemoteMuteChanged(e.mute.sid,e.mute.muted):e.roomUpdate?this.onRoomUpdate&&this.onRoomUpdate(e.roomUpdate.room):e.connectionQuality?this.onConnectionQuality&&this.onConnectionQuality(e.connectionQuality):e.streamStateUpdate?this.onStreamStateUpdate&&this.onStreamStateUpdate(e.streamStateUpdate):e.subscribedQualityUpdate?this.onSubscribedQualityUpdate&&this.onSubscribedQualityUpdate(e.subscribedQualityUpdate):e.subscriptionPermissionUpdate?this.onSubscriptionPermissionUpdate&&this.onSubscriptionPermissionUpdate(e.subscriptionPermissionUpdate):e.refreshToken?this.onTokenRefresh&&this.onTokenRefresh(e.refreshToken):e.trackUnpublished?this.onLocalTrackUnpublished&&this.onLocalTrackUnpublished(e.trackUnpublished):s.debug("unsupported message",e)}setReconnected(){this.isReconnecting=!1,this.requestQueue.run()}handleWSError(e){s.error("websocket error",e)}}function Gr(e){const t={type:"offer",sdp:e.sdp};switch(e.type){case"answer":case"offer":case"pranswer":case"rollback":t.type=e.type}return t}function Kr(e){return{sdp:e.sdp,type:e.type}}class Hr{constructor(e){this.pendingCandidates=[],this.restartingIce=!1,this.renegotiate=!1,this.negotiate=fn((()=>{this.createAndSendOffer()}),100),this.pc=new RTCPeerConnection(e)}get isICEConnected(){return"connected"===this.pc.iceConnectionState||"completed"===this.pc.iceConnectionState}async addIceCandidate(e){if(this.pc.remoteDescription&&!this.restartingIce)return this.pc.addIceCandidate(e);this.pendingCandidates.push(e)}async setRemoteDescription(e){await this.pc.setRemoteDescription(e),this.pendingCandidates.forEach((e=>{this.pc.addIceCandidate(e)})),this.pendingCandidates=[],this.restartingIce=!1,this.renegotiate&&(this.renegotiate=!1,this.createAndSendOffer())}async createAndSendOffer(e){if(void 0===this.onOffer)return;if((null==e?void 0:e.iceRestart)&&(s.debug("restarting ICE"),this.restartingIce=!0),"have-local-offer"===this.pc.signalingState){const t=this.pc.remoteDescription;if(!(null==e?void 0:e.iceRestart)||!t)return void(this.renegotiate=!0);await this.pc.setRemoteDescription(t)}else if("closed"===this.pc.signalingState)return void s.warn("could not createOffer with closed peer connection");s.debug("starting to negotiate");const t=await this.pc.createOffer(e);await this.pc.setLocalDescription(t),this.onOffer(t)}close(){this.pc.close()}}const zr="_lossy",Zr="_reliable",$r=15e3;var Yr;!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"}(Yr||(Yr={}));class Xr extends Bi.exports.EventEmitter{constructor(){super(),this.rtcConfig={},this.subscriberPrimary=!1,this.pcState=Yr.New,this.isClosed=!0,this.pendingTrackResolvers={},this.hasPublished=!1,this.reconnectAttempts=0,this.reconnectStart=0,this.fullReconnectOnNext=!1,this.handleDataChannel=async({channel:e})=>{if(e){if(e.label===Zr)this.reliableDCSub=e;else{if(e.label!==zr)return;this.lossyDCSub=e}s.debug(`on data channel ${e.id}, ${e.label}`),e.onmessage=this.handleDataMessage}},this.handleDataMessage=async t=>{let i;if(t.data instanceof ArrayBuffer)i=t.data;else{if(!(t.data instanceof Blob))return void s.error("unsupported data type",t.data);i=await t.data.arrayBuffer()}const n=vt.decode(new Uint8Array(i));n.speaker?this.emit(e.EngineEvent.ActiveSpeakersUpdate,n.speaker.speakers):n.user&&this.emit(e.EngineEvent.DataPacketReceived,n.user,n.kind)},this.handleDataError=e=>{const t=0===e.currentTarget.maxRetransmits?"lossy":"reliable";if(e instanceof ErrorEvent){const{error:i}=e.error;s.error(`DataChannel error on ${t}: ${e.message}`,i)}else s.error(`Unknown DataChannel Error on ${t}`,e)},this.handleDisconnect=t=>{if(this.isClosed)return;s.debug(`${t} disconnected`),0===this.reconnectAttempts&&(this.reconnectStart=Date.now());const i=this.reconnectAttempts*this.reconnectAttempts*300;setTimeout((async()=>{var t;if(!this.isClosed){(Oi()||(null===(t=this.clientConfiguration)||void 0===t?void 0:t.resumeConnection)===Ge.DISABLED)&&(this.fullReconnectOnNext=!0);try{this.fullReconnectOnNext?await this.restartConnection():await this.resumeConnection(),this.reconnectAttempts=0,this.fullReconnectOnNext=!1}catch(t){this.reconnectAttempts+=1;let i=!0;t instanceof vi?(s.debug("received unrecoverable error",{error:t}),i=!1):t instanceof ts||(this.fullReconnectOnNext=!0);const n=Date.now()-this.reconnectStart;(this.reconnectAttempts>=10||n>6e4)&&(i=!1),i?this.handleDisconnect("reconnect"):(s.info(`could not recover connection after 10 attempts, ${n}ms. giving up`),this.emit(e.EngineEvent.Disconnected),this.close())}}}),i)},this.client=new Wr}async join(e,t,i){this.url=e,this.token=t,this.signalOpts=i;const n=await this.client.join(e,t,i);return this.isClosed=!1,this.subscriberPrimary=n.subscriberPrimary,this.publisher||this.configure(n),this.subscriberPrimary||this.negotiate(),this.clientConfiguration=n.clientConfiguration,n}close(){this.isClosed=!0,this.removeAllListeners(),this.publisher&&"closed"!==this.publisher.pc.signalingState&&(this.publisher.pc.getSenders().forEach((e=>{var t,i;try{(null===(t=this.publisher)||void 0===t?void 0:t.pc.removeTrack)&&(null===(i=this.publisher)||void 0===i||i.pc.removeTrack(e))}catch(e){s.warn("could not removeTrack",{error:e})}})),this.publisher.close(),this.publisher=void 0),this.subscriber&&(this.subscriber.close(),this.subscriber=void 0),this.client.close()}addTrack(e){if(this.pendingTrackResolvers[e.cid])throw new mi("a track with the same ID has already been published");return new Promise((t=>{this.pendingTrackResolvers[e.cid]=t,this.client.sendAddTrack(e)}))}updateMuteStatus(e,t){this.client.sendMuteTrack(e,t)}get dataSubscriberReadyState(){var e;return null===(e=this.reliableDCSub)||void 0===e?void 0:e.readyState}get connectedServerAddress(){return this.connectedServerAddr}configure(t){if(this.publisher||this.subscriber)return;if(t.iceServers&&!this.rtcConfig.iceServers){const e=[];t.iceServers.forEach((t=>{const i={urls:t.urls};t.username&&(i.username=t.username),t.credential&&(i.credential=t.credential),e.push(i)})),this.rtcConfig.iceServers=e}this.rtcConfig.sdpSemantics="unified-plan",this.rtcConfig.continualGatheringPolicy="gather_continually",this.publisher=new Hr(this.rtcConfig),this.subscriber=new Hr(this.rtcConfig),this.emit(e.EngineEvent.TransportsCreated,this.publisher,this.subscriber),this.publisher.pc.onicecandidate=e=>{e.candidate&&(s.trace("adding ICE candidate for peer",e.candidate),this.client.sendIceCandidate(e.candidate,Ut.PUBLISHER))},this.subscriber.pc.onicecandidate=e=>{e.candidate&&this.client.sendIceCandidate(e.candidate,Ut.SUBSCRIBER)},this.publisher.onOffer=e=>{this.client.sendOffer(e)};let i=this.publisher.pc;t.subscriberPrimary&&(i=this.subscriber.pc,this.subscriber.pc.ondatachannel=this.handleDataChannel),this.primaryPC=i,i.onconnectionstatechange=async()=>{if(s.trace("connection state changed",{state:i.connectionState}),"connected"===i.connectionState){try{this.connectedServerAddr=await es(i)}catch(e){s.warn("could not get connected server address",{error:e})}const t=this.pcState===Yr.New;this.pcState=Yr.Connected,t&&this.emit(e.EngineEvent.Connected)}else"failed"===i.connectionState&&this.pcState===Yr.Connected&&(this.pcState=Yr.Disconnected,this.handleDisconnect("peerconnection"))},Di()?this.subscriber.pc.ontrack=t=>{this.emit(e.EngineEvent.MediaTrackAdded,t.track,t.streams[0],t.receiver)}:this.subscriber.pc.onaddstream=t=>{const i=t.stream.getTracks()[0];this.emit(e.EngineEvent.MediaTrackAdded,i,t.stream)},this.lossyDC=this.publisher.pc.createDataChannel(zr,{ordered:!0,maxRetransmits:0}),this.reliableDC=this.publisher.pc.createDataChannel(Zr,{ordered:!0}),this.lossyDC.onmessage=this.handleDataMessage,this.reliableDC.onmessage=this.handleDataMessage,this.lossyDC.onerror=this.handleDataError,this.reliableDC.onerror=this.handleDataError,this.client.onAnswer=async e=>{this.publisher&&(s.debug("received server answer",{RTCSdpType:e.type,signalingState:this.publisher.pc.signalingState}),await this.publisher.setRemoteDescription(e))},this.client.onTrickle=(e,t)=>{this.publisher&&this.subscriber&&(s.trace("got ICE candidate from peer",{candidate:e,target:t}),t===Ut.PUBLISHER?this.publisher.addIceCandidate(e):this.subscriber.addIceCandidate(e))},this.client.onOffer=async e=>{if(!this.subscriber)return;s.debug("received server offer",{RTCSdpType:e.type,signalingState:this.subscriber.pc.signalingState}),await this.subscriber.setRemoteDescription(e);const t=await this.subscriber.pc.createAnswer();await this.subscriber.pc.setLocalDescription(t),this.client.sendAnswer(t)},this.client.onLocalTrackPublished=e=>{s.debug("received trackPublishedResponse",e);const t=this.pendingTrackResolvers[e.cid];t?(delete this.pendingTrackResolvers[e.cid],t(e.track)):s.error(`missing track resolver for ${e.cid}`)},this.client.onTokenRefresh=e=>{this.token=e},this.client.onClose=()=>{this.handleDisconnect("signal")},this.client.onLeave=t=>{(null==t?void 0:t.canReconnect)?(this.fullReconnectOnNext=!0,this.primaryPC=void 0):(this.emit(e.EngineEvent.Disconnected),this.close())}}async restartConnection(){var t,i;if(!this.url||!this.token)throw new vi("could not reconnect, url or token not saved");let n;s.info(`reconnecting, attempt: ${this.reconnectAttempts}`),0===this.reconnectAttempts&&this.emit(e.EngineEvent.Restarting),this.primaryPC=void 0,null===(t=this.publisher)||void 0===t||t.close(),this.publisher=void 0,null===(i=this.subscriber)||void 0===i||i.close(),this.subscriber=void 0;try{n=await this.join(this.url,this.token,this.signalOpts)}catch(e){throw new ts}await this.waitForPCConnected(),this.client.setReconnected(),this.emit(e.EngineEvent.Restarted,n)}async resumeConnection(){if(!this.url||!this.token)throw new vi("could not reconnect, url or token not saved");if(!this.publisher||!this.subscriber)throw new vi("publisher and subscriber connections unset");s.info(`resuming signal connection, attempt ${this.reconnectAttempts}`),0===this.reconnectAttempts&&this.emit(e.EngineEvent.Resuming);try{await this.client.reconnect(this.url,this.token)}catch(e){throw new ts}this.emit(e.EngineEvent.SignalResumed),this.subscriber.restartingIce=!0,this.hasPublished&&await this.publisher.createAndSendOffer({iceRestart:!0}),await this.waitForPCConnected(),this.client.setReconnected(),this.emit(e.EngineEvent.Resumed)}async waitForPCConnected(){var e;const t=Date.now();let i=t;for(this.pcState=Yr.Reconnecting,s.debug("waiting for peer connection to reconnect");i-t<$r&&void 0!==this.primaryPC;){if(i-t>2e3&&"connected"===(null===(e=this.primaryPC)||void 0===e?void 0:e.connectionState)){this.pcState=Yr.Connected;try{this.connectedServerAddr=await es(this.primaryPC)}catch(e){s.warn("could not get connected server address",{error:e})}}if(this.pcState===Yr.Connected)return;await Ri(100),i=Date.now()}throw new pi("could not establish PC connection")}async sendDataPacket(t,i){const n=vt.encode(t).finish();await this.ensurePublisherConnected(i),i===e.DataPacket_Kind.LOSSY&&this.lossyDC?this.lossyDC.send(n):i===e.DataPacket_Kind.RELIABLE&&this.reliableDC&&this.reliableDC.send(n)}async ensurePublisherConnected(e){var t,i;if(!this.subscriberPrimary)return;if(!this.publisher)throw new pi("publisher connection not set");this.publisher.isICEConnected||"checking"===this.publisher.pc.iceConnectionState||this.negotiate();const n=this.dataChannelForKind(e);if("open"===(null==n?void 0:n.readyState))return;const r=(new Date).getTime()+$r;for(;(new Date).getTime()<r;){if(this.publisher.isICEConnected&&"open"===(null===(t=this.dataChannelForKind(e))||void 0===t?void 0:t.readyState))return;await Ri(50)}throw new pi(`could not establish publisher connection, state ${null===(i=this.publisher)||void 0===i?void 0:i.pc.iceConnectionState}`)}negotiate(){this.publisher&&(this.hasPublished=!0,this.publisher.negotiate())}dataChannelForKind(t,i){if(i){if(t===e.DataPacket_Kind.LOSSY)return this.lossyDCSub;if(t===e.DataPacket_Kind.RELIABLE)return this.reliableDCSub}else{if(t===e.DataPacket_Kind.LOSSY)return this.lossyDC;if(t===e.DataPacket_Kind.RELIABLE)return this.reliableDC}}}async function es(e){var t;let i="";const n=new Map,r=new Map;if((await e.getStats()).forEach((e=>{switch(e.type){case"transport":i=e.selectedCandidatePairId;break;case"candidate-pair":""===i&&e.selected&&(i=e.id),n.set(e.id,e);break;case"remote-candidate":r.set(e.id,`${e.address}:${e.port}`)}})),""===i)return;const s=null===(t=n.get(i))||void 0===t?void 0:t.remoteCandidateId;return void 0!==s?r.get(s):void 0}class ts extends Error{}const is={audioBitrate:e.AudioPresets.speech.maxBitrate,dtx:!0,simulcast:!0,screenShareEncoding:Cn.h1080fps15.encoding,stopMicTrackOnMute:!1},ns={autoGainControl:!0,channelCount:1,echoCancellation:!0,noiseSuppression:!0},rs={resolution:yn.h540.resolution};var ss;e.RoomState=void 0,(ss=e.RoomState||(e.RoomState={})).Disconnected="disconnected",ss.Connected="connected",ss.Reconnecting="reconnecting";class as extends Bi.exports.EventEmitter{constructor(t){var i,n;switch(super(),this.state=e.RoomState.Disconnected,this.activeSpeakers=[],this.sid="",this.name="",this.metadata=void 0,this.audioEnabled=!0,this.connect=async(t,i,n)=>{var r,a;if(this.state===e.RoomState.Disconnected){this.createEngine(),this.acquireAudioContext(),(null==n?void 0:n.rtcConfig)&&(this.engine.rtcConfig=n.rtcConfig),this.connOptions=n;try{const o=await this.engine.join(t,i,{autoSubscribe:null==n?void 0:n.autoSubscribe,publishOnly:null==n?void 0:n.publishOnly,adaptiveStream:"object"==typeof(null===(r=this.options)||void 0===r?void 0:r.adaptiveStream)||(null===(a=this.options)||void 0===a?void 0:a.adaptiveStream)});if(s.debug(`connected to Livekit Server version: ${o.serverVersion}, region: ${o.serverRegion}`),!o.serverVersion)throw new fi("unknown server version");"0.15.1"===o.serverVersion&&this.options.dynacast&&(s.debug("disabling dynacast due to server version"),this.options.dynacast=!1),this.state=e.RoomState.Connected;const c=o.participant;this.localParticipant.sid=c.sid,this.localParticipant.identity=c.identity,this.localParticipant.updateInfo(c),this.localParticipant.on(e.ParticipantEvent.MetadataChanged,(t=>{this.emit(e.RoomEvent.MetadataChanged,t,this.localParticipant)})).on(e.ParticipantEvent.ParticipantMetadataChanged,(t=>{this.emit(e.RoomEvent.ParticipantMetadataChanged,t,this.localParticipant)})).on(e.ParticipantEvent.TrackMuted,(t=>{this.emit(e.RoomEvent.TrackMuted,t,this.localParticipant)})).on(e.ParticipantEvent.TrackUnmuted,(t=>{this.emit(e.RoomEvent.TrackUnmuted,t,this.localParticipant)})).on(e.ParticipantEvent.LocalTrackPublished,(t=>{this.emit(e.RoomEvent.LocalTrackPublished,t,this.localParticipant)})).on(e.ParticipantEvent.LocalTrackUnpublished,(t=>{this.emit(e.RoomEvent.LocalTrackUnpublished,t,this.localParticipant)})).on(e.ParticipantEvent.ConnectionQualityChanged,(t=>{this.emit(e.RoomEvent.ConnectionQualityChanged,t,this.localParticipant)})).on(e.ParticipantEvent.MediaDevicesError,(t=>{this.emit(e.RoomEvent.MediaDevicesError,t)})).on(e.ParticipantEvent.ParticipantPermissionsChanged,(t=>{this.emit(e.RoomEvent.ParticipantPermissionsChanged,t,this.localParticipant)})),o.otherParticipants.forEach((e=>{this.getOrCreateParticipant(e.sid,e)})),this.name=o.room.name,this.sid=o.room.sid,this.metadata=o.room.metadata,this.emit(e.RoomEvent.StateChanged,this.state)}catch(e){throw this.engine.close(),e}return new Promise(((t,i)=>{const n=setTimeout((()=>{this.engine.close(),i(new pi("could not connect after timeout"))}),$r);this.engine.once(e.EngineEvent.Connected,(()=>{var e;clearTimeout(n),Di()&&(window.addEventListener("beforeunload",this.onBeforeUnload),null===(e=navigator.mediaDevices)||void 0===e||e.addEventListener("devicechange",this.handleDeviceChange)),t(this)}))}))}s.warn(`already connected to room ${this.name}`)},this.disconnect=(e=!0)=>{this.engine&&(this.engine.client.sendLeave(),this.engine.close()),this.handleDisconnect(e),this.engine=void 0},this.onBeforeUnload=()=>{this.disconnect()},this.handleRestarting=()=>{this.state=e.RoomState.Reconnecting,this.emit(e.RoomEvent.Reconnecting),this.emit(e.RoomEvent.StateChanged,this.state);for(const e of this.participants.values())this.handleParticipantDisconnected(e.sid,e)},this.handleRestarted=async t=>{s.debug(`reconnected to server region ${t.serverRegion}`),this.state=e.RoomState.Connected,this.emit(e.RoomEvent.Reconnected),this.emit(e.RoomEvent.StateChanged,this.state),t.participant&&(this.localParticipant.sid=t.participant.sid,this.handleParticipantUpdates([t.participant])),this.handleParticipantUpdates(t.otherParticipants);const i=[];this.localParticipant.tracks.forEach((e=>{e.track&&i.push(e)})),await Promise.all(i.map((async e=>{const t=e.track;this.localParticipant.unpublishTrack(t,!1),this.localParticipant.publishTrack(t,e.options)})))},this.handleParticipantUpdates=t=>{t.forEach((t=>{if(t.sid===this.localParticipant.sid||t.identity===this.localParticipant.identity)return void this.localParticipant.updateInfo(t);let i=this.participants.get(t.sid);const n=!i;i=this.getOrCreateParticipant(t.sid,t),t.state===Ke.DISCONNECTED?this.handleParticipantDisconnected(t.sid,i):n?this.emit(e.RoomEvent.ParticipantConnected,i):i.updateInfo(t)}))},this.handleActiveSpeakersUpdate=t=>{const i=[],n={};t.forEach((e=>{if(n[e.sid]=!0,e.sid===this.localParticipant.sid)this.localParticipant.audioLevel=e.level,this.localParticipant.setIsSpeaking(!0),i.push(this.localParticipant);else{const t=this.participants.get(e.sid);t&&(t.audioLevel=e.level,t.setIsSpeaking(!0),i.push(t))}})),n[this.localParticipant.sid]||(this.localParticipant.audioLevel=0,this.localParticipant.setIsSpeaking(!1)),this.participants.forEach((e=>{n[e.sid]||(e.audioLevel=0,e.setIsSpeaking(!1))})),this.activeSpeakers=i,this.emit(e.RoomEvent.ActiveSpeakersChanged,i)},this.handleSpeakersChanged=t=>{const i=new Map;this.activeSpeakers.forEach((e=>{i.set(e.sid,e)})),t.forEach((e=>{let t=this.participants.get(e.sid);e.sid===this.localParticipant.sid&&(t=this.localParticipant),t&&(t.audioLevel=e.level,t.setIsSpeaking(e.active),e.active?i.set(e.sid,t):i.delete(e.sid))}));const n=Array.from(i.values());n.sort(((e,t)=>t.audioLevel-e.audioLevel)),this.activeSpeakers=n,this.emit(e.RoomEvent.ActiveSpeakersChanged,n)},this.handleStreamStateUpdate=t=>{t.streamStates.forEach((t=>{const i=this.participants.get(t.participantSid);if(!i)return;const n=i.getTrackPublication(t.trackSid);n&&n.track&&(n.track.streamState=tn.streamStateFromProto(t.state),i.emit(e.ParticipantEvent.TrackStreamStateChanged,n,n.track.streamState),this.emit(e.ParticipantEvent.TrackStreamStateChanged,n,n.track.streamState,i))}))},this.handleSubscriptionPermissionUpdate=t=>{const i=this.participants.get(t.participantSid);if(!i)return;const n=i.getTrackPublication(t.trackSid);n&&(n._allowed=t.allowed,i.emit(e.ParticipantEvent.TrackSubscriptionPermissionChanged,n,n.subscriptionStatus),this.emit(e.ParticipantEvent.TrackSubscriptionPermissionChanged,n,n.subscriptionStatus,i))},this.handleDataPacket=(t,i)=>{const n=this.participants.get(t.participantSid);this.emit(e.RoomEvent.DataReceived,t.payload,n,i),null==n||n.emit(e.ParticipantEvent.DataReceived,t.payload,i)},this.handleAudioPlaybackStarted=()=>{this.canPlaybackAudio||(this.audioEnabled=!0,this.emit(e.RoomEvent.AudioPlaybackStatusChanged,!0))},this.handleAudioPlaybackFailed=t=>{s.warn("could not playback audio",t),this.canPlaybackAudio&&(this.audioEnabled=!1,this.emit(e.RoomEvent.AudioPlaybackStatusChanged,!1))},this.handleDeviceChange=async()=>{this.emit(e.RoomEvent.MediaDevicesChanged)},this.handleRoomUpdate=t=>{this.metadata=t.metadata,this.emit(e.RoomEvent.RoomMetadataChanged,t.metadata)},this.handleConnectionQualityUpdate=e=>{e.updates.forEach((e=>{if(e.participantSid===this.localParticipant.sid)return void this.localParticipant.setConnectionQuality(e.quality);const t=this.participants.get(e.participantSid);t&&t.setConnectionQuality(e.quality)}))},this.participants=new Map,this.options=t||{},null===(n=null===(i=this.options)||void 0===i?void 0:i.publishDefaults)||void 0===n?void 0:n.videoCodec){case"av1":case"vp9":this.options.publishDefaults.simulcast=void 0}this.options.audioCaptureDefaults={...ns,...null==t?void 0:t.audioCaptureDefaults},this.options.videoCaptureDefaults={...rs,...null==t?void 0:t.videoCaptureDefaults},this.options.publishDefaults={...is,...null==t?void 0:t.publishDefaults},this.createEngine(),this.localParticipant=new Jn("","",this.engine,this.options)}createEngine(){this.engine||(this.engine=new Xr,this.engine.client.signalLatency=this.options.expSignalLatency,this.engine.client.onParticipantUpdate=this.handleParticipantUpdates,this.engine.client.onRoomUpdate=this.handleRoomUpdate,this.engine.client.onSpeakersChanged=this.handleSpeakersChanged,this.engine.client.onStreamStateUpdate=this.handleStreamStateUpdate,this.engine.client.onSubscriptionPermissionUpdate=this.handleSubscriptionPermissionUpdate,this.engine.client.onConnectionQuality=this.handleConnectionQualityUpdate,this.engine.on(e.EngineEvent.MediaTrackAdded,((e,t,i)=>{this.onTrackAdded(e,t,i)})).on(e.EngineEvent.Disconnected,(()=>{this.handleDisconnect()})).on(e.EngineEvent.ActiveSpeakersUpdate,this.handleActiveSpeakersUpdate).on(e.EngineEvent.DataPacketReceived,this.handleDataPacket).on(e.EngineEvent.Resuming,(()=>{this.state=e.RoomState.Reconnecting,this.emit(e.RoomEvent.Reconnecting),this.emit(e.RoomEvent.StateChanged,this.state)})).on(e.EngineEvent.Resumed,(()=>{this.state=e.RoomState.Connected,this.emit(e.RoomEvent.Reconnected),this.emit(e.RoomEvent.StateChanged,this.state),this.updateSubscriptions()})).on(e.EngineEvent.SignalResumed,(()=>{this.state===e.RoomState.Reconnecting&&this.sendSyncState()})).on(e.EngineEvent.Restarting,this.handleRestarting).on(e.EngineEvent.Restarted,this.handleRestarted))}static getLocalDevices(e,t=!0){return Ei.getInstance().getDevices(e,t)}getParticipantByIdentity(e){for(const[,t]of this.participants)if(t.identity===e)return t;if(this.localParticipant.identity===e)return this.localParticipant}simulateScenario(e){let t;switch(e){case"speaker":t=ui.fromPartial({speakerUpdate:3});break;case"node-failure":t=ui.fromPartial({nodeFailure:!0});break;case"server-leave":t=ui.fromPartial({serverLeave:!0});break;case"migration":t=ui.fromPartial({migration:!0})}t&&this.engine.client.sendSimulateScenario(t)}async startAudio(){this.acquireAudioContext();const e=[];this.participants.forEach((t=>{t.audioTracks.forEach((t=>{t.track&&t.track.attachedElements.forEach((t=>{e.push(t)}))}))}));try{await Promise.all(e.map((e=>e.play()))),this.handleAudioPlaybackStarted()}catch(e){throw this.handleAudioPlaybackFailed(e),e}}get canPlaybackAudio(){return this.audioEnabled}async switchActiveDevice(e,t){if("audioinput"===e){const e=Array.from(this.localParticipant.audioTracks.values()).filter((e=>e.source===tn.Source.Microphone));await Promise.all(e.map((e=>{var i;return null===(i=e.audioTrack)||void 0===i?void 0:i.setDeviceId(t)}))),this.options.audioCaptureDefaults.deviceId=t}else if("videoinput"===e){const e=Array.from(this.localParticipant.videoTracks.values()).filter((e=>e.source===tn.Source.Camera));await Promise.all(e.map((e=>{var i;return null===(i=e.videoTrack)||void 0===i?void 0:i.setDeviceId(t)}))),this.options.videoCaptureDefaults.deviceId=t}else if("audiooutput"===e){const e=[];this.participants.forEach((t=>{t.audioTracks.forEach((t=>{t.isSubscribed&&t.track&&t.track.attachedElements.forEach((t=>{e.push(t)}))}))})),await Promise.all(e.map((async e=>{"setSinkId"in e&&await e.setSinkId(t)})))}}onTrackAdded(e,t,i){const n=function(e){const t=e.split("|");return t.length>1?[t[0],e.substr(t[0].length+1)]:[e,""]}(t.id),r=n[0];let s=n[1];s&&""!==s||(s=e.id);const a=this.getOrCreateParticipant(r);let o;this.options.adaptiveStream&&(o="object"==typeof this.options.adaptiveStream?this.options.adaptiveStream:{}),a.addSubscribedMediaTrack(e,s,t,i,o)}handleDisconnect(t=!0){var i;this.state!==e.RoomState.Disconnected&&(this.participants.forEach((e=>{e.tracks.forEach((t=>{e.unpublishTrack(t.trackSid)}))})),this.localParticipant.tracks.forEach((e=>{var i,n;e.track&&this.localParticipant.unpublishTrack(e.track),t&&(null===(i=e.track)||void 0===i||i.detach(),null===(n=e.track)||void 0===n||n.stop())})),this.participants.clear(),this.activeSpeakers=[],this.audioContext&&(this.audioContext.close(),this.audioContext=void 0),Di()&&(window.removeEventListener("beforeunload",this.onBeforeUnload),null===(i=navigator.mediaDevices)||void 0===i||i.removeEventListener("devicechange",this.handleDeviceChange)),this.state=e.RoomState.Disconnected,this.emit(e.RoomEvent.Disconnected),this.emit(e.RoomEvent.StateChanged,this.state))}handleParticipantDisconnected(t,i){this.participants.delete(t),i&&(i.tracks.forEach((e=>{i.unpublishTrack(e.trackSid)})),this.emit(e.RoomEvent.ParticipantDisconnected,i))}acquireAudioContext(){this.audioContext&&this.audioContext.close();const e=dn();e&&(this.audioContext=e)}createParticipant(e,t){let i;return i=t?xn.fromParticipantInfo(this.engine.client,t):new xn(this.engine.client,e,""),i}getOrCreateParticipant(t,i){if(this.participants.has(t))return this.participants.get(t);const n=this.createParticipant(t,i);return this.participants.set(t,n),n.on(e.ParticipantEvent.TrackPublished,(t=>{this.emit(e.RoomEvent.TrackPublished,t,n)})).on(e.ParticipantEvent.TrackSubscribed,((t,i)=>{t.kind===tn.Kind.Audio&&(t.on(e.TrackEvent.AudioPlaybackStarted,this.handleAudioPlaybackStarted),t.on(e.TrackEvent.AudioPlaybackFailed,this.handleAudioPlaybackFailed)),this.emit(e.RoomEvent.TrackSubscribed,t,i,n)})).on(e.ParticipantEvent.TrackUnpublished,(t=>{this.emit(e.RoomEvent.TrackUnpublished,t,n)})).on(e.ParticipantEvent.TrackUnsubscribed,((t,i)=>{this.emit(e.RoomEvent.TrackUnsubscribed,t,i,n)})).on(e.ParticipantEvent.TrackSubscriptionFailed,(t=>{this.emit(e.RoomEvent.TrackSubscriptionFailed,t,n)})).on(e.ParticipantEvent.TrackMuted,(t=>{this.emit(e.RoomEvent.TrackMuted,t,n)})).on(e.ParticipantEvent.TrackUnmuted,(t=>{this.emit(e.RoomEvent.TrackUnmuted,t,n)})).on(e.ParticipantEvent.MetadataChanged,(t=>{this.emit(e.RoomEvent.MetadataChanged,t,n)})).on(e.ParticipantEvent.ParticipantMetadataChanged,(t=>{this.emit(e.RoomEvent.ParticipantMetadataChanged,t,n)})).on(e.ParticipantEvent.ConnectionQualityChanged,(t=>{this.emit(e.RoomEvent.ConnectionQualityChanged,t,n)})).on(e.ParticipantEvent.ParticipantPermissionsChanged,(t=>{this.emit(e.RoomEvent.ParticipantPermissionsChanged,t,n)})),n}sendSyncState(){var e;if(void 0===this.engine.subscriber||null===this.engine.subscriber.pc.localDescription)return;const t=this.engine.subscriber.pc.localDescription,i=(null===(e=this.connOptions)||void 0===e?void 0:e.autoSubscribe)||!1,n=new Array;this.participants.forEach((e=>{e.tracks.forEach((e=>{e.isSubscribed!==i&&n.push(e.trackSid)}))})),this.engine.client.sendSyncState({answer:Kr({sdp:t.sdp,type:t.type}),subscription:{trackSids:n,subscribe:!i,participantTracks:[]},publishTracks:this.localParticipant.publishedTracksInfo(),dataChannels:this.localParticipant.dataChannelsInfo()})}updateSubscriptions(){for(const e of this.participants.values())for(const t of e.videoTracks.values())t.isSubscribed&&t instanceof _n&&t.emitTrackUpdate()}emit(e,...t){return s.debug("room event",{event:e,args:t}),super.emit(e,...t)}}async function os(e){var t,i;null!=e||(e={}),null!==(t=e.audio)&&void 0!==t||(e.audio=!0),null!==(i=e.video)&&void 0!==i||(e.video=!0);const n=cn(an(e,ns,rs)),r=await navigator.mediaDevices.getUserMedia(n);return r.getTracks().map((t=>{const i="audio"===t.kind;let s;i?e.audio:e.video;const a=i?n.audio:n.video;"boolean"!=typeof a&&(s=a);const o=En(t,s);return o.kind===tn.Kind.Video?o.source=tn.Source.Camera:o.kind===tn.Kind.Audio&&(o.source=tn.Source.Microphone),o.mediaStream=r,o}))}e.ConnectionError=pi,e.LivekitError=hi,e.LocalAudioTrack=un,e.LocalParticipant=Jn,e.LocalTrack=sn,e.LocalTrackPublication=bn,e.LocalVideoTrack=ln,e.Participant=Tn,e.PublishDataError=class extends hi{constructor(e){super(13,e||"Unable to publish data")}},e.RemoteAudioTrack=mn,e.RemoteParticipant=xn,e.RemoteTrack=pn,e.RemoteTrackPublication=_n,e.RemoteVideoTrack=vn,e.Room=as,e.ScreenSharePresets=Cn,e.Track=tn,e.TrackInvalidError=mi,e.TrackPublication=gn,e.UnexpectedConnectionState=vi,e.UnsupportedServer=fi,e.VideoPreset=kn,e.VideoPresets=yn,e.VideoPresets43=wn,e.attachToElement=nn,e.connect=async function(t,i,n){var r,o,c,d;null!=n||(n={}),void 0===n.adaptiveStream&&(n.adaptiveStream=!0===n.autoManageVideo?{}:void 0),a(null!==(r=n.logLevel)&&void 0!==r?r:e.LogLevel.warn);const u=null!==(o=n.rtcConfig)&&void 0!==o?o:{};n.iceServers&&(u.iceServers=n.iceServers);const l=new as(n);await l.connect(t,i,n);const h=null!==(c=n.audio)&&void 0!==c&&c,p=null!==(d=n.video)&&void 0!==d&&d;return(h||p)&&setTimeout((async()=>{let t;if(h&&p)try{await l.localParticipant.enableCameraAndMicrophone()}catch(i){const n=e.MediaDeviceFailure.getFailure(i);if(s.warn("received error while creating media",{error:n}),i instanceof Error&&s.warn(i.message),n===e.MediaDeviceFailure.NotFound||n===e.MediaDeviceFailure.DeviceInUse)try{await l.localParticipant.setMicrophoneEnabled(!0)}catch(e){t=e}else t=i}else if(h)try{await l.localParticipant.setMicrophoneEnabled(!0)}catch(e){t=e}else if(p)try{await l.localParticipant.setCameraEnabled(!0)}catch(e){t=e}t&&(l.emit(e.RoomEvent.MediaDevicesError,t),s.error("could not create media",t))})),l},e.createLocalAudioTrack=async function(e){return(await os({audio:e,video:!1}))[0]},e.createLocalScreenTracks=async function(e){var t;void 0===e&&(e={}),void 0===e.resolution&&(e.resolution=yn.fhd.resolution);let i=!0;e.resolution&&(i={width:e.resolution.width,height:e.resolution.height});const n=await navigator.mediaDevices.getDisplayMedia({audio:null!==(t=e.audio)&&void 0!==t&&t,video:i}),r=n.getVideoTracks();if(0===r.length)throw new mi("no video track found");const s=new ln(r[0]);s.source=tn.Source.ScreenShare;const a=[s];if(n.getAudioTracks().length>0){const e=new un(n.getAudioTracks()[0]);e.source=tn.Source.ScreenShareAudio,a.push(e)}return a},e.createLocalTracks=os,e.createLocalVideoTrack=async function(e){return(await os({audio:!1,video:e}))[0]},e.detachTrack=rn,e.protocolVersion=7,e.setLogExtension=function(t){const i=s.methodFactory;s.methodFactory=(n,r,a)=>{const o=i(n,r,a),c=s.getLevel(),d=r>=c&&r<e.LogLevel.silent;return(e,i)=>{i?o(e,i):o(e),d&&t(r,e,i)}},s.setLevel(s.getLevel())},e.setLogLevel=a,e.version=Pi,Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=livekit-client.umd.js.map