New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ceeblue/web-utils

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ceeblue/web-utils - npm Package Compare versions

Comparing version 2.6.1 to 3.0.0

215

dist/web-utils.d.ts

@@ -76,5 +76,119 @@ declare class BinaryReader {

/**
* Log levels
*/
declare enum LogLevel {
ERROR = "error",
WARN = "warn",
INFO = "info",
DEBUG = "debug"
}
/**
* Log interface to deal with log everywhere:
* - filter log level: filter log level independantly of the browser
* - subscribe logs: listen logs to effectuate some specific job related logs
* - intercept logs: intercept logs to change the default behavior
* - redirect logs: redirect logs to one other logger engine
* - redefine logs: change log text like adding a prefix
*
* You have 4 {@link LogLevel} 'error','warn','info',and 'debug', as commonly managed by browsers.
* You can use {@link ILog.level} or {@link ILog.on} to customer log level and behavior.
*
* @example
* // filter log level globally, independantly of the browser
* import { log } from '@ceeblue/web-utils';
* log.level = LogLevel.WARN; // displays errors and warns
*
* // filter log level only for Player compoment
* player.log.level = false; // no logs at all for player compoment
*
* // Intercept and redirect all the logs to the console (default behavior)
* import { log } from '@ceeblue/web-utils';
* log.on = (level:LogLevel,args:unknown[]) => {
* console[level](...args.splice(0)); // args is empty after this call = final interception
* }
*
* // Intercept the logs from Player compoment and displays only WARN logs
* player.log.on = (level:LogLevel,args:unknown[]) => {
* if (level !== LogLevel.WARN) {
* args.length = 0; // args is empty after this call = final interception
* }
* }
*
* // Subscribe and redirect all the logs to a file logger
* import { log } from '@ceeblue/web-utils';
* log.on = (level:LogLevel,args:unknown[]) => {
* fileLogger[level](...args); // args stays unchanged to let's continue the default behavior
* }
*
* // Redefine the log to add some prefix indication
* class Player {
* connector = new Connector();
* constructor() {
* connector.log = this.log.bind(this,"Connector log:");
* }
* }
*
*/
interface ILog {
/**
* Build a log
*/
(...args: unknown[]): Log;
/**
* Intercept,redefine or redirect any log
* If you clear args you intercept the log and nothing happen more after this call.
* @param type log level
* @param args args
* @returns
*/
on: (level: LogLevel, args: unknown[]) => void;
/**
* Change log level, default log level is {@link LogLevel.INFO},
* Boolean can be user to lets pass all the logs with `true` or disables all the logs with `false`.
* @note To debug production code without modifying it you can use a special query parameter
* called !cb-override-log-level to override this configuration.
*/
level?: LogLevel | boolean;
}
/**
* Log instance
*/
declare class Log {
get error(): (...args: any[]) => void;
get warn(): (...args: any[]) => void;
get info(): (...args: any[]) => void;
get debug(): (...args: any[]) => void;
private _args;
private _done?;
private _log;
constructor(log: ILog, ...args: unknown[]);
private _onLog;
private _bind;
}
/**
* Inherits from this class to use logs
*/
declare class Loggable {
/**
* Start a log
* @param args
* @returns a Log object with the levels of log to call
*/
log: ILog;
}
/**
* Global log
*/
declare const log: ILog;
/**
* Copyright 2024 Ceeblue B.V.
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
*/
/**
* BitReader allows to read binary data bit by bit
*/
declare class BitReader {
declare class BitReader extends Loggable {
private _data;

@@ -188,97 +302,4 @@ private _size;

*/
/**
* Log interface to deal with log everywhere:
* - subscribe logs: listen logs to effectuate some specific job related logs
* - intercept logs: intercept logs to change the default behavior
* - redirect logs: redirect logs to one other logger engine
* - redefine logs: change log text like adding a prefix
*
* You have 4 {@link LogType} 'error', 'warn', 'info', and 'debug', as commonly managed by browsers.
*
* @example
* // Intercept and redirect all the logs to the console (default behavior)
* import { log } from '@ceeblue/web-utils';
* log.on(type:LogType, args:uknown[]) => {
* console[type](...args.splice(0)); // args is empty after this call = final interception
* }
*
* // Intercept and redirect the logs from Player compoment to the console
* player.log.on(type:LogType, args:uknown[]) => {
* console[type](...args.splice(0)); // args is empty after this call = final interception
* }
*
* // Subscribe and redirect all the logs to a file logger
* log.on(type:LogType, args:uknown[]) => {
* fileLogger[type](...args); // args stays unchanged to let's continue the default behavior
* }
*
* // Redefine the log to add some prefix indication
* class Player {
* connector = new Connector();
* constructor() {
* connector.log = this.log.bind(this, "Connector log:");
* }
* }
*
*/
interface ILog {
/**
* Build a log
*/
(...args: unknown[]): Log;
/**
* Intercept, redefine or redirect any log
* If you clear args you intercept the log and nothing happen more after this call.
* @param type log level
* @param args args
* @returns
*/
on: (type: LogType, args: unknown[]) => void;
}
/**
* Log types
*/
declare enum LogType {
ERROR = "error",
WARN = "warn",
INFO = "info",
DEBUG = "debug"
}
/**
* Log instance
*/
declare class Log {
get error(): (...args: any[]) => void;
get warn(): (...args: any[]) => void;
get info(): (...args: any[]) => void;
get debug(): (...args: any[]) => void;
private _args;
private _done?;
private _onLog;
constructor(onLog: Function, ...args: unknown[]);
private _bind;
}
/**
* Inherits from this class to use logs
*/
declare class Loggable {
/**
* Start a log
* @param args
* @returns a Log object with the levels of log to call
*/
log: ILog;
}
/**
* Global log
*/
declare const log: ILog;
/**
* Copyright 2024 Ceeblue B.V.
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
*/
/**
* A advanced EventEmitter which allows to declare event as natural function in the inheriting children class,

@@ -699,3 +720,3 @@ * function must start by `on` prefix to be recognized as an event.

*/
declare function options(urlOrQueryOrSearch?: URL | URLSearchParams | string | object | undefined): object;
declare function options(urlOrQueryOrSearch?: URL | URLSearchParams | string | object | undefined): any;
/**

@@ -711,3 +732,3 @@ * Returns an easy-to-use Javascript object something iterable, such as a Map, Set, or Array

noEmptyString: boolean;
}): object;
}): any;
/**

@@ -1027,2 +1048,2 @@ * Returns entries from something iterable, such as a Map, Set, or Array

export { BinaryReader, BinaryWriter, BitReader, ByteRate, Connect, EpochTime, EventEmitter, FixMap, type ILog, Log, LogType, Loggable, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable, type WebSocketReliableError, log };
export { BinaryReader, BinaryWriter, BitReader, ByteRate, Connect, EpochTime, EventEmitter, FixMap, type ILog, Log, LogLevel, Loggable, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable, type WebSocketReliableError, log };

@@ -1,1 +0,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))}}const i=new TextEncoder;class s{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){return this.reserve(this._size+t.length),this._data.set(t,this._size),this._size+=t.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(i.encode(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}}class r{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._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?(console.warn("Exponential-Golomb code exceeding unsigned 16 bits"),0):e+(1<<t)-1}}function n(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o=new TextDecoder,a=new TextEncoder,h=performance,u=()=>{};function c(){return Math.floor(h.now())}function l(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,r]of _(t)){if(t=r,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 _(t){return t.entries?t.entries():Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}function d(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function f(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 p(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;return t.substring(s)}var b,m=Object.freeze({__proto__:null,EMPTY_FUNCTION:u,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 n(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:d,getFile:f,objectEntries:_,objectFrom:l,options:function(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})},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 s=e.error||e.message;if(s&&(e=s),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]":o.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 n="";for(const s in e)n+=(n?",":"{")+r+s+":",n+=t(e[s],Object.assign(Object.assign({},i),{recursion:i.recursion-1}));return n+(r+"}")},time:c,timeOrigin:function(){return Math.floor(h.now()+h.timeOrigin)},toBin:function(t){return a.encode(t)},trim:function(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;let r=t.length;for(;r>0&&i.includes(t.charCodeAt(r-1));)--r;return t.substring(s,r)},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:p});class y{onBytes(t){}get delta(){return this._delta}constructor(t=1e3){this._time=c(),this._value=NaN,this._delta=t,this._bytes=0}value(){return Math.round(this.exact())}exact(){const t=c(),e=t-this._time;return(e>this._delta||isNaN(this._value))&&(this._value=1e3*this._bytes/e,this._bytes=0,this._time=t),this._value}addBytes(t){return this._bytes+=t,this.onBytes(t),this}}class w{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))}}function v(t,e){switch(t){case b.HESP:e.mediaExt="mp4";break;case b.WEBRTC:e.mediaExt="rtp";break;case b.WRTS:try{const t=d(f(new URL(e.endPoint).pathname));t&&".json"!==t.toLowerCase()&&(e.mediaExt=t)}catch(t){}e.mediaExt||(e.mediaExt="rts");break;case b.META:e.mediaExt="js";break;case b.DATA:e.mediaExt="json";break;default:e.mediaExt="",console.warn("Unknown params type "+t)}p(e.mediaExt,".")}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(b||(b={}));var x=Object.freeze({__proto__:null,get Type(){return b},buildURL:function(t,e,i="wss"){v(t,e);const s=new URL(w.fixProtocol(i,e.endPoint));if(s.pathname.length<=1)switch(t){case b.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case b.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case b.WRTS:s.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case b.META:s.pathname="/json_"+e.streamName+".js";break;case b.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:v});let S=0;var A;setInterval((()=>{console.assert(0===S,S.toFixed(),"calls to log was useless")}),1e4),function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(A||(A={}));class z{get error(){return this._bind(A.ERROR)}get warn(){return this._bind(A.WARN)}get info(){return this._bind(A.INFO)}get debug(){return this._bind(A.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._onLog=t,++S}_bind(t){return this._done||(this._done=!0,--S),this._onLog&&this._onLog(t,this._args),this._args.length&&O.on&&O.on(t,this._args),this._args.length?console[t].bind(console,...this._args):u}}class E{constructor(){this.log=(...t)=>new z(this.log.on,...t)}}const O=(...t)=>new z((()=>{}),...t);class T extends E{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 r=(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)};Object.defineProperties(this,{[e]:{get:()=>r,set:t=>{s=t}}})}t=Object.getPrototypeOf(t)}}on(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add(e),i&&i.signal.addEventListener("abort",(()=>s.delete(e)),{once:!0})}once(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add(((...t)=>{s.delete(e),e(...t)})),i&&i.signal.addEventListener("abort",(()=>s.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 U{[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 k{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 C extends k{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 L={fromString(t){if(Array.isArray(t))return t;const e=new Array;let i,s=e;for(let r of t.toString().split("\n")){if(r=r.trim(),!r)continue;let t=r[0];const n=r.substring(r.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!n)continue;t=this.addAttribute(s,n),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:n});break;default:s[t]=n}}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 r of Object.keys(t)){if("v"===r||"o"===r||"s"===r)continue;const t=s[r];if(null==t)continue;const n=parseInt(r);if(!isNaN(n)){e[n]=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;r.length>1?(i+="a="+r,s&&(i+=":")):i+=r+"=",i+=s+"\n"}}for(const t of e)i+=this.toString(t);return i},addAttribute(t,e){var i;const s=L.parseAttribute(e),r=null!==(i=s.value)&&void 0!==i?i:"",n=t,o=n[s.key];return o?Array.isArray(o)?o.push(r):r!==o&&(n[s.key]=[o,r]):n[s.key]=r,s.key},removeAttribute(t,e){const i=L.parseAttribute(e),s=t;if(void 0===i.value)return delete s[e],e;const r=s[e];if(Array.isArray(i.value)){const t=r.findIndex((t=>t===i.value));t>=0&&r.splice(t,1)}else r===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(L);class R extends T{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 y,this._sendByteRate=new y,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 B(t,e,i=32,s=.2){const r=e/i;let n="",o=r/2;const a=t.getImageData(0,Math.round(o),e,1).data,h=new Uint32Array(a.buffer),u=255*s,c=255*(1-s);for(;o<h.length;){const t=16777215&h[Math.round(o)],e=.299*(t>>16&255)+.587*(t>>8&255)+.114*(255&t);if(e<u)n+="1";else{if(!(e>c))return;n+="0"}o+=r}const l=parseInt(n.slice(0,5),2),_=parseInt(n.slice(5,10),2),d=parseInt(n.slice(10,16),2),f=parseInt(n.slice(16,22),2),g=parseInt(n.slice(22,32),2),p=new Date;return new Date(Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),l,_,d,f,g))}var j=Object.freeze({__proto__:null,decodeTimestamp:B,encodeTimestamp:function(t,e,i=32,s=new Date){const r=Math.floor(e/i),n=s.getUTCDate(),o=s.getUTCHours(),a=s.getUTCMinutes(),h=s.getUTCSeconds(),u=s.getUTCMilliseconds(),c=n.toString(2).padStart(5,"0")+o.toString(2).padStart(5,"0")+a.toString(2).padStart(6,"0")+h.toString(2).padStart(6,"0")+u.toString(2).padStart(10,"0");for(let e=0;e<c.length;e++){const s=e%i*r,n=Math.floor(e/i)*r;t.fillStyle="1"===c[e]?"black":"white",t.fillRect(s,n,r,r)}},getLatency:function(t,e,i,s=new Date,r=32,n=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/r),!e.width||!e.height)return 0;i.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const o=B(i,e.width,r,n);return null==o?0:s.getTime()-o.getTime()}});const q="2.6.1";export{e as BinaryReader,s as BinaryWriter,r as BitReader,y as ByteRate,x as Connect,j as EpochTime,T as EventEmitter,U as FixMap,z as Log,A as LogType,E as Loggable,w as NetAddress,C as Numbers,k as Queue,L as SDP,m as Util,q as VERSION,R as WebSocketReliable,O as log};//# sourceMappingURL=web-utils.min.js.map
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))}}const i=new TextEncoder;class s{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){return this.reserve(this._size+t.length),this._data.set(t,this._size),this._size+=t.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(i.encode(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 r(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=new TextDecoder,o=new TextEncoder,a=performance,h=()=>{};function u(){return Math.floor(a.now())}function c(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,r]of _(t)){if(t=r,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 _(t){return t.entries?t.entries():Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}function d(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function f(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 p(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;return t.substring(s)}var b,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 r(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:d,getFile:f,objectEntries:_,objectFrom:l,options:c,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 s=e.error||e.message;if(s&&(e=s),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]":n.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:u,timeOrigin:function(){return Math.floor(a.now()+a.timeOrigin)},toBin:function(t){return o.encode(t)},trim:function(t,e=" "){const i=g(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;let r=t.length;for(;r>0&&i.includes(t.charCodeAt(r-1));)--r;return t.substring(s,r)},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:p});!function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(b||(b={}));let y=0;setInterval((()=>{console.assert(0===y,y.toFixed(),"calls to log was useless")}),1e4);const w=c()["!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(b.ERROR)}get warn(){return this._bind(b.WARN)}get info(){return this._bind(b.INFO)}get debug(){return this._bind(b.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._log=t,++y}_onLog(t,e){var i,s;const r=null!==(s=null!==(i=null!=w?w:t.level)&&void 0!==i?i:A.level)&&void 0!==s?s:b.INFO;return!1!==r&&(!(!0!==r&&v[e.charCodeAt(0)]>v[r.charCodeAt(0)])&&(t.on&&t.on(e,this._args),!!this._args.length))}_bind(t){return this._done||(this._done=!0,--y),this._onLog(A,t)&&(this._log===A||this._onLog(this._log,t))?console[t].bind(console,...this._args):h}}class S{constructor(){this.log=(...t)=>new x(this.log,...t)}}const A=(...t)=>new x(A,...t);class z 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 delta(){return this._delta}constructor(t=1e3){this._time=u(),this._value=NaN,this._delta=t,this._bytes=0}value(){return Math.round(this.exact())}exact(){const t=u(),e=t-this._time;return(e>this._delta||isNaN(this._value))&&(this._value=1e3*this._bytes/e,this._bytes=0,this._time=t),this._value}addBytes(t){return this._bytes+=t,this.onBytes(t),this}}class O{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 T;function U(t,e){switch(t){case T.HESP:e.mediaExt="mp4";break;case T.WEBRTC:e.mediaExt="rtp";break;case T.WRTS:try{const t=d(f(new URL(e.endPoint).pathname));t&&".json"!==t.toLowerCase()&&(e.mediaExt=t)}catch(t){}e.mediaExt||(e.mediaExt="rts");break;case T.META:e.mediaExt="js";break;case T.DATA:e.mediaExt="json";break;default:e.mediaExt="",console.warn("Unknown params type "+t)}p(e.mediaExt,".")}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(T||(T={}));var k=Object.freeze({__proto__:null,get Type(){return T},buildURL:function(t,e,i="wss"){U(t,e);const s=new URL(O.fixProtocol(i,e.endPoint));if(s.pathname.length<=1)switch(t){case T.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case T.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case T.WRTS:s.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case T.META:s.pathname="/json_"+e.streamName+".js";break;case T.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:U});class C 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 r=(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)};Object.defineProperties(this,{[e]:{get:()=>r,set:t=>{s=t}}})}t=Object.getPrototypeOf(t)}}on(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add(e),i&&i.signal.addEventListener("abort",(()=>s.delete(e)),{once:!0})}once(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add(((...t)=>{s.delete(e),e(...t)})),i&&i.signal.addEventListener("abort",(()=>s.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 L{[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 R{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 B extends R{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 j={fromString(t){if(Array.isArray(t))return t;const e=new Array;let i,s=e;for(let r of t.toString().split("\n")){if(r=r.trim(),!r)continue;let t=r[0];const n=r.substring(r.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!n)continue;t=this.addAttribute(s,n),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:n});break;default:s[t]=n}}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 r of Object.keys(t)){if("v"===r||"o"===r||"s"===r)continue;const t=s[r];if(null==t)continue;const n=parseInt(r);if(!isNaN(n)){e[n]=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;r.length>1?(i+="a="+r,s&&(i+=":")):i+=r+"=",i+=s+"\n"}}for(const t of e)i+=this.toString(t);return i},addAttribute(t,e){var i;const s=j.parseAttribute(e),r=null!==(i=s.value)&&void 0!==i?i:"",n=t,o=n[s.key];return o?Array.isArray(o)?o.push(r):r!==o&&(n[s.key]=[o,r]):n[s.key]=r,s.key},removeAttribute(t,e){const i=j.parseAttribute(e),s=t;if(void 0===i.value)return delete s[e],e;const r=s[e];if(Array.isArray(i.value)){const t=r.findIndex((t=>t===i.value));t>=0&&r.splice(t,1)}else r===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(j);class q extends C{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 M(t,e,i=32,s=.2){const r=e/i;let n="",o=r/2;const a=t.getImageData(0,Math.round(o),e,1).data,h=new Uint32Array(a.buffer),u=255*s,c=255*(1-s);for(;o<h.length;){const t=16777215&h[Math.round(o)],e=.299*(t>>16&255)+.587*(t>>8&255)+.114*(255&t);if(e<u)n+="1";else{if(!(e>c))return;n+="0"}o+=r}const l=parseInt(n.slice(0,5),2),_=parseInt(n.slice(5,10),2),d=parseInt(n.slice(10,16),2),f=parseInt(n.slice(16,22),2),g=parseInt(n.slice(22,32),2),p=new Date;return new Date(Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),l,_,d,f,g))}var N=Object.freeze({__proto__:null,decodeTimestamp:M,encodeTimestamp:function(t,e,i=32,s=new Date){const r=Math.floor(e/i),n=s.getUTCDate(),o=s.getUTCHours(),a=s.getUTCMinutes(),h=s.getUTCSeconds(),u=s.getUTCMilliseconds(),c=n.toString(2).padStart(5,"0")+o.toString(2).padStart(5,"0")+a.toString(2).padStart(6,"0")+h.toString(2).padStart(6,"0")+u.toString(2).padStart(10,"0");for(let e=0;e<c.length;e++){const s=e%i*r,n=Math.floor(e/i)*r;t.fillStyle="1"===c[e]?"black":"white",t.fillRect(s,n,r,r)}},getLatency:function(t,e,i,s=new Date,r=32,n=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/r),!e.width||!e.height)return 0;i.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const o=M(i,e.width,r,n);return null==o?0:s.getTime()-o.getTime()}});const P="3.0.0";export{e as BinaryReader,s as BinaryWriter,z as BitReader,E as ByteRate,k as Connect,N as EpochTime,C as EventEmitter,L as FixMap,x as Log,b as LogLevel,S as Loggable,O as NetAddress,B as Numbers,R as Queue,j as SDP,m as Util,P as VERSION,q as WebSocketReliable,A as log};//# sourceMappingURL=web-utils.min.js.map
{
"name": "@ceeblue/web-utils",
"version": "2.6.1",
"version": "3.0.0",
"description": "Ceeblue web framework",

@@ -5,0 +5,0 @@ "keywords": [

@@ -30,2 +30,9 @@ [Usage](#usage) | [Building locally](#building-locally) | [Documentation](#documentation) | [Contribution](#contribution) | [License](#license)

> ⚠️ **REMARKS**
>
> To debug production code without modifying it, the library can use special query parameter of the main page's URL:
> - __!cb-override-log-level__ : allows to override the log level for the entire library, see [Log.ts](./src/Log.ts) for details on handling log levels.
## Building locally

@@ -32,0 +39,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc