From 4b5f550532495cb2363fadabd86339efb273a5e5 Mon Sep 17 00:00:00 2001 From: CrazyH <87752773+CrazyH2@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:07:47 +0100 Subject: [PATCH] add server scripts --- libraries/peerjs.esm.js | 58 ++++++ server.html | 18 ++ server/controllerTracking.js | 38 ++++ server/positionalTracking.js | 62 ++++++- server/rotationalTracking.js | 45 +++++ server/serverScript.js | 4 +- server/socketScript.js | 44 +++++ utils/ControllerBluetoothInterface.js | 254 ++++++++++++++++++++++++++ 8 files changed, 518 insertions(+), 5 deletions(-) create mode 100644 libraries/peerjs.esm.js create mode 100644 server/controllerTracking.js create mode 100644 server/rotationalTracking.js create mode 100644 server/socketScript.js create mode 100644 utils/ControllerBluetoothInterface.js diff --git a/libraries/peerjs.esm.js b/libraries/peerjs.esm.js new file mode 100644 index 0000000..f15051b --- /dev/null +++ b/libraries/peerjs.esm.js @@ -0,0 +1,58 @@ +/* esm.sh - esbuild bundle(peerjs@1.5.2) es2021 production */ +(()=>{var R=Object.defineProperty;var C=(n,e,t)=>e in n?R(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var f=(n,e,t)=>(C(n,typeof e!="symbol"?e+"":e,t),t);var l=typeof Reflect=="object"?Reflect:null,y=l&&typeof l.apply=="function"?l.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)},d;l&&typeof l.ownKeys=="function"?d=l.ownKeys:Object.getOwnPropertySymbols?d=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:d=function(e){return Object.getOwnPropertyNames(e)};function N(n){console&&console.warn&&console.warn(n)}var L=Number.isNaN||function(e){return e!==e};function s(){b.call(this)}s.EventEmitter=s;s.prototype._events=void 0;s.prototype._eventsCount=0;s.prototype._maxListeners=void 0;var w=10;function v(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return w},set:function(n){if(typeof n!="number"||n<0||L(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");w=n}});function b(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}s.init=b;s.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||L(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};function _(n){return n._maxListeners===void 0?s.defaultMaxListeners:n._maxListeners}s.prototype.getMaxListeners=function(){return _(this)};s.prototype.emit=function(e){for(var t=[],r=1;r0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var p=u[e];if(p===void 0)return!1;if(typeof p=="function")y(p,this,t);else for(var g=p.length,D=j(p,g),r=0;r0&&o.length>i&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,N(a)}return n}s.prototype.addListener=function(e,t){return E(this,e,t,!1)};s.prototype.on=s.prototype.addListener;s.prototype.prependListener=function(e,t){return E(this,e,t,!0)};function P(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function O(n,e,t){var r={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},i=P.bind(r);return i.listener=t,r.wrapFn=i,i}s.prototype.once=function(e,t){return v(t),this.on(e,O(this,e,t)),this};s.prototype.prependOnceListener=function(e,t){return v(t),this.prependListener(e,O(this,e,t)),this};s.prototype.removeListener=function(e,t){var r,i,u,o,a;if(v(t),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===t||r.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||t));else if(typeof r!="function"){for(u=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){a=r[o].listener,u=o;break}if(u<0)return this;u===0?r.shift():T(r,u),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};s.prototype.off=s.prototype.removeListener;s.prototype.removeAllListeners=function(e){var t,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var u=Object.keys(r),o;for(i=0;i=0;i--)this.removeListener(e,t[i]);return this};function x(n,e,t){var r=n._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?t?[i.listener||i]:[i]:t?I(i):j(i,i.length)}s.prototype.listeners=function(e){return x(this,e,!0)};s.prototype.rawListeners=function(e){return x(this,e,!1)};function A(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):s.prototype.listenerCount.call(n,e)}s.listenerCount=A;s.prototype.listenerCount=function(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0};s.prototype.eventNames=function(){return this._eventsCount>0?d(this._events):[]};function j(n,e){for(var t=new Array(e),r=0;r{throw new Error("process.emitWarning is not supported")});f(this,"binding",()=>{throw new Error("process.binding is not supported")});f(this,"cwd",()=>{throw new Error("process.cwd is not supported")});f(this,"chdir",t=>{throw new Error("process.chdir is not supported")});f(this,"umask",()=>18);f(this,"nextTick",(t,...r)=>queueMicrotask(()=>t(...r)));f(this,"hrtime",h)}},c=new m;if(typeof Deno<"u"){c.name="deno",c.browser=!1,c.pid=Deno.pid,c.cwd=()=>Deno.cwd(),c.chdir=e=>Deno.chdir(e),c.arch=Deno.build.arch,c.platform=Deno.build.os,c.version="v18.12.1",c.versions={node:"18.12.1",uv:"1.43.0",zlib:"1.2.11",brotli:"1.0.9",ares:"1.18.1",modules:"108",nghttp2:"1.47.0",napi:"8",llhttp:"6.0.10",openssl:"3.0.7+quic",cldr:"41.0",icu:"71.1",tz:"2022b",unicode:"14.0",ngtcp2:"0.8.1",nghttp3:"0.7.0",...Deno.version},c.env=new Proxy({},{get(e,t){return Deno.env.get(String(t))},ownKeys:()=>Reflect.ownKeys(Deno.env.toObject()),getOwnPropertyDescriptor:(e,t)=>{let r=Deno.env.toObject();if(t in Deno.env.toObject()){let i={enumerable:!0,configurable:!0};return typeof t=="string"&&(i.value=r[t]),i}},set(e,t,r){return Deno.env.set(String(t),String(r)),r}});let n=["","",...Deno.args];Object.defineProperty(n,"0",{get:Deno.execPath}),Object.defineProperty(n,"1",{get:()=>Deno.mainModule.startsWith("file:")?new URL(Deno.mainModule).pathname:join(Deno.cwd(),"$deno$node.js")}),c.argv=n}else{let n="/";c.cwd=()=>n,c.chdir=e=>n=e}var M=c;globalThis.__Process$=M;})(); +(()=>{var Lt=Object.create,q=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,xt=Object.getOwnPropertyNames,Ct=Object.getPrototypeOf,Mt=Object.prototype.hasOwnProperty,W=(p,a)=>()=>(a||p((a={exports:{}}).exports,a),a.exports),Pt=(p,a)=>{for(var s in a)q(p,s,{get:a[s],enumerable:!0})},V=(p,a,s,S)=>{if(a&&typeof a=="object"||typeof a=="function")for(let b of xt(a))!Mt.call(p,b)&&b!==s&&q(p,b,{get:()=>a[b],enumerable:!(S=_t(a,b))||S.enumerable});return p},$t=(p,a,s)=>(V(p,a,"default"),s&&V(s,a,"default")),st=(p,a,s)=>(s=p!=null?Lt(Ct(p)):{},V(a||!p||!p.__esModule?q(s,"default",{value:p,enumerable:!0}):s,p)),Nt=W(p=>{"use strict";p.byteLength=T,p.toByteArray=$,p.fromByteArray=P;var a=[],s=[],S=typeof Uint8Array<"u"?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,c=b.length;B0)throw new Error("Invalid string. Length must be a multiple of 4");var w=h.indexOf("=");w===-1&&(w=l);var A=w===l?0:4-w%4;return[w,A]}function T(h){var l=f(h),w=l[0],A=l[1];return(w+A)*3/4-A}function L(h,l,w){return(l+w)*3/4-w}function $(h){var l,w=f(h),A=w[0],_=w[1],E=new S(L(h,A,_)),x=0,M=_>0?A-4:A,O;for(O=0;O>16&255,E[x++]=l>>8&255,E[x++]=l&255;return _===2&&(l=s[h.charCodeAt(O)]<<2|s[h.charCodeAt(O+1)]>>4,E[x++]=l&255),_===1&&(l=s[h.charCodeAt(O)]<<10|s[h.charCodeAt(O+1)]<<4|s[h.charCodeAt(O+2)]>>2,E[x++]=l>>8&255,E[x++]=l&255),E}function m(h){return a[h>>18&63]+a[h>>12&63]+a[h>>6&63]+a[h&63]}function U(h,l,w){for(var A,_=[],E=l;EM?M:x+E));return A===1?(l=h[w-1],_.push(a[l>>2]+a[l<<4&63]+"==")):A===2&&(l=(h[w-2]<<8)+h[w-1],_.push(a[l>>10]+a[l>>4&63]+a[l<<2&63]+"=")),_.join("")}}),jt=W(p=>{p.read=function(a,s,S,b,B){var c,f,T=B*8-b-1,L=(1<>1,m=-7,U=S?B-1:0,P=S?-1:1,h=a[s+U];for(U+=P,c=h&(1<<-m)-1,h>>=-m,m+=T;m>0;c=c*256+a[s+U],U+=P,m-=8);for(f=c&(1<<-m)-1,c>>=-m,m+=b;m>0;f=f*256+a[s+U],U+=P,m-=8);if(c===0)c=1-$;else{if(c===L)return f?NaN:(h?-1:1)*(1/0);f=f+Math.pow(2,b),c=c-$}return(h?-1:1)*f*Math.pow(2,c-b)},p.write=function(a,s,S,b,B,c){var f,T,L,$=c*8-B-1,m=(1<<$)-1,U=m>>1,P=B===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=b?0:c-1,l=b?1:-1,w=s<0||s===0&&1/s<0?1:0;for(s=Math.abs(s),isNaN(s)||s===1/0?(T=isNaN(s)?1:0,f=m):(f=Math.floor(Math.log(s)/Math.LN2),s*(L=Math.pow(2,-f))<1&&(f--,L*=2),f+U>=1?s+=P/L:s+=P*Math.pow(2,1-U),s*L>=2&&(f++,L/=2),f+U>=m?(T=0,f=m):f+U>=1?(T=(s*L-1)*Math.pow(2,B),f=f+U):(T=s*Math.pow(2,U-1)*Math.pow(2,B),f=0));B>=8;a[S+h]=T&255,h+=l,T/=256,B-=8);for(f=f<0;a[S+h]=f&255,h+=l,f/=256,$-=8);a[S+h-l]|=w*128}}),ht=W(p=>{"use strict";var a=Nt(),s=jt(),S=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;p.Buffer=f,p.SlowBuffer=_,p.INSPECT_MAX_BYTES=50;var b=2147483647;p.kMaxLength=b,f.TYPED_ARRAY_SUPPORT=B(),!f.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function B(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}});function c(t){if(t>b)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,f.prototype),e}function f(t,e,n){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return m(t)}return T(t,e,n)}f.poolSize=8192;function T(t,e,n){if(typeof t=="string")return U(t,e);if(ArrayBuffer.isView(t))return h(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(N(t,ArrayBuffer)||t&&N(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(N(t,SharedArrayBuffer)||t&&N(t.buffer,SharedArrayBuffer)))return l(t,e,n);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=t.valueOf&&t.valueOf();if(r!=null&&r!==t)return f.from(r,e,n);let o=w(t);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return f.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}f.from=function(t,e,n){return T(t,e,n)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array);function L(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function $(t,e,n){return L(t),t<=0?c(t):e!==void 0?typeof n=="string"?c(t).fill(e,n):c(t).fill(e):c(t)}f.alloc=function(t,e,n){return $(t,e,n)};function m(t){return L(t),c(t<0?0:A(t)|0)}f.allocUnsafe=function(t){return m(t)},f.allocUnsafeSlow=function(t){return m(t)};function U(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!f.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let n=E(t,e)|0,r=c(n),o=r.write(t,e);return o!==n&&(r=r.slice(0,o)),r}function P(t){let e=t.length<0?0:A(t.length)|0,n=c(e);for(let r=0;r=b)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+b.toString(16)+" bytes");return t|0}function _(t){return+t!=t&&(t=0),f.alloc(+t)}f.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==f.prototype},f.compare=function(t,e){if(N(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),N(e,Uint8Array)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(t)||!f.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,r=e.length;for(let o=0,i=Math.min(n,r);or.length?(f.isBuffer(i)||(i=f.from(i)),i.copy(r,o)):Uint8Array.prototype.set.call(r,i,o);else if(f.isBuffer(i))i.copy(r,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=i.length}return r};function E(t,e){if(f.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||N(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let n=t.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return it(t).length;default:if(o)return r?-1:G(t).length;e=(""+e).toLowerCase(),o=!0}}f.byteLength=E;function x(t,e,n){let r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,e>>>=0,n<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return Et(this,e,n);case"utf8":case"utf-8":return H(this,e,n);case"ascii":return Bt(this,e,n);case"latin1":case"binary":return mt(this,e,n);case"base64":return dt(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return vt(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}f.prototype._isBuffer=!0;function M(t,e,n){let r=t[e];t[e]=t[n],t[n]=r}f.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;ee&&(t+=" ... "),""},S&&(f.prototype[S]=f.prototype.inspect),f.prototype.compare=function(t,e,n,r,o){if(N(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),n===void 0&&(n=t?t.length:0),r===void 0&&(r=0),o===void 0&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;let i=o-r,u=n-e,g=Math.min(i,u),R=this.slice(r,o),d=t.slice(e,n);for(let y=0;y2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,X(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0)if(o)n=0;else return-1;if(typeof e=="string"&&(e=f.from(e,r)),f.isBuffer(e))return e.length===0?-1:Z(t,e,n,r,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):Z(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function Z(t,e,n,r,o){let i=1,u=t.length,g=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(t.length<2||e.length<2)return-1;i=2,u/=2,g/=2,n/=2}function R(y,v){return i===1?y[v]:y.readUInt16BE(v*i)}let d;if(o){let y=-1;for(d=n;du&&(n=u-g),d=n;d>=0;d--){let y=!0;for(let v=0;vo&&(r=o)):r=o;let i=e.length;r>i/2&&(r=i/2);let u;for(u=0;u>>0,isFinite(n)?(n=n>>>0,r===void 0&&(r="utf8")):(r=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-e;if((n===void 0||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let i=!1;for(;;)switch(r){case"hex":return pt(this,t,e,n);case"utf8":case"utf-8":return ct(this,t,e,n);case"ascii":case"latin1":case"binary":return gt(this,t,e,n);case"base64":return yt(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wt(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function dt(t,e,n){return e===0&&n===t.length?a.fromByteArray(t):a.fromByteArray(t.slice(e,n))}function H(t,e,n){n=Math.min(t.length,n);let r=[],o=e;for(;o239?4:i>223?3:i>191?2:1;if(o+g<=n){let R,d,y,v;switch(g){case 1:i<128&&(u=i);break;case 2:R=t[o+1],(R&192)===128&&(v=(i&31)<<6|R&63,v>127&&(u=v));break;case 3:R=t[o+1],d=t[o+2],(R&192)===128&&(d&192)===128&&(v=(i&15)<<12|(R&63)<<6|d&63,v>2047&&(v<55296||v>57343)&&(u=v));break;case 4:R=t[o+1],d=t[o+2],y=t[o+3],(R&192)===128&&(d&192)===128&&(y&192)===128&&(v=(i&15)<<18|(R&63)<<12|(d&63)<<6|y&63,v>65535&&v<1114112&&(u=v))}}u===null?(u=65533,g=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|u&1023),r.push(u),o+=g}return bt(r)}var K=4096;function bt(t){let e=t.length;if(e<=K)return String.fromCharCode.apply(String,t);let n="",r=0;for(;rr)&&(n=r);let o="";for(let i=e;in&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),en)throw new RangeError("Trying to access beyond buffer length")}f.prototype.readUintLE=f.prototype.readUIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||I(t,e,this.length);let r=this[t],o=1,i=0;for(;++i>>0,e=e>>>0,n||I(t,e,this.length);let r=this[t+--e],o=1;for(;e>0&&(o*=256);)r+=this[t+--e]*o;return r},f.prototype.readUint8=f.prototype.readUInt8=function(t,e){return t=t>>>0,e||I(t,1,this.length),this[t]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||I(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||I(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||I(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readBigUInt64LE=j(function(t){t=t>>>0,F(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&D(t,this.length-8);let r=e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(r)+(BigInt(o)<>>0,F(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&D(t,this.length-8);let r=e*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(r)<>>0,e=e>>>0,n||I(t,e,this.length);let r=this[t],o=1,i=0;for(;++i=o&&(r-=Math.pow(2,8*e)),r},f.prototype.readIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||I(t,e,this.length);let r=e,o=1,i=this[t+--r];for(;r>0&&(o*=256);)i+=this[t+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},f.prototype.readInt8=function(t,e){return t=t>>>0,e||I(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},f.prototype.readInt16LE=function(t,e){t=t>>>0,e||I(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n},f.prototype.readInt16BE=function(t,e){t=t>>>0,e||I(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n},f.prototype.readInt32LE=function(t,e){return t=t>>>0,e||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return t=t>>>0,e||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readBigInt64LE=j(function(t){t=t>>>0,F(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&D(t,this.length-8);let r=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(r)<>>0,F(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&D(t,this.length-8);let r=(e<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(r)<>>0,e||I(t,4,this.length),s.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,e){return t=t>>>0,e||I(t,4,this.length),s.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||I(t,8,this.length),s.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||I(t,8,this.length),s.read(this,t,!1,52,8)};function C(t,e,n,r,o,i){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||et.length)throw new RangeError("Index out of range")}f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e=e>>>0,n=n>>>0,!r){let u=Math.pow(2,8*n)-1;C(this,t,e,n,u,0)}let o=1,i=0;for(this[e]=t&255;++i>>0,n=n>>>0,!r){let u=Math.pow(2,8*n)-1;C(this,t,e,n,u,0)}let o=n-1,i=1;for(this[e+o]=t&255;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},f.prototype.writeUint8=f.prototype.writeUInt8=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,1,255,0),this[e]=t&255,e+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function Q(t,e,n,r,o){ft(e,r,o,t,n,7);let i=Number(e&BigInt(4294967295));t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i,i=i>>8,t[n++]=i;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=u,u=u>>8,t[n++]=u,u=u>>8,t[n++]=u,u=u>>8,t[n++]=u,n}function tt(t,e,n,r,o){ft(e,r,o,t,n,7);let i=Number(e&BigInt(4294967295));t[n+7]=i,i=i>>8,t[n+6]=i,i=i>>8,t[n+5]=i,i=i>>8,t[n+4]=i;let u=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=u,u=u>>8,t[n+2]=u,u=u>>8,t[n+1]=u,u=u>>8,t[n]=u,n+8}f.prototype.writeBigUInt64LE=j(function(t,e=0){return Q(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=j(function(t,e=0){return tt(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e=e>>>0,!r){let g=Math.pow(2,8*n-1);C(this,t,e,n,g-1,-g)}let o=0,i=1,u=0;for(this[e]=t&255;++o>0)-u&255;return e+n},f.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e=e>>>0,!r){let g=Math.pow(2,8*n-1);C(this,t,e,n,g-1,-g)}let o=n-1,i=1,u=0;for(this[e+o]=t&255;--o>=0&&(i*=256);)t<0&&u===0&&this[e+o+1]!==0&&(u=1),this[e+o]=(t/i>>0)-u&255;return e+n},f.prototype.writeInt8=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1},f.prototype.writeInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2},f.prototype.writeInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2},f.prototype.writeInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},f.prototype.writeInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||C(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4},f.prototype.writeBigInt64LE=j(function(t,e=0){return Q(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=j(function(t,e=0){return tt(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function et(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function nt(t,e,n,r,o){return e=+e,n=n>>>0,o||et(t,e,n,4,34028234663852886e22,-34028234663852886e22),s.write(t,e,n,r,23,4),n+4}f.prototype.writeFloatLE=function(t,e,n){return nt(this,t,e,!0,n)},f.prototype.writeFloatBE=function(t,e,n){return nt(this,t,e,!1,n)};function rt(t,e,n,r,o){return e=+e,n=n>>>0,o||et(t,e,n,8,17976931348623157e292,-17976931348623157e292),s.write(t,e,n,r,52,8),n+8}f.prototype.writeDoubleLE=function(t,e,n){return rt(this,t,e,!0,n)},f.prototype.writeDoubleBE=function(t,e,n){return rt(this,t,e,!1,n)},f.prototype.copy=function(t,e,n,r){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!r&&r!==0&&(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let o;if(typeof t=="number")for(o=e;o2**32?o=ot(String(n)):typeof n=="bigint"&&(o=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(o=ot(o)),o+="n"),r+=` It must be ${e}. Received ${o}`,r},RangeError);function ot(t){let e="",n=t.length,r=t[0]==="-"?1:0;for(;n>=r+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function At(t,e,n){F(e,"offset"),(t[e]===void 0||t[e+n]===void 0)&&D(e,t.length-(n+1))}function ft(t,e,n,r,o,i){if(t>n||t3?e===0||e===BigInt(0)?g=`>= 0${u} and < 2${u} ** ${(i+1)*8}${u}`:g=`>= -(2${u} ** ${(i+1)*8-1}${u}) and < 2 ** ${(i+1)*8-1}${u}`:g=`>= ${e}${u} and <= ${n}${u}`,new k.ERR_OUT_OF_RANGE("value",g,t)}At(r,o,i)}function F(t,e){if(typeof t!="number")throw new k.ERR_INVALID_ARG_TYPE(e,"number",t)}function D(t,e,n){throw Math.floor(t)!==t?(F(t,n),new k.ERR_OUT_OF_RANGE(n||"offset","an integer",t)):e<0?new k.ERR_BUFFER_OUT_OF_BOUNDS:new k.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${e}`,t)}var It=/[^+/0-9A-Za-z-_]/g;function Ut(t){if(t=t.split("=")[0],t=t.trim().replace(It,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function G(t,e){e=e||1/0;let n,r=t.length,o=null,i=[];for(let u=0;u55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(u+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function Rt(t){let e=[];for(let n=0;n>8,o=n%256,i.push(o),i.push(r);return i}function it(t){return a.toByteArray(Ut(t))}function Y(t,e,n,r){let o;for(o=0;o=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function N(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function X(t){return t!==t}var Ot=function(){let t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){let r=n*16;for(let o=0;o<16;++o)e[r+o]=t[n]+t[o]}return e}();function j(t){return typeof BigInt>"u"?St:t}function St(){throw new Error("BigInt not supported")}}),at={};Pt(at,{Buffer:()=>J,INSPECT_MAX_BYTES:()=>Ft,SlowBuffer:()=>kt,default:()=>zt,kMaxLength:()=>Dt});var lt=st(ht());$t(at,st(ht()));var{Buffer:J,SlowBuffer:kt,INSPECT_MAX_BYTES:Ft,kMaxLength:Dt}=lt,{default:ut,...Yt}=lt,zt=ut!==void 0?ut:Yt;globalThis.__Buffer$=J;})(); +/*! Bundled license information: + +ieee754/index.js: + (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh *) + +buffer/index.js: + (*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + *) +*/ +var hi=Object.create;var jt=Object.defineProperty;var di=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var mi=Object.getPrototypeOf,yi=Object.prototype.hasOwnProperty;var gi=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),et=(t,e)=>{for(var r in e)jt(t,r,{get:e[r],enumerable:!0})},xi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pi(e))!yi.call(t,i)&&i!==r&&jt(t,i,{get:()=>e[i],enumerable:!(n=di(e,i))||n.enumerable});return t};var pn=(t,e,r)=>(r=t!=null?hi(mi(t)):{},xi(e||!t||!t.__esModule?jt(r,"default",{value:t,enumerable:!0}):r,t));var we=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)};var Sr=gi((js,vr)=>{"use strict";var g={};g.generateIdentifier=function(){return Math.random().toString(36).substring(2,12)};g.localCName=g.generateIdentifier();g.splitLines=function(t){return t.trim().split(` +`).map(e=>e.trim())};g.splitSections=function(t){return t.split(` +m=`).map((r,n)=>(n>0?"m="+r:r).trim()+`\r +`)};g.getDescription=function(t){let e=g.splitSections(t);return e&&e[0]};g.getMediaSections=function(t){let e=g.splitSections(t);return e.shift(),e};g.matchPrefix=function(t,e){return g.splitLines(t).filter(r=>r.indexOf(e)===0)};g.parseCandidate=function(t){let e;t.indexOf("a=candidate:")===0?e=t.substring(12).split(" "):e=t.substring(10).split(" ");let r={foundation:e[0],component:{1:"rtp",2:"rtcp"}[e[1]]||e[1],protocol:e[2].toLowerCase(),priority:parseInt(e[3],10),ip:e[4],address:e[4],port:parseInt(e[5],10),type:e[7]};for(let n=8;n0?e[0].split("/")[1]:"sendrecv",uri:e[1],attributes:e.slice(2).join(" ")}};g.writeExtmap=function(t){return"a=extmap:"+(t.id||t.preferredId)+(t.direction&&t.direction!=="sendrecv"?"/"+t.direction:"")+" "+t.uri+(t.attributes?" "+t.attributes:"")+`\r +`};g.parseFmtp=function(t){let e={},r,n=t.substring(t.indexOf(" ")+1).split(";");for(let i=0;i{t.parameters[i]!==void 0?n.push(i+"="+t.parameters[i]):n.push(i)}),e+="a=fmtp:"+r+" "+n.join(";")+`\r +`}return e};g.parseRtcpFb=function(t){let e=t.substring(t.indexOf(" ")+1).split(" ");return{type:e.shift(),parameter:e.join(" ")}};g.writeRtcpFb=function(t){let e="",r=t.payloadType;return t.preferredPayloadType!==void 0&&(r=t.preferredPayloadType),t.rtcpFeedback&&t.rtcpFeedback.length&&t.rtcpFeedback.forEach(n=>{e+="a=rtcp-fb:"+r+" "+n.type+(n.parameter&&n.parameter.length?" "+n.parameter:"")+`\r +`}),e};g.parseSsrcMedia=function(t){let e=t.indexOf(" "),r={ssrc:parseInt(t.substring(7,e),10)},n=t.indexOf(":",e);return n>-1?(r.attribute=t.substring(e+1,n),r.value=t.substring(n+1)):r.attribute=t.substring(e+1),r};g.parseSsrcGroup=function(t){let e=t.substring(13).split(" ");return{semantics:e.shift(),ssrcs:e.map(r=>parseInt(r,10))}};g.getMid=function(t){let e=g.matchPrefix(t,"a=mid:")[0];if(e)return e.substring(6)};g.parseFingerprint=function(t){let e=t.substring(14).split(" ");return{algorithm:e[0].toLowerCase(),value:e[1].toUpperCase()}};g.getDtlsParameters=function(t,e){return{role:"auto",fingerprints:g.matchPrefix(t+e,"a=fingerprint:").map(g.parseFingerprint)}};g.writeDtlsParameters=function(t,e){let r="a=setup:"+e+`\r +`;return t.fingerprints.forEach(n=>{r+="a=fingerprint:"+n.algorithm+" "+n.value+`\r +`}),r};g.parseCryptoLine=function(t){let e=t.substring(9).split(" ");return{tag:parseInt(e[0],10),cryptoSuite:e[1],keyParams:e[2],sessionParams:e.slice(3)}};g.writeCryptoLine=function(t){return"a=crypto:"+t.tag+" "+t.cryptoSuite+" "+(typeof t.keyParams=="object"?g.writeCryptoKeyParams(t.keyParams):t.keyParams)+(t.sessionParams?" "+t.sessionParams.join(" "):"")+`\r +`};g.parseCryptoKeyParams=function(t){if(t.indexOf("inline:")!==0)return null;let e=t.substring(7).split("|");return{keyMethod:"inline",keySalt:e[0],lifeTime:e[1],mkiValue:e[2]?e[2].split(":")[0]:void 0,mkiLength:e[2]?e[2].split(":")[1]:void 0}};g.writeCryptoKeyParams=function(t){return t.keyMethod+":"+t.keySalt+(t.lifeTime?"|"+t.lifeTime:"")+(t.mkiValue&&t.mkiLength?"|"+t.mkiValue+":"+t.mkiLength:"")};g.getCryptoParameters=function(t,e){return g.matchPrefix(t+e,"a=crypto:").map(g.parseCryptoLine)};g.getIceParameters=function(t,e){let r=g.matchPrefix(t+e,"a=ice-ufrag:")[0],n=g.matchPrefix(t+e,"a=ice-pwd:")[0];return r&&n?{usernameFragment:r.substring(12),password:n.substring(10)}:null};g.writeIceParameters=function(t){let e="a=ice-ufrag:"+t.usernameFragment+`\r +a=ice-pwd:`+t.password+`\r +`;return t.iceLite&&(e+=`a=ice-lite\r +`),e};g.parseRtpParameters=function(t){let e={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},n=g.splitLines(t)[0].split(" ");e.profile=n[2];for(let s=3;s{e.headerExtensions.push(g.parseExtmap(s))});let i=g.matchPrefix(t,"a=rtcp-fb:* ").map(g.parseRtcpFb);return e.codecs.forEach(s=>{i.forEach(o=>{s.rtcpFeedback.find(f=>f.type===o.type&&f.parameter===o.parameter)||s.rtcpFeedback.push(o)})}),e};g.writeRtpDescription=function(t,e){let r="";r+="m="+t+" ",r+=e.codecs.length>0?"9":"0",r+=" "+(e.profile||"UDP/TLS/RTP/SAVPF")+" ",r+=e.codecs.map(i=>i.preferredPayloadType!==void 0?i.preferredPayloadType:i.payloadType).join(" ")+`\r +`,r+=`c=IN IP4 0.0.0.0\r +`,r+=`a=rtcp:9 IN IP4 0.0.0.0\r +`,e.codecs.forEach(i=>{r+=g.writeRtpMap(i),r+=g.writeFmtp(i),r+=g.writeRtcpFb(i)});let n=0;return e.codecs.forEach(i=>{i.maxptime>n&&(n=i.maxptime)}),n>0&&(r+="a=maxptime:"+n+`\r +`),e.headerExtensions&&e.headerExtensions.forEach(i=>{r+=g.writeExtmap(i)}),r};g.parseRtpEncodingParameters=function(t){let e=[],r=g.parseRtpParameters(t),n=r.fecMechanisms.indexOf("RED")!==-1,i=r.fecMechanisms.indexOf("ULPFEC")!==-1,s=g.matchPrefix(t,"a=ssrc:").map(u=>g.parseSsrcMedia(u)).filter(u=>u.attribute==="cname"),o=s.length>0&&s[0].ssrc,a,f=g.matchPrefix(t,"a=ssrc-group:FID").map(u=>u.substring(17).split(" ").map(y=>parseInt(y,10)));f.length>0&&f[0].length>1&&f[0][0]===o&&(a=f[0][1]),r.codecs.forEach(u=>{if(u.name.toUpperCase()==="RTX"&&u.parameters.apt){let d={ssrc:o,codecPayloadType:parseInt(u.parameters.apt,10)};o&&a&&(d.rtx={ssrc:a}),e.push(d),n&&(d=JSON.parse(JSON.stringify(d)),d.fec={ssrc:o,mechanism:i?"red+ulpfec":"red"},e.push(d))}}),e.length===0&&o&&e.push({ssrc:o});let c=g.matchPrefix(t,"b=");return c.length&&(c[0].indexOf("b=TIAS:")===0?c=parseInt(c[0].substring(7),10):c[0].indexOf("b=AS:")===0?c=parseInt(c[0].substring(5),10)*1e3*.95-50*40*8:c=void 0,e.forEach(u=>{u.maxBitrate=c})),e};g.parseRtcpParameters=function(t){let e={},r=g.matchPrefix(t,"a=ssrc:").map(s=>g.parseSsrcMedia(s)).filter(s=>s.attribute==="cname")[0];r&&(e.cname=r.value,e.ssrc=r.ssrc);let n=g.matchPrefix(t,"a=rtcp-rsize");e.reducedSize=n.length>0,e.compound=n.length===0;let i=g.matchPrefix(t,"a=rtcp-mux");return e.mux=i.length>0,e};g.writeRtcpParameters=function(t){let e="";return t.reducedSize&&(e+=`a=rtcp-rsize\r +`),t.mux&&(e+=`a=rtcp-mux\r +`),t.ssrc!==void 0&&t.cname&&(e+="a=ssrc:"+t.ssrc+" cname:"+t.cname+`\r +`),e};g.parseMsid=function(t){let e,r=g.matchPrefix(t,"a=msid:");if(r.length===1)return e=r[0].substring(7).split(" "),{stream:e[0],track:e[1]};let n=g.matchPrefix(t,"a=ssrc:").map(i=>g.parseSsrcMedia(i)).filter(i=>i.attribute==="msid");if(n.length>0)return e=n[0].value.split(" "),{stream:e[0],track:e[1]}};g.parseSctpDescription=function(t){let e=g.parseMLine(t),r=g.matchPrefix(t,"a=max-message-size:"),n;r.length>0&&(n=parseInt(r[0].substring(19),10)),isNaN(n)&&(n=65536);let i=g.matchPrefix(t,"a=sctp-port:");if(i.length>0)return{port:parseInt(i[0].substring(12),10),protocol:e.fmt,maxMessageSize:n};let s=g.matchPrefix(t,"a=sctpmap:");if(s.length>0){let o=s[0].substring(10).split(" ");return{port:parseInt(o[0],10),protocol:o[1],maxMessageSize:n}}};g.writeSctpDescription=function(t,e){let r=[];return t.protocol!=="DTLS/SCTP"?r=["m="+t.kind+" 9 "+t.protocol+" "+e.protocol+`\r +`,`c=IN IP4 0.0.0.0\r +`,"a=sctp-port:"+e.port+`\r +`]:r=["m="+t.kind+" 9 "+t.protocol+" "+e.port+`\r +`,`c=IN IP4 0.0.0.0\r +`,"a=sctpmap:"+e.port+" "+e.protocol+` 65535\r +`],e.maxMessageSize!==void 0&&r.push("a=max-message-size:"+e.maxMessageSize+`\r +`),r.join("")};g.generateSessionId=function(){return Math.random().toString().substr(2,22)};g.writeSessionBoilerplate=function(t,e,r){let n,i=e!==void 0?e:2;return t?n=t:n=g.generateSessionId(),`v=0\r +o=`+(r||"thisisadapterortc")+" "+n+" "+i+` IN IP4 127.0.0.1\r +s=-\r +t=0 0\r +`};g.getDirection=function(t,e){let r=g.splitLines(t);for(let n=0;n0){let e=new Uint8Array(this._pieces);this._parts.push(e),this._pieces=[]}}toArrayBuffer(){let e=[];for(let r of this._parts)e.push(r);return _i(e).buffer}};function _i(t){let e=0;for(let i of t)e+=i.byteLength;let r=new Uint8Array(e),n=0;for(let i of t){let s=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);r.set(s,n),n+=i.byteLength}return r}function Kt(t){return new $t(t).unpack()}function Jt(t){let e=new Gt,r=e.pack(t);return r instanceof Promise?r.then(()=>e.getBuffer()):e.getBuffer()}var $t=class{constructor(e){this.index=0,this.dataBuffer=e,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}unpack(){let e=this.unpack_uint8();if(e<128)return e;if((e^224)<32)return(e^224)-32;let r;if((r=e^160)<=15)return this.unpack_raw(r);if((r=e^176)<=15)return this.unpack_string(r);if((r=e^144)<=15)return this.unpack_array(r);if((r=e^128)<=15)return this.unpack_map(r);switch(e){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:return;case 213:return;case 214:return;case 215:return;case 216:return r=this.unpack_uint16(),this.unpack_string(r);case 217:return r=this.unpack_uint32(),this.unpack_string(r);case 218:return r=this.unpack_uint16(),this.unpack_raw(r);case 219:return r=this.unpack_uint32(),this.unpack_raw(r);case 220:return r=this.unpack_uint16(),this.unpack_array(r);case 221:return r=this.unpack_uint32(),this.unpack_array(r);case 222:return r=this.unpack_uint16(),this.unpack_map(r);case 223:return r=this.unpack_uint32(),this.unpack_map(r)}}unpack_uint8(){let e=this.dataView[this.index]&255;return this.index++,e}unpack_uint16(){let e=this.read(2),r=(e[0]&255)*256+(e[1]&255);return this.index+=2,r}unpack_uint32(){let e=this.read(4),r=((e[0]*256+e[1])*256+e[2])*256+e[3];return this.index+=4,r}unpack_uint64(){let e=this.read(8),r=((((((e[0]*256+e[1])*256+e[2])*256+e[3])*256+e[4])*256+e[5])*256+e[6])*256+e[7];return this.index+=8,r}unpack_int8(){let e=this.unpack_uint8();return e<128?e:e-256}unpack_int16(){let e=this.unpack_uint16();return e<32768?e:e-65536}unpack_int32(){let e=this.unpack_uint32();return e<2**31?e:e-2**32}unpack_int64(){let e=this.unpack_uint64();return e<2**63?e:e-2**64}unpack_raw(e){if(this.length>31,n=(e>>23&255)-127,i=e&8388607|8388608;return(r===0?1:-1)*i*2**(n-23)}unpack_double(){let e=this.unpack_uint32(),r=this.unpack_uint32(),n=e>>31,i=(e>>20&2047)-1023,o=(e&1048575|1048576)*2**(i-20)+r*2**(i-52);return(n===0?1:-1)*o}read(e){let r=this.index;if(r+e<=this.length)return this.dataView.subarray(r,r+e);throw new Error("BinaryPackFailure: read index out of range")}},Gt=class{getBuffer(){return this._bufferBuilder.toArrayBuffer()}pack(e){if(typeof e=="string")this.pack_string(e);else if(typeof e=="number")Math.floor(e)===e?this.pack_integer(e):this.pack_double(e);else if(typeof e=="boolean")e===!0?this._bufferBuilder.append(195):e===!1&&this._bufferBuilder.append(194);else if(e===void 0)this._bufferBuilder.append(192);else if(typeof e=="object")if(e===null)this._bufferBuilder.append(192);else{let r=e.constructor;if(e instanceof Array){let n=this.pack_array(e);if(n instanceof Promise)return n.then(()=>this._bufferBuilder.flush())}else if(e instanceof ArrayBuffer)this.pack_bin(new Uint8Array(e));else if("BYTES_PER_ELEMENT"in e){let n=e;this.pack_bin(new Uint8Array(n.buffer,n.byteOffset,n.byteLength))}else if(e instanceof Date)this.pack_string(e.toString());else{if(e instanceof Blob)return e.arrayBuffer().then(n=>{this.pack_bin(new Uint8Array(n)),this._bufferBuilder.flush()});if(r==Object||r.toString().startsWith("class")){let n=this.pack_object(e);if(n instanceof Promise)return n.then(()=>this._bufferBuilder.flush())}else throw new Error(`Type "${r.toString()}" not yet supported`)}}else throw new Error(`Type "${typeof e}" not yet supported`);this._bufferBuilder.flush()}pack_bin(e){let r=e.length;if(r<=15)this.pack_uint8(160+r);else if(r<=65535)this._bufferBuilder.append(218),this.pack_uint16(r);else if(r<=4294967295)this._bufferBuilder.append(219),this.pack_uint32(r);else throw new Error("Invalid length");this._bufferBuilder.append_buffer(e)}pack_string(e){let r=this._textEncoder.encode(e),n=r.length;if(n<=15)this.pack_uint8(176+n);else if(n<=65535)this._bufferBuilder.append(216),this.pack_uint16(n);else if(n<=4294967295)this._bufferBuilder.append(217),this.pack_uint32(n);else throw new Error("Invalid length");this._bufferBuilder.append_buffer(r)}pack_array(e){let r=e.length;if(r<=15)this.pack_uint8(144+r);else if(r<=65535)this._bufferBuilder.append(220),this.pack_uint16(r);else if(r<=4294967295)this._bufferBuilder.append(221),this.pack_uint32(r);else throw new Error("Invalid length");let n=i=>{if(in(i+1)):n(i+1)}};return n(0)}pack_integer(e){if(e>=-32&&e<=127)this._bufferBuilder.append(e&255);else if(e>=0&&e<=255)this._bufferBuilder.append(204),this.pack_uint8(e);else if(e>=-128&&e<=127)this._bufferBuilder.append(208),this.pack_int8(e);else if(e>=0&&e<=65535)this._bufferBuilder.append(205),this.pack_uint16(e);else if(e>=-32768&&e<=32767)this._bufferBuilder.append(209),this.pack_int16(e);else if(e>=0&&e<=4294967295)this._bufferBuilder.append(206),this.pack_uint32(e);else if(e>=-2147483648&&e<=2147483647)this._bufferBuilder.append(210),this.pack_int32(e);else if(e>=-9223372036854776e3&&e<=9223372036854776e3)this._bufferBuilder.append(211),this.pack_int64(e);else if(e>=0&&e<=18446744073709552e3)this._bufferBuilder.append(207),this.pack_uint64(e);else throw new Error("Invalid integer")}pack_double(e){let r=0;e<0&&(r=1,e=-e);let n=Math.floor(Math.log(e)/Math.LN2),i=e/2**n-1,s=Math.floor(i*2**52),o=2**32,a=r<<31|n+1023<<20|s/o&1048575,f=s%o;this._bufferBuilder.append(203),this.pack_int32(a),this.pack_int32(f)}pack_object(e){let r=Object.keys(e),n=r.length;if(n<=15)this.pack_uint8(128+n);else if(n<=65535)this._bufferBuilder.append(222),this.pack_uint16(n);else if(n<=4294967295)this._bufferBuilder.append(223),this.pack_uint32(n);else throw new Error("Invalid length");let i=s=>{if(si(s+1))}return i(s+1)}};return i(0)}pack_uint8(e){this._bufferBuilder.append(e)}pack_uint16(e){this._bufferBuilder.append(e>>8),this._bufferBuilder.append(e&255)}pack_uint32(e){let r=e&4294967295;this._bufferBuilder.append((r&4278190080)>>>24),this._bufferBuilder.append((r&16711680)>>>16),this._bufferBuilder.append((r&65280)>>>8),this._bufferBuilder.append(r&255)}pack_uint64(e){let r=e/4294967296,n=e%2**32;this._bufferBuilder.append((r&4278190080)>>>24),this._bufferBuilder.append((r&16711680)>>>16),this._bufferBuilder.append((r&65280)>>>8),this._bufferBuilder.append(r&255),this._bufferBuilder.append((n&4278190080)>>>24),this._bufferBuilder.append((n&16711680)>>>16),this._bufferBuilder.append((n&65280)>>>8),this._bufferBuilder.append(n&255)}pack_int8(e){this._bufferBuilder.append(e&255)}pack_int16(e){this._bufferBuilder.append((e&65280)>>8),this._bufferBuilder.append(e&255)}pack_int32(e){this._bufferBuilder.append(e>>>24&255),this._bufferBuilder.append((e&16711680)>>>16),this._bufferBuilder.append((e&65280)>>>8),this._bufferBuilder.append(e&255)}pack_int64(e){let r=Math.floor(e/4294967296),n=e%2**32;this._bufferBuilder.append((r&4278190080)>>>24),this._bufferBuilder.append((r&16711680)>>>16),this._bufferBuilder.append((r&65280)>>>8),this._bufferBuilder.append(r&255),this._bufferBuilder.append((n&4278190080)>>>24),this._bufferBuilder.append((n&16711680)>>>16),this._bufferBuilder.append((n&65280)>>>8),this._bufferBuilder.append(n&255)}constructor(){this._bufferBuilder=new Vt,this._textEncoder=new TextEncoder}};var yn=!0,gn=!0;function De(t,e,r){let n=t.match(e);return n&&n.length>=r&&parseInt(n[r],10)}function ee(t,e,r){if(!t.RTCPeerConnection)return;let n=t.RTCPeerConnection.prototype,i=n.addEventListener;n.addEventListener=function(o,a){if(o!==e)return i.apply(this,arguments);let f=c=>{let u=r(c);u&&(a.handleEvent?a.handleEvent(u):a(u))};return this._eventMap=this._eventMap||{},this._eventMap[e]||(this._eventMap[e]=new Map),this._eventMap[e].set(a,f),i.apply(this,[o,f])};let s=n.removeEventListener;n.removeEventListener=function(o,a){if(o!==e||!this._eventMap||!this._eventMap[e])return s.apply(this,arguments);if(!this._eventMap[e].has(a))return s.apply(this,arguments);let f=this._eventMap[e].get(a);return this._eventMap[e].delete(a),this._eventMap[e].size===0&&delete this._eventMap[e],Object.keys(this._eventMap).length===0&&delete this._eventMap,s.apply(this,[o,f])},Object.defineProperty(n,"on"+e,{get(){return this["_on"+e]},set(o){this["_on"+e]&&(this.removeEventListener(e,this["_on"+e]),delete this["_on"+e]),o&&this.addEventListener(e,this["_on"+e]=o)},enumerable:!0,configurable:!0})}function xn(t){return typeof t!="boolean"?new Error("Argument type: "+typeof t+". Please use a boolean."):(yn=t,t?"adapter.js logging disabled":"adapter.js logging enabled")}function _n(t){return typeof t!="boolean"?new Error("Argument type: "+typeof t+". Please use a boolean."):(gn=!t,"adapter.js deprecation warnings "+(t?"disabled":"enabled"))}function tt(){if(typeof window=="object"){if(yn)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function _e(t,e){gn&&console.warn(t+" is deprecated, please use "+e+" instead.")}function vn(t){let e={browser:null,version:null};if(typeof t>"u"||!t.navigator||!t.navigator.userAgent)return e.browser="Not a browser.",e;let{navigator:r}=t;if(r.mozGetUserMedia)e.browser="firefox",e.version=De(r.userAgent,/Firefox\/(\d+)\./,1);else if(r.webkitGetUserMedia||t.isSecureContext===!1&&t.webkitRTCPeerConnection)e.browser="chrome",e.version=De(r.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.RTCPeerConnection&&r.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=De(r.userAgent,/AppleWebKit\/(\d+)\./,1),e.supportsUnifiedPlan=t.RTCRtpTransceiver&&"currentDirection"in t.RTCRtpTransceiver.prototype;else return e.browser="Not a supported browser.",e;return e}function mn(t){return Object.prototype.toString.call(t)==="[object Object]"}function Wt(t){return mn(t)?Object.keys(t).reduce(function(e,r){let n=mn(t[r]),i=n?Wt(t[r]):t[r],s=n&&!Object.keys(i).length;return i===void 0||s?e:Object.assign(e,{[r]:i})},{}):t}function Ht(t,e,r){!e||r.has(e.id)||(r.set(e.id,e),Object.keys(e).forEach(n=>{n.endsWith("Id")?Ht(t,t.get(e[n]),r):n.endsWith("Ids")&&e[n].forEach(i=>{Ht(t,t.get(i),r)})}))}function Yt(t,e,r){let n=r?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;let s=[];return t.forEach(o=>{o.type==="track"&&o.trackIdentifier===e.id&&s.push(o)}),s.forEach(o=>{t.forEach(a=>{a.type===n&&a.trackId===o.id&&Ht(t,a,i)})}),i}var it={};et(it,{fixNegotiationNeeded:()=>rr,shimAddTrackRemoveTrack:()=>tr,shimAddTrackRemoveTrackWithNative:()=>bn,shimGetDisplayMedia:()=>Cn,shimGetSendersWithDtmf:()=>Zt,shimGetStats:()=>Qt,shimGetUserMedia:()=>rt,shimMediaStream:()=>Xt,shimOnTrack:()=>qt,shimPeerConnection:()=>nt,shimSenderReceiverGetStats:()=>er});var Sn=tt;function rt(t,e){let r=t&&t.navigator;if(!r.mediaDevices)return;let n=function(a){if(typeof a!="object"||a.mandatory||a.optional)return a;let f={};return Object.keys(a).forEach(c=>{if(c==="require"||c==="advanced"||c==="mediaSource")return;let u=typeof a[c]=="object"?a[c]:{ideal:a[c]};u.exact!==void 0&&typeof u.exact=="number"&&(u.min=u.max=u.exact);let d=function(y,v){return y?y+v.charAt(0).toUpperCase()+v.slice(1):v==="deviceId"?"sourceId":v};if(u.ideal!==void 0){f.optional=f.optional||[];let y={};typeof u.ideal=="number"?(y[d("min",c)]=u.ideal,f.optional.push(y),y={},y[d("max",c)]=u.ideal,f.optional.push(y)):(y[d("",c)]=u.ideal,f.optional.push(y))}u.exact!==void 0&&typeof u.exact!="number"?(f.mandatory=f.mandatory||{},f.mandatory[d("",c)]=u.exact):["min","max"].forEach(y=>{u[y]!==void 0&&(f.mandatory=f.mandatory||{},f.mandatory[d(y,c)]=u[y])})}),a.advanced&&(f.optional=(f.optional||[]).concat(a.advanced)),f},i=function(a,f){if(e.version>=61)return f(a);if(a=JSON.parse(JSON.stringify(a)),a&&typeof a.audio=="object"){let c=function(u,d,y){d in u&&!(y in u)&&(u[y]=u[d],delete u[d])};a=JSON.parse(JSON.stringify(a)),c(a.audio,"autoGainControl","googAutoGainControl"),c(a.audio,"noiseSuppression","googNoiseSuppression"),a.audio=n(a.audio)}if(a&&typeof a.video=="object"){let c=a.video.facingMode;c=c&&(typeof c=="object"?c:{ideal:c});let u=e.version<66;if(c&&(c.exact==="user"||c.exact==="environment"||c.ideal==="user"||c.ideal==="environment")&&!(r.mediaDevices.getSupportedConstraints&&r.mediaDevices.getSupportedConstraints().facingMode&&!u)){delete a.video.facingMode;let d;if(c.exact==="environment"||c.ideal==="environment"?d=["back","rear"]:(c.exact==="user"||c.ideal==="user")&&(d=["front"]),d)return r.mediaDevices.enumerateDevices().then(y=>{y=y.filter(E=>E.kind==="videoinput");let v=y.find(E=>d.some(U=>E.label.toLowerCase().includes(U)));return!v&&y.length&&d.includes("back")&&(v=y[y.length-1]),v&&(a.video.deviceId=c.exact?{exact:v.deviceId}:{ideal:v.deviceId}),a.video=n(a.video),Sn("chrome: "+JSON.stringify(a)),f(a)})}a.video=n(a.video)}return Sn("chrome: "+JSON.stringify(a)),f(a)},s=function(a){return e.version>=64?a:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[a.name]||a.name,message:a.message,constraint:a.constraint||a.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}},o=function(a,f,c){i(a,u=>{r.webkitGetUserMedia(u,f,d=>{c&&c(s(d))})})};if(r.getUserMedia=o.bind(r),r.mediaDevices.getUserMedia){let a=r.mediaDevices.getUserMedia.bind(r.mediaDevices);r.mediaDevices.getUserMedia=function(f){return i(f,c=>a(c).then(u=>{if(c.audio&&!u.getAudioTracks().length||c.video&&!u.getVideoTracks().length)throw u.getTracks().forEach(d=>{d.stop()}),new DOMException("","NotFoundError");return u},u=>Promise.reject(s(u))))}}}function Cn(t,e){if(!(t.navigator.mediaDevices&&"getDisplayMedia"in t.navigator.mediaDevices)&&t.navigator.mediaDevices){if(typeof e!="function"){console.error("shimGetDisplayMedia: getSourceId argument is not a function");return}t.navigator.mediaDevices.getDisplayMedia=function(n){return e(n).then(i=>{let s=n.video&&n.video.width,o=n.video&&n.video.height,a=n.video&&n.video.frameRate;return n.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:i,maxFrameRate:a||3}},s&&(n.video.mandatory.maxWidth=s),o&&(n.video.mandatory.maxHeight=o),t.navigator.mediaDevices.getUserMedia(n)})}}}function Xt(t){t.MediaStream=t.MediaStream||t.webkitMediaStream}function qt(t){if(typeof t=="object"&&t.RTCPeerConnection&&!("ontrack"in t.RTCPeerConnection.prototype)){Object.defineProperty(t.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(r){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=r)},enumerable:!0,configurable:!0});let e=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=n=>{n.stream.addEventListener("addtrack",i=>{let s;t.RTCPeerConnection.prototype.getReceivers?s=this.getReceivers().find(a=>a.track&&a.track.id===i.track.id):s={track:i.track};let o=new Event("track");o.track=i.track,o.receiver=s,o.transceiver={receiver:s},o.streams=[n.stream],this.dispatchEvent(o)}),n.stream.getTracks().forEach(i=>{let s;t.RTCPeerConnection.prototype.getReceivers?s=this.getReceivers().find(a=>a.track&&a.track.id===i.id):s={track:i};let o=new Event("track");o.track=i,o.receiver=s,o.transceiver={receiver:s},o.streams=[n.stream],this.dispatchEvent(o)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else ee(t,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function Zt(t){if(typeof t=="object"&&t.RTCPeerConnection&&!("getSenders"in t.RTCPeerConnection.prototype)&&"createDTMFSender"in t.RTCPeerConnection.prototype){let e=function(i,s){return{track:s,get dtmf(){return this._dtmf===void 0&&(s.kind==="audio"?this._dtmf=i.createDTMFSender(s):this._dtmf=null),this._dtmf},_pc:i}};if(!t.RTCPeerConnection.prototype.getSenders){t.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};let i=t.RTCPeerConnection.prototype.addTrack;t.RTCPeerConnection.prototype.addTrack=function(a,f){let c=i.apply(this,arguments);return c||(c=e(this,a),this._senders.push(c)),c};let s=t.RTCPeerConnection.prototype.removeTrack;t.RTCPeerConnection.prototype.removeTrack=function(a){s.apply(this,arguments);let f=this._senders.indexOf(a);f!==-1&&this._senders.splice(f,1)}}let r=t.RTCPeerConnection.prototype.addStream;t.RTCPeerConnection.prototype.addStream=function(s){this._senders=this._senders||[],r.apply(this,[s]),s.getTracks().forEach(o=>{this._senders.push(e(this,o))})};let n=t.RTCPeerConnection.prototype.removeStream;t.RTCPeerConnection.prototype.removeStream=function(s){this._senders=this._senders||[],n.apply(this,[s]),s.getTracks().forEach(o=>{let a=this._senders.find(f=>f.track===o);a&&this._senders.splice(this._senders.indexOf(a),1)})}}else if(typeof t=="object"&&t.RTCPeerConnection&&"getSenders"in t.RTCPeerConnection.prototype&&"createDTMFSender"in t.RTCPeerConnection.prototype&&t.RTCRtpSender&&!("dtmf"in t.RTCRtpSender.prototype)){let e=t.RTCPeerConnection.prototype.getSenders;t.RTCPeerConnection.prototype.getSenders=function(){let n=e.apply(this,[]);return n.forEach(i=>i._pc=this),n},Object.defineProperty(t.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function Qt(t){if(!t.RTCPeerConnection)return;let e=t.RTCPeerConnection.prototype.getStats;t.RTCPeerConnection.prototype.getStats=function(){let[n,i,s]=arguments;if(arguments.length>0&&typeof n=="function")return e.apply(this,arguments);if(e.length===0&&(arguments.length===0||typeof n!="function"))return e.apply(this,[]);let o=function(f){let c={};return f.result().forEach(d=>{let y={id:d.id,timestamp:d.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[d.type]||d.type};d.names().forEach(v=>{y[v]=d.stat(v)}),c[y.id]=y}),c},a=function(f){return new Map(Object.keys(f).map(c=>[c,f[c]]))};if(arguments.length>=2){let f=function(c){i(a(o(c)))};return e.apply(this,[f,n])}return new Promise((f,c)=>{e.apply(this,[function(u){f(a(o(u)))},c])}).then(i,s)}}function er(t){if(!(typeof t=="object"&&t.RTCPeerConnection&&t.RTCRtpSender&&t.RTCRtpReceiver))return;if(!("getStats"in t.RTCRtpSender.prototype)){let r=t.RTCPeerConnection.prototype.getSenders;r&&(t.RTCPeerConnection.prototype.getSenders=function(){let s=r.apply(this,[]);return s.forEach(o=>o._pc=this),s});let n=t.RTCPeerConnection.prototype.addTrack;n&&(t.RTCPeerConnection.prototype.addTrack=function(){let s=n.apply(this,arguments);return s._pc=this,s}),t.RTCRtpSender.prototype.getStats=function(){let s=this;return this._pc.getStats().then(o=>Yt(o,s.track,!0))}}if(!("getStats"in t.RTCRtpReceiver.prototype)){let r=t.RTCPeerConnection.prototype.getReceivers;r&&(t.RTCPeerConnection.prototype.getReceivers=function(){let i=r.apply(this,[]);return i.forEach(s=>s._pc=this),i}),ee(t,"track",n=>(n.receiver._pc=n.srcElement,n)),t.RTCRtpReceiver.prototype.getStats=function(){let i=this;return this._pc.getStats().then(s=>Yt(s,i.track,!1))}}if(!("getStats"in t.RTCRtpSender.prototype&&"getStats"in t.RTCRtpReceiver.prototype))return;let e=t.RTCPeerConnection.prototype.getStats;t.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof t.MediaStreamTrack){let n=arguments[0],i,s,o;return this.getSenders().forEach(a=>{a.track===n&&(i?o=!0:i=a)}),this.getReceivers().forEach(a=>(a.track===n&&(s?o=!0:s=a),a.track===n)),o||i&&s?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):i?i.getStats():s?s.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function bn(t){t.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(o=>this._shimmedLocalStreams[o][0])};let e=t.RTCPeerConnection.prototype.addTrack;t.RTCPeerConnection.prototype.addTrack=function(o,a){if(!a)return e.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};let f=e.apply(this,arguments);return this._shimmedLocalStreams[a.id]?this._shimmedLocalStreams[a.id].indexOf(f)===-1&&this._shimmedLocalStreams[a.id].push(f):this._shimmedLocalStreams[a.id]=[a,f],f};let r=t.RTCPeerConnection.prototype.addStream;t.RTCPeerConnection.prototype.addStream=function(o){this._shimmedLocalStreams=this._shimmedLocalStreams||{},o.getTracks().forEach(c=>{if(this.getSenders().find(d=>d.track===c))throw new DOMException("Track already exists.","InvalidAccessError")});let a=this.getSenders();r.apply(this,arguments);let f=this.getSenders().filter(c=>a.indexOf(c)===-1);this._shimmedLocalStreams[o.id]=[o].concat(f)};let n=t.RTCPeerConnection.prototype.removeStream;t.RTCPeerConnection.prototype.removeStream=function(o){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[o.id],n.apply(this,arguments)};let i=t.RTCPeerConnection.prototype.removeTrack;t.RTCPeerConnection.prototype.removeTrack=function(o){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},o&&Object.keys(this._shimmedLocalStreams).forEach(a=>{let f=this._shimmedLocalStreams[a].indexOf(o);f!==-1&&this._shimmedLocalStreams[a].splice(f,1),this._shimmedLocalStreams[a].length===1&&delete this._shimmedLocalStreams[a]}),i.apply(this,arguments)}}function tr(t,e){if(!t.RTCPeerConnection)return;if(t.RTCPeerConnection.prototype.addTrack&&e.version>=65)return bn(t);let r=t.RTCPeerConnection.prototype.getLocalStreams;t.RTCPeerConnection.prototype.getLocalStreams=function(){let u=r.apply(this);return this._reverseStreams=this._reverseStreams||{},u.map(d=>this._reverseStreams[d.id])};let n=t.RTCPeerConnection.prototype.addStream;t.RTCPeerConnection.prototype.addStream=function(u){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},u.getTracks().forEach(d=>{if(this.getSenders().find(v=>v.track===d))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[u.id]){let d=new t.MediaStream(u.getTracks());this._streams[u.id]=d,this._reverseStreams[d.id]=u,u=d}n.apply(this,[u])};let i=t.RTCPeerConnection.prototype.removeStream;t.RTCPeerConnection.prototype.removeStream=function(u){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[u.id]||u]),delete this._reverseStreams[this._streams[u.id]?this._streams[u.id].id:u.id],delete this._streams[u.id]},t.RTCPeerConnection.prototype.addTrack=function(u,d){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");let y=[].slice.call(arguments,1);if(y.length!==1||!y[0].getTracks().find(U=>U===u))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(this.getSenders().find(U=>U.track===u))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};let E=this._streams[d.id];if(E)E.addTrack(u),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{let U=new t.MediaStream([u]);this._streams[d.id]=U,this._reverseStreams[U.id]=d,this.addStream(U)}return this.getSenders().find(U=>U.track===u)};function s(c,u){let d=u.sdp;return Object.keys(c._reverseStreams||[]).forEach(y=>{let v=c._reverseStreams[y],E=c._streams[v.id];d=d.replace(new RegExp(E.id,"g"),v.id)}),new RTCSessionDescription({type:u.type,sdp:d})}function o(c,u){let d=u.sdp;return Object.keys(c._reverseStreams||[]).forEach(y=>{let v=c._reverseStreams[y],E=c._streams[v.id];d=d.replace(new RegExp(v.id,"g"),E.id)}),new RTCSessionDescription({type:u.type,sdp:d})}["createOffer","createAnswer"].forEach(function(c){let u=t.RTCPeerConnection.prototype[c],d={[c](){let y=arguments;return arguments.length&&typeof arguments[0]=="function"?u.apply(this,[E=>{let U=s(this,E);y[0].apply(null,[U])},E=>{y[1]&&y[1].apply(null,E)},arguments[2]]):u.apply(this,arguments).then(E=>s(this,E))}};t.RTCPeerConnection.prototype[c]=d[c]});let a=t.RTCPeerConnection.prototype.setLocalDescription;t.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type?a.apply(this,arguments):(arguments[0]=o(this,arguments[0]),a.apply(this,arguments))};let f=Object.getOwnPropertyDescriptor(t.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(t.RTCPeerConnection.prototype,"localDescription",{get(){let c=f.get.apply(this);return c.type===""?c:s(this,c)}}),t.RTCPeerConnection.prototype.removeTrack=function(u){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!u._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(u._pc===this))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");this._streams=this._streams||{};let y;Object.keys(this._streams).forEach(v=>{this._streams[v].getTracks().find(U=>u.track===U)&&(y=this._streams[v])}),y&&(y.getTracks().length===1?this.removeStream(this._reverseStreams[y.id]):y.removeTrack(u.track),this.dispatchEvent(new Event("negotiationneeded")))}}function nt(t,e){!t.RTCPeerConnection&&t.webkitRTCPeerConnection&&(t.RTCPeerConnection=t.webkitRTCPeerConnection),t.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(r){let n=t.RTCPeerConnection.prototype[r],i={[r](){return arguments[0]=new(r==="addIceCandidate"?t.RTCIceCandidate:t.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};t.RTCPeerConnection.prototype[r]=i[r]})}function rr(t,e){ee(t,"negotiationneeded",r=>{let n=r.target;if(!((e.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics==="plan-b")&&n.signalingState!=="stable"))return r})}var at={};et(at,{shimAddTransceiver:()=>cr,shimCreateAnswer:()=>ur,shimCreateOffer:()=>lr,shimGetDisplayMedia:()=>kn,shimGetParameters:()=>fr,shimGetUserMedia:()=>st,shimOnTrack:()=>nr,shimPeerConnection:()=>ot,shimRTCDataChannel:()=>ar,shimReceiverGetStats:()=>sr,shimRemoveStream:()=>or,shimSenderGetStats:()=>ir});function st(t,e){let r=t&&t.navigator,n=t&&t.MediaStreamTrack;if(r.getUserMedia=function(i,s,o){_e("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),r.mediaDevices.getUserMedia(i).then(s,o)},!(e.version>55&&"autoGainControl"in r.mediaDevices.getSupportedConstraints())){let i=function(o,a,f){a in o&&!(f in o)&&(o[f]=o[a],delete o[a])},s=r.mediaDevices.getUserMedia.bind(r.mediaDevices);if(r.mediaDevices.getUserMedia=function(o){return typeof o=="object"&&typeof o.audio=="object"&&(o=JSON.parse(JSON.stringify(o)),i(o.audio,"autoGainControl","mozAutoGainControl"),i(o.audio,"noiseSuppression","mozNoiseSuppression")),s(o)},n&&n.prototype.getSettings){let o=n.prototype.getSettings;n.prototype.getSettings=function(){let a=o.apply(this,arguments);return i(a,"mozAutoGainControl","autoGainControl"),i(a,"mozNoiseSuppression","noiseSuppression"),a}}if(n&&n.prototype.applyConstraints){let o=n.prototype.applyConstraints;n.prototype.applyConstraints=function(a){return this.kind==="audio"&&typeof a=="object"&&(a=JSON.parse(JSON.stringify(a)),i(a,"autoGainControl","mozAutoGainControl"),i(a,"noiseSuppression","mozNoiseSuppression")),o.apply(this,[a])}}}}function kn(t,e){t.navigator.mediaDevices&&"getDisplayMedia"in t.navigator.mediaDevices||t.navigator.mediaDevices&&(t.navigator.mediaDevices.getDisplayMedia=function(n){if(!(n&&n.video)){let i=new DOMException("getDisplayMedia without video constraints is undefined");return i.name="NotFoundError",i.code=8,Promise.reject(i)}return n.video===!0?n.video={mediaSource:e}:n.video.mediaSource=e,t.navigator.mediaDevices.getUserMedia(n)})}function nr(t){typeof t=="object"&&t.RTCTrackEvent&&"receiver"in t.RTCTrackEvent.prototype&&!("transceiver"in t.RTCTrackEvent.prototype)&&Object.defineProperty(t.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function ot(t,e){if(typeof t!="object"||!(t.RTCPeerConnection||t.mozRTCPeerConnection))return;!t.RTCPeerConnection&&t.mozRTCPeerConnection&&(t.RTCPeerConnection=t.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){let s=t.RTCPeerConnection.prototype[i],o={[i](){return arguments[0]=new(i==="addIceCandidate"?t.RTCIceCandidate:t.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};t.RTCPeerConnection.prototype[i]=o[i]});let r={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=t.RTCPeerConnection.prototype.getStats;t.RTCPeerConnection.prototype.getStats=function(){let[s,o,a]=arguments;return n.apply(this,[s||null]).then(f=>{if(e.version<53&&!o)try{f.forEach(c=>{c.type=r[c.type]||c.type})}catch(c){if(c.name!=="TypeError")throw c;f.forEach((u,d)=>{f.set(d,Object.assign({},u,{type:r[u.type]||u.type}))})}return f}).then(o,a)}}function ir(t){if(!(typeof t=="object"&&t.RTCPeerConnection&&t.RTCRtpSender)||t.RTCRtpSender&&"getStats"in t.RTCRtpSender.prototype)return;let e=t.RTCPeerConnection.prototype.getSenders;e&&(t.RTCPeerConnection.prototype.getSenders=function(){let i=e.apply(this,[]);return i.forEach(s=>s._pc=this),i});let r=t.RTCPeerConnection.prototype.addTrack;r&&(t.RTCPeerConnection.prototype.addTrack=function(){let i=r.apply(this,arguments);return i._pc=this,i}),t.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function sr(t){if(!(typeof t=="object"&&t.RTCPeerConnection&&t.RTCRtpSender)||t.RTCRtpSender&&"getStats"in t.RTCRtpReceiver.prototype)return;let e=t.RTCPeerConnection.prototype.getReceivers;e&&(t.RTCPeerConnection.prototype.getReceivers=function(){let n=e.apply(this,[]);return n.forEach(i=>i._pc=this),n}),ee(t,"track",r=>(r.receiver._pc=r.srcElement,r)),t.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function or(t){!t.RTCPeerConnection||"removeStream"in t.RTCPeerConnection.prototype||(t.RTCPeerConnection.prototype.removeStream=function(r){_e("removeStream","removeTrack"),this.getSenders().forEach(n=>{n.track&&r.getTracks().includes(n.track)&&this.removeTrack(n)})})}function ar(t){t.DataChannel&&!t.RTCDataChannel&&(t.RTCDataChannel=t.DataChannel)}function cr(t){if(!(typeof t=="object"&&t.RTCPeerConnection))return;let e=t.RTCPeerConnection.prototype.addTransceiver;e&&(t.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];let n=arguments[1]&&arguments[1].sendEncodings;n===void 0&&(n=[]),n=[...n];let i=n.length>0;i&&n.forEach(o=>{if("rid"in o&&!/^[a-z0-9]{0,16}$/i.test(o.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in o&&!(parseFloat(o.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in o&&!(parseFloat(o.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});let s=e.apply(this,arguments);if(i){let{sender:o}=s,a=o.getParameters();(!("encodings"in a)||a.encodings.length===1&&Object.keys(a.encodings[0]).length===0)&&(a.encodings=n,o.sendEncodings=n,this.setParametersPromises.push(o.setParameters(a).then(()=>{delete o.sendEncodings}).catch(()=>{delete o.sendEncodings})))}return s})}function fr(t){if(!(typeof t=="object"&&t.RTCRtpSender))return;let e=t.RTCRtpSender.prototype.getParameters;e&&(t.RTCRtpSender.prototype.getParameters=function(){let n=e.apply(this,arguments);return"encodings"in n||(n.encodings=[].concat(this.sendEncodings||[{}])),n})}function lr(t){if(!(typeof t=="object"&&t.RTCPeerConnection))return;let e=t.RTCPeerConnection.prototype.createOffer;t.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}function ur(t){if(!(typeof t=="object"&&t.RTCPeerConnection))return;let e=t.RTCPeerConnection.prototype.createAnswer;t.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}var ct={};et(ct,{shimAudioContext:()=>_r,shimCallbacksAPI:()=>pr,shimConstraints:()=>Tn,shimCreateOfferLegacy:()=>xr,shimGetUserMedia:()=>mr,shimLocalStreamsAPI:()=>hr,shimRTCIceServerUrls:()=>yr,shimRemoteStreamsAPI:()=>dr,shimTrackEventTransceiver:()=>gr});function hr(t){if(!(typeof t!="object"||!t.RTCPeerConnection)){if("getLocalStreams"in t.RTCPeerConnection.prototype||(t.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in t.RTCPeerConnection.prototype)){let e=t.RTCPeerConnection.prototype.addTrack;t.RTCPeerConnection.prototype.addStream=function(n){this._localStreams||(this._localStreams=[]),this._localStreams.includes(n)||this._localStreams.push(n),n.getAudioTracks().forEach(i=>e.call(this,i,n)),n.getVideoTracks().forEach(i=>e.call(this,i,n))},t.RTCPeerConnection.prototype.addTrack=function(n,...i){return i&&i.forEach(s=>{this._localStreams?this._localStreams.includes(s)||this._localStreams.push(s):this._localStreams=[s]}),e.apply(this,arguments)}}"removeStream"in t.RTCPeerConnection.prototype||(t.RTCPeerConnection.prototype.removeStream=function(r){this._localStreams||(this._localStreams=[]);let n=this._localStreams.indexOf(r);if(n===-1)return;this._localStreams.splice(n,1);let i=r.getTracks();this.getSenders().forEach(s=>{i.includes(s.track)&&this.removeTrack(s)})})}}function dr(t){if(!(typeof t!="object"||!t.RTCPeerConnection)&&("getRemoteStreams"in t.RTCPeerConnection.prototype||(t.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in t.RTCPeerConnection.prototype))){Object.defineProperty(t.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(r){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=r),this.addEventListener("track",this._onaddstreampoly=n=>{n.streams.forEach(i=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(i))return;this._remoteStreams.push(i);let s=new Event("addstream");s.stream=i,this.dispatchEvent(s)})})}});let e=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(){let n=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(i){i.streams.forEach(s=>{if(n._remoteStreams||(n._remoteStreams=[]),n._remoteStreams.indexOf(s)>=0)return;n._remoteStreams.push(s);let o=new Event("addstream");o.stream=s,n.dispatchEvent(o)})}),e.apply(n,arguments)}}}function pr(t){if(typeof t!="object"||!t.RTCPeerConnection)return;let e=t.RTCPeerConnection.prototype,r=e.createOffer,n=e.createAnswer,i=e.setLocalDescription,s=e.setRemoteDescription,o=e.addIceCandidate;e.createOffer=function(c,u){let d=arguments.length>=2?arguments[2]:arguments[0],y=r.apply(this,[d]);return u?(y.then(c,u),Promise.resolve()):y},e.createAnswer=function(c,u){let d=arguments.length>=2?arguments[2]:arguments[0],y=n.apply(this,[d]);return u?(y.then(c,u),Promise.resolve()):y};let a=function(f,c,u){let d=i.apply(this,[f]);return u?(d.then(c,u),Promise.resolve()):d};e.setLocalDescription=a,a=function(f,c,u){let d=s.apply(this,[f]);return u?(d.then(c,u),Promise.resolve()):d},e.setRemoteDescription=a,a=function(f,c,u){let d=o.apply(this,[f]);return u?(d.then(c,u),Promise.resolve()):d},e.addIceCandidate=a}function mr(t){let e=t&&t.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){let r=e.mediaDevices,n=r.getUserMedia.bind(r);e.mediaDevices.getUserMedia=i=>n(Tn(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(n,i,s){e.mediaDevices.getUserMedia(n).then(i,s)}.bind(e))}function Tn(t){return t&&t.video!==void 0?Object.assign({},t,{video:Wt(t.video)}):t}function yr(t){if(!t.RTCPeerConnection)return;let e=t.RTCPeerConnection;t.RTCPeerConnection=function(n,i){if(n&&n.iceServers){let s=[];for(let o=0;oo.receiver.track.kind==="audio");n.offerToReceiveAudio===!1&&i?i.direction==="sendrecv"?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":i.direction==="recvonly"&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):n.offerToReceiveAudio===!0&&!i&&this.addTransceiver("audio",{direction:"recvonly"}),typeof n.offerToReceiveVideo<"u"&&(n.offerToReceiveVideo=!!n.offerToReceiveVideo);let s=this.getTransceivers().find(o=>o.receiver.track.kind==="video");n.offerToReceiveVideo===!1&&s?s.direction==="sendrecv"?s.setDirection?s.setDirection("sendonly"):s.direction="sendonly":s.direction==="recvonly"&&(s.setDirection?s.setDirection("inactive"):s.direction="inactive"):n.offerToReceiveVideo===!0&&!s&&this.addTransceiver("video",{direction:"recvonly"})}return e.apply(this,arguments)}}function _r(t){typeof t!="object"||t.AudioContext||(t.AudioContext=t.webkitAudioContext)}var Cr={};et(Cr,{removeExtmapAllowMixed:()=>ut,shimAddIceCandidateNullOrEmpty:()=>Oe,shimConnectionState:()=>lt,shimMaxMessageSize:()=>Me,shimParameterlessSetLocalDescription:()=>Le,shimRTCIceCandidate:()=>Ae,shimRTCIceCandidateRelayProtocol:()=>ft,shimSendThrowTypeError:()=>Ue});var ve=pn(Sr());function Ae(t){if(!t.RTCIceCandidate||t.RTCIceCandidate&&"foundation"in t.RTCIceCandidate.prototype)return;let e=t.RTCIceCandidate;t.RTCIceCandidate=function(n){if(typeof n=="object"&&n.candidate&&n.candidate.indexOf("a=")===0&&(n=JSON.parse(JSON.stringify(n)),n.candidate=n.candidate.substring(2)),n.candidate&&n.candidate.length){let i=new e(n),s=ve.default.parseCandidate(n.candidate);for(let o in s)o in i||Object.defineProperty(i,o,{value:s[o]});return i.toJSON=function(){return{candidate:i.candidate,sdpMid:i.sdpMid,sdpMLineIndex:i.sdpMLineIndex,usernameFragment:i.usernameFragment}},i}return new e(n)},t.RTCIceCandidate.prototype=e.prototype,ee(t,"icecandidate",r=>(r.candidate&&Object.defineProperty(r,"candidate",{value:new t.RTCIceCandidate(r.candidate),writable:"false"}),r))}function ft(t){!t.RTCIceCandidate||t.RTCIceCandidate&&"relayProtocol"in t.RTCIceCandidate.prototype||ee(t,"icecandidate",e=>{if(e.candidate){let r=ve.default.parseCandidate(e.candidate.candidate);r.type==="relay"&&(e.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[r.priority>>24])}return e})}function Me(t,e){if(!t.RTCPeerConnection)return;"sctp"in t.RTCPeerConnection.prototype||Object.defineProperty(t.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});let r=function(a){if(!a||!a.sdp)return!1;let f=ve.default.splitSections(a.sdp);return f.shift(),f.some(c=>{let u=ve.default.parseMLine(c);return u&&u.kind==="application"&&u.protocol.indexOf("SCTP")!==-1})},n=function(a){let f=a.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(f===null||f.length<2)return-1;let c=parseInt(f[1],10);return c!==c?-1:c},i=function(a){let f=65536;return e.browser==="firefox"&&(e.version<57?a===-1?f=16384:f=2147483637:e.version<60?f=e.version===57?65535:65536:f=2147483637),f},s=function(a,f){let c=65536;e.browser==="firefox"&&e.version===57&&(c=65535);let u=ve.default.matchPrefix(a.sdp,"a=max-message-size:");return u.length>0?c=parseInt(u[0].substring(19),10):e.browser==="firefox"&&f!==-1&&(c=2147483637),c},o=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){let{sdpSemantics:f}=this.getConfiguration();f==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(r(arguments[0])){let f=n(arguments[0]),c=i(f),u=s(arguments[0],f),d;c===0&&u===0?d=Number.POSITIVE_INFINITY:c===0||u===0?d=Math.max(c,u):d=Math.min(c,u);let y={};Object.defineProperty(y,"maxMessageSize",{get(){return d}}),this._sctp=y}return o.apply(this,arguments)}}function Ue(t){if(!(t.RTCPeerConnection&&"createDataChannel"in t.RTCPeerConnection.prototype))return;function e(n,i){let s=n.send;n.send=function(){let a=arguments[0],f=a.length||a.size||a.byteLength;if(n.readyState==="open"&&i.sctp&&f>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return s.apply(n,arguments)}}let r=t.RTCPeerConnection.prototype.createDataChannel;t.RTCPeerConnection.prototype.createDataChannel=function(){let i=r.apply(this,arguments);return e(i,this),i},ee(t,"datachannel",n=>(e(n.channel,n.target),n))}function lt(t){if(!t.RTCPeerConnection||"connectionState"in t.RTCPeerConnection.prototype)return;let e=t.RTCPeerConnection.prototype;Object.defineProperty(e,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(r){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),r&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=r)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(r=>{let n=e[r];e[r]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{let s=i.target;if(s._lastConnectionState!==s.connectionState){s._lastConnectionState=s.connectionState;let o=new Event("connectionstatechange",i);s.dispatchEvent(o)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}})}function ut(t,e){if(!t.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;let r=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(i){if(i&&i.sdp&&i.sdp.indexOf(` +a=extmap-allow-mixed`)!==-1){let s=i.sdp.split(` +`).filter(o=>o.trim()!=="a=extmap-allow-mixed").join(` +`);t.RTCSessionDescription&&i instanceof t.RTCSessionDescription?arguments[0]=new t.RTCSessionDescription({type:i.type,sdp:s}):i.sdp=s}return r.apply(this,arguments)}}function Oe(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;let r=t.RTCPeerConnection.prototype.addIceCandidate;!r||r.length===0||(t.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():r.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Le(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;let r=t.RTCPeerConnection.prototype.setLocalDescription;!r||r.length===0||(t.RTCPeerConnection.prototype.setLocalDescription=function(){let i=arguments[0]||{};if(typeof i!="object"||i.type&&i.sdp)return r.apply(this,arguments);if(i={type:i.type,sdp:i.sdp},!i.type)switch(this.signalingState){case"stable":case"have-local-offer":case"have-remote-pranswer":i.type="offer";break;default:i.type="answer";break}return i.sdp||i.type!=="offer"&&i.type!=="answer"?r.apply(this,[i]):(i.type==="offer"?this.createOffer:this.createAnswer).apply(this).then(o=>r.apply(this,[o]))})}var vi=pn(Sr());function En({window:t}={},e={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){let r=tt,n=vn(t),i={browserDetails:n,commonShim:Cr,extractVersion:De,disableLog:xn,disableWarnings:_n,sdp:vi};switch(n.browser){case"chrome":if(!it||!nt||!e.shimChrome)return r("Chrome shim is not included in this adapter release."),i;if(n.version===null)return r("Chrome shim can not determine version, not shimming."),i;r("adapter.js shimming chrome."),i.browserShim=it,Oe(t,n),Le(t,n),rt(t,n),Xt(t,n),nt(t,n),qt(t,n),tr(t,n),Zt(t,n),Qt(t,n),er(t,n),rr(t,n),Ae(t,n),ft(t,n),lt(t,n),Me(t,n),Ue(t,n),ut(t,n);break;case"firefox":if(!at||!ot||!e.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=at,Oe(t,n),Le(t,n),st(t,n),ot(t,n),nr(t,n),or(t,n),ir(t,n),sr(t,n),ar(t,n),cr(t,n),fr(t,n),lr(t,n),ur(t,n),Ae(t,n),lt(t,n),Me(t,n),Ue(t,n);break;case"safari":if(!ct||!e.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=ct,Oe(t,n),Le(t,n),yr(t,n),xr(t,n),pr(t,n),hr(t,n),dr(t,n),gr(t,n),mr(t,n),_r(t,n),Ae(t,n),ft(t,n),Me(t,n),Ue(t,n),ut(t,n);break;default:r("Unsupported browser!");break}return i}var Si=En({window:typeof window>"u"?void 0:window}),br=Si;var kr;try{kr=new TextDecoder}catch{}var k,he,m=0;var An=[],Ci=105,bi=57342,ki=57343,Rn=57337;var Pn=6,Se={},Tr=An,Er=0,D={},L,pt,mt=0,Fe=0,z,Z,F=[],Rr=[],J,G,Be,In={useRecords:!1,mapsAsObjects:!0},ze=!1,Mn=2;try{new Function("")}catch{Mn=1/0}var oe=class t{constructor(e){if(e&&((e.keyMap||e._keyMap)&&!e.useRecords&&(e.useRecords=!1,e.mapsAsObjects=!0),e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.getStructures&&(e.getShared=e.getStructures),e.getShared&&!e.structures&&((e.structures=[]).uninitialized=!0),e.keyMap)){this.mapKey=new Map;for(let[r,n]of Object.entries(e.keyMap))this.mapKey.set(n,r)}Object.assign(this,e)}decodeKey(e){return this.keyMap&&this.mapKey.get(e)||e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(e){if(!this._keyMap)return e;let r=new Map;for(let[n,i]of Object.entries(e))r.set(this._keyMap.hasOwnProperty(n)?this._keyMap[n]:n,i);return r}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[n,i]of Object.entries(this._keyMap))this._mapKey.set(i,n)}let r={};return e.forEach((n,i)=>r[Y(this._mapKey.has(i)?this._mapKey.get(i):i)]=n),r}mapDecode(e,r){let n=this.decode(e);if(this._keyMap)switch(n.constructor.name){case"Array":return n.map(i=>this.decodeKeys(i))}return n}decode(e,r){if(k)return Bn(()=>(yt(),this?this.decode(e,r):t.prototype.decode.call(In,e,r)));he=r>-1?r:e.length,m=0,Er=0,Fe=0,pt=null,Tr=An,z=null,k=e;try{G=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(n){throw k=null,e instanceof Uint8Array?n:new Error("Source must be a Uint8Array or Buffer but was a "+(e&&typeof e=="object"?e.constructor.name:typeof e))}if(this instanceof t){if(D=this,J=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return L=this.structures,ht();(!L||L.length>0)&&(L=[])}else D=In,(!L||L.length>0)&&(L=[]),J=null;return ht()}decodeMultiple(e,r){let n,i=0;try{let s=e.length;ze=!0;let o=this?this.decode(e,s):Ar.decode(e,s);if(r){if(r(o)===!1)return;for(;m=z.postBundlePosition){let e=new Error("Unexpected bundle position");throw e.incomplete=!0,e}m=z.postBundlePosition,z=null}if(m==he)L=null,k=null,Z&&(Z=null);else if(m>he){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}else if(!ze)throw new Error("Data read, but end of buffer not reached");return t}catch(t){throw yt(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer"))&&(t.incomplete=!0),t}}function w(){let t=k[m++],e=t>>5;if(t=t&31,t>23)switch(t){case 24:t=k[m++];break;case 25:if(e==7)return Pi();t=G.getUint16(m),m+=2;break;case 26:if(e==7){let r=G.getFloat32(m);if(D.useFloat32>2){let n=gt[(k[m]&127)<<1|k[m+1]>>7];return m+=4,(n*r+(r>0?.5:-.5)>>0)/n}return m+=4,r}t=G.getUint32(m),m+=4;break;case 27:if(e==7){let r=G.getFloat64(m);return m+=8,r}if(e>1){if(G.getUint32(m)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");t=G.getUint32(m+4)}else D.int64AsNumber?(t=G.getUint32(m)*4294967296,t+=G.getUint32(m+4)):t=G.getBigUint64(m);m+=8;break;case 31:switch(e){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let r=[],n,i=0;for(;(n=w())!=Se;)r[i++]=n;return e==4?r:e==3?r.join(""):__Buffer$.concat(r);case 5:let s;if(D.mapsAsObjects){let o={};if(D.keyMap)for(;(s=w())!=Se;)o[Y(D.decodeKey(s))]=w();else for(;(s=w())!=Se;)o[Y(s)]=w();return o}else{Be&&(D.mapsAsObjects=!0,Be=!1);let o=new Map;if(D.keyMap)for(;(s=w())!=Se;)o.set(D.decodeKey(s),w());else for(;(s=w())!=Se;)o.set(s,w());return o}case 7:return Se;default:throw new Error("Invalid major type for indefinite length "+e)}default:throw new Error("Unknown token "+t)}switch(e){case 0:return t;case 1:return~t;case 2:return Ri(t);case 3:if(Fe>=m)return pt.slice(m-mt,(m+=t)-mt);if(Fe==0&&he<140&&t<32){let i=t<16?Un(t):Ei(t);if(i!=null)return i}return Ti(t);case 4:let r=new Array(t);for(let i=0;i=Rn){let i=L[t&8191];if(i)return i.read||(i.read=Pr(i)),i.read();if(t<65536){if(t==ki){let s=be(),o=w(),a=w();wr(o,a);let f={};if(D.keyMap)for(let c=2;c23)switch(r){case 24:r=k[m++];break;case 25:r=G.getUint16(m),m+=2;break;case 26:r=G.getUint32(m),m+=4;break;default:throw new Error("Expected array header, but got "+k[m-1])}let n=this.compiledReader;for(;n;){if(n.propertyCount===r)return n(w);n=n.next}if(this.slowReads++>=Mn){let s=this.length==r?this:this.slice(0,r);return n=D.keyMap?new Function("r","return {"+s.map(o=>D.decodeKey(o)).map(o=>wn.test(o)?Y(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"):new Function("r","return {"+s.map(o=>wn.test(o)?Y(o)+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"}"),this.compiledReader&&(n.next=this.compiledReader),n.propertyCount=r,this.compiledReader=n,n(w)}let i={};if(D.keyMap)for(let s=0;s64&&kr)return kr.decode(k.subarray(m,m+=t));let r=m+t,n=[];for(e="";m65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|f&1023),n.push(f)}else n.push(i);n.length>=4096&&(e+=j.apply(String,n),n.length=0)}return n.length>0&&(e+=j.apply(String,n)),e}var j=String.fromCharCode;function Ei(t){let e=m,r=new Array(t);for(let n=0;n0){m=e;return}r[n]=i}return j.apply(String,r)}function Un(t){if(t<4)if(t<2){if(t===0)return"";{let e=k[m++];if((e&128)>1){m-=1;return}return j(e)}}else{let e=k[m++],r=k[m++];if((e&128)>0||(r&128)>0){m-=2;return}if(t<3)return j(e,r);let n=k[m++];if((n&128)>0){m-=3;return}return j(e,r,n)}else{let e=k[m++],r=k[m++],n=k[m++],i=k[m++];if((e&128)>0||(r&128)>0||(n&128)>0||(i&128)>0){m-=4;return}if(t<6){if(t===4)return j(e,r,n,i);{let s=k[m++];if((s&128)>0){m-=5;return}return j(e,r,n,i,s)}}else if(t<8){let s=k[m++],o=k[m++];if((s&128)>0||(o&128)>0){m-=6;return}if(t<7)return j(e,r,n,i,s,o);let a=k[m++];if((a&128)>0){m-=7;return}return j(e,r,n,i,s,o,a)}else{let s=k[m++],o=k[m++],a=k[m++],f=k[m++];if((s&128)>0||(o&128)>0||(a&128)>0||(f&128)>0){m-=8;return}if(t<10){if(t===8)return j(e,r,n,i,s,o,a,f);{let c=k[m++];if((c&128)>0){m-=9;return}return j(e,r,n,i,s,o,a,f,c)}}else if(t<12){let c=k[m++],u=k[m++];if((c&128)>0||(u&128)>0){m-=10;return}if(t<11)return j(e,r,n,i,s,o,a,f,c,u);let d=k[m++];if((d&128)>0){m-=11;return}return j(e,r,n,i,s,o,a,f,c,u,d)}else{let c=k[m++],u=k[m++],d=k[m++],y=k[m++];if((c&128)>0||(u&128)>0||(d&128)>0||(y&128)>0){m-=12;return}if(t<14){if(t===12)return j(e,r,n,i,s,o,a,f,c,u,d,y);{let v=k[m++];if((v&128)>0){m-=13;return}return j(e,r,n,i,s,o,a,f,c,u,d,y,v)}}else{let v=k[m++],E=k[m++];if((v&128)>0||(E&128)>0){m-=14;return}if(t<15)return j(e,r,n,i,s,o,a,f,c,u,d,y,v,E);let U=k[m++];if((U&128)>0){m-=15;return}return j(e,r,n,i,s,o,a,f,c,u,d,y,v,E,U)}}}}}function Ri(t){return D.copyBuffers?Uint8Array.prototype.slice.call(k,m,m+=t):k.subarray(m,m+=t)}var On=new Float32Array(1),dt=new Uint8Array(On.buffer,0,4);function Pi(){let t=k[m++],e=k[m++],r=(t&127)>>2;if(r===31)return e||t&3?NaN:t&128?-1/0:1/0;if(r===0){let n=((t&3)<<8|e)/16777216;return t&128?-n:n}return dt[3]=t&128|(r>>1)+56,dt[2]=(t&7)<<5|e>>3,dt[1]=e<<5,dt[0]=0,On[0]}var Ks=new Array(4096);var Q=class{constructor(e,r){this.value=e,this.tag=r}};F[0]=t=>new Date(t);F[1]=t=>new Date(Math.round(t*1e3));F[2]=t=>{let e=BigInt(0);for(let r=0,n=t.byteLength;rBigInt(-1)-F[2](t);F[4]=t=>+(t[1]+"e"+t[0]);F[5]=t=>t[1]*Math.exp(t[0]*Math.log(2));var wr=(t,e)=>{t=t-57344;let r=L[t];r&&r.isShared&&((L.restoreStructures||(L.restoreStructures=[]))[t]=r),L[t]=e,e.read=Pr(e)};F[Ci]=t=>{let e=t.length,r=t[1];wr(t[0],r);let n={};for(let i=2;iz?z[0].slice(z.position0,z.position0+=t):new Q(t,14);F[15]=t=>z?z[1].slice(z.position1,z.position1+=t):new Q(t,15);var Ii={Error,RegExp};F[27]=t=>(Ii[t[0]]||Error)(t[1],t[2]);var Ln=t=>{if(k[m++]!=132)throw new Error("Packed values structure must be followed by a 4 element array");let e=t();return J=J?e.concat(J.slice(e.length)):e,J.prefixes=t(),J.suffixes=t(),t()};Ln.handlesRead=!0;F[51]=Ln;F[Pn]=t=>{if(!J)if(D.getShared)Dr();else return new Q(t,Pn);if(typeof t=="number")return J[16+(t>=0?2*t:-2*t-1)];throw new Error("No support for non-integer packed references yet")};F[28]=t=>{Z||(Z=new Map,Z.id=0);let e=Z.id++,r=k[m],n;r>>5==4?n=[]:n={};let i={target:n};Z.set(e,i);let s=t();return i.used?Object.assign(n,s):(i.target=s,s)};F[28].handlesRead=!0;F[29]=t=>{let e=Z.get(t);return e.used=!0,e.target};F[258]=t=>new Set(t);(F[259]=t=>(D.mapsAsObjects&&(D.mapsAsObjects=!1,Be=!0),t())).handlesRead=!0;function Ce(t,e){return typeof t=="string"?t+e:t instanceof Array?t.concat(e):Object.assign({},t,e)}function ue(){if(!J)if(D.getShared)Dr();else throw new Error("No packed values available");return J}var wi=1399353956;Rr.push((t,e)=>{if(t>=225&&t<=255)return Ce(ue().prefixes[t-224],e);if(t>=28704&&t<=32767)return Ce(ue().prefixes[t-28672],e);if(t>=1879052288&&t<=2147483647)return Ce(ue().prefixes[t-1879048192],e);if(t>=216&&t<=223)return Ce(e,ue().suffixes[t-216]);if(t>=27647&&t<=28671)return Ce(e,ue().suffixes[t-27639]);if(t>=1811940352&&t<=1879048191)return Ce(e,ue().suffixes[t-1811939328]);if(t==wi)return{packedValues:J,structures:L.slice(0),version:e};if(t==55799)return e});var Di=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,Dn=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],Ai=[64,68,69,70,71,72,77,78,79,85,86];for(let t=0;t{if(!t)throw new Error("Could not find typed array for code "+e);return new t(Uint8Array.prototype.slice.call(o,0).buffer)}:o=>{if(!t)throw new Error("Could not find typed array for code "+e);let a=new DataView(o.buffer,o.byteOffset,o.byteLength),f=o.length>>s,c=new t(f),u=a[r];for(let d=0;d23)switch(t){case 24:t=k[m++];break;case 25:t=G.getUint16(m),m+=2;break;case 26:t=G.getUint32(m),m+=4;break}return t}function Dr(){if(D.getShared){let t=Bn(()=>(k=null,D.getShared()))||{},e=t.structures||[];D.sharedVersion=t.version,J=D.sharedValues=t.packedValues,L===!0?D.structures=L=e:L.splice.apply(L,[0,e.length].concat(e))}}function Bn(t){let e=he,r=m,n=Er,i=mt,s=Fe,o=pt,a=Tr,f=Z,c=z,u=new Uint8Array(k.slice(0,he)),d=L,y=D,v=ze,E=t();return he=e,m=r,Er=n,mt=i,Fe=s,pt=o,Tr=a,Z=f,z=c,k=u,ze=v,L=d,D=y,G=new DataView(k.buffer,k.byteOffset,k.byteLength),E}function yt(){k=null,Z=null,L=null}var gt=new Array(147);for(let t=0;t<256;t++)gt[t]=+("1e"+Math.floor(45.15-t*.30103));var Ar=new oe({useRecords:!1}),Oi=Ar.decode,Li=Ar.decodeMultiple,xt={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};var _t;try{_t=new TextEncoder}catch{}var Br,Gn,Ct=typeof globalThis=="object"&&globalThis.Buffer,Ne=typeof Ct<"u",Mr=Ne?Ct.allocUnsafeSlow:Uint8Array,Fn=Ne?Ct:Uint8Array,zn=256,Nn=Ne?4294967296:2144337920;var Ur,h,O,l=0,ce,N=null,Bi=61440,Fi=/[\u0080-\uFFFF]/,W=Symbol("record-id"),de=class extends oe{constructor(e){super(e),this.offset=0;let r,n,i,s,o,a;e=e||{};let f=Fn.prototype.utf8Write?function(p,C,_){return h.utf8Write(p,C,_)}:_t&&_t.encodeInto?function(p,C){return _t.encodeInto(p,h.subarray(C)).written}:!1,c=this,u=e.structures||e.saveStructures,d=e.maxSharedStructures;if(d==null&&(d=u?128:0),d>8190)throw new Error("Maximum maxSharedStructure is 8190");let y=e.sequential;y&&(d=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let v,E,U=e.sharedValues,q;if(U){q=Object.create(null);for(let p=0,C=U.length;pthis.encodeKeys(_));break}return this.encode(p,C)},this.encode=function(p,C){if(h||(h=new Mr(8192),O=new DataView(h.buffer,0,8192),l=0),ce=h.length-10,ce-l<2048?(h=new Mr(h.length),O=new DataView(h.buffer,0,h.length),ce=h.length-10,l=0):C===Fr&&(l=l+7&2147483640),n=l,c.useSelfDescribedHeader&&(O.setUint32(l,3654940416),l+=3),a=c.structuredClone?new Map:null,c.bundleStrings&&typeof p!="string"?(N=[],N.size=1/0):N=null,i=c.structures,i){if(i.uninitialized){let S=c.getShared()||{};c.structures=i=S.structures||[],c.sharedVersion=S.version;let x=c.sharedValues=S.packedValues;if(x){q={};for(let T=0,R=x.length;Td&&!y&&(_=d),!i.transitions){i.transitions=Object.create(null);for(let S=0;S<_;S++){let x=i[S];if(!x)continue;let T,R=i.transitions;for(let P=0,I=x.length;P0){h[l++]=216,h[l++]=51,re(4);let S=_.values;M(S),re(0),re(0),E=Object.create(q||null);for(let x=0,T=S.length;xce&&Pe(l),c.offset=l;let _=ji(h.subarray(n,l),a.idsToInsert);return a=null,_}return C&Fr?(h.start=n,h.end=l,h):h.subarray(n,l)}finally{if(i){if(Qe<10&&Qe++,i.length>d&&(i.length=d),Ft>1e4)i.transitions=null,Qe=0,Ft=0,se.length>0&&(se=[]);else if(se.length>0&&!y){for(let _=0,S=se.length;_d&&(c.structures=c.structures.slice(0,d));let _=h.subarray(n,l);return c.updateSharedData()===!1?c.encode(p):_}C&Yi&&(l=n)}},this.findCommonStringsToPack=()=>(v=new Map,q||(q=Object.create(null)),p=>{let C=p&&p.threshold||4,_=this.pack?p.maxPrivatePackedValues||16:0;U||(U=this.sharedValues=[]);for(let[S,x]of v)x.count>C&&(q[S]=_++,U.push(S),s=!0);for(;this.saveShared&&this.updateSharedData()===!1;);v=null});let M=p=>{l>ce&&(h=Pe(l));var C=typeof p,_;if(C==="string"){if(E){let R=E[p];if(R>=0){R<16?h[l++]=R+224:(h[l++]=198,R&1?M(15-R>>1):M(R-16>>1));return}else if(v&&!e.pack){let P=v.get(p);P?P.count++:v.set(p,{count:1})}}let S=p.length;if(N&&S>=4&&S<1024){if((N.size+=S)>Bi){let P,I=(N[0]?N[0].length*3+N[1].length:0)+10;l+I>ce&&(h=Pe(l+I)),h[l++]=217,h[l++]=223,h[l++]=249,h[l++]=N.position?132:130,h[l++]=26,P=l-n,l+=4,N.position&&$n(n,M),N=["",""],N.size=0,N.position=P}let R=Fi.test(p);N[R?0:1]+=p,h[l++]=R?206:207,M(S);return}let x;S<32?x=1:S<256?x=2:S<65536?x=3:x=5;let T=S*3;if(l+T>ce&&(h=Pe(l+T)),S<64||!f){let R,P,I,A=l+x;for(R=0;R>6|192,h[A++]=P&63|128):(P&64512)===55296&&((I=p.charCodeAt(R+1))&64512)===56320?(P=65536+((P&1023)<<10)+(I&1023),R++,h[A++]=P>>18|240,h[A++]=P>>12&63|128,h[A++]=P>>6&63|128,h[A++]=P&63|128):(h[A++]=P>>12|224,h[A++]=P>>6&63|128,h[A++]=P&63|128);_=A-l-x}else _=f(p,l+x,T);_<24?h[l++]=96|_:_<256?(x<2&&h.copyWithin(l+2,l+1,l+1+_),h[l++]=120,h[l++]=_):_<65536?(x<3&&h.copyWithin(l+3,l+2,l+2+_),h[l++]=121,h[l++]=_>>8,h[l++]=_&255):(x<5&&h.copyWithin(l+5,l+3,l+3+_),h[l++]=122,O.setUint32(l,_),l+=4),l+=_}else if(C==="number")if(!this.alwaysUseFloat&&p>>>0===p)p<24?h[l++]=p:p<256?(h[l++]=24,h[l++]=p):p<65536?(h[l++]=25,h[l++]=p>>8,h[l++]=p&255):(h[l++]=26,O.setUint32(l,p),l+=4);else if(!this.alwaysUseFloat&&p>>0===p)p>=-24?h[l++]=31-p:p>=-256?(h[l++]=56,h[l++]=~p):p>=-65536?(h[l++]=57,O.setUint16(l,~p),l+=2):(h[l++]=58,O.setUint32(l,~p),l+=4);else{let S;if((S=this.useFloat32)>0&&p<4294967296&&p>=-2147483648){h[l++]=250,O.setFloat32(l,p);let x;if(S<4||(x=p*gt[(h[l]&127)<<1|h[l+1]>>7])>>0===x){l+=4;return}else l--}h[l++]=251,O.setFloat64(l,p),l+=8}else if(C==="object")if(!p)h[l++]=246;else{if(a){let x=a.get(p);if(x){if(h[l++]=216,h[l++]=29,h[l++]=25,!x.references){let T=a.idsToInsert||(a.idsToInsert=[]);x.references=[],T.push(x)}x.references.push(l-n),l+=2;return}else a.set(p,{offset:l-n})}let S=p.constructor;if(S===Object)zt(p,!0);else if(S===Array){_=p.length,_<24?h[l++]=128|_:re(_);for(let x=0;x<_;x++)M(p[x])}else if(S===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(h[l++]=217,h[l++]=1,h[l++]=3),_=p.size,_<24?h[l++]=160|_:_<256?(h[l++]=184,h[l++]=_):_<65536?(h[l++]=185,h[l++]=_>>8,h[l++]=_&255):(h[l++]=186,O.setUint32(l,_),l+=4),c.keyMap)for(let[x,T]of p)M(c.encodeKey(x)),M(T);else for(let[x,T]of p)M(x),M(T);else{for(let x=0,T=Br.length;x>8,h[l++]=I&255):I>-1&&(h[l++]=218,O.setUint32(l,I),l+=4),P.encode.call(this,p,M,Pe);return}}if(p[Symbol.iterator]){if(Ur){let x=new Error("Iterable should be serialized as iterator");throw x.iteratorNotHandled=!0,x}h[l++]=159;for(let x of p)M(x);h[l++]=255;return}if(p[Symbol.asyncIterator]||Or(p)){let x=new Error("Iterable/blob should be serialized as iterator");throw x.iteratorNotHandled=!0,x}if(this.useToJSON&&p.toJSON){let x=p.toJSON();if(x!==p)return M(x)}zt(p,!p.hasOwnProperty)}}else if(C==="boolean")h[l++]=p?245:244;else if(C==="bigint"){if(p=0)h[l++]=27,O.setBigUint64(l,p);else if(p>-(BigInt(1)<{let C=Object.keys(p),_=Object.values(p),S=C.length;S<24?h[l++]=160|S:S<256?(h[l++]=184,h[l++]=S):S<65536?(h[l++]=185,h[l++]=S>>8,h[l++]=S&255):(h[l++]=186,O.setUint32(l,S),l+=4);let x;if(c.keyMap)for(let T=0;T{h[l++]=185;let _=l-n;l+=2;let S=0;if(c.keyMap)for(let x in p)(C||p.hasOwnProperty(x))&&(M(c.encodeKey(x)),M(p[x]),S++);else for(let x in p)(C||p.hasOwnProperty(x))&&(M(x),M(p[x]),S++);h[_+++n]=S>>8,h[_+n]=S&255}:(p,C)=>{let _,S=o.transitions||(o.transitions=Object.create(null)),x=0,T=0,R,P;if(this.keyMap){P=Object.keys(p).map(A=>this.encodeKey(A)),T=P.length;for(let A=0;A>8|224,h[l++]=I&255;else if(P||(P=S.__keys__||(S.__keys__=Object.keys(p))),R===void 0?(I=o.nextId++,I||(I=0,o.nextId=1),I>=zn&&(o.nextId=(I=d)+1)):I=R,o[I]=P,I>8|224,h[l++]=I&255,S=o.transitions;for(let A=0;A=zn-d&&(se.shift()[W]=void 0),se.push(S),re(T+2),M(57344+I),M(P),C===null)return;for(let A in p)(C||p.hasOwnProperty(A))&&M(p[A]);return}if(T<24?h[l++]=128|T:re(T),C!==null)for(let A in p)(C||p.hasOwnProperty(A))&&M(p[A])},Pe=p=>{let C;if(p>16777216){if(p-n>Nn)throw new Error("Encoded buffer would be larger than maximum buffer size");C=Math.min(Nn,Math.round(Math.max((p-n)*(p>67108864?1.25:2),4194304)/4096)*4096)}else C=(Math.max(p-n<<2,h.length-1)>>12)+1<<12;let _=new Mr(C);return O=new DataView(_.buffer,0,C),h.copy?h.copy(_,0,n,p):_.set(h.slice(n,p)),l-=n,n=0,ce=_.length-10,h=_},fe=100,ln=1e3;this.encodeAsIterable=function(p,C){return un(p,C,xe)},this.encodeAsAsyncIterable=function(p,C){return un(p,C,hn)};function*xe(p,C,_){let S=p.constructor;if(S===Object){let x=c.useRecords!==!1;x?zt(p,null):jn(Object.keys(p).length,160);for(let T in p){let R=p[T];x||M(T),R&&typeof R=="object"?C[T]?yield*xe(R,C[T]):yield*Nt(R,C,T):M(R)}}else if(S===Array){let x=p.length;re(x);for(let T=0;Tfe)?C.element?yield*xe(R,C.element):yield*Nt(R,C,"element"):M(R)}}else if(p[Symbol.iterator]){h[l++]=159;for(let x of p)x&&(typeof x=="object"||l-n>fe)?C.element?yield*xe(x,C.element):yield*Nt(x,C,"element"):M(x);h[l++]=255}else Or(p)?(jn(p.size,64),yield h.subarray(n,l),yield p,Ie()):p[Symbol.asyncIterator]?(h[l++]=159,yield h.subarray(n,l),yield p,Ie(),h[l++]=255):M(p);_&&l>n?yield h.subarray(n,l):l-n>fe&&(yield h.subarray(n,l),Ie())}function*Nt(p,C,_){let S=l-n;try{M(p),l-n>fe&&(yield h.subarray(n,l),Ie())}catch(x){if(x.iteratorNotHandled)C[_]={},l=n+S,yield*xe.call(this,p,C[_]);else throw x}}function Ie(){fe=ln,c.encode(null,Lr)}function un(p,C,_){return C&&C.chunkThreshold?fe=ln=C.chunkThreshold:fe=100,p&&typeof p=="object"?(c.encode(null,Lr),_(p,c.iterateProperties||(c.iterateProperties={}),!0)):[c.encode(p)]}async function*hn(p,C){for(let _ of xe(p,C,!0)){let S=_.constructor;if(S===Fn||S===Uint8Array)yield _;else if(Or(_)){let x=_.stream().getReader(),T;for(;!(T=await x.read()).done;)yield T.value}else if(_[Symbol.asyncIterator])for await(let x of _)Ie(),x?yield*hn(x,C.async||(C.async={})):yield c.encode(x);else yield _}}}useBuffer(e){h=e,O=new DataView(h.buffer,h.byteOffset,h.byteLength),l=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let e=this.sharedVersion||0;this.sharedVersion=e+1;let r=this.structures.slice(0),n=new St(r,this.sharedValues,this.sharedVersion),i=this.saveShared(n,s=>(s&&s.version||0)==e);return i===!1?(n=this.getShared()||{},this.structures=n.structures||[],this.sharedValues=n.packedValues,this.sharedVersion=n.version,this.structures.nextId=this.structures.length):r.forEach((s,o)=>this.structures[o]=s),i}};function jn(t,e){t<24?h[l++]=e|t:t<256?(h[l++]=e|24,h[l++]=t):t<65536?(h[l++]=e|25,h[l++]=t>>8,h[l++]=t&255):(h[l++]=e|26,O.setUint32(l,t),l+=4)}var St=class{constructor(e,r,n){this.structures=e,this.packedValues=r,this.version=n}};function re(t){t<24?h[l++]=128|t:t<256?(h[l++]=152,h[l++]=t):t<65536?(h[l++]=153,h[l++]=t>>8,h[l++]=t&255):(h[l++]=154,O.setUint32(l,t),l+=4)}var zi=typeof Blob>"u"?function(){}:Blob;function Or(t){if(t instanceof zi)return!0;let e=t[Symbol.toStringTag];return e==="Blob"||e==="File"}function vt(t,e){switch(typeof t){case"string":if(t.length>3){if(e.objectMap[t]>-1||e.values.length>=e.maxValues)return;let n=e.get(t);if(n)++n.count==2&&e.values.push(t);else if(e.set(t,{count:1}),e.samplingPackedValues){let i=e.samplingPackedValues.get(t);i?i.count++:e.samplingPackedValues.set(t,{count:1})}}break;case"object":if(t)if(t instanceof Array)for(let n=0,i=t.length;n"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,St];Br=[{tag:1,encode(t,e){let r=t.getTime()/1e3;(this.useTimestamp32||t.getMilliseconds()===0)&&r>=0&&r<4294967296?(h[l++]=26,O.setUint32(l,r),l+=4):(h[l++]=251,O.setFloat64(l,r),l+=8)}},{tag:258,encode(t,e){let r=Array.from(t);e(r)}},{tag:27,encode(t,e){e([t.name,t.message])}},{tag:27,encode(t,e){e(["RegExp",t.source,t.flags])}},{getTag(t){return t.tag},encode(t,e){e(t.value)}},{encode(t,e,r){Vn(t,r)}},{getTag(t){if(t.constructor===Uint8Array&&(this.tagUint8Array||Ne&&this.tagUint8Array!==!1))return 64},encode(t,e,r){Vn(t,r)}},te(68,1),te(69,2),te(70,4),te(71,8),te(72,1),te(77,2),te(78,4),te(79,8),te(85,4),te(86,8),{encode(t,e){let r=t.packedValues||[],n=t.structures||[];if(r.values.length>0){h[l++]=216,h[l++]=51,re(4);let i=r.values;e(i),re(0),re(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let s=0,o=i.length;s1&&(t-=4),{tag:t,encode:function(n,i){let s=n.byteLength,o=n.byteOffset||0,a=n.buffer||n;i(Ne?Ct.from(a,o,s):new Uint8Array(a,o,s))}}}function Vn(t,e){let r=t.byteLength;r<24?h[l++]=64+r:r<256?(h[l++]=88,h[l++]=r):r<65536?(h[l++]=89,h[l++]=r>>8,h[l++]=r&255):(h[l++]=90,O.setUint32(l,r),l+=4),l+r>=h.length&&e(l+r),h.set(t.buffer?t:new Uint8Array(t),l),l+=r}function ji(t,e){let r,n=e.length*2,i=t.length-n;e.sort((s,o)=>s.offset>o.offset?1:-1);for(let s=0;s>8,t[a]=s&255}for(;r=e.pop();){let s=r.offset;t.copyWithin(s+n,s,i),n-=2;let o=s+n;t[o++]=216,t[o++]=28,i=s}return t}function $n(t,e){O.setUint32(N.position+t,l-N.position-t+1);let r=N;N=null,e(r[0]),e(r[1])}var zr=new de({useRecords:!1}),Vi=zr.encode,$i=zr.encodeAsIterable,Gi=zr.encodeAsAsyncIterable,{NEVER:Ki,ALWAYS:Ji,DECIMAL_ROUND:Hi,DECIMAL_FIT:Wi}=xt,Fr=512,Yi=1024,Lr=2048;var ae=4294967295;function Kn(t,e,r){var n=r/4294967296,i=r;t.setUint32(e,n),t.setUint32(e+4,i)}function bt(t,e,r){var n=Math.floor(r/4294967296),i=r;t.setUint32(e,n),t.setUint32(e+4,i)}function kt(t,e){var r=t.getInt32(e),n=t.getUint32(e+4);return r*4294967296+n}function Jn(t,e){var r=t.getUint32(e),n=t.getUint32(e+4);return r*4294967296+n}var Nr,jr,Vr,Tt=(typeof __Process$>"u"||((Nr=__Process$?.env)===null||Nr===void 0?void 0:Nr.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function $r(t){for(var e=t.length,r=0,n=0;n=55296&&i<=56319&&n>6&31|192;else{if(o>=55296&&o<=56319&&s>18&7|240,e[i++]=o>>12&63|128,e[i++]=o>>6&63|128):(e[i++]=o>>12&15|224,e[i++]=o>>6&63|128)}else{e[i++]=o;continue}e[i++]=o&63|128}}var je=Tt?new TextEncoder:void 0,Wn=Tt?typeof __Process$<"u"&&((jr=__Process$?.env)===null||jr===void 0?void 0:jr.TEXT_ENCODING)!=="force"?200:0:ae;function Xi(t,e,r){e.set(je.encode(t),r)}function qi(t,e,r){je.encodeInto(t,e.subarray(r))}var Yn=je?.encodeInto?qi:Xi,Zi=4096;function Et(t,e,r){for(var n=e,i=n+r,s=[],o="";n65535&&(d-=65536,s.push(d>>>10&1023|55296),d=56320|d&1023),s.push(d)}else s.push(a);s.length>=Zi&&(o+=String.fromCharCode.apply(String,s),s.length=0)}return s.length>0&&(o+=String.fromCharCode.apply(String,s)),o}var Qi=Tt?new TextDecoder:null,Xn=Tt?typeof __Process$<"u"&&((Vr=__Process$?.env)===null||Vr===void 0?void 0:Vr.TEXT_DECODER)!=="force"?200:0:ae;function qn(t,e,r){var n=t.subarray(e,e+r);return Qi.decode(n)}var Ve=function(){function t(e,r){this.type=e,this.data=r}return t}();var es=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},t(e,r)};return function(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),X=function(t){es(e,t);function e(r){var n=t.call(this,r)||this,i=Object.create(e.prototype);return Object.setPrototypeOf(n,i),Object.defineProperty(n,"name",{configurable:!0,enumerable:!1,value:e.name}),n}return e}(Error);var ts=-1,rs=4294967296-1,ns=17179869184-1;function is(t){var e=t.sec,r=t.nsec;if(e>=0&&r>=0&&e<=ns)if(r===0&&e<=rs){var n=new Uint8Array(4),i=new DataView(n.buffer);return i.setUint32(0,e),n}else{var s=e/4294967296,o=e&4294967295,n=new Uint8Array(8),i=new DataView(n.buffer);return i.setUint32(0,r<<2|s&3),i.setUint32(4,o),n}else{var n=new Uint8Array(12),i=new DataView(n.buffer);return i.setUint32(0,r),bt(i,4,e),n}}function ss(t){var e=t.getTime(),r=Math.floor(e/1e3),n=(e-r*1e3)*1e6,i=Math.floor(n/1e9);return{sec:r+i,nsec:n-i*1e9}}function os(t){if(t instanceof Date){var e=ss(t);return is(e)}else return null}function as(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:{var r=e.getUint32(0),n=0;return{sec:r,nsec:n}}case 8:{var i=e.getUint32(0),s=e.getUint32(4),r=(i&3)*4294967296+s,n=i>>>2;return{sec:r,nsec:n}}case 12:{var r=kt(e,4),n=e.getUint32(0);return{sec:r,nsec:n}}default:throw new X("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(t.length))}}function cs(t){var e=as(t);return new Date(e.sec*1e3+e.nsec/1e6)}var Zn={type:ts,encode:os,decode:cs};var Rt=function(){function t(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Zn)}return t.prototype.register=function(e){var r=e.type,n=e.encode,i=e.decode;if(r>=0)this.encoders[r]=n,this.decoders[r]=i;else{var s=1+r;this.builtInEncoders[s]=n,this.builtInDecoders[s]=i}},t.prototype.tryToEncode=function(e,r){for(var n=0;nthis.maxDepth)throw new Error("Too deep objects in depth ".concat(r));e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.encodeObject(e,r)},t.prototype.ensureBufferSizeToWrite=function(e){var r=this.pos+e;this.view.byteLength=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):(this.writeU8(211),this.writeI64(e)):this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))},t.prototype.writeStringHeader=function(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error("Too long string: ".concat(e," bytes in UTF-8"))},t.prototype.encodeString=function(e){var r=5,n=e.length;if(n>Wn){var i=$r(e);this.ensureBufferSizeToWrite(r+i),this.writeStringHeader(i),Yn(e,this.bytes,this.pos),this.pos+=i}else{var i=$r(e);this.ensureBufferSizeToWrite(r+i),this.writeStringHeader(i),Hn(e,this.bytes,this.pos),this.pos+=i}},t.prototype.encodeObject=function(e,r){var n=this.extensionCodec.tryToEncode(e,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(e))this.encodeArray(e,r);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,r);else throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(e)))},t.prototype.encodeBinary=function(e){var r=e.byteLength;if(r<256)this.writeU8(196),this.writeU8(r);else if(r<65536)this.writeU8(197),this.writeU16(r);else if(r<4294967296)this.writeU8(198),this.writeU32(r);else throw new Error("Too large binary: ".concat(r));var n=ke(e);this.writeU8a(n)},t.prototype.encodeArray=function(e,r){var n=e.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw new Error("Too large array: ".concat(n));for(var i=0,s=e;i0&&e<=this.maxKeyLength},t.prototype.find=function(e,r,n){var i=this.caches[n-1];e:for(var s=0,o=i;s=this.maxLengthPerKey?n[Math.random()*n.length|0]=i:n.push(i)},t.prototype.decode=function(e,r,n){var i=this.find(e,r,n);if(i!=null)return this.hit++,i;this.miss++;var s=Et(e,r,n),o=Uint8Array.prototype.slice.call(e,r,r+n);return this.store(o,s),s},t}();var ds=function(t,e,r,n){function i(s){return s instanceof r?s:new r(function(o){o(s)})}return new(r||(r=Promise))(function(s,o){function a(u){try{c(n.next(u))}catch(d){o(d)}}function f(u){try{c(n.throw(u))}catch(d){o(d)}}function c(u){u.done?s(u.value):i(u.value).then(a,f)}c((n=n.apply(t,e||[])).next())})},Kr=function(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(u){return f([c,u])}}function f(c){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(s=c[0]&2?i.return:c[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,c[1])).done)return s;switch(i=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return r.label++,{value:c[1],done:!1};case 5:r.label++,i=c[1],c=[0];continue;case 7:c=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]1||a(y,v)})})}function a(y,v){try{f(n[y](v))}catch(E){d(s[0][3],E)}}function f(y){y.value instanceof Te?Promise.resolve(y.value.v).then(c,u):d(s[0][2],y)}function c(y){a("next",y)}function u(y){a("throw",y)}function d(y,v){y(v),s.shift(),s.length&&a(s[0][0],s[0][1])}},ms=function(t){var e=typeof t;return e==="string"||e==="number"},$e=-1,Hr=new DataView(new ArrayBuffer(0)),ys=new Uint8Array(Hr.buffer),Jr=function(){try{Hr.getInt8(0)}catch(t){return t.constructor}throw new Error("never reached")}(),ri=new Jr("Insufficient data"),gs=new ei,ni=function(){function t(e,r,n,i,s,o,a,f){e===void 0&&(e=Rt.defaultCodec),r===void 0&&(r=void 0),n===void 0&&(n=ae),i===void 0&&(i=ae),s===void 0&&(s=ae),o===void 0&&(o=ae),a===void 0&&(a=ae),f===void 0&&(f=gs),this.extensionCodec=e,this.context=r,this.maxStrLength=n,this.maxBinLength=i,this.maxArrayLength=s,this.maxMapLength=o,this.maxExtLength=a,this.keyDecoder=f,this.totalPos=0,this.pos=0,this.view=Hr,this.bytes=ys,this.headByte=$e,this.stack=[]}return t.prototype.reinitializeState=function(){this.totalPos=0,this.headByte=$e,this.stack.length=0},t.prototype.setBuffer=function(e){this.bytes=ke(e),this.view=Qn(this.bytes),this.pos=0},t.prototype.appendBuffer=function(e){if(this.headByte===$e&&!this.hasRemaining(1))this.setBuffer(e);else{var r=this.bytes.subarray(this.pos),n=ke(e),i=new Uint8Array(r.length+n.length);i.set(r),i.set(n,r.length),this.setBuffer(i)}},t.prototype.hasRemaining=function(e){return this.view.byteLength-this.pos>=e},t.prototype.createExtraByteError=function(e){var r=this,n=r.view,i=r.pos;return new RangeError("Extra ".concat(n.byteLength-i," of ").concat(n.byteLength," byte(s) found at buffer[").concat(e,"]"))},t.prototype.decode=function(e){this.reinitializeState(),this.setBuffer(e);var r=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return r},t.prototype.decodeMulti=function(e){return Kr(this,function(r){switch(r.label){case 0:this.reinitializeState(),this.setBuffer(e),r.label=1;case 1:return this.hasRemaining(1)?[4,this.doDecodeSync()]:[3,3];case 2:return r.sent(),[3,1];case 3:return[2]}})},t.prototype.decodeAsync=function(e){var r,n,i,s;return ds(this,void 0,void 0,function(){var o,a,f,c,u,d,y,v;return Kr(this,function(E){switch(E.label){case 0:o=!1,E.label=1;case 1:E.trys.push([1,6,7,12]),r=ti(e),E.label=2;case 2:return[4,r.next()];case 3:if(n=E.sent(),!!n.done)return[3,5];if(f=n.value,o)throw this.createExtraByteError(this.totalPos);this.appendBuffer(f);try{a=this.doDecodeSync(),o=!0}catch(U){if(!(U instanceof Jr))throw U}this.totalPos+=this.pos,E.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=E.sent(),i={error:c},[3,12];case 7:return E.trys.push([7,,10,11]),n&&!n.done&&(s=r.return)?[4,s.call(r)]:[3,9];case 8:E.sent(),E.label=9;case 9:return[3,11];case 10:if(i)throw i.error;return[7];case 11:return[7];case 12:if(o){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return[2,a]}throw u=this,d=u.headByte,y=u.pos,v=u.totalPos,new RangeError("Insufficient data in parsing ".concat(Pt(d)," at ").concat(v," (").concat(y," in the current buffer)"))}})})},t.prototype.decodeArrayStream=function(e){return this.decodeMultiAsync(e,!0)},t.prototype.decodeStream=function(e){return this.decodeMultiAsync(e,!1)},t.prototype.decodeMultiAsync=function(e,r){return ps(this,arguments,function(){var i,s,o,a,f,c,u,d,y;return Kr(this,function(v){switch(v.label){case 0:i=r,s=-1,v.label=1;case 1:v.trys.push([1,13,14,19]),o=ti(e),v.label=2;case 2:return[4,Te(o.next())];case 3:if(a=v.sent(),!!a.done)return[3,12];if(f=a.value,r&&s===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(f),i&&(s=this.readArraySize(),i=!1,this.complete()),v.label=4;case 4:v.trys.push([4,9,,10]),v.label=5;case 5:return[4,Te(this.doDecodeSync())];case 6:return[4,v.sent()];case 7:return v.sent(),--s===0?[3,8]:[3,5];case 8:return[3,10];case 9:if(c=v.sent(),!(c instanceof Jr))throw c;return[3,10];case 10:this.totalPos+=this.pos,v.label=11;case 11:return[3,2];case 12:return[3,19];case 13:return u=v.sent(),d={error:u},[3,19];case 14:return v.trys.push([14,,17,18]),a&&!a.done&&(y=o.return)?[4,Te(y.call(o))]:[3,16];case 15:v.sent(),v.label=16;case 16:return[3,18];case 17:if(d)throw d.error;return[7];case 18:return[7];case 19:return[2]}})})},t.prototype.doDecodeSync=function(){e:for(;;){var e=this.readHeadByte(),r=void 0;if(e>=224)r=e-256;else if(e<192)if(e<128)r=e;else if(e<144){var n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else r={}}else if(e<160){var n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else r=[]}else{var i=e-160;r=this.decodeUtf8String(i,0)}else if(e===192)r=null;else if(e===194)r=!1;else if(e===195)r=!0;else if(e===202)r=this.readF32();else if(e===203)r=this.readF64();else if(e===204)r=this.readU8();else if(e===205)r=this.readU16();else if(e===206)r=this.readU32();else if(e===207)r=this.readU64();else if(e===208)r=this.readI8();else if(e===209)r=this.readI16();else if(e===210)r=this.readI32();else if(e===211)r=this.readI64();else if(e===217){var i=this.lookU8();r=this.decodeUtf8String(i,1)}else if(e===218){var i=this.lookU16();r=this.decodeUtf8String(i,2)}else if(e===219){var i=this.lookU32();r=this.decodeUtf8String(i,4)}else if(e===220){var n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else r=[]}else if(e===221){var n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else r=[]}else if(e===222){var n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else r={}}else if(e===223){var n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else r={}}else if(e===196){var n=this.lookU8();r=this.decodeBinary(n,1)}else if(e===197){var n=this.lookU16();r=this.decodeBinary(n,2)}else if(e===198){var n=this.lookU32();r=this.decodeBinary(n,4)}else if(e===212)r=this.decodeExtension(1,0);else if(e===213)r=this.decodeExtension(2,0);else if(e===214)r=this.decodeExtension(4,0);else if(e===215)r=this.decodeExtension(8,0);else if(e===216)r=this.decodeExtension(16,0);else if(e===199){var n=this.lookU8();r=this.decodeExtension(n,1)}else if(e===200){var n=this.lookU16();r=this.decodeExtension(n,2)}else if(e===201){var n=this.lookU32();r=this.decodeExtension(n,4)}else throw new X("Unrecognized type byte: ".concat(Pt(e)));this.complete();for(var s=this.stack;s.length>0;){var o=s[s.length-1];if(o.type===0)if(o.array[o.position]=r,o.position++,o.position===o.size)s.pop(),r=o.array;else continue e;else if(o.type===1){if(!ms(r))throw new X("The type of key must be string or number but "+typeof r);if(r==="__proto__")throw new X("The key __proto__ is not allowed");o.key=r,o.type=2;continue e}else if(o.map[o.key]=r,o.readCount++,o.readCount===o.size)s.pop(),r=o.map;else{o.key=null,o.type=1;continue e}}return r}},t.prototype.readHeadByte=function(){return this.headByte===$e&&(this.headByte=this.readU8()),this.headByte},t.prototype.complete=function(){this.headByte=$e},t.prototype.readArraySize=function(){var e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new X("Unrecognized array type byte: ".concat(Pt(e)))}}},t.prototype.pushMapState=function(e){if(e>this.maxMapLength)throw new X("Max length exceeded: map length (".concat(e,") > maxMapLengthLength (").concat(this.maxMapLength,")"));this.stack.push({type:1,size:e,key:null,readCount:0,map:{}})},t.prototype.pushArrayState=function(e){if(e>this.maxArrayLength)throw new X("Max length exceeded: array length (".concat(e,") > maxArrayLength (").concat(this.maxArrayLength,")"));this.stack.push({type:0,size:e,array:new Array(e),position:0})},t.prototype.decodeUtf8String=function(e,r){var n;if(e>this.maxStrLength)throw new X("Max length exceeded: UTF-8 byte length (".concat(e,") > maxStrLength (").concat(this.maxStrLength,")"));if(this.bytes.byteLengthXn?s=qn(this.bytes,i,e):s=Et(this.bytes,i,e),this.pos+=r+e,s},t.prototype.stateIsMapKey=function(){if(this.stack.length>0){var e=this.stack[this.stack.length-1];return e.type===1}return!1},t.prototype.decodeBinary=function(e,r){if(e>this.maxBinLength)throw new X("Max length exceeded: bin length (".concat(e,") > maxBinLength (").concat(this.maxBinLength,")"));if(!this.hasRemaining(e+r))throw ri;var n=this.pos+r,i=this.bytes.subarray(n,n+e);return this.pos+=r+e,i},t.prototype.decodeExtension=function(e,r){if(e>this.maxExtLength)throw new X("Max length exceeded: ext length (".concat(e,") > maxExtLength (").concat(this.maxExtLength,")"));var n=this.view.getInt8(this.pos+r),i=this.decodeBinary(e,r+1);return this.extensionCodec.decode(i,n,this.context)},t.prototype.lookU8=function(){return this.view.getUint8(this.pos)},t.prototype.lookU16=function(){return this.view.getUint16(this.pos)},t.prototype.lookU32=function(){return this.view.getUint32(this.pos)},t.prototype.readU8=function(){var e=this.view.getUint8(this.pos);return this.pos++,e},t.prototype.readI8=function(){var e=this.view.getInt8(this.pos);return this.pos++,e},t.prototype.readU16=function(){var e=this.view.getUint16(this.pos);return this.pos+=2,e},t.prototype.readI16=function(){var e=this.view.getInt16(this.pos);return this.pos+=2,e},t.prototype.readU32=function(){var e=this.view.getUint32(this.pos);return this.pos+=4,e},t.prototype.readI32=function(){var e=this.view.getInt32(this.pos);return this.pos+=4,e},t.prototype.readU64=function(){var e=Jn(this.view,this.pos);return this.pos+=8,e},t.prototype.readI64=function(){var e=kt(this.view,this.pos);return this.pos+=8,e},t.prototype.readF32=function(){var e=this.view.getFloat32(this.pos);return this.pos+=4,e},t.prototype.readF64=function(){var e=this.view.getFloat64(this.pos);return this.pos+=8,e},t}();var ii={};var xs=function(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(u){return f([c,u])}}function f(c){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(s=c[0]&2?i.return:c[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,c[1])).done)return s;switch(i=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return r.label++,{value:c[1],done:!1};case 5:r.label++,i=c[1],c=[0];continue;case 7:c=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]1||a(y,v)})})}function a(y,v){try{f(n[y](v))}catch(E){d(s[0][3],E)}}function f(y){y.value instanceof Ee?Promise.resolve(y.value.v).then(c,u):d(s[0][2],y)}function c(y){a("next",y)}function u(y){a("throw",y)}function d(y,v){y(v),s.shift(),s.length&&a(s[0][0],s[0][1])}};function vs(t){return t[Symbol.asyncIterator]!=null}function Ss(t){if(t==null)throw new Error("Assertion Failure: value must not be null nor undefined")}function Cs(t){return _s(this,arguments,function(){var r,n,i,s;return xs(this,function(o){switch(o.label){case 0:r=t.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,Ee(r.read())];case 3:return n=o.sent(),i=n.done,s=n.value,i?[4,Ee(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return Ss(s),[4,Ee(s)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function si(t){return vs(t)?t:Cs(t)}function Wr(t,e){e===void 0&&(e=ii);var r=si(t),n=new ni(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength);return n.decodeStream(r)}function ye(t,e,r,n){Object.defineProperty(t,e,{get:r,set:n,enumerable:!0,configurable:!0})}var wt=class{constructor(){this.chunkedMTU=16300,this._dataCount=1,this.chunk=e=>{let r=[],n=e.byteLength,i=Math.ceil(n/this.chunkedMTU),s=0,o=0;for(;o=this.minChromeVersion:t==="firefox"?e>=this.minFirefoxVersion:t==="safari"?!this.isIOS&&e>=this.minSafariVersion:!1:!1}getBrowser(){return Yr.browserDetails.browser}getVersion(){return Yr.browserDetails.version||0}isUnifiedPlanSupported(){let t=this.getBrowser(),e=Yr.browserDetails.version||0;if(t==="chrome"&&e=this.minFirefoxVersion)return!0;if(!window.RTCRtpTransceiver||!("currentDirection"in RTCRtpTransceiver.prototype))return!1;let r,n=!1;try{r=new RTCPeerConnection,r.addTransceiver("audio"),n=!0}catch{}finally{r&&r.close()}return n}toString(){return`Supports: + browser:${this.getBrowser()} + version:${this.getVersion()} + isIOS:${this.isIOS} + isWebRTCSupported:${this.isWebRTCSupported()} + isBrowserSupported:${this.isBrowserSupported()} + isUnifiedPlanSupported:${this.isUnifiedPlanSupported()}`}constructor(){this.isIOS=["iPad","iPhone","iPod"].includes(navigator.platform),this.supportedBrowsers=["firefox","chrome","safari"],this.minFirefoxVersion=59,this.minChromeVersion=72,this.minSafariVersion=605}},ks=t=>!t||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(t),li=()=>Math.random().toString(36).slice(2),oi={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},Xr=class extends wt{noop(){}blobToArrayBuffer(e,r){let n=new FileReader;return n.onload=function(i){i.target&&r(i.target.result)},n.readAsArrayBuffer(e),n}binaryStringToArrayBuffer(e){let r=new Uint8Array(e.length);for(let n=0;n=3&&this._print(3,...e)}warn(...e){this._logLevel>=2&&this._print(2,...e)}error(...e){this._logLevel>=1&&this._print(1,...e)}setLogFunction(e){this._print=e}_print(e,...r){let n=[Ts,...r];for(let i in n)n[i]instanceof Error&&(n[i]="("+n[i].name+") "+n[i].message);e>=3?console.log(...n):e>=2?console.warn("WARNING",...n):e>=1&&console.error("ERROR",...n)}constructor(){this._logLevel=0}},b=new qr,cn={},Es=Object.prototype.hasOwnProperty,K="~";function We(){}Object.create&&(We.prototype=Object.create(null),new We().__proto__||(K=!1));function Rs(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ui(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Rs(r,n||t,i),o=K?K+e:e;return t._events[o]?t._events[o].fn?t._events[o]=[t._events[o],s]:t._events[o].push(s):(t._events[o]=s,t._eventsCount++),t}function It(t,e){--t._eventsCount===0?t._events=new We:delete t._events[e]}function $(){this._events=new We,this._eventsCount=0}$.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Es.call(r,n)&&e.push(K?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};$.prototype.listeners=function(e){var r=K?K+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);iie);ye(ge,"PeerErrorType",()=>B);ye(ge,"BaseConnectionErrorType",()=>Ye);ye(ge,"DataConnectionErrorType",()=>Xe);ye(ge,"SerializationType",()=>Re);ye(ge,"SocketEventType",()=>ne);ye(ge,"ServerMessageType",()=>V);var ie;(function(t){t.Data="data",t.Media="media"})(ie||(ie={}));var B;(function(t){t.BrowserIncompatible="browser-incompatible",t.Disconnected="disconnected",t.InvalidID="invalid-id",t.InvalidKey="invalid-key",t.Network="network",t.PeerUnavailable="peer-unavailable",t.SslUnavailable="ssl-unavailable",t.ServerError="server-error",t.SocketError="socket-error",t.SocketClosed="socket-closed",t.UnavailableID="unavailable-id",t.WebRTC="webrtc"})(B||(B={}));var Ye;(function(t){t.NegotiationFailed="negotiation-failed",t.ConnectionClosed="connection-closed"})(Ye||(Ye={}));var Xe;(function(t){t.NotOpenYet="not-open-yet",t.MessageToBig="message-too-big"})(Xe||(Xe={}));var Re;(function(t){t.Binary="binary",t.BinaryUTF8="binary-utf8",t.JSON="json",t.None="raw"})(Re||(Re={}));var ne;(function(t){t.Message="message",t.Disconnected="disconnected",t.Error="error",t.Close="close"})(ne||(ne={}));var V;(function(t){t.Heartbeat="HEARTBEAT",t.Candidate="CANDIDATE",t.Offer="OFFER",t.Answer="ANSWER",t.Open="OPEN",t.Error="ERROR",t.IdTaken="ID-TAKEN",t.InvalidKey="INVALID-KEY",t.Leave="LEAVE",t.Expire="EXPIRE"})(V||(V={}));var fn={};fn=JSON.parse('{"name":"peerjs","version":"1.5.2","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu ","afrokick ","ericz ","Jairo ","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana ","Carlos Caballero ","hc ","Muhammad Asif ","PrashoonB ","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski ","lmb ","Jairooo ","Moritz St\xFCckler ","Simon ","Denis Lukov ","Philipp Hancke ","Hans Oksendahl ","Jess ","khankuan ","DUODVK ","XiZhao ","Matthias Lohr ","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt ","Chris Cowan ","Alex Chuev ","alxnull ","Yemel Jardi ","Ben Parnell ","Benny Lichtner ","fresheneesz ","bob.barstead@exaptive.com ","chandika ","emersion ","Christopher Van ","eddieherm ","Eduardo Pinho ","Evandro Zanatta ","Gardner Bickford ","Gian Luca ","PatrickJS ","jonnyf ","Hizkia Felix ","Hristo Oskov ","Isaac Madwed ","Ilya Konanykhin ","jasonbarry ","Jonathan Burke ","Josh Hamit ","Jordan Austin ","Joel Wetzell ","xizhao ","Alberto Torres ","Jonathan Mayol ","Jefferson Felix ","Rolf Erik Lekang ","Kevin Mai-Husan Chia ","Pepijn de Vos ","JooYoung ","Tobias Speicher ","Steve Blaurock ","Kyrylo Shegeda ","Diwank Singh Tomer ","So\u0308ren Balko ","Arpit Solanki ","Yuki Ito ","Artur Zayats "],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","browser-minified-cbor":"dist/serializer.cbor.mjs","browser-minified-msgpack":"dist/serializer.msgpack.mjs","types":"dist/types.d.ts","engines":{"node":">= 14"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 80, safari >= 15"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 80, safari >= 15"},"source":"lib/global.ts"},"browser-minified-cbor":{"context":"browser","outputFormat":"esmodule","isLibrary":true,"optimize":true,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 102, safari >= 15"},"source":"lib/dataconnection/StreamConnection/Cbor.ts"},"browser-minified-msgpack":{"context":"browser","outputFormat":"esmodule","isLibrary":true,"optimize":true,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 102, safari >= 15"},"source":"lib/dataconnection/StreamConnection/MsgPack.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit && tsc -p e2e/tsconfig.json --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"jest","test:watch":"jest --watch","coverage":"jest --coverage --collectCoverageFrom=\\"./lib/**\\"","format":"prettier --write .","format:check":"prettier --check .","semantic-release":"semantic-release","e2e":"wdio run e2e/wdio.local.conf.ts","e2e:bstack":"wdio run e2e/wdio.bstack.conf.ts"},"devDependencies":{"@parcel/config-default":"^2.9.3","@parcel/packager-ts":"^2.9.3","@parcel/transformer-typescript-tsc":"^2.9.3","@parcel/transformer-typescript-types":"^2.9.3","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@swc/core":"^1.3.27","@swc/jest":"^0.2.24","@types/jasmine":"^4.3.4","@wdio/browserstack-service":"^8.11.2","@wdio/cli":"^8.11.2","@wdio/globals":"^8.11.2","@wdio/jasmine-framework":"^8.11.2","@wdio/local-runner":"^8.11.2","@wdio/spec-reporter":"^8.11.2","@wdio/types":"^8.10.4","http-server":"^14.1.1","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","mock-socket":"^9.0.0","parcel":"^2.9.3","prettier":"^3.0.0","semantic-release":"^21.0.0","ts-node":"^10.9.1","typescript":"^5.0.0","wdio-geckodriver-service":"^5.0.1"},"dependencies":{"@msgpack/msgpack":"^2.8.0","cbor-x":"1.5.4","eventemitter3":"^4.0.7","peerjs-js-binarypack":"^2.1.0","webrtc-adapter":"^8.0.0"},"alias":{"process":false,"buffer":false}}');var Zr=class extends cn.EventEmitter{constructor(e,r,n,i,s,o=5e3){super(),this.pingInterval=o,this._disconnected=!0,this._messagesQueue=[];let a=e?"wss://":"ws://";this._baseUrl=a+r+":"+n+i+"peerjs?key="+s}start(e,r){this._id=e;let n=`${this._baseUrl}&id=${e}&token=${r}`;this._socket||!this._disconnected||(this._socket=new WebSocket(n+"&version="+fn.version),this._disconnected=!1,this._socket.onmessage=i=>{let s;try{s=JSON.parse(i.data),b.log("Server message received:",s)}catch{b.log("Invalid server message",i.data);return}this.emit(ne.Message,s)},this._socket.onclose=i=>{this._disconnected||(b.log("Socket closed.",i),this._cleanup(),this._disconnected=!0,this.emit(ne.Disconnected))},this._socket.onopen=()=>{this._disconnected||(this._sendQueuedMessages(),b.log("Socket open"),this._scheduleHeartbeat())})}_scheduleHeartbeat(){this._wsPingTimer=setTimeout(()=>{this._sendHeartbeat()},this.pingInterval)}_sendHeartbeat(){if(!this._wsOpen()){b.log("Cannot send heartbeat, because socket closed");return}let e=JSON.stringify({type:V.Heartbeat});this._socket.send(e),this._scheduleHeartbeat()}_wsOpen(){return!!this._socket&&this._socket.readyState===1}_sendQueuedMessages(){let e=[...this._messagesQueue];this._messagesQueue=[];for(let r of e)this.send(r)}send(e){if(this._disconnected)return;if(!this._id){this._messagesQueue.push(e);return}if(!e.type){this.emit(ne.Error,"Invalid message");return}if(!this._wsOpen())return;let r=JSON.stringify(e);this._socket.send(r)}close(){this._disconnected||(this._cleanup(),this._disconnected=!0)}_cleanup(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)}},Dt=class{constructor(e){this.connection=e}startConnection(e){let r=this._startPeerConnection();if(this.connection.peerConnection=r,this.connection.type===ie.Media&&e._stream&&this._addTracksToConnection(e._stream,r),e.originator){let n=this.connection,i={ordered:!!e.reliable},s=r.createDataChannel(n.label,i);n._initializeDataChannel(s),this._makeOffer()}else this.handleSDP("OFFER",e.sdp)}_startPeerConnection(){b.log("Creating RTCPeerConnection.");let e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e}_setupListeners(e){let r=this.connection.peer,n=this.connection.connectionId,i=this.connection.type,s=this.connection.provider;b.log("Listening for ICE candidates."),e.onicecandidate=o=>{!o.candidate||!o.candidate.candidate||(b.log(`Received ICE candidates for ${r}:`,o.candidate),s.socket.send({type:V.Candidate,payload:{candidate:o.candidate,type:i,connectionId:n},dst:r}))},e.oniceconnectionstatechange=()=>{switch(e.iceConnectionState){case"failed":b.log("iceConnectionState is failed, closing connections to "+r),this.connection.emitError(Ye.NegotiationFailed,"Negotiation of connection to "+r+" failed."),this.connection.close();break;case"closed":b.log("iceConnectionState is closed, closing connections to "+r),this.connection.emitError(Ye.ConnectionClosed,"Connection to "+r+" closed."),this.connection.close();break;case"disconnected":b.log("iceConnectionState changed to disconnected on the connection with "+r);break;case"completed":e.onicecandidate=()=>{};break}this.connection.emit("iceStateChanged",e.iceConnectionState)},b.log("Listening for data channel"),e.ondatachannel=o=>{b.log("Received data channel");let a=o.channel;s.getConnection(r,n)._initializeDataChannel(a)},b.log("Listening for remote stream"),e.ontrack=o=>{b.log("Received remote stream");let a=o.streams[0],f=s.getConnection(r,n);if(f.type===ie.Media){let c=f;this._addStreamToMediaConnection(a,c)}}}cleanup(){b.log("Cleaning up PeerConnection to "+this.connection.peer);let e=this.connection.peerConnection;if(!e)return;this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=()=>{};let r=e.signalingState!=="closed",n=!1,i=this.connection.dataChannel;i&&(n=!!i.readyState&&i.readyState!=="closed"),(r||n)&&e.close()}async _makeOffer(){let e=this.connection.peerConnection,r=this.connection.provider;try{let n=await e.createOffer(this.connection.options.constraints);b.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp);try{await e.setLocalDescription(n),b.log("Set localDescription:",n,`for:${this.connection.peer}`);let i={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata};if(this.connection.type===ie.Data){let s=this.connection;i={...i,label:s.label,reliable:s.reliable,serialization:s.serialization}}r.socket.send({type:V.Offer,payload:i,dst:this.connection.peer})}catch(i){i!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(r.emitError(B.WebRTC,i),b.log("Failed to setLocalDescription, ",i))}}catch(n){r.emitError(B.WebRTC,n),b.log("Failed to createOffer, ",n)}}async _makeAnswer(){let e=this.connection.peerConnection,r=this.connection.provider;try{let n=await e.createAnswer();b.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp);try{await e.setLocalDescription(n),b.log("Set localDescription:",n,`for:${this.connection.peer}`),r.socket.send({type:V.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId},dst:this.connection.peer})}catch(i){r.emitError(B.WebRTC,i),b.log("Failed to setLocalDescription, ",i)}}catch(n){r.emitError(B.WebRTC,n),b.log("Failed to create answer, ",n)}}async handleSDP(e,r){r=new RTCSessionDescription(r);let n=this.connection.peerConnection,i=this.connection.provider;b.log("Setting remote description",r);let s=this;try{await n.setRemoteDescription(r),b.log(`Set remoteDescription:${e} for:${this.connection.peer}`),e==="OFFER"&&await s._makeAnswer()}catch(o){i.emitError(B.WebRTC,o),b.log("Failed to setRemoteDescription, ",o)}}async handleCandidate(e){b.log("handleCandidate:",e);try{await this.connection.peerConnection.addIceCandidate(e),b.log(`Added ICE candidate for:${this.connection.peer}`)}catch(r){this.connection.provider.emitError(B.WebRTC,r),b.log("Failed to handleCandidate, ",r)}}_addTracksToConnection(e,r){if(b.log(`add tracks from stream ${e.id} to peer connection`),!r.addTrack)return b.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(n=>{r.addTrack(n,e)})}_addStreamToMediaConnection(e,r){b.log(`add stream ${e.id} to media connection ${r.connectionId}`),r.addStream(e)}},At=class extends cn.EventEmitter{emitError(e,r){b.error("Error:",r),this.emit("error",new Qr(`${e}`,r))}},Qr=class extends Error{constructor(e,r){typeof r=="string"?super(r):(super(),Object.assign(this,r)),this.type=e}},Mt=class extends At{get open(){return this._open}constructor(e,r,n){super(),this.peer=e,this.provider=r,this.options=n,this._open=!1,this.metadata=n.metadata}},nn,Je=class Je extends Mt{get type(){return ie.Media}get localStream(){return this._localStream}get remoteStream(){return this._remoteStream}constructor(e,r,n){super(e,r,n),this._localStream=this.options._stream,this.connectionId=this.options.connectionId||Je.ID_PREFIX+H.randomToken(),this._negotiator=new Dt(this),this._localStream&&this._negotiator.startConnection({_stream:this._localStream,originator:!0})}_initializeDataChannel(e){this.dataChannel=e,this.dataChannel.onopen=()=>{b.log(`DC#${this.connectionId} dc connection success`),this.emit("willCloseOnRemote")},this.dataChannel.onclose=()=>{b.log(`DC#${this.connectionId} dc closed for:`,this.peer),this.close()}}addStream(e){b.log("Receiving stream",e),this._remoteStream=e,super.emit("stream",e)}handleMessage(e){let r=e.type,n=e.payload;switch(e.type){case V.Answer:this._negotiator.handleSDP(r,n.sdp),this._open=!0;break;case V.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:b.warn(`Unrecognized message type:${r} from peer:${this.peer}`);break}}answer(e,r={}){if(this._localStream){b.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=e,r&&r.sdpTransform&&(this.options.sdpTransform=r.sdpTransform),this._negotiator.startConnection({...this.options._payload,_stream:e});let n=this.provider._getMessages(this.connectionId);for(let i of n)this.handleMessage(i);this._open=!0}close(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,super.emit("close"))}};nn=new WeakMap,we(Je,nn,Je.ID_PREFIX="mc_");var Ut=Je,en=class{constructor(e){this._options=e}_buildRequest(e){let r=this._options.secure?"https":"http",{host:n,port:i,path:s,key:o}=this._options,a=new URL(`${r}://${n}:${i}${s}${o}/${e}`);return a.searchParams.set("ts",`${Date.now()}${Math.random()}`),a.searchParams.set("version",fn.version),fetch(a.href,{referrerPolicy:this._options.referrerPolicy})}async retrieveId(){try{let e=await this._buildRequest("id");if(e.status!==200)throw new Error(`Error. Status:${e.status}`);return e.text()}catch(e){b.error("Error retrieving ID",e);let r="";throw this._options.path==="/"&&this._options.host!==H.CLOUD_HOST&&(r=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+r)}}async listAllPeers(){try{let e=await this._buildRequest("peers");if(e.status!==200){if(e.status===401){let r="";throw this._options.host===H.CLOUD_HOST?r="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":r="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+r)}throw new Error(`Error. Status:${e.status}`)}return e.json()}catch(e){throw b.error("Error retrieving list peers",e),new Error("Could not get list peers from the server."+e)}}},sn,on,pe=class pe extends Mt{get type(){return ie.Data}constructor(e,r,n){super(e,r,n),this.connectionId=this.options.connectionId||pe.ID_PREFIX+li(),this.label=this.options.label||this.connectionId,this.reliable=!!this.options.reliable,this._negotiator=new Dt(this),this._negotiator.startConnection(this.options._payload||{originator:!0,reliable:this.reliable})}_initializeDataChannel(e){this.dataChannel=e,this.dataChannel.onopen=()=>{b.log(`DC#${this.connectionId} dc connection success`),this._open=!0,this.emit("open")},this.dataChannel.onmessage=r=>{b.log(`DC#${this.connectionId} dc onmessage:`,r.data)},this.dataChannel.onclose=()=>{b.log(`DC#${this.connectionId} dc closed for:`,this.peer),this.close()}}close(e){if(e?.flush){this.send({__peerData:{type:"close"}});return}this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this.dataChannel=null),this.open&&(this._open=!1,super.emit("close"))}send(e,r=!1){if(!this.open){this.emitError(Xe.NotOpenYet,"Connection is not open. You should listen for the `open` event before sending messages.");return}return this._send(e,r)}async handleMessage(e){let r=e.payload;switch(e.type){case V.Answer:await this._negotiator.handleSDP(e.type,r.sdp);break;case V.Candidate:await this._negotiator.handleCandidate(r.candidate);break;default:b.warn("Unrecognized message type:",e.type,"from peer:",this.peer);break}}};sn=new WeakMap,on=new WeakMap,we(pe,sn,pe.ID_PREFIX="dc_"),we(pe,on,pe.MAX_BUFFERED_AMOUNT=8388608);var me=pe,qe=class extends me{get bufferSize(){return this._bufferSize}_initializeDataChannel(e){super._initializeDataChannel(e),this.dataChannel.binaryType="arraybuffer",this.dataChannel.addEventListener("message",r=>this._handleDataMessage(r))}_bufferedSend(e){(this._buffering||!this._trySend(e))&&(this._buffer.push(e),this._bufferSize=this._buffer.length)}_trySend(e){if(!this.open)return!1;if(this.dataChannel.bufferedAmount>me.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(()=>{this._buffering=!1,this._tryBuffer()},50),!1;try{this.dataChannel.send(e)}catch(r){return b.error(`DC#:${this.connectionId} Error when sending:`,r),this._buffering=!0,this.close(),!1}return!0}_tryBuffer(){if(!this.open||this._buffer.length===0)return;let e=this._buffer[0];this._trySend(e)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}close(e){if(e?.flush){this.send({__peerData:{type:"close"}});return}this._buffer=[],this._bufferSize=0,super.close()}constructor(...e){super(...e),this._buffer=[],this._bufferSize=0,this._buffering=!1}},Ke=class extends qe{close(e){super.close(e),this._chunkedData={}}constructor(e,r,n){super(e,r,n),this.chunker=new wt,this.serialization=Re.Binary,this._chunkedData={}}_handleDataMessage({data:e}){let r=Kt(e),n=r.__peerData;if(n){if(n.type==="close"){this.close();return}this._handleChunk(r);return}this.emit("data",r)}_handleChunk(e){let r=e.__peerData,n=this._chunkedData[r]||{data:[],count:0,total:e.total};if(n.data[e.n]=new Uint8Array(e.data),n.count++,this._chunkedData[r]=n,n.total===n.count){delete this._chunkedData[r];let i=bs(n.data);this._handleDataMessage({data:i})}}_send(e,r){let n=Jt(e);if(n instanceof Promise)return this._send_blob(n);if(!r&&n.byteLength>this.chunker.chunkedMTU){this._sendChunks(n);return}this._bufferedSend(n)}async _send_blob(e){let r=await e;if(r.byteLength>this.chunker.chunkedMTU){this._sendChunks(r);return}this._bufferedSend(r)}_sendChunks(e){let r=this.chunker.chunk(e);b.log(`DC#${this.connectionId} Try to send ${r.length} chunks...`);for(let n of r)this.send(n,!0)}},tn=class extends qe{_handleDataMessage({data:e}){super.emit("data",e)}_send(e,r){this._bufferedSend(e)}constructor(...e){super(...e),this.serialization=Re.None}},rn=class extends qe{_handleDataMessage({data:e}){let r=this.parse(this.decoder.decode(e)),n=r.__peerData;if(n&&n.type==="close"){this.close();return}this.emit("data",r)}_send(e,r){let n=this.encoder.encode(this.stringify(e));if(n.byteLength>=H.chunkedMTU){this.emitError(Xe.MessageToBig,"Message too big for JSON channel");return}this._bufferedSend(n)}constructor(...e){super(...e),this.serialization=Re.JSON,this.encoder=new TextEncoder,this.decoder=new TextDecoder,this.stringify=JSON.stringify,this.parse=JSON.parse}};var an,He=class He extends At{get id(){return this._id}get options(){return this._options}get open(){return this._open}get socket(){return this._socket}get connections(){let e=Object.create(null);for(let[r,n]of this._connections)e[r]=n;return e}get destroyed(){return this._destroyed}get disconnected(){return this._disconnected}constructor(e,r){super(),this._serializers={raw:tn,json:rn,binary:Ke,"binary-utf8":Ke,default:Ke},this._id=null,this._lastServerId=null,this._destroyed=!1,this._disconnected=!1,this._open=!1,this._connections=new Map,this._lostMessages=new Map;let n;if(e&&e.constructor==Object?r=e:e&&(n=e.toString()),r={debug:0,host:H.CLOUD_HOST,port:H.CLOUD_PORT,path:"/",key:He.DEFAULT_KEY,token:H.randomToken(),config:H.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin",serializers:{},...r},this._options=r,this._serializers={...this._serializers,...this.options.serializers},this._options.host==="/"&&(this._options.host=window.location.hostname),this._options.path&&(this._options.path[0]!=="/"&&(this._options.path="/"+this._options.path),this._options.path[this._options.path.length-1]!=="/"&&(this._options.path+="/")),this._options.secure===void 0&&this._options.host!==H.CLOUD_HOST?this._options.secure=H.isSecure():this._options.host==H.CLOUD_HOST&&(this._options.secure=!0),this._options.logFunction&&b.setLogFunction(this._options.logFunction),b.logLevel=this._options.debug||0,this._api=new en(r),this._socket=this._createServerConnection(),!H.supports.audioVideo&&!H.supports.data){this._delayedAbort(B.BrowserIncompatible,"The current browser does not support WebRTC");return}if(n&&!H.validateId(n)){this._delayedAbort(B.InvalidID,`ID "${n}" is invalid`);return}n?this._initialize(n):this._api.retrieveId().then(i=>this._initialize(i)).catch(i=>this._abort(B.ServerError,i))}_createServerConnection(){let e=new Zr(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return e.on(ne.Message,r=>{this._handleMessage(r)}),e.on(ne.Error,r=>{this._abort(B.SocketError,r)}),e.on(ne.Disconnected,()=>{this.disconnected||(this.emitError(B.Network,"Lost connection to server."),this.disconnect())}),e.on(ne.Close,()=>{this.disconnected||this._abort(B.SocketClosed,"Underlying socket is already closed.")}),e}_initialize(e){this._id=e,this.socket.start(e,this._options.token)}_handleMessage(e){let r=e.type,n=e.payload,i=e.src;switch(r){case V.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case V.Error:this._abort(B.ServerError,n.msg);break;case V.IdTaken:this._abort(B.UnavailableID,`ID "${this.id}" is taken`);break;case V.InvalidKey:this._abort(B.InvalidKey,`API KEY "${this._options.key}" is invalid`);break;case V.Leave:b.log(`Received leave message from ${i}`),this._cleanupPeer(i),this._connections.delete(i);break;case V.Expire:this.emitError(B.PeerUnavailable,`Could not connect to peer ${i}`);break;case V.Offer:{let s=n.connectionId,o=this.getConnection(i,s);if(o&&(o.close(),b.warn(`Offer received for existing Connection ID:${s}`)),n.type===ie.Media){let f=new Ut(i,this,{connectionId:s,_payload:n,metadata:n.metadata});o=f,this._addConnection(i,o),this.emit("call",f)}else if(n.type===ie.Data){let f=new this._serializers[n.serialization](i,this,{connectionId:s,_payload:n,metadata:n.metadata,label:n.label,serialization:n.serialization,reliable:n.reliable});o=f,this._addConnection(i,o),this.emit("connection",f)}else{b.warn(`Received malformed connection type:${n.type}`);return}let a=this._getMessages(s);for(let f of a)o.handleMessage(f);break}default:{if(!n){b.warn(`You received a malformed message from ${i} of type ${r}`);return}let s=n.connectionId,o=this.getConnection(i,s);o&&o.peerConnection?o.handleMessage(e):s?this._storeMessage(s,e):b.warn("You received an unrecognized message:",e);break}}}_storeMessage(e,r){this._lostMessages.has(e)||this._lostMessages.set(e,[]),this._lostMessages.get(e).push(r)}_getMessages(e){let r=this._lostMessages.get(e);return r?(this._lostMessages.delete(e),r):[]}connect(e,r={}){if(r={serialization:"default",...r},this.disconnected){b.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(B.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}let n=new this._serializers[r.serialization](e,this,r);return this._addConnection(e,n),n}call(e,r,n={}){if(this.disconnected){b.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(B.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!r){b.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}let i=new Ut(e,this,{...n,_stream:r});return this._addConnection(e,i),i}_addConnection(e,r){b.log(`add connection ${r.type}:${r.connectionId} to peerId:${e}`),this._connections.has(e)||this._connections.set(e,[]),this._connections.get(e).push(r)}_removeConnection(e){let r=this._connections.get(e.peer);if(r){let n=r.indexOf(e);n!==-1&&r.splice(n,1)}this._lostMessages.delete(e.connectionId)}getConnection(e,r){let n=this._connections.get(e);if(!n)return null;for(let i of n)if(i.connectionId===r)return i;return null}_delayedAbort(e,r){setTimeout(()=>{this._abort(e,r)},0)}_abort(e,r){b.error("Aborting!"),this.emitError(e,r),this._lastServerId?this.disconnect():this.destroy()}destroy(){this.destroyed||(b.log(`Destroy peer with ID:${this.id}`),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))}_cleanup(){for(let e of this._connections.keys())this._cleanupPeer(e),this._connections.delete(e);this.socket.removeAllListeners()}_cleanupPeer(e){let r=this._connections.get(e);if(r)for(let n of r)n.close()}disconnect(){if(this.disconnected)return;let e=this.id;b.log(`Disconnect peer with ID:${e}`),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=e,this._id=null,this.emit("disconnected",e)}reconnect(){if(this.disconnected&&!this.destroyed)b.log(`Attempting reconnection to server with ID ${this._lastServerId}`),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)b.error("In a hurry? We're still trying to make the initial connection!");else throw new Error(`Peer ${this.id} cannot reconnect because it is not disconnected from the server!`)}}listAllPeers(e=r=>{}){this._api.listAllPeers().then(r=>e(r)).catch(r=>this._abort(B.ServerError,r))}};an=new WeakMap,we(He,an,He.DEFAULT_KEY="peerjs");var Ze=He,Ot=class extends me{constructor(e,r,n){super(e,r,{...n,reliable:!0}),this._CHUNK_SIZE=32768,this._splitStream=new TransformStream({transform:(i,s)=>{for(let o=0;o{let o=new Promise(a=>this.dataChannel.addEventListener("bufferedamountlow",a,{once:!0}));await(this.dataChannel.bufferedAmount<=me.MAX_BUFFERED_AMOUNT-i.byteLength||o);try{this.dataChannel.send(i)}catch(a){b.error(`DC#:${this.connectionId} Error when sending:`,a),s.error(a),this.close()}}}),this.writer=this._splitStream.writable.getWriter(),this._rawReadStream=new ReadableStream({start:i=>{this.once("open",()=>{this.dataChannel.addEventListener("message",s=>{i.enqueue(s.data)})})}}),this._splitStream.readable.pipeTo(this._rawSendStream)}_initializeDataChannel(e){super._initializeDataChannel(e),this.dataChannel.binaryType="arraybuffer",this.dataChannel.bufferedAmountLowThreshold=me.MAX_BUFFERED_AMOUNT/2}},Ps=Symbol.for(null);function Is(t,e){let r=new Uint8Array(t.byteLength+e.byteLength);return r.set(t,0),r.set(e,t.byteLength),new Uint8Array(r.buffer)}var ws=async function*(t){let e=t.getReader();try{for(;;){let{done:r,value:n}=await e.read();if(r)return;yield n}}finally{e.releaseLock()}},Lt=class extends Ot{constructor(e,r,n){super(e,r,{...n,reliable:!0}),this.serialization="Cbor",this._encoder=new de,this._decoder=new oe,this._decoderStream=new TransformStream({transform:(i,s)=>{let o=new Uint8Array(i);this._inc&&(o=Is(this._inc,o),this._inc=null);let a;try{a=this._decoder.decodeMultiple(o)}catch(f){if(f.incomplete)this._inc=o.subarray(f.lastPosition),a=f.values;else throw f}finally{for(let f of a||[])f===null&&(f=Ps),s.enqueue(f)}}}),this._rawReadStream.pipeTo(this._decoderStream.writable),(async()=>{for await(let i of ws(this._decoderStream.readable)){if(i.__peerData?.type==="close"){this.close();return}this.emit("data",i)}})()}_send(e){return this.writer.write(this._encoder.encode(e))}},ci=class extends Ze{constructor(...e){super(...e),this._serializers={Cbor:Lt,default:Lt}}},Bt=class extends Ot{constructor(e,r,n){super(e,r,n),this.serialization="MsgPack",this._encoder=new Gr,(async()=>{for await(let i of Wr(this._rawReadStream)){if(i.__peerData?.type==="close"){this.close();return}this.emit("data",i)}})()}_send(e){return this.writer.write(this._encoder.encode(e))}},fi=class extends Ze{constructor(...e){super(...e),this._serializers={MsgPack:Bt,default:Bt}}},ra=Ze;export{Ye as BaseConnectionErrorType,qe as BufferedConnection,Lt as Cbor,ci as CborPeer,ie as ConnectionType,Xe as DataConnectionErrorType,Bt as MsgPack,fi as MsgPackPeer,Ze as Peer,Qr as PeerError,B as PeerErrorType,Re as SerializationType,V as ServerMessageType,ne as SocketEventType,Ot as StreamConnection,ra as default,H as util}; +//# sourceMappingURL=peerjs.bundle.mjs.map \ No newline at end of file diff --git a/server.html b/server.html index e2f3e88..49e2fd1 100644 --- a/server.html +++ b/server.html @@ -19,6 +19,23 @@ + + @@ -36,6 +53,7 @@

CardiVR

+ diff --git a/server/controllerTracking.js b/server/controllerTracking.js new file mode 100644 index 0000000..3defd25 --- /dev/null +++ b/server/controllerTracking.js @@ -0,0 +1,38 @@ +import { PositionalTracking } from "./positionalTracking.js"; +import { RotationalTracking } from "./rotationalTracking.js"; +import { SocketManager } from "./socketScript.js"; + +class ControllerTracking { + constructor() { + this.rotation = { error: "Starting" }; + this.position = { error: "Starting" }; + + this.socket = new SocketManager(); + this.PositionalTracking = new PositionalTracking(this); + this.RotationalTracking = new RotationalTracking(this); + }; + + connect(id) { + var scope = this; + + //this.socket.connect(id); + + setInterval(() => { + scope.send(scope); + }, 200); + }; + + send(scope) { + /*this.socket.send(JSON.stringify({ + position: scope.position, + rotation: scope.rotation + }));*/ + + console.log({ + position: scope.position, + rotation: scope.rotation + }); + }; +}; + +export { ControllerTracking }; \ No newline at end of file diff --git a/server/positionalTracking.js b/server/positionalTracking.js index 40ce571..c4bad7b 100644 --- a/server/positionalTracking.js +++ b/server/positionalTracking.js @@ -1,7 +1,12 @@ class PositionalTracking { - constructor() { + constructor(root) { + this.root = root; var scope = this; + this.focalLength = 10000000; // Focal length of the camera in pixels (hypothetical value) + this.trackedObjectWidth = 4; // Width of the object in cm + this.trackedObjectHeight = 4; // Height of the object in cm + navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: "user" }}).then(function success(stream) { document.querySelector("#cameraFeed").srcObject = stream; @@ -12,7 +17,21 @@ class PositionalTracking { start() { var scope = this; - this.color = new tracking.ColorTracker(['yellow']); + /*tracking.ColorTracker.registerColor('theColor', function(r, g, b) { + if (r > 185 && g > 115 && g < 135 && b < 40) { + return true; + } + return false; + });*/ + + tracking.ColorTracker.registerColor('yellowgreen', function(r, g, b) { + if (r > 150 && g > 150 && b < 80) { + return true; + } + return false; + }); + + this.color = new tracking.ColorTracker(['yellowgreen']);//yellow this.color.setMinDimension(5); tracking.track('#cameraFeed', scope.color); @@ -30,13 +49,50 @@ class PositionalTracking { }; update(scope, event) { - event.data.forEach(function(rect) { + /*event.data.forEach(function(rect) { + console.log(rect.x, rect.y, rect.height, rect.width, rect.color); // rect.x, rect.y, rect.height, rect.width, rect.color + });*/ + var canvas = document.getElementById('canvas'); + var context = canvas.getContext('2d'); + + context.clearRect(0, 0, canvas.width, canvas.height); + + event.data.forEach(function(rect) { + if (rect.color === 'custom') { + rect.color = scope.color.customColor; + } + + context.strokeStyle = rect.color; + context.strokeRect(rect.x, rect.y, rect.width, rect.height); + + rect.z = scope.estimateDepth(scope.focalLength, scope.trackedObjectWidth, scope.trackedObjectHeight, rect.width, rect.height); }); + + var output = { + color: event.data[0].color, + x: event.data[0].x / 10, + y: event.data[0].y / 10, + z: event.data[0].z + } + + scope.root.position = output; + + //console.log(output); }; notVisibleController(scope, event) { + scope.root.position = { error: "Empty" }; + + //console.log({ error: "Empty" }); + }; + + estimateDepth(focalLength, objectWidth, objectHeight, imageWidth, imageHeight) { + const distance = (focalLength * (objectWidth / 100)) / imageWidth; + + const correctedDistance = (distance * (objectHeight / 100)) / imageHeight; + return correctedDistance; }; }; diff --git a/server/rotationalTracking.js b/server/rotationalTracking.js new file mode 100644 index 0000000..7c09cd5 --- /dev/null +++ b/server/rotationalTracking.js @@ -0,0 +1,45 @@ +import { ControllerBluetoothInterface } from "../utils/ControllerBluetoothInterface.js"; + +class RotationalTracking { + constructor(root) { + this.root = root; + var scope = this; + + this.dataUpdate = false; + + this.controllerBluetoothInterface = new ControllerBluetoothInterface((e) => { + scope.data(scope, e); + }); + + this.start(); + }; + + async start() { + await this.controllerBluetoothInterface.pair(); + + var scope = this; + + setInterval(() => { + this.tick(scope) + }, 1000); + }; + + async tick(scope) { + if(scope.dataUpdate == false) { + await this.controllerBluetoothInterface.runCommand(ControllerBluetoothInterface.CMD_VR_MODE); + await this.controllerBluetoothInterface.runCommand(ControllerBluetoothInterface.CMD_SENSOR); + } else { + scope.dataUpdate = false; + }; + }; + + data(scope, event) { + scope.dataUpdate = true; + + scope.root.rotation = event; + + //console.log(event); + }; +}; + +export { RotationalTracking }; \ No newline at end of file diff --git a/server/serverScript.js b/server/serverScript.js index deed5be..b6bfc83 100644 --- a/server/serverScript.js +++ b/server/serverScript.js @@ -1,7 +1,7 @@ -import { PositionalTracking } from "./positionalTracking.js"; +import { ControllerTracking } from "./controllerTracking.js"; async function setupController() { - window.positionTracking = new PositionalTracking(); + window.controllerTracking = new ControllerTracking(); }; document.querySelector(".setupController").addEventListener("click", setupController); \ No newline at end of file diff --git a/server/socketScript.js b/server/socketScript.js new file mode 100644 index 0000000..ffbcfdd --- /dev/null +++ b/server/socketScript.js @@ -0,0 +1,44 @@ +import { Peer } from "../libraries/peerjs.esm.js"; + +class SocketManager { + constructor() { + console.log("Waiting for Peer connection"); + + this.peer = new Peer(); + this.conn = null; + }; + + connect(id) { + if(this.conn !== null) return false; + + this.conn = this.peer.connect(id); + + var scope = this; + + this.conn.on('open', function(){ + console.log("Peer connected"); + }); + + this.conn.on('data', function(data){ + scope.data(data, scope); + }); + + return true; + }; + + data(data, scope) { + if(this.conn == null) return false; + + console.log("Data recieved: " + data); + return true; + }; + + send(data) { + if(this.conn == null) return false; + + this.conn.send(data); + return true; + }; +}; + +export { SocketManager }; \ No newline at end of file diff --git a/utils/ControllerBluetoothInterface.js b/utils/ControllerBluetoothInterface.js new file mode 100644 index 0000000..32875f4 --- /dev/null +++ b/utils/ControllerBluetoothInterface.js @@ -0,0 +1,254 @@ +class ControllerBluetoothInterface { + constructor(onControllerDataReceived, onDeviceDisconnected) { + this.gattServer = null; + this.batteryService = null; + this.deviceInformationService = null; + this.customService = null; + this.customServiceNotify = null; + this.customServiceWrite = null; + + this.pair = this.pair.bind(this); + this.disconnect = this.disconnect.bind(this); + this.runCommand = this.runCommand.bind(this); + + this.onDeviceConnected = this.onDeviceConnected.bind(this); + this.onNotificationReceived = this.onNotificationReceived.bind(this); + + if (onDeviceDisconnected) { + this.onDeviceDisconnected = onDeviceDisconnected.bind(this); + } + + if (onControllerDataReceived) { + this.onControllerDataReceived = onControllerDataReceived.bind(this); + } + + this.calibrating = false; + this.calibrationValues = null; + this.calibrationCount = 0; + this.controllerAngle = -30 * (Math.PI / 180.0); + } + + onDeviceConnected(device) { + if (this.onDeviceDisconnected) { + device.addEventListener('gattserverdisconnected', onDeviceDisconnected); + } + + return device.gatt.connect(); + } + + pair() { + return navigator.bluetooth.requestDevice({ + acceptAllDevices: false, + filters: [{ + namePrefix: "Gear VR Controller" + }], + optionalServices: [ + ControllerBluetoothInterface.UUID_CUSTOM_SERVICE + ] + }) + .then(this.onDeviceConnected) + .then(gattServer => this.gattServer = gattServer) + + // Get custom service + .then(() => this.gattServer.getPrimaryService(ControllerBluetoothInterface.UUID_CUSTOM_SERVICE)) + .then(customService => this.customService = customService) + + //todo: battery service, device information service + + .then(() => this.customService + .getCharacteristic(ControllerBluetoothInterface.UUID_CUSTOM_SERVICE_WRITE) + .then(characteristic => this.customServiceWrite = characteristic)) + + .then(() => this.customService + .getCharacteristic(ControllerBluetoothInterface.UUID_CUSTOM_SERVICE_NOTIFY) + .then(characteristic => this.customServiceNotify = characteristic)) + + .then(() => this.customServiceNotify + .startNotifications() + .then(() => this.customServiceNotify.addEventListener('characteristicvaluechanged', this.onNotificationReceived))) + ; + } + + disconnect() { + this.gattServer && this.gattServer.disconnect(); + } + + onNotificationReceived(e) { + const {buffer} = e.target.value; + const eventData = new Uint8Array(buffer); + + if(eventData.length !== 60) { + return; + } + + // Max observed value = 315 + // (corresponds to touchpad sensitive dimension in mm) + const axisX = ( + ((eventData[54] & 0xF) << 6) + + ((eventData[55] & 0xFC) >> 2) + ) & 0x3FF; + + // Max observed value = 315 + const axisY = ( + ((eventData[55] & 0x3) << 8) + + ((eventData[56] & 0xFF) >> 0) + ) & 0x3FF; + + // com.samsung.android.app.vr.input.service/ui/c.class:L222 + const timestamp = ((new Int32Array(buffer.slice(0, 4))[0]) & 0xFFFFFFFF) / 1000 * ControllerBluetoothInterface.TIMESTAMP_FACTOR; + + // com.samsung.android.app.vr.input.service/ui/c.class:L222 + const temperature = eventData[57]; + + const { + getAccelerometerFloatWithOffsetFromArrayBufferAtIndex, + getGyroscopeFloatWithOffsetFromArrayBufferAtIndex, + getMagnetometerFloatWithOffsetFromArrayBufferAtIndex + } = ControllerBluetoothInterface; + + // 3 x accelerometer and gyroscope x,y,z values per data event + const accel = [ + getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 4, 0), + getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 6, 0), + getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 8, 0), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 4, 1), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 6, 1), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 8, 1), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 4, 2), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 6, 2), + // getAccelerometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 8, 2) + ].map(v => v * ControllerBluetoothInterface.ACCEL_FACTOR); + + const gyro = [ + getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 10, 0), + getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 12, 0), + getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 14, 0), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 10, 1), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 12, 1), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 14, 1), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 10, 2), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 12, 2), + // getGyroscopeFloatWithOffsetFromArrayBufferAtIndex(buffer, 14, 2) + ].map(v => v * ControllerBluetoothInterface.GYRO_FACTOR); + + let magX = getMagnetometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 0); + let magY = getMagnetometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 2); + let magZ = getMagnetometerFloatWithOffsetFromArrayBufferAtIndex(buffer, 4); + + const triggerButton = Boolean(eventData[58] & (1 << 0)); + const homeButton = Boolean(eventData[58] & (1 << 1)); + const backButton = Boolean(eventData[58] & (1 << 2)); + const touchpadButton = Boolean(eventData[58] & (1 << 3)); + const volumeUpButton = Boolean(eventData[58] & (1 << 4)); + const volumeDownButton = Boolean(eventData[58] & (1 << 5)); + + if(!this.calibrating && triggerButton && backButton) { + this.calibrating = true; + this.calibrationValues = [1e8, -1e8, 1e8, -1e8, 1e8, -1e8]; + this.calibrationCount = 0; + } + + if(this.calibrating && !(triggerButton || backButton)) { + this.calibrating = false; + } + + if(this.calibrating) { + this.calibrationCount += 1; + this.calibrationValues[0] = Math.min(magX, this.calibrationValues[0]); + this.calibrationValues[1] = Math.max(magX, this.calibrationValues[1]); + this.calibrationValues[2] = Math.min(magY, this.calibrationValues[2]); + this.calibrationValues[3] = Math.max(magY, this.calibrationValues[3]); + this.calibrationValues[4] = Math.min(magZ, this.calibrationValues[4]); + this.calibrationValues[5] = Math.max(magZ, this.calibrationValues[5]); + } + + if(this.calibrationValues !== null && this.calibrationCount > 10) { + magX = (magX - this.calibrationValues[0]) / (this.calibrationValues[1] - this.calibrationValues[0]) - 0.5; + magY = (magY - this.calibrationValues[2]) / (this.calibrationValues[3] - this.calibrationValues[2]) - 0.5; + magZ = (magZ - this.calibrationValues[4]) / (this.calibrationValues[5] - this.calibrationValues[4]) - 0.5; + } + + let rMagX = -magX; + let rMagY = magY * Math.cos(this.controllerAngle) + -magZ * Math.sin(this.controllerAngle); + let rMagZ = magY * Math.sin(this.controllerAngle) + magZ * Math.cos(this.controllerAngle); + + magX = rMagX; + magY = rMagY; + magZ = rMagZ; + + this.onControllerDataReceived({ + accel, + gyro, + + magX, magY, magZ, + + timestamp, + temperature, + axisX, axisY, + triggerButton, + homeButton, + backButton, + touchpadButton, + volumeUpButton, + volumeDownButton + }); + } + + runCommand(commandValue) { + const {getLittleEndianUint8Array, onBluetoothError} = ControllerBluetoothInterface; + + return this.customServiceWrite.writeValue(getLittleEndianUint8Array(commandValue)) + .catch(onBluetoothError); + } +} + +ControllerBluetoothInterface.onBluetoothError = e => { + console.warn('Error: ' + e); +}; + +ControllerBluetoothInterface.UUID_CUSTOM_SERVICE = "4f63756c-7573-2054-6872-65656d6f7465"; +ControllerBluetoothInterface.UUID_CUSTOM_SERVICE_WRITE = "c8c51726-81bc-483b-a052-f7a14ea3d282"; +ControllerBluetoothInterface.UUID_CUSTOM_SERVICE_NOTIFY = "c8c51726-81bc-483b-a052-f7a14ea3d281"; + +ControllerBluetoothInterface.CMD_OFF = '0000'; +ControllerBluetoothInterface.CMD_SENSOR = '0100'; +ControllerBluetoothInterface.CMD_UNKNOWN_FIRMWARE_UPDATE_FUNC = '0200'; +ControllerBluetoothInterface.CMD_CALIBRATE = '0300'; +ControllerBluetoothInterface.CMD_KEEP_ALIVE = '0400'; +ControllerBluetoothInterface.CMD_UNKNOWN_SETTING = '0500'; +ControllerBluetoothInterface.CMD_LPM_ENABLE = '0600'; +ControllerBluetoothInterface.CMD_LPM_DISABLE = '0700'; +ControllerBluetoothInterface.CMD_VR_MODE = '0800'; + +ControllerBluetoothInterface.GYRO_FACTOR = 0.0001; // to radians / s +ControllerBluetoothInterface.ACCEL_FACTOR = 0.00001; // to g (9.81 m/s**2) +ControllerBluetoothInterface.TIMESTAMP_FACTOR = 0.001; // to seconds + +ControllerBluetoothInterface.getAccelerometerFloatWithOffsetFromArrayBufferAtIndex = (arrayBuffer, offset, index) => { + const arrayOfShort = new Int16Array(arrayBuffer.slice(16 * index + offset, 16 * index + offset + 2)); + return (new Float32Array([arrayOfShort[0] * 10000.0 * 9.80665 / 2048.0]))[0]; +}; + +ControllerBluetoothInterface.getGyroscopeFloatWithOffsetFromArrayBufferAtIndex = (arrayBuffer, offset, index) => { + const arrayOfShort = new Int16Array(arrayBuffer.slice(16 * index + offset, 16 * index + offset + 2)); + return (new Float32Array([arrayOfShort[0] * 10000.0 * 0.017453292 / 14.285]))[0]; +}; + +ControllerBluetoothInterface.getMagnetometerFloatWithOffsetFromArrayBufferAtIndex = (arrayBuffer, offset) => { + const arrayOfShort = new Int16Array(arrayBuffer.slice(48 + offset, 48 + offset + 2)); + return (new Float32Array([arrayOfShort[0] * 0.06]))[0]; +}; + +ControllerBluetoothInterface.getLength = (f1, f2, f3) => Math.sqrt(f1 ** 2 + f2 ** 2 + f3 ** 2); + +ControllerBluetoothInterface.getLittleEndianUint8Array = hexString => { + const leAB = new Uint8Array(hexString.length >> 1); + + for (let i = 0, j = 0; i + 2 <= hexString.length; i += 2, j++) { + leAB[j] = parseInt(hexString.substr(i, 2), 16); + } + + return leAB; +}; + +export { ControllerBluetoothInterface }; \ No newline at end of file