@ceeblue/web-utils
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -96,2 +96,18 @@ declare class BinaryReader { | ||
/** | ||
* Compute ByteRate every delta time | ||
*/ | ||
declare class ByteRate { | ||
onBytes(bytes: number): void; | ||
get delta(): number; | ||
private _bytes; | ||
private _time; | ||
private _delta; | ||
private _value; | ||
constructor(delta?: number); | ||
value(): number; | ||
exact(): number; | ||
addBytes(bytes: number): this; | ||
} | ||
/** | ||
* Parameters of connections | ||
@@ -233,2 +249,28 @@ */ | ||
/** | ||
* Some fix for JS MAP: | ||
* - find(key) search an item in the map and returns undefined if not found | ||
* - get(key) return the item if exists or otherwise create and returns it | ||
* - set(key, value) returns the value of the item (rather the MAP) | ||
*/ | ||
declare class FixMap<KeyType, ValueType> { | ||
private _initValue; | ||
[Symbol.iterator](): IterableIterator<[KeyType, ValueType]>; | ||
get size(): number; | ||
private _map; | ||
constructor(_initValue: () => ValueType); | ||
get(key: KeyType): ValueType; | ||
find(key: KeyType): ValueType | undefined; | ||
has(key: KeyType): boolean; | ||
clear(): void; | ||
delete(key: KeyType): boolean; | ||
set(key: KeyType, value: ValueType): ValueType; | ||
forEach(callbackfn: (value: ValueType, key: KeyType, map: Map<KeyType, ValueType>) => void, thisArg?: any): void; | ||
} | ||
/** | ||
* 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. | ||
*/ | ||
/** | ||
* Implement this interface to throw log and error | ||
@@ -779,2 +821,2 @@ */ | ||
export { BinaryReader, BinaryWriter, BitReader, Connect, EventEmitter, type ILog, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable }; | ||
export { BinaryReader, BinaryWriter, BitReader, ByteRate, Connect, EventEmitter, FixMap, type ILog, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable }; |
@@ -344,126 +344,2 @@ /** | ||
} | ||
}/** | ||
* 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. | ||
*/ | ||
/** | ||
* Help class to manipulate and parse a net address. The Address can be only the domain field, | ||
* or a URL format with protocol and path part `(http://)domain(:port/path)` | ||
* @example | ||
* const address = new Address('nl-ams-42.live.ceeblue.tv:80'); | ||
* console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv' | ||
* console.log(address.port) // '80' | ||
* console.log(address) // 'nl-ams-42.live.ceeblue.tv:80' | ||
*/ | ||
class NetAddress { | ||
/** | ||
* Static help function to build an end point from an address `(proto://)domain(:port/path)` | ||
* | ||
* Mainly it fix the protocol, in addition if: | ||
* - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version | ||
* - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version | ||
* @param protocol protocol to set in the end point returned | ||
* @param address string address to fix with protocol as indicated | ||
* @returns the end point built | ||
* @example | ||
* console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path' | ||
* console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path' | ||
* console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path' | ||
*/ | ||
static fixProtocol(protocol, address) { | ||
const found = address.indexOf('://'); | ||
// isolate protocol is present in address | ||
if (found >= 0) { | ||
// In this case replace by protocol in keeping SSL like given in address | ||
if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') { | ||
// SSL! | ||
if (protocol.length <= 2 || !protocol.endsWith('s')) { | ||
protocol += 's'; // Add SSL | ||
} | ||
} | ||
else { | ||
// Not SSL! | ||
if (protocol.length > 2 && protocol.endsWith('s')) { | ||
protocol = protocol.slice(0, -1); // Remove SSL | ||
} | ||
} | ||
// Build host! | ||
address = address.substring(found + 3); | ||
} | ||
return protocol + '://' + address; | ||
} | ||
/** | ||
* The domain part from address `(http://)domain(:port/path)` | ||
*/ | ||
get domain() { | ||
return this._domain; | ||
} | ||
/** | ||
* The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor | ||
*/ | ||
get port() { | ||
return this._port; | ||
} | ||
/** | ||
* @returns the string address as passed in the constructor | ||
*/ | ||
toString() { | ||
return this._address; | ||
} | ||
/** | ||
* @returns the string address as passed in the constructor | ||
* @override | ||
*/ | ||
valueOf() { | ||
return this._address; | ||
} | ||
/** | ||
* Build a NetAddress object and parse address | ||
* @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)` | ||
* @param defaultPort set a default port to use if there is no port in the string address parsed | ||
*/ | ||
constructor(address, defaultPort) { | ||
this._address = address; | ||
// Remove Protocol | ||
let pos = address.indexOf('/'); | ||
if (pos >= 0) { | ||
// Remove :// | ||
if (address.charCodeAt(pos + 1) === 47) { | ||
// has // | ||
if (pos > 0) { | ||
if (address.charCodeAt(pos - 1) === 58) { | ||
// has :// | ||
address = address.substring(pos + 2); | ||
} // something else #// | ||
} | ||
else { | ||
// otherwise starts by // | ||
address = address.substring(2); | ||
} | ||
} | ||
else if (!pos) { | ||
// starts by /, remove it | ||
address = address.substring(1); | ||
} // else something else #/ | ||
} | ||
this._domain = address; | ||
this._port = defaultPort; | ||
// Parse Port | ||
pos = address.lastIndexOf(':'); | ||
if (pos >= 0) { | ||
const port = parseInt(address.substring(pos + 1)); | ||
if (port && port <= 0xffff) { | ||
this._port = port; | ||
this._domain = address.substring(0, pos); | ||
} | ||
} | ||
else { | ||
// Remove Path! | ||
pos = address.indexOf('/'); | ||
if (pos >= 0) { | ||
this._domain = address.substring(0, pos); | ||
} | ||
} | ||
} | ||
}/****************************************************************************** | ||
@@ -741,2 +617,164 @@ Copyright (c) Microsoft Corporation. | ||
/** | ||
* Compute ByteRate every delta time | ||
*/ | ||
class ByteRate { | ||
onBytes(bytes) { } | ||
get delta() { | ||
return this._delta; | ||
} | ||
constructor(delta = 1000) { | ||
this._time = time(); | ||
this._value = NaN; | ||
this._delta = delta; | ||
this._bytes = 0; | ||
} | ||
value() { | ||
return Math.round(this.exact()); | ||
} | ||
exact() { | ||
const now = time(); | ||
const elapsed = now - this._time; | ||
if (elapsed > this._delta || isNaN(this._value)) { | ||
// wait "_delta" before next compute rate | ||
this._value = (this._bytes * 1000) / elapsed; | ||
this._bytes = 0; | ||
this._time = now; | ||
} | ||
return this._value; | ||
} | ||
addBytes(bytes) { | ||
this._bytes += bytes; | ||
this.onBytes(bytes); | ||
return this; | ||
} | ||
}/** | ||
* 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. | ||
*/ | ||
/** | ||
* Help class to manipulate and parse a net address. The Address can be only the domain field, | ||
* or a URL format with protocol and path part `(http://)domain(:port/path)` | ||
* @example | ||
* const address = new Address('nl-ams-42.live.ceeblue.tv:80'); | ||
* console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv' | ||
* console.log(address.port) // '80' | ||
* console.log(address) // 'nl-ams-42.live.ceeblue.tv:80' | ||
*/ | ||
class NetAddress { | ||
/** | ||
* Static help function to build an end point from an address `(proto://)domain(:port/path)` | ||
* | ||
* Mainly it fix the protocol, in addition if: | ||
* - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version | ||
* - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version | ||
* @param protocol protocol to set in the end point returned | ||
* @param address string address to fix with protocol as indicated | ||
* @returns the end point built | ||
* @example | ||
* console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path' | ||
* console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path' | ||
* console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path' | ||
*/ | ||
static fixProtocol(protocol, address) { | ||
const found = address.indexOf('://'); | ||
// isolate protocol is present in address | ||
if (found >= 0) { | ||
// In this case replace by protocol in keeping SSL like given in address | ||
if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') { | ||
// SSL! | ||
if (protocol.length <= 2 || !protocol.endsWith('s')) { | ||
protocol += 's'; // Add SSL | ||
} | ||
} | ||
else { | ||
// Not SSL! | ||
if (protocol.length > 2 && protocol.endsWith('s')) { | ||
protocol = protocol.slice(0, -1); // Remove SSL | ||
} | ||
} | ||
// Build host! | ||
address = address.substring(found + 3); | ||
} | ||
return protocol + '://' + address; | ||
} | ||
/** | ||
* The domain part from address `(http://)domain(:port/path)` | ||
*/ | ||
get domain() { | ||
return this._domain; | ||
} | ||
/** | ||
* The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor | ||
*/ | ||
get port() { | ||
return this._port; | ||
} | ||
/** | ||
* @returns the string address as passed in the constructor | ||
*/ | ||
toString() { | ||
return this._address; | ||
} | ||
/** | ||
* @returns the string address as passed in the constructor | ||
* @override | ||
*/ | ||
valueOf() { | ||
return this._address; | ||
} | ||
/** | ||
* Build a NetAddress object and parse address | ||
* @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)` | ||
* @param defaultPort set a default port to use if there is no port in the string address parsed | ||
*/ | ||
constructor(address, defaultPort) { | ||
this._address = address; | ||
// Remove Protocol | ||
let pos = address.indexOf('/'); | ||
if (pos >= 0) { | ||
// Remove :// | ||
if (address.charCodeAt(pos + 1) === 47) { | ||
// has // | ||
if (pos > 0) { | ||
if (address.charCodeAt(pos - 1) === 58) { | ||
// has :// | ||
address = address.substring(pos + 2); | ||
} // something else #// | ||
} | ||
else { | ||
// otherwise starts by // | ||
address = address.substring(2); | ||
} | ||
} | ||
else if (!pos) { | ||
// starts by /, remove it | ||
address = address.substring(1); | ||
} // else something else #/ | ||
} | ||
this._domain = address; | ||
this._port = defaultPort; | ||
// Parse Port | ||
pos = address.lastIndexOf(':'); | ||
if (pos >= 0) { | ||
const port = parseInt(address.substring(pos + 1)); | ||
if (port && port <= 0xffff) { | ||
this._port = port; | ||
this._domain = address.substring(0, pos); | ||
} | ||
} | ||
else { | ||
// Remove Path! | ||
pos = address.indexOf('/'); | ||
if (pos >= 0) { | ||
this._domain = address.substring(0, pos); | ||
} | ||
} | ||
} | ||
}/** | ||
* 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. | ||
*/ | ||
/** | ||
* Type of connection | ||
@@ -942,2 +980,51 @@ */ | ||
/** | ||
* Some fix for JS MAP: | ||
* - find(key) search an item in the map and returns undefined if not found | ||
* - get(key) return the item if exists or otherwise create and returns it | ||
* - set(key, value) returns the value of the item (rather the MAP) | ||
*/ | ||
class FixMap { | ||
[Symbol.iterator]() { | ||
return this._map[Symbol.iterator](); | ||
} | ||
get size() { | ||
return this._map.size; | ||
} | ||
constructor(_initValue) { | ||
this._initValue = _initValue; | ||
this._map = new Map(); | ||
} | ||
get(key) { | ||
let value = this.find(key); | ||
if (value === undefined) { | ||
this._map.set(key, (value = this._initValue())); | ||
} | ||
return value; | ||
} | ||
find(key) { | ||
return this._map.get(key); | ||
} | ||
has(key) { | ||
return this._map.has(key); | ||
} | ||
clear() { | ||
this._map.clear(); | ||
} | ||
delete(key) { | ||
return this._map.delete(key); | ||
} | ||
set(key, value) { | ||
this._map.set(key, value); | ||
return value; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
forEach(callbackfn, thisArg) { | ||
this._map.forEach(callbackfn, thisArg); | ||
} | ||
}/** | ||
* 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. | ||
*/ | ||
/** | ||
* Queue typed similar to a {@link https://en.cppreference.com/w/cpp/container/queue | std::queue<Type>} with possibility to limit the capacity like a FIFO | ||
@@ -1360,40 +1447,2 @@ * @example | ||
/** | ||
* Compute ByteRate every delta time | ||
*/ | ||
class ByteRate { | ||
onBytes(bytes) { } | ||
get delta() { | ||
return this._delta; | ||
} | ||
constructor(delta = 1000) { | ||
this._time = time(); | ||
this._value = NaN; | ||
this._delta = delta; | ||
this._bytes = 0; | ||
} | ||
value() { | ||
return Math.round(this.exact()); | ||
} | ||
exact() { | ||
const now = time(); | ||
const elapsed = now - this._time; | ||
if (elapsed > this._delta || isNaN(this._value)) { | ||
// wait "_delta" before next compute rate | ||
this._value = (this._bytes * 1000) / elapsed; | ||
this._bytes = 0; | ||
this._time = now; | ||
} | ||
return this._value; | ||
} | ||
addBytes(bytes) { | ||
this._bytes += bytes; | ||
this.onBytes(bytes); | ||
return this; | ||
} | ||
}/** | ||
* 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. | ||
*/ | ||
/** | ||
* The WebSocketReliable class extends WebSocket to bring up the following improvements: | ||
@@ -1621,2 +1670,2 @@ * - Fix all possible unintentional closing ways to get always a related error message, {@link onClose | onClose(error?) event} | ||
*/ | ||
const VERSION = '1.3.0';export{BinaryReader,BinaryWriter,BitReader,Connect,EventEmitter,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable};//# sourceMappingURL=web-utils.js.map | ||
const VERSION = '1.4.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable};//# sourceMappingURL=web-utils.js.map |
@@ -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)}}class n{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 o(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 a=new TextDecoder,h=new TextEncoder,u=performance;function c(){return Math.floor(u.now())}function _(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,r]of l(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 l(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):""}var f,g=Object.freeze({__proto__:null,EMPTY_FUNCTION:()=>{},fetch:function(t,e){return o(this,void 0,void 0,(function*(){const i=yield self.fetch(t,e);if(i.status>=300){if(i.body)throw(yield i.text())||i.statusText;throw i.statusText}return i}))},objectEntries:l,objectFrom:_,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 _(t,{withType:!0,noEmptyString:!0})},parseExtension:d,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,recursive: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("boolean"==typeof e||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(Object.assign({},i),{recursive:i.recursive-1}));return s+=r+"]"}if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return a.decode(e);let n="";if(i.noBin)return"["+e.byteLength+"#bytes]";for(const s in e)n+=(n?",":"{")+r+s+":",n+=t(e[s],Object.assign(Object.assign({},i),{recursive:i.recursive-1}));return n+(r+"}")},time:c,timeOrigin:function(){return Math.floor(u.now()+u.timeOrigin)},toBin:function(t){return h.encode(t)}});!function(t){t.HESP="HESP",t.WEBRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(f||(f={}));var p=Object.freeze({__proto__:null,get Type(){return f},buildURL:function(t,e,i="wss"){const s=new URL(n.fixProtocol(i,e.host));if(s.pathname.length<=1)switch(t){case f.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case f.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case f.WEBRTS:s.pathname="/webrts/"+e.streamName;break;case f.META:s.pathname="/json_"+e.streamName+".js";break;case f.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 e.streamName.substring(0,e.streamName.length-d(e.streamName).length),s}});class b{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];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 y{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 w extends y{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 v={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=v.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=v.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(v);class m{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 x extends b{onOpen(){}onMessage(t){}onClose(t){t&&console.error(t)}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 m,this._sendByteRate=new m,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(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._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._opened=!1,this._queueing.length=0,this._queueingBytes=0,this.onClose(t))}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}const z="1.3.0";export{e as BinaryReader,s as BinaryWriter,r as BitReader,p as Connect,b as EventEmitter,n as NetAddress,w as Numbers,y as Queue,v as SDP,g as Util,z as VERSION,x as WebSocketReliable};//# 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}}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)}}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;function u(){return Math.floor(h.now())}function c(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 l(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}var d,f=Object.freeze({__proto__:null,EMPTY_FUNCTION:()=>{},fetch:function(t,e){return n(this,void 0,void 0,(function*(){const i=yield self.fetch(t,e);if(i.status>=300){if(i.body)throw(yield i.text())||i.statusText;throw i.statusText}return i}))},objectEntries:_,objectFrom:c,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 c(t,{withType:!0,noEmptyString:!0})},parseExtension:l,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,recursive: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("boolean"==typeof e||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(Object.assign({},i),{recursive:i.recursive-1}));return s+=r+"]"}if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return o.decode(e);let n="";if(i.noBin)return"["+e.byteLength+"#bytes]";for(const s in e)n+=(n?",":"{")+r+s+":",n+=t(e[s],Object.assign(Object.assign({},i),{recursive:i.recursive-1}));return n+(r+"}")},time:u,timeOrigin:function(){return Math.floor(h.now()+h.timeOrigin)},toBin:function(t){return a.encode(t)}});class g{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 p{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(t){t.HESP="HESP",t.WEBRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(d||(d={}));var b=Object.freeze({__proto__:null,get Type(){return d},buildURL:function(t,e,i="wss"){const s=new URL(p.fixProtocol(i,e.host));if(s.pathname.length<=1)switch(t){case d.HESP:s.pathname="/hesp/"+e.streamName+"/index.json";break;case d.WEBRTC:s.pathname="/webrtc/"+e.streamName;break;case d.WEBRTS:s.pathname="/webrts/"+e.streamName;break;case d.META:s.pathname="/json_"+e.streamName+".js";break;case d.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 e.streamName.substring(0,e.streamName.length-l(e.streamName).length),s}});class y{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];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 m{[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 w{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 v extends w{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 x={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=x.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=x.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(x);class z extends y{onOpen(){}onMessage(t){}onClose(t){t&&console.error(t)}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 g,this._sendByteRate=new g,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(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._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._opened=!1,this._queueing.length=0,this._queueingBytes=0,this.onClose(t))}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}const A="1.4.0";export{e as BinaryReader,s as BinaryWriter,r as BitReader,g as ByteRate,b as Connect,y as EventEmitter,m as FixMap,p as NetAddress,v as Numbers,w as Queue,x as SDP,f as Util,A as VERSION,z as WebSocketReliable};//# sourceMappingURL=web-utils.min.js.map |
{ | ||
"name": "@ceeblue/web-utils", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Ceeblue web framework", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@ [Usage](#usage) | [Building locally](#building-locally) | [Documentation](#documentation) | [Contribution](#contribution) | [License](#license) | ||
This is a Web base compoments for CeeblueTV's web libraries : a collection of tools and utilities used across all of CeeblueTV's web projects. | ||
This is a basic component library for Ceeblue projects, consisting of a collection of essential tools and utilities used in all Ceeblue web projects. | ||
@@ -20,4 +20,4 @@ ## Usage | ||
> | ||
> If your project uses [TypeScript](https://www.typescriptlang.org/), it is recommended to set `"target": "ES6"` in your configuration to align with our usage of ES6 features and ensures that your build will succeed (for those requiring a backwards-compatible [UMD](https://github.com/umdjs/umd) version, a [local build](#building-locally) is advised). | ||
> Then Defining the compiler option `"moduleResolution": "Node"` in **tsconfig.json** helps with import errors by ensuring that TypeScript uses the correct strategy for resolving imports based on the targeted Node.js version. | ||
> If your project uses TypeScript, it is recommended that you set target: "ES6" in your configuration to match our use of ES6 features and ensure that your build will succeed (for those requiring a backward-compatible UMD version, a local build is recommended). | ||
> Then define the "moduleResolution" compiler option: "Node" in tsconfig.json helps with import failures by ensuring that TypeScript uses the correct import resolution strategy based on the targeted Node.js version. | ||
> ```json | ||
@@ -35,4 +35,4 @@ > { | ||
1. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository | ||
2. Enter the `webr-utils` folder and run `npm install` to install packages dependencies. | ||
3. Execute `npm run build`. The output will be five files placed in the **/dist/** folder: | ||
2. Got to the `web-utils` folder and run `npm install` to install the packages dependencies. | ||
3. Run `npm run build`. The output will be five files placed in the **/dist/** folder: | ||
- **web-utils.d.ts** Typescript definitions file | ||
@@ -57,6 +57,3 @@ - **web-utils.js**: Bundled JavaScript library | ||
``` | ||
You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`), or if you have installed and started the [http-server package](https://www.npmjs.com/package/http-server) by navigating to: | ||
``` | ||
http://localhost:8080/docs/ | ||
``` | ||
You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`). | ||
@@ -63,0 +60,0 @@ ## Contribution |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
350363
2523
62