Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ceeblue/web-utils

Package Overview
Dependencies
Maintainers
4
Versions
17
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 1.0.0 to 1.0.1

34

dist/web-utils.d.ts
/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -40,3 +40,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -74,6 +74,9 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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 {

@@ -153,3 +156,3 @@ private _data;

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -229,3 +232,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -253,3 +256,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -312,3 +315,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -378,3 +381,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -431,3 +434,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -550,3 +553,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -594,2 +597,8 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Returns entries from something iterable, such as a Map, Set, or Array
* @param value iterable input
* @returns An javascript object
*/
declare function objectEntries(value: any): [string, any][];
/**
* Converts various data types, such as objects, strings, exceptions, errors,

@@ -613,2 +622,3 @@ * or numbers, into a string representation. Since it offers a more comprehensive format,

declare const Util_VERSION: typeof VERSION;
declare const Util_objectEntries: typeof objectEntries;
declare const Util_objectFrom: typeof objectFrom;

@@ -621,7 +631,7 @@ declare const Util_options: typeof options;

declare namespace Util {
export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_VERSION as VERSION, Util_objectFrom as objectFrom, Util_options as options, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_VERSION as VERSION, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
}
/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -628,0 +638,0 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -113,3 +113,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -291,6 +291,9 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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
*/
class BitReader {

@@ -355,3 +358,3 @@ constructor(data) {

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -480,3 +483,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -539,3 +542,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}var Connect=/*#__PURE__*/Object.freeze({__proto__:null,get Type(){return Type},buildURL:buildURL});/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -683,3 +686,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -773,3 +776,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -859,3 +862,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

}/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -1103,3 +1106,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

Object.freeze(SDP);/**
* Copyright 2023 Ceeblue B.V.
* 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.

@@ -1118,3 +1121,3 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

*/
const VERSION = '1.0.0';
const VERSION = '1.0.1';
/**

@@ -1288,4 +1291,4 @@ * An empty lambda function, pratical to disable default behavior of function or events which are not expected to be null

return _encoder.encode(value);
}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,VERSION:VERSION,objectFrom:objectFrom,options:options,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin});/**
* Copyright 2023 Ceeblue B.V.
}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,VERSION:VERSION,objectEntries:objectEntries,objectFrom:objectFrom,options:options,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin});/**
* 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.

@@ -1292,0 +1295,0 @@ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.

@@ -1,1 +0,1 @@

class t{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=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+=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}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){if(t>5)throw Error("BinaryReader in JS can't decode more than 32 usefull bits");if(!(t>0))throw Error("Have to indicate a positive number of bytes to decode");let e,i=0;do{if(e=this.read8(),! --t)return(i<<8|e)>>>0;i=i<<7|127&e}while(128&e);return i}readString(){return String.fromCharCode(...this.read(this.read7Bit()))}readHex(t){let e="";for(;t--;)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._data.subarray(this._position,this._position+t);return this._position+=t,e}}class e{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){if(this.reserve(this._size+t.length),"string"==typeof t){for(let e=0;e<t.length;++e){const i=t.charCodeAt(e);this._data[this._size++]=i>255?32:i}return this}return 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}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,e=5){if(e>5)throw Error("BinaryWriter in JS can't encode more than 32 usefull bits");if(!(e>0))throw Error("Have to indicate a positive number of bytes to encode");let i=7*--e;const s=t>4294967295?256:t>>>i;if(s)++i,s>255&&(t=4294967295);else for(;(i-=7)&&!(t>>>i););for(;i>1;)this.write8(128|t>>>i&255),i-=7;return this.write8(t&(i?255:127))}writeString(t){return this.write7Bit(t.length).write(t)}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 new Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw new 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 i{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)}}class s{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 r;!function(t){t.HESP="hesp",t.WEBRTS="webrts",t.WEBRTC="webrtc",t.META="meta",t.DATA="data"}(r||(r={}));var n=Object.freeze({__proto__:null,get Type(){return r},buildURL:function(t,e,i="wss"){const n=new URL(s.fixProtocol(i,e.host));if(n.pathname.length<=1)switch(t){case r.HESP:n.pathname="/hesp/"+e.streamName+"/index.json";break;case r.WEBRTC:n.pathname="/webrtc/"+e.streamName;break;case r.WEBRTS:n.pathname="/webrts/"+e.streamName;break;case r.META:n.pathname="/json_"+e.streamName+".js";break;case r.DATA:n.pathname="/"+e.streamName+".json";break;default:console.warn("Unknown url type "+t)}e.accessToken&&n.searchParams.set("id",e.accessToken);for(const t in e.query)n.searchParams.set(t,e.query[t]);return n}});class o{constructor(){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];Object.defineProperties(this,{[e]:{get:()=>(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)},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(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add((()=>{s.delete(e),e()})),i&&i.signal.addEventListener("abort",(()=>{s.delete(e)}))}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 h{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 a extends h{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 u={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=u.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=u.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(u);const _=new TextDecoder,c=new TextEncoder,l=performance;function d(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,r]of function(t){if(t.entries)return t.entries();return Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}(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}var f=Object.freeze({__proto__:null,EMPTY_FUNCTION:()=>{},VERSION:"1.0.0",objectFrom:d,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 d(t,{withType:!0,noEmptyString:!0})},stringify:function t(e,i={}){if(i=Object.assign({space:" ",decimal:2,recursive:1},i),!e)return String(e);const s=e.error||e.message;if(s&&(e=s),e.toFixed)return e.toFixed(Number(i.decimal)||0);if(e.substring||!i.recursive)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(i,{recursive:i.recursive-1}));return s+=r+"]"}if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return _.decode(e);let n="";for(const s in e)n+=(n?",":"{")+r+s+":",n+=t(e[s],Object.assign(i,{recursive:i.recursive-1}));return n+(r+"}")},time:function(){return Math.floor(l.now())},timeOrigin:function(){return Math.floor(l.now()+l.timeOrigin)},toBin:function(t){return c.encode(t)}});class g extends o{onOpen(){}onMessage(t){}onClose(t){t&&console.error(t)}get binaryType(){return"arraybuffer"}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,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=>this.onMessage(t.data),i.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close(t.toString()+" shutdown"):this.close(t.toString()+" disconnection ("+String(e.reason||e.code)+")"):this.close(t.toString()+" connection failed ("+String(e.reason||e.code)+")")},i.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(!this._ws)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._ws.send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._ws.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._opened=!1,this._queueing.length=0,this._queueingBytes=0,this.onClose(t))}}export{t as BinaryReader,e as BinaryWriter,i as BitReader,n as Connect,o as EventEmitter,s as NetAddress,a as Numbers,h as Queue,u as SDP,f as Util,g as WebSocketReliable};//# sourceMappingURL=web-utils.min.js.map
class t{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=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+=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}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){if(t>5)throw Error("BinaryReader in JS can't decode more than 32 usefull bits");if(!(t>0))throw Error("Have to indicate a positive number of bytes to decode");let e,i=0;do{if(e=this.read8(),! --t)return(i<<8|e)>>>0;i=i<<7|127&e}while(128&e);return i}readString(){return String.fromCharCode(...this.read(this.read7Bit()))}readHex(t){let e="";for(;t--;)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._data.subarray(this._position,this._position+t);return this._position+=t,e}}class e{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){if(this.reserve(this._size+t.length),"string"==typeof t){for(let e=0;e<t.length;++e){const i=t.charCodeAt(e);this._data[this._size++]=i>255?32:i}return this}return 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}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,e=5){if(e>5)throw Error("BinaryWriter in JS can't encode more than 32 usefull bits");if(!(e>0))throw Error("Have to indicate a positive number of bytes to encode");let i=7*--e;const s=t>4294967295?256:t>>>i;if(s)++i,s>255&&(t=4294967295);else for(;(i-=7)&&!(t>>>i););for(;i>1;)this.write8(128|t>>>i&255),i-=7;return this.write8(t&(i?255:127))}writeString(t){return this.write7Bit(t.length).write(t)}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 new Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw new 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 i{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)}}class s{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 r;!function(t){t.HESP="hesp",t.WEBRTS="webrts",t.WEBRTC="webrtc",t.META="meta",t.DATA="data"}(r||(r={}));var n=Object.freeze({__proto__:null,get Type(){return r},buildURL:function(t,e,i="wss"){const n=new URL(s.fixProtocol(i,e.host));if(n.pathname.length<=1)switch(t){case r.HESP:n.pathname="/hesp/"+e.streamName+"/index.json";break;case r.WEBRTC:n.pathname="/webrtc/"+e.streamName;break;case r.WEBRTS:n.pathname="/webrts/"+e.streamName;break;case r.META:n.pathname="/json_"+e.streamName+".js";break;case r.DATA:n.pathname="/"+e.streamName+".json";break;default:console.warn("Unknown url type "+t)}e.accessToken&&n.searchParams.set("id",e.accessToken);for(const t in e.query)n.searchParams.set(t,e.query[t]);return n}});class o{constructor(){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];Object.defineProperties(this,{[e]:{get:()=>(...t)=>{s&&s.call(this,...t);for(const e of i)e(...t)},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(t,e,i){if(!e)throw Error("event to subscribe cannot be null");const s=this._event(t);s.add((()=>{s.delete(e),e()})),i&&i.signal.addEventListener("abort",(()=>{s.delete(e)}))}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 h{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 a extends h{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 u={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=u.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=u.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(u);const _=new TextDecoder,c=new TextEncoder,l=performance;function d(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,r]of f(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 f(t){return t.entries?t.entries():Array.from({[Symbol.iterator]:function*(){for(const e in t)yield[e,t[e]]}})}var g=Object.freeze({__proto__:null,EMPTY_FUNCTION:()=>{},VERSION:"1.0.1",objectEntries:f,objectFrom:d,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 d(t,{withType:!0,noEmptyString:!0})},stringify:function t(e,i={}){if(i=Object.assign({space:" ",decimal:2,recursive:1},i),!e)return String(e);const s=e.error||e.message;if(s&&(e=s),e.toFixed)return e.toFixed(Number(i.decimal)||0);if(e.substring||!i.recursive)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(i,{recursive:i.recursive-1}));return s+=r+"]"}if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return _.decode(e);let n="";for(const s in e)n+=(n?",":"{")+r+s+":",n+=t(e[s],Object.assign(i,{recursive:i.recursive-1}));return n+(r+"}")},time:function(){return Math.floor(l.now())},timeOrigin:function(){return Math.floor(l.now()+l.timeOrigin)},toBin:function(t){return c.encode(t)}});class p extends o{onOpen(){}onMessage(t){}onClose(t){t&&console.error(t)}get binaryType(){return"arraybuffer"}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,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=>this.onMessage(t.data),i.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close(t.toString()+" shutdown"):this.close(t.toString()+" disconnection ("+String(e.reason||e.code)+")"):this.close(t.toString()+" connection failed ("+String(e.reason||e.code)+")")},i.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(!this._ws)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._ws.send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._ws.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._opened=!1,this._queueing.length=0,this._queueingBytes=0,this.onClose(t))}}export{t as BinaryReader,e as BinaryWriter,i as BitReader,n as Connect,o as EventEmitter,s as NetAddress,a as Numbers,h as Queue,u as SDP,g as Util,p as WebSocketReliable};//# sourceMappingURL=web-utils.min.js.map
{
"name": "@ceeblue/web-utils",
"version": "1.0.0",
"version": "1.0.1",
"description": "Ceeblue web framework",

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

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