@ceeblue/web-utils 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const t=new TextDecoder;class e{constructor(t){this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._view=new DataView(this._data.buffer,this._data.byteOffset,this._size)}data(){return this._data}size(){return this._size}available(){return this._size-this._position}value(t=this._position){return this._data[t]}position(){return this._position}reset(t=0){this._position=Math.max(0,t>this._size?this._size:t)}shrink(t){const e=this._size-this._position;return t>e?e:(this._size=this._position+t,t)}next(t=1){const e=this._size-this._position;return t>e&&(t=e),this._position=Math.max(0,this._position+t),t}read8(){return 1===this.next(1)?this._view.getUint8(this._position-1):0}read16(){return 2===this.next(2)?this._view.getUint16(this._position-2):0}read24(){return 3===this.next(3)?this._view.getUint16(this._position-3)<<8|255&this._view.getUint8(this._position-1):0}read32(){return 4===this.next(4)?this._view.getUint32(this._position-4):0}read64(){return 8!==this.next(8)?0:4294967296*this._view.getUint32(this._position-8)+this._view.getUint32(this._position-4)}readFloat(){return 4===this.next(4)?this._view.getFloat32(this._position-4):0}readDouble(){return 8===this.next(8)?this._view.getFloat64(this._position-8):0}read7Bit(t=5){let e=0,i=1;for(;this.available();){const t=this.read8();if(e+=(127&t)*i,!(128&t))break;i*=128}return e}readString(){let e=this._position;for(;e<this._size&&this._data[e];)++e;const i=this.read(e-this._position);return this.next(),t.decode(i)}readHex(t){let e="";for(;t-- >0;)e+=("0"+this.read8().toString(16)).slice(-2);return e}read(t=this.available()){if(this.available()<t)return new Uint8Array(t);const e=this._position;return this._data.subarray(e,Math.max(e,this._position+=t))}}function i(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{a(s.next(t))}catch(t){r(t)}}function h(t){try{a(s.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,h)}a((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=new TextDecoder,n=new TextEncoder,r=performance,o=()=>{};function h(){return Math.floor(r.now())}function a(t=("undefined"==typeof location?void 0:location)){if(!t)return{};try{t=new URL(t).searchParams}catch(e){"string"==typeof t&&(t.startsWith("?")&&(t=t.substring(1)),t=new URLSearchParams(t))}return l(t,{withType:!0,noEmptyString:!0})}function l(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,n]of u(t)){if(t=n,e.withType&&null!=t&&t.substring)if(t){const e=Number(t);if(isNaN(e))switch(t.toLowerCase()){case"true":t=!0;break;case"false":t=!1;break;case"null":t=null;break;case"undefined":t=void 0}else t=e}else e.noEmptyString&&(t=!0);i[s]?(Array.isArray(i[s])||(i[s]=new Array(i[s])),i[s].push(t)):i[s]=t}return i}function u(t){return t.entries?t.entries():Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}function c(t){return n.encode(t)}function _(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function d(t){return t.substring(t.lastIndexOf("/")+1)}function g(t){const e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i));return e}function f(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;return t.substring(s)}var p,m=Object.freeze({__proto__:null,EMPTY_FUNCTION:o,equal:function(t,e){if(Object(t)!==t)return Object(e)!==e&&t===e;if(t[Symbol.iterator]){if(!e[Symbol.iterator])return!1;if(t.length!==e.length)return!1;for(let i=0;i!==t.length;++i)if(t[i]!==e[i])return!1;return!0}return t===e},fetch:function(t,e){return i(this,void 0,void 0,(function*(){const i=yield self.fetch(t,e);if(i.status>=300){let t;throw i.body&&(t=yield i.text()),(t||i.statusText||i.status).toString()}return i}))},getBaseFile:function(t){const e=t.lastIndexOf("."),i=t.lastIndexOf("/")+1;return e>=0&&e>=i?t.substring(i,e):t.substring(i)},getExtension:_,getFile:d,objectEntries:u,objectFrom:l,options:a,safePromise:function(t,e){let i;return Promise.race([e instanceof Promise?e:new Promise(e),new Promise(((e,s)=>i=setTimeout((()=>s("timed out in "+t+"ms")),t)))]).finally((()=>clearTimeout(i)))},sleep:function(t){return new Promise((e=>{setTimeout(e,t)}))},stringify:function t(e,i={}){if(i=Object.assign({space:" ",decimal:2,recursion:1,noBin:!1},i),null==e)return String(e);const n=e.error||e.message;if(n&&(e=n),e.toFixed)return e.toFixed(Number(i.decimal)||0);if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return i.noBin?"["+e.byteLength+"#bytes]":s.decode(e);if("boolean"==typeof e||e.substring||!i.recursion)return String(e);const r=i.space||"";if(Array.isArray(e)){let s="";for(const n of e)s+=(s?",":"[")+r,s+=t(n,Object.assign(Object.assign({},i),{recursion:i.recursion-1}));return s+=r+"]"}let o="{";for(const s in e)o.length>1&&(o+=","),o+=r+s+":",o+=t(e[s],Object.assign(Object.assign({},i),{recursion:i.recursion-1}))+r;return o+"}"},time:h,timeOrigin:function(){return Math.floor(r.now()+r.timeOrigin)},toBin:c,trim:function(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;let n=t.length;for(;n>0&&i.includes(t.charCodeAt(n-1));)--n;return t.substring(s,n)},trimEnd:function(t,e=" "){const i=g(e);let s=t.length;for(;s>0&&i.includes(t.charCodeAt(s-1));)--s;return t.substring(0,s)},trimStart:f});class b{get view(){return this._view||(this._view=new DataView(this._data.buffer,this._data.byteOffset,this._data.byteLength)),this._view}get capacity(){return this._data.byteLength}constructor(t=64,e=0,i){"number"==typeof t?(this._data=new Uint8Array(t),this._size=0):"buffer"in t?(this._data=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this._size=t.byteLength):(this._isConst=!0,null==i&&(i=t.byteLength),this._data=new Uint8Array(t,e,i),this._size=0)}data(){return new Uint8Array(this._data.buffer,this._data.byteOffset,this._size)}size(){return this._size||0}next(t=1){return this.reserve(this._size+=t)}clear(t=0){return this.reserve(this._size=t)}write(t){var e;let i;return i="string"==typeof t?c(t):t instanceof ArrayBuffer?new Uint8Array(t):"buffer"in t?new Uint8Array(t.buffer,null!==(e=t.byteOffset)&&void 0!==e?e:0,t.byteLength):t,this.reserve(this._size+i.length),this._data.set(i,this._size),this._size+=i.length,this}write8(t){return t>255&&(t=255),this.reserve(this._size+1),this._data[this._size++]=t,this}write16(t){return t>65535&&(t=65535),this.reserve(this._size+2),this.view.setUint16(this._size,t),this._size+=2,this}write24(t){return t>16777215&&(t=16777215),this.reserve(this._size+3),this.view.setUint16(this._size,t>>8),this.view.setUint8(this._size+=2,255&t),++this._size,this}write32(t){return t>4294967295&&(t=4294967295),this.reserve(this._size+4),this.view.setUint32(this._size,t),this._size+=4,this}write64(t){return this.write32(t/4294967296),this.write32(4294967295&t)}writeFloat(t){return this.reserve(this._size+4),this.view.setFloat32(this._size,t),this._size+=4,this}writeDouble(t){return this.reserve(this._size+8),this.view.setFloat64(this._size,t),this._size+=8,this}write7Bit(t){let e=127&t;for(;t=Math.floor(t/128);)this.write8(128|e),e=127&t;return this.write8(e)}writeString(t){return this.write(c(t)).write8(0)}writeHex(t){for(let e=0;e<t.length;e+=2)this.write8(parseInt(t.substring(e,e+2),16));return this}reserve(t){if(!this._data)throw Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw Error("writing exceeds maximum "+this._data.byteLength+" bytes limit");--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t;const e=new Uint8Array(t);return e.set(this._data),this._data=e,this._view=void 0,this}}!function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(p||(p={}));let y=0;setInterval((()=>{console.assert(0===y,y.toFixed(),"calls to log was useless")}),1e4);const w=a()["!cb-override-log-level"],v=new Array(128);v[101]=v[69]=1,v[119]=v[87]=2,v[105]=v[73]=3,v[100]=v[68]=4;class x{get error(){return this._bind(p.ERROR)}get warn(){return this._bind(p.WARN)}get info(){return this._bind(p.INFO)}get debug(){return this._bind(p.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._log=t,++y}_onLog(t,e){var i,s;const n=null!==(s=null!==(i=null!=w?w:t.level)&&void 0!==i?i:z.level)&&void 0!==s?s:p.INFO;return!1!==n&&(!(!0!==n&&v[e.charCodeAt(0)]>v[n.charCodeAt(0)])&&(t.on&&t.on(e,this._args),!!this._args.length))}_bind(t){return this._done||(this._done=!0,--y),this._onLog(z,t)&&(this._log===z||this._onLog(this._log,t))?console[t].bind(console,...this._args):o}}class S{constructor(){this.log=(...t)=>new x(this.log,...t)}}const z=(...t)=>new x(z,...t);class A extends S{constructor(t){super(),this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._bit=0}data(){return this._data}size(){return this._size}available(){return 8*(this._size-this._position)-this._bit}next(t=1){let e=0;for(;this._position!==this._size&&t--;)++e,8==++this._bit&&(this._bit=0,++this._position);return e}read(t=1){let e=0;for(;this._position!==this._size&&t--;)e<<=1,this._data[this._position]&128>>this._bit++&&(e|=1),8===this._bit&&(this._bit=0,++this._position);return e}read8(){return this.read(8)}read16(){return this.read(16)}read24(){return this.read(24)}read32(){return this.read(32)}readExpGolomb(){let t=0;for(;!this.read();){if(!this.available())return 0;++t}const e=this.read(t);return t>15?(this.log("Exponential-Golomb code exceeding unsigned 16 bits").warn(),0):e+(1<<t)-1}}class E{onBytes(t){}get interval(){return this._interval}set interval(t){this._interval=t,this.updateSamples()}constructor(t=1e3){this._interval=t,this.clear()}value(){return Math.round(this.exact())}exact(){this.updateSamples();const t=h()-this._time;return t?this._bytes/t*1e3:0}addBytes(t){var e;const i=h(),s=this.updateSamples(i)[this._samples.length-1];if(i>(null!==(e=null==s?void 0:s.time)&&void 0!==e?e:this._time))this._samples.push({bytes:t,time:i,clip:!1});else{if(!s)return this;s.bytes+=t}return this._bytes+=t,this.onBytes(t),this}clear(){return this._bytes=0,this._time=h(),this._samples=[],this._clip=!1,this}clip(){if(this._clip){this._clip=!1;let t=0;for(const e of this._samples)if(this._bytes-=e.bytes,++t,this._time=e.time,e.clip)break;this._samples.splice(0,t)}const t=this._samples[this._samples.length-1];return t&&(t.clip=!0,this._clip=!0),this}updateSamples(t=h()){const e=t-this._interval;let i,s=0;for(;this._time<e&&(i=this._samples[s]);){if(this._bytes-=i.bytes,i.clip&&(this._clip=i.clip=!1),i.time>e){i.bytes*=(i.time-e)/(i.time-this._time),this._time=e,this._bytes+=i.bytes;break}++s,this._time=i.time}return this._samples.splice(0,s),this._samples}}class M{static fixProtocol(t,e){const i=e.indexOf("://");return i>=0&&(i>2&&"s"===e.charAt(i-1).toLowerCase()?(t.length<=2||!t.endsWith("s"))&&(t+="s"):t.length>2&&t.endsWith("s")&&(t=t.slice(0,-1)),e=e.substring(i+3)),t+"://"+e}get domain(){return this._domain}get port(){return this._port}toString(){return this._address}valueOf(){return this._address}constructor(t,e){this._address=t;let i=t.indexOf("/");if(i>=0&&(47===t.charCodeAt(i+1)?i>0?58===t.charCodeAt(i-1)&&(t=t.substring(i+2)):t=t.substring(2):i||(t=t.substring(1))),this._domain=t,this._port=e,i=t.lastIndexOf(":"),i>=0){const e=parseInt(t.substring(i+1));e&&e<=65535&&(this._port=e,this._domain=t.substring(0,i))}else i=t.indexOf("/"),i>=0&&(this._domain=t.substring(0,i))}}var O;function T(t,e){switch(t){case O.HESP:e.mediaExt="mp4";break;case O.WEBRTC:e.mediaExt="rtp";break;case O.WRTS:try{const t=_(d(new URL(e.endPoint).pathname));t&&".json"!==t.toLowerCase()&&(e.mediaExt=t)}catch(t){}e.mediaExt||(e.mediaExt="rts");break;case O.META:e.mediaExt="js";break;case O.DATA:e.mediaExt="json";break;default:e.mediaExt="",console.warn("Unknown params type "+t)}e.mediaExt=f(e.mediaExt,".")}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(O||(O={}));var k=Object.freeze({__proto__:null,get Type(){return O},buildURL:function(t,e,i="wss"){T(t,e);const s=new URL(M.fixProtocol(i,e.endPoint));if(s.pathname.length<=1)switch(t){case O.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case O.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case O.WRTS:s.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case O.META:s.pathname="/json_"+e.streamName+".js";break;case O.DATA:s.pathname="/"+e.streamName+".json";break;default:console.warn("Unknown url type "+t)}e.accessToken&&s.searchParams.set("id",e.accessToken);for(const t in e.query)s.searchParams.set(t,e.query[t]);return s},defineMediaExt:T});class U extends S{constructor(){super(),this._events=new Map;let t=Object.getPrototypeOf(this);for(;t&&t!==Object.prototype;){for(const e of Object.getOwnPropertyNames(t))if(!(e.length<3)&&e.startsWith("on")&&t[e]instanceof Function){const i=new Set;this._events.set(e.substring(2).toLowerCase(),i);let s=t[e];const n=(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)};Object.defineProperties(this,{[e]:{get:()=>n,set:t=>{s=t}}})}t=Object.getPrototypeOf(t)}}on(t,e,i){var s;if(!e)throw Error("event to subscribe cannot be null");const n=this._event(t);n.add(e),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>n.delete(e)),{once:!0})}once(t,e,i){var s;if(!e)throw Error("event to subscribe cannot be null");const n=this._event(t);n.add(((...t)=>{n.delete(e),e(...t)})),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>n.delete(e)),{once:!0})}off(t,e){if(!e)throw Error("event to unsubscribe cannot be null");this._event(t).delete(e)}_event(t){const e=this._events.get(t.toLowerCase());if(!e)throw Error("No event on"+t+" on class "+this.constructor.name);return e}}class I{[Symbol.iterator](){return this._map[Symbol.iterator]()}get size(){return this._map.size}constructor(t){this._initValue=t,this._map=new Map}get(t){let e=this.find(t);return void 0===e&&this._map.set(t,e=this._initValue()),e}find(t){return this._map.get(t)}has(t){return this._map.has(t)}clear(){this._map.clear()}delete(t){return this._map.delete(t)}set(t,e){return this._map.set(t,e),e}forEach(t,e){this._map.forEach(t,e)}}class C{get size(){return this._queue.length}get capacity(){return this._capacity}set capacity(t){this._capacity=t,null!=t&&this._queue.length>t&&this._queue.splice(0,this._queue.length-t)}get front(){return this._queue[0]}get back(){return this._queue[this._queue.length-1]}[Symbol.iterator](){return this._queue[Symbol.iterator]()}constructor(t){this._capacity=t,this._queue=new Array}push(t){return null!=this._capacity&&this._queue.push(t)>this._capacity&&this.pop(),this}pop(){return this._queue.shift()}clear(){return this._queue.length=0,this}}class L extends C{get minimum(){return this._min}get maximum(){return this._max}get average(){return null==this._average&&(this._average=this.size?this._sum/this.size:0),this._average}constructor(t){super(t),this._sum=0,this._min=0,this._max=0}push(t){return t>this._max?this._max=t:t<this._min&&(this._min=t),this._average=void 0,this._sum+=t,super.push(t),this}pop(){const t=super.pop();return t===this._max?this._max=Math.max(0,...this):t===this._min&&(this._min=Math.min(0,...this)),this._average=void 0,this._sum-=t||0,t}clear(){return this._min=this._max=this._sum=0,super.clear(),this}}const F={fromString(t){if(Array.isArray(t))return t;const e=new Array;let i,s=e;for(let n of t.toString().split("\n")){if(n=n.trim(),!n)continue;let t=n[0];const r=n.substring(n.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!r)continue;t=this.addAttribute(s,r),e===s&&"fingerprint"===t.toLowerCase()&&(i=s.fingerprint);break;case"m":e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e.push(s={m:r});break;default:s[t]=r}}return e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e},toString(t){if("string"==typeof t)return t;const e=[];let i="v"in t?"v="+t.v+"\n":"";"o"in t&&(i+="o="+t.o+"\n"),"s"in t&&(i+="s="+t.s+"\n");const s=t;for(const n of Object.keys(t)){if("v"===n||"o"===n||"s"===n)continue;const t=s[n];if(null==t)continue;const r=parseInt(n);if(!isNaN(r)){e[r]=t;continue}const o=Array.isArray(t)&&t.length||1;for(let e=0;e<o;++e){const s=Array.isArray(t)&&t.length?t[e]:t;n.length>1?(i+="a="+n,s&&(i+=":")):i+=n+"=",i+=s+"\n"}}for(const t of e)i+=this.toString(t);return i},addAttribute(t,e){var i;const s=F.parseAttribute(e),n=null!==(i=s.value)&&void 0!==i?i:"",r=t,o=r[s.key];return o?Array.isArray(o)?o.push(n):n!==o&&(r[s.key]=[o,n]):r[s.key]=n,s.key},removeAttribute(t,e){const i=F.parseAttribute(e),s=t;if(void 0===i.value)return delete s[e],e;const n=s[e];if(Array.isArray(i.value)){const t=n.findIndex((t=>t===i.value));t>=0&&n.splice(t,1)}else n===i.value&&delete s[e];return i.key},parseAttribute(t){const e=t.indexOf(":");return{key:(e>=0?t.substring(0,e):t).trim(),value:e>=0?t.substring(e+1).trim():void 0}}};Object.freeze(F);class N extends U{onOpen(){}onMessage(t){}onClose(t){t?this.log("onClose",t).error():this.log("onClose").info()}get binaryType(){return"arraybuffer"}get recvByteRate(){return this._recvByteRate.value()}get sendByteRate(){return this._sendByteRate.value()}get url(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.url)&&void 0!==e?e:""}get extensions(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.extensions)&&void 0!==e?e:""}get protocol(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.protocol)&&void 0!==e?e:""}get opened(){return this._opened}get readyState(){return this._ws?this._ws.readyState:3}get closed(){return this._closed}get bufferedAmount(){var t;return this._queueingBytes+((null===(t=this._ws)||void 0===t?void 0:t.bufferedAmount)||0)}get queueing(){return this._queueing}constructor(t,e){super(),this._queueing=[],this._queueingBytes=0,this._opened=!1,this._closed=!0,this._recvByteRate=new E,this._sendByteRate=new E,t&&this.open(t,e)}open(t,e){this._closed=!1;const i=this._ws=new WebSocket(t,e);return i.binaryType=this.binaryType,i.onmessage=t=>{var e;this._recvByteRate.addBytes(null!==(e=t.data.byteLength)&&void 0!==e?e:t.data.length),this.onMessage(t.data)},i.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close({type:"WebSocketReliableError",name:"Server shutdown",url:t.toString()}):this.close({type:"WebSocketReliableError",name:"Socket disconnection",url:t.toString(),reason:String(e.reason||e.code)}):this.close({type:"WebSocketReliableError",name:"Connection failed",url:t.toString(),reason:String(e.reason||e.code)})},i.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(this._closed)throw Error("Open socket before to send data");return e||!this._opened?(this._queueing.push(t),this._queueingBytes+="string"==typeof t?t.length:t.byteLength):this._send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._send(t);this._queueing.length=0,this._queueingBytes=0}close(t){this._ws&&!this._closed&&(this._closed=!0,this._ws.onopen=this._ws.onclose=this._ws.onmessage=null,this._ws.close(),this._queueing.length=0,this._queueingBytes=0,this.onClose(t),this._opened=!1)}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}function R(t,e,i=32,s=.2){const n=e/i;let r="",o=n/2;const h=t.getImageData(0,Math.round(o),e,1).data,a=new Uint32Array(h.buffer),l=255*s,u=255*(1-s);for(;o<a.length;){const t=16777215&a[Math.round(o)],e=.299*(t>>16&255)+.587*(t>>8&255)+.114*(255&t);if(e<l)r+="1";else{if(!(e>u))return;r+="0"}o+=n}const c=parseInt(r.slice(0,5),2),_=parseInt(r.slice(5,10),2),d=parseInt(r.slice(10,16),2),g=parseInt(r.slice(16,22),2),f=parseInt(r.slice(22,32),2),p=new Date;return new Date(Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),c,_,d,g,f))}var B=Object.freeze({__proto__:null,decodeTimestamp:R,encodeTimestamp:function(t,e,i=32,s=new Date){const n=Math.floor(e/i),r=s.getUTCDate(),o=s.getUTCHours(),h=s.getUTCMinutes(),a=s.getUTCSeconds(),l=s.getUTCMilliseconds(),u=r.toString(2).padStart(5,"0")+o.toString(2).padStart(5,"0")+h.toString(2).padStart(6,"0")+a.toString(2).padStart(6,"0")+l.toString(2).padStart(10,"0");for(let e=0;e<u.length;e++){const s=e%i*n,r=Math.floor(e/i)*n;t.fillStyle="1"===u[e]?"black":"white",t.fillRect(s,r,n,n)}},getLatency:function(t,e,i,s=new Date,n=32,r=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/n),!e.width||!e.height)return 0;i.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const o=R(i,e.width,n,r);return null==o?0:s.getTime()-o.getTime()}});class q{get graphMargin(){return this._graphMargin}set graphMargin(t){this._graphMargin=t}get textMargin(){return this._textMargin}set textMargin(t){this._textMargin=t}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight=t}get labelWidth(){return this._labelWidth}set labelWidth(t){this._labelWidth=t}get legendFontSize(){return this._legendFontSize}set legendFontSize(t){this._legendFontSize=t}get stepSize(){return this._stepSize}set stepSize(t){this._stepSize=t}constructor(t){this._ui=t,this._lineHeight=40,this._labelWidth=170,this._graphMargin=5,this._textMargin=5,this._legendFontSize=13,this._stepSize=10,this._ranges={}}reset(){this._ranges={}}display(t){if(null!=this._html)return;this._html="";const e=this._legendFontSize/2*7,i=this._ui.clientWidth-e,s=this._lineHeight-2*this._graphMargin,n=Math.round(this._lineHeight/2),r=Math.round(this._lineHeight/2+this._textMargin),o=this._labelWidth-2*this._textMargin,h=e/2;for(const[e,a]of t){let t=this._labelWidth+a.length*this._stepSize;if(t>=i&&(t-=a.splice(0,Math.ceil((t-i)/this._stepSize)).length*this._stepSize),!a.length)continue;this._html+='<svg class="list-group-item p-0" style="height: '+this._lineHeight+'px" xmlns="http://www.w3.org/2000/svg">',this._html+='<text x="'+this._textMargin+'" y="'+r+'">'+e+"</text>",this._html+='<text x="'+o+'" y="'+r+'" text-anchor="end">'+a[a.length-1].toString()+"</text>",this._html+='<path fill="none" d="M'+this._labelWidth+" "+n,this._html+="H"+(i+h),this._html+='" stroke-width="1" stroke="lightgray" stroke-dasharray="10,10"/>',this._html+='<path fill="none" stroke-width="1" stroke="brown" d="M';let l=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(let t=0;t<a.length;++t){const e=parseFloat(a[t].toString());e<l&&(l=e),e>u&&(u=e)}let c=this._ranges[e];c||(this._ranges[e]=c={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}),c.min=Math.min(c.min,l),c.max=Math.max(c.max,u);const _=c.max-c.min;let d="",g="";for(let e=0;e<a.length;++e){t-=this._stepSize;const i=parseFloat(a[e].toString()),r=n+(_?Math.round((.5-(i-c.min)/_)*s):0);this._html+=t+" "+r+" ",i===l?g=g||this._drawCircle(t,r,i):i===u&&(d=d||this._drawCircle(t,r,i))}this._html+='" />';const f=Math.round((u-l)/2);this._html+='<text text-anchor="middle" font-size="'+this._legendFontSize+'" y="'+r+'">',this._html+='<tspan x="'+(i+h)+'" dy="-0.5em">'+(l!==u?"≈":"=")+(l+f)+"</tspan>",this._html+='<tspan x="'+(i+h)+'" dy="1em">±'+f+"</tspan>",this._html+="</text>",this._html+=d+g,this._html+="</svg>"}requestAnimationFrame((()=>{null!=this._html&&(this._ui.innerHTML=this._html,this._html=void 0)}))}_drawCircle(t,e,i){let s='<circle cx="'+t+'" cy="'+e+'" r="2" fill="green" />';const n=.7*this._legendFontSize;return e<Math.round(this._lineHeight/2)?e+=this.textMargin+n:e-=this.textMargin,s+='<text font-style="italic" font-size="'+this._legendFontSize+'" x="'+(t-this._legendFontSize)+'" y="'+e+'">'+i+"</text>",s}}const W="3.2.0";export{e as BinaryReader,b as BinaryWriter,A as BitReader,E as ByteRate,k as Connect,B as EpochTime,U as EventEmitter,I as FixMap,x as Log,p as LogLevel,S as Loggable,M as NetAddress,L as Numbers,C as Queue,F as SDP,q as UIMetrics,m as Util,W as VERSION,N as WebSocketReliable,z as log};//# sourceMappingURL=web-utils.min.js.map
1
+ const t=new TextDecoder;class e{constructor(t){this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._view=new DataView(this._data.buffer,this._data.byteOffset,this._size)}data(){return this._data}size(){return this._size}available(){return this._size-this._position}value(t=this._position){return this._data[t]}position(){return this._position}reset(t=0){this._position=Math.max(0,t>this._size?this._size:t)}shrink(t){const e=this._size-this._position;return t>e?e:(this._size=this._position+t,t)}next(t=1){const e=this._size-this._position;return t>e&&(t=e),this._position=Math.max(0,this._position+t),t}read8(){return 1===this.next(1)?this._view.getUint8(this._position-1):0}read16(){return 2===this.next(2)?this._view.getUint16(this._position-2):0}read24(){return 3===this.next(3)?this._view.getUint16(this._position-3)<<8|255&this._view.getUint8(this._position-1):0}read32(){return 4===this.next(4)?this._view.getUint32(this._position-4):0}read64(){return 8!==this.next(8)?0:4294967296*this._view.getUint32(this._position-8)+this._view.getUint32(this._position-4)}readFloat(){return 4===this.next(4)?this._view.getFloat32(this._position-4):0}readDouble(){return 8===this.next(8)?this._view.getFloat64(this._position-8):0}read7Bit(t=5){let e=0,i=1;for(;this.available();){const t=this.read8();if(e+=(127&t)*i,!(128&t))break;i*=128}return e}readString(){let e=this._position;for(;e<this._size&&this._data[e];)++e;const i=this.read(e-this._position);return this.next(),t.decode(i)}readHex(t){let e="";for(;t-- >0;)e+=("0"+this.read8().toString(16)).slice(-2);return e}read(t=this.available()){if(this.available()<t)return new Uint8Array(t);const e=this._position;return this._data.subarray(e,Math.max(e,this._position+=t))}}function i(t,e,i,s){return new(i||(i=Promise))((function(n,r){function h(t){try{a(s.next(t))}catch(t){r(t)}}function o(t){try{a(s.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(h,o)}a((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=new TextDecoder,n=new TextEncoder,r=performance,h=()=>{};function o(){return Math.floor(r.now())}function a(t=("undefined"==typeof location?void 0:location)){if(!t)return{};try{t=new URL(t).searchParams}catch(e){"string"==typeof t&&(t.startsWith("?")&&(t=t.substring(1)),t=new URLSearchParams(t))}return l(t,{withType:!0,noEmptyString:!0})}function l(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,n]of u(t)){if(t=n,e.withType&&null!=t&&t.substring)if(t){const e=Number(t);if(isNaN(e))switch(t.toLowerCase()){case"true":t=!0;break;case"false":t=!1;break;case"null":t=null;break;case"undefined":t=void 0}else t=e}else e.noEmptyString&&(t=!0);i[s]?(Array.isArray(i[s])||(i[s]=new Array(i[s])),i[s].push(t)):i[s]=t}return i}function u(t){return t.entries?t.entries():Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}function c(t){return n.encode(t)}function _(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function d(t){return t.substring(t.lastIndexOf("/")+1)}function g(t){const e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i));return e}function f(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;return t.substring(s)}var p,m=Object.freeze({__proto__:null,EMPTY_FUNCTION:h,equal:function(t,e){if(Object(t)!==t)return Object(e)!==e&&t===e;if(t[Symbol.iterator]){if(!e[Symbol.iterator])return!1;if(t.length!==e.length)return!1;for(let i=0;i!==t.length;++i)if(t[i]!==e[i])return!1;return!0}return t===e},fetch:function(t,e){return i(this,void 0,void 0,(function*(){const i=yield self.fetch(t,e);if(i.status>=300){let t;throw i.body&&(t=yield i.text()),(t||i.statusText||i.status).toString()}return i}))},getBaseFile:function(t){const e=t.lastIndexOf("."),i=t.lastIndexOf("/")+1;return e>=0&&e>=i?t.substring(i,e):t.substring(i)},getExtension:_,getFile:d,objectEntries:u,objectFrom:l,options:a,safePromise:function(t,e){let i;return Promise.race([e instanceof Promise?e:new Promise(e),new Promise(((e,s)=>i=setTimeout((()=>s("timed out in "+t+"ms")),t)))]).finally((()=>clearTimeout(i)))},sleep:function(t){return new Promise((e=>{setTimeout(e,t)}))},stringify:function t(e,i={}){if(i=Object.assign({space:" ",decimal:2,recursion:1,noBin:!1},i),null==e)return String(e);const n=e.error||e.message;if(n&&(e=n),e.toFixed)return e.toFixed(Number(i.decimal)||0);if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return i.noBin?"["+e.byteLength+"#bytes]":s.decode(e);if("boolean"==typeof e||e.substring||!i.recursion)return String(e);const r=i.space||"";if(Array.isArray(e)){let s="";for(const n of e)s+=(s?",":"[")+r,s+=t(n,Object.assign(Object.assign({},i),{recursion:i.recursion-1}));return s+=r+"]"}let h="{";for(const s in e)h.length>1&&(h+=","),h+=r+s+":",h+=t(e[s],Object.assign(Object.assign({},i),{recursion:i.recursion-1}))+r;return h+"}"},time:o,timeOrigin:function(){return Math.floor(r.now()+r.timeOrigin)},toBin:c,trim:function(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;let n=t.length;for(;n>0&&i.includes(t.charCodeAt(n-1));)--n;return t.substring(s,n)},trimEnd:function(t,e=" "){const i=g(e);let s=t.length;for(;s>0&&i.includes(t.charCodeAt(s-1));)--s;return t.substring(0,s)},trimStart:f});class b{get view(){return this._view||(this._view=new DataView(this._data.buffer,this._data.byteOffset,this._data.byteLength)),this._view}get capacity(){return this._data.byteLength}constructor(t=64,e=0,i){"number"==typeof t?(this._data=new Uint8Array(t),this._size=0):"buffer"in t?(this._data=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this._size=t.byteLength):(this._isConst=!0,null==i&&(i=t.byteLength),this._data=new Uint8Array(t,e,i),this._size=0)}data(){return new Uint8Array(this._data.buffer,this._data.byteOffset,this._size)}size(){return this._size||0}next(t=1){return this.reserve(this._size+=t)}clear(t=0){return this.reserve(this._size=t)}write(t){var e;let i;return i="string"==typeof t?c(t):t instanceof ArrayBuffer?new Uint8Array(t):"buffer"in t?new Uint8Array(t.buffer,null!==(e=t.byteOffset)&&void 0!==e?e:0,t.byteLength):t,this.reserve(this._size+i.length),this._data.set(i,this._size),this._size+=i.length,this}write8(t){return t>255&&(t=255),this.reserve(this._size+1),this._data[this._size++]=t,this}write16(t){return t>65535&&(t=65535),this.reserve(this._size+2),this.view.setUint16(this._size,t),this._size+=2,this}write24(t){return t>16777215&&(t=16777215),this.reserve(this._size+3),this.view.setUint16(this._size,t>>8),this.view.setUint8(this._size+=2,255&t),++this._size,this}write32(t){return t>4294967295&&(t=4294967295),this.reserve(this._size+4),this.view.setUint32(this._size,t),this._size+=4,this}write64(t){return this.write32(t/4294967296),this.write32(4294967295&t)}writeFloat(t){return this.reserve(this._size+4),this.view.setFloat32(this._size,t),this._size+=4,this}writeDouble(t){return this.reserve(this._size+8),this.view.setFloat64(this._size,t),this._size+=8,this}write7Bit(t){let e=127&t;for(;t=Math.floor(t/128);)this.write8(128|e),e=127&t;return this.write8(e)}writeString(t){return this.write(c(t)).write8(0)}writeHex(t){for(let e=0;e<t.length;e+=2)this.write8(parseInt(t.substring(e,e+2),16));return this}reserve(t){if(!this._data)throw Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw Error("writing exceeds maximum "+this._data.byteLength+" bytes limit");--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t;const e=new Uint8Array(t);return e.set(this._data),this._data=e,this._view=void 0,this}}!function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(p||(p={}));let y=0;setInterval((()=>{console.assert(0===y,y.toFixed(),"calls to log was useless")}),1e4);const w=a()["!cb-override-log-level"],v=new Array(128);v[101]=v[69]=1,v[119]=v[87]=2,v[105]=v[73]=3,v[100]=v[68]=4;class x{get error(){return this._bind(p.ERROR)}get warn(){return this._bind(p.WARN)}get info(){return this._bind(p.INFO)}get debug(){return this._bind(p.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._log=t,++y}_onLog(t,e){var i,s;const n=null!==(s=null!==(i=null!=w?w:t.level)&&void 0!==i?i:z.level)&&void 0!==s?s:p.INFO;return!1!==n&&(!(!0!==n&&v[e.charCodeAt(0)]>v[n.charCodeAt(0)])&&(t.on&&t.on(e,this._args),!!this._args.length))}_bind(t){return this._done||(this._done=!0,--y),this._onLog(z,t)&&(this._log===z||this._onLog(this._log,t))?console[t].bind(console,...this._args):h}}class S{constructor(){this.log=(...t)=>new x(this.log,...t)}}const z=(...t)=>new x(z,...t);class A extends S{constructor(t){super(),this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._bit=0}data(){return this._data}size(){return this._size}available(){return 8*(this._size-this._position)-this._bit}next(t=1){let e=0;for(;this._position!==this._size&&t--;)++e,8==++this._bit&&(this._bit=0,++this._position);return e}read(t=1){let e=0;for(;this._position!==this._size&&t--;)e<<=1,this._data[this._position]&128>>this._bit++&&(e|=1),8===this._bit&&(this._bit=0,++this._position);return e}read8(){return this.read(8)}read16(){return this.read(16)}read24(){return this.read(24)}read32(){return this.read(32)}readExpGolomb(){let t=0;for(;!this.read();){if(!this.available())return 0;++t}const e=this.read(t);return t>15?(this.log("Exponential-Golomb code exceeding unsigned 16 bits").warn(),0):e+(1<<t)-1}}class E{onBytes(t){}get interval(){return this._interval}set interval(t){this._interval=t,this.updateSamples()}constructor(t=1e3){this._interval=t,this.clear()}value(){return Math.round(this.exact())}exact(){this.updateSamples();const t=o()-this._time;return t?this._bytes/t*1e3:0}addBytes(t){var e;const i=o(),s=this.updateSamples(i)[this._samples.length-1];if(i>(null!==(e=null==s?void 0:s.time)&&void 0!==e?e:this._time))this._samples.push({bytes:t,time:i,clip:!1});else{if(!s)return this;s.bytes+=t}return this._bytes+=t,this.onBytes(t),this}clear(){return this._bytes=0,this._time=o(),this._samples=[],this._clip=!1,this}clip(){if(this._clip){this._clip=!1;let t=0;for(const e of this._samples)if(this._bytes-=e.bytes,++t,this._time=e.time,e.clip)break;this._samples.splice(0,t)}const t=this._samples[this._samples.length-1];return t&&(t.clip=!0,this._clip=!0),this}updateSamples(t=o()){const e=t-this._interval;let i,s=0;for(;this._time<e&&(i=this._samples[s]);){if(this._bytes-=i.bytes,i.clip&&(this._clip=i.clip=!1),i.time>e){i.bytes*=(i.time-e)/(i.time-this._time),this._time=e,this._bytes+=i.bytes;break}++s,this._time=i.time}return this._samples.splice(0,s),this._samples}}class M{static fixProtocol(t,e){const i=e.indexOf("://");return i>=0&&(i>2&&"s"===e.charAt(i-1).toLowerCase()?(t.length<=2||!t.endsWith("s"))&&(t+="s"):t.length>2&&t.endsWith("s")&&(t=t.slice(0,-1)),e=e.substring(i+3)),t+"://"+e}get domain(){return this._domain}get port(){return this._port}toString(){return this._address}valueOf(){return this._address}constructor(t,e){this._address=t;let i=t.indexOf("/");if(i>=0&&(47===t.charCodeAt(i+1)?i>0?58===t.charCodeAt(i-1)&&(t=t.substring(i+2)):t=t.substring(2):i||(t=t.substring(1))),this._domain=t,this._port=e,i=t.lastIndexOf(":"),i>=0){const e=parseInt(t.substring(i+1));e&&e<=65535&&(this._port=e,this._domain=t.substring(0,i))}else i=t.indexOf("/"),i>=0&&(this._domain=t.substring(0,i))}}var O;function T(t,e){switch(t){case O.HESP:e.mediaExt="mp4";break;case O.WEBRTC:e.mediaExt="rtp";break;case O.WRTS:try{const t=_(d(new URL(e.endPoint).pathname));t&&".json"!==t.toLowerCase()&&(e.mediaExt=t)}catch(t){}e.mediaExt||(e.mediaExt="rts");break;case O.META:e.mediaExt="js";break;case O.DATA:e.mediaExt="json";break;default:e.mediaExt="",console.warn("Unknown params type "+t)}e.mediaExt=f(e.mediaExt,".")}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(O||(O={}));var k=Object.freeze({__proto__:null,get Type(){return O},buildURL:function(t,e,i="wss"){T(t,e);const s=new URL(M.fixProtocol(i,e.endPoint));if(s.pathname.length<=1)switch(t){case O.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case O.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case O.WRTS:s.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case O.META:s.pathname="/json_"+e.streamName+".js";break;case O.DATA:s.pathname="/"+e.streamName+".json";break;default:console.warn("Unknown url type "+t)}e.accessToken&&s.searchParams.set("id",e.accessToken);for(const t in e.query)s.searchParams.set(t,e.query[t]);return s},defineMediaExt:T});class U extends S{constructor(){super(),this._events=new Map;let t=Object.getPrototypeOf(this);for(;t&&t!==Object.prototype;){for(const e of Object.getOwnPropertyNames(t))if(!(e.length<3)&&e.startsWith("on")&&t[e]instanceof Function){const i=new Set;this._events.set(e.substring(2).toLowerCase(),i);let s=t[e];const n=(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)};Object.defineProperties(this,{[e]:{get:()=>n,set:t=>{s=t}}})}t=Object.getPrototypeOf(t)}}on(t,e,i){var s;if(!e)throw Error("event to subscribe cannot be null");const n=this._event(t);n.add(e),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>n.delete(e)),{once:!0})}once(t,e,i){var s;if(!e)throw Error("event to subscribe cannot be null");const n=this._event(t);n.add(((...t)=>{n.delete(e),e(...t)})),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>n.delete(e)),{once:!0})}off(t,e){if(!e)throw Error("event to unsubscribe cannot be null");this._event(t).delete(e)}_event(t){const e=this._events.get(t.toLowerCase());if(!e)throw Error("No event on"+t+" on class "+this.constructor.name);return e}}class C{[Symbol.iterator](){return this._map[Symbol.iterator]()}get size(){return this._map.size}constructor(t){this._initValue=t,this._map=new Map}get(t){let e=this.find(t);return void 0===e&&this._map.set(t,e=this._initValue()),e}find(t){return this._map.get(t)}has(t){return this._map.has(t)}clear(){this._map.clear()}delete(t){return this._map.delete(t)}set(t,e){return this._map.set(t,e),e}forEach(t,e){this._map.forEach(t,e)}}class I{get size(){return this._queue.length}get capacity(){return this._capacity}set capacity(t){this._capacity=t,null!=t&&this._queue.length>t&&this._queue.splice(0,this._queue.length-t)}get front(){return this._queue[0]}get back(){return this._queue[this._queue.length-1]}[Symbol.iterator](){return this._queue[Symbol.iterator]()}constructor(t){this._capacity=t,this._queue=new Array}push(t){return null!=this._capacity&&this._queue.push(t)>this._capacity&&this.pop(),this}pop(){return this._queue.shift()}clear(){return this._queue.length=0,this}}class L extends I{get minimum(){return this._min}get maximum(){return this._max}get average(){return null==this._average&&(this._average=this.size?this._sum/this.size:0),this._average}constructor(t){super(t),this._sum=0,this._min=0,this._max=0}push(t){return t>this._max?this._max=t:t<this._min&&(this._min=t),this._average=void 0,this._sum+=t,super.push(t),this}pop(){const t=super.pop();return t===this._max?this._max=Math.max(0,...this):t===this._min&&(this._min=Math.min(0,...this)),this._average=void 0,this._sum-=t||0,t}clear(){return this._min=this._max=this._sum=0,super.clear(),this}}const F={fromString(t){if(Array.isArray(t))return t;const e=new Array;let i,s=e;for(let n of t.toString().split("\n")){if(n=n.trim(),!n)continue;let t=n[0];const r=n.substring(n.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!r)continue;t=this.addAttribute(s,r),e===s&&"fingerprint"===t.toLowerCase()&&(i=s.fingerprint);break;case"m":e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e.push(s={m:r});break;default:s[t]=r}}return e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e},toString(t){if("string"==typeof t)return t;const e=[];let i="v"in t?"v="+t.v+"\n":"";"o"in t&&(i+="o="+t.o+"\n"),"s"in t&&(i+="s="+t.s+"\n");const s=t;for(const n of Object.keys(t)){if("v"===n||"o"===n||"s"===n)continue;const t=s[n];if(null==t)continue;const r=parseInt(n);if(!isNaN(r)){e[r]=t;continue}const h=Array.isArray(t)&&t.length||1;for(let e=0;e<h;++e){const s=Array.isArray(t)&&t.length?t[e]:t;n.length>1?(i+="a="+n,s&&(i+=":")):i+=n+"=",i+=s+"\n"}}for(const t of e)i+=this.toString(t);return i},addAttribute(t,e){var i;const s=F.parseAttribute(e),n=null!==(i=s.value)&&void 0!==i?i:"",r=t,h=r[s.key];return h?Array.isArray(h)?h.push(n):n!==h&&(r[s.key]=[h,n]):r[s.key]=n,s.key},removeAttribute(t,e){const i=F.parseAttribute(e),s=t;if(void 0===i.value)return delete s[e],e;const n=s[e];if(Array.isArray(i.value)){const t=n.findIndex((t=>t===i.value));t>=0&&n.splice(t,1)}else n===i.value&&delete s[e];return i.key},parseAttribute(t){const e=t.indexOf(":");return{key:(e>=0?t.substring(0,e):t).trim(),value:e>=0?t.substring(e+1).trim():void 0}}};Object.freeze(F);class N extends U{onOpen(){}onMessage(t){}onClose(t){t?this.log("onClose",t).error():this.log("onClose").info()}get binaryType(){return"arraybuffer"}get recvByteRate(){return this._recvByteRate.value()}get sendByteRate(){return this._sendByteRate.value()}get url(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.url)&&void 0!==e?e:""}get extensions(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.extensions)&&void 0!==e?e:""}get protocol(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.protocol)&&void 0!==e?e:""}get opened(){return this._opened}get readyState(){return this._ws?this._ws.readyState:3}get closed(){return this._closed}get bufferedAmount(){var t;return this._queueingBytes+((null===(t=this._ws)||void 0===t?void 0:t.bufferedAmount)||0)}get queueing(){return this._queueing}constructor(t,e){super(),this._queueing=[],this._queueingBytes=0,this._opened=!1,this._closed=!0,this._recvByteRate=new E,this._sendByteRate=new E,t&&this.open(t,e)}open(t,e){this._closed=!1;const i=this._ws=new WebSocket(t,e);return i.binaryType=this.binaryType,i.onmessage=t=>{var e;this._recvByteRate.addBytes(null!==(e=t.data.byteLength)&&void 0!==e?e:t.data.length),this.onMessage(t.data)},i.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close({type:"WebSocketReliableError",name:"Server shutdown",url:t.toString()}):this.close({type:"WebSocketReliableError",name:"Socket disconnection",url:t.toString(),reason:String(e.reason||e.code)}):this.close({type:"WebSocketReliableError",name:"Connection failed",url:t.toString(),reason:String(e.reason||e.code)})},i.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(this._closed)throw Error("Open socket before to send data");return e||!this._opened?(this._queueing.push(t),this._queueingBytes+="string"==typeof t?t.length:t.byteLength):this._send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._send(t);this._queueing.length=0,this._queueingBytes=0}close(t){this._ws&&!this._closed&&(this._closed=!0,this._ws.onopen=this._ws.onclose=this._ws.onmessage=null,this._ws.close(),this._queueing.length=0,this._queueingBytes=0,this.onClose(t),this._opened=!1)}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}function W(t,e,i=32,s=.2){const n=e/i;let r="",h=n/2;const o=t.getImageData(0,Math.round(h),e,1).data,a=new Uint32Array(o.buffer),l=255*s,u=255*(1-s);for(;h<a.length;){const t=16777215&a[Math.round(h)],e=.299*(t>>16&255)+.587*(t>>8&255)+.114*(255&t);if(e<l)r+="1";else{if(!(e>u))return;r+="0"}h+=n}const c=parseInt(r.slice(0,5),2),_=parseInt(r.slice(5,10),2),d=parseInt(r.slice(10,16),2),g=parseInt(r.slice(16,22),2),f=parseInt(r.slice(22,32),2),p=new Date;return new Date(Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),c,_,d,g,f))}var R=Object.freeze({__proto__:null,decodeTimestamp:W,encodeTimestamp:function(t,e,i=32,s=new Date){const n=Math.floor(e/i),r=s.getUTCDate(),h=s.getUTCHours(),o=s.getUTCMinutes(),a=s.getUTCSeconds(),l=s.getUTCMilliseconds(),u=r.toString(2).padStart(5,"0")+h.toString(2).padStart(5,"0")+o.toString(2).padStart(6,"0")+a.toString(2).padStart(6,"0")+l.toString(2).padStart(10,"0");for(let e=0;e<u.length;e++){const s=e%i*n,r=Math.floor(e/i)*n;t.fillStyle="1"===u[e]?"black":"white",t.fillRect(s,r,n,n)}},getLatency:function(t,e,i,s=new Date,n=32,r=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/n),!e.width||!e.height)return 0;i.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const h=W(i,e.width,n,r);return null==h?0:s.getTime()-h.getTime()}});class B{get graphMargin(){return this._graphMargin}set graphMargin(t){this._graphMargin=t}get textMargin(){return this._textMargin}set textMargin(t){this._textMargin=t}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight=t}get labelWidth(){return this._labelWidth}set labelWidth(t){this._labelWidth=t}get legendFontSize(){return this._legendFontSize}set legendFontSize(t){this._legendFontSize=t}get stepSize(){return this._stepSize}set stepSize(t){this._stepSize=t}get averageDisplayWidth(){return this._legendFontSize/2*7}get displayableCount(){const t=this._ui.clientWidth-this.averageDisplayWidth;return Math.ceil((t-this._labelWidth)/this._stepSize)}constructor(t){this._ui=t,this._lineHeight=40,this._labelWidth=170,this._graphMargin=5,this._textMargin=5,this._legendFontSize=13,this._stepSize=10,this._ranges={}}reset(){this._ranges={}}display(t){if(null!=this._html)return;this._html="";const e=this.averageDisplayWidth,i=e/2,s=this._ui.clientWidth-e,n=this._lineHeight-2*this._graphMargin,r=Math.round(this._lineHeight/2),h=Math.round(this._lineHeight/2+this._textMargin),o=this._labelWidth-2*this._textMargin;for(const[e,a]of t){const t=Math.ceil((s-this._labelWidth)/this._stepSize),l=a.slice(Math.max(0,a.length-t));if(!l.length)continue;let u=this._labelWidth+l.length*this._stepSize;this._html+='<svg class="list-group-item p-0" style="height: '+this._lineHeight+'px" xmlns="http://www.w3.org/2000/svg">',this._html+='<text x="'+this._textMargin+'" y="'+h+'">'+e+"</text>",this._html+='<text x="'+o+'" y="'+h+'" text-anchor="end">'+l[l.length-1].toString()+"</text>",this._html+='<path fill="none" d="M'+this._labelWidth+" "+r,this._html+="H"+(s+i),this._html+='" stroke-width="1" stroke="lightgray" stroke-dasharray="10,10"/>',this._html+='<path fill="none" stroke-width="1" stroke="brown" d="M';let c=Number.POSITIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(let t=0;t<l.length;++t){const e=parseFloat(l[t].toString());e<c&&(c=e),e>_&&(_=e)}let d=this._ranges[e];d||(this._ranges[e]=d={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}),d.min=Math.min(d.min,c),d.max=Math.max(d.max,_);const g=d.max-d.min;let f="",p="";for(let t=0;t<l.length;++t){u-=this._stepSize;const e=parseFloat(l[t].toString()),i=r+(g?Math.round((.5-(e-d.min)/g)*n):0);this._html+=u+" "+i+" ",e===c?p=p||this._drawCircle(u,i,e):e===_&&(f=f||this._drawCircle(u,i,e))}this._html+='" />';const m=Math.round((_-c)/2);this._html+='<text text-anchor="middle" font-size="'+this._legendFontSize+'" y="'+h+'">',this._html+='<tspan x="'+(s+i)+'" dy="-0.5em">'+(c!==_?"≈":"=")+(c+m)+"</tspan>",this._html+='<tspan x="'+(s+i)+'" dy="1em">±'+m+"</tspan>",this._html+="</text>",this._html+=f+p,this._html+="</svg>"}requestAnimationFrame((()=>{null!=this._html&&(this._ui.innerHTML=this._html,this._html=void 0)}))}_drawCircle(t,e,i){let s='<circle cx="'+t+'" cy="'+e+'" r="2" fill="green" />';const n=.7*this._legendFontSize;return e<Math.round(this._lineHeight/2)?e+=this.textMargin+n:e-=this.textMargin,s+='<text font-style="italic" font-size="'+this._legendFontSize+'" x="'+(t-this._legendFontSize)+'" y="'+e+'">'+i+"</text>",s}}const q="3.2.1";export{e as BinaryReader,b as BinaryWriter,A as BitReader,E as ByteRate,k as Connect,R as EpochTime,U as EventEmitter,C as FixMap,x as Log,p as LogLevel,S as Loggable,M as NetAddress,L as Numbers,I as Queue,F as SDP,B as UIMetrics,m as Util,q as VERSION,N as WebSocketReliable,z as log};//# sourceMappingURL=web-utils.min.js.map