livekit-client 2.19.2 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/livekit-client.e2ee.worker.js +1 -1
- package/dist/livekit-client.e2ee.worker.js.map +1 -1
- package/dist/livekit-client.e2ee.worker.mjs +23 -23
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +179 -111
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.fm.worker.js +2 -0
- package/dist/{livekit-client.pt.worker.js.map → livekit-client.fm.worker.js.map} +1 -1
- package/dist/{livekit-client.pt.worker.mjs → livekit-client.fm.worker.mjs} +4 -4
- package/dist/livekit-client.fm.worker.mjs.map +1 -0
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/e2ee/E2eeManager.d.ts +1 -1
- package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
- package/dist/src/e2ee/types.d.ts +5 -5
- package/dist/src/e2ee/types.d.ts.map +1 -1
- package/dist/src/e2ee/worker/FrameCryptor.d.ts +8 -8
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/{packetTrailer/PacketTrailerManager.d.ts → frameMetadata/FrameMetadataManager.d.ts} +8 -4
- package/dist/src/{packetTrailer/PacketTrailerManager.d.ts.map → frameMetadata/FrameMetadataManager.d.ts.map} +1 -1
- package/dist/src/{packetTrailer/packetTrailer.d.ts → frameMetadata/frameMetadata.d.ts} +7 -7
- package/dist/src/frameMetadata/frameMetadata.d.ts.map +1 -0
- package/dist/src/{packetTrailer → frameMetadata}/types.d.ts +10 -6
- package/dist/src/frameMetadata/types.d.ts.map +1 -0
- package/dist/src/frameMetadata/utils.d.ts +9 -0
- package/dist/src/{packetTrailer → frameMetadata}/utils.d.ts.map +1 -1
- package/dist/src/frameMetadata/worker/frameMetadata.worker.d.ts +2 -0
- package/dist/src/frameMetadata/worker/frameMetadata.worker.d.ts.map +1 -0
- package/dist/src/index.d.ts +10 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/options.d.ts +8 -4
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +1 -0
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/PCTransportManager.d.ts +1 -0
- package/dist/src/room/PCTransportManager.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +3 -1
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +2 -2
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +2 -2
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
- package/dist/src/room/token-source/TokenSource.d.ts.map +1 -1
- package/dist/src/room/token-source/types.d.ts +1 -0
- package/dist/src/room/token-source/types.d.ts.map +1 -1
- package/dist/src/room/token-source/utils.d.ts.map +1 -1
- package/dist/src/room/track/FrameMetadataExtractor.d.ts +19 -0
- package/dist/src/room/track/FrameMetadataExtractor.d.ts.map +1 -0
- package/dist/src/room/track/RemoteVideoTrack.d.ts +7 -7
- package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/options.d.ts +17 -5
- package/dist/src/room/track/options.d.ts.map +1 -1
- package/dist/ts4.2/e2ee/E2eeManager.d.ts +1 -1
- package/dist/ts4.2/e2ee/types.d.ts +5 -5
- package/dist/ts4.2/e2ee/worker/FrameCryptor.d.ts +8 -8
- package/dist/ts4.2/{packetTrailer/PacketTrailerManager.d.ts → frameMetadata/FrameMetadataManager.d.ts} +8 -4
- package/dist/ts4.2/{packetTrailer/packetTrailer.d.ts → frameMetadata/frameMetadata.d.ts} +7 -7
- package/dist/ts4.2/{packetTrailer → frameMetadata}/types.d.ts +10 -6
- package/dist/ts4.2/frameMetadata/utils.d.ts +9 -0
- package/dist/ts4.2/frameMetadata/worker/frameMetadata.worker.d.ts +2 -0
- package/dist/ts4.2/index.d.ts +9 -3
- package/dist/ts4.2/options.d.ts +8 -4
- package/dist/ts4.2/room/PCTransport.d.ts +1 -0
- package/dist/ts4.2/room/PCTransportManager.d.ts +1 -0
- package/dist/ts4.2/room/RTCEngine.d.ts +3 -1
- package/dist/ts4.2/room/Room.d.ts +2 -2
- package/dist/ts4.2/room/participant/LocalParticipant.d.ts +2 -2
- package/dist/ts4.2/room/token-source/types.d.ts +1 -0
- package/dist/ts4.2/room/track/FrameMetadataExtractor.d.ts +19 -0
- package/dist/ts4.2/room/track/RemoteVideoTrack.d.ts +7 -7
- package/dist/ts4.2/room/track/options.d.ts +17 -5
- package/package.json +23 -18
- package/src/api/SignalClient.test.ts +4 -4
- package/src/api/SignalClient.ts +7 -3
- package/src/api/WebSocketStream.test.ts +7 -7
- package/src/e2ee/E2eeManager.ts +13 -11
- package/src/e2ee/types.ts +5 -5
- package/src/e2ee/worker/FrameCryptor.test.ts +5 -5
- package/src/e2ee/worker/FrameCryptor.ts +27 -23
- package/src/e2ee/worker/e2ee.worker.ts +5 -5
- package/src/e2ee/worker/tsconfig.json +4 -1
- package/src/{packetTrailer/PacketTrailerManager.test.ts → frameMetadata/FrameMetadataManager.test.ts} +10 -8
- package/src/{packetTrailer/PacketTrailerManager.ts → frameMetadata/FrameMetadataManager.ts} +21 -15
- package/src/{packetTrailer/packetTrailer.test.ts → frameMetadata/frameMetadata.test.ts} +1 -1
- package/src/{packetTrailer/packetTrailer.ts → frameMetadata/frameMetadata.ts} +9 -9
- package/src/{packetTrailer → frameMetadata}/types.ts +12 -6
- package/src/{packetTrailer → frameMetadata}/utils.test.ts +19 -19
- package/src/{packetTrailer → frameMetadata}/utils.ts +11 -11
- package/src/{packetTrailer/worker/packetTrailer.worker.ts → frameMetadata/worker/frameMetadata.worker.ts} +5 -5
- package/src/{packetTrailer → frameMetadata}/worker/tsconfig.json +4 -1
- package/src/index.ts +13 -2
- package/src/options.ts +9 -4
- package/src/room/PCTransport.ts +4 -0
- package/src/room/PCTransportManager.ts +4 -0
- package/src/room/RTCEngine.test.ts +143 -9
- package/src/room/RTCEngine.ts +111 -31
- package/src/room/Room.ts +10 -10
- package/src/room/participant/LocalParticipant.test.ts +19 -19
- package/src/room/participant/LocalParticipant.ts +21 -16
- package/src/room/participant/publishUtils.test.ts +6 -0
- package/src/room/participant/publishUtils.ts +4 -1
- package/src/room/rpc/client/RpcClientManager.ts +1 -1
- package/src/room/rpc/server/RpcServerManager.ts +1 -1
- package/src/room/token-source/TokenSource.ts +9 -23
- package/src/room/token-source/types.ts +1 -0
- package/src/room/token-source/utils.ts +1 -0
- package/src/room/track/{PacketTrailerExtractor.ts → FrameMetadataExtractor.ts} +8 -8
- package/src/room/track/RemoteVideoTrack.ts +7 -11
- package/src/room/track/options.ts +19 -5
- package/dist/livekit-client.pt.worker.js +0 -2
- package/dist/livekit-client.pt.worker.mjs.map +0 -1
- package/dist/src/packetTrailer/packetTrailer.d.ts.map +0 -1
- package/dist/src/packetTrailer/types.d.ts.map +0 -1
- package/dist/src/packetTrailer/utils.d.ts +0 -9
- package/dist/src/packetTrailer/worker/packetTrailer.worker.d.ts +0 -2
- package/dist/src/packetTrailer/worker/packetTrailer.worker.d.ts.map +0 -1
- package/dist/src/room/track/PacketTrailerExtractor.d.ts +0 -19
- package/dist/src/room/track/PacketTrailerExtractor.d.ts.map +0 -1
- package/dist/ts4.2/packetTrailer/utils.d.ts +0 -9
- package/dist/ts4.2/packetTrailer/worker/packetTrailer.worker.d.ts +0 -2
- package/dist/ts4.2/room/track/PacketTrailerExtractor.d.ts +0 -19
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var t,n={exports:{}};var r,i,a,o,s,c=(t||(t=1,i=n.exports,a=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"],i={},a=null;function o(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return"No console available for logging"}function d(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function u(r,i,a){return function(r){return"debug"===r&&(r="log"),typeof console!==t&&("trace"===r&&n?s:void 0!==console[r]?o(console,r):void 0!==console.log?o(console,"log"):e)}(r)||d.apply(this,arguments)}function l(e,n){var o,s,d,l=this,h="loglevel";function f(){var e;if(typeof window!==t&&h){try{e=window.localStorage[h]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(h),i=n.indexOf(r+"=");-1!==i&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch(e){}return void 0===l.levels[e]&&(e=void 0),e}}function p(e){var t=e;if("string"==typeof t&&void 0!==l.levels[t.toUpperCase()]&&(t=l.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=l.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?h+=":"+e:"symbol"==typeof e&&(h=void 0),l.name=e,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=n||u,l.getLevel=function(){return null!=d?d:null!=s?s:o},l.setLevel=function(e,n){return d=p(e),!1!==n&&function(e){var n=(r[e]||"silent").toUpperCase();if(typeof window!==t&&h){try{return void(window.localStorage[h]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"="+n+";"}catch(e){}}}(d),c.call(l)},l.setDefaultLevel=function(e){s=p(e),f()||l.setLevel(e,!1)},l.resetLevel=function(){d=null,function(){if(typeof window!==t&&h){try{window.localStorage.removeItem(h)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),c.call(l)},l.enableAll=function(e){l.setLevel(l.levels.TRACE,e)},l.disableAll=function(e){l.setLevel(l.levels.SILENT,e)},l.rebuild=function(){if(a!==l&&(o=p(a.getLevel())),c.call(l),a===l)for(var e in i)i[e].rebuild()},o=p(a?a.getLevel():"WARN");var y=f();null!=y&&(d=p(y)),c.call(l)}(a=new 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=i[e];return t||(t=i[e]=new l(e,a.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=h),a},a.getLoggers=function(){return i},a.default=a,a},(r=n).exports?r.exports=a():i.log=a()),n.exports);!function(e){e[e.trace=0]="trace",e[e.debug=1]="debug",e[e.info=2]="info",e[e.warn=3]="warn",e[e.error=4]="error",e[e.silent=5]="silent"}(o||(o={})),function(e){e.Default="livekit",e.Room="livekit-room",e.TokenSource="livekit-token-source",e.Participant="livekit-participant",e.Track="livekit-track",e.Publication="livekit-track-publication",e.Engine="livekit-engine",e.Signal="livekit-signal",e.PCManager="livekit-pc-manager",e.PCTransport="livekit-pc-transport",e.E2EE="lk-e2ee",e.DataTracks="livekit-data-tracks"}(s||(s={}));let d=c.getLogger(s.Default);function u(e,t){const n=c.getLogger(e);return n.setDefaultLevel(d.getLevel()),n}Object.values(s).map((e=>c.getLogger(e))),d.setDefaultLevel(o.info);const l=c.getLogger(s.E2EE);var h,f=Object.defineProperty,p=(e,t,n)=>((e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class y{constructor(){p(this,"_locking"),p(this,"_locks"),this._locking=Promise.resolve(),this._locks=0}isLocked(){return this._locks>0}lock(){let e;this._locks+=1;const t=new Promise((t=>e=()=>{this._locks-=1,t()})),n=this._locking.then((()=>e));return this._locking=this._locking.then((()=>t)),n}}!function(e){e[e.WAITING=0]="WAITING",e[e.RUNNING=1]="RUNNING",e[e.COMPLETED=2]="COMPLETED"}(h||(h={}));const m="AES-GCM",g={key:10,delta:3,audio:1,empty:0},b={sharedKey:!1,ratchetSalt:"LKFrameEncryptionKey",ratchetWindowSize:8,failureTolerance:10,keyringSize:16,keySize:128};function v(e,t){if(!e)throw new Error(t)}const k=34028234663852886e22,w=-34028234663852886e22,T=4294967295,S=2147483647,I=-2147483648;function E(e){if("number"!=typeof e)throw new Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>S||e<I)throw new Error("invalid int 32: "+e)}function N(e){if("number"!=typeof e)throw new Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>T||e<0)throw new Error("invalid uint 32: "+e)}function A(e){if("number"!=typeof e)throw new Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>k||e<w))throw new Error("invalid float 32: "+e)}const L=Symbol("@bufbuild/protobuf/enum-type");function C(e){const t=e[L];return v(t,"missing enum type on enum object"),t}function R(e,t,n,r){e[L]=U(t,n.map((t=>({no:t.no,name:t.name,localName:e[t.no]}))))}function U(e,t,n){const r=Object.create(null),i=Object.create(null),a=[];for(const e of t){const t=P(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName:e=>r[e],findNumber:e=>i[e]}}function O(e,t,n){const r={};for(const e of t){const t=P(e);r[t.localName]=t.no,r[t.no]=t.localName}return R(r,e,t),r}function P(e){return"localName"in e?e:Object.assign(Object.assign({},e),{localName:e.name})}class _{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){const n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){const n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error("cannot decode ".concat(this.getType().typeName," from JSON: ").concat(e instanceof Error?e.message:String(e)))}return this.fromJson(n,t)}toBinary(e){const t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){const t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){var t;const n=this.toJson(e);return JSON.stringify(n,null,null!==(t=null==e?void 0:e.prettySpaces)&&void 0!==t?t:0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}}function D(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,0==(128&r))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(15&n)<<28,t=(112&n)>>4,0==(128&n))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,0==(128&r))return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function F(e,t,n){for(let r=0;r<28;r+=7){const i=e>>>r,a=!(i>>>7==0&&0==t),o=255&(a?128|i:i);if(n.push(o),!a)return}const r=e>>>28&15|(7&t)<<4,i=!(t>>3==0);if(n.push(255&(i?128|r:r)),i){for(let e=3;e<31;e+=7){const r=t>>>e,i=!(r>>>7==0),a=255&(i?128|r:r);if(n.push(a),!i)return}n.push(t>>>31&1)}}const x=4294967296;function B(e){const t="-"===e[0];t&&(e=e.slice(1));const n=1e6;let r=0,i=0;function a(t,a){const o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=x&&(i+=r/x|0,r%=x)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?j(r,i):K(r,i)}function M(e,t){var n=function(e,t){return{lo:e>>>0,hi:t>>>0}}(e,t);if(e=n.lo,(t=n.hi)<=2097151)return String(x*t+e);const r=16777215&(e>>>24|t<<8),i=t>>16&65535;let a=(16777215&e)+6777216*r+6710656*i,o=r+8147497*i,s=2*i;const c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+V(o)+V(a)}function K(e,t){return{lo:0|e,hi:0|t}}function j(e,t){return t=~t,e?e=1+~e:t+=1,K(e,t)}const V=e=>{const t=String(e);return"0000000".slice(t.length)+t};function W(e,t){if(e>=0){for(;e>127;)t.push(127&e|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(127&e|128),e>>=7;t.push(1)}}function q(){let e=this.buf[this.pos++],t=127&e;if(0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<7,0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<14,0==(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<21,0==(128&e))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(15&e)<<28;for(let t=5;0!=(128&e)&&t<10;t++)e=this.buf[this.pos++];if(0!=(128&e))throw new Error("invalid varint");return this.assertBounds(),t>>>0}const G=function(){const e=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof e.getBigInt64&&"function"==typeof e.getBigUint64&&"function"==typeof e.setBigInt64&&"function"==typeof e.setBigUint64&&("object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const t=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(e){const r="bigint"==typeof e?e:BigInt(e);if(r>n||r<t)throw new Error("int64 invalid: ".concat(e));return r},uParse(e){const t="bigint"==typeof e?e:BigInt(e);if(t>i||t<r)throw new Error("uint64 invalid: ".concat(e));return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec:(t,n)=>(e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)),uDec:(t,n)=>(e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0))}}const t=e=>v(/^-?[0-9]+$/.test(e),"int64 invalid: ".concat(e)),n=e=>v(/^[0-9]+$/.test(e),"uint64 invalid: ".concat(e));return{zero:"0",supported:!1,parse:e=>("string"!=typeof e&&(e=e.toString()),t(e),e),uParse:e=>("string"!=typeof e&&(e=e.toString()),n(e),e),enc:e=>("string"!=typeof e&&(e=e.toString()),t(e),B(e)),uEnc:e=>("string"!=typeof e&&(e=e.toString()),n(e),B(e)),dec:(e,t)=>function(e,t){let n=K(e,t);const r=2147483648&n.hi;r&&(n=j(n.lo,n.hi));const i=M(n.lo,n.hi);return r?"-"+i:i}(e,t),uDec:(e,t)=>M(e,t)}}();var X,J,H;function z(e,t,n){if(t===n)return!0;if(e==X.BYTES){if(!(t instanceof Uint8Array&&n instanceof Uint8Array))return!1;if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case X.UINT64:case X.FIXED64:case X.INT64:case X.SFIXED64:case X.SINT64:return t==n}return!1}function Y(e,t){switch(e){case X.BOOL:return!1;case X.UINT64:case X.FIXED64:case X.INT64:case X.SFIXED64:case X.SINT64:return 0==t?G.zero:"0";case X.DOUBLE:case X.FLOAT:return 0;case X.BYTES:return new Uint8Array(0);case X.STRING:return"";default:return 0}}function Q(e,t){switch(e){case X.BOOL:return!1===t;case X.STRING:return""===t;case X.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return 0==t}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a,o,s=[],c=!0,d=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){d=!0,i=e}finally{try{if(!c&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(d)throw i}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return $(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?$(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}!function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"}(X||(X={})),function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING"}(J||(J={})),function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"}(H||(H={}));class ee{constructor(e){this.stack=[],this.textEncoder=null!=e?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(N(e);e>127;)this.buf.push(127&e|128),e>>>=7;return this.buf.push(e),this}int32(e){return E(e),W(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){A(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){N(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){E(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return E(e),W(e=(e<<1^e>>31)>>>0,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=G.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=G.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=G.enc(e);return F(t.lo,t.hi,this.buf),this}sint64(e){let t=G.enc(e),n=t.hi>>31;return F(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=G.uEnc(e);return F(t.lo,t.hi,this.buf),this}}class te{constructor(e,t){this.varint64=D,this.uint32=q,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=null!=t?t:new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=7&e;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case H.Varint:for(;128&this.buf[this.pos++];);break;case H.Bit64:this.pos+=4;case H.Bit32:this.pos+=4;break;case H.LengthDelimited:let n=this.uint32();this.pos+=n;break;case H.StartGroup:for(;;){const e=Z(this.tag(),2),n=e[0],r=e[1];if(r===H.EndGroup){if(void 0!==t&&n!==t)throw new Error("invalid end group tag");break}this.skip(r,n)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let e=this.uint32();return e>>>1^-(1&e)}int64(){return G.dec(...this.varint64())}uint64(){return G.uDec(...this.varint64())}sint64(){let e=Z(this.varint64(),2),t=e[0],n=e[1],r=-(1&t);return t=(t>>>1|(1&n)<<31)^r,n=n>>>1^r,G.dec(t,n)}bool(){let e=Z(this.varint64(),2),t=e[0],n=e[1];return 0!==t||0!==n}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return G.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return G.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}function ne(e){const t=e.field.localName,n=Object.create(null);return n[t]=function(e){const t=e.field;if(t.repeated)return[];if(void 0!==t.default)return t.default;switch(t.kind){case"enum":return t.T.values[0].no;case"scalar":return Y(t.T,t.L);case"message":const e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case"map":throw"map fields are not allowed to be extensions"}}(e),[n,()=>n[t]]}let re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),ie=[];for(let e=0;e<re.length;e++)ie[re[e].charCodeAt(0)]=e;ie["-".charCodeAt(0)]=re.indexOf("+"),ie["_".charCodeAt(0)]=re.indexOf("/");const ae={dec(e){let t=3*e.length/4;"="==e[e.length-2]?t-=2:"="==e[e.length-1]&&(t-=1);let n,r=new Uint8Array(t),i=0,a=0,o=0;for(let t=0;t<e.length;t++){if(n=ie[e.charCodeAt(t)],void 0===n)switch(e[t]){case"=":a=0;case"\n":case"\r":case"\t":case" ":continue;default:throw Error("invalid base64 string.")}switch(a){case 0:o=n,a=1;break;case 1:r[i++]=o<<2|(48&n)>>4,o=n,a=2;break;case 2:r[i++]=(15&o)<<4|(60&n)>>2,o=n,a=3;break;case 3:r[i++]=(3&o)<<6|n,a=0}}if(1==a)throw Error("invalid base64 string.");return r.subarray(0,i)},enc(e){let t,n="",r=0,i=0;for(let a=0;a<e.length;a++)switch(t=e[a],r){case 0:n+=re[t>>2],i=(3&t)<<4,r=1;break;case 1:n+=re[i|t>>4],i=(15&t)<<2,r=2;break;case 2:n+=re[i|t>>6],n+=re[63&t],r=0}return r&&(n+=re[i],n+="=",1==r&&(n+="=")),n}};function oe(e,t,n){de(t,e);const r=t.runtime.bin.makeReadOptions(n),i=function(e,t){if(!t.repeated&&("enum"==t.kind||"scalar"==t.kind)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter((e=>e.no===t.no))}(e.getType().runtime.bin.listUnknownFields(e),t.field),a=Z(ne(t),2),o=a[0],s=a[1];for(const e of i)t.runtime.bin.readField(o,r.readerFactory(e.data),t.field,e.wireType,r);return s()}function se(e,t,n,r){de(t,e);const i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(ce(e,t)){const n=e.getType().runtime.bin.listUnknownFields(e).filter((e=>e.no!=t.field.no));e.getType().runtime.bin.discardUnknownFields(e);for(const t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}const o=a.writerFactory();let s=t.field;s.opt||s.repeated||"enum"!=s.kind&&"scalar"!=s.kind||(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);const c=i.readerFactory(o.finish());for(;c.pos<c.len;){const t=Z(c.tag(),2),n=t[0],r=t[1],i=c.skip(r,n);e.getType().runtime.bin.onUnknownField(e,n,r,i)}}function ce(e,t){const n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find((e=>e.no==t.field.no))}function de(e,t){v(e.extendee.typeName==t.getType().typeName,"extension ".concat(e.typeName," can only be applied to message ").concat(e.extendee.typeName))}function ue(e,t){const n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case"enum":case"scalar":return e.opt||e.req?void 0!==t[n]:"enum"==e.kind?t[n]!==e.T.values[0].no:!Q(e.T,t[n]);case"message":return void 0!==t[n];case"map":return Object.keys(t[n]).length>0}}function le(e,t){const n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case"map":t[n]={};break;case"enum":t[n]=r?e.T.values[0].no:void 0;break;case"scalar":t[n]=r?Y(e.T,e.L):void 0;break;case"message":t[n]=void 0}}function he(e,t){if(null===e||"object"!=typeof e)return!1;if(!Object.getOwnPropertyNames(_.prototype).every((t=>t in e&&"function"==typeof e[t])))return!1;const n=e.getType();return null!==n&&"function"==typeof n&&"typeName"in n&&"string"==typeof n.typeName&&(void 0===t||n.typeName==t.typeName)}function fe(e,t){return he(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}X.DOUBLE,X.FLOAT,X.INT64,X.UINT64,X.INT32,X.UINT32,X.BOOL,X.STRING,X.BYTES;const pe={ignoreUnknownFields:!1},ye={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function me(e){return e?Object.assign(Object.assign({},pe),e):pe}function ge(e){return e?Object.assign(Object.assign({},ye),e):ye}const be=Symbol(),ve=Symbol();function ke(e){if(null===e)return"null";switch(typeof e){case"object":return Array.isArray(e)?"array":"object";case"string":return e.length>100?"string":'"'.concat(e.split('"').join('\\"'),'"');default:return String(e)}}function we(e,t,n,r,i){let a=n.localName;if(n.repeated){if(v("map"!=n.kind),null===t)return;if(!Array.isArray(t))throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(t)));const o=e[a];for(const e of t){if(null===e)throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(e)));switch(n.kind){case"message":o.push(n.T.fromJson(e,r));break;case"enum":const t=Ie(n.T,e,r.ignoreUnknownFields,!0);t!==ve&&o.push(t);break;case"scalar":try{o.push(Se(n.T,e,n.L,!0))}catch(t){let r="cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(e));throw t instanceof Error&&t.message.length>0&&(r+=": ".concat(t.message)),new Error(r)}}}}else if("map"==n.kind){if(null===t)return;if("object"!=typeof t||Array.isArray(t))throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(t)));const s=e[a];for(const e of Object.entries(t)){var o=Z(e,2);const a=o[0],c=o[1];if(null===c)throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: map value null"));let d;try{d=Te(n.K,a)}catch(e){let r="cannot decode map key for field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}switch(n.V.kind){case"message":s[d]=n.V.T.fromJson(c,r);break;case"enum":const e=Ie(n.V.T,c,r.ignoreUnknownFields,!0);e!==ve&&(s[d]=e);break;case"scalar":try{s[d]=Se(n.V.T,c,J.BIGINT,!0)}catch(e){let r="cannot decode map value for field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a="value"),n.kind){case"message":const o=n.T;if(null===t&&"google.protobuf.Value"!=o.typeName)return;let s=e[a];he(s)?s.fromJson(t,r):(e[a]=s=o.fromJson(t,r),o.fieldWrapper&&!n.oneof&&(e[a]=o.fieldWrapper.unwrapField(s)));break;case"enum":const c=Ie(n.T,t,r.ignoreUnknownFields,!1);switch(c){case be:le(n,e);break;case ve:break;default:e[a]=c}break;case"scalar":try{const r=Se(n.T,t,n.L,!1);if(r===be)le(n,e);else e[a]=r}catch(e){let r="cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ke(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}}}function Te(e,t){if(e===X.BOOL)switch(t){case"true":t=!0;break;case"false":t=!1}return Se(e,t,J.BIGINT,!0).toString()}function Se(e,t,n,r){if(null===t)return r?Y(e,n):be;switch(e){case X.DOUBLE:case X.FLOAT:if("NaN"===t)return Number.NaN;if("Infinity"===t)return Number.POSITIVE_INFINITY;if("-Infinity"===t)return Number.NEGATIVE_INFINITY;if(""===t)break;if("string"==typeof t&&t.trim().length!==t.length)break;if("string"!=typeof t&&"number"!=typeof t)break;const r=Number(t);if(Number.isNaN(r))break;if(!Number.isFinite(r))break;return e==X.FLOAT&&A(r),r;case X.INT32:case X.FIXED32:case X.SFIXED32:case X.SINT32:case X.UINT32:let i;if("number"==typeof t?i=t:"string"==typeof t&&t.length>0&&t.trim().length===t.length&&(i=Number(t)),void 0===i)break;return e==X.UINT32||e==X.FIXED32?N(i):E(i),i;case X.INT64:case X.SFIXED64:case X.SINT64:if("number"!=typeof t&&"string"!=typeof t)break;const a=G.parse(t);return n?a.toString():a;case X.FIXED64:case X.UINT64:if("number"!=typeof t&&"string"!=typeof t)break;const o=G.uParse(t);return n?o.toString():o;case X.BOOL:if("boolean"!=typeof t)break;return t;case X.STRING:if("string"!=typeof t)break;try{encodeURIComponent(t)}catch(e){throw new Error("invalid UTF8")}return t;case X.BYTES:if(""===t)return new Uint8Array(0);if("string"!=typeof t)break;return ae.dec(t)}throw new Error}function Ie(e,t,n,r){if(null===t)return"google.protobuf.NullValue"==e.typeName?0:r?e.values[0].no:be;switch(typeof t){case"number":if(Number.isInteger(t))return t;break;case"string":const r=e.findName(t);if(void 0!==r)return r.no;if(n)return ve}throw new Error("cannot decode enum ".concat(e.typeName," from JSON: ").concat(ke(t)))}function Ee(e){return!(!e.repeated&&"map"!=e.kind)||!e.oneof&&("message"!=e.kind&&(!e.opt&&!e.req))}function Ne(e,t,n){if("map"==e.kind){v("object"==typeof t&&null!=t);const o={},s=Object.entries(t);switch(e.V.kind){case"scalar":for(const t of s){var r=Z(t,2);const n=r[0],i=r[1];o[n.toString()]=Le(e.V.T,i)}break;case"message":for(const e of s){var i=Z(e,2);const t=i[0],r=i[1];o[t.toString()]=r.toJson(n)}break;case"enum":const t=e.V.T;for(const e of s){var a=Z(e,2);const r=a[0],i=a[1];o[r.toString()]=Ae(t,i,n.enumAsInteger)}}return n.emitDefaultValues||s.length>0?o:void 0}if(e.repeated){v(Array.isArray(t));const r=[];switch(e.kind){case"scalar":for(let n=0;n<t.length;n++)r.push(Le(e.T,t[n]));break;case"enum":for(let i=0;i<t.length;i++)r.push(Ae(e.T,t[i],n.enumAsInteger));break;case"message":for(let e=0;e<t.length;e++)r.push(t[e].toJson(n))}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case"scalar":return Le(e.T,t);case"enum":return Ae(e.T,t,n.enumAsInteger);case"message":return fe(e.T,t).toJson(n)}}function Ae(e,t,n){var r;if(v("number"==typeof t),"google.protobuf.NullValue"==e.typeName)return null;if(n)return t;const i=e.findNumber(t);return null!==(r=null==i?void 0:i.name)&&void 0!==r?r:t}function Le(e,t){switch(e){case X.INT32:case X.SFIXED32:case X.SINT32:case X.FIXED32:case X.UINT32:return v("number"==typeof t),t;case X.FLOAT:case X.DOUBLE:return v("number"==typeof t),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t;case X.STRING:return v("string"==typeof t),t;case X.BOOL:return v("boolean"==typeof t),t;case X.UINT64:case X.FIXED64:case X.INT64:case X.SFIXED64:case X.SINT64:return v("bigint"==typeof t||"string"==typeof t||"number"==typeof t),t.toString();case X.BYTES:return v(t instanceof Uint8Array),ae.enc(t)}}const Ce=Symbol("@bufbuild/protobuf/unknown-fields"),Re={readUnknownFields:!0,readerFactory:e=>new te(e)},Ue={writeUnknownFields:!0,writerFactory:()=>new ee};function Oe(e){return e?Object.assign(Object.assign({},Re),e):Re}function Pe(e){return e?Object.assign(Object.assign({},Ue),e):Ue}function _e(e,t,n,r,i){let a=n.repeated,o=n.localName;switch(n.oneof&&((e=e[n.oneof.localName]).case!=o&&delete e.value,e.case=o,o="value"),n.kind){case"scalar":case"enum":const s="enum"==n.kind?X.INT32:n.T;let c=xe;if("scalar"==n.kind&&n.L>0&&(c=Fe),a){let n=e[o];if(r==H.LengthDelimited&&s!=X.STRING&&s!=X.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case"message":const d=n.T;a?e[o].push(De(t,new d,i,n)):he(e[o])?De(t,e[o],i,n):(e[o]=De(t,new d,i,n),!d.fieldWrapper||n.oneof||n.repeated||(e[o]=d.fieldWrapper.unwrapField(e[o])));break;case"map":let u=function(e,t,n){const r=t.uint32(),i=t.pos+r;let a,o;for(;t.pos<i;){switch(Z(t.tag(),1)[0]){case 1:a=xe(t,e.K);break;case 2:switch(e.V.kind){case"scalar":o=xe(t,e.V.T);break;case"enum":o=t.int32();break;case"message":o=De(t,new e.V.T,n,void 0)}}}void 0===a&&(a=Y(e.K,J.BIGINT));"string"!=typeof a&&"number"!=typeof a&&(a=a.toString());if(void 0===o)switch(e.V.kind){case"scalar":o=Y(e.V.T,J.BIGINT);break;case"enum":o=e.V.T.values[0].no;break;case"message":o=new e.V.T}return[a,o]}(n,t,i),l=Z(u,2),h=l[0],f=l[1];e[o][h]=f}}function De(e,t,n,r){const i=t.getType().runtime.bin,a=null==r?void 0:r.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function Fe(e,t){const n=xe(e,t);return"bigint"==typeof n?n.toString():n}function xe(e,t){switch(t){case X.STRING:return e.string();case X.BOOL:return e.bool();case X.DOUBLE:return e.double();case X.FLOAT:return e.float();case X.INT32:return e.int32();case X.INT64:return e.int64();case X.UINT64:return e.uint64();case X.FIXED64:return e.fixed64();case X.BYTES:return e.bytes();case X.FIXED32:return e.fixed32();case X.SFIXED32:return e.sfixed32();case X.SFIXED64:return e.sfixed64();case X.SINT64:return e.sint64();case X.UINT32:return e.uint32();case X.SINT32:return e.sint32()}}function Be(e,t,n,r){v(void 0!==t);const i=e.repeated;switch(e.kind){case"scalar":case"enum":let o="enum"==e.kind?X.INT32:e.T;if(i)if(v(Array.isArray(t)),e.packed)!function(e,t,n,r){if(!r.length)return;e.tag(n,H.LengthDelimited).fork();let i=Z(Ve(t),2)[1];for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}(n,o,e.no,t);else for(const r of t)je(n,o,e.no,r);else je(n,o,e.no,t);break;case"message":if(i){v(Array.isArray(t));for(const i of t)Ke(n,r,e,i)}else Ke(n,r,e,t);break;case"map":v("object"==typeof t&&null!=t);for(const i of Object.entries(t)){var a=Z(i,2);Me(n,r,e,a[0],a[1])}}}function Me(e,t,n,r,i){e.tag(n.no,H.LengthDelimited),e.fork();let a=r;switch(n.K){case X.INT32:case X.FIXED32:case X.UINT32:case X.SFIXED32:case X.SINT32:a=Number.parseInt(r);break;case X.BOOL:v("true"==r||"false"==r),a="true"==r}switch(je(e,n.K,1,a),n.V.kind){case"scalar":je(e,n.V.T,2,i);break;case"enum":je(e,X.INT32,2,i);break;case"message":v(void 0!==i),e.tag(2,H.LengthDelimited).bytes(i.toBinary(t))}e.join()}function Ke(e,t,n,r){const i=fe(n.T,r);n.delimited?e.tag(n.no,H.StartGroup).raw(i.toBinary(t)).tag(n.no,H.EndGroup):e.tag(n.no,H.LengthDelimited).bytes(i.toBinary(t))}function je(e,t,n,r){v(void 0!==r);let i=Z(Ve(t),2),a=i[0],o=i[1];e.tag(n,a)[o](r)}function Ve(e){let t=H.Varint;switch(e){case X.BYTES:case X.STRING:t=H.LengthDelimited;break;case X.DOUBLE:case X.FIXED64:case X.SFIXED64:t=H.Bit64;break;case X.FIXED32:case X.SFIXED32:case X.FLOAT:t=H.Bit32}return[t,X[e].toLowerCase()]}function We(e){if(void 0===e)return e;if(he(e))return e.clone();if(e instanceof Uint8Array){const t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function qe(e){return e instanceof Uint8Array?e:new Uint8Array(e)}class Ge{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){const e={};for(const t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){const e={};for(const t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||(this.all=this._normalizer(this._fields)),this.all}byNumber(){return this.numbersAsc||(this.numbersAsc=this.list().concat().sort(((e,t)=>e.no-t.no))),this.numbersAsc}byMember(){if(!this.members){this.members=[];const e=this.members;let t;for(const n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}}function Xe(e,t){const n=He(e);return t?n:Ze($e(n))}const Je=He;function He(e){let t=!1;const n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case"_":t=!0;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join("")}const ze=new Set(["constructor","toString","toJSON","valueOf"]),Ye=new Set(["getType","clone","equals","fromBinary","fromJson","fromJsonString","toBinary","toJson","toJsonString","toObject"]),Qe=e=>"".concat(e,"$"),$e=e=>Ye.has(e)?Qe(e):e,Ze=e=>ze.has(e)?Qe(e):e;class et{constructor(e){this.kind="oneof",this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Xe(e,!1)}addField(e){v(e.oneof===this,"field ".concat(e.name," not one of ").concat(this.name)),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}}const tt=(nt=e=>new Ge(e,(e=>function(e,t){var n,r,i,a,o,s;const c=[];let d;for(const t of"function"==typeof e?e():e){const e=t;if(e.localName=Xe(t.name,void 0!==t.oneof),e.jsonName=null!==(n=t.jsonName)&&void 0!==n?n:Je(t.name),e.repeated=null!==(r=t.repeated)&&void 0!==r&&r,"scalar"==t.kind&&(e.L=null!==(i=t.L)&&void 0!==i?i:J.BIGINT),e.delimited=null!==(a=t.delimited)&&void 0!==a&&a,e.req=null!==(o=t.req)&&void 0!==o&&o,e.opt=null!==(s=t.opt)&&void 0!==s&&s,void 0===t.packed&&(e.packed="enum"==t.kind||"scalar"==t.kind&&t.T!=X.BYTES&&t.T!=X.STRING),void 0!==t.oneof){const n="string"==typeof t.oneof?t.oneof:t.oneof.name;d&&d.name==n||(d=new et(n)),e.oneof=d,d.addField(e)}c.push(e)}return c}(e))),rt=e=>{for(const t of e.getType().fields.byMember()){if(t.opt)continue;const n=t.localName,r=e;if(t.repeated)r[n]=[];else switch(t.kind){case"oneof":r[n]={case:void 0};break;case"enum":r[n]=0;break;case"map":r[n]={};break;case"scalar":r[n]=Y(t.T,t.L)}}},{syntax:"proto3",json:{makeReadOptions:me,makeWriteOptions:ge,readMessage(e,t,n,r){if(null==t||Array.isArray(t)||"object"!=typeof t)throw new Error("cannot decode message ".concat(e.typeName," from JSON: ").concat(ke(t)));r=null!=r?r:new e;const i=new Map,a=n.typeRegistry;for(const s of Object.entries(t)){var o=Z(s,2);const t=o[0],c=o[1],d=e.fields.findJsonName(t);if(d){if(d.oneof){if(null===c&&"scalar"==d.kind)continue;const n=i.get(d.oneof);if(void 0!==n)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: multiple keys for oneof "').concat(d.oneof.name,'" present: "').concat(n,'", "').concat(t,'"'));i.set(d.oneof,t)}we(r,c,d,n,e)}else{let i=!1;if((null==a?void 0:a.findExtension)&&t.startsWith("[")&&t.endsWith("]")){const o=a.findExtension(t.substring(1,t.length-1));if(o&&o.extendee.typeName==e.typeName){i=!0;const e=Z(ne(o),2),t=e[0],a=e[1];we(t,c,o.field,n,o),se(r,o,a(),n)}}if(!i&&!n.ignoreUnknownFields)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: key "').concat(t,'" is unknown'))}}return r},writeMessage(e,t){const n=e.getType(),r={};let i;try{for(i of n.fields.byNumber()){if(!ue(i,e)){if(i.req)throw"required field not set";if(!t.emitDefaultValues)continue;if(!Ee(i))continue}const n=Ne(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t);void 0!==n&&(r[t.useProtoFieldName?i.name:i.jsonName]=n)}const a=t.typeRegistry;if(null==a?void 0:a.findExtensionFor)for(const i of n.runtime.bin.listUnknownFields(e)){const o=a.findExtensionFor(n.typeName,i.no);if(o&&ce(e,o)){const n=oe(e,o,t),i=Ne(o.field,n,t);void 0!==i&&(r[o.field.jsonName]=i)}}}catch(e){const t=i?"cannot encode field ".concat(n.typeName,".").concat(i.name," to JSON"):"cannot encode message ".concat(n.typeName," to JSON"),r=e instanceof Error?e.message:String(e);throw new Error(t+(r.length>0?": ".concat(r):""))}return r},readScalar:(e,t,n)=>Se(e,t,null!=n?n:J.BIGINT,!0),writeScalar(e,t,n){if(void 0!==t)return n||Q(e,t)?Le(e,t):void 0},debug:ke},bin:{makeReadOptions:Oe,makeWriteOptions:Pe,listUnknownFields(e){var t;return null!==(t=e[Ce])&&void 0!==t?t:[]},discardUnknownFields(e){delete e[Ce]},writeUnknownFields(e,t){const n=e[Ce];if(n)for(const e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){const i=e;Array.isArray(i[Ce])||(i[Ce]=[]),i[Ce].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){const a=e.getType(),o=i?t.len:t.pos+n;let s,c;for(;t.pos<o;){var d=Z(t.tag(),2);if(s=d[0],c=d[1],!0===i&&c==H.EndGroup)break;const n=a.fields.find(s);if(n)_e(e,t,n,c,r);else{const n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n)}}if(i&&(c!=H.EndGroup||s!==n))throw new Error("invalid end group tag")},readField:_e,writeMessage(e,t,n){const r=e.getType();for(const i of r.fields.byNumber())if(ue(i,e))Be(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n);else if(i.req)throw new Error("cannot encode field ".concat(r.typeName,".").concat(i.name," to binary: required field not set"));return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){void 0!==t&&Be(e,t,n,r)}},util:Object.assign(Object.assign({},{setEnumType:R,initPartial(e,t){if(void 0===e)return;const n=t.getType();for(const i of n.fields.byMember()){const n=i.localName,a=t,o=e;if(null!=o[n])switch(i.kind){case"oneof":const e=o[n].case;if(void 0===e)continue;const t=i.findField(e);let s=o[n].value;t&&"message"==t.kind&&!he(s,t.T)?s=new t.T(s):t&&"scalar"===t.kind&&t.T===X.BYTES&&(s=qe(s)),a[n]={case:e,value:s};break;case"scalar":case"enum":let c=o[n];i.T===X.BYTES&&(c=i.repeated?c.map(qe):qe(c)),a[n]=c;break;case"map":switch(i.V.kind){case"scalar":case"enum":if(i.V.T===X.BYTES)for(const e of Object.entries(o[n])){var r=Z(e,2);const t=r[0],i=r[1];a[n][t]=qe(i)}else Object.assign(a[n],o[n]);break;case"message":const e=i.V.T;for(const t of Object.keys(o[n])){let r=o[n][t];e.fieldWrapper||(r=new e(r)),a[n][t]=r}}break;case"message":const d=i.T;if(i.repeated)a[n]=o[n].map((e=>he(e,d)?e:new d(e)));else{const e=o[n];d.fieldWrapper?"google.protobuf.BytesValue"===d.typeName?a[n]=qe(e):a[n]=e:a[n]=he(e,d)?e:new d(e)}}}},equals:(e,t,n)=>t===n||!(!t||!n)&&e.fields.byMember().every((e=>{const r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case"message":return r.every(((t,n)=>e.T.equals(t,i[n])));case"scalar":return r.every(((t,n)=>z(e.T,t,i[n])));case"enum":return r.every(((e,t)=>z(X.INT32,e,i[t])))}throw new Error("repeated cannot contain ".concat(e.kind))}switch(e.kind){case"message":let t=r,n=i;return e.T.fieldWrapper&&(void 0===t||he(t)||(t=e.T.fieldWrapper.wrapField(t)),void 0===n||he(n)||(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case"enum":return z(X.INT32,r,i);case"scalar":return z(e.T,r,i);case"oneof":if(r.case!==i.case)return!1;const a=e.findField(r.case);if(void 0===a)return!0;switch(a.kind){case"message":return a.T.equals(r.value,i.value);case"enum":return z(X.INT32,r.value,i.value);case"scalar":return z(a.T,r.value,i.value)}throw new Error("oneof cannot contain ".concat(a.kind));case"map":const o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case"message":const t=e.V.T;return o.every((e=>t.equals(r[e],i[e])));case"enum":return o.every((e=>z(X.INT32,r[e],i[e])));case"scalar":const n=e.V.T;return o.every((e=>z(n,r[e],i[e])))}}})),clone(e){const t=e.getType(),n=new t,r=n;for(const n of t.fields.byMember()){const t=e[n.localName];let a;if(n.repeated)a=t.map(We);else if("map"==n.kind){a=r[n.localName];for(const e of Object.entries(t)){var i=Z(e,2);const t=i[0],n=i[1];a[t]=We(n)}}else a="oneof"==n.kind?n.findField(t.case)?{case:t.case,value:We(t.value)}:{case:void 0}:We(t);r[n.localName]=a}for(const n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}),{newFieldList:nt,initFields:rt}),makeMessageType(e,t,n){return function(e,t,n,r){var i;const a=null!==(i=null==r?void 0:r.localName)&&void 0!==i?i:t.substring(t.lastIndexOf(".")+1),o={[a]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[a];return Object.setPrototypeOf(o.prototype,new _),Object.assign(o,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary:(e,t)=>(new o).fromBinary(e,t),fromJson:(e,t)=>(new o).fromJson(e,t),fromJsonString:(e,t)=>(new o).fromJsonString(e,t),equals:(t,n)=>e.util.equals(o,t,n)}),o}(this,e,t,n)},makeEnum:O,makeEnumType:U,getEnumType:C,makeExtension(e,t,n){return function(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){const n="function"==typeof r?r():r;n.name=t.split(".").pop(),n.jsonName="[".concat(t,"]"),i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}(this,e,t,n)}});var nt,rt;const it=tt.makeEnum("livekit.TrackType",[{no:0,name:"AUDIO"},{no:1,name:"VIDEO"},{no:2,name:"DATA"}]),at=tt.makeEnum("livekit.TrackSource",[{no:0,name:"UNKNOWN"},{no:1,name:"CAMERA"},{no:2,name:"MICROPHONE"},{no:3,name:"SCREEN_SHARE"},{no:4,name:"SCREEN_SHARE_AUDIO"}]),ot=tt.makeEnum("livekit.StreamState",[{no:0,name:"ACTIVE"},{no:1,name:"PAUSED"}]);class st extends Error{constructor(e,t,n){super(t||"an error has occurred"),this.name="LiveKitError",this.code=e,void 0!==(null==n?void 0:n.cause)&&(this.cause=null==n?void 0:n.cause)}}var ct,dt,ut,lt,ht,ft,pt,yt;!function(e){e[e.NotAllowed=0]="NotAllowed",e[e.ServerUnreachable=1]="ServerUnreachable",e[e.InternalError=2]="InternalError",e[e.Cancelled=3]="Cancelled",e[e.LeaveRequest=4]="LeaveRequest",e[e.Timeout=5]="Timeout",e[e.WebSocket=6]="WebSocket",e[e.ServiceNotFound=7]="ServiceNotFound"}(ct||(ct={})),function(e){e[e.AlreadyOpened=0]="AlreadyOpened",e[e.AbnormalEnd=1]="AbnormalEnd",e[e.DecodeFailed=2]="DecodeFailed",e[e.LengthExceeded=3]="LengthExceeded",e[e.Incomplete=4]="Incomplete",e[e.HandlerAlreadyRegistered=7]="HandlerAlreadyRegistered",e[e.EncryptionTypeMismatch=8]="EncryptionTypeMismatch"}(dt||(dt={})),function(e){e.PermissionDenied="PermissionDenied",e.NotFound="NotFound",e.DeviceInUse="DeviceInUse",e.Other="Other"}(ut||(ut={})),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}}(ut||(ut={})),function(e){e[e.InvalidKey=0]="InvalidKey",e[e.MissingKey=1]="MissingKey",e[e.InternalError=2]="InternalError"}(lt||(lt={}));class mt extends st{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:lt.InternalError,n=arguments.length>2?arguments[2]:void 0;super(40,e),this.reason=t,this.participantIdentity=n}}function gt(e){return"type"in e}function bt(e,t){const n=(new TextEncoder).encode(t);switch(e){case"HKDF":return{name:"HKDF",salt:n,hash:"SHA-256",info:new ArrayBuffer(128)};case"PBKDF2":return{name:"PBKDF2",salt:n,hash:"SHA-256",iterations:1e5};default:throw new Error("algorithm ".concat(e," is currently unsupported"))}}function vt(t,n){return e(this,void 0,void 0,(function*(){const e=bt(t.algorithm.name,n.ratchetSalt),r=yield crypto.subtle.deriveKey(e,t,{name:m,length:n.keySize},!1,["encrypt","decrypt"]);return{material:t,encryptionKey:r}}))}!function(e){e.SetKey="setKey",e.RatchetRequest="ratchetRequest",e.KeyRatcheted="keyRatcheted"}(ht||(ht={})),function(e){e.KeyRatcheted="keyRatcheted"}(ft||(ft={})),function(e){e.ParticipantEncryptionStatusChanged="participantEncryptionStatusChanged",e.EncryptionError="encryptionError"}(pt||(pt={})),function(e){e.Error="cryptorError"}(yt||(yt={}));class kt{static makeIV(e){const t=new ArrayBuffer(12),n=new DataView(t),r=crypto.getRandomValues(new Uint32Array(1));return n.setUint32(0,r[0]),n.setUint32(4,e),n.setUint32(8,e-kt.sendCount%65535),kt.sendCount++,t}static encrypt(t,n){return e(this,void 0,void 0,(function*(){const e=kt.makeIV(performance.now()),r=yield n.getKeySet();if(!r)throw new Error("No key set found");const i=yield crypto.subtle.encrypt({name:m,iv:e},r.encryptionKey,new Uint8Array(t));return{payload:new Uint8Array(i),iv:new Uint8Array(e),keyIndex:n.getCurrentKeyIndex()}}))}static decrypt(t,n,r){return e(this,arguments,void 0,(function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=arguments.length>4?arguments[4]:void 0,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{ratchetCount:0};return function*(){const o=yield n.getKeySet(r);if(!o)throw new Error("No key set found");try{const n=yield crypto.subtle.decrypt({name:m,iv:t},o.encryptionKey,new Uint8Array(e));return{payload:new Uint8Array(n)}}catch(s){if(n.keyProviderOptions.ratchetWindowSize>0){if(a.ratchetCount<n.keyProviderOptions.ratchetWindowSize){let s,c;l.debug("DataCryptor: ratcheting key attempt ".concat(a.ratchetCount," of ").concat(n.keyProviderOptions.ratchetWindowSize,", for data packet")),(null!=i?i:o)===n.getKeySet(r)&&(c=yield n.ratchetKey(r,!1),s=yield vt(c.cryptoKey,n.keyProviderOptions));const d=yield kt.decrypt(e,t,n,r,i,{ratchetCount:a.ratchetCount+1,encryptionKey:null==s?void 0:s.encryptionKey});return d&&s&&(null!=i?i:o)===n.getKeySet(r)&&(n.setKeySet(s,r,c),n.setCurrentKeyIndex(r)),d}throw l.warn("DataCryptor: maximum ratchet attempts exceeded"),new mt("DataCryptor: valid key missing for participant ".concat(n.participantIdentity),lt.InvalidKey,n.participantIdentity)}throw new mt("DataCryptor: Decryption failed: ".concat(s.message),lt.InvalidKey,n.participantIdentity)}}()}))}}kt.sendCount=0;var wt,Tt={exports:{}};var St,It,Et=function(){if(wt)return Tt.exports;wt=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}Tt.exports=i,Tt.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}p(e,t,a,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,n)}(e,i,{once:!0})}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function o(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function s(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,a,c,d;if(o(n),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),c=a[t]),void 0===c)c=a[t]=n,++e._eventsCount;else if("function"==typeof c?c=a[t]=r?[n,c]:[c,n]:r?c.unshift(n):c.push(n),(i=s(e))>0&&c.length>i&&!c.warned){c.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=c.length,d=u,console&&console.warn&&console.warn(d)}return e}function d(){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 u(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=d.bind(r);return i.listener=n,r.wrapFn=i,i}function l(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):f(i,i.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function f(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function p(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);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 i(a){r.once&&e.removeEventListener(t,i),n(a)}))}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.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},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(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},i.prototype.getMaxListeners=function(){return s(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,a=this._events;if(void 0!==a)i=i&&void 0===a.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var c=a[e];if(void 0===c)return!1;if("function"==typeof c)n(c,this,t);else{var d=c.length,u=f(c,d);for(r=0;r<d;++r)n(u[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return o(t),this.on(e,u(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,u(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,i,a,s;if(o(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return l(this,e,!0)},i.prototype.rawListeners=function(e){return l(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},i.prototype.listenerCount=h,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},Tt.exports}();class Nt extends(It=Promise){constructor(e){super(e)}catch(e){return super.catch(e)}static reject(e){return super.reject(e)}static all(e){return super.all(e)}static race(e){return super.race(e)}}St=Nt,Nt.resolve=e=>Reflect.get(It,"resolve",St).call(St,e);const At=/version\/(\d+(\.?_?\d+)+)/i;let Lt;function Ct(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("undefined"==typeof navigator)return;const n=navigator.userAgent.toLowerCase();if(void 0===Lt||t){const e=Rt.find((e=>e.test.test(n)));Lt=null==e?void 0:e.describe(n)}return Lt}const Rt=[{test:/firefox|iceweasel|fxios/i,describe:e=>({name:"Firefox",version:Ut(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("fxios")?"iOS":void 0,osVersion:Ot(e)})},{test:/chrom|crios|crmo/i,describe:e=>({name:"Chrome",version:Ut(/(?:chrome|chromium|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("crios")?"iOS":void 0,osVersion:Ot(e)})},{test:/safari|applewebkit/i,describe:e=>({name:"Safari",version:Ut(At,e),os:e.includes("mobile/")?"iOS":"macOS",osVersion:Ot(e)})}];function Ut(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;const r=t.match(e);return r&&r.length>=n&&r[n]||""}function Ot(e){return e.includes("mac os")?Ut(/\(.+?(\d+_\d+(:?_\d+)?)/,e,1).replace(/_/g,"."):void 0}var Pt,_t,Dt,Ft;!function(e){e.Connected="connected",e.Reconnecting="reconnecting",e.SignalReconnecting="signalReconnecting",e.Reconnected="reconnected",e.Disconnected="disconnected",e.ConnectionStateChanged="connectionStateChanged",e.Moved="moved",e.MediaDevicesChanged="mediaDevicesChanged",e.ParticipantConnected="participantConnected",e.ParticipantDisconnected="participantDisconnected",e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalAudioSilenceDetected="localAudioSilenceDetected",e.ActiveSpeakersChanged="activeSpeakersChanged",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.ParticipantAttributesChanged="participantAttributesChanged",e.ParticipantActive="participantActive",e.RoomMetadataChanged="roomMetadataChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.AudioPlaybackStatusChanged="audioPlaybackChanged",e.VideoPlaybackStatusChanged="videoPlaybackChanged",e.MediaDevicesError="mediaDevicesError",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.SignalConnected="signalConnected",e.RecordingStatusChanged="recordingStatusChanged",e.ParticipantEncryptionStatusChanged="participantEncryptionStatusChanged",e.EncryptionError="encryptionError",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ActiveDeviceChanged="activeDeviceChanged",e.ChatMessage="chatMessage",e.LocalTrackSubscribed="localTrackSubscribed",e.MetricsReceived="metricsReceived",e.DataTrackPublished="dataTrackPublished",e.DataTrackUnpublished="dataTrackUnpublished",e.LocalDataTrackPublished="localDataTrackPublished",e.LocalDataTrackUnpublished="localDataTrackUnpublished"}(Pt||(Pt={})),function(e){e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackCpuConstrained="localTrackCpuConstrained",e.LocalSenderCreated="localSenderCreated",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.IsSpeakingChanged="isSpeakingChanged",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.TrackCpuConstrained="trackCpuConstrained",e.MediaDevicesError="mediaDevicesError",e.AudioStreamAcquired="audioStreamAcquired",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.PCTrackAdded="pcTrackAdded",e.AttributesChanged="attributesChanged",e.LocalTrackSubscribed="localTrackSubscribed",e.ChatMessage="chatMessage",e.Active="active"}(_t||(_t={})),function(e){e.TransportsCreated="transportsCreated",e.Connected="connected",e.Disconnected="disconnected",e.Resuming="resuming",e.Resumed="resumed",e.Restarting="restarting",e.Restarted="restarted",e.SignalResumed="signalResumed",e.SignalRestarted="signalRestarted",e.Closing="closing",e.MediaTrackAdded="mediaTrackAdded",e.ActiveSpeakersUpdate="activeSpeakersUpdate",e.DataPacketReceived="dataPacketReceived",e.RTPVideoMapUpdate="rtpVideoMapUpdate",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ParticipantUpdate="participantUpdate",e.RoomUpdate="roomUpdate",e.SpeakersChanged="speakersChanged",e.StreamStateChanged="streamStateChanged",e.ConnectionQualityUpdate="connectionQualityUpdate",e.SubscriptionError="subscriptionError",e.SubscriptionPermissionUpdate="subscriptionPermissionUpdate",e.RemoteMute="remoteMute",e.SubscribedQualityUpdate="subscribedQualityUpdate",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackSubscribed="localTrackSubscribed",e.Offline="offline",e.SignalRequestResponse="signalRequestResponse",e.SignalConnected="signalConnected",e.RoomMoved="roomMoved",e.PublishDataTrackResponse="publishDataTrackResponse",e.UnPublishDataTrackResponse="unPublishDataTrackResponse",e.DataTrackSubscriberHandles="dataTrackSubscriberHandles",e.DataTrackPacketReceived="dataTrackPacketReceived",e.Joined="joined",e.TokenRefreshed="tokenRefreshed",e.ServerRegionsReported="serverRegionsReported"}(Dt||(Dt={})),function(e){e.Message="message",e.Muted="muted",e.Unmuted="unmuted",e.Restarted="restarted",e.Ended="ended",e.Subscribed="subscribed",e.Unsubscribed="unsubscribed",e.CpuConstrained="cpuConstrained",e.UpdateSettings="updateSettings",e.UpdateSubscription="updateSubscription",e.AudioPlaybackStarted="audioPlaybackStarted",e.AudioPlaybackFailed="audioPlaybackFailed",e.AudioSilenceDetected="audioSilenceDetected",e.VisibilityChanged="visibilityChanged",e.VideoDimensionsChanged="videoDimensionsChanged",e.VideoPlaybackStarted="videoPlaybackStarted",e.VideoPlaybackFailed="videoPlaybackFailed",e.ElementAttached="elementAttached",e.ElementDetached="elementDetached",e.UpstreamPaused="upstreamPaused",e.UpstreamResumed="upstreamResumed",e.SubscriptionPermissionChanged="subscriptionPermissionChanged",e.SubscriptionStatusChanged="subscriptionStatusChanged",e.SubscriptionFailed="subscriptionFailed",e.TrackProcessorUpdate="trackProcessorUpdate",e.AudioTrackFeatureUpdate="audioTrackFeatureUpdate",e.TranscriptionReceived="transcriptionReceived",e.TimeSyncUpdate="timeSyncUpdate",e.PreConnectBufferFlushed="preConnectBufferFlushed"}(Ft||(Ft={}));class xt{constructor(e,t,n,r,i){if("object"==typeof e)this.width=e.width,this.height=e.height,this.aspectRatio=e.aspectRatio,this.encoding={maxBitrate:e.maxBitrate,maxFramerate:e.maxFramerate,priority:e.priority};else{if(void 0===t||void 0===n)throw new TypeError("Unsupported options: provide at least width, height and maxBitrate");this.width=e,this.height=t,this.aspectRatio=e/t,this.encoding={maxBitrate:n,maxFramerate:r,priority:i}}}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.aspectRatio}}}const Bt=["vp8","h264","vp9","av1","h265"];var Mt,Kt;function jt(e){return"mediaStreamTrack"in e?{trackID:e.sid,source:e.source,muted:e.isMuted,enabled:e.mediaStreamTrack.enabled,kind:e.kind,streamID:e.mediaStreamID,streamTrackID:e.mediaStreamTrack.id}:{trackID:e.trackSid,enabled:e.isEnabled,muted:e.isMuted,trackInfo:Object.assign({mimeType:e.mimeType,name:e.trackName,encrypted:e.isEncrypted,kind:e.kind,source:e.source},e.track?jt(e.track):{})}}!function(e){e[e.PREFER_REGRESSION=0]="PREFER_REGRESSION",e[e.SIMULCAST=1]="SIMULCAST",e[e.REGRESSION=2]="REGRESSION"}(Mt||(Mt={})),function(e){e.telephone={maxBitrate:12e3},e.speech={maxBitrate:24e3},e.music={maxBitrate:48e3},e.musicStereo={maxBitrate:64e3},e.musicHighQuality={maxBitrate:96e3},e.musicHighQualityStereo={maxBitrate:128e3}}(Kt||(Kt={})),new xt(160,90,9e4,20),new xt(320,180,16e4,20),new xt(384,216,18e4,20),new xt(640,360,45e4,20),new xt(960,540,8e5,25),new xt(1280,720,17e5,30),new xt(1920,1080,3e6,30),new xt(2560,1440,5e6,30),new xt(3840,2160,8e6,30),new xt(160,120,7e4,20),new xt(240,180,125e3,20),new xt(320,240,14e4,20),new xt(480,360,33e4,20),new xt(640,480,5e5,20),new xt(720,540,6e5,25),new xt(960,720,13e5,30),new xt(1440,1080,23e5,30),new xt(1920,1440,38e5,30),new xt(640,360,2e5,3,"medium"),new xt(640,360,4e5,15,"medium"),new xt(1280,720,8e5,5,"medium"),new xt(1280,720,15e5,15,"medium"),new xt(1280,720,2e6,30,"medium"),new xt(1920,1080,25e5,15,"medium"),new xt(1920,1080,5e6,30,"medium"),new xt(0,0,7e6,30,"medium");const Vt=[];var Wt;!function(e){e[e.LOW=0]="LOW",e[e.MEDIUM=1]="MEDIUM",e[e.HIGH=2]="HIGH"}(Wt||(Wt={}));class qt extends Et.EventEmitter{get streamState(){return this._streamState}setStreamState(e){this._streamState=e}constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var r;super(),this.attachedElements=[],this.isMuted=!1,this._streamState=qt.StreamState.Active,this.isInBackground=!1,this._currentBitrate=0,this.log=d,this.appVisibilityChangedListener=()=>{this.backgroundTimeout&&clearTimeout(this.backgroundTimeout),"hidden"===document.visibilityState?this.backgroundTimeout=setTimeout((()=>this.handleAppVisibilityChanged()),5e3):this.handleAppVisibilityChanged()},this.log=u(null!==(r=n.loggerName)&&void 0!==r?r:s.Track),this.loggerContextCb=n.loggerContextCb,this.setMaxListeners(100),this.kind=t,this._mediaStreamTrack=e,this._mediaStreamID=e.id,this.source=qt.Source.Unknown}get logContext(){var e;return Object.assign(Object.assign({},null===(e=this.loggerContextCb)||void 0===e?void 0:e.call(this)),jt(this))}get currentBitrate(){return this._currentBitrate}get mediaStreamTrack(){return this._mediaStreamTrack}get mediaStreamID(){return this._mediaStreamID}attach(e){let t="audio";this.kind===qt.Kind.Video&&(t="video"),0===this.attachedElements.length&&this.kind===qt.Kind.Video&&this.addAppVisibilityListener(),e||("audio"===t&&(Vt.forEach((t=>{null!==t.parentElement||e||(e=t)})),e&&Vt.splice(Vt.indexOf(e),1)),e||(e=document.createElement(t))),this.attachedElements.includes(e)||this.attachedElements.push(e),function(e,t){let n,r;n=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream;r="audio"===e.kind?n.getAudioTracks():n.getVideoTracks();r.includes(e)||(r.forEach((e=>{n.removeTrack(e)})),n.addTrack(e));Xt()&&t instanceof HTMLVideoElement||(t.autoplay=!0);t.muted=0===n.getAudioTracks().length,t instanceof HTMLVideoElement&&(t.playsInline=!0);t.srcObject!==n&&(t.srcObject=n,(Xt()||function(){var e;return"Firefox"===(null===(e=Ct())||void 0===e?void 0:e.name)}())&&t instanceof HTMLVideoElement&&setTimeout((()=>{t.srcObject=n,t.play().catch((()=>{}))}),0))}(this.mediaStreamTrack,e);const n=e.srcObject.getTracks(),r=n.some((e=>"audio"===e.kind));return e.play().then((()=>{this.emit(r?Ft.AudioPlaybackStarted:Ft.VideoPlaybackStarted)})).catch((t=>{"NotAllowedError"===t.name?this.emit(r?Ft.AudioPlaybackFailed:Ft.VideoPlaybackFailed,t):"AbortError"===t.name?d.debug("".concat(r?"audio":"video"," playback aborted, likely due to new play request")):d.warn("could not playback ".concat(r?"audio":"video"),t),r&&e&&n.some((e=>"video"===e.kind))&&"NotAllowedError"===t.name&&(e.muted=!0,e.play().catch((()=>{})))})),this.emit(Ft.ElementAttached,e),e}detach(e){try{if(e){Gt(this.mediaStreamTrack,e);const t=this.attachedElements.indexOf(e);return t>=0&&(this.attachedElements.splice(t,1),this.recycleElement(e),this.emit(Ft.ElementDetached,e)),e}const t=[];return this.attachedElements.forEach((e=>{Gt(this.mediaStreamTrack,e),t.push(e),this.recycleElement(e),this.emit(Ft.ElementDetached,e)})),this.attachedElements=[],t}finally{0===this.attachedElements.length&&this.removeAppVisibilityListener()}}stop(){this.stopMonitor(),this._mediaStreamTrack.stop()}enable(){this._mediaStreamTrack.enabled=!0}disable(){this._mediaStreamTrack.enabled=!1}stopMonitor(){this.monitorInterval&&clearInterval(this.monitorInterval),this.timeSyncHandle&&cancelAnimationFrame(this.timeSyncHandle)}updateLoggerOptions(e){e.loggerName&&(this.log=u(e.loggerName)),e.loggerContextCb&&(this.loggerContextCb=e.loggerContextCb)}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),Vt.forEach((e=>{e.parentElement||(t=!1)})),t&&Vt.push(e)}}handleAppVisibilityChanged(){return e(this,void 0,void 0,(function*(){this.isInBackground="hidden"===document.visibilityState,this.isInBackground||this.kind!==qt.Kind.Video||setTimeout((()=>this.attachedElements.forEach((e=>e.play().catch((()=>{}))))),0)}))}addAppVisibilityListener(){Jt()?(this.isInBackground="hidden"===document.visibilityState,document.addEventListener("visibilitychange",this.appVisibilityChangedListener)):this.isInBackground=!1}removeAppVisibilityListener(){Jt()&&document.removeEventListener("visibilitychange",this.appVisibilityChangedListener)}}function Gt(e,t){if(t.srcObject instanceof MediaStream){const n=t.srcObject;n.removeTrack(e),n.getTracks().length>0?t.srcObject=n:t.srcObject=null}}function Xt(){var e;return"Safari"===(null===(e=Ct())||void 0===e?void 0:e.name)}function Jt(){return"undefined"!=typeof document}function Ht(e){return!(!(null==e?void 0:e.timestamp)&&!(null==e?void 0:e.frameId))}!function(e){let t,n,r;!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"}(n=e.Source||(e.Source={})),function(e){e.Active="active",e.Paused="paused",e.Unknown="unknown"}(r=e.StreamState||(e.StreamState={})),e.kindToProto=function(e){switch(e){case t.Audio:return it.AUDIO;case t.Video:return it.VIDEO;default:return it.DATA}},e.kindFromProto=function(e){switch(e){case it.AUDIO:return t.Audio;case it.VIDEO:return t.Video;default:return t.Unknown}},e.sourceToProto=function(e){switch(e){case n.Camera:return at.CAMERA;case n.Microphone:return at.MICROPHONE;case n.ScreenShare:return at.SCREEN_SHARE;case n.ScreenShareAudio:return at.SCREEN_SHARE_AUDIO;default:return at.UNKNOWN}},e.sourceFromProto=function(e){switch(e){case at.CAMERA:return n.Camera;case at.MICROPHONE:return n.Microphone;case at.SCREEN_SHARE:return n.ScreenShare;case at.SCREEN_SHARE_AUDIO:return n.ScreenShareAudio;default:return n.Unknown}},e.streamStateFromProto=function(e){switch(e){case ot.ACTIVE:return r.Active;case ot.PAUSED:return r.Paused;default:return r.Unknown}}}(qt||(qt={}));const zt=Uint8Array.from(["L".charCodeAt(0),"K".charCodeAt(0),"T".charCodeAt(0),"S".charCodeAt(0)]),Yt=1,Qt=2,$t=5,Zt=10,en=6;function tn(e,t,n){const r=t!==BigInt(0),i=0!==n;if(!r&&!i)return e;const a=(r?Zt:0)+(i?en:0)+$t,o=new Uint8Array(e.length+a);let s=0;return o.set(e,s),s+=e.length,r&&(o[s++]=255^Yt,o[s++]=247,function(e,t,n){const r=Number(n>>BigInt(32)&BigInt(4294967295)),i=Number(n&BigInt(4294967295));e[t]=r>>>24^255,e[t+1]=r>>>16&255^255,e[t+2]=r>>>8&255^255,e[t+3]=255&r^255,e[t+4]=i>>>24^255,e[t+5]=i>>>16&255^255,e[t+6]=i>>>8&255^255,e[t+7]=255&i^255}(o,s,t),s+=8),i&&(o[s++]=255^Qt,o[s++]=251,function(e,t,n){for(let r=3;r>=0;r-=1)e[t+(3-r)]=n>>8*r&255^255}(o,s,n),s+=4),o[s++]=255^a,o.set(zt,s),o}function nn(e){const t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.length<$t)return{data:t};if(!function(e,t){for(let n=0;n<zt.length;n+=1)if(e[t+n]!==zt[n])return!1;return!0}(t,t.length-zt.length))return{data:t};const n=255^t[t.length-$t];if(n<$t||n>t.length)return{data:t};const r=t.length-n,i=t.length-$t,a=t.subarray(0,r);let o=r,s=!1;const c={userTimestamp:BigInt(0),frameId:0};for(;o+2<=i;){const e=255^t[o++],n=255^t[o++];if(o+n>i)break;e===Yt&&8===n?(c.userTimestamp=rn(t,o),s=!0):e===Qt&&4===n&&(c.frameId=an(t,o,n),s=!0),o+=n}return s?{data:a,metadata:c}:{data:t}}function rn(e,t){const n=BigInt(((255^e[t])<<24|(255^e[t+1])<<16|(255^e[t+2])<<8|255^e[t+3])>>>0),r=BigInt(((255^e[t+4])<<24|(255^e[t+5])<<16|(255^e[t+6])<<8|255^e[t+7])>>>0);return n<<BigInt(32)|r}function an(e,t,n){let r=0;for(let i=0;i<n;i+=1)r=r<<8|255^e[t+i];return r>>>0}function on(e){try{const t=e.getMetadata();if("number"==typeof t.synchronizationSource)return t.synchronizationSource}catch(e){}return 0}const sn=31;var cn,dn;function un(e){return e&sn}function ln(e){return e>>1&63}function hn(e){return e===cn.SLICE_IDR||e===cn.SLICE_NON_IDR}function fn(e){return e===dn.TRAIL_N||e===dn.TRAIL_R||e===dn.TSA_N||e===dn.TSA_R||e===dn.STSA_N||e===dn.STSA_R||e===dn.RADL_N||e===dn.RADL_R||e===dn.RASL_N||e===dn.RASL_R||e===dn.BLA_W_LP||e===dn.BLA_W_RADL||e===dn.BLA_N_LP||e===dn.IDR_W_RADL||e===dn.IDR_N_LP||e===dn.CRA_NUT}function pn(e,t){const n=function(e){const t=[];let n=0,r=0,i=e.length-3;for(;r<i;){for(;r<i&&!(r<i-1&&0===e[r]&&0===e[r+1]&&0===e[r+2]&&1===e[r+3])&&(0!==e[r]||0!==e[r+1]||1!==e[r+2]);)r++;r>=i&&(r=e.length);let a=r;for(;a>n&&0===e[a-1];)a--;if(0===n){if(a!==n)throw TypeError("byte stream contains leading data")}else t.push(n);let o=3;r<e.length-3&&0===e[r]&&0===e[r+1]&&0===e[r+2]&&1===e[r+3]&&(o=4),n=r+=o}return t}(e),r=null!=t?t:function(e,t){for(const n of t){if(hn(un(e[n])))return"h264";if(fn(ln(e[n])))return"h265"}return"unknown"}(e,n);if("unknown"===r)return{unencryptedBytes:0,detectedCodec:r,requiresNALUProcessing:!1};const i=function(e,t,n){for(const r of t)if("h265"===n){if(fn(ln(e[r])))return r+2}else if(hn(un(e[r])))return r+2;return null}(e,n,r);if(null===i)throw new TypeError("Could not find NALU");return{unencryptedBytes:i,detectedCodec:r,requiresNALUProcessing:!0}}!function(e){e[e.SLICE_NON_IDR=1]="SLICE_NON_IDR",e[e.SLICE_PARTITION_A=2]="SLICE_PARTITION_A",e[e.SLICE_PARTITION_B=3]="SLICE_PARTITION_B",e[e.SLICE_PARTITION_C=4]="SLICE_PARTITION_C",e[e.SLICE_IDR=5]="SLICE_IDR",e[e.SEI=6]="SEI",e[e.SPS=7]="SPS",e[e.PPS=8]="PPS",e[e.AUD=9]="AUD",e[e.END_SEQ=10]="END_SEQ",e[e.END_STREAM=11]="END_STREAM",e[e.FILLER_DATA=12]="FILLER_DATA",e[e.SPS_EXT=13]="SPS_EXT",e[e.PREFIX_NALU=14]="PREFIX_NALU",e[e.SUBSET_SPS=15]="SUBSET_SPS",e[e.DPS=16]="DPS",e[e.SLICE_AUX=19]="SLICE_AUX",e[e.SLICE_EXT=20]="SLICE_EXT",e[e.SLICE_LAYER_EXT=21]="SLICE_LAYER_EXT"}(cn||(cn={})),function(e){e[e.TRAIL_N=0]="TRAIL_N",e[e.TRAIL_R=1]="TRAIL_R",e[e.TSA_N=2]="TSA_N",e[e.TSA_R=3]="TSA_R",e[e.STSA_N=4]="STSA_N",e[e.STSA_R=5]="STSA_R",e[e.RADL_N=6]="RADL_N",e[e.RADL_R=7]="RADL_R",e[e.RASL_N=8]="RASL_N",e[e.RASL_R=9]="RASL_R",e[e.BLA_W_LP=16]="BLA_W_LP",e[e.BLA_W_RADL=17]="BLA_W_RADL",e[e.BLA_N_LP=18]="BLA_N_LP",e[e.IDR_W_RADL=19]="IDR_W_RADL",e[e.IDR_N_LP=20]="IDR_N_LP",e[e.CRA_NUT=21]="CRA_NUT",e[e.VPS_NUT=32]="VPS_NUT",e[e.SPS_NUT=33]="SPS_NUT",e[e.PPS_NUT=34]="PPS_NUT",e[e.AUD_NUT=35]="AUD_NUT",e[e.EOS_NUT=36]="EOS_NUT",e[e.EOB_NUT=37]="EOB_NUT",e[e.FD_NUT=38]="FD_NUT",e[e.PREFIX_SEI_NUT=39]="PREFIX_SEI_NUT",e[e.SUFFIX_SEI_NUT=40]="SUFFIX_SEI_NUT"}(dn||(dn={}));const yn="ef0161653d8b2b23aad46624b420af1d03ce48950e9fc85718028f91b50f9219",mn="f0a0e09647d891d6d50aa898bce7108090375d0d55e50a2bb21147afee558e44",gn="61d9665eed71b6d424ae9539330a3bdd5cb386d4d781c808219a6e36750493a7",bn="faffc26b68a2fc09096fa20f3351e706398b6f838a7500c8063472c2e476e90d",vn="aad8d31fc56b2802ca500e58c2fb9d0b29ad71bb7cb52cd6530251eade188988";function kn(t){return e(this,void 0,void 0,(function*(){const n=yield function(t){return e(this,void 0,void 0,(function*(){const e=yield crypto.subtle.digest("SHA-256",t),n=new Uint8Array(e);return Array.from(n).map((e=>e.toString(16).padStart(2,"0"))).join("")}))}(t);switch(n){case yn:return"vp8";case mn:case gn:case bn:return"h264";case vn:return"opus";default:return null}}))}const wn=new Map;class Tn extends Et.EventEmitter{encodeFunction(e,t){throw Error("not implemented for subclass")}decodeFunction(e,t){throw Error("not implemented for subclass")}}class Sn extends Tn{constructor(e){var t;super(),this.hasPacketTrailer=!1,this.packetTrailerFrameId=0,this.lastErrorTimestamp=new Map,this.errorCounts=new Map,this.ERROR_THROTTLE_MS=1e3,this.MAX_ERRORS_PER_MINUTE=5,this.ERROR_WINDOW_MS=6e4,this.loggedNALUFallbacks=new Set,this.sendCounts=new Map,this.keys=e.keys,this.participantIdentity=e.participantIdentity,this.rtpMap=new Map,this.keyProviderOptions=e.keyProviderOptions,this.sifTrailer=null!==(t=e.sifTrailer)&&void 0!==t?t:Uint8Array.from([])}get logContext(){return{participant:this.participantIdentity,mediaTrackId:this.trackId,fallbackCodec:this.videoCodec}}setParticipant(e,t){l.debug("setting new participant on cryptor",Object.assign(Object.assign({},this.logContext),{newParticipant:e,hadPreviousParticipant:!!this.participantIdentity})),this.participantIdentity&&this.participantIdentity!==e&&(l.warn("cryptor has already a participant set, cleaning up before switching",{oldParticipant:this.participantIdentity,newParticipant:e,trackId:this.trackId}),this.unsetParticipant()),this.participantIdentity=e,this.keys=t}unsetParticipant(){l.debug("unsetting participant",this.logContext),this.currentTransform&&(this.currentTransform=void 0),this.participantIdentity=void 0,this.lastErrorTimestamp=new Map,this.errorCounts=new Map}isEnabled(){return this.participantIdentity?wn.get(this.participantIdentity):void 0}getParticipantIdentity(){return this.participantIdentity}getTrackId(){return this.trackId}setVideoCodec(e){this.videoCodec=e}setRtpMap(e){this.rtpMap=e}setHasPacketTrailer(e){this.hasPacketTrailer=e}setPacketTrailer(e){this.packetTrailer=e,this.packetTrailerFrameId=0}setupTransform(e,t,n,r,i,a,o){if(a&&(l.info("setting codec on cryptor to",{codec:a}),this.videoCodec=a),"encode"===e&&this.setPacketTrailer(o),l.debug("Setting up frame cryptor transform",Object.assign({operation:e,passedTrackId:r,codec:a,isReuse:i,hasCurrentTransform:!!this.currentTransform},this.logContext)),this.trackId=r,i&&this.currentTransform&&t===this.currentTransform.readable&&n===this.currentTransform.writable)return void l.debug("reusing existing transform",Object.assign(Object.assign({},this.logContext),{trackId:r}));const s=Symbol("transform"),c="encode"===e?this.encodeFunction:this.decodeFunction,d=new TransformStream({transform:c.bind(this)});this.currentTransform={readable:t,writable:n,transformer:d,trackId:r,symbol:s},t.pipeThrough(d).pipeTo(n).catch((e=>{e instanceof TypeError&&"Destination stream closed"===e.message?l.debug("destination stream closed"):(l.warn("transform error",Object.assign({error:e},this.logContext)),this.emit(yt.Error,e instanceof mt?e:new mt(e.message,void 0,this.participantIdentity)))})).finally((()=>{var e;(null===(e=this.currentTransform)||void 0===e?void 0:e.symbol)===s&&(l.debug("transform completed",Object.assign(Object.assign({},this.logContext),{trackId:r})),this.currentTransform=void 0)}))}setSifTrailer(e){l.debug("setting SIF trailer",Object.assign(Object.assign({},this.logContext),{trailer:e})),this.sifTrailer=e}shouldEmitError(e){var t,n;const r=Date.now(),i=null!==(t=this.lastErrorTimestamp.get(e))&&void 0!==t?t:0,a=null!==(n=this.errorCounts.get(e))&&void 0!==n?n:0;return r-i>this.ERROR_WINDOW_MS?(this.errorCounts.set(e,0),this.lastErrorTimestamp.set(e,r),!0):!(r-i<this.ERROR_THROTTLE_MS)&&(a>=this.MAX_ERRORS_PER_MINUTE?(a===this.MAX_ERRORS_PER_MINUTE&&(l.warn("Suppressing further decryption errors for ".concat(this.participantIdentity),Object.assign(Object.assign({},this.logContext),{errorKey:e})),this.errorCounts.set(e,a+1)),!1):(this.lastErrorTimestamp.set(e,r),this.errorCounts.set(e,a+1),!0))}emitThrottledError(e){var t;const n="".concat(this.participantIdentity,"-").concat(e.reason,"-decrypt");if(this.shouldEmitError(n)){const r=null!==(t=this.errorCounts.get(n))&&void 0!==t?t:0;r>1&&l.debug("Decryption error (".concat(r," occurrences in window)"),Object.assign(Object.assign({},this.logContext),{reason:lt[e.reason]})),this.emit(yt.Error,e)}}encodeFunction(t,n){return e(this,void 0,void 0,(function*(){var e;if(0===t.data.byteLength)return n.enqueue(t);if(!this.isEnabled())return this.appendPacketTrailer(t),n.enqueue(t);const r=this.keys.getKeySet();if(!r)return void this.emitThrottledError(new mt("key set not found for ".concat(this.participantIdentity," at index ").concat(this.keys.getCurrentKeyIndex()),lt.MissingKey,this.participantIdentity));const i=r.encryptionKey,a=this.keys.getCurrentKeyIndex();if(i){const r=this.makeIV(null!==(e=t.getMetadata().synchronizationSource)&&void 0!==e?e:-1,t.timestamp);let s=this.getUnencryptedBytes(t);const c=new Uint8Array(t.data,0,s.unencryptedBytes),d=new Uint8Array(2);d[0]=12,d[1]=a;try{const e=yield crypto.subtle.encrypt({name:m,iv:r,additionalData:new Uint8Array(t.data,0,c.byteLength)},i,new Uint8Array(t.data,s.unencryptedBytes));let a=new Uint8Array(e.byteLength+r.byteLength+d.byteLength);a.set(new Uint8Array(e)),a.set(new Uint8Array(r),e.byteLength),a.set(d,e.byteLength+r.byteLength),s.requiresNALUProcessing&&(a=function(e){const t=[];for(var n=0,r=0;r<e.length;++r){var i=e[r];i<=3&&n>=2&&(t.push(3),n=0),t.push(i),0==i?++n:n=0}return new Uint8Array(t)}(a));var o=new Uint8Array(c.byteLength+a.byteLength);return o.set(c),o.set(a,c.byteLength),t.data=o.buffer,this.appendPacketTrailer(t),n.enqueue(t)}catch(e){l.error(e)}}else l.debug("failed to encrypt, emitting error",this.logContext),this.emitThrottledError(new mt("encryption key missing for encoding",lt.MissingKey,this.participantIdentity))}))}appendPacketTrailer(e){var t;Ht(this.packetTrailer)&>(e)&&((null===(t=this.packetTrailer)||void 0===t?void 0:t.frameId)&&(this.packetTrailerFrameId=4294967295===this.packetTrailerFrameId?1:this.packetTrailerFrameId+1),function(e,t,n){if(!Ht(t)||0===e.data.byteLength)return!1;const r=(null==t?void 0:t.timestamp)?BigInt(Date.now())*BigInt(1e3):BigInt(0),i=(null==t?void 0:t.frameId)?n:0,a=new Uint8Array(e.data),o=tn(a,r,i);o.byteLength!==a.byteLength&&(e.data=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength))}(e,this.packetTrailer,this.packetTrailerFrameId))}decodeFunction(t,n){return e(this,void 0,void 0,(function*(){if(this.hasPacketTrailer&>(t))try{const e=function(e,t){if(0===e.data.byteLength)return{};const n=nn(e.data);if(!n.metadata)return{};const r=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength),i=function(e){try{const t=e.getMetadata();if("number"==typeof t.rtpTimestamp)return t.rtpTimestamp;if("number"==typeof t.timestamp)return t.timestamp}catch(e){}if("number"==typeof e.timestamp)return e.timestamp}(e);return void 0!==i&&t?{data:r,payload:{trackId:t,rtpTimestamp:i,ssrc:on(e),metadata:n.metadata}}:{data:r}}(t,this.trackId);if(e.data&&(t.data=e.data),e.payload&&this.participantIdentity){const t={kind:"packetTrailerMetadata",data:e.payload};postMessage(t)}}catch(e){}if(!this.isEnabled()||0===t.data.byteLength)return n.enqueue(t);if(function(e,t){if(0===t.byteLength)return!1;const n=new Uint8Array(e.slice(e.byteLength-t.byteLength));return t.every(((e,t)=>e===n[t]))}(t.data,this.sifTrailer))return t.data=t.data.slice(0,t.data.byteLength-this.sifTrailer.byteLength),(yield kn(t.data))?(l.debug("enqueue SIF",this.logContext),n.enqueue(t)):void l.warn("Unexpected SIF frame payload, dropping frame",this.logContext);const e=new Uint8Array(t.data)[t.data.byteLength-1];if(!this.keys.hasInvalidKeyAtIndex(e))if(this.keys.getKeySet(e))try{const r=yield this.decryptFrame(t,e);if(this.keys.decryptionSuccess(e),r)return n.enqueue(r)}catch(t){t instanceof mt&&t.reason===lt.InvalidKey?this.keys.hasValidKey&&(this.emitThrottledError(t),this.keys.decryptionFailure(e)):l.warn("decoding frame failed",{error:t})}else l.warn("skipping decryption due to missing key at index ".concat(e)),this.emitThrottledError(new mt("missing key at index ".concat(e," for participant ").concat(this.participantIdentity),lt.MissingKey,this.participantIdentity)),this.keys.decryptionFailure(e)}))}decryptFrame(t,n){return e(this,arguments,void 0,(function(e,t){var n=this;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{ratchetCount:0};return function*(){var a;const o=n.keys.getKeySet(t);if(!i.encryptionKey&&!o)throw new TypeError("no encryption key found for decryption of ".concat(n.participantIdentity));let s=n.getUnencryptedBytes(e);try{const t=new Uint8Array(e.data,0,s.unencryptedBytes);var c=new Uint8Array(e.data,t.length,e.data.byteLength-t.length);if(s.requiresNALUProcessing&&function(e){for(var t=0;t<e.length-3;t++)if(0==e[t]&&0==e[t+1]&&3==e[t+2])return!0;return!1}(c)){c=function(e){const t=[];for(var n=e.length,r=0;r<e.length;)n-r>=3&&!e[r]&&!e[r+1]&&3==e[r+2]?(t.push(e[r++]),t.push(e[r++]),r++):t.push(e[r++]);return new Uint8Array(t)}(c);const n=new Uint8Array(t.byteLength+c.byteLength);n.set(t),n.set(c,t.byteLength),e.data=n.buffer}const n=new Uint8Array(e.data,e.data.byteLength-2,2),r=n[0],d=new Uint8Array(e.data,e.data.byteLength-r-n.byteLength,r),u=t.byteLength,l=e.data.byteLength-(t.byteLength+r+n.byteLength),h=yield crypto.subtle.decrypt({name:m,iv:d,additionalData:new Uint8Array(e.data,0,t.byteLength)},null!==(a=i.encryptionKey)&&void 0!==a?a:o.encryptionKey,new Uint8Array(e.data,u,l)),f=new ArrayBuffer(t.byteLength+h.byteLength),p=new Uint8Array(f);return p.set(new Uint8Array(e.data,0,t.byteLength)),p.set(new Uint8Array(h),t.byteLength),e.data=f,e}catch(a){if(n.keyProviderOptions.ratchetWindowSize>0){if(i.ratchetCount<n.keyProviderOptions.ratchetWindowSize){let a,s;l.debug("ratcheting key attempt ".concat(i.ratchetCount," of ").concat(n.keyProviderOptions.ratchetWindowSize,", for kind ").concat(e instanceof RTCEncodedAudioFrame?"audio":"video")),(null!=r?r:o)===n.keys.getKeySet(t)&&(s=yield n.keys.ratchetKey(t,!1),a=yield vt(s.cryptoKey,n.keyProviderOptions));const c=yield n.decryptFrame(e,t,r||o,{ratchetCount:i.ratchetCount+1,encryptionKey:null==a?void 0:a.encryptionKey});return c&&a&&(null!=r?r:o)===n.keys.getKeySet(t)&&(n.keys.setKeySet(a,t,s),n.keys.setCurrentKeyIndex(t)),c}throw l.warn("maximum ratchet attempts exceeded"),new mt("valid key missing for participant ".concat(n.participantIdentity),lt.InvalidKey,n.participantIdentity)}throw new mt("Decryption failed: ".concat(a.message),lt.InvalidKey,n.participantIdentity)}}()}))}makeIV(e,t){var n;const r=new ArrayBuffer(12),i=new DataView(r);this.sendCounts.has(e)||this.sendCounts.set(e,Math.floor(65535*Math.random()));const a=null!==(n=this.sendCounts.get(e))&&void 0!==n?n:0;return i.setUint32(0,e),i.setUint32(4,t),i.setUint32(8,t-a%65535),this.sendCounts.set(e,a+1),r}getUnencryptedBytes(e){var t;if(!gt(e))return{unencryptedBytes:g.audio,requiresNALUProcessing:!1};const n=null!==(t=this.getVideoCodec(e))&&void 0!==t?t:this.videoCodec;if(n!==this.detectedCodec&&(l.debug("detected different codec",Object.assign({detectedCodec:n,oldCodec:this.detectedCodec},this.logContext)),this.detectedCodec=n),"av1"===n)throw new Error("".concat(n," is not yet supported for end to end encryption"));if("vp8"===n)return{unencryptedBytes:g[e.type],requiresNALUProcessing:!1};if("vp9"===n)return{unencryptedBytes:0,requiresNALUProcessing:!1};const r=e.getMetadata().payloadType,i="".concat(this.participantIdentity,"-").concat(this.trackId,"-").concat(r);try{const t="h264"===n||"h265"===n?n:void 0,r=pn(new Uint8Array(e.data),t);if(r.requiresNALUProcessing)return this.loggedNALUFallbacks.delete(i),{unencryptedBytes:r.unencryptedBytes,requiresNALUProcessing:!0}}catch(e){this.logNALUFallbackOnce(i,r,e)}return{unencryptedBytes:g[e.type],requiresNALUProcessing:!1}}logNALUFallbackOnce(e,t,n){this.loggedNALUFallbacks.has(e)||(this.loggedNALUFallbacks.add(e),l.warn("NALU processing failed, falling back to VP8 handling",Object.assign({error:n,payloadType:t},this.logContext)))}getVideoCodec(e){const t=e.getMetadata();if(t.mimeType){const e=t.mimeType.split("/")[1].toLowerCase();if(Bt.includes(e))return e}if(0===this.rtpMap.size)return;const n=t.payloadType;return n?this.rtpMap.get(n):void 0}}class In extends Et.EventEmitter{get hasValidKey(){return!this.hasInvalidKeyAtIndex(this.currentKeyIndex)}constructor(e,t){if(super(),this.currentKeyIndex=0,t.keyringSize<1||t.keyringSize>256)throw new TypeError("Keyring size needs to be between 1 and 256");this.cryptoKeyRing=new Array(t.keyringSize).fill(void 0),this.decryptionFailureCounts=new Array(t.keyringSize).fill(0),this.keyProviderOptions=t,this.ratchetPromiseMap=new Map,this.participantIdentity=e}hasInvalidKeyAtIndex(e){return this.keyProviderOptions.failureTolerance>=0&&this.decryptionFailureCounts[e]>this.keyProviderOptions.failureTolerance}decryptionFailure(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.currentKeyIndex;this.keyProviderOptions.failureTolerance<0||(this.decryptionFailureCounts[e]+=1,this.decryptionFailureCounts[e]>this.keyProviderOptions.failureTolerance&&l.warn("key for ".concat(this.participantIdentity," at index ").concat(e," is being marked as invalid")))}decryptionSuccess(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.currentKeyIndex;this.resetKeyStatus(e)}resetKeyStatus(e){void 0===e?this.decryptionFailureCounts.fill(0):this.decryptionFailureCounts[e]=0}ratchetKey(t){let n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=null!=t?t:this.getCurrentKeyIndex(),i=this.ratchetPromiseMap.get(r);if(void 0!==i)return i;const a=new Promise(((t,i)=>e(this,void 0,void 0,(function*(){try{const i=this.getKeySet(r);if(!i)throw new TypeError("Cannot ratchet key without a valid keyset of participant ".concat(this.participantIdentity));const a=i.material,o=yield function(t,n){return e(this,void 0,void 0,(function*(){const e=bt(t.algorithm.name,n);return crypto.subtle.deriveBits(e,t,256)}))}(a,this.keyProviderOptions.ratchetSalt),s=yield function(t){return e(this,arguments,void 0,(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{name:m},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"encrypt";return function*(){return crypto.subtle.importKey("raw",e,t,!1,"derive"===n?["deriveBits","deriveKey"]:["encrypt","decrypt"])}()}))}(o,a.algorithm.name,"derive"),c={chainKey:o,cryptoKey:s};n&&(yield this.setKeyFromMaterial(s,r,c)),t(c)}catch(e){i(e)}finally{this.ratchetPromiseMap.delete(r)}}))));return this.ratchetPromiseMap.set(r,a),a}setKey(t){return e(this,arguments,void 0,(function(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return function*(){yield t.setKeyFromMaterial(e,n,null,r),r&&t.resetKeyStatus(n)}()}))}setKeyFromMaterial(t,n){return e(this,arguments,void 0,(function(e,t){var n=this;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return function*(){const a=yield vt(e,n.keyProviderOptions),o=t>=0?t%n.cryptoKeyRing.length:n.currentKeyIndex;l.debug("setting new key with index ".concat(t),{usage:e.usages,algorithm:e.algorithm,ratchetSalt:n.keyProviderOptions.ratchetSalt}),n.setKeySet(a,o,r),o>=0&&i&&(n.currentKeyIndex=o)}()}))}setKeySet(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.cryptoKeyRing[t%this.cryptoKeyRing.length]=e,n&&this.emit(ft.KeyRatcheted,n,this.participantIdentity,t)}setCurrentKeyIndex(t){return e(this,void 0,void 0,(function*(){this.currentKeyIndex=t%this.cryptoKeyRing.length,this.resetKeyStatus(t)}))}getCurrentKeyIndex(){return this.currentKeyIndex}getKeySet(e){return this.cryptoKeyRing[null!=e?e:this.currentKeyIndex]}}const En=[],Nn=new Map;let An,Ln,Cn=new class{constructor(){this.pendingTasks=new Map,this.taskMutex=new y,this.nextTaskIndex=0}run(t){return e(this,void 0,void 0,(function*(){const e={id:this.nextTaskIndex++,enqueuedAt:Date.now(),status:h.WAITING};this.pendingTasks.set(e.id,e);const n=yield this.taskMutex.lock();try{return e.executedAt=Date.now(),e.status=h.RUNNING,yield t()}finally{e.status=h.COMPLETED,this.pendingTasks.delete(e.id),n()}}))}flush(){return e(this,void 0,void 0,(function*(){return this.run((()=>e(this,void 0,void 0,(function*(){}))))}))}snapshot(){return Array.from(this.pendingTasks.values())}},Rn=!1,Un=b,On=new Map;function Pn(e,t){let n=En.filter((e=>e.getTrackId()===t));if(n.length>1){const r=n.map((e=>({participant:e.getParticipantIdentity()}))).join(",");l.error("Found multiple cryptors for the same trackID ".concat(t,". target participant: ").concat(e," "),{participants:r})}let r=n[0];if(r)e!==r.getParticipantIdentity()&&r.setParticipant(e,_n(e));else{if(l.info("creating new cryptor for",{participantIdentity:e,trackId:t}),!Un)throw Error("Missing keyProvider options");r=new Sn({participantIdentity:e,keys:_n(e),keyProviderOptions:Un,sifTrailer:Ln}),r.setRtpMap(On),function(e){e.on(yt.Error,(e=>{const t={kind:"error",data:{error:new Error("".concat(lt[e.reason],": ").concat(e.message)),participantIdentity:e.participantIdentity}};postMessage(t)}))}(r),En.push(r)}return r}function _n(e){if(Rn)return Dn();let t=Nn.get(e);return t||(t=new In(e,Un),t.on(ft.KeyRatcheted,Fn),Nn.set(e,t)),t}function Dn(){return An||(l.debug("creating new shared key handler"),An=new In("shared-key",Un)),An}function Fn(e,t,n){postMessage({kind:"ratchetKey",data:{participantIdentity:t,keyIndex:n,ratchetResult:e}})}l.setDefaultLevel("info"),onmessage=t=>{Cn.run((()=>e(void 0,void 0,void 0,(function*(){const n=t.data,r=n.kind,i=n.data;switch(r){case"init":l.setLevel(i.loglevel),l.info("worker initialized"),Un=i.keyProviderOptions,Rn=!!i.keyProviderOptions.sharedKey;postMessage({kind:"initAck",data:{enabled:false}});break;case"enable":o=i.enabled,s=i.participantIdentity,l.debug("setting encryption enabled for all tracks of ".concat(s),{enable:o}),wn.set(s,o),l.info("updated e2ee enabled status for ".concat(i.participantIdentity," to ").concat(i.enabled)),postMessage(t.data);break;case"decode":let n=Pn(i.participantIdentity,i.trackId);n.setHasPacketTrailer(i.hasPacketTrailer),n.setupTransform(r,i.readableStream,i.writableStream,i.trackId,i.isReuse,i.codec);break;case"encode":let c=Pn(i.participantIdentity,i.trackId);c.setHasPacketTrailer(i.hasPacketTrailer),c.setupTransform(r,i.readableStream,i.writableStream,i.trackId,i.isReuse,i.codec,i.packetTrailer);break;case"encryptDataRequest":const d=yield kt.encrypt(i.payload,_n(i.participantIdentity)),u=d.payload,h=d.iv,f=d.keyIndex;console.log("encrypted payload",{original:i.payload,encrypted:u,iv:h}),postMessage({kind:"encryptDataResponse",data:{payload:u,iv:h,keyIndex:f,uuid:i.uuid}});break;case"decryptDataRequest":try{const e=(yield kt.decrypt(i.payload,i.iv,_n(i.participantIdentity),i.keyIndex)).payload;postMessage({kind:"decryptDataResponse",data:{payload:e,uuid:i.uuid}})}catch(e){l.error("DataCryptor decryption failed",{error:e,participantIdentity:i.participantIdentity,uuid:i.uuid}),postMessage({kind:"error",data:{error:e instanceof Error?e:new Error(String(e)),uuid:i.uuid}})}break;case"setKey":Rn?yield function(t,n,r){return e(this,void 0,void 0,(function*(){l.info("set shared key",{index:n}),yield Dn().setKey(t,n,r)}))}(i.key,i.keyIndex,i.updateCurrentKeyIndex):i.participantIdentity?(l.info("set participant sender key ".concat(i.participantIdentity," index ").concat(i.keyIndex)),yield _n(i.participantIdentity).setKey(i.key,i.keyIndex,i.updateCurrentKeyIndex)):l.error("no participant Id was provided and shared key usage is disabled");break;case"removeTransform":!function(e,t){const n=En.filter((n=>n.getParticipantIdentity()===t&&n.getTrackId()===e));n.length>1&&l.error("Found multiple cryptors for the same participant and trackID combination",{trackId:e,participantIdentity:t});const r=n[0];r?r.unsetParticipant():l.warn("Could not unset participant on cryptor",{trackId:e,participantIdentity:t})}(i.trackId,i.participantIdentity);break;case"updateCodec":const p=Pn(i.participantIdentity,i.trackId);p.setVideoCodec(i.codec),p.setHasPacketTrailer(i.hasPacketTrailer),l.info("updated codec",{participantIdentity:i.participantIdentity,trackId:i.trackId,codec:i.codec,hasPacketTrailer:i.hasPacketTrailer});break;case"setRTPMap":On=i.map,En.forEach((e=>{e.getParticipantIdentity()===i.participantIdentity&&e.setRtpMap(i.map)}));break;case"ratchetRequest":!function(t){e(this,void 0,void 0,(function*(){if(Rn){const e=Dn();yield e.ratchetKey(t.keyIndex),e.resetKeyStatus()}else if(t.participantIdentity){const e=_n(t.participantIdentity);yield e.ratchetKey(t.keyIndex),e.resetKeyStatus()}else l.error("no participant Id was provided for ratchet request and shared key usage is disabled")}))}(i);break;case"setSifTrailer":a=i.trailer,Ln=a,En.forEach((e=>{e.setSifTrailer(a)}))}var a,o,s}))))},self.RTCTransformEvent&&(self.onrtctransform=t=>{const n=t.transformer,r=n.options,i=r.kind,a=r.participantIdentity,o=r.trackId,s=r.codec,c=r.hasPacketTrailer;Cn.run((()=>e(void 0,void 0,void 0,(function*(){const e=Pn(a,o);e.setHasPacketTrailer(c),l.debug("onrtctransform setup",{participantIdentity:a,trackId:o,codec:s}),e.setupTransform(i,n.readable,n.writable,o,!1,s,"encode"===i?r.packetTrailer:void 0)}))))})}));
|
|
1
|
+
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var t,n={exports:{}};var r,i,a,o,s,c=(t||(t=1,i=n.exports,a=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"],i={},a=null;function o(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return"No console available for logging"}function d(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function u(r,i,a){return function(r){return"debug"===r&&(r="log"),typeof console!==t&&("trace"===r&&n?s:void 0!==console[r]?o(console,r):void 0!==console.log?o(console,"log"):e)}(r)||d.apply(this,arguments)}function l(e,n){var o,s,d,l=this,h="loglevel";function f(){var e;if(typeof window!==t&&h){try{e=window.localStorage[h]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(h),i=n.indexOf(r+"=");-1!==i&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch(e){}return void 0===l.levels[e]&&(e=void 0),e}}function p(e){var t=e;if("string"==typeof t&&void 0!==l.levels[t.toUpperCase()]&&(t=l.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=l.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?h+=":"+e:"symbol"==typeof e&&(h=void 0),l.name=e,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=n||u,l.getLevel=function(){return null!=d?d:null!=s?s:o},l.setLevel=function(e,n){return d=p(e),!1!==n&&function(e){var n=(r[e]||"silent").toUpperCase();if(typeof window!==t&&h){try{return void(window.localStorage[h]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"="+n+";"}catch(e){}}}(d),c.call(l)},l.setDefaultLevel=function(e){s=p(e),f()||l.setLevel(e,!1)},l.resetLevel=function(){d=null,function(){if(typeof window!==t&&h){try{window.localStorage.removeItem(h)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),c.call(l)},l.enableAll=function(e){l.setLevel(l.levels.TRACE,e)},l.disableAll=function(e){l.setLevel(l.levels.SILENT,e)},l.rebuild=function(){if(a!==l&&(o=p(a.getLevel())),c.call(l),a===l)for(var e in i)i[e].rebuild()},o=p(a?a.getLevel():"WARN");var y=f();null!=y&&(d=p(y)),c.call(l)}(a=new 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=i[e];return t||(t=i[e]=new l(e,a.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=h),a},a.getLoggers=function(){return i},a.default=a,a},(r=n).exports?r.exports=a():i.log=a()),n.exports);!function(e){e[e.trace=0]="trace",e[e.debug=1]="debug",e[e.info=2]="info",e[e.warn=3]="warn",e[e.error=4]="error",e[e.silent=5]="silent"}(o||(o={})),function(e){e.Default="livekit",e.Room="livekit-room",e.TokenSource="livekit-token-source",e.Participant="livekit-participant",e.Track="livekit-track",e.Publication="livekit-track-publication",e.Engine="livekit-engine",e.Signal="livekit-signal",e.PCManager="livekit-pc-manager",e.PCTransport="livekit-pc-transport",e.E2EE="lk-e2ee",e.DataTracks="livekit-data-tracks"}(s||(s={}));let d=c.getLogger(s.Default);function u(e,t){const n=c.getLogger(e);return n.setDefaultLevel(d.getLevel()),n}Object.values(s).map((e=>c.getLogger(e))),d.setDefaultLevel(o.info);const l=c.getLogger(s.E2EE);var h,f=Object.defineProperty,p=(e,t,n)=>((e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class y{constructor(){p(this,"_locking"),p(this,"_locks"),this._locking=Promise.resolve(),this._locks=0}isLocked(){return this._locks>0}lock(){let e;this._locks+=1;const t=new Promise((t=>e=()=>{this._locks-=1,t()})),n=this._locking.then((()=>e));return this._locking=this._locking.then((()=>t)),n}}!function(e){e[e.WAITING=0]="WAITING",e[e.RUNNING=1]="RUNNING",e[e.COMPLETED=2]="COMPLETED"}(h||(h={}));const m="AES-GCM",g={key:10,delta:3,audio:1,empty:0},b={sharedKey:!1,ratchetSalt:"LKFrameEncryptionKey",ratchetWindowSize:8,failureTolerance:10,keyringSize:16,keySize:128};function v(e,t){if(!e)throw new Error(t)}function k(e){if("number"!=typeof e)throw new Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new Error("invalid int 32: "+e)}function w(e){if("number"!=typeof e)throw new Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>4294967295||e<0)throw new Error("invalid uint 32: "+e)}function T(e){if("number"!=typeof e)throw new Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>34028234663852886e22||e<-34028234663852886e22))throw new Error("invalid float 32: "+e)}const S=Symbol("@bufbuild/protobuf/enum-type");function I(e){const t=e[S];return v(t,"missing enum type on enum object"),t}function E(e,t,n,r){e[S]=N(t,n.map((t=>({no:t.no,name:t.name,localName:e[t.no]}))))}function N(e,t,n){const r=Object.create(null),i=Object.create(null),a=[];for(const e of t){const t=L(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName:e=>r[e],findNumber:e=>i[e]}}function A(e,t,n){const r={};for(const e of t){const t=L(e);r[t.localName]=t.no,r[t.no]=t.localName}return E(r,e,t),r}function L(e){return"localName"in e?e:Object.assign(Object.assign({},e),{localName:e.name})}class C{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){const n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){const n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error("cannot decode ".concat(this.getType().typeName," from JSON: ").concat(e instanceof Error?e.message:String(e)))}return this.fromJson(n,t)}toBinary(e){const t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){const t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){var t;const n=this.toJson(e);return JSON.stringify(n,null,null!==(t=null==e?void 0:e.prettySpaces)&&void 0!==t?t:0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}}function R(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,!(128&r))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(15&n)<<28,t=(112&n)>>4,!(128&n))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,!(128&r))return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function U(e,t,n){for(let r=0;r<28;r+=7){const i=e>>>r,a=!(i>>>7==0&&0==t),o=255&(a?128|i:i);if(n.push(o),!a)return}const r=e>>>28&15|(7&t)<<4,i=!!(t>>3);if(n.push(255&(i?128|r:r)),i){for(let e=3;e<31;e+=7){const r=t>>>e,i=!(r>>>7==0),a=255&(i?128|r:r);if(n.push(a),!i)return}n.push(t>>>31&1)}}const O=4294967296;function _(e){const t="-"===e[0];t&&(e=e.slice(1));const n=1e6;let r=0,i=0;function a(t,a){const o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=O&&(i+=r/O|0,r%=O)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?P(r,i):D(r,i)}function F(e,t){var n=function(e,t){return{lo:e>>>0,hi:t>>>0}}(e,t);if(e=n.lo,(t=n.hi)<=2097151)return String(O*t+e);const r=16777215&(e>>>24|t<<8),i=t>>16&65535;let a=(16777215&e)+6777216*r+6710656*i,o=r+8147497*i,s=2*i;const c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+M(o)+M(a)}function D(e,t){return{lo:0|e,hi:0|t}}function P(e,t){return t=~t,e?e=1+~e:t+=1,D(e,t)}const M=e=>{const t=String(e);return"0000000".slice(t.length)+t};function x(e,t){if(e>=0){for(;e>127;)t.push(127&e|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(127&e|128),e>>=7;t.push(1)}}function B(){let e=this.buf[this.pos++],t=127&e;if(!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<7,!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<14,!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<21,!(128&e))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(15&e)<<28;for(let t=5;128&e&&t<10;t++)e=this.buf[this.pos++];if(128&e)throw new Error("invalid varint");return this.assertBounds(),t>>>0}const K=function(){const e=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof e.getBigInt64&&"function"==typeof e.getBigUint64&&"function"==typeof e.setBigInt64&&"function"==typeof e.setBigUint64&&("object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const t=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(e){const r="bigint"==typeof e?e:BigInt(e);if(r>n||r<t)throw new Error("int64 invalid: ".concat(e));return r},uParse(e){const t="bigint"==typeof e?e:BigInt(e);if(t>i||t<r)throw new Error("uint64 invalid: ".concat(e));return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec:(t,n)=>(e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)),uDec:(t,n)=>(e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0))}}const t=e=>v(/^-?[0-9]+$/.test(e),"int64 invalid: ".concat(e)),n=e=>v(/^[0-9]+$/.test(e),"uint64 invalid: ".concat(e));return{zero:"0",supported:!1,parse:e=>("string"!=typeof e&&(e=e.toString()),t(e),e),uParse:e=>("string"!=typeof e&&(e=e.toString()),n(e),e),enc:e=>("string"!=typeof e&&(e=e.toString()),t(e),_(e)),uEnc:e=>("string"!=typeof e&&(e=e.toString()),n(e),_(e)),dec:(e,t)=>function(e,t){let n=D(e,t);const r=2147483648&n.hi;r&&(n=P(n.lo,n.hi));const i=F(n.lo,n.hi);return r?"-"+i:i}(e,t),uDec:(e,t)=>F(e,t)}}();var j,V,W;function q(e,t,n){if(t===n)return!0;if(e==j.BYTES){if(!(t instanceof Uint8Array&&n instanceof Uint8Array))return!1;if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case j.UINT64:case j.FIXED64:case j.INT64:case j.SFIXED64:case j.SINT64:return t==n}return!1}function G(e,t){switch(e){case j.BOOL:return!1;case j.UINT64:case j.FIXED64:case j.INT64:case j.SFIXED64:case j.SINT64:return 0==t?K.zero:"0";case j.DOUBLE:case j.FLOAT:return 0;case j.BYTES:return new Uint8Array(0);case j.STRING:return"";default:return 0}}function X(e,t){switch(e){case j.BOOL:return!1===t;case j.STRING:return""===t;case j.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return 0==t}}function J(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function H(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a,o,s=[],c=!0,d=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){d=!0,i=e}finally{try{if(!c&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(d)throw i}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return J(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?J(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}!function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"}(j||(j={})),function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING"}(V||(V={})),function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"}(W||(W={}));class z{constructor(e){this.stack=[],this.textEncoder=null!=e?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(w(e);e>127;)this.buf.push(127&e|128),e>>>=7;return this.buf.push(e),this}int32(e){return k(e),x(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){T(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){w(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){k(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return k(e),x(e=(e<<1^e>>31)>>>0,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=K.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=K.enc(e);return U(t.lo,t.hi,this.buf),this}sint64(e){let t=K.enc(e),n=t.hi>>31;return U(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=K.uEnc(e);return U(t.lo,t.hi,this.buf),this}}class Y{constructor(e,t){this.varint64=R,this.uint32=B,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=null!=t?t:new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=7&e;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case W.Varint:for(;128&this.buf[this.pos++];);break;case W.Bit64:this.pos+=4;case W.Bit32:this.pos+=4;break;case W.LengthDelimited:let n=this.uint32();this.pos+=n;break;case W.StartGroup:for(;;){const e=H(this.tag(),2),n=e[0],r=e[1];if(r===W.EndGroup){if(void 0!==t&&n!==t)throw new Error("invalid end group tag");break}this.skip(r,n)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let e=this.uint32();return e>>>1^-(1&e)}int64(){return K.dec(...this.varint64())}uint64(){return K.uDec(...this.varint64())}sint64(){let e=H(this.varint64(),2),t=e[0],n=e[1],r=-(1&t);return t=(t>>>1|(1&n)<<31)^r,n=n>>>1^r,K.dec(t,n)}bool(){let e=H(this.varint64(),2),t=e[0],n=e[1];return 0!==t||0!==n}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return K.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return K.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}function Q(e){const t=e.field.localName,n=Object.create(null);return n[t]=function(e){const t=e.field;if(t.repeated)return[];if(void 0!==t.default)return t.default;switch(t.kind){case"enum":return t.T.values[0].no;case"scalar":return G(t.T,t.L);case"message":const e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case"map":throw"map fields are not allowed to be extensions"}}(e),[n,()=>n[t]]}let $="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Z=[];for(let e=0;e<$.length;e++)Z[$[e].charCodeAt(0)]=e;Z["-".charCodeAt(0)]=$.indexOf("+"),Z["_".charCodeAt(0)]=$.indexOf("/");const ee={dec(e){let t=3*e.length/4;"="==e[e.length-2]?t-=2:"="==e[e.length-1]&&(t-=1);let n,r=new Uint8Array(t),i=0,a=0,o=0;for(let t=0;t<e.length;t++){if(n=Z[e.charCodeAt(t)],void 0===n)switch(e[t]){case"=":a=0;case"\n":case"\r":case"\t":case" ":continue;default:throw Error("invalid base64 string.")}switch(a){case 0:o=n,a=1;break;case 1:r[i++]=o<<2|(48&n)>>4,o=n,a=2;break;case 2:r[i++]=(15&o)<<4|(60&n)>>2,o=n,a=3;break;case 3:r[i++]=(3&o)<<6|n,a=0}}if(1==a)throw Error("invalid base64 string.");return r.subarray(0,i)},enc(e){let t,n="",r=0,i=0;for(let a=0;a<e.length;a++)switch(t=e[a],r){case 0:n+=$[t>>2],i=(3&t)<<4,r=1;break;case 1:n+=$[i|t>>4],i=(15&t)<<2,r=2;break;case 2:n+=$[i|t>>6],n+=$[63&t],r=0}return r&&(n+=$[i],n+="=",1==r&&(n+="=")),n}};function te(e,t,n){ie(t,e);const r=t.runtime.bin.makeReadOptions(n),i=function(e,t){if(!t.repeated&&("enum"==t.kind||"scalar"==t.kind)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter((e=>e.no===t.no))}(e.getType().runtime.bin.listUnknownFields(e),t.field),a=H(Q(t),2),o=a[0],s=a[1];for(const e of i)t.runtime.bin.readField(o,r.readerFactory(e.data),t.field,e.wireType,r);return s()}function ne(e,t,n,r){ie(t,e);const i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(re(e,t)){const n=e.getType().runtime.bin.listUnknownFields(e).filter((e=>e.no!=t.field.no));e.getType().runtime.bin.discardUnknownFields(e);for(const t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}const o=a.writerFactory();let s=t.field;s.opt||s.repeated||"enum"!=s.kind&&"scalar"!=s.kind||(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);const c=i.readerFactory(o.finish());for(;c.pos<c.len;){const t=H(c.tag(),2),n=t[0],r=t[1],i=c.skip(r,n);e.getType().runtime.bin.onUnknownField(e,n,r,i)}}function re(e,t){const n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find((e=>e.no==t.field.no))}function ie(e,t){v(e.extendee.typeName==t.getType().typeName,"extension ".concat(e.typeName," can only be applied to message ").concat(e.extendee.typeName))}function ae(e,t){const n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case"enum":case"scalar":return e.opt||e.req?void 0!==t[n]:"enum"==e.kind?t[n]!==e.T.values[0].no:!X(e.T,t[n]);case"message":return void 0!==t[n];case"map":return Object.keys(t[n]).length>0}}function oe(e,t){const n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case"map":t[n]={};break;case"enum":t[n]=r?e.T.values[0].no:void 0;break;case"scalar":t[n]=r?G(e.T,e.L):void 0;break;case"message":t[n]=void 0}}function se(e,t){if(null===e||"object"!=typeof e)return!1;if(!Object.getOwnPropertyNames(C.prototype).every((t=>t in e&&"function"==typeof e[t])))return!1;const n=e.getType();return null!==n&&"function"==typeof n&&"typeName"in n&&"string"==typeof n.typeName&&(void 0===t||n.typeName==t.typeName)}function ce(e,t){return se(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}j.DOUBLE,j.FLOAT,j.INT64,j.UINT64,j.INT32,j.UINT32,j.BOOL,j.STRING,j.BYTES;const de={ignoreUnknownFields:!1},ue={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function le(e){return e?Object.assign(Object.assign({},de),e):de}function he(e){return e?Object.assign(Object.assign({},ue),e):ue}const fe=Symbol(),pe=Symbol();function ye(e){if(null===e)return"null";switch(typeof e){case"object":return Array.isArray(e)?"array":"object";case"string":return e.length>100?"string":'"'.concat(e.split('"').join('\\"'),'"');default:return String(e)}}function me(e,t,n,r,i){let a=n.localName;if(n.repeated){if(v("map"!=n.kind),null===t)return;if(!Array.isArray(t))throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(t)));const o=e[a];for(const e of t){if(null===e)throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(e)));switch(n.kind){case"message":o.push(n.T.fromJson(e,r));break;case"enum":const t=ve(n.T,e,r.ignoreUnknownFields,!0);t!==pe&&o.push(t);break;case"scalar":try{o.push(be(n.T,e,n.L,!0))}catch(t){let r="cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(e));throw t instanceof Error&&t.message.length>0&&(r+=": ".concat(t.message)),new Error(r)}}}}else if("map"==n.kind){if(null===t)return;if("object"!=typeof t||Array.isArray(t))throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(t)));const s=e[a];for(const e of Object.entries(t)){var o=H(e,2);const a=o[0],c=o[1];if(null===c)throw new Error("cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: map value null"));let d;try{d=ge(n.K,a)}catch(e){let r="cannot decode map key for field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}switch(n.V.kind){case"message":s[d]=n.V.T.fromJson(c,r);break;case"enum":const e=ve(n.V.T,c,r.ignoreUnknownFields,!0);e!==pe&&(s[d]=e);break;case"scalar":try{s[d]=be(n.V.T,c,V.BIGINT,!0)}catch(e){let r="cannot decode map value for field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a="value"),n.kind){case"message":const o=n.T;if(null===t&&"google.protobuf.Value"!=o.typeName)return;let s=e[a];se(s)?s.fromJson(t,r):(e[a]=s=o.fromJson(t,r),o.fieldWrapper&&!n.oneof&&(e[a]=o.fieldWrapper.unwrapField(s)));break;case"enum":const c=ve(n.T,t,r.ignoreUnknownFields,!1);switch(c){case fe:oe(n,e);break;case pe:break;default:e[a]=c}break;case"scalar":try{const r=be(n.T,t,n.L,!1);if(r===fe)oe(n,e);else e[a]=r}catch(e){let r="cannot decode field ".concat(i.typeName,".").concat(n.name," from JSON: ").concat(ye(t));throw e instanceof Error&&e.message.length>0&&(r+=": ".concat(e.message)),new Error(r)}}}function ge(e,t){if(e===j.BOOL)switch(t){case"true":t=!0;break;case"false":t=!1}return be(e,t,V.BIGINT,!0).toString()}function be(e,t,n,r){if(null===t)return r?G(e,n):fe;switch(e){case j.DOUBLE:case j.FLOAT:if("NaN"===t)return Number.NaN;if("Infinity"===t)return Number.POSITIVE_INFINITY;if("-Infinity"===t)return Number.NEGATIVE_INFINITY;if(""===t)break;if("string"==typeof t&&t.trim().length!==t.length)break;if("string"!=typeof t&&"number"!=typeof t)break;const r=Number(t);if(Number.isNaN(r))break;if(!Number.isFinite(r))break;return e==j.FLOAT&&T(r),r;case j.INT32:case j.FIXED32:case j.SFIXED32:case j.SINT32:case j.UINT32:let i;if("number"==typeof t?i=t:"string"==typeof t&&t.length>0&&t.trim().length===t.length&&(i=Number(t)),void 0===i)break;return e==j.UINT32||e==j.FIXED32?w(i):k(i),i;case j.INT64:case j.SFIXED64:case j.SINT64:if("number"!=typeof t&&"string"!=typeof t)break;const a=K.parse(t);return n?a.toString():a;case j.FIXED64:case j.UINT64:if("number"!=typeof t&&"string"!=typeof t)break;const o=K.uParse(t);return n?o.toString():o;case j.BOOL:if("boolean"!=typeof t)break;return t;case j.STRING:if("string"!=typeof t)break;try{encodeURIComponent(t)}catch(e){throw new Error("invalid UTF8")}return t;case j.BYTES:if(""===t)return new Uint8Array(0);if("string"!=typeof t)break;return ee.dec(t)}throw new Error}function ve(e,t,n,r){if(null===t)return"google.protobuf.NullValue"==e.typeName?0:r?e.values[0].no:fe;switch(typeof t){case"number":if(Number.isInteger(t))return t;break;case"string":const r=e.findName(t);if(void 0!==r)return r.no;if(n)return pe}throw new Error("cannot decode enum ".concat(e.typeName," from JSON: ").concat(ye(t)))}function ke(e){return!(!e.repeated&&"map"!=e.kind)||!e.oneof&&("message"!=e.kind&&(!e.opt&&!e.req))}function we(e,t,n){if("map"==e.kind){v("object"==typeof t&&null!=t);const o={},s=Object.entries(t);switch(e.V.kind){case"scalar":for(const t of s){var r=H(t,2);const n=r[0],i=r[1];o[n.toString()]=Se(e.V.T,i)}break;case"message":for(const e of s){var i=H(e,2);const t=i[0],r=i[1];o[t.toString()]=r.toJson(n)}break;case"enum":const t=e.V.T;for(const e of s){var a=H(e,2);const r=a[0],i=a[1];o[r.toString()]=Te(t,i,n.enumAsInteger)}}return n.emitDefaultValues||s.length>0?o:void 0}if(e.repeated){v(Array.isArray(t));const r=[];switch(e.kind){case"scalar":for(let n=0;n<t.length;n++)r.push(Se(e.T,t[n]));break;case"enum":for(let i=0;i<t.length;i++)r.push(Te(e.T,t[i],n.enumAsInteger));break;case"message":for(let e=0;e<t.length;e++)r.push(t[e].toJson(n))}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case"scalar":return Se(e.T,t);case"enum":return Te(e.T,t,n.enumAsInteger);case"message":return ce(e.T,t).toJson(n)}}function Te(e,t,n){var r;if(v("number"==typeof t),"google.protobuf.NullValue"==e.typeName)return null;if(n)return t;const i=e.findNumber(t);return null!==(r=null==i?void 0:i.name)&&void 0!==r?r:t}function Se(e,t){switch(e){case j.INT32:case j.SFIXED32:case j.SINT32:case j.FIXED32:case j.UINT32:return v("number"==typeof t),t;case j.FLOAT:case j.DOUBLE:return v("number"==typeof t),Number.isNaN(t)?"NaN":t===Number.POSITIVE_INFINITY?"Infinity":t===Number.NEGATIVE_INFINITY?"-Infinity":t;case j.STRING:return v("string"==typeof t),t;case j.BOOL:return v("boolean"==typeof t),t;case j.UINT64:case j.FIXED64:case j.INT64:case j.SFIXED64:case j.SINT64:return v("bigint"==typeof t||"string"==typeof t||"number"==typeof t),t.toString();case j.BYTES:return v(t instanceof Uint8Array),ee.enc(t)}}const Ie=Symbol("@bufbuild/protobuf/unknown-fields"),Ee={readUnknownFields:!0,readerFactory:e=>new Y(e)},Ne={writeUnknownFields:!0,writerFactory:()=>new z};function Ae(e){return e?Object.assign(Object.assign({},Ee),e):Ee}function Le(e){return e?Object.assign(Object.assign({},Ne),e):Ne}function Ce(e,t,n,r,i){let a=n.repeated,o=n.localName;switch(n.oneof&&((e=e[n.oneof.localName]).case!=o&&delete e.value,e.case=o,o="value"),n.kind){case"scalar":case"enum":const s="enum"==n.kind?j.INT32:n.T;let c=Oe;if("scalar"==n.kind&&n.L>0&&(c=Ue),a){let n=e[o];if(r==W.LengthDelimited&&s!=j.STRING&&s!=j.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case"message":const d=n.T;a?e[o].push(Re(t,new d,i,n)):se(e[o])?Re(t,e[o],i,n):(e[o]=Re(t,new d,i,n),!d.fieldWrapper||n.oneof||n.repeated||(e[o]=d.fieldWrapper.unwrapField(e[o])));break;case"map":let u=function(e,t,n){const r=t.uint32(),i=t.pos+r;let a,o;for(;t.pos<i;){switch(H(t.tag(),1)[0]){case 1:a=Oe(t,e.K);break;case 2:switch(e.V.kind){case"scalar":o=Oe(t,e.V.T);break;case"enum":o=t.int32();break;case"message":o=Re(t,new e.V.T,n,void 0)}}}void 0===a&&(a=G(e.K,V.BIGINT));"string"!=typeof a&&"number"!=typeof a&&(a=a.toString());if(void 0===o)switch(e.V.kind){case"scalar":o=G(e.V.T,V.BIGINT);break;case"enum":o=e.V.T.values[0].no;break;case"message":o=new e.V.T}return[a,o]}(n,t,i),l=H(u,2),h=l[0],f=l[1];e[o][h]=f}}function Re(e,t,n,r){const i=t.getType().runtime.bin,a=null==r?void 0:r.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function Ue(e,t){const n=Oe(e,t);return"bigint"==typeof n?n.toString():n}function Oe(e,t){switch(t){case j.STRING:return e.string();case j.BOOL:return e.bool();case j.DOUBLE:return e.double();case j.FLOAT:return e.float();case j.INT32:return e.int32();case j.INT64:return e.int64();case j.UINT64:return e.uint64();case j.FIXED64:return e.fixed64();case j.BYTES:return e.bytes();case j.FIXED32:return e.fixed32();case j.SFIXED32:return e.sfixed32();case j.SFIXED64:return e.sfixed64();case j.SINT64:return e.sint64();case j.UINT32:return e.uint32();case j.SINT32:return e.sint32()}}function _e(e,t,n,r){v(void 0!==t);const i=e.repeated;switch(e.kind){case"scalar":case"enum":let o="enum"==e.kind?j.INT32:e.T;if(i)if(v(Array.isArray(t)),e.packed)!function(e,t,n,r){if(!r.length)return;e.tag(n,W.LengthDelimited).fork();let i=H(Me(t),2)[1];for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}(n,o,e.no,t);else for(const r of t)Pe(n,o,e.no,r);else Pe(n,o,e.no,t);break;case"message":if(i){v(Array.isArray(t));for(const i of t)De(n,r,e,i)}else De(n,r,e,t);break;case"map":v("object"==typeof t&&null!=t);for(const i of Object.entries(t)){var a=H(i,2);Fe(n,r,e,a[0],a[1])}}}function Fe(e,t,n,r,i){e.tag(n.no,W.LengthDelimited),e.fork();let a=r;switch(n.K){case j.INT32:case j.FIXED32:case j.UINT32:case j.SFIXED32:case j.SINT32:a=Number.parseInt(r);break;case j.BOOL:v("true"==r||"false"==r),a="true"==r}switch(Pe(e,n.K,1,a),n.V.kind){case"scalar":Pe(e,n.V.T,2,i);break;case"enum":Pe(e,j.INT32,2,i);break;case"message":v(void 0!==i),e.tag(2,W.LengthDelimited).bytes(i.toBinary(t))}e.join()}function De(e,t,n,r){const i=ce(n.T,r);n.delimited?e.tag(n.no,W.StartGroup).raw(i.toBinary(t)).tag(n.no,W.EndGroup):e.tag(n.no,W.LengthDelimited).bytes(i.toBinary(t))}function Pe(e,t,n,r){v(void 0!==r);let i=H(Me(t),2),a=i[0],o=i[1];e.tag(n,a)[o](r)}function Me(e){let t=W.Varint;switch(e){case j.BYTES:case j.STRING:t=W.LengthDelimited;break;case j.DOUBLE:case j.FIXED64:case j.SFIXED64:t=W.Bit64;break;case j.FIXED32:case j.SFIXED32:case j.FLOAT:t=W.Bit32}return[t,j[e].toLowerCase()]}function xe(e){if(void 0===e)return e;if(se(e))return e.clone();if(e instanceof Uint8Array){const t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Be(e){return e instanceof Uint8Array?e:new Uint8Array(e)}class Ke{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){const e={};for(const t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){const e={};for(const t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||(this.all=this._normalizer(this._fields)),this.all}byNumber(){return this.numbersAsc||(this.numbersAsc=this.list().concat().sort(((e,t)=>e.no-t.no))),this.numbersAsc}byMember(){if(!this.members){this.members=[];const e=this.members;let t;for(const n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}}function je(e,t){const n=We(e);return t?n:He(Je(n))}const Ve=We;function We(e){let t=!1;const n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case"_":t=!0;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join("")}const qe=new Set(["constructor","toString","toJSON","valueOf"]),Ge=new Set(["getType","clone","equals","fromBinary","fromJson","fromJsonString","toBinary","toJson","toJsonString","toObject"]),Xe=e=>"".concat(e,"$"),Je=e=>Ge.has(e)?Xe(e):e,He=e=>qe.has(e)?Xe(e):e;class ze{constructor(e){this.kind="oneof",this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=je(e,!1)}addField(e){v(e.oneof===this,"field ".concat(e.name," not one of ").concat(this.name)),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}}const Ye=(Qe=e=>new Ke(e,(e=>function(e){var t,n,r,i,a,o;const s=[];let c;for(const d of"function"==typeof e?e():e){const e=d;if(e.localName=je(d.name,void 0!==d.oneof),e.jsonName=null!==(t=d.jsonName)&&void 0!==t?t:Ve(d.name),e.repeated=null!==(n=d.repeated)&&void 0!==n&&n,"scalar"==d.kind&&(e.L=null!==(r=d.L)&&void 0!==r?r:V.BIGINT),e.delimited=null!==(i=d.delimited)&&void 0!==i&&i,e.req=null!==(a=d.req)&&void 0!==a&&a,e.opt=null!==(o=d.opt)&&void 0!==o&&o,void 0===d.packed&&(e.packed="enum"==d.kind||"scalar"==d.kind&&d.T!=j.BYTES&&d.T!=j.STRING),void 0!==d.oneof){const t="string"==typeof d.oneof?d.oneof:d.oneof.name;c&&c.name==t||(c=new ze(t)),e.oneof=c,c.addField(e)}s.push(e)}return s}(e))),$e=e=>{for(const t of e.getType().fields.byMember()){if(t.opt)continue;const n=t.localName,r=e;if(t.repeated)r[n]=[];else switch(t.kind){case"oneof":r[n]={case:void 0};break;case"enum":r[n]=0;break;case"map":r[n]={};break;case"scalar":r[n]=G(t.T,t.L)}}},{syntax:"proto3",json:{makeReadOptions:le,makeWriteOptions:he,readMessage(e,t,n,r){if(null==t||Array.isArray(t)||"object"!=typeof t)throw new Error("cannot decode message ".concat(e.typeName," from JSON: ").concat(ye(t)));r=null!=r?r:new e;const i=new Map,a=n.typeRegistry;for(const s of Object.entries(t)){var o=H(s,2);const t=o[0],c=o[1],d=e.fields.findJsonName(t);if(d){if(d.oneof){if(null===c&&"scalar"==d.kind)continue;const n=i.get(d.oneof);if(void 0!==n)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: multiple keys for oneof "').concat(d.oneof.name,'" present: "').concat(n,'", "').concat(t,'"'));i.set(d.oneof,t)}me(r,c,d,n,e)}else{let i=!1;if((null==a?void 0:a.findExtension)&&t.startsWith("[")&&t.endsWith("]")){const o=a.findExtension(t.substring(1,t.length-1));if(o&&o.extendee.typeName==e.typeName){i=!0;const e=H(Q(o),2),t=e[0],a=e[1];me(t,c,o.field,n,o),ne(r,o,a(),n)}}if(!i&&!n.ignoreUnknownFields)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: key "').concat(t,'" is unknown'))}}return r},writeMessage(e,t){const n=e.getType(),r={};let i;try{for(i of n.fields.byNumber()){if(!ae(i,e)){if(i.req)throw"required field not set";if(!t.emitDefaultValues)continue;if(!ke(i))continue}const n=we(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t);void 0!==n&&(r[t.useProtoFieldName?i.name:i.jsonName]=n)}const a=t.typeRegistry;if(null==a?void 0:a.findExtensionFor)for(const i of n.runtime.bin.listUnknownFields(e)){const o=a.findExtensionFor(n.typeName,i.no);if(o&&re(e,o)){const n=te(e,o,t),i=we(o.field,n,t);void 0!==i&&(r[o.field.jsonName]=i)}}}catch(e){const t=i?"cannot encode field ".concat(n.typeName,".").concat(i.name," to JSON"):"cannot encode message ".concat(n.typeName," to JSON"),r=e instanceof Error?e.message:String(e);throw new Error(t+(r.length>0?": ".concat(r):""))}return r},readScalar:(e,t,n)=>be(e,t,null!=n?n:V.BIGINT,!0),writeScalar(e,t,n){if(void 0!==t)return n||X(e,t)?Se(e,t):void 0},debug:ye},bin:{makeReadOptions:Ae,makeWriteOptions:Le,listUnknownFields(e){var t;return null!==(t=e[Ie])&&void 0!==t?t:[]},discardUnknownFields(e){delete e[Ie]},writeUnknownFields(e,t){const n=e[Ie];if(n)for(const e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){const i=e;Array.isArray(i[Ie])||(i[Ie]=[]),i[Ie].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){const a=e.getType(),o=i?t.len:t.pos+n;let s,c;for(;t.pos<o;){var d=H(t.tag(),2);if(s=d[0],c=d[1],!0===i&&c==W.EndGroup)break;const n=a.fields.find(s);if(n)Ce(e,t,n,c,r);else{const n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n)}}if(i&&(c!=W.EndGroup||s!==n))throw new Error("invalid end group tag")},readField:Ce,writeMessage(e,t,n){const r=e.getType();for(const i of r.fields.byNumber())if(ae(i,e))_e(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n);else if(i.req)throw new Error("cannot encode field ".concat(r.typeName,".").concat(i.name," to binary: required field not set"));return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){void 0!==t&&_e(e,t,n,r)}},util:Object.assign(Object.assign({},{setEnumType:E,initPartial(e,t){if(void 0===e)return;const n=t.getType();for(const i of n.fields.byMember()){const n=i.localName,a=t,o=e;if(null!=o[n])switch(i.kind){case"oneof":const e=o[n].case;if(void 0===e)continue;const t=i.findField(e);let s=o[n].value;t&&"message"==t.kind&&!se(s,t.T)?s=new t.T(s):t&&"scalar"===t.kind&&t.T===j.BYTES&&(s=Be(s)),a[n]={case:e,value:s};break;case"scalar":case"enum":let c=o[n];i.T===j.BYTES&&(c=i.repeated?c.map(Be):Be(c)),a[n]=c;break;case"map":switch(i.V.kind){case"scalar":case"enum":if(i.V.T===j.BYTES)for(const e of Object.entries(o[n])){var r=H(e,2);const t=r[0],i=r[1];a[n][t]=Be(i)}else Object.assign(a[n],o[n]);break;case"message":const e=i.V.T;for(const t of Object.keys(o[n])){let r=o[n][t];e.fieldWrapper||(r=new e(r)),a[n][t]=r}}break;case"message":const d=i.T;if(i.repeated)a[n]=o[n].map((e=>se(e,d)?e:new d(e)));else{const e=o[n];d.fieldWrapper?"google.protobuf.BytesValue"===d.typeName?a[n]=Be(e):a[n]=e:a[n]=se(e,d)?e:new d(e)}}}},equals:(e,t,n)=>t===n||!(!t||!n)&&e.fields.byMember().every((e=>{const r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case"message":return r.every(((t,n)=>e.T.equals(t,i[n])));case"scalar":return r.every(((t,n)=>q(e.T,t,i[n])));case"enum":return r.every(((e,t)=>q(j.INT32,e,i[t])))}throw new Error("repeated cannot contain ".concat(e.kind))}switch(e.kind){case"message":let t=r,n=i;return e.T.fieldWrapper&&(void 0===t||se(t)||(t=e.T.fieldWrapper.wrapField(t)),void 0===n||se(n)||(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case"enum":return q(j.INT32,r,i);case"scalar":return q(e.T,r,i);case"oneof":if(r.case!==i.case)return!1;const a=e.findField(r.case);if(void 0===a)return!0;switch(a.kind){case"message":return a.T.equals(r.value,i.value);case"enum":return q(j.INT32,r.value,i.value);case"scalar":return q(a.T,r.value,i.value)}throw new Error("oneof cannot contain ".concat(a.kind));case"map":const o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case"message":const t=e.V.T;return o.every((e=>t.equals(r[e],i[e])));case"enum":return o.every((e=>q(j.INT32,r[e],i[e])));case"scalar":const n=e.V.T;return o.every((e=>q(n,r[e],i[e])))}}})),clone(e){const t=e.getType(),n=new t,r=n;for(const n of t.fields.byMember()){const t=e[n.localName];let a;if(n.repeated)a=t.map(xe);else if("map"==n.kind){a=r[n.localName];for(const e of Object.entries(t)){var i=H(e,2);const t=i[0],n=i[1];a[t]=xe(n)}}else a="oneof"==n.kind?n.findField(t.case)?{case:t.case,value:xe(t.value)}:{case:void 0}:xe(t);r[n.localName]=a}for(const n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}),{newFieldList:Qe,initFields:$e}),makeMessageType(e,t,n){return function(e,t,n,r){var i;const a=null!==(i=null==r?void 0:r.localName)&&void 0!==i?i:t.substring(t.lastIndexOf(".")+1),o={[a]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[a];return Object.setPrototypeOf(o.prototype,new C),Object.assign(o,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary:(e,t)=>(new o).fromBinary(e,t),fromJson:(e,t)=>(new o).fromJson(e,t),fromJsonString:(e,t)=>(new o).fromJsonString(e,t),equals:(t,n)=>e.util.equals(o,t,n)}),o}(this,e,t,n)},makeEnum:A,makeEnumType:N,getEnumType:I,makeExtension(e,t,n){return function(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){const n="function"==typeof r?r():r;n.name=t.split(".").pop(),n.jsonName="[".concat(t,"]"),i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}(this,e,t,n)}});var Qe,$e;const Ze=Ye.makeEnum("livekit.TrackType",[{no:0,name:"AUDIO"},{no:1,name:"VIDEO"},{no:2,name:"DATA"}]),et=Ye.makeEnum("livekit.TrackSource",[{no:0,name:"UNKNOWN"},{no:1,name:"CAMERA"},{no:2,name:"MICROPHONE"},{no:3,name:"SCREEN_SHARE"},{no:4,name:"SCREEN_SHARE_AUDIO"}]),tt=Ye.makeEnum("livekit.StreamState",[{no:0,name:"ACTIVE"},{no:1,name:"PAUSED"}]);class nt extends Error{constructor(e,t,n){super(t||"an error has occurred"),this.name="LiveKitError",this.code=e,void 0!==(null==n?void 0:n.cause)&&(this.cause=null==n?void 0:n.cause)}}var rt,it,at,ot,st,ct,dt,ut;!function(e){e[e.NotAllowed=0]="NotAllowed",e[e.ServerUnreachable=1]="ServerUnreachable",e[e.InternalError=2]="InternalError",e[e.Cancelled=3]="Cancelled",e[e.LeaveRequest=4]="LeaveRequest",e[e.Timeout=5]="Timeout",e[e.WebSocket=6]="WebSocket",e[e.ServiceNotFound=7]="ServiceNotFound"}(rt||(rt={})),function(e){e[e.AlreadyOpened=0]="AlreadyOpened",e[e.AbnormalEnd=1]="AbnormalEnd",e[e.DecodeFailed=2]="DecodeFailed",e[e.LengthExceeded=3]="LengthExceeded",e[e.Incomplete=4]="Incomplete",e[e.HandlerAlreadyRegistered=7]="HandlerAlreadyRegistered",e[e.EncryptionTypeMismatch=8]="EncryptionTypeMismatch"}(it||(it={})),function(e){e.PermissionDenied="PermissionDenied",e.NotFound="NotFound",e.DeviceInUse="DeviceInUse",e.Other="Other"}(at||(at={})),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}}(at||(at={})),function(e){e[e.InvalidKey=0]="InvalidKey",e[e.MissingKey=1]="MissingKey",e[e.InternalError=2]="InternalError"}(ot||(ot={}));class lt extends nt{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ot.InternalError,n=arguments.length>2?arguments[2]:void 0;super(40,e),this.reason=t,this.participantIdentity=n}}function ht(e){return"type"in e}function ft(e,t){const n=(new TextEncoder).encode(t);switch(e){case"HKDF":return{name:"HKDF",salt:n,hash:"SHA-256",info:new ArrayBuffer(128)};case"PBKDF2":return{name:"PBKDF2",salt:n,hash:"SHA-256",iterations:1e5};default:throw new Error("algorithm ".concat(e," is currently unsupported"))}}function pt(t,n){return e(this,void 0,void 0,(function*(){const e=ft(t.algorithm.name,n.ratchetSalt),r=yield crypto.subtle.deriveKey(e,t,{name:m,length:n.keySize},!1,["encrypt","decrypt"]);return{material:t,encryptionKey:r}}))}!function(e){e.SetKey="setKey",e.RatchetRequest="ratchetRequest",e.KeyRatcheted="keyRatcheted"}(st||(st={})),function(e){e.KeyRatcheted="keyRatcheted"}(ct||(ct={})),function(e){e.ParticipantEncryptionStatusChanged="participantEncryptionStatusChanged",e.EncryptionError="encryptionError"}(dt||(dt={})),function(e){e.Error="cryptorError"}(ut||(ut={}));class yt{static makeIV(e){const t=new ArrayBuffer(12),n=new DataView(t),r=crypto.getRandomValues(new Uint32Array(1));return n.setUint32(0,r[0]),n.setUint32(4,e),n.setUint32(8,e-yt.sendCount%65535),yt.sendCount++,t}static encrypt(t,n){return e(this,void 0,void 0,(function*(){const e=yt.makeIV(performance.now()),r=yield n.getKeySet();if(!r)throw new Error("No key set found");const i=yield crypto.subtle.encrypt({name:m,iv:e},r.encryptionKey,new Uint8Array(t));return{payload:new Uint8Array(i),iv:new Uint8Array(e),keyIndex:n.getCurrentKeyIndex()}}))}static decrypt(t,n,r){return e(this,arguments,void 0,(function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=arguments.length>4?arguments[4]:void 0,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{ratchetCount:0};return function*(){const o=yield n.getKeySet(r);if(!o)throw new Error("No key set found");try{const n=yield crypto.subtle.decrypt({name:m,iv:t},o.encryptionKey,new Uint8Array(e));return{payload:new Uint8Array(n)}}catch(s){if(n.keyProviderOptions.ratchetWindowSize>0){if(a.ratchetCount<n.keyProviderOptions.ratchetWindowSize){let s,c;l.debug("DataCryptor: ratcheting key attempt ".concat(a.ratchetCount," of ").concat(n.keyProviderOptions.ratchetWindowSize,", for data packet")),(null!=i?i:o)===n.getKeySet(r)&&(c=yield n.ratchetKey(r,!1),s=yield pt(c.cryptoKey,n.keyProviderOptions));const d=yield yt.decrypt(e,t,n,r,i,{ratchetCount:a.ratchetCount+1,encryptionKey:null==s?void 0:s.encryptionKey});return d&&s&&(null!=i?i:o)===n.getKeySet(r)&&(n.setKeySet(s,r,c),n.setCurrentKeyIndex(r)),d}throw l.warn("DataCryptor: maximum ratchet attempts exceeded"),new lt("DataCryptor: valid key missing for participant ".concat(n.participantIdentity),ot.InvalidKey,n.participantIdentity)}throw new lt("DataCryptor: Decryption failed: ".concat(s.message),ot.InvalidKey,n.participantIdentity)}}()}))}}yt.sendCount=0;var mt,gt={exports:{}};var bt,vt,kt=function(){if(mt)return gt.exports;mt=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}gt.exports=i,gt.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}p(e,t,a,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,n)}(e,i,{once:!0})}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function o(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function s(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,a,c,d;if(o(n),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),c=a[t]),void 0===c)c=a[t]=n,++e._eventsCount;else if("function"==typeof c?c=a[t]=r?[n,c]:[c,n]:r?c.unshift(n):c.push(n),(i=s(e))>0&&c.length>i&&!c.warned){c.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=c.length,d=u,console&&console.warn&&console.warn(d)}return e}function d(){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 u(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=d.bind(r);return i.listener=n,r.wrapFn=i,i}function l(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):f(i,i.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function f(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function p(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);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 i(a){r.once&&e.removeEventListener(t,i),n(a)}))}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.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},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(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},i.prototype.getMaxListeners=function(){return s(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,a=this._events;if(void 0!==a)i=i&&void 0===a.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var c=a[e];if(void 0===c)return!1;if("function"==typeof c)n(c,this,t);else{var d=c.length,u=f(c,d);for(r=0;r<d;++r)n(u[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return o(t),this.on(e,u(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,u(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,i,a,s;if(o(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return l(this,e,!0)},i.prototype.rawListeners=function(e){return l(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},i.prototype.listenerCount=h,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},gt.exports}();class wt extends(vt=Promise){constructor(e){super(e)}catch(e){return super.catch(e)}static reject(e){return super.reject(e)}static all(e){return super.all(e)}static race(e){return super.race(e)}}bt=wt,wt.resolve=e=>Reflect.get(vt,"resolve",bt).call(bt,e);const Tt=/version\/(\d+(\.?_?\d+)+)/i;let St;function It(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("undefined"==typeof navigator)return;const n=navigator.userAgent.toLowerCase();if(void 0===St||t){const e=Et.find((e=>e.test.test(n)));St=null==e?void 0:e.describe(n)}return St}const Et=[{test:/firefox|iceweasel|fxios/i,describe:e=>({name:"Firefox",version:Nt(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("fxios")?"iOS":void 0,osVersion:At(e)})},{test:/chrom|crios|crmo/i,describe:e=>({name:"Chrome",version:Nt(/(?:chrome|chromium|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("crios")?"iOS":void 0,osVersion:At(e)})},{test:/safari|applewebkit/i,describe:e=>({name:"Safari",version:Nt(Tt,e),os:e.includes("mobile/")?"iOS":"macOS",osVersion:At(e)})}];function Nt(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;const r=t.match(e);return r&&r.length>=n&&r[n]||""}function At(e){return e.includes("mac os")?Nt(/\(.+?(\d+_\d+(:?_\d+)?)/,e,1).replace(/_/g,"."):void 0}var Lt,Ct,Rt,Ut;!function(e){e.Connected="connected",e.Reconnecting="reconnecting",e.SignalReconnecting="signalReconnecting",e.Reconnected="reconnected",e.Disconnected="disconnected",e.ConnectionStateChanged="connectionStateChanged",e.Moved="moved",e.MediaDevicesChanged="mediaDevicesChanged",e.ParticipantConnected="participantConnected",e.ParticipantDisconnected="participantDisconnected",e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalAudioSilenceDetected="localAudioSilenceDetected",e.ActiveSpeakersChanged="activeSpeakersChanged",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.ParticipantAttributesChanged="participantAttributesChanged",e.ParticipantActive="participantActive",e.RoomMetadataChanged="roomMetadataChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.AudioPlaybackStatusChanged="audioPlaybackChanged",e.VideoPlaybackStatusChanged="videoPlaybackChanged",e.MediaDevicesError="mediaDevicesError",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.SignalConnected="signalConnected",e.RecordingStatusChanged="recordingStatusChanged",e.ParticipantEncryptionStatusChanged="participantEncryptionStatusChanged",e.EncryptionError="encryptionError",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ActiveDeviceChanged="activeDeviceChanged",e.ChatMessage="chatMessage",e.LocalTrackSubscribed="localTrackSubscribed",e.MetricsReceived="metricsReceived",e.DataTrackPublished="dataTrackPublished",e.DataTrackUnpublished="dataTrackUnpublished",e.LocalDataTrackPublished="localDataTrackPublished",e.LocalDataTrackUnpublished="localDataTrackUnpublished"}(Lt||(Lt={})),function(e){e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackCpuConstrained="localTrackCpuConstrained",e.LocalSenderCreated="localSenderCreated",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.IsSpeakingChanged="isSpeakingChanged",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.TrackCpuConstrained="trackCpuConstrained",e.MediaDevicesError="mediaDevicesError",e.AudioStreamAcquired="audioStreamAcquired",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.PCTrackAdded="pcTrackAdded",e.AttributesChanged="attributesChanged",e.LocalTrackSubscribed="localTrackSubscribed",e.ChatMessage="chatMessage",e.Active="active"}(Ct||(Ct={})),function(e){e.TransportsCreated="transportsCreated",e.Connected="connected",e.Disconnected="disconnected",e.Resuming="resuming",e.Resumed="resumed",e.Restarting="restarting",e.Restarted="restarted",e.SignalResumed="signalResumed",e.SignalRestarted="signalRestarted",e.Closing="closing",e.MediaTrackAdded="mediaTrackAdded",e.ActiveSpeakersUpdate="activeSpeakersUpdate",e.DataPacketReceived="dataPacketReceived",e.RTPVideoMapUpdate="rtpVideoMapUpdate",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ParticipantUpdate="participantUpdate",e.RoomUpdate="roomUpdate",e.SpeakersChanged="speakersChanged",e.StreamStateChanged="streamStateChanged",e.ConnectionQualityUpdate="connectionQualityUpdate",e.SubscriptionError="subscriptionError",e.SubscriptionPermissionUpdate="subscriptionPermissionUpdate",e.RemoteMute="remoteMute",e.SubscribedQualityUpdate="subscribedQualityUpdate",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackSubscribed="localTrackSubscribed",e.Offline="offline",e.SignalRequestResponse="signalRequestResponse",e.SignalConnected="signalConnected",e.RoomMoved="roomMoved",e.PublishDataTrackResponse="publishDataTrackResponse",e.UnPublishDataTrackResponse="unPublishDataTrackResponse",e.DataTrackSubscriberHandles="dataTrackSubscriberHandles",e.DataTrackPacketReceived="dataTrackPacketReceived",e.Joined="joined",e.TokenRefreshed="tokenRefreshed",e.ServerRegionsReported="serverRegionsReported"}(Rt||(Rt={})),function(e){e.Message="message",e.Muted="muted",e.Unmuted="unmuted",e.Restarted="restarted",e.Ended="ended",e.Subscribed="subscribed",e.Unsubscribed="unsubscribed",e.CpuConstrained="cpuConstrained",e.UpdateSettings="updateSettings",e.UpdateSubscription="updateSubscription",e.AudioPlaybackStarted="audioPlaybackStarted",e.AudioPlaybackFailed="audioPlaybackFailed",e.AudioSilenceDetected="audioSilenceDetected",e.VisibilityChanged="visibilityChanged",e.VideoDimensionsChanged="videoDimensionsChanged",e.VideoPlaybackStarted="videoPlaybackStarted",e.VideoPlaybackFailed="videoPlaybackFailed",e.ElementAttached="elementAttached",e.ElementDetached="elementDetached",e.UpstreamPaused="upstreamPaused",e.UpstreamResumed="upstreamResumed",e.SubscriptionPermissionChanged="subscriptionPermissionChanged",e.SubscriptionStatusChanged="subscriptionStatusChanged",e.SubscriptionFailed="subscriptionFailed",e.TrackProcessorUpdate="trackProcessorUpdate",e.AudioTrackFeatureUpdate="audioTrackFeatureUpdate",e.TranscriptionReceived="transcriptionReceived",e.TimeSyncUpdate="timeSyncUpdate",e.PreConnectBufferFlushed="preConnectBufferFlushed"}(Ut||(Ut={}));class Ot{constructor(e,t,n,r,i){if("object"==typeof e)this.width=e.width,this.height=e.height,this.aspectRatio=e.aspectRatio,this.encoding={maxBitrate:e.maxBitrate,maxFramerate:e.maxFramerate,priority:e.priority};else{if(void 0===t||void 0===n)throw new TypeError("Unsupported options: provide at least width, height and maxBitrate");this.width=e,this.height=t,this.aspectRatio=e/t,this.encoding={maxBitrate:n,maxFramerate:r,priority:i}}}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.aspectRatio}}}const _t=["vp8","h264","vp9","av1","h265"];var Ft,Dt;function Pt(e){return"mediaStreamTrack"in e?{trackID:e.sid,source:e.source,muted:e.isMuted,enabled:e.mediaStreamTrack.enabled,kind:e.kind,streamID:e.mediaStreamID,streamTrackID:e.mediaStreamTrack.id}:{trackID:e.trackSid,enabled:e.isEnabled,muted:e.isMuted,trackInfo:Object.assign({mimeType:e.mimeType,name:e.trackName,encrypted:e.isEncrypted,kind:e.kind,source:e.source},e.track?Pt(e.track):{})}}!function(e){e[e.PREFER_REGRESSION=0]="PREFER_REGRESSION",e[e.SIMULCAST=1]="SIMULCAST",e[e.REGRESSION=2]="REGRESSION"}(Ft||(Ft={})),function(e){e.telephone={maxBitrate:12e3},e.speech={maxBitrate:24e3},e.music={maxBitrate:48e3},e.musicStereo={maxBitrate:64e3},e.musicHighQuality={maxBitrate:96e3},e.musicHighQualityStereo={maxBitrate:128e3}}(Dt||(Dt={})),new Ot(160,90,9e4,20),new Ot(320,180,16e4,20),new Ot(384,216,18e4,20),new Ot(640,360,45e4,20),new Ot(960,540,8e5,25),new Ot(1280,720,17e5,30),new Ot(1920,1080,3e6,30),new Ot(2560,1440,5e6,30),new Ot(3840,2160,8e6,30),new Ot(160,120,7e4,20),new Ot(240,180,125e3,20),new Ot(320,240,14e4,20),new Ot(480,360,33e4,20),new Ot(640,480,5e5,20),new Ot(720,540,6e5,25),new Ot(960,720,13e5,30),new Ot(1440,1080,23e5,30),new Ot(1920,1440,38e5,30),new Ot(640,360,2e5,3,"medium"),new Ot(640,360,4e5,15,"medium"),new Ot(1280,720,8e5,5,"medium"),new Ot(1280,720,15e5,15,"medium"),new Ot(1280,720,2e6,30,"medium"),new Ot(1920,1080,25e5,15,"medium"),new Ot(1920,1080,5e6,30,"medium"),new Ot(0,0,7e6,30,"medium");const Mt=[];var xt;!function(e){e[e.LOW=0]="LOW",e[e.MEDIUM=1]="MEDIUM",e[e.HIGH=2]="HIGH"}(xt||(xt={}));class Bt extends kt.EventEmitter{get streamState(){return this._streamState}setStreamState(e){this._streamState=e}constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var r;super(),this.attachedElements=[],this.isMuted=!1,this._streamState=Bt.StreamState.Active,this.isInBackground=!1,this._currentBitrate=0,this.log=d,this.appVisibilityChangedListener=()=>{this.backgroundTimeout&&clearTimeout(this.backgroundTimeout),"hidden"===document.visibilityState?this.backgroundTimeout=setTimeout((()=>this.handleAppVisibilityChanged()),5e3):this.handleAppVisibilityChanged()},this.log=u(null!==(r=n.loggerName)&&void 0!==r?r:s.Track),this.loggerContextCb=n.loggerContextCb,this.setMaxListeners(100),this.kind=t,this._mediaStreamTrack=e,this._mediaStreamID=e.id,this.source=Bt.Source.Unknown}get logContext(){var e;return Object.assign(Object.assign({},null===(e=this.loggerContextCb)||void 0===e?void 0:e.call(this)),Pt(this))}get currentBitrate(){return this._currentBitrate}get mediaStreamTrack(){return this._mediaStreamTrack}get mediaStreamID(){return this._mediaStreamID}attach(e){let t="audio";this.kind===Bt.Kind.Video&&(t="video"),0===this.attachedElements.length&&this.kind===Bt.Kind.Video&&this.addAppVisibilityListener(),e||("audio"===t&&(Mt.forEach((t=>{null!==t.parentElement||e||(e=t)})),e&&Mt.splice(Mt.indexOf(e),1)),e||(e=document.createElement(t))),this.attachedElements.includes(e)||this.attachedElements.push(e),function(e,t){let n,r;n=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream;r="audio"===e.kind?n.getAudioTracks():n.getVideoTracks();r.includes(e)||(r.forEach((e=>{n.removeTrack(e)})),n.addTrack(e));jt()&&t instanceof HTMLVideoElement||(t.autoplay=!0);t.muted=0===n.getAudioTracks().length,t instanceof HTMLVideoElement&&(t.playsInline=!0);t.srcObject!==n&&(t.srcObject=n,(jt()||function(){var e;return"Firefox"===(null===(e=It())||void 0===e?void 0:e.name)}())&&t instanceof HTMLVideoElement&&setTimeout((()=>{t.srcObject=n,t.play().catch((()=>{}))}),0))}(this.mediaStreamTrack,e);const n=e.srcObject.getTracks(),r=n.some((e=>"audio"===e.kind));return e.play().then((()=>{this.emit(r?Ut.AudioPlaybackStarted:Ut.VideoPlaybackStarted)})).catch((t=>{"NotAllowedError"===t.name?this.emit(r?Ut.AudioPlaybackFailed:Ut.VideoPlaybackFailed,t):"AbortError"===t.name?d.debug("".concat(r?"audio":"video"," playback aborted, likely due to new play request")):d.warn("could not playback ".concat(r?"audio":"video"),t),r&&e&&n.some((e=>"video"===e.kind))&&"NotAllowedError"===t.name&&(e.muted=!0,e.play().catch((()=>{})))})),this.emit(Ut.ElementAttached,e),e}detach(e){try{if(e){Kt(this.mediaStreamTrack,e);const t=this.attachedElements.indexOf(e);return t>=0&&(this.attachedElements.splice(t,1),this.recycleElement(e),this.emit(Ut.ElementDetached,e)),e}const t=[];return this.attachedElements.forEach((e=>{Kt(this.mediaStreamTrack,e),t.push(e),this.recycleElement(e),this.emit(Ut.ElementDetached,e)})),this.attachedElements=[],t}finally{0===this.attachedElements.length&&this.removeAppVisibilityListener()}}stop(){this.stopMonitor(),this._mediaStreamTrack.stop()}enable(){this._mediaStreamTrack.enabled=!0}disable(){this._mediaStreamTrack.enabled=!1}stopMonitor(){this.monitorInterval&&clearInterval(this.monitorInterval),this.timeSyncHandle&&cancelAnimationFrame(this.timeSyncHandle)}updateLoggerOptions(e){e.loggerName&&(this.log=u(e.loggerName)),e.loggerContextCb&&(this.loggerContextCb=e.loggerContextCb)}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),Mt.forEach((e=>{e.parentElement||(t=!1)})),t&&Mt.push(e)}}handleAppVisibilityChanged(){return e(this,void 0,void 0,(function*(){this.isInBackground="hidden"===document.visibilityState,this.isInBackground||this.kind!==Bt.Kind.Video||setTimeout((()=>this.attachedElements.forEach((e=>e.play().catch((()=>{}))))),0)}))}addAppVisibilityListener(){Vt()?(this.isInBackground="hidden"===document.visibilityState,document.addEventListener("visibilitychange",this.appVisibilityChangedListener)):this.isInBackground=!1}removeAppVisibilityListener(){Vt()&&document.removeEventListener("visibilitychange",this.appVisibilityChangedListener)}}function Kt(e,t){if(t.srcObject instanceof MediaStream){const n=t.srcObject;n.removeTrack(e),n.getTracks().length>0?t.srcObject=n:t.srcObject=null}}function jt(){var e;return"Safari"===(null===(e=It())||void 0===e?void 0:e.name)}function Vt(){return"undefined"!=typeof document}function Wt(e){return!(!(null==e?void 0:e.timestamp)&&!(null==e?void 0:e.frameId))}!function(e){let t,n,r;!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"}(n=e.Source||(e.Source={})),function(e){e.Active="active",e.Paused="paused",e.Unknown="unknown"}(r=e.StreamState||(e.StreamState={})),e.kindToProto=function(e){switch(e){case t.Audio:return Ze.AUDIO;case t.Video:return Ze.VIDEO;default:return Ze.DATA}},e.kindFromProto=function(e){switch(e){case Ze.AUDIO:return t.Audio;case Ze.VIDEO:return t.Video;default:return t.Unknown}},e.sourceToProto=function(e){switch(e){case n.Camera:return et.CAMERA;case n.Microphone:return et.MICROPHONE;case n.ScreenShare:return et.SCREEN_SHARE;case n.ScreenShareAudio:return et.SCREEN_SHARE_AUDIO;default:return et.UNKNOWN}},e.sourceFromProto=function(e){switch(e){case et.CAMERA:return n.Camera;case et.MICROPHONE:return n.Microphone;case et.SCREEN_SHARE:return n.ScreenShare;case et.SCREEN_SHARE_AUDIO:return n.ScreenShareAudio;default:return n.Unknown}},e.streamStateFromProto=function(e){switch(e){case tt.ACTIVE:return r.Active;case tt.PAUSED:return r.Paused;default:return r.Unknown}}}(Bt||(Bt={}));const qt=Uint8Array.from(["L".charCodeAt(0),"K".charCodeAt(0),"T".charCodeAt(0),"S".charCodeAt(0)]);function Gt(e,t,n){const r=t!==BigInt(0),i=0!==n;if(!r&&!i)return e;const a=(r?10:0)+(i?6:0)+5,o=new Uint8Array(e.length+a);let s=0;return o.set(e,s),s+=e.length,r&&(o[s++]=254,o[s++]=247,function(e,t,n){const r=Number(n>>BigInt(32)&BigInt(4294967295)),i=Number(n&BigInt(4294967295));e[t]=r>>>24^255,e[t+1]=r>>>16&255^255,e[t+2]=r>>>8&255^255,e[t+3]=255&r^255,e[t+4]=i>>>24^255,e[t+5]=i>>>16&255^255,e[t+6]=i>>>8&255^255,e[t+7]=255&i^255}(o,s,t),s+=8),i&&(o[s++]=253,o[s++]=251,function(e,t,n){for(let r=3;r>=0;r-=1)e[t+(3-r)]=n>>8*r&255^255}(o,s,n),s+=4),o[s++]=255^a,o.set(qt,s),o}function Xt(e){const t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.length<5)return{data:t};if(!function(e,t){for(let n=0;n<qt.length;n+=1)if(e[t+n]!==qt[n])return!1;return!0}(t,t.length-qt.length))return{data:t};const n=255^t[t.length-5];if(n<5||n>t.length)return{data:t};const r=t.length-n,i=t.length-5,a=t.subarray(0,r);let o=r,s=!1;const c={userTimestamp:BigInt(0),frameId:0};for(;o+2<=i;){const e=255^t[o++],n=255^t[o++];if(o+n>i)break;1===e&&8===n?(c.userTimestamp=Jt(t,o),s=!0):2===e&&4===n&&(c.frameId=Ht(t,o,n),s=!0),o+=n}return s?{data:a,metadata:c}:{data:t}}function Jt(e,t){const n=BigInt(((255^e[t])<<24|(255^e[t+1])<<16|(255^e[t+2])<<8|255^e[t+3])>>>0),r=BigInt(((255^e[t+4])<<24|(255^e[t+5])<<16|(255^e[t+6])<<8|255^e[t+7])>>>0);return n<<BigInt(32)|r}function Ht(e,t,n){let r=0;for(let i=0;i<n;i+=1)r=r<<8|255^e[t+i];return r>>>0}function zt(e){try{const t=e.getMetadata();if("number"==typeof t.synchronizationSource)return t.synchronizationSource}catch(e){}return 0}var Yt,Qt;function $t(e){return 31&e}function Zt(e){return e>>1&63}function en(e){return e===Yt.SLICE_IDR||e===Yt.SLICE_NON_IDR}function tn(e){return e===Qt.TRAIL_N||e===Qt.TRAIL_R||e===Qt.TSA_N||e===Qt.TSA_R||e===Qt.STSA_N||e===Qt.STSA_R||e===Qt.RADL_N||e===Qt.RADL_R||e===Qt.RASL_N||e===Qt.RASL_R||e===Qt.BLA_W_LP||e===Qt.BLA_W_RADL||e===Qt.BLA_N_LP||e===Qt.IDR_W_RADL||e===Qt.IDR_N_LP||e===Qt.CRA_NUT}function nn(e,t){const n=function(e){const t=[];let n=0,r=0,i=e.length-3;for(;r<i;){for(;r<i&&!(r<i-1&&0===e[r]&&0===e[r+1]&&0===e[r+2]&&1===e[r+3])&&(0!==e[r]||0!==e[r+1]||1!==e[r+2]);)r++;r>=i&&(r=e.length);let a=r;for(;a>n&&0===e[a-1];)a--;if(0===n){if(a!==n)throw TypeError("byte stream contains leading data")}else t.push(n);let o=3;r<e.length-3&&0===e[r]&&0===e[r+1]&&0===e[r+2]&&1===e[r+3]&&(o=4),n=r+=o}return t}(e),r=null!=t?t:function(e,t){for(const n of t){if(en($t(e[n])))return"h264";if(tn(Zt(e[n])))return"h265"}return"unknown"}(e,n);if("unknown"===r)return{unencryptedBytes:0,detectedCodec:r,requiresNALUProcessing:!1};const i=function(e,t,n){for(const r of t)if("h265"===n){if(tn(Zt(e[r])))return r+2}else if(en($t(e[r])))return r+2;return null}(e,n,r);if(null===i)throw new TypeError("Could not find NALU");return{unencryptedBytes:i,detectedCodec:r,requiresNALUProcessing:!0}}!function(e){e[e.SLICE_NON_IDR=1]="SLICE_NON_IDR",e[e.SLICE_PARTITION_A=2]="SLICE_PARTITION_A",e[e.SLICE_PARTITION_B=3]="SLICE_PARTITION_B",e[e.SLICE_PARTITION_C=4]="SLICE_PARTITION_C",e[e.SLICE_IDR=5]="SLICE_IDR",e[e.SEI=6]="SEI",e[e.SPS=7]="SPS",e[e.PPS=8]="PPS",e[e.AUD=9]="AUD",e[e.END_SEQ=10]="END_SEQ",e[e.END_STREAM=11]="END_STREAM",e[e.FILLER_DATA=12]="FILLER_DATA",e[e.SPS_EXT=13]="SPS_EXT",e[e.PREFIX_NALU=14]="PREFIX_NALU",e[e.SUBSET_SPS=15]="SUBSET_SPS",e[e.DPS=16]="DPS",e[e.SLICE_AUX=19]="SLICE_AUX",e[e.SLICE_EXT=20]="SLICE_EXT",e[e.SLICE_LAYER_EXT=21]="SLICE_LAYER_EXT"}(Yt||(Yt={})),function(e){e[e.TRAIL_N=0]="TRAIL_N",e[e.TRAIL_R=1]="TRAIL_R",e[e.TSA_N=2]="TSA_N",e[e.TSA_R=3]="TSA_R",e[e.STSA_N=4]="STSA_N",e[e.STSA_R=5]="STSA_R",e[e.RADL_N=6]="RADL_N",e[e.RADL_R=7]="RADL_R",e[e.RASL_N=8]="RASL_N",e[e.RASL_R=9]="RASL_R",e[e.BLA_W_LP=16]="BLA_W_LP",e[e.BLA_W_RADL=17]="BLA_W_RADL",e[e.BLA_N_LP=18]="BLA_N_LP",e[e.IDR_W_RADL=19]="IDR_W_RADL",e[e.IDR_N_LP=20]="IDR_N_LP",e[e.CRA_NUT=21]="CRA_NUT",e[e.VPS_NUT=32]="VPS_NUT",e[e.SPS_NUT=33]="SPS_NUT",e[e.PPS_NUT=34]="PPS_NUT",e[e.AUD_NUT=35]="AUD_NUT",e[e.EOS_NUT=36]="EOS_NUT",e[e.EOB_NUT=37]="EOB_NUT",e[e.FD_NUT=38]="FD_NUT",e[e.PREFIX_SEI_NUT=39]="PREFIX_SEI_NUT",e[e.SUFFIX_SEI_NUT=40]="SUFFIX_SEI_NUT"}(Qt||(Qt={}));const rn="ef0161653d8b2b23aad46624b420af1d03ce48950e9fc85718028f91b50f9219",an="f0a0e09647d891d6d50aa898bce7108090375d0d55e50a2bb21147afee558e44",on="61d9665eed71b6d424ae9539330a3bdd5cb386d4d781c808219a6e36750493a7",sn="faffc26b68a2fc09096fa20f3351e706398b6f838a7500c8063472c2e476e90d",cn="aad8d31fc56b2802ca500e58c2fb9d0b29ad71bb7cb52cd6530251eade188988";function dn(t){return e(this,void 0,void 0,(function*(){const n=yield function(t){return e(this,void 0,void 0,(function*(){const e=yield crypto.subtle.digest("SHA-256",t),n=new Uint8Array(e);return Array.from(n).map((e=>e.toString(16).padStart(2,"0"))).join("")}))}(t);switch(n){case rn:return"vp8";case an:case on:case sn:return"h264";case cn:return"opus";default:return null}}))}const un=new Map;class ln extends kt.EventEmitter{encodeFunction(e,t){throw Error("not implemented for subclass")}decodeFunction(e,t){throw Error("not implemented for subclass")}}class hn extends ln{constructor(e){var t;super(),this.hasFrameMetadata=!1,this.frameMetadataFrameId=0,this.lastErrorTimestamp=new Map,this.errorCounts=new Map,this.ERROR_THROTTLE_MS=1e3,this.MAX_ERRORS_PER_MINUTE=5,this.ERROR_WINDOW_MS=6e4,this.loggedNALUFallbacks=new Set,this.sendCounts=new Map,this.keys=e.keys,this.participantIdentity=e.participantIdentity,this.rtpMap=new Map,this.keyProviderOptions=e.keyProviderOptions,this.sifTrailer=null!==(t=e.sifTrailer)&&void 0!==t?t:Uint8Array.from([])}get logContext(){return{participant:this.participantIdentity,mediaTrackId:this.trackId,fallbackCodec:this.videoCodec}}setParticipant(e,t){l.debug("setting new participant on cryptor",Object.assign(Object.assign({},this.logContext),{newParticipant:e,hadPreviousParticipant:!!this.participantIdentity})),this.participantIdentity&&this.participantIdentity!==e&&(l.warn("cryptor has already a participant set, cleaning up before switching",{oldParticipant:this.participantIdentity,newParticipant:e,trackId:this.trackId}),this.unsetParticipant()),this.participantIdentity=e,this.keys=t}unsetParticipant(){l.debug("unsetting participant",this.logContext),this.currentTransform&&(this.currentTransform=void 0),this.participantIdentity=void 0,this.lastErrorTimestamp=new Map,this.errorCounts=new Map}isEnabled(){return this.participantIdentity?un.get(this.participantIdentity):void 0}getParticipantIdentity(){return this.participantIdentity}getTrackId(){return this.trackId}setVideoCodec(e){this.videoCodec=e}setRtpMap(e){this.rtpMap=e}setHasFrameMetadata(e){this.hasFrameMetadata=e}setFrameMetadataOpts(e){this.frameMetadataOpts=e,this.frameMetadataFrameId=0}setupTransform(e,t,n,r,i,a,o){if(a&&(l.info("setting codec on cryptor to",{codec:a}),this.videoCodec=a),"encode"===e&&this.setFrameMetadataOpts(o),l.debug("Setting up frame cryptor transform",Object.assign({operation:e,passedTrackId:r,codec:a,isReuse:i,hasCurrentTransform:!!this.currentTransform},this.logContext)),this.trackId=r,i&&this.currentTransform&&t===this.currentTransform.readable&&n===this.currentTransform.writable)return void l.debug("reusing existing transform",Object.assign(Object.assign({},this.logContext),{trackId:r}));const s=Symbol("transform"),c="encode"===e?this.encodeFunction:this.decodeFunction,d=new TransformStream({transform:c.bind(this)});this.currentTransform={readable:t,writable:n,transformer:d,trackId:r,symbol:s},t.pipeThrough(d).pipeTo(n).catch((e=>{e instanceof TypeError&&"Destination stream closed"===e.message?l.debug("destination stream closed"):(l.warn("transform error",Object.assign({error:e},this.logContext)),this.emit(ut.Error,e instanceof lt?e:new lt(e.message,void 0,this.participantIdentity)))})).finally((()=>{var e;(null===(e=this.currentTransform)||void 0===e?void 0:e.symbol)===s&&(l.debug("transform completed",Object.assign(Object.assign({},this.logContext),{trackId:r})),this.currentTransform=void 0)}))}setSifTrailer(e){l.debug("setting SIF trailer",Object.assign(Object.assign({},this.logContext),{trailer:e})),this.sifTrailer=e}shouldEmitError(e){var t,n;const r=Date.now(),i=null!==(t=this.lastErrorTimestamp.get(e))&&void 0!==t?t:0,a=null!==(n=this.errorCounts.get(e))&&void 0!==n?n:0;return r-i>this.ERROR_WINDOW_MS?(this.errorCounts.set(e,0),this.lastErrorTimestamp.set(e,r),!0):!(r-i<this.ERROR_THROTTLE_MS)&&(a>=this.MAX_ERRORS_PER_MINUTE?(a===this.MAX_ERRORS_PER_MINUTE&&(l.warn("Suppressing further decryption errors for ".concat(this.participantIdentity),Object.assign(Object.assign({},this.logContext),{errorKey:e})),this.errorCounts.set(e,a+1)),!1):(this.lastErrorTimestamp.set(e,r),this.errorCounts.set(e,a+1),!0))}emitThrottledError(e){var t;const n="".concat(this.participantIdentity,"-").concat(e.reason,"-decrypt");if(this.shouldEmitError(n)){const r=null!==(t=this.errorCounts.get(n))&&void 0!==t?t:0;r>1&&l.debug("Decryption error (".concat(r," occurrences in window)"),Object.assign(Object.assign({},this.logContext),{reason:ot[e.reason]})),this.emit(ut.Error,e)}}encodeFunction(t,n){return e(this,void 0,void 0,(function*(){var e;if(0===t.data.byteLength)return n.enqueue(t);if(!this.isEnabled())return this.appendFrameMetadata(t),n.enqueue(t);const r=this.keys.getKeySet();if(!r)return void this.emitThrottledError(new lt("key set not found for ".concat(this.participantIdentity," at index ").concat(this.keys.getCurrentKeyIndex()),ot.MissingKey,this.participantIdentity));const i=r.encryptionKey,a=this.keys.getCurrentKeyIndex();if(i){const r=this.makeIV(null!==(e=t.getMetadata().synchronizationSource)&&void 0!==e?e:-1,t.timestamp);let s=this.getUnencryptedBytes(t);const c=new Uint8Array(t.data,0,s.unencryptedBytes),d=new Uint8Array(2);d[0]=12,d[1]=a;try{const e=yield crypto.subtle.encrypt({name:m,iv:r,additionalData:new Uint8Array(t.data,0,c.byteLength)},i,new Uint8Array(t.data,s.unencryptedBytes));let a=new Uint8Array(e.byteLength+r.byteLength+d.byteLength);a.set(new Uint8Array(e)),a.set(new Uint8Array(r),e.byteLength),a.set(d,e.byteLength+r.byteLength),s.requiresNALUProcessing&&(a=function(e){const t=[];for(var n=0,r=0;r<e.length;++r){var i=e[r];i<=3&&n>=2&&(t.push(3),n=0),t.push(i),0==i?++n:n=0}return new Uint8Array(t)}(a));var o=new Uint8Array(c.byteLength+a.byteLength);return o.set(c),o.set(a,c.byteLength),t.data=o.buffer,this.appendFrameMetadata(t),n.enqueue(t)}catch(e){l.error(e)}}else l.debug("failed to encrypt, emitting error",this.logContext),this.emitThrottledError(new lt("encryption key missing for encoding",ot.MissingKey,this.participantIdentity))}))}appendFrameMetadata(e){var t;Wt(this.frameMetadataOpts)&&ht(e)&&((null===(t=this.frameMetadataOpts)||void 0===t?void 0:t.frameId)&&(this.frameMetadataFrameId=4294967295===this.frameMetadataFrameId?1:this.frameMetadataFrameId+1),function(e,t,n){if(!Wt(t)||0===e.data.byteLength)return!1;const r=(null==t?void 0:t.timestamp)?BigInt(Date.now())*BigInt(1e3):BigInt(0),i=(null==t?void 0:t.frameId)?n:0,a=new Uint8Array(e.data),o=Gt(a,r,i);o.byteLength!==a.byteLength&&(e.data=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength))}(e,this.frameMetadataOpts,this.frameMetadataFrameId))}decodeFunction(t,n){return e(this,void 0,void 0,(function*(){if(this.hasFrameMetadata&&ht(t))try{const e=function(e,t){if(0===e.data.byteLength)return{};const n=Xt(e.data);if(!n.metadata)return{};const r=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength),i=function(e){try{const t=e.getMetadata();if("number"==typeof t.rtpTimestamp)return t.rtpTimestamp;if("number"==typeof t.timestamp)return t.timestamp}catch(e){}if("number"==typeof e.timestamp)return e.timestamp}(e);return void 0!==i&&t?{data:r,payload:{trackId:t,rtpTimestamp:i,ssrc:zt(e),metadata:n.metadata}}:{data:r}}(t,this.trackId);if(e.data&&(t.data=e.data),e.payload&&this.participantIdentity){const t={kind:"packetTrailerMetadata",data:e.payload};postMessage(t)}}catch(e){}if(!this.isEnabled()||0===t.data.byteLength)return n.enqueue(t);if(function(e,t){if(0===t.byteLength)return!1;const n=new Uint8Array(e.slice(e.byteLength-t.byteLength));return t.every(((e,t)=>e===n[t]))}(t.data,this.sifTrailer))return t.data=t.data.slice(0,t.data.byteLength-this.sifTrailer.byteLength),(yield dn(t.data))?(l.debug("enqueue SIF",this.logContext),n.enqueue(t)):void l.warn("Unexpected SIF frame payload, dropping frame",this.logContext);const e=new Uint8Array(t.data)[t.data.byteLength-1];if(!this.keys.hasInvalidKeyAtIndex(e))if(this.keys.getKeySet(e))try{const r=yield this.decryptFrame(t,e);if(this.keys.decryptionSuccess(e),r)return n.enqueue(r)}catch(t){t instanceof lt&&t.reason===ot.InvalidKey?this.keys.hasValidKey&&(this.emitThrottledError(t),this.keys.decryptionFailure(e)):l.warn("decoding frame failed",{error:t})}else l.warn("skipping decryption due to missing key at index ".concat(e)),this.emitThrottledError(new lt("missing key at index ".concat(e," for participant ").concat(this.participantIdentity),ot.MissingKey,this.participantIdentity)),this.keys.decryptionFailure(e)}))}decryptFrame(t,n){return e(this,arguments,void 0,(function(e,t){var n=this;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{ratchetCount:0};return function*(){var a;const o=n.keys.getKeySet(t);if(!i.encryptionKey&&!o)throw new TypeError("no encryption key found for decryption of ".concat(n.participantIdentity));let s=n.getUnencryptedBytes(e);try{const t=new Uint8Array(e.data,0,s.unencryptedBytes);var c=new Uint8Array(e.data,t.length,e.data.byteLength-t.length);if(s.requiresNALUProcessing&&function(e){for(var t=0;t<e.length-3;t++)if(0==e[t]&&0==e[t+1]&&3==e[t+2])return!0;return!1}(c)){c=function(e){const t=[];for(var n=e.length,r=0;r<e.length;)n-r>=3&&!e[r]&&!e[r+1]&&3==e[r+2]?(t.push(e[r++]),t.push(e[r++]),r++):t.push(e[r++]);return new Uint8Array(t)}(c);const n=new Uint8Array(t.byteLength+c.byteLength);n.set(t),n.set(c,t.byteLength),e.data=n.buffer}const n=new Uint8Array(e.data,e.data.byteLength-2,2),r=n[0],d=new Uint8Array(e.data,e.data.byteLength-r-n.byteLength,r),u=t.byteLength,l=e.data.byteLength-(t.byteLength+r+n.byteLength),h=yield crypto.subtle.decrypt({name:m,iv:d,additionalData:new Uint8Array(e.data,0,t.byteLength)},null!==(a=i.encryptionKey)&&void 0!==a?a:o.encryptionKey,new Uint8Array(e.data,u,l)),f=new ArrayBuffer(t.byteLength+h.byteLength),p=new Uint8Array(f);return p.set(new Uint8Array(e.data,0,t.byteLength)),p.set(new Uint8Array(h),t.byteLength),e.data=f,e}catch(a){if(n.keyProviderOptions.ratchetWindowSize>0){if(i.ratchetCount<n.keyProviderOptions.ratchetWindowSize){let a,s;l.debug("ratcheting key attempt ".concat(i.ratchetCount," of ").concat(n.keyProviderOptions.ratchetWindowSize,", for kind ").concat(e instanceof RTCEncodedAudioFrame?"audio":"video")),(null!=r?r:o)===n.keys.getKeySet(t)&&(s=yield n.keys.ratchetKey(t,!1),a=yield pt(s.cryptoKey,n.keyProviderOptions));const c=yield n.decryptFrame(e,t,r||o,{ratchetCount:i.ratchetCount+1,encryptionKey:null==a?void 0:a.encryptionKey});return c&&a&&(null!=r?r:o)===n.keys.getKeySet(t)&&(n.keys.setKeySet(a,t,s),n.keys.setCurrentKeyIndex(t)),c}throw l.warn("maximum ratchet attempts exceeded"),new lt("valid key missing for participant ".concat(n.participantIdentity),ot.InvalidKey,n.participantIdentity)}throw new lt("Decryption failed: ".concat(a.message),ot.InvalidKey,n.participantIdentity)}}()}))}makeIV(e,t){var n;const r=new ArrayBuffer(12),i=new DataView(r);this.sendCounts.has(e)||this.sendCounts.set(e,Math.floor(65535*Math.random()));const a=null!==(n=this.sendCounts.get(e))&&void 0!==n?n:0;return i.setUint32(0,e),i.setUint32(4,t),i.setUint32(8,t-a%65535),this.sendCounts.set(e,a+1),r}getUnencryptedBytes(e){var t;if(!ht(e))return{unencryptedBytes:g.audio,requiresNALUProcessing:!1};const n=null!==(t=this.getVideoCodec(e))&&void 0!==t?t:this.videoCodec;if(n!==this.detectedCodec&&(l.debug("detected different codec",Object.assign({detectedCodec:n,oldCodec:this.detectedCodec},this.logContext)),this.detectedCodec=n),"av1"===n)throw new Error("".concat(n," is not yet supported for end to end encryption"));if("vp8"===n)return{unencryptedBytes:g[e.type],requiresNALUProcessing:!1};if("vp9"===n)return{unencryptedBytes:0,requiresNALUProcessing:!1};const r=e.getMetadata().payloadType,i="".concat(this.participantIdentity,"-").concat(this.trackId,"-").concat(r);try{const t="h264"===n||"h265"===n?n:void 0,r=nn(new Uint8Array(e.data),t);if(r.requiresNALUProcessing)return this.loggedNALUFallbacks.delete(i),{unencryptedBytes:r.unencryptedBytes,requiresNALUProcessing:!0}}catch(e){this.logNALUFallbackOnce(i,r,e)}return{unencryptedBytes:g[e.type],requiresNALUProcessing:!1}}logNALUFallbackOnce(e,t,n){this.loggedNALUFallbacks.has(e)||(this.loggedNALUFallbacks.add(e),l.warn("NALU processing failed, falling back to VP8 handling",Object.assign({error:n,payloadType:t},this.logContext)))}getVideoCodec(e){const t=e.getMetadata();if(t.mimeType){const e=t.mimeType.split("/")[1].toLowerCase();if(_t.includes(e))return e}if(0===this.rtpMap.size)return;const n=t.payloadType;return n?this.rtpMap.get(n):void 0}}class fn extends kt.EventEmitter{get hasValidKey(){return!this.hasInvalidKeyAtIndex(this.currentKeyIndex)}constructor(e,t){if(super(),this.currentKeyIndex=0,t.keyringSize<1||t.keyringSize>256)throw new TypeError("Keyring size needs to be between 1 and 256");this.cryptoKeyRing=new Array(t.keyringSize).fill(void 0),this.decryptionFailureCounts=new Array(t.keyringSize).fill(0),this.keyProviderOptions=t,this.ratchetPromiseMap=new Map,this.participantIdentity=e}hasInvalidKeyAtIndex(e){return this.keyProviderOptions.failureTolerance>=0&&this.decryptionFailureCounts[e]>this.keyProviderOptions.failureTolerance}decryptionFailure(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.currentKeyIndex;this.keyProviderOptions.failureTolerance<0||(this.decryptionFailureCounts[e]+=1,this.decryptionFailureCounts[e]>this.keyProviderOptions.failureTolerance&&l.warn("key for ".concat(this.participantIdentity," at index ").concat(e," is being marked as invalid")))}decryptionSuccess(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.currentKeyIndex;this.resetKeyStatus(e)}resetKeyStatus(e){void 0===e?this.decryptionFailureCounts.fill(0):this.decryptionFailureCounts[e]=0}ratchetKey(t){let n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=null!=t?t:this.getCurrentKeyIndex(),i=this.ratchetPromiseMap.get(r);if(void 0!==i)return i;const a=new Promise(((t,i)=>e(this,void 0,void 0,(function*(){try{const i=this.getKeySet(r);if(!i)throw new TypeError("Cannot ratchet key without a valid keyset of participant ".concat(this.participantIdentity));const a=i.material,o=yield function(t,n){return e(this,void 0,void 0,(function*(){const e=ft(t.algorithm.name,n);return crypto.subtle.deriveBits(e,t,256)}))}(a,this.keyProviderOptions.ratchetSalt),s=yield function(t){return e(this,arguments,void 0,(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{name:m},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"encrypt";return function*(){return crypto.subtle.importKey("raw",e,t,!1,"derive"===n?["deriveBits","deriveKey"]:["encrypt","decrypt"])}()}))}(o,a.algorithm.name,"derive"),c={chainKey:o,cryptoKey:s};n&&(yield this.setKeyFromMaterial(s,r,c)),t(c)}catch(e){i(e)}finally{this.ratchetPromiseMap.delete(r)}}))));return this.ratchetPromiseMap.set(r,a),a}setKey(t){return e(this,arguments,void 0,(function(e){var t=this;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return function*(){yield t.setKeyFromMaterial(e,n,null,r),r&&t.resetKeyStatus(n)}()}))}setKeyFromMaterial(t,n){return e(this,arguments,void 0,(function(e,t){var n=this;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return function*(){const a=yield pt(e,n.keyProviderOptions),o=t>=0?t%n.cryptoKeyRing.length:n.currentKeyIndex;l.debug("setting new key with index ".concat(t),{usage:e.usages,algorithm:e.algorithm,ratchetSalt:n.keyProviderOptions.ratchetSalt}),n.setKeySet(a,o,r),o>=0&&i&&(n.currentKeyIndex=o)}()}))}setKeySet(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.cryptoKeyRing[t%this.cryptoKeyRing.length]=e,n&&this.emit(ct.KeyRatcheted,n,this.participantIdentity,t)}setCurrentKeyIndex(t){return e(this,void 0,void 0,(function*(){this.currentKeyIndex=t%this.cryptoKeyRing.length,this.resetKeyStatus(t)}))}getCurrentKeyIndex(){return this.currentKeyIndex}getKeySet(e){return this.cryptoKeyRing[null!=e?e:this.currentKeyIndex]}}const pn=[],yn=new Map;let mn,gn,bn=new class{constructor(){this.pendingTasks=new Map,this.taskMutex=new y,this.nextTaskIndex=0}run(t){return e(this,void 0,void 0,(function*(){const e={id:this.nextTaskIndex++,enqueuedAt:Date.now(),status:h.WAITING};this.pendingTasks.set(e.id,e);const n=yield this.taskMutex.lock();try{return e.executedAt=Date.now(),e.status=h.RUNNING,yield t()}finally{e.status=h.COMPLETED,this.pendingTasks.delete(e.id),n()}}))}flush(){return e(this,void 0,void 0,(function*(){return this.run((()=>e(this,void 0,void 0,(function*(){}))))}))}snapshot(){return Array.from(this.pendingTasks.values())}},vn=!1,kn=b,wn=new Map;function Tn(e,t){let n=pn.filter((e=>e.getTrackId()===t));if(n.length>1){const r=n.map((e=>({participant:e.getParticipantIdentity()}))).join(",");l.error("Found multiple cryptors for the same trackID ".concat(t,". target participant: ").concat(e," "),{participants:r})}let r=n[0];if(r)e!==r.getParticipantIdentity()&&r.setParticipant(e,Sn(e));else{if(l.info("creating new cryptor for",{participantIdentity:e,trackId:t}),!kn)throw Error("Missing keyProvider options");r=new hn({participantIdentity:e,keys:Sn(e),keyProviderOptions:kn,sifTrailer:gn}),r.setRtpMap(wn),function(e){e.on(ut.Error,(e=>{const t={kind:"error",data:{error:new Error("".concat(ot[e.reason],": ").concat(e.message)),participantIdentity:e.participantIdentity}};postMessage(t)}))}(r),pn.push(r)}return r}function Sn(e){if(vn)return In();let t=yn.get(e);return t||(t=new fn(e,kn),t.on(ct.KeyRatcheted,En),yn.set(e,t)),t}function In(){return mn||(l.debug("creating new shared key handler"),mn=new fn("shared-key",kn)),mn}function En(e,t,n){postMessage({kind:"ratchetKey",data:{participantIdentity:t,keyIndex:n,ratchetResult:e}})}l.setDefaultLevel("info"),onmessage=t=>{bn.run((()=>e(void 0,void 0,void 0,(function*(){const n=t.data,r=n.kind,i=n.data;switch(r){case"init":l.setLevel(i.loglevel),l.info("worker initialized"),kn=i.keyProviderOptions,vn=!!i.keyProviderOptions.sharedKey;postMessage({kind:"initAck",data:{enabled:false}});break;case"enable":o=i.enabled,s=i.participantIdentity,l.debug("setting encryption enabled for all tracks of ".concat(s),{enable:o}),un.set(s,o),l.info("updated e2ee enabled status for ".concat(i.participantIdentity," to ").concat(i.enabled)),postMessage(t.data);break;case"decode":let n=Tn(i.participantIdentity,i.trackId);n.setHasFrameMetadata(i.hasPacketTrailer),n.setupTransform(r,i.readableStream,i.writableStream,i.trackId,i.isReuse,i.codec);break;case"encode":let c=Tn(i.participantIdentity,i.trackId);c.setHasFrameMetadata(i.hasPacketTrailer),c.setupTransform(r,i.readableStream,i.writableStream,i.trackId,i.isReuse,i.codec,i.packetTrailer);break;case"encryptDataRequest":const d=yield yt.encrypt(i.payload,Sn(i.participantIdentity)),u=d.payload,h=d.iv,f=d.keyIndex;console.log("encrypted payload",{original:i.payload,encrypted:u,iv:h}),postMessage({kind:"encryptDataResponse",data:{payload:u,iv:h,keyIndex:f,uuid:i.uuid}});break;case"decryptDataRequest":try{const e=(yield yt.decrypt(i.payload,i.iv,Sn(i.participantIdentity),i.keyIndex)).payload;postMessage({kind:"decryptDataResponse",data:{payload:e,uuid:i.uuid}})}catch(e){l.error("DataCryptor decryption failed",{error:e,participantIdentity:i.participantIdentity,uuid:i.uuid}),postMessage({kind:"error",data:{error:e instanceof Error?e:new Error(String(e)),uuid:i.uuid}})}break;case"setKey":vn?yield function(t,n,r){return e(this,void 0,void 0,(function*(){l.info("set shared key",{index:n}),yield In().setKey(t,n,r)}))}(i.key,i.keyIndex,i.updateCurrentKeyIndex):i.participantIdentity?(l.info("set participant sender key ".concat(i.participantIdentity," index ").concat(i.keyIndex)),yield Sn(i.participantIdentity).setKey(i.key,i.keyIndex,i.updateCurrentKeyIndex)):l.error("no participant Id was provided and shared key usage is disabled");break;case"removeTransform":!function(e,t){const n=pn.filter((n=>n.getParticipantIdentity()===t&&n.getTrackId()===e));n.length>1&&l.error("Found multiple cryptors for the same participant and trackID combination",{trackId:e,participantIdentity:t});const r=n[0];r?r.unsetParticipant():l.warn("Could not unset participant on cryptor",{trackId:e,participantIdentity:t})}(i.trackId,i.participantIdentity);break;case"updateCodec":const p=Tn(i.participantIdentity,i.trackId);p.setVideoCodec(i.codec),p.setHasFrameMetadata(i.hasPacketTrailer),l.info("updated codec",{participantIdentity:i.participantIdentity,trackId:i.trackId,codec:i.codec,hasPacketTrailer:i.hasPacketTrailer});break;case"setRTPMap":wn=i.map,pn.forEach((e=>{e.getParticipantIdentity()===i.participantIdentity&&e.setRtpMap(i.map)}));break;case"ratchetRequest":!function(t){e(this,void 0,void 0,(function*(){if(vn){const e=In();yield e.ratchetKey(t.keyIndex),e.resetKeyStatus()}else if(t.participantIdentity){const e=Sn(t.participantIdentity);yield e.ratchetKey(t.keyIndex),e.resetKeyStatus()}else l.error("no participant Id was provided for ratchet request and shared key usage is disabled")}))}(i);break;case"setSifTrailer":a=i.trailer,gn=a,pn.forEach((e=>{e.setSifTrailer(a)}))}var a,o,s}))))},self.RTCTransformEvent&&(self.onrtctransform=t=>{const n=t.transformer,r=n.options,i=r.kind,a=r.participantIdentity,o=r.trackId,s=r.codec,c=r.hasPacketTrailer;bn.run((()=>e(void 0,void 0,void 0,(function*(){const e=Tn(a,o);e.setHasFrameMetadata(c),l.debug("onrtctransform setup",{participantIdentity:a,trackId:o,codec:s}),e.setupTransform(i,n.readable,n.writable,o,!1,s,"encode"===i?r.packetTrailer:void 0)}))))})}));
|
|
2
2
|
//# sourceMappingURL=livekit-client.e2ee.worker.js.map
|