@ceeblue/web-utils 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web-utils.d.ts +8 -0
- package/dist/web-utils.js +22 -9
- package/dist/web-utils.js.map +1 -1
- package/dist/web-utils.min.js +1 -1
- package/dist/web-utils.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-utils.min.js","sources":["web-utils.js"],"sourcesContent":["/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BinaryReader allows to read binary data\n */\nconst _decoder$1 = new TextDecoder();\nclass BinaryReader {\n constructor(data) {\n this._data =\n 'buffer' in data ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : new Uint8Array(data);\n this._size = this._data.byteLength;\n this._position = 0;\n this._view = new DataView(this._data.buffer, this._data.byteOffset, this._size);\n }\n data() {\n return this._data;\n }\n size() {\n return this._size;\n }\n available() {\n return this._size - this._position;\n }\n value(position = this._position) {\n return this._data[position];\n }\n position() {\n return this._position;\n }\n reset(position = 0) {\n this._position = Math.max(0, position > this._size ? this._size : position);\n }\n shrink(available) {\n const rest = this._size - this._position;\n if (available > rest) {\n return rest;\n }\n this._size = this._position + available;\n return available;\n }\n next(count = 1) {\n const rest = this._size - this._position;\n if (count > rest) {\n count = rest;\n }\n this._position = Math.max(0, this._position + count);\n return count;\n }\n read8() {\n return this.next(1) === 1 ? this._view.getUint8(this._position - 1) : 0;\n }\n read16() {\n return this.next(2) === 2 ? this._view.getUint16(this._position - 2) : 0;\n }\n read24() {\n return this.next(3) === 3\n ? (this._view.getUint16(this._position - 3) << 8) | (this._view.getUint8(this._position - 1) & 0xff)\n : 0;\n }\n read32() {\n return this.next(4) === 4 ? this._view.getUint32(this._position - 4) : 0;\n }\n read64() {\n if (this.next(8) !== 8) {\n return 0;\n }\n return this._view.getUint32(this._position - 8) * 4294967296 + this._view.getUint32(this._position - 4);\n }\n readFloat() {\n return this.next(4) === 4 ? this._view.getFloat32(this._position - 4) : 0;\n }\n readDouble() {\n return this.next(8) === 8 ? this._view.getFloat64(this._position - 8) : 0;\n }\n read7Bit(bytes = 5) {\n let result = 0;\n let factor = 1;\n while (this.available()) {\n const byte = this.read8();\n result += (byte & 0x7f) * factor;\n if (!(byte & 0x80)) {\n break;\n }\n factor *= 128;\n }\n return result;\n }\n readString() {\n let i = this._position;\n while (i < this._size && this._data[i]) {\n ++i;\n }\n const result = this.read(i - this._position);\n this.next(); // skip the 0 termination\n return _decoder$1.decode(result);\n }\n readHex(size) {\n let hex = '';\n while (size-- > 0) {\n hex += ('0' + this.read8().toString(16)).slice(-2);\n }\n return hex;\n }\n /**\n * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size)) or Util.stringify\n * @param {UInt32} size\n */\n read(size = this.available()) {\n if (this.available() < size) {\n return new Uint8Array(size); // default value = empty bytearray!\n }\n const pos = this._position;\n return this._data.subarray(pos, Math.max(pos, (this._position += size)));\n }\n}/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\n\r\nfunction __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\ntypeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\nconst _decoder = new TextDecoder();\nconst _encoder = new TextEncoder();\n/* eslint-disable @typescript-eslint/no-explicit-any */\nconst _perf = performance; // to increase x10 now performance!\n/**\n * Some basic utility functions\n */\n/**\n * An empty lambda function, pratical to disable default behavior of function or events which are not expected to be null\n * @example\n * console.log = Util.EMPTY_FUNCTION; // disable logs without breaking calls\n */\nconst EMPTY_FUNCTION = () => { };\n/**\n * Efficient and high resolution timestamp in milliseconds elapsed since {@link Util.timeOrigin}\n */\nfunction time() {\n return Math.floor(_perf.now());\n}\n/**\n * Time origin represents the time when the application has started\n */\nfunction timeOrigin() {\n return Math.floor(_perf.now() + _perf.timeOrigin);\n}\n/**\n * Parse query and returns it in an easy-to-use Javascript object form\n * @param urlOrQueryOrSearch string, url, or searchParams containing query. If not set it uses `location.search` to determinate query.\n * @returns An javascript object containing each option\n */\nfunction options(urlOrQueryOrSearch = typeof location === 'undefined'\n ? undefined\n : location) {\n if (!urlOrQueryOrSearch) {\n return {};\n }\n try {\n const url = urlOrQueryOrSearch;\n urlOrQueryOrSearch = new URL(url).searchParams;\n }\n catch (e) {\n if (typeof urlOrQueryOrSearch == 'string') {\n if (urlOrQueryOrSearch.startsWith('?')) {\n urlOrQueryOrSearch = urlOrQueryOrSearch.substring(1);\n }\n urlOrQueryOrSearch = new URLSearchParams(urlOrQueryOrSearch);\n }\n }\n // works same if urlOrQueryOrSearch is null, integer, or a already object etc...\n return objectFrom(urlOrQueryOrSearch, { withType: true, noEmptyString: true });\n}\n/**\n * Returns an easy-to-use Javascript object something iterable, such as a Map, Set, or Array\n * @param value iterable input\n * @param params.withType `false`, if set it tries to cast string value to a JS number/boolean/undefined/null type.\n * @param params.noEmptyString `false`, if set it converts empty string value to a true boolean, usefull to allow a `if(result.key)` check for example\n * @returns An javascript object\n */\nfunction objectFrom(value, params) {\n params = Object.assign({ withType: false, noEmptyString: false }, params);\n const obj = {};\n if (!value) {\n return obj;\n }\n for (const [key, val] of objectEntries(value)) {\n value = val;\n if (params.withType && value != null && value.substring) {\n if (value) {\n const number = Number(value);\n if (isNaN(number)) {\n switch (value.toLowerCase()) {\n case 'true':\n value = true;\n break;\n case 'false':\n value = false;\n break;\n case 'null':\n value = null;\n break;\n case 'undefined':\n value = undefined;\n break;\n }\n }\n else {\n value = number;\n }\n }\n else if (params.noEmptyString) {\n // if empty string => TRUE to allow a if(options.key) check for example\n value = true;\n }\n }\n if (obj[key]) {\n if (!Array.isArray(obj[key])) {\n obj[key] = new Array(obj[key]);\n }\n obj[key].push(value);\n }\n else {\n obj[key] = value;\n }\n }\n return obj;\n}\n/**\n * Returns entries from something iterable, such as a Map, Set, or Array\n * @param value iterable input\n * @returns An javascript object\n */\nfunction objectEntries(value) {\n if (value.entries) {\n return value.entries();\n }\n return Array.from({\n [Symbol.iterator]: function* () {\n for (const key in value) {\n yield [key, value[key]];\n }\n }\n });\n}\n/**\n * Converts various data types, such as objects, strings, exceptions, errors,\n * or numbers, into a string representation. Since it offers a more comprehensive format,\n * this function is preferred to `JSON.stringify()`.\n * @param obj Any objects, strings, exceptions, errors, or number\n * @param params.space `''`, allows to configure space in the string representation\n * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation\n * @param params.recursion `1`, recursion depth to stringify recursively every object value until this depth, beware if a value refers to a already parsed value an infinite loop will occur\n * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information\n * @returns the final string representation\n */\n// Online Javascript Editor for free\n// Write, Edit and Run your Javascript code using JS Online Compiler\nfunction stringify(obj, params = {}) {\n params = Object.assign({ space: ' ', decimal: 2, recursion: 1, noBin: false }, params);\n if (obj == null) {\n return String(obj);\n }\n const error = obj.error || obj.message;\n if (error) {\n // is a error!\n obj = error;\n }\n // number\n if (obj.toFixed) {\n return obj.toFixed(Number(params.decimal) || 0);\n }\n if (obj.byteLength != null && (obj === null || obj === void 0 ? void 0 : obj[Symbol.iterator])) {\n // Binary!\n if (!params.noBin) {\n return _decoder.decode(obj);\n }\n return '[' + obj.byteLength + '#bytes]';\n }\n // boolean or string type or stop recursivity\n if (typeof obj === 'boolean' || obj.substring || !params.recursion) {\n // is already a string OR has to be stringified\n return String(obj);\n }\n const space = params.space || '';\n if (Array.isArray(obj)) {\n // Array!\n let res = '';\n for (const value of obj) {\n res += (res ? ',' : '[') + space;\n res += stringify(value, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));\n }\n return (res += space + ']');\n }\n let res = '{';\n for (const name in obj) {\n if (res.length > 1) {\n res += ',';\n }\n res += space + name + ':';\n res += stringify(obj[name], Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 })) + space;\n }\n return (res += '}');\n}\n/**\n * Encode a string to a binary representation\n * @param value string value to convert\n * @returns binary conversion\n */\nfunction toBin(value) {\n return _encoder.encode(value);\n}\n/**\n * Execute a promise in a safe way with a timeout if caller doesn't resolve it in the accurate time\n */\nfunction safePromise(timeout, promise) {\n // Returns a race between our timeout and the passed in promise\n let timer;\n return Promise.race([\n promise instanceof Promise ? promise : new Promise(promise),\n new Promise((resolve, reject) => (timer = setTimeout(() => reject('timed out in ' + timeout + 'ms'), timeout)))\n ]).finally(() => clearTimeout(timer));\n}\n/**\n * Wait in milliseconds, requires a call with await keyword!\n */\nfunction sleep(ms) {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n/**\n * Test equality between two value whatever their type, array included\n */\nfunction equal(a, b) {\n if (Object(a) !== a) {\n if (Object(b) === b) {\n return false;\n }\n // both primitive (null and undefined included)\n return a === b;\n }\n // complexe object\n if (a[Symbol.iterator]) {\n if (!b[Symbol.iterator]) {\n return false;\n }\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i !== a.length; ++i) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n }\n return a === b;\n}\n/**\n * fetch help method with few usefull fix:\n * - throw an string exception if response code is not 200 with the text of the response or uses statusText\n */\nfunction fetch(input, init) {\n return __awaiter(this, void 0, void 0, function* () {\n const response = yield self.fetch(input, init);\n if (response.status >= 300) {\n let error;\n if (response.body) {\n error = yield response.text();\n }\n throw (error || response.statusText || response.status).toString();\n }\n return response;\n });\n}\n/**\n * Get Extension part from path\n * @param path path to parse\n * @returns the extension\n */\nfunction getExtension(path) {\n const dot = path.lastIndexOf('.');\n const ext = dot >= 0 && dot > path.lastIndexOf('/') ? path.substring(dot) : '';\n return ext;\n}\n/**\n * Get File part from path\n * @param path path to parse\n * @returns the file name\n */\nfunction getFile(path) {\n return path.substring(path.lastIndexOf('/') + 1);\n}\n/**\n * Get Base File part from path, without extension\n * @param path path to parse\n * @returns the base file name\n */\nfunction getBaseFile(path) {\n const dot = path.lastIndexOf('.');\n const file = path.lastIndexOf('/') + 1;\n return dot >= 0 && dot >= file ? path.substring(file, dot) : path.substring(file);\n}\nfunction codesFromString(value) {\n const codes = [];\n for (let i = 0; i < value.length; ++i) {\n codes.push(value.charCodeAt(i));\n }\n return codes;\n}\n/**\n * String Trim function with customizable chars\n * @param value string to trim\n * @param chars chars to use to trim\n * @returns string trimmed\n */\nfunction trim(value, chars = ' ') {\n const codes = codesFromString(chars);\n let start = 0;\n while (start < value.length && codes.includes(value.charCodeAt(start))) {\n ++start;\n }\n let end = value.length;\n while (end > 0 && codes.includes(value.charCodeAt(end - 1))) {\n --end;\n }\n return value.substring(start, end);\n}\n/**\n * String Trim Start function with customizable chars\n * @param value string to trim start\n * @param chars chars to use to trim start\n * @returns string trimmed\n */\nfunction trimStart(value, chars = ' ') {\n const codes = codesFromString(chars);\n let i = 0;\n while (i < value.length && codes.includes(value.charCodeAt(i))) {\n ++i;\n }\n return value.substring(i);\n}\n/**\n * String Trim End function with customizable chars\n * @param value string to trim end\n * @param chars chars to use to trim end\n * @returns string trimmed\n */\nfunction trimEnd(value, chars = ' ') {\n const codes = codesFromString(chars);\n let i = value.length;\n while (i > 0 && codes.includes(value.charCodeAt(i - 1))) {\n --i;\n }\n return value.substring(0, i);\n}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getBaseFile:getBaseFile,getExtension:getExtension,getFile:getFile,objectEntries:objectEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BinaryWriter allows to write data in its binary form\n */\nclass BinaryWriter {\n get view() {\n if (!this._view) {\n this._view = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);\n }\n return this._view;\n }\n get capacity() {\n return this._data.byteLength;\n }\n constructor(dataOrSize = 64, offset = 0, length) {\n if (typeof dataOrSize == 'number') {\n // allocate new buffer\n this._data = new Uint8Array(dataOrSize);\n this._size = 0;\n }\n else if ('buffer' in dataOrSize) {\n // append to existing data!\n this._data = new Uint8Array(dataOrSize.buffer, dataOrSize.byteOffset, dataOrSize.byteLength);\n this._size = dataOrSize.byteLength;\n }\n else {\n // overrides data\n this._isConst = true; // better than boolean for memory usage\n if (length == null) {\n // /!\\ Safari does not support undefined length, so we need to use byteLength instead\n length = dataOrSize.byteLength;\n }\n this._data = new Uint8Array(dataOrSize, offset, length);\n this._size = 0;\n }\n }\n data() {\n return new Uint8Array(this._data.buffer, this._data.byteOffset, this._size);\n }\n size() {\n return this._size || 0;\n }\n next(count = 1) {\n return this.reserve((this._size += count));\n }\n clear(size = 0) {\n return this.reserve((this._size = size));\n }\n /**\n * Write binary data\n * @param data\n */\n write(data) {\n var _a;\n let bin;\n if (typeof data === 'string') {\n // Convertit la chaîne en Uint8Array\n bin = toBin(data);\n }\n else if (data instanceof ArrayBuffer) {\n bin = new Uint8Array(data);\n }\n else if ('buffer' in data) {\n bin = new Uint8Array(data.buffer, (_a = data.byteOffset) !== null && _a !== void 0 ? _a : 0, data.byteLength);\n }\n else {\n bin = data;\n }\n this.reserve(this._size + bin.length);\n this._data.set(bin, this._size);\n this._size += bin.length;\n return this;\n }\n write8(value) {\n if (value > 0xff) {\n // cast to 8bits range\n value = 0xff;\n }\n this.reserve(this._size + 1);\n this._data[this._size++] = value;\n return this;\n }\n write16(value) {\n if (value > 0xffff) {\n // cast to 16bits range\n value = 0xffff;\n }\n this.reserve(this._size + 2);\n this.view.setUint16(this._size, value);\n this._size += 2;\n return this;\n }\n write24(value) {\n if (value > 0xffffff) {\n // cast to 24bits range\n value = 0xffffff;\n }\n this.reserve(this._size + 3);\n this.view.setUint16(this._size, value >> 8);\n this.view.setUint8((this._size += 2), value & 0xff);\n ++this._size;\n return this;\n }\n write32(value) {\n if (value > 0xffffffff) {\n // cast to 32bits range\n value = 0xffffffff;\n }\n this.reserve(this._size + 4);\n this.view.setUint32(this._size, value);\n this._size += 4;\n return this;\n }\n write64(value) {\n this.write32(value / 4294967296);\n return this.write32(value & 0xffffffff);\n }\n writeFloat(value) {\n this.reserve(this._size + 4);\n this.view.setFloat32(this._size, value);\n this._size += 4;\n return this;\n }\n writeDouble(value) {\n this.reserve(this._size + 8);\n this.view.setFloat64(this._size, value);\n this._size += 8;\n return this;\n }\n write7Bit(value) {\n let byte = value & 0x7f;\n while ((value = Math.floor(value / 0x80))) {\n // equivalent to >>=7 for JS!\n this.write8(0x80 | byte);\n byte = value & 0x7f;\n }\n return this.write8(byte);\n }\n writeString(value) {\n return this.write(toBin(value)).write8(0);\n }\n writeHex(value) {\n for (let i = 0; i < value.length; i += 2) {\n this.write8(parseInt(value.substring(i, i + 2), 16));\n }\n return this;\n }\n reserve(size) {\n if (!this._data) {\n throw Error('buffer not writable');\n }\n if (size <= this._data.byteLength) {\n return this;\n }\n if (this._isConst) {\n throw Error('writing exceeds maximum ' + this._data.byteLength + ' bytes limit');\n }\n --size;\n size |= size >> 1;\n size |= size >> 2;\n size |= size >> 4;\n size |= size >> 8;\n size |= size >> 16;\n ++size;\n const data = new Uint8Array(size);\n data.set(this._data); // copy old buffer!\n this._data = data;\n this._view = undefined; // release view\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Log levels\n */\nvar LogLevel;\n(function (LogLevel) {\n LogLevel[\"ERROR\"] = \"error\";\n LogLevel[\"WARN\"] = \"warn\";\n LogLevel[\"INFO\"] = \"info\";\n LogLevel[\"DEBUG\"] = \"debug\";\n})(LogLevel || (LogLevel = {}));\n// check coder issuer: everytime we don't forget to use the built Log\nlet _logging = 0;\nsetInterval(() => {\n console.assert(_logging === 0, _logging.toFixed(), 'calls to log was useless');\n}, 10000);\n// !cb-override-log-level\nconst _overrideLogLevel = options()['!cb-override-log-level'];\nconst _charLevels = new Array(128);\n_charLevels[101] = _charLevels[69] = 1; // error\n_charLevels[119] = _charLevels[87] = 2; // warn\n_charLevels[105] = _charLevels[73] = 3; // info\n_charLevels[100] = _charLevels[68] = 4; // debug\n/**\n * Log instance\n */\nclass Log {\n get error() {\n return this._bind(LogLevel.ERROR);\n }\n get warn() {\n return this._bind(LogLevel.WARN);\n }\n get info() {\n return this._bind(LogLevel.INFO);\n }\n get debug() {\n return this._bind(LogLevel.DEBUG);\n }\n constructor(log, ...args) {\n if (!args.length) {\n // cannot have 0 args to be called correctly!\n args.push(undefined);\n }\n this._args = args;\n this._log = log;\n ++_logging;\n }\n _onLog(localLog, level) {\n var _a, _b;\n // we take like log-level by priority order:\n // 1- the overrideLogLevel\n // 2- the localLog.level\n // 3- the global log.level\n // 4- LogLevel.INFO\n const logLevel = (_b = (_a = _overrideLogLevel !== null && _overrideLogLevel !== void 0 ? _overrideLogLevel : localLog.level) !== null && _a !== void 0 ? _a : log.level) !== null && _b !== void 0 ? _b : LogLevel.INFO;\n if (logLevel === false) {\n // explicit null, no log at all!\n return false;\n }\n if (logLevel !== true && _charLevels[level.charCodeAt(0)] > _charLevels[logLevel.charCodeAt(0)]) {\n return false;\n }\n if (localLog.on) {\n localLog.on(level, this._args);\n }\n return this._args.length ? true : false;\n }\n _bind(level) {\n if (!this._done) {\n this._done = true;\n --_logging;\n }\n // call the global onLog in first (global filter)\n if (!this._onLog(log, level)) {\n return EMPTY_FUNCTION;\n }\n // call the local onLog (local filter)\n if (this._log !== log && !this._onLog(this._log, level)) {\n return EMPTY_FUNCTION;\n }\n // if not intercepted display the log\n return console[level].bind(console, ...this._args);\n }\n}\n/**\n * Inherits from this class to use logs\n */\nclass Loggable {\n constructor() {\n /**\n * Start a log\n * @param args\n * @returns a Log object with the levels of log to call\n */\n this.log = ((...args) => {\n return new Log(this.log, ...args);\n });\n }\n}\n/**\n * Global log\n */\nconst log = ((...args) => {\n return new Log(log, ...args);\n});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BitReader allows to read binary data bit by bit\n */\nclass BitReader extends Loggable {\n constructor(data) {\n super();\n if ('buffer' in data) {\n this._data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n }\n else {\n this._data = new Uint8Array(data);\n }\n this._size = this._data.byteLength;\n this._position = 0;\n this._bit = 0;\n }\n data() {\n return this._data;\n }\n size() {\n return this._size;\n }\n available() {\n return (this._size - this._position) * 8 - this._bit;\n }\n next(count = 1) {\n let gotten = 0;\n while (this._position !== this._size && count--) {\n ++gotten;\n if (++this._bit === 8) {\n this._bit = 0;\n ++this._position;\n }\n }\n return gotten;\n }\n read(count = 1) {\n let result = 0;\n while (this._position !== this._size && count--) {\n result <<= 1;\n if (this._data[this._position] & (0x80 >> this._bit++)) {\n result |= 1;\n }\n if (this._bit === 8) {\n this._bit = 0;\n ++this._position;\n }\n }\n return result;\n }\n read8() {\n return this.read(8);\n }\n read16() {\n return this.read(16);\n }\n read24() {\n return this.read(24);\n }\n read32() {\n return this.read(32);\n }\n readExpGolomb() {\n let i = 0;\n while (!this.read()) {\n if (!this.available()) {\n return 0;\n }\n ++i;\n }\n const result = this.read(i);\n if (i > 15) {\n this.log('Exponential-Golomb code exceeding unsigned 16 bits').warn();\n return 0;\n }\n return result + (1 << i) - 1;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Class to compute a weighted average byte rate over a specified time interval.\n *\n * This class continuously tracks data transmission and computes the byte rate\n * based on a weighted average, considering both the duration and the number of\n * bytes in each sample. It allows for real-time monitoring of bandwidth usage\n * and provides mechanisms to dynamically adjust the measurement interval.\n *\n * Features:\n * - Computes the byte rate using a **weighted average** approach.\n * - Allows setting a custom interval for tracking.\n * - Supports dynamic clipping to manually shrink the observation window.\n */\nclass ByteRate {\n /**\n * Raised when new bytes are added\n */\n onBytes(bytes) { }\n /**\n * Returns the interval used for computing the byte rate\n */\n get interval() {\n return this._interval;\n }\n /**\n * Sets a new interval for computing the average byte rate\n */\n set interval(value) {\n this._interval = value;\n this.updateSamples();\n }\n /**\n * Constructor initializes the ByteRate object with a specified interval (default: 1000ms).\n * It sets up necessary variables to track byte rate over time.\n *\n * @param interval - Time interval in milliseconds to compute the byte rate.\n */\n constructor(interval = 1000) {\n this._interval = interval;\n this.clear();\n }\n /**\n * Returns the computed byte rate rounded to the nearest integer\n */\n value() {\n return Math.round(this.exact());\n }\n /**\n * Computes the exact byte rate in bytes per second\n */\n exact() {\n // compute rate/s\n this.updateSamples();\n const duration = time() - this._time;\n return duration ? (this._bytes / duration) * 1000 : 0;\n }\n /**\n * Adds a new byte sample to the tracking system.\n * Updates the list of samples and recomputes the byte rate\n *\n * @param bytes - Number of bytes added in this interval\n */\n addBytes(bytes) {\n var _a;\n const time$1 = time();\n const lastSample = this.updateSamples(time$1)[this._samples.length - 1];\n const lastTime = (_a = lastSample === null || lastSample === void 0 ? void 0 : lastSample.time) !== null && _a !== void 0 ? _a : this._time;\n if (time$1 > lastTime) {\n this._samples.push({ bytes, time: time$1, clip: false });\n }\n else {\n // no new duration => attach byte to last-one\n if (!lastSample) {\n // Ignore, was before our ByteRate scope !\n return this;\n }\n lastSample.bytes += bytes;\n }\n this._bytes += bytes;\n this.onBytes(bytes);\n return this;\n }\n /**\n * Clears all recorded byte rate data.\n */\n clear() {\n this._bytes = 0;\n this._time = time();\n this._samples = [];\n this._clip = false;\n return this;\n }\n /**\n * Clips the byte rate tracking by marking the last sample as clipped.\n * If a previous clip exists, removes the clipped sample and all preceding samples.\n * Allows to shrink the interval manually between two positions.\n */\n clip() {\n if (this._clip) {\n this._clip = false;\n let removes = 0;\n for (const sample of this._samples) {\n this._bytes -= sample.bytes;\n ++removes;\n this._time = sample.time;\n if (sample.clip) {\n break;\n }\n }\n this._samples.splice(0, removes);\n }\n const lastSample = this._samples[this._samples.length - 1];\n if (lastSample) {\n lastSample.clip = true;\n this._clip = true;\n }\n return this;\n }\n updateSamples(now = time()) {\n // Remove obsolete sample\n const timeOK = now - this._interval;\n let removes = 0;\n let sample;\n while (this._time < timeOK && (sample = this._samples[removes])) {\n this._bytes -= sample.bytes;\n if (sample.clip) {\n this._clip = sample.clip = false;\n }\n if (sample.time > timeOK) {\n // only a part of the sample to delete !\n sample.bytes *= (sample.time - timeOK) / (sample.time - this._time);\n this._time = timeOK;\n this._bytes += sample.bytes;\n break;\n }\n ++removes;\n this._time = sample.time;\n }\n this._samples.splice(0, removes);\n return this._samples;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Help class to manipulate and parse a net address. The Address can be only the domain field,\n * or a URL format with protocol and path part `(http://)domain(:port/path)`\n * @example\n * const address = new Address('nl-ams-42.live.ceeblue.tv:80');\n * console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'\n * console.log(address.port) // '80'\n * console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'\n */\nclass NetAddress {\n /**\n * Static help function to build an end point from an address `(proto://)domain(:port/path)`\n *\n * Mainly it fix the protocol, in addition if:\n * - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version\n * - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version\n * @param protocol protocol to set in the end point returned\n * @param address string address to fix with protocol as indicated\n * @returns the end point built\n * @example\n * console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'\n * console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'\n * console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'\n */\n static fixProtocol(protocol, address) {\n const found = address.indexOf('://');\n // isolate protocol is present in address\n if (found >= 0) {\n // In this case replace by protocol in keeping SSL like given in address\n if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') {\n // SSL!\n if (protocol.length <= 2 || !protocol.endsWith('s')) {\n protocol += 's'; // Add SSL\n }\n }\n else {\n // Not SSL!\n if (protocol.length > 2 && protocol.endsWith('s')) {\n protocol = protocol.slice(0, -1); // Remove SSL\n }\n }\n // Build address!\n address = address.substring(found + 3);\n }\n return protocol + '://' + address;\n }\n /**\n * The domain part from address `(http://)domain(:port/path)`\n */\n get domain() {\n return this._domain;\n }\n /**\n * The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor\n */\n get port() {\n return this._port;\n }\n /**\n * @returns the string address as passed in the constructor\n */\n toString() {\n return this._address;\n }\n /**\n * @returns the string address as passed in the constructor\n * @override\n */\n valueOf() {\n return this._address;\n }\n /**\n * Build a NetAddress object and parse address\n * @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)`\n * @param defaultPort set a default port to use if there is no port in the string address parsed\n */\n constructor(address, defaultPort) {\n this._address = address;\n // Remove Protocol\n let pos = address.indexOf('/');\n if (pos >= 0) {\n // Remove ://\n if (address.charCodeAt(pos + 1) === 47) {\n // has //\n if (pos > 0) {\n if (address.charCodeAt(pos - 1) === 58) {\n // has ://\n address = address.substring(pos + 2);\n } // something else #//\n }\n else {\n // otherwise starts by //\n address = address.substring(2);\n }\n }\n else if (!pos) {\n // starts by /, remove it\n address = address.substring(1);\n } // else something else #/\n }\n this._domain = address;\n this._port = defaultPort;\n // Parse Port\n pos = address.lastIndexOf(':');\n if (pos >= 0) {\n const port = parseInt(address.substring(pos + 1));\n if (port && port <= 0xffff) {\n this._port = port;\n this._domain = address.substring(0, pos);\n }\n }\n else {\n // Remove Path!\n pos = address.indexOf('/');\n if (pos >= 0) {\n this._domain = address.substring(0, pos);\n }\n }\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Type of connection\n */\nvar Type;\n(function (Type) {\n Type[\"HESP\"] = \"HESP\";\n Type[\"WRTS\"] = \"WebRTS\";\n Type[\"WEBRTC\"] = \"WebRTC\";\n Type[\"META\"] = \"Meta\";\n Type[\"DATA\"] = \"Data\";\n})(Type || (Type = {}));\n/**\n * Some connection utility functions\n */\n/**\n * Defines the {@link Params.mediaExt} based on the type of parameters and its endpoint.\n * This method always assigns a value to params.mediaExt, defaulting to an empty string if indeterminable,\n * allowing detection of whether the function has been applied to the parameters.\n * @param type The type of parameters to define.\n * @param params The parameters for which the media extension is to be defined\n */\nfunction defineMediaExt(type, params) {\n // Compute appropriate mediaExt out parameter\n switch (type) {\n case Type.HESP:\n params.mediaExt = 'mp4';\n break;\n case Type.WEBRTC:\n params.mediaExt = 'rtp';\n break;\n case Type.WRTS: {\n try {\n const url = new URL(params.endPoint);\n const ext = getExtension(getFile(url.pathname));\n // set extension just if not json, json means a manifest file endPoint\n if (ext && ext.toLowerCase() !== '.json') {\n params.mediaExt = ext;\n }\n }\n catch (_) {\n // not an URL, it's only a host => keep mediaExt unchanged to build the URL\n }\n if (!params.mediaExt) {\n // set to its default rts value => always set for WRTS!\n params.mediaExt = 'rts';\n }\n break;\n }\n case Type.META:\n params.mediaExt = 'js';\n break;\n case Type.DATA:\n params.mediaExt = 'json';\n break;\n default:\n params.mediaExt = ''; // set always a value to know that the parameters have been fixed\n console.warn('Unknown params type ' + type);\n break;\n }\n // Fix mediaExt in removing the possible '.' prefix\n params.mediaExt = trimStart(params.mediaExt, '.');\n}\n/**\n * Build an URL from {@link Type | type} and {@link Params | params}\n * @param type Type of the connection wanted\n * @param params Connection parameters\n * @param protocol Optional parameter to choose the prefered protocol to connect\n * @returns The URL of connection\n */\nfunction buildURL(type, params, protocol = 'wss') {\n defineMediaExt(type, params);\n const url = new URL(NetAddress.fixProtocol(protocol, params.endPoint));\n if (url.pathname.length <= 1) {\n // build ceeblue path!\n switch (type) {\n case Type.HESP:\n url.pathname = '/hesp/' + params.streamName + '/index.json';\n break;\n case Type.WEBRTC:\n url.pathname = '/webrtc/' + params.streamName;\n break;\n case Type.WRTS:\n url.pathname = '/wrts/' + params.streamName + '.' + params.mediaExt;\n break;\n case Type.META:\n url.pathname = '/json_' + params.streamName + '.js';\n break;\n case Type.DATA:\n url.pathname = '/' + params.streamName + '.json';\n break;\n default:\n console.warn('Unknown url type ' + type);\n break;\n }\n } // Host has already a path! keep it unchanged, it's user intentionnal (used with some other WHIP/WHEP server?)\n if (params.accessToken) {\n url.searchParams.set('id', params.accessToken);\n }\n for (const key in params.query) {\n url.searchParams.set(key, params.query[key]);\n }\n return url;\n}var Connect=/*#__PURE__*/Object.freeze({__proto__:null,get Type(){return Type},buildURL:buildURL,defineMediaExt:defineMediaExt});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * A advanced EventEmitter which allows to declare event as natural function in the inheriting children class,\n * function must start by `on` prefix to be recognized as an event.\n * The function can define a behavior by default, and user can choose to redefine this behavior,\n * or add an additionnal subscription for this event.\n * In addition you can unsubscribe to multiple events with an `AbortController`\n * @example\n * class Logger extends EventEmitter {\n * onLog(log:string) { console.log(log); } // behavior by default\n *\n * test() {\n * // raise event onLog\n * this.onLog('test');\n * }\n * }\n *\n * const logger = new Logger();\n * logger.test(); // displays a log 'test'\n *\n * // redefine default behavior to display nothing\n * logger.onLog = () => {}\n * logger.test(); // displays nothing\n *\n * // add an additionnal subscription\n * logger.on('log', console.log);\n * logger.test(); // displays a log 'test'\n *\n * // remove the additionnal subscription\n * logger.off('log', console.log);\n * logger.test(); // displays nothing\n *\n * // add two additionnal subscriptions with a AbortController\n * const controller = new AbortController();\n * logger.on('log', log => console.log(log), controller);\n * logger.on('log', log => console.error(log), controller);\n * logger.test(); // displays a log 'test' + an error 'test'\n *\n * // Unsubscribe all the subscription with the AbortController\n * controller.abort();\n * logger.test(); // displays nothing\n */\nclass EventEmitter extends Loggable {\n /**\n * Build our EventEmitter, usually call from children class\n */\n constructor() {\n super();\n this._events = new Map();\n // Fill events with events as defined!\n let proto = Object.getPrototypeOf(this);\n while (proto && proto !== Object.prototype) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n if (name.length < 3 || !name.startsWith('on')) {\n continue;\n }\n if (proto[name] instanceof Function) {\n const events = new Set();\n this._events.set(name.substring(2).toLowerCase(), events);\n let defaultEvent = proto[name];\n const raise = (...args) => {\n // Call default event if not null (can happen in JS usage)\n if (defaultEvent) {\n defaultEvent.call(this, ...args);\n }\n // Call subscribers\n for (const event of events) {\n event(...args);\n }\n };\n Object.defineProperties(this, {\n [name]: {\n get: () => raise,\n set: (value) => {\n // Assign a default behavior!\n defaultEvent = value;\n }\n }\n });\n }\n }\n proto = Object.getPrototypeOf(proto);\n }\n }\n /**\n * Event subscription\n * @param name Name of event without the `on` prefix (ex: `log` to `onLog` event declared)\n * @param event Subscriber Function\n * @param options.signal Optional `AbortSignal` to stop this or multiple subscriptions in same time\n */\n on(name, event, options) {\n var _a;\n if (!event) {\n throw Error('event to subscribe cannot be null');\n }\n const events = this._event(name);\n events.add(event);\n (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(event), { once: true });\n }\n /**\n * Event subscription only one time, once time fired it's automatically unsubscribe\n * @param name Name of event without the `on` prefix (ex: `log` to `onLog` event declared)\n * @param event Subscriber Function\n * @param options.abortSignal Optional `AbortSignal` to stop this or multiple subscriptions in same time\n */\n once(name, event, options) {\n var _a;\n if (!event) {\n throw Error('event to subscribe cannot be null');\n }\n const events = this._event(name);\n events.add((...args) => {\n events.delete(event); // delete from events\n event(...args); // execute event\n });\n (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(event), { once: true });\n }\n /**\n * Event unsubscription\n * @param name Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)\n * @param event Unsubscriber Function, must be the one passed to {@link on} or {@link once} subscription methods\n */\n off(name, event) {\n if (!event) {\n throw Error('event to unsubscribe cannot be null');\n }\n this._event(name).delete(event);\n }\n _event(name) {\n const events = this._events.get(name.toLowerCase());\n if (!events) {\n throw Error('No event on' + name + ' on class ' + this.constructor.name);\n }\n return events;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Some fix for JS MAP:\n * - find(key) search an item in the map and returns undefined if not found\n * - get(key) return the item if exists or otherwise create and returns it\n * - set(key, value) returns the value of the item (rather the MAP)\n */\nclass FixMap {\n [Symbol.iterator]() {\n return this._map[Symbol.iterator]();\n }\n get size() {\n return this._map.size;\n }\n constructor(_initValue) {\n this._initValue = _initValue;\n this._map = new Map();\n }\n get(key) {\n let value = this.find(key);\n if (value === undefined) {\n this._map.set(key, (value = this._initValue()));\n }\n return value;\n }\n find(key) {\n return this._map.get(key);\n }\n has(key) {\n return this._map.has(key);\n }\n clear() {\n this._map.clear();\n }\n delete(key) {\n return this._map.delete(key);\n }\n set(key, value) {\n this._map.set(key, value);\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forEach(callbackfn, thisArg) {\n this._map.forEach(callbackfn, thisArg);\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * 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\n * @example\n * const queue = new Queue<number>(2);\n * queue.push(1); // [1]\n * queue.push(2); // [1,2]\n * queue.push(3); // [2,3] 1 has been removed to respect 2 capacity\n */\nclass Queue {\n /**\n * Number of element in the queue\n */\n get size() {\n return this._queue.length;\n }\n /**\n * Maximum capacity for the queue, if not set queue has unlimited capacity\n */\n get capacity() {\n return this._capacity;\n }\n /**\n * Set a maximum capacity for the queue,\n * if you push new value exceding this capacity the firsts are removed (FIFO)\n * if set to undefined the queue is unlimited\n */\n set capacity(value) {\n this._capacity = value;\n if (value != null && this._queue.length > value) {\n this._queue.splice(0, this._queue.length - value);\n }\n }\n /**\n * The front element\n */\n get front() {\n return this._queue[0];\n }\n /**\n * The back element\n */\n get back() {\n return this._queue[this._queue.length - 1];\n }\n /**\n * Iterator though queue's elements\n */\n [Symbol.iterator]() {\n return this._queue[Symbol.iterator]();\n }\n /**\n * Instanciate a new queue object with the type passed as template\n * @param capacity if set it limits the size of the queue, any exceding element pops the first element pushed (FIFO)\n */\n constructor(capacity) {\n this._capacity = capacity;\n this._queue = new Array();\n }\n /**\n * Push a new element in the queue\n * @param value value of the element\n * @returns this\n */\n push(value) {\n if (this._capacity != null && this._queue.push(value) > this._capacity) {\n this.pop();\n }\n return this;\n }\n /**\n * Pop the first element from the queue\n * @returns The first element removed\n */\n pop() {\n return this._queue.shift();\n }\n /**\n * Clear all the elements, queue becomes empty\n * @returns this\n */\n clear() {\n this._queue.length = 0;\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * A collection of number Queue<number> with the following efficient mathematic computation:\n * - minimum value in the collection\n * - maximum value in the collection\n * - average value of the collection\n */\nclass Numbers extends Queue {\n /**\n * minimum value in the collection, or 0 if colleciton is empty\n */\n get minimum() {\n return this._min;\n }\n /**\n * maximum value in the collection, or 0 if colleciton is empty\n */\n get maximum() {\n return this._max;\n }\n /**\n * average value of the collection, or 0 if collection if empty\n */\n get average() {\n if (this._average == null) {\n this._average = this.size ? this._sum / this.size : 0;\n }\n return this._average;\n }\n /**\n * Instantiate the collection of the number\n * @param capacity if set it limits the number of values stored, any exceding number pops the first number pushed (FIFO)\n */\n constructor(capacity) {\n super(capacity);\n this._sum = 0;\n this._min = 0;\n this._max = 0;\n }\n /**\n * Push a value to the back to the collection\n * @param value number to add\n * @returns this\n */\n push(value) {\n if (value > this._max) {\n this._max = value;\n }\n else if (value < this._min) {\n this._min = value;\n }\n this._average = undefined;\n this._sum += value;\n super.push(value);\n return this;\n }\n /**\n * Pop the front number from the collection\n * @returns the front number removed\n */\n pop() {\n const front = super.pop();\n if (front === this._max) {\n this._max = Math.max(0, ...this);\n }\n else if (front === this._min) {\n this._min = Math.min(0, ...this);\n }\n this._average = undefined;\n this._sum -= front || 0;\n return front;\n }\n /**\n * Clear all the numbers, collection becomes empty\n * @returns this\n */\n clear() {\n this._min = this._max = this._sum = 0;\n super.clear();\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * Toolkit to deal with Session Description Protocol (SDP),\n * mainly to tranform a SDP string Offer/Answer to a manipulable JS object representation\n * @example\n * const peerConnection = new RTCPeerConnection();\n * peerConnection.createOffer()\n * .then( offer =>\n * // Change offer.sdp string to a JS manipulable object\n * const sdp = SDP.fromString(offer.sdp || '');\n * // Change a property of SDP\n * sdp.v = 2; // change SDP version\n * // Reserialize to the legal SDP string format\n * offer.sdp = SDP.toString(sdp);\n * // Set SDP offer to peerConnection\n * peerConnection.setLocalDescription(offer);\n * )\n */\nconst SDP = {\n /**\n * Unserialize SDP string to a manipulable JS object representation\n * It's an object with:\n * - root SDP properties\n * - media description iterable\n * @param lines SDP string reprensentation\n * @returns SDP object representation, iterable through media description\n * @example\n * [\n * group: \"DUNBLE 0 1\",\n * o: \"- 1699450751193623 0 IN IP4 0.0.0.0\",\n * s: \"-\",\n * t: \"0 0\",\n * v: \"0\",\n * ice-lite: \"\",\n * length: 2,\n * {\n * m: \"audio 9 UDP/TLS/RTP/SAVPF 111\",\n * c: \"IN IP4 0.0.0.0\",\n * rtcp: \"9\",\n * sendonly: \"\",\n * setup: \"passive\",\n * fingerprint: \"sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8\",\n * ice-ufrag: \"fa37\",\n * ice-pwd: \"JncCHryDsbzayy4cBWDxS2\",\n * rtcp-mux: \"\",\n * rtcp-rsize: \"\",\n * rtpmap: \"111 opus/48000/2\",\n * rtcp-fb: \"111 nack\",\n * id: \"0\",\n * fmtp: \"111 minptime=10;useinbandfec=1\",\n * candidate: \"1 1 udp 2130706431 89.105.221.108 56643 typ host\",\n * end-of-candidates: \"\"\n * },\n * {\n * m: \"video 9 UDP/TLS/RTP/SAVPF 106\",\n * c: \"IN IP4 0.0.0.0\",\n * rtcp: \"9\",\n * sendonly: \"\",\n * setup: \"passive\",\n * fingerprint: \"sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8\",\n * ice-ufrag: \"fa37\",\n * ice-pwd: \"JncCHryDsbzayy4cBWDxS2\",\n * rtcp-mux: \"\",\n * rtcp-rsize: \"\",\n * rtpmap: \"106 H264/90000\",\n * rtcp-fb: [\n * \"106 nack\",\n * \"106 goog-remb\"\n * ],\n * mid: \"1\",\n * fmtp: \"106 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1\",\n * candidate: \"1 1 udp 2130706431 89.105.221.108 56643 typ host\",\n * end-of-candidates: \"\"\n * }\n * ]\n */\n fromString(lines) {\n if (Array.isArray(lines)) {\n return lines; // already converted\n }\n const sdp = new Array();\n let media = sdp;\n let fingerprint;\n for (let line of lines.toString().split('\\n')) {\n line = line.trim();\n if (!line) {\n continue;\n }\n let key = line[0];\n const value = line.substring(line.indexOf('=') + 1).trim();\n switch (key.toLowerCase()) {\n case 'a': {\n if (!value) {\n continue;\n } // empty attribute!\n key = this.addAttribute(media, value);\n // save fingerprint to repeat it in medias\n if (sdp === media && key.toLowerCase() === 'fingerprint') {\n fingerprint = media.fingerprint;\n }\n break;\n }\n case 'm':\n if (sdp.length && fingerprint && !sdp[sdp.length - 1].fingerprint) {\n media.fingerprint = fingerprint;\n }\n sdp.push((media = { m: value }));\n break;\n default:\n media[key] = value;\n }\n }\n if (sdp.length && fingerprint && !sdp[sdp.length - 1].fingerprint) {\n media.fingerprint = fingerprint;\n }\n return sdp;\n },\n /**\n * Serialize SDP JS object to a SDP string legal representation\n * @param sdp SDP object reprensetation\n * @returns SDP string reprensentation\n */\n toString(sdp) {\n if (typeof sdp === 'string') {\n return sdp; // already converted\n }\n const medias = [];\n // https://www.cl.cam.ac.uk/~jac22/books/mm/book/node182.html\n let lines = 'v' in sdp ? 'v=' + sdp.v + '\\n' : '';\n if ('o' in sdp) {\n lines += 'o=' + sdp.o + '\\n';\n }\n if ('s' in sdp) {\n lines += 's=' + sdp.s + '\\n';\n }\n const obj = sdp;\n for (const key of Object.keys(sdp)) {\n if (key === 'v' || key === 'o' || key === 's') {\n continue;\n }\n const value = obj[key];\n if (value == null) {\n continue;\n } // ignore this key/value\n const index = parseInt(key);\n if (!isNaN(index)) {\n // Is a number! Media object!\n medias[index] = value;\n continue;\n }\n const count = (Array.isArray(value) && value.length) || 1; // value can be numeric!\n for (let i = 0; i < count; ++i) {\n const line = Array.isArray(value) && value.length ? value[i] : value;\n if (key.length > 1) {\n // when key is superior to 1 letter it's a attribute!\n lines += 'a=' + key;\n if (line) {\n lines += ':';\n }\n }\n else {\n lines += key + '=';\n }\n lines += line + '\\n';\n }\n }\n for (const media of medias) {\n lines += this.toString(media);\n }\n return lines;\n },\n /**\n * While set a property to a SDP object representation is possible directly,\n * we could prefer add a new property without overload a possible already existing value.\n * This function allows to add a property to our SDP representation:\n * - if the key's attribute doesn't exists yet it adds it like a simple JS property sdp[key] = value\n * - if the key's attribute exists already it morphs the value to a Array and push it inside\n * @param sdp the SDP object representation on which added the attribute\n * @param attribute the string attribut in a format \"key:value\" or just \"key\" to add an attribute without value\n * @returns the key part of the attribute added (or if value is empty it returns the same attribute as passed in argument)\n */\n addAttribute(sdp, attribute) {\n var _a;\n const a = SDP.parseAttribute(attribute);\n const value = (_a = a.value) !== null && _a !== void 0 ? _a : ''; // to allow to test if key exists even without value with if(sdp.key != null)\n const obj = sdp;\n const oldValue = obj[a.key];\n if (!oldValue) {\n obj[a.key] = value;\n }\n else if (Array.isArray(oldValue)) {\n oldValue.push(value);\n }\n else if (value !== oldValue) {\n obj[a.key] = [oldValue, value];\n }\n return a.key;\n },\n /**\n * While it's possible to delete a attribute manually on the SDP object representation with a delete sdp.key,\n * we could prefer remove only a value in a sdp.key array containing multiple values.\n * Like opposite to addAttribute this method allows to remove an unique attribute value.\n * @param sdp the SDP object representation on which removed the attribute\n * @param attribute the string attribut in a format \"key:value\" or just \"key\" to remove the whole attribute and all its values\n * @returns the key part of the attribute removed (or if value is empty it returns the same attribute as passed in argument)\n */\n removeAttribute(sdp, attribute) {\n const a = SDP.parseAttribute(attribute);\n const obj = sdp;\n if (a.value === undefined) {\n delete obj[attribute];\n return attribute;\n }\n const current = obj[attribute];\n if (Array.isArray(a.value)) {\n const i = current.findIndex((current) => current === a.value);\n if (i >= 0) {\n current.splice(i, 1);\n }\n }\n else if (current === a.value) {\n delete obj[attribute];\n }\n return a.key;\n },\n /**\n * Parse an attribute in a format \"key:value\"\n * @param attribute string attribute to parse\n * @returns the {key, value} result, with value undefined if attribute was a \"key\" without value\n */\n parseAttribute(attribute) {\n const found = attribute.indexOf(':');\n return {\n key: (found >= 0 ? attribute.substring(0, found) : attribute).trim(),\n value: found >= 0 ? attribute.substring(found + 1).trim() : undefined\n };\n }\n};\nObject.freeze(SDP);/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * The WebSocketReliable class extends WebSocket to bring up the following improvements:\n * - Fix all possible unintentional closing ways to get always a related error message, {@link onClose | onClose(error?) event}\n * - Make possible message sending while connecting. Indeed no need to wait {@link onOpen} before to send message,\n * you can open the socket and immediately send messages, it will be queue and flushs on connection etablishment\n * - Make possible a delayed connection, or a reconnection. Indeed you can create an unconnected Websocket instance\n * without passing any url argument and starts the conneciton more later with {@link WebSocketReliable.open(url) | open(url)} method\n * - Make possible to control sending/queueing message: send method take an optional queueing=true argument to\n * queue message rather send it, a futur call to flush will send it. Then queueing getter allows to handle the queue\n * if need to purge it or remove some queued message. Use it all together can help to prioritize messages or control overload.\n * @example\n * const ws = new WebSocketReliable(url);\n * ws.onClose = (error?:string) => {\n * if(error) {\n * console.error(error);\n * }\n * // reconnection attempt every seconds\n * setTimeout(() => ws.open(url), 1000);\n * }\n * ws.onMessage = (message:string) => {\n * console.log(message);\n * }\n * ws.send('hello'); // send immediatly a hello message is possible (no need to wait onOpen)\n */\nclass WebSocketReliable extends EventEmitter {\n /**\n * Fired when socket is connected\n * @event\n */\n onOpen() { }\n /**\n * Fired on message reception\n * @param message can be binary or string.\n * If you subscribe to the event with message as string type (and not union),\n * it means that you know that all your messages are distributed in a string format\n * @event\n */\n onMessage(message) { }\n /**\n * Fired on websocket close\n * @param error error description on an improper closure\n * @event\n */\n onClose(error) {\n if (error) {\n this.log('onClose', error).error();\n }\n else {\n this.log('onClose').info();\n }\n }\n /**\n * binaryType, fix binary type to arrayBuffer\n */\n get binaryType() {\n return 'arraybuffer';\n }\n get recvByteRate() {\n return this._recvByteRate.value();\n }\n get sendByteRate() {\n return this._sendByteRate.value();\n }\n /**\n * url of connection\n */\n get url() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * extensions negociated by the server\n */\n get extensions() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.extensions) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * protocol negociated by the server\n */\n get protocol() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.protocol) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * opened equals true when connection is etablished, in other word when onOpen event is fired\n */\n get opened() {\n return this._opened;\n }\n /**\n * {@link https://developer.mozilla.org/docs/Web/API/WebSocket/readyState | Official websocket readyState}\n */\n get readyState() {\n return this._ws ? this._ws.readyState : 3;\n }\n /**\n * True when connection is closed, in other words when {@link onClose} event is fired\n * or when WebSocketReliable is build without url (disconnected creation)\n */\n get closed() {\n return this._closed;\n }\n /**\n * The number of bytes of data that were queued during calls to send() but not yet transmitted to the network\n */\n get bufferedAmount() {\n var _a;\n return this._queueingBytes + (((_a = this._ws) === null || _a === void 0 ? void 0 : _a.bufferedAmount) || 0);\n }\n /**\n * Queued messages from a call to send() waiting to be transmit one time websocket connection opened (or with an explicit call to flush() method)\n */\n get queueing() {\n return this._queueing;\n }\n /**\n * Create a WebSocketReliable object, and open it if an url is passed in argument\n * @param url URL of the WebSocket endpoint or null to start the connection later\n */\n constructor(url, protocols) {\n super();\n this._queueing = [];\n this._queueingBytes = 0;\n this._opened = false;\n this._closed = true;\n this._recvByteRate = new ByteRate();\n this._sendByteRate = new ByteRate();\n if (url) {\n this.open(url, protocols);\n }\n }\n /**\n * Open a WebSocket connection\n * @param url url of the websocket endpoint\n * @returns this\n */\n open(url, protocols) {\n this._closed = false;\n const ws = (this._ws = new WebSocket(url, protocols));\n ws.binaryType = this.binaryType;\n ws.onmessage = e => {\n var _a;\n this._recvByteRate.addBytes((_a = e.data.byteLength) !== null && _a !== void 0 ? _a : e.data.length);\n this.onMessage(e.data);\n };\n // Add details and fix close ways\n ws.onclose = (e) => {\n if (!this._opened) {\n // close during connection!\n this.close({\n type: 'WebSocketReliableError',\n name: 'Connection failed',\n url: url.toString(),\n reason: String(e.reason || e.code)\n });\n }\n else if (e.code === 1000 || e.code === 1005) {\n // normal disconnection from server\n this.close({\n type: 'WebSocketReliableError',\n name: 'Server shutdown',\n url: url.toString()\n });\n }\n else {\n // abnormal disconnection from server\n this.close({\n type: 'WebSocketReliableError',\n name: 'Socket disconnection',\n url: url.toString(),\n reason: String(e.reason || e.code)\n });\n }\n };\n // Wrap send method to queue messages until connection is established.\n ws.onopen = _ => {\n this._opened = true;\n this.flush();\n this.onOpen();\n };\n return this;\n }\n /**\n * Send a message\n * @param message\n * @param queueing When set it reports the sending to a more later call to flush\n * @returns this\n */\n send(message, queueing = false) {\n if (this._closed) {\n throw Error('Open socket before to send data');\n }\n if (queueing || !this._opened) {\n this._queueing.push(message);\n this._queueingBytes += typeof message === 'string' ? message.length : message.byteLength;\n }\n else {\n this._send(message);\n }\n return this;\n }\n /**\n * Send queueing messages\n */\n flush() {\n if (this._ws) {\n for (const message of this._queueing) {\n this._send(message);\n }\n }\n this._queueing.length = 0;\n this._queueingBytes = 0;\n }\n /**\n * Close websocket\n * @param error the error reason if is not a proper close\n */\n close(error) {\n if (!this._ws || this._closed) {\n return;\n }\n this._closed = true;\n this._ws.onopen = this._ws.onclose = this._ws.onmessage = null; // otherwise can receive message AFTER close!\n this._ws.close(); // Don't set to undefined to keep this._ws properties valid!\n // release resources!\n this._queueing.length = 0;\n this._queueingBytes = 0;\n this.onClose(error);\n // Reset _opened in last to allow to differenciate in onClose an error while connecting OR while connected\n this._opened = false;\n }\n _send(message) {\n if (!this._ws) {\n return;\n }\n this._sendByteRate.addBytes(typeof message === 'string' ? message.length : message.byteLength);\n this._ws.send(message);\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Decode the timestamp from a video element and compute the latency between the timestamp and the current date.\n *\n * @param {HTMLVideoElement} sourceEl the video element to get the image from\n * @param {HTMLCanvasElement} canvas\n * @param {CanvasRenderingContext2D} context\n * @param {Date} now current date, new Date() by default\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Number} tolerance percentage of tolerance for the black and white threshold, 0.2 by default\n * @returns {Number} The latency in millisecond between 'now' and the decoded timestamp, 0 if the timestamp cannot be decoded\n */\nfunction getLatency(sourceEl, canvas, context, now = new Date(), blocksPerRow = 32, tolerance = 0.2) {\n canvas.width = sourceEl.videoWidth;\n canvas.height = Math.floor(canvas.width / blocksPerRow);\n if (!canvas.width || !canvas.height) {\n // No pixel to parse!\n return 0;\n }\n context.drawImage(sourceEl, 0, 0, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height);\n const timestamp = decodeTimestamp(context, canvas.width, blocksPerRow, tolerance);\n return timestamp == null ? 0 : now.getTime() - timestamp.getTime();\n}\n/**\n * Decode a previously encoded timestamp from a canvas\n *\n * @param {CanvasRenderingContext2D} context\n * @param {Number} lineWidth width of the line in pixels\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Number} tolerance percentage of tolerance for the black and white threshold, 0.2 by default\n * @returns {Date|null} The Date object representing the timestamp or null if the timestamp cannot be decoded\n */\nfunction decodeTimestamp(context, lineWidth, blocksPerRow = 32, tolerance = 0.2) {\n const blockSize = lineWidth / blocksPerRow;\n let binaryTime = '';\n let i = blockSize / 2;\n const data = context.getImageData(0, Math.round(i), lineWidth, 1).data;\n const pixels = new Uint32Array(data.buffer);\n const blackThreshold = 0xff * tolerance;\n const whiteThreshold = 0xff * (1 - tolerance);\n while (i < pixels.length) {\n const pixel = pixels[Math.round(i)] & 0xffffff;\n // Extract luminance from RGB\n const Y = 0.299 * ((pixel >> 16) & 0xff) + 0.587 * ((pixel >> 8) & 0xff) + 0.114 * (pixel & 0xff);\n if (Y < blackThreshold) {\n // Black\n binaryTime += '1';\n }\n else if (Y > whiteThreshold) {\n // White\n binaryTime += '0';\n }\n else {\n return;\n }\n i += blockSize;\n }\n const day = parseInt(binaryTime.slice(0, 5), 2);\n const hour = parseInt(binaryTime.slice(5, 10), 2);\n const minute = parseInt(binaryTime.slice(10, 16), 2);\n const second = parseInt(binaryTime.slice(16, 22), 2);\n const millisecond = parseInt(binaryTime.slice(22, 32), 2);\n const now = new Date();\n return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute, second, millisecond));\n}\n/**\n * Encode the current timestamp into a line composed of blocks of black and white pixels\n * written on the top of the canvas.\n *\n * @param {CanvasRenderingContext2D} context\n * @param {Number} lineWidth width of the line in pixels\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Date} now current date, new Date() by default\n */\nfunction encodeTimestamp(context, lineWidth, blocksPerRow = 32, now = new Date()) {\n const blockSize = Math.floor(lineWidth / blocksPerRow);\n const day = now.getUTCDate();\n const hour = now.getUTCHours();\n const minute = now.getUTCMinutes();\n const second = now.getUTCSeconds();\n const millisecond = now.getUTCMilliseconds();\n const binaryDay = day.toString(2).padStart(5, '0');\n const binaryHour = hour.toString(2).padStart(5, '0');\n const binaryMinute = minute.toString(2).padStart(6, '0');\n const binarySecond = second.toString(2).padStart(6, '0');\n const binaryMillisecond = millisecond.toString(2).padStart(10, '0');\n const binaryTime = binaryDay + binaryHour + binaryMinute + binarySecond + binaryMillisecond;\n for (let i = 0; i < binaryTime.length; i++) {\n const x = (i % blocksPerRow) * blockSize;\n const y = Math.floor(i / blocksPerRow) * blockSize;\n context.fillStyle = binaryTime[i] === '1' ? 'black' : 'white';\n context.fillRect(x, y, blockSize, blockSize);\n }\n}var EpochTime=/*#__PURE__*/Object.freeze({__proto__:null,decodeTimestamp:decodeTimestamp,encodeTimestamp:encodeTimestamp,getLatency:getLatency});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * An user-interface compoment to vizualize real-time metrics\n */\nclass UIMetrics {\n /**\n * get graph margin in pixels\n */\n get graphMargin() {\n return this._graphMargin;\n }\n /**\n * set graph margin in pixels\n */\n set graphMargin(value) {\n this._graphMargin = value;\n }\n /**\n * get text margin in pixels\n */\n get textMargin() {\n return this._textMargin;\n }\n /**\n * set text margin in pixels\n */\n set textMargin(value) {\n this._textMargin = value;\n }\n /**\n * get metric line height in pixels\n */\n get lineHeight() {\n return this._lineHeight;\n }\n /**\n * set metric line height in pixels\n */\n set lineHeight(value) {\n this._lineHeight = value;\n }\n /**\n * get label width in pixels\n */\n get labelWidth() {\n return this._labelWidth;\n }\n /**\n * set label width in pixels\n */\n set labelWidth(value) {\n this._labelWidth = value;\n }\n /**\n * get legend font size in pixels\n */\n get legendFontSize() {\n return this._legendFontSize;\n }\n /**\n * set legend font size in pixels\n */\n set legendFontSize(value) {\n this._legendFontSize = value;\n }\n /**\n * get the metric unit-step in pixels\n */\n get stepSize() {\n return this._stepSize;\n }\n /**\n * set the metric unit-step in pixels\n */\n set stepSize(value) {\n this._stepSize = value;\n }\n constructor(ui) {\n this._ui = ui;\n // default values in pixels\n this._lineHeight = 40;\n this._labelWidth = 170;\n this._graphMargin = 5;\n this._textMargin = 5;\n this._legendFontSize = 13;\n this._stepSize = 10;\n this._ranges = {};\n }\n /**\n * Reset metrics stats, essentially rescaling the metrics\n */\n reset() {\n this._ranges = {};\n }\n /**\n * build metric from stats\n * @param stats Map with stats per entry\n * @returns\n */\n display(stats) {\n if (this._html != null) {\n // CPU processing, skip one stats!\n return;\n }\n this._html = '';\n const averageWidth = (this._legendFontSize / 2) * 7; // 7 chars (1 char width ≈ fontSize/2)\n const width = this._ui.clientWidth - averageWidth;\n const graphHeight = this._lineHeight - 2 * this._graphMargin;\n const graphMiddle = Math.round(this._lineHeight / 2);\n const textY = Math.round(this._lineHeight / 2 + this._textMargin);\n const titleWidth = this._labelWidth - 2 * this._textMargin;\n const averageCenter = averageWidth / 2;\n for (const [key, values] of stats) {\n let x = this._labelWidth + values.length * this._stepSize;\n if (x >= width) {\n x -= values.splice(0, Math.ceil((x - width) / this._stepSize)).length * this._stepSize;\n }\n if (!values.length) {\n continue;\n }\n /*\n <svg class=\"list-group-item p-0\" style=\"height: 40px;\" xmlns=\"http://www.w3.org/2000/svg\">\n <text x=\"5\" y=\"22\">M text</text>\n <path fill=\"none\" d=\"M100 0 110 22 120 0 130 20\" stroke-width=\"1\" stroke=\"brown\"/>\n </svg>\n */\n this._html +=\n '<svg class=\"list-group-item p-0\" style=\"height: ' +\n this._lineHeight +\n 'px\" xmlns=\"http://www.w3.org/2000/svg\">';\n this._html += '<text x=\"' + this._textMargin + '\" y=\"' + textY + '\">' + key + '</text>';\n this._html +=\n '<text x=\"' +\n titleWidth +\n '\" y=\"' +\n textY +\n '\" text-anchor=\"end\">' +\n values[values.length - 1].toString() +\n '</text>';\n this._html += '<path fill=\"none\" d=\"M' + this._labelWidth + ' ' + graphMiddle;\n this._html += 'H' + (width + averageCenter);\n this._html += '\" stroke-width=\"1\" stroke=\"lightgray\" stroke-dasharray=\"10,10\"/>';\n this._html += '<path fill=\"none\" stroke-width=\"1\" stroke=\"brown\" d=\"M';\n let min = Number.POSITIVE_INFINITY;\n let max = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < values.length; ++i) {\n const value = parseFloat(values[i].toString());\n if (value < min) {\n min = value;\n }\n if (value > max) {\n max = value;\n }\n }\n let range = this._ranges[key];\n if (!range) {\n this._ranges[key] = range = { min: Number.POSITIVE_INFINITY, max: Number.NEGATIVE_INFINITY };\n }\n range.min = Math.min(range.min, min);\n range.max = Math.max(range.max, max);\n const delta = range.max - range.min;\n let minCircle = '';\n let maxCircle = '';\n for (let i = 0; i < values.length; ++i) {\n x -= this._stepSize;\n const value = parseFloat(values[i].toString());\n const y = graphMiddle + (delta ? Math.round((0.5 - (value - range.min) / delta) * graphHeight) : 0);\n this._html += x + ' ' + y + ' ';\n if (value === min) {\n maxCircle = maxCircle || this._drawCircle(x, y, value);\n }\n else if (value === max) {\n minCircle = minCircle || this._drawCircle(x, y, value);\n }\n }\n this._html += '\" />'; // end path\n // Average\n const average = Math.round((max - min) / 2);\n this._html += '<text text-anchor=\"middle\" font-size=\"' + this._legendFontSize + '\" y=\"' + textY + '\">';\n this._html +=\n '<tspan x=\"' +\n (width + averageCenter) +\n '\" dy=\"-0.5em\">' +\n (min !== max ? '≈' : '=') +\n (min + average) +\n '</tspan>';\n this._html += '<tspan x=\"' + (width + averageCenter) + '\" dy=\"1em\">±' + average + '</tspan>';\n this._html += '</text>';\n this._html += minCircle + maxCircle;\n this._html += '</svg>';\n }\n requestAnimationFrame(() => {\n if (this._html != null) {\n this._ui.innerHTML = this._html;\n this._html = undefined;\n }\n });\n }\n _drawCircle(x, y, value) {\n let circle = '<circle cx=\"' + x + '\" cy=\"' + y + '\" r=\"2\" fill=\"green\" />';\n const legendFontHeight = 0.7 * this._legendFontSize;\n const graphMiddle = Math.round(this._lineHeight / 2);\n if (y < graphMiddle) {\n // legend below\n y += this.textMargin + legendFontHeight;\n }\n else {\n // legend above\n y -= this.textMargin;\n }\n circle +=\n '<text font-style=\"italic\" font-size=\"' +\n this._legendFontSize +\n '\" x=\"' +\n (x - this._legendFontSize) +\n '\" y=\"' +\n y +\n '\">' +\n value +\n '</text>';\n return circle;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\nconst VERSION = '3.2.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map\n"],"names":["_decoder$1","TextDecoder","BinaryReader","constructor","data","this","_data","Uint8Array","buffer","byteOffset","byteLength","_size","_position","_view","DataView","size","available","value","position","reset","Math","max","shrink","rest","next","count","read8","getUint8","read16","getUint16","read24","read32","getUint32","read64","readFloat","getFloat32","readDouble","getFloat64","read7Bit","bytes","result","factor","byte","readString","i","read","decode","readHex","hex","toString","slice","pos","subarray","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","e","rejected","done","then","apply","SuppressedError","_decoder","_encoder","TextEncoder","_perf","performance","EMPTY_FUNCTION","time","floor","now","options","urlOrQueryOrSearch","location","undefined","URL","searchParams","startsWith","substring","URLSearchParams","objectFrom","withType","noEmptyString","params","Object","assign","obj","key","val","objectEntries","number","Number","isNaN","toLowerCase","Array","isArray","push","entries","from","Symbol","iterator","toBin","encode","getExtension","path","dot","lastIndexOf","getFile","codesFromString","codes","length","charCodeAt","trimStart","chars","includes","LogLevel","Util","freeze","__proto__","equal","a","b","fetch","input","init","response","self","status","error","body","text","statusText","getBaseFile","file","safePromise","timeout","promise","timer","race","setTimeout","finally","clearTimeout","sleep","ms","stringify","space","decimal","recursion","noBin","String","message","toFixed","res","name","timeOrigin","trim","start","end","trimEnd","BinaryWriter","view","capacity","dataOrSize","offset","_isConst","reserve","clear","write","_a","bin","ArrayBuffer","set","write8","write16","setUint16","write24","setUint8","write32","setUint32","write64","writeFloat","setFloat32","writeDouble","setFloat64","write7Bit","writeString","writeHex","parseInt","Error","_logging","setInterval","console","assert","_overrideLogLevel","_charLevels","Log","_bind","ERROR","warn","WARN","info","INFO","debug","DEBUG","log","args","_args","_log","_onLog","localLog","level","_b","logLevel","on","_done","bind","Loggable","BitReader","super","_bit","gotten","readExpGolomb","ByteRate","onBytes","interval","_interval","updateSamples","round","exact","duration","_time","_bytes","addBytes","time$1","lastSample","_samples","clip","_clip","removes","sample","splice","timeOK","NetAddress","fixProtocol","protocol","address","found","indexOf","charAt","endsWith","domain","_domain","port","_port","_address","valueOf","defaultPort","Type","defineMediaExt","type","HESP","mediaExt","WEBRTC","WRTS","ext","endPoint","pathname","_","META","DATA","Connect","buildURL","url","streamName","accessToken","query","EventEmitter","_events","Map","proto","getPrototypeOf","prototype","getOwnPropertyNames","Function","events","Set","defaultEvent","raise","call","event","defineProperties","get","_event","add","signal","addEventListener","delete","once","off","FixMap","_map","_initValue","find","has","forEach","callbackfn","Queue","_queue","_capacity","front","back","pop","shift","Numbers","minimum","_min","maximum","_max","average","_average","_sum","min","SDP","fromString","lines","sdp","fingerprint","media","line","split","addAttribute","m","medias","v","o","s","keys","index","attribute","parseAttribute","oldValue","removeAttribute","current","findIndex","WebSocketReliable","onOpen","onMessage","onClose","binaryType","recvByteRate","_recvByteRate","sendByteRate","_sendByteRate","_ws","extensions","opened","_opened","readyState","closed","_closed","bufferedAmount","_queueingBytes","queueing","_queueing","protocols","open","ws","WebSocket","onmessage","onclose","code","close","reason","onopen","flush","send","_send","decodeTimestamp","context","lineWidth","blocksPerRow","tolerance","blockSize","binaryTime","getImageData","pixels","Uint32Array","blackThreshold","whiteThreshold","pixel","Y","day","hour","minute","second","millisecond","Date","UTC","getUTCFullYear","getUTCMonth","EpochTime","encodeTimestamp","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","getUTCMilliseconds","padStart","x","y","fillStyle","fillRect","getLatency","sourceEl","canvas","width","videoWidth","height","drawImage","timestamp","getTime","UIMetrics","graphMargin","_graphMargin","textMargin","_textMargin","lineHeight","_lineHeight","labelWidth","_labelWidth","legendFontSize","_legendFontSize","stepSize","_stepSize","ui","_ui","_ranges","display","stats","_html","averageWidth","clientWidth","graphHeight","graphMiddle","textY","titleWidth","averageCenter","values","ceil","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","range","delta","minCircle","maxCircle","_drawCircle","requestAnimationFrame","innerHTML","circle","legendFontHeight","VERSION"],"mappings":"AAQA,MAAMA,EAAa,IAAIC,YACvB,MAAMC,E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pC,OAlBItB,EADgB5Y,KAAKsN,MAAMrO,KAAK6a,YAAc,GAG9ClB,GAAK3Z,KAAK0a,WAAaoC,EAIvBnD,GAAK3Z,KAAK0a,WAEdmC,GACI,wCACI7c,KAAKib,gBACL,SACCvB,EAAI1Z,KAAKib,iBACV,QACAtB,EACA,KACA/Y,EACA,UACDic,CACV,EAMA,MAACE,EAAU,eAAAld,kBAAAoK,kBAAA0D,eAAAK,cAAAgD,aAAAkI,eAAA5H,kBAAAuB,YAAAxG,SAAAhF,cAAAqG,cAAA0B,gBAAAuE,aAAAP,WAAAgB,SAAAmG,eAAAjT,UAAAyV,aAAArH,uBAAA5I"}
|
|
1
|
+
{"version":3,"file":"web-utils.min.js","sources":["web-utils.js"],"sourcesContent":["/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BinaryReader allows to read binary data\n */\nconst _decoder$1 = new TextDecoder();\nclass BinaryReader {\n constructor(data) {\n this._data =\n 'buffer' in data ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : new Uint8Array(data);\n this._size = this._data.byteLength;\n this._position = 0;\n this._view = new DataView(this._data.buffer, this._data.byteOffset, this._size);\n }\n data() {\n return this._data;\n }\n size() {\n return this._size;\n }\n available() {\n return this._size - this._position;\n }\n value(position = this._position) {\n return this._data[position];\n }\n position() {\n return this._position;\n }\n reset(position = 0) {\n this._position = Math.max(0, position > this._size ? this._size : position);\n }\n shrink(available) {\n const rest = this._size - this._position;\n if (available > rest) {\n return rest;\n }\n this._size = this._position + available;\n return available;\n }\n next(count = 1) {\n const rest = this._size - this._position;\n if (count > rest) {\n count = rest;\n }\n this._position = Math.max(0, this._position + count);\n return count;\n }\n read8() {\n return this.next(1) === 1 ? this._view.getUint8(this._position - 1) : 0;\n }\n read16() {\n return this.next(2) === 2 ? this._view.getUint16(this._position - 2) : 0;\n }\n read24() {\n return this.next(3) === 3\n ? (this._view.getUint16(this._position - 3) << 8) | (this._view.getUint8(this._position - 1) & 0xff)\n : 0;\n }\n read32() {\n return this.next(4) === 4 ? this._view.getUint32(this._position - 4) : 0;\n }\n read64() {\n if (this.next(8) !== 8) {\n return 0;\n }\n return this._view.getUint32(this._position - 8) * 4294967296 + this._view.getUint32(this._position - 4);\n }\n readFloat() {\n return this.next(4) === 4 ? this._view.getFloat32(this._position - 4) : 0;\n }\n readDouble() {\n return this.next(8) === 8 ? this._view.getFloat64(this._position - 8) : 0;\n }\n read7Bit(bytes = 5) {\n let result = 0;\n let factor = 1;\n while (this.available()) {\n const byte = this.read8();\n result += (byte & 0x7f) * factor;\n if (!(byte & 0x80)) {\n break;\n }\n factor *= 128;\n }\n return result;\n }\n readString() {\n let i = this._position;\n while (i < this._size && this._data[i]) {\n ++i;\n }\n const result = this.read(i - this._position);\n this.next(); // skip the 0 termination\n return _decoder$1.decode(result);\n }\n readHex(size) {\n let hex = '';\n while (size-- > 0) {\n hex += ('0' + this.read8().toString(16)).slice(-2);\n }\n return hex;\n }\n /**\n * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size)) or Util.stringify\n * @param {UInt32} size\n */\n read(size = this.available()) {\n if (this.available() < size) {\n return new Uint8Array(size); // default value = empty bytearray!\n }\n const pos = this._position;\n return this._data.subarray(pos, Math.max(pos, (this._position += size)));\n }\n}/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\n\r\nfunction __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\ntypeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\nconst _decoder = new TextDecoder();\nconst _encoder = new TextEncoder();\n/* eslint-disable @typescript-eslint/no-explicit-any */\nconst _perf = performance; // to increase x10 now performance!\n/**\n * Some basic utility functions\n */\n/**\n * An empty lambda function, pratical to disable default behavior of function or events which are not expected to be null\n * @example\n * console.log = Util.EMPTY_FUNCTION; // disable logs without breaking calls\n */\nconst EMPTY_FUNCTION = () => { };\n/**\n * Efficient and high resolution timestamp in milliseconds elapsed since {@link Util.timeOrigin}\n */\nfunction time() {\n return Math.floor(_perf.now());\n}\n/**\n * Time origin represents the time when the application has started\n */\nfunction timeOrigin() {\n return Math.floor(_perf.now() + _perf.timeOrigin);\n}\n/**\n * Parse query and returns it in an easy-to-use Javascript object form\n * @param urlOrQueryOrSearch string, url, or searchParams containing query. If not set it uses `location.search` to determinate query.\n * @returns An javascript object containing each option\n */\nfunction options(urlOrQueryOrSearch = typeof location === 'undefined'\n ? undefined\n : location) {\n if (!urlOrQueryOrSearch) {\n return {};\n }\n try {\n const url = urlOrQueryOrSearch;\n urlOrQueryOrSearch = new URL(url).searchParams;\n }\n catch (e) {\n if (typeof urlOrQueryOrSearch == 'string') {\n if (urlOrQueryOrSearch.startsWith('?')) {\n urlOrQueryOrSearch = urlOrQueryOrSearch.substring(1);\n }\n urlOrQueryOrSearch = new URLSearchParams(urlOrQueryOrSearch);\n }\n }\n // works same if urlOrQueryOrSearch is null, integer, or a already object etc...\n return objectFrom(urlOrQueryOrSearch, { withType: true, noEmptyString: true });\n}\n/**\n * Returns an easy-to-use Javascript object something iterable, such as a Map, Set, or Array\n * @param value iterable input\n * @param params.withType `false`, if set it tries to cast string value to a JS number/boolean/undefined/null type.\n * @param params.noEmptyString `false`, if set it converts empty string value to a true boolean, usefull to allow a `if(result.key)` check for example\n * @returns An javascript object\n */\nfunction objectFrom(value, params) {\n params = Object.assign({ withType: false, noEmptyString: false }, params);\n const obj = {};\n if (!value) {\n return obj;\n }\n for (const [key, val] of objectEntries(value)) {\n value = val;\n if (params.withType && value != null && value.substring) {\n if (value) {\n const number = Number(value);\n if (isNaN(number)) {\n switch (value.toLowerCase()) {\n case 'true':\n value = true;\n break;\n case 'false':\n value = false;\n break;\n case 'null':\n value = null;\n break;\n case 'undefined':\n value = undefined;\n break;\n }\n }\n else {\n value = number;\n }\n }\n else if (params.noEmptyString) {\n // if empty string => TRUE to allow a if(options.key) check for example\n value = true;\n }\n }\n if (obj[key]) {\n if (!Array.isArray(obj[key])) {\n obj[key] = new Array(obj[key]);\n }\n obj[key].push(value);\n }\n else {\n obj[key] = value;\n }\n }\n return obj;\n}\n/**\n * Returns entries from something iterable, such as a Map, Set, or Array\n * @param value iterable input\n * @returns An javascript object\n */\nfunction objectEntries(value) {\n if (value.entries) {\n return value.entries();\n }\n return Array.from({\n [Symbol.iterator]: function* () {\n for (const key in value) {\n yield [key, value[key]];\n }\n }\n });\n}\n/**\n * Converts various data types, such as objects, strings, exceptions, errors,\n * or numbers, into a string representation. Since it offers a more comprehensive format,\n * this function is preferred to `JSON.stringify()`.\n * @param obj Any objects, strings, exceptions, errors, or number\n * @param params.space `''`, allows to configure space in the string representation\n * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation\n * @param params.recursion `1`, recursion depth to stringify recursively every object value until this depth, beware if a value refers to a already parsed value an infinite loop will occur\n * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information\n * @returns the final string representation\n */\n// Online Javascript Editor for free\n// Write, Edit and Run your Javascript code using JS Online Compiler\nfunction stringify(obj, params = {}) {\n params = Object.assign({ space: ' ', decimal: 2, recursion: 1, noBin: false }, params);\n if (obj == null) {\n return String(obj);\n }\n const error = obj.error || obj.message;\n if (error) {\n // is a error!\n obj = error;\n }\n // number\n if (obj.toFixed) {\n return obj.toFixed(Number(params.decimal) || 0);\n }\n if (obj.byteLength != null && (obj === null || obj === void 0 ? void 0 : obj[Symbol.iterator])) {\n // Binary!\n if (!params.noBin) {\n return _decoder.decode(obj);\n }\n return '[' + obj.byteLength + '#bytes]';\n }\n // boolean or string type or stop recursivity\n if (typeof obj === 'boolean' || obj.substring || !params.recursion) {\n // is already a string OR has to be stringified\n return String(obj);\n }\n const space = params.space || '';\n if (Array.isArray(obj)) {\n // Array!\n let res = '';\n for (const value of obj) {\n res += (res ? ',' : '[') + space;\n res += stringify(value, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));\n }\n return (res += space + ']');\n }\n let res = '{';\n for (const name in obj) {\n if (res.length > 1) {\n res += ',';\n }\n res += space + name + ':';\n res += stringify(obj[name], Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 })) + space;\n }\n return (res += '}');\n}\n/**\n * Encode a string to a binary representation\n * @param value string value to convert\n * @returns binary conversion\n */\nfunction toBin(value) {\n return _encoder.encode(value);\n}\n/**\n * Execute a promise in a safe way with a timeout if caller doesn't resolve it in the accurate time\n */\nfunction safePromise(timeout, promise) {\n // Returns a race between our timeout and the passed in promise\n let timer;\n return Promise.race([\n promise instanceof Promise ? promise : new Promise(promise),\n new Promise((resolve, reject) => (timer = setTimeout(() => reject('timed out in ' + timeout + 'ms'), timeout)))\n ]).finally(() => clearTimeout(timer));\n}\n/**\n * Wait in milliseconds, requires a call with await keyword!\n */\nfunction sleep(ms) {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n/**\n * Test equality between two value whatever their type, array included\n */\nfunction equal(a, b) {\n if (Object(a) !== a) {\n if (Object(b) === b) {\n return false;\n }\n // both primitive (null and undefined included)\n return a === b;\n }\n // complexe object\n if (a[Symbol.iterator]) {\n if (!b[Symbol.iterator]) {\n return false;\n }\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i !== a.length; ++i) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n }\n return a === b;\n}\n/**\n * fetch help method with few usefull fix:\n * - throw an string exception if response code is not 200 with the text of the response or uses statusText\n */\nfunction fetch(input, init) {\n return __awaiter(this, void 0, void 0, function* () {\n const response = yield self.fetch(input, init);\n if (response.status >= 300) {\n let error;\n if (response.body) {\n error = yield response.text();\n }\n throw (error || response.statusText || response.status).toString();\n }\n return response;\n });\n}\n/**\n * Get Extension part from path\n * @param path path to parse\n * @returns the extension\n */\nfunction getExtension(path) {\n const dot = path.lastIndexOf('.');\n const ext = dot >= 0 && dot > path.lastIndexOf('/') ? path.substring(dot) : '';\n return ext;\n}\n/**\n * Get File part from path\n * @param path path to parse\n * @returns the file name\n */\nfunction getFile(path) {\n return path.substring(path.lastIndexOf('/') + 1);\n}\n/**\n * Get Base File part from path, without extension\n * @param path path to parse\n * @returns the base file name\n */\nfunction getBaseFile(path) {\n const dot = path.lastIndexOf('.');\n const file = path.lastIndexOf('/') + 1;\n return dot >= 0 && dot >= file ? path.substring(file, dot) : path.substring(file);\n}\nfunction codesFromString(value) {\n const codes = [];\n for (let i = 0; i < value.length; ++i) {\n codes.push(value.charCodeAt(i));\n }\n return codes;\n}\n/**\n * String Trim function with customizable chars\n * @param value string to trim\n * @param chars chars to use to trim\n * @returns string trimmed\n */\nfunction trim(value, chars = ' ') {\n const codes = codesFromString(chars);\n let start = 0;\n while (start < value.length && codes.includes(value.charCodeAt(start))) {\n ++start;\n }\n let end = value.length;\n while (end > 0 && codes.includes(value.charCodeAt(end - 1))) {\n --end;\n }\n return value.substring(start, end);\n}\n/**\n * String Trim Start function with customizable chars\n * @param value string to trim start\n * @param chars chars to use to trim start\n * @returns string trimmed\n */\nfunction trimStart(value, chars = ' ') {\n const codes = codesFromString(chars);\n let i = 0;\n while (i < value.length && codes.includes(value.charCodeAt(i))) {\n ++i;\n }\n return value.substring(i);\n}\n/**\n * String Trim End function with customizable chars\n * @param value string to trim end\n * @param chars chars to use to trim end\n * @returns string trimmed\n */\nfunction trimEnd(value, chars = ' ') {\n const codes = codesFromString(chars);\n let i = value.length;\n while (i > 0 && codes.includes(value.charCodeAt(i - 1))) {\n --i;\n }\n return value.substring(0, i);\n}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getBaseFile:getBaseFile,getExtension:getExtension,getFile:getFile,objectEntries:objectEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BinaryWriter allows to write data in its binary form\n */\nclass BinaryWriter {\n get view() {\n if (!this._view) {\n this._view = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);\n }\n return this._view;\n }\n get capacity() {\n return this._data.byteLength;\n }\n constructor(dataOrSize = 64, offset = 0, length) {\n if (typeof dataOrSize == 'number') {\n // allocate new buffer\n this._data = new Uint8Array(dataOrSize);\n this._size = 0;\n }\n else if ('buffer' in dataOrSize) {\n // append to existing data!\n this._data = new Uint8Array(dataOrSize.buffer, dataOrSize.byteOffset, dataOrSize.byteLength);\n this._size = dataOrSize.byteLength;\n }\n else {\n // overrides data\n this._isConst = true; // better than boolean for memory usage\n if (length == null) {\n // /!\\ Safari does not support undefined length, so we need to use byteLength instead\n length = dataOrSize.byteLength;\n }\n this._data = new Uint8Array(dataOrSize, offset, length);\n this._size = 0;\n }\n }\n data() {\n return new Uint8Array(this._data.buffer, this._data.byteOffset, this._size);\n }\n size() {\n return this._size || 0;\n }\n next(count = 1) {\n return this.reserve((this._size += count));\n }\n clear(size = 0) {\n return this.reserve((this._size = size));\n }\n /**\n * Write binary data\n * @param data\n */\n write(data) {\n var _a;\n let bin;\n if (typeof data === 'string') {\n // Convertit la chaîne en Uint8Array\n bin = toBin(data);\n }\n else if (data instanceof ArrayBuffer) {\n bin = new Uint8Array(data);\n }\n else if ('buffer' in data) {\n bin = new Uint8Array(data.buffer, (_a = data.byteOffset) !== null && _a !== void 0 ? _a : 0, data.byteLength);\n }\n else {\n bin = data;\n }\n this.reserve(this._size + bin.length);\n this._data.set(bin, this._size);\n this._size += bin.length;\n return this;\n }\n write8(value) {\n if (value > 0xff) {\n // cast to 8bits range\n value = 0xff;\n }\n this.reserve(this._size + 1);\n this._data[this._size++] = value;\n return this;\n }\n write16(value) {\n if (value > 0xffff) {\n // cast to 16bits range\n value = 0xffff;\n }\n this.reserve(this._size + 2);\n this.view.setUint16(this._size, value);\n this._size += 2;\n return this;\n }\n write24(value) {\n if (value > 0xffffff) {\n // cast to 24bits range\n value = 0xffffff;\n }\n this.reserve(this._size + 3);\n this.view.setUint16(this._size, value >> 8);\n this.view.setUint8((this._size += 2), value & 0xff);\n ++this._size;\n return this;\n }\n write32(value) {\n if (value > 0xffffffff) {\n // cast to 32bits range\n value = 0xffffffff;\n }\n this.reserve(this._size + 4);\n this.view.setUint32(this._size, value);\n this._size += 4;\n return this;\n }\n write64(value) {\n this.write32(value / 4294967296);\n return this.write32(value & 0xffffffff);\n }\n writeFloat(value) {\n this.reserve(this._size + 4);\n this.view.setFloat32(this._size, value);\n this._size += 4;\n return this;\n }\n writeDouble(value) {\n this.reserve(this._size + 8);\n this.view.setFloat64(this._size, value);\n this._size += 8;\n return this;\n }\n write7Bit(value) {\n let byte = value & 0x7f;\n while ((value = Math.floor(value / 0x80))) {\n // equivalent to >>=7 for JS!\n this.write8(0x80 | byte);\n byte = value & 0x7f;\n }\n return this.write8(byte);\n }\n writeString(value) {\n return this.write(toBin(value)).write8(0);\n }\n writeHex(value) {\n for (let i = 0; i < value.length; i += 2) {\n this.write8(parseInt(value.substring(i, i + 2), 16));\n }\n return this;\n }\n reserve(size) {\n if (!this._data) {\n throw Error('buffer not writable');\n }\n if (size <= this._data.byteLength) {\n return this;\n }\n if (this._isConst) {\n throw Error('writing exceeds maximum ' + this._data.byteLength + ' bytes limit');\n }\n --size;\n size |= size >> 1;\n size |= size >> 2;\n size |= size >> 4;\n size |= size >> 8;\n size |= size >> 16;\n ++size;\n const data = new Uint8Array(size);\n data.set(this._data); // copy old buffer!\n this._data = data;\n this._view = undefined; // release view\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Log levels\n */\nvar LogLevel;\n(function (LogLevel) {\n LogLevel[\"ERROR\"] = \"error\";\n LogLevel[\"WARN\"] = \"warn\";\n LogLevel[\"INFO\"] = \"info\";\n LogLevel[\"DEBUG\"] = \"debug\";\n})(LogLevel || (LogLevel = {}));\n// check coder issuer: everytime we don't forget to use the built Log\nlet _logging = 0;\nsetInterval(() => {\n console.assert(_logging === 0, _logging.toFixed(), 'calls to log was useless');\n}, 10000);\n// !cb-override-log-level\nconst _overrideLogLevel = options()['!cb-override-log-level'];\nconst _charLevels = new Array(128);\n_charLevels[101] = _charLevels[69] = 1; // error\n_charLevels[119] = _charLevels[87] = 2; // warn\n_charLevels[105] = _charLevels[73] = 3; // info\n_charLevels[100] = _charLevels[68] = 4; // debug\n/**\n * Log instance\n */\nclass Log {\n get error() {\n return this._bind(LogLevel.ERROR);\n }\n get warn() {\n return this._bind(LogLevel.WARN);\n }\n get info() {\n return this._bind(LogLevel.INFO);\n }\n get debug() {\n return this._bind(LogLevel.DEBUG);\n }\n constructor(log, ...args) {\n if (!args.length) {\n // cannot have 0 args to be called correctly!\n args.push(undefined);\n }\n this._args = args;\n this._log = log;\n ++_logging;\n }\n _onLog(localLog, level) {\n var _a, _b;\n // we take like log-level by priority order:\n // 1- the overrideLogLevel\n // 2- the localLog.level\n // 3- the global log.level\n // 4- LogLevel.INFO\n const logLevel = (_b = (_a = _overrideLogLevel !== null && _overrideLogLevel !== void 0 ? _overrideLogLevel : localLog.level) !== null && _a !== void 0 ? _a : log.level) !== null && _b !== void 0 ? _b : LogLevel.INFO;\n if (logLevel === false) {\n // explicit null, no log at all!\n return false;\n }\n if (logLevel !== true && _charLevels[level.charCodeAt(0)] > _charLevels[logLevel.charCodeAt(0)]) {\n return false;\n }\n if (localLog.on) {\n localLog.on(level, this._args);\n }\n return this._args.length ? true : false;\n }\n _bind(level) {\n if (!this._done) {\n this._done = true;\n --_logging;\n }\n // call the global onLog in first (global filter)\n if (!this._onLog(log, level)) {\n return EMPTY_FUNCTION;\n }\n // call the local onLog (local filter)\n if (this._log !== log && !this._onLog(this._log, level)) {\n return EMPTY_FUNCTION;\n }\n // if not intercepted display the log\n return console[level].bind(console, ...this._args);\n }\n}\n/**\n * Inherits from this class to use logs\n */\nclass Loggable {\n constructor() {\n /**\n * Start a log\n * @param args\n * @returns a Log object with the levels of log to call\n */\n this.log = ((...args) => {\n return new Log(this.log, ...args);\n });\n }\n}\n/**\n * Global log\n */\nconst log = ((...args) => {\n return new Log(log, ...args);\n});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * BitReader allows to read binary data bit by bit\n */\nclass BitReader extends Loggable {\n constructor(data) {\n super();\n if ('buffer' in data) {\n this._data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n }\n else {\n this._data = new Uint8Array(data);\n }\n this._size = this._data.byteLength;\n this._position = 0;\n this._bit = 0;\n }\n data() {\n return this._data;\n }\n size() {\n return this._size;\n }\n available() {\n return (this._size - this._position) * 8 - this._bit;\n }\n next(count = 1) {\n let gotten = 0;\n while (this._position !== this._size && count--) {\n ++gotten;\n if (++this._bit === 8) {\n this._bit = 0;\n ++this._position;\n }\n }\n return gotten;\n }\n read(count = 1) {\n let result = 0;\n while (this._position !== this._size && count--) {\n result <<= 1;\n if (this._data[this._position] & (0x80 >> this._bit++)) {\n result |= 1;\n }\n if (this._bit === 8) {\n this._bit = 0;\n ++this._position;\n }\n }\n return result;\n }\n read8() {\n return this.read(8);\n }\n read16() {\n return this.read(16);\n }\n read24() {\n return this.read(24);\n }\n read32() {\n return this.read(32);\n }\n readExpGolomb() {\n let i = 0;\n while (!this.read()) {\n if (!this.available()) {\n return 0;\n }\n ++i;\n }\n const result = this.read(i);\n if (i > 15) {\n this.log('Exponential-Golomb code exceeding unsigned 16 bits').warn();\n return 0;\n }\n return result + (1 << i) - 1;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Class to compute a weighted average byte rate over a specified time interval.\n *\n * This class continuously tracks data transmission and computes the byte rate\n * based on a weighted average, considering both the duration and the number of\n * bytes in each sample. It allows for real-time monitoring of bandwidth usage\n * and provides mechanisms to dynamically adjust the measurement interval.\n *\n * Features:\n * - Computes the byte rate using a **weighted average** approach.\n * - Allows setting a custom interval for tracking.\n * - Supports dynamic clipping to manually shrink the observation window.\n */\nclass ByteRate {\n /**\n * Raised when new bytes are added\n */\n onBytes(bytes) { }\n /**\n * Returns the interval used for computing the byte rate\n */\n get interval() {\n return this._interval;\n }\n /**\n * Sets a new interval for computing the average byte rate\n */\n set interval(value) {\n this._interval = value;\n this.updateSamples();\n }\n /**\n * Constructor initializes the ByteRate object with a specified interval (default: 1000ms).\n * It sets up necessary variables to track byte rate over time.\n *\n * @param interval - Time interval in milliseconds to compute the byte rate.\n */\n constructor(interval = 1000) {\n this._interval = interval;\n this.clear();\n }\n /**\n * Returns the computed byte rate rounded to the nearest integer\n */\n value() {\n return Math.round(this.exact());\n }\n /**\n * Computes the exact byte rate in bytes per second\n */\n exact() {\n // compute rate/s\n this.updateSamples();\n const duration = time() - this._time;\n return duration ? (this._bytes / duration) * 1000 : 0;\n }\n /**\n * Adds a new byte sample to the tracking system.\n * Updates the list of samples and recomputes the byte rate\n *\n * @param bytes - Number of bytes added in this interval\n */\n addBytes(bytes) {\n var _a;\n const time$1 = time();\n const lastSample = this.updateSamples(time$1)[this._samples.length - 1];\n const lastTime = (_a = lastSample === null || lastSample === void 0 ? void 0 : lastSample.time) !== null && _a !== void 0 ? _a : this._time;\n if (time$1 > lastTime) {\n this._samples.push({ bytes, time: time$1, clip: false });\n }\n else {\n // no new duration => attach byte to last-one\n if (!lastSample) {\n // Ignore, was before our ByteRate scope !\n return this;\n }\n lastSample.bytes += bytes;\n }\n this._bytes += bytes;\n this.onBytes(bytes);\n return this;\n }\n /**\n * Clears all recorded byte rate data.\n */\n clear() {\n this._bytes = 0;\n this._time = time();\n this._samples = [];\n this._clip = false;\n return this;\n }\n /**\n * Clips the byte rate tracking by marking the last sample as clipped.\n * If a previous clip exists, removes the clipped sample and all preceding samples.\n * Allows to shrink the interval manually between two positions.\n */\n clip() {\n if (this._clip) {\n this._clip = false;\n let removes = 0;\n for (const sample of this._samples) {\n this._bytes -= sample.bytes;\n ++removes;\n this._time = sample.time;\n if (sample.clip) {\n break;\n }\n }\n this._samples.splice(0, removes);\n }\n const lastSample = this._samples[this._samples.length - 1];\n if (lastSample) {\n lastSample.clip = true;\n this._clip = true;\n }\n return this;\n }\n updateSamples(now = time()) {\n // Remove obsolete sample\n const timeOK = now - this._interval;\n let removes = 0;\n let sample;\n while (this._time < timeOK && (sample = this._samples[removes])) {\n this._bytes -= sample.bytes;\n if (sample.clip) {\n this._clip = sample.clip = false;\n }\n if (sample.time > timeOK) {\n // only a part of the sample to delete !\n sample.bytes *= (sample.time - timeOK) / (sample.time - this._time);\n this._time = timeOK;\n this._bytes += sample.bytes;\n break;\n }\n ++removes;\n this._time = sample.time;\n }\n this._samples.splice(0, removes);\n return this._samples;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Help class to manipulate and parse a net address. The Address can be only the domain field,\n * or a URL format with protocol and path part `(http://)domain(:port/path)`\n * @example\n * const address = new Address('nl-ams-42.live.ceeblue.tv:80');\n * console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'\n * console.log(address.port) // '80'\n * console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'\n */\nclass NetAddress {\n /**\n * Static help function to build an end point from an address `(proto://)domain(:port/path)`\n *\n * Mainly it fix the protocol, in addition if:\n * - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version\n * - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version\n * @param protocol protocol to set in the end point returned\n * @param address string address to fix with protocol as indicated\n * @returns the end point built\n * @example\n * console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'\n * console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'\n * console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'\n */\n static fixProtocol(protocol, address) {\n const found = address.indexOf('://');\n // isolate protocol is present in address\n if (found >= 0) {\n // In this case replace by protocol in keeping SSL like given in address\n if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') {\n // SSL!\n if (protocol.length <= 2 || !protocol.endsWith('s')) {\n protocol += 's'; // Add SSL\n }\n }\n else {\n // Not SSL!\n if (protocol.length > 2 && protocol.endsWith('s')) {\n protocol = protocol.slice(0, -1); // Remove SSL\n }\n }\n // Build address!\n address = address.substring(found + 3);\n }\n return protocol + '://' + address;\n }\n /**\n * The domain part from address `(http://)domain(:port/path)`\n */\n get domain() {\n return this._domain;\n }\n /**\n * The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor\n */\n get port() {\n return this._port;\n }\n /**\n * @returns the string address as passed in the constructor\n */\n toString() {\n return this._address;\n }\n /**\n * @returns the string address as passed in the constructor\n * @override\n */\n valueOf() {\n return this._address;\n }\n /**\n * Build a NetAddress object and parse address\n * @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)`\n * @param defaultPort set a default port to use if there is no port in the string address parsed\n */\n constructor(address, defaultPort) {\n this._address = address;\n // Remove Protocol\n let pos = address.indexOf('/');\n if (pos >= 0) {\n // Remove ://\n if (address.charCodeAt(pos + 1) === 47) {\n // has //\n if (pos > 0) {\n if (address.charCodeAt(pos - 1) === 58) {\n // has ://\n address = address.substring(pos + 2);\n } // something else #//\n }\n else {\n // otherwise starts by //\n address = address.substring(2);\n }\n }\n else if (!pos) {\n // starts by /, remove it\n address = address.substring(1);\n } // else something else #/\n }\n this._domain = address;\n this._port = defaultPort;\n // Parse Port\n pos = address.lastIndexOf(':');\n if (pos >= 0) {\n const port = parseInt(address.substring(pos + 1));\n if (port && port <= 0xffff) {\n this._port = port;\n this._domain = address.substring(0, pos);\n }\n }\n else {\n // Remove Path!\n pos = address.indexOf('/');\n if (pos >= 0) {\n this._domain = address.substring(0, pos);\n }\n }\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Type of connection\n */\nvar Type;\n(function (Type) {\n Type[\"HESP\"] = \"HESP\";\n Type[\"WRTS\"] = \"WebRTS\";\n Type[\"WEBRTC\"] = \"WebRTC\";\n Type[\"META\"] = \"Meta\";\n Type[\"DATA\"] = \"Data\";\n})(Type || (Type = {}));\n/**\n * Some connection utility functions\n */\n/**\n * Defines the {@link Params.mediaExt} based on the type of parameters and its endpoint.\n * This method always assigns a value to params.mediaExt, defaulting to an empty string if indeterminable,\n * allowing detection of whether the function has been applied to the parameters.\n * @param type The type of parameters to define.\n * @param params The parameters for which the media extension is to be defined\n */\nfunction defineMediaExt(type, params) {\n // Compute appropriate mediaExt out parameter\n switch (type) {\n case Type.HESP:\n params.mediaExt = 'mp4';\n break;\n case Type.WEBRTC:\n params.mediaExt = 'rtp';\n break;\n case Type.WRTS: {\n try {\n const url = new URL(params.endPoint);\n const ext = getExtension(getFile(url.pathname));\n // set extension just if not json, json means a manifest file endPoint\n if (ext && ext.toLowerCase() !== '.json') {\n params.mediaExt = ext;\n }\n }\n catch (_) {\n // not an URL, it's only a host => keep mediaExt unchanged to build the URL\n }\n if (!params.mediaExt) {\n // set to its default rts value => always set for WRTS!\n params.mediaExt = 'rts';\n }\n break;\n }\n case Type.META:\n params.mediaExt = 'js';\n break;\n case Type.DATA:\n params.mediaExt = 'json';\n break;\n default:\n params.mediaExt = ''; // set always a value to know that the parameters have been fixed\n console.warn('Unknown params type ' + type);\n break;\n }\n // Fix mediaExt in removing the possible '.' prefix\n params.mediaExt = trimStart(params.mediaExt, '.');\n}\n/**\n * Build an URL from {@link Type | type} and {@link Params | params}\n * @param type Type of the connection wanted\n * @param params Connection parameters\n * @param protocol Optional parameter to choose the prefered protocol to connect\n * @returns The URL of connection\n */\nfunction buildURL(type, params, protocol = 'wss') {\n defineMediaExt(type, params);\n const url = new URL(NetAddress.fixProtocol(protocol, params.endPoint));\n if (url.pathname.length <= 1) {\n // build ceeblue path!\n switch (type) {\n case Type.HESP:\n url.pathname = '/hesp/' + params.streamName + '/index.json';\n break;\n case Type.WEBRTC:\n url.pathname = '/webrtc/' + params.streamName;\n break;\n case Type.WRTS:\n url.pathname = '/wrts/' + params.streamName + '.' + params.mediaExt;\n break;\n case Type.META:\n url.pathname = '/json_' + params.streamName + '.js';\n break;\n case Type.DATA:\n url.pathname = '/' + params.streamName + '.json';\n break;\n default:\n console.warn('Unknown url type ' + type);\n break;\n }\n } // Host has already a path! keep it unchanged, it's user intentionnal (used with some other WHIP/WHEP server?)\n if (params.accessToken) {\n url.searchParams.set('id', params.accessToken);\n }\n for (const key in params.query) {\n url.searchParams.set(key, params.query[key]);\n }\n return url;\n}var Connect=/*#__PURE__*/Object.freeze({__proto__:null,get Type(){return Type},buildURL:buildURL,defineMediaExt:defineMediaExt});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * A advanced EventEmitter which allows to declare event as natural function in the inheriting children class,\n * function must start by `on` prefix to be recognized as an event.\n * The function can define a behavior by default, and user can choose to redefine this behavior,\n * or add an additionnal subscription for this event.\n * In addition you can unsubscribe to multiple events with an `AbortController`\n * @example\n * class Logger extends EventEmitter {\n * onLog(log:string) { console.log(log); } // behavior by default\n *\n * test() {\n * // raise event onLog\n * this.onLog('test');\n * }\n * }\n *\n * const logger = new Logger();\n * logger.test(); // displays a log 'test'\n *\n * // redefine default behavior to display nothing\n * logger.onLog = () => {}\n * logger.test(); // displays nothing\n *\n * // add an additionnal subscription\n * logger.on('log', console.log);\n * logger.test(); // displays a log 'test'\n *\n * // remove the additionnal subscription\n * logger.off('log', console.log);\n * logger.test(); // displays nothing\n *\n * // add two additionnal subscriptions with a AbortController\n * const controller = new AbortController();\n * logger.on('log', log => console.log(log), controller);\n * logger.on('log', log => console.error(log), controller);\n * logger.test(); // displays a log 'test' + an error 'test'\n *\n * // Unsubscribe all the subscription with the AbortController\n * controller.abort();\n * logger.test(); // displays nothing\n */\nclass EventEmitter extends Loggable {\n /**\n * Build our EventEmitter, usually call from children class\n */\n constructor() {\n super();\n this._events = new Map();\n // Fill events with events as defined!\n let proto = Object.getPrototypeOf(this);\n while (proto && proto !== Object.prototype) {\n for (const name of Object.getOwnPropertyNames(proto)) {\n if (name.length < 3 || !name.startsWith('on')) {\n continue;\n }\n if (proto[name] instanceof Function) {\n const events = new Set();\n this._events.set(name.substring(2).toLowerCase(), events);\n let defaultEvent = proto[name];\n const raise = (...args) => {\n // Call default event if not null (can happen in JS usage)\n if (defaultEvent) {\n defaultEvent.call(this, ...args);\n }\n // Call subscribers\n for (const event of events) {\n event(...args);\n }\n };\n Object.defineProperties(this, {\n [name]: {\n get: () => raise,\n set: (value) => {\n // Assign a default behavior!\n defaultEvent = value;\n }\n }\n });\n }\n }\n proto = Object.getPrototypeOf(proto);\n }\n }\n /**\n * Event subscription\n * @param name Name of event without the `on` prefix (ex: `log` to `onLog` event declared)\n * @param event Subscriber Function\n * @param options.signal Optional `AbortSignal` to stop this or multiple subscriptions in same time\n */\n on(name, event, options) {\n var _a;\n if (!event) {\n throw Error('event to subscribe cannot be null');\n }\n const events = this._event(name);\n events.add(event);\n (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(event), { once: true });\n }\n /**\n * Event subscription only one time, once time fired it's automatically unsubscribe\n * @param name Name of event without the `on` prefix (ex: `log` to `onLog` event declared)\n * @param event Subscriber Function\n * @param options.abortSignal Optional `AbortSignal` to stop this or multiple subscriptions in same time\n */\n once(name, event, options) {\n var _a;\n if (!event) {\n throw Error('event to subscribe cannot be null');\n }\n const events = this._event(name);\n events.add((...args) => {\n events.delete(event); // delete from events\n event(...args); // execute event\n });\n (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(event), { once: true });\n }\n /**\n * Event unsubscription\n * @param name Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)\n * @param event Unsubscriber Function, must be the one passed to {@link on} or {@link once} subscription methods\n */\n off(name, event) {\n if (!event) {\n throw Error('event to unsubscribe cannot be null');\n }\n this._event(name).delete(event);\n }\n _event(name) {\n const events = this._events.get(name.toLowerCase());\n if (!events) {\n throw Error('No event on' + name + ' on class ' + this.constructor.name);\n }\n return events;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Some fix for JS MAP:\n * - find(key) search an item in the map and returns undefined if not found\n * - get(key) return the item if exists or otherwise create and returns it\n * - set(key, value) returns the value of the item (rather the MAP)\n */\nclass FixMap {\n [Symbol.iterator]() {\n return this._map[Symbol.iterator]();\n }\n get size() {\n return this._map.size;\n }\n constructor(_initValue) {\n this._initValue = _initValue;\n this._map = new Map();\n }\n get(key) {\n let value = this.find(key);\n if (value === undefined) {\n this._map.set(key, (value = this._initValue()));\n }\n return value;\n }\n find(key) {\n return this._map.get(key);\n }\n has(key) {\n return this._map.has(key);\n }\n clear() {\n this._map.clear();\n }\n delete(key) {\n return this._map.delete(key);\n }\n set(key, value) {\n this._map.set(key, value);\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forEach(callbackfn, thisArg) {\n this._map.forEach(callbackfn, thisArg);\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * 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\n * @example\n * const queue = new Queue<number>(2);\n * queue.push(1); // [1]\n * queue.push(2); // [1,2]\n * queue.push(3); // [2,3] 1 has been removed to respect 2 capacity\n */\nclass Queue {\n /**\n * Number of element in the queue\n */\n get size() {\n return this._queue.length;\n }\n /**\n * Maximum capacity for the queue, if not set queue has unlimited capacity\n */\n get capacity() {\n return this._capacity;\n }\n /**\n * Set a maximum capacity for the queue,\n * if you push new value exceding this capacity the firsts are removed (FIFO)\n * if set to undefined the queue is unlimited\n */\n set capacity(value) {\n this._capacity = value;\n if (value != null && this._queue.length > value) {\n this._queue.splice(0, this._queue.length - value);\n }\n }\n /**\n * The front element\n */\n get front() {\n return this._queue[0];\n }\n /**\n * The back element\n */\n get back() {\n return this._queue[this._queue.length - 1];\n }\n /**\n * Iterator though queue's elements\n */\n [Symbol.iterator]() {\n return this._queue[Symbol.iterator]();\n }\n /**\n * Instanciate a new queue object with the type passed as template\n * @param capacity if set it limits the size of the queue, any exceding element pops the first element pushed (FIFO)\n */\n constructor(capacity) {\n this._capacity = capacity;\n this._queue = new Array();\n }\n /**\n * Push a new element in the queue\n * @param value value of the element\n * @returns this\n */\n push(value) {\n if (this._capacity != null && this._queue.push(value) > this._capacity) {\n this.pop();\n }\n return this;\n }\n /**\n * Pop the first element from the queue\n * @returns The first element removed\n */\n pop() {\n return this._queue.shift();\n }\n /**\n * Clear all the elements, queue becomes empty\n * @returns this\n */\n clear() {\n this._queue.length = 0;\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * A collection of number Queue<number> with the following efficient mathematic computation:\n * - minimum value in the collection\n * - maximum value in the collection\n * - average value of the collection\n */\nclass Numbers extends Queue {\n /**\n * minimum value in the collection, or 0 if colleciton is empty\n */\n get minimum() {\n return this._min;\n }\n /**\n * maximum value in the collection, or 0 if colleciton is empty\n */\n get maximum() {\n return this._max;\n }\n /**\n * average value of the collection, or 0 if collection if empty\n */\n get average() {\n if (this._average == null) {\n this._average = this.size ? this._sum / this.size : 0;\n }\n return this._average;\n }\n /**\n * Instantiate the collection of the number\n * @param capacity if set it limits the number of values stored, any exceding number pops the first number pushed (FIFO)\n */\n constructor(capacity) {\n super(capacity);\n this._sum = 0;\n this._min = 0;\n this._max = 0;\n }\n /**\n * Push a value to the back to the collection\n * @param value number to add\n * @returns this\n */\n push(value) {\n if (value > this._max) {\n this._max = value;\n }\n else if (value < this._min) {\n this._min = value;\n }\n this._average = undefined;\n this._sum += value;\n super.push(value);\n return this;\n }\n /**\n * Pop the front number from the collection\n * @returns the front number removed\n */\n pop() {\n const front = super.pop();\n if (front === this._max) {\n this._max = Math.max(0, ...this);\n }\n else if (front === this._min) {\n this._min = Math.min(0, ...this);\n }\n this._average = undefined;\n this._sum -= front || 0;\n return front;\n }\n /**\n * Clear all the numbers, collection becomes empty\n * @returns this\n */\n clear() {\n this._min = this._max = this._sum = 0;\n super.clear();\n return this;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * Toolkit to deal with Session Description Protocol (SDP),\n * mainly to tranform a SDP string Offer/Answer to a manipulable JS object representation\n * @example\n * const peerConnection = new RTCPeerConnection();\n * peerConnection.createOffer()\n * .then( offer =>\n * // Change offer.sdp string to a JS manipulable object\n * const sdp = SDP.fromString(offer.sdp || '');\n * // Change a property of SDP\n * sdp.v = 2; // change SDP version\n * // Reserialize to the legal SDP string format\n * offer.sdp = SDP.toString(sdp);\n * // Set SDP offer to peerConnection\n * peerConnection.setLocalDescription(offer);\n * )\n */\nconst SDP = {\n /**\n * Unserialize SDP string to a manipulable JS object representation\n * It's an object with:\n * - root SDP properties\n * - media description iterable\n * @param lines SDP string reprensentation\n * @returns SDP object representation, iterable through media description\n * @example\n * [\n * group: \"DUNBLE 0 1\",\n * o: \"- 1699450751193623 0 IN IP4 0.0.0.0\",\n * s: \"-\",\n * t: \"0 0\",\n * v: \"0\",\n * ice-lite: \"\",\n * length: 2,\n * {\n * m: \"audio 9 UDP/TLS/RTP/SAVPF 111\",\n * c: \"IN IP4 0.0.0.0\",\n * rtcp: \"9\",\n * sendonly: \"\",\n * setup: \"passive\",\n * fingerprint: \"sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8\",\n * ice-ufrag: \"fa37\",\n * ice-pwd: \"JncCHryDsbzayy4cBWDxS2\",\n * rtcp-mux: \"\",\n * rtcp-rsize: \"\",\n * rtpmap: \"111 opus/48000/2\",\n * rtcp-fb: \"111 nack\",\n * id: \"0\",\n * fmtp: \"111 minptime=10;useinbandfec=1\",\n * candidate: \"1 1 udp 2130706431 89.105.221.108 56643 typ host\",\n * end-of-candidates: \"\"\n * },\n * {\n * m: \"video 9 UDP/TLS/RTP/SAVPF 106\",\n * c: \"IN IP4 0.0.0.0\",\n * rtcp: \"9\",\n * sendonly: \"\",\n * setup: \"passive\",\n * fingerprint: \"sha-256 51:36:ED:78:A4:9F:25:8C:39:9A:0E:A0:B4:9B:6E:04:37:FF:AD:96:93:71:43:88:2C:0B:0F:AB:6F:9A:52:B8\",\n * ice-ufrag: \"fa37\",\n * ice-pwd: \"JncCHryDsbzayy4cBWDxS2\",\n * rtcp-mux: \"\",\n * rtcp-rsize: \"\",\n * rtpmap: \"106 H264/90000\",\n * rtcp-fb: [\n * \"106 nack\",\n * \"106 goog-remb\"\n * ],\n * mid: \"1\",\n * fmtp: \"106 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1\",\n * candidate: \"1 1 udp 2130706431 89.105.221.108 56643 typ host\",\n * end-of-candidates: \"\"\n * }\n * ]\n */\n fromString(lines) {\n if (Array.isArray(lines)) {\n return lines; // already converted\n }\n const sdp = new Array();\n let media = sdp;\n let fingerprint;\n for (let line of lines.toString().split('\\n')) {\n line = line.trim();\n if (!line) {\n continue;\n }\n let key = line[0];\n const value = line.substring(line.indexOf('=') + 1).trim();\n switch (key.toLowerCase()) {\n case 'a': {\n if (!value) {\n continue;\n } // empty attribute!\n key = this.addAttribute(media, value);\n // save fingerprint to repeat it in medias\n if (sdp === media && key.toLowerCase() === 'fingerprint') {\n fingerprint = media.fingerprint;\n }\n break;\n }\n case 'm':\n if (sdp.length && fingerprint && !sdp[sdp.length - 1].fingerprint) {\n media.fingerprint = fingerprint;\n }\n sdp.push((media = { m: value }));\n break;\n default:\n media[key] = value;\n }\n }\n if (sdp.length && fingerprint && !sdp[sdp.length - 1].fingerprint) {\n media.fingerprint = fingerprint;\n }\n return sdp;\n },\n /**\n * Serialize SDP JS object to a SDP string legal representation\n * @param sdp SDP object reprensetation\n * @returns SDP string reprensentation\n */\n toString(sdp) {\n if (typeof sdp === 'string') {\n return sdp; // already converted\n }\n const medias = [];\n // https://www.cl.cam.ac.uk/~jac22/books/mm/book/node182.html\n let lines = 'v' in sdp ? 'v=' + sdp.v + '\\n' : '';\n if ('o' in sdp) {\n lines += 'o=' + sdp.o + '\\n';\n }\n if ('s' in sdp) {\n lines += 's=' + sdp.s + '\\n';\n }\n const obj = sdp;\n for (const key of Object.keys(sdp)) {\n if (key === 'v' || key === 'o' || key === 's') {\n continue;\n }\n const value = obj[key];\n if (value == null) {\n continue;\n } // ignore this key/value\n const index = parseInt(key);\n if (!isNaN(index)) {\n // Is a number! Media object!\n medias[index] = value;\n continue;\n }\n const count = (Array.isArray(value) && value.length) || 1; // value can be numeric!\n for (let i = 0; i < count; ++i) {\n const line = Array.isArray(value) && value.length ? value[i] : value;\n if (key.length > 1) {\n // when key is superior to 1 letter it's a attribute!\n lines += 'a=' + key;\n if (line) {\n lines += ':';\n }\n }\n else {\n lines += key + '=';\n }\n lines += line + '\\n';\n }\n }\n for (const media of medias) {\n lines += this.toString(media);\n }\n return lines;\n },\n /**\n * While set a property to a SDP object representation is possible directly,\n * we could prefer add a new property without overload a possible already existing value.\n * This function allows to add a property to our SDP representation:\n * - if the key's attribute doesn't exists yet it adds it like a simple JS property sdp[key] = value\n * - if the key's attribute exists already it morphs the value to a Array and push it inside\n * @param sdp the SDP object representation on which added the attribute\n * @param attribute the string attribut in a format \"key:value\" or just \"key\" to add an attribute without value\n * @returns the key part of the attribute added (or if value is empty it returns the same attribute as passed in argument)\n */\n addAttribute(sdp, attribute) {\n var _a;\n const a = SDP.parseAttribute(attribute);\n const value = (_a = a.value) !== null && _a !== void 0 ? _a : ''; // to allow to test if key exists even without value with if(sdp.key != null)\n const obj = sdp;\n const oldValue = obj[a.key];\n if (!oldValue) {\n obj[a.key] = value;\n }\n else if (Array.isArray(oldValue)) {\n oldValue.push(value);\n }\n else if (value !== oldValue) {\n obj[a.key] = [oldValue, value];\n }\n return a.key;\n },\n /**\n * While it's possible to delete a attribute manually on the SDP object representation with a delete sdp.key,\n * we could prefer remove only a value in a sdp.key array containing multiple values.\n * Like opposite to addAttribute this method allows to remove an unique attribute value.\n * @param sdp the SDP object representation on which removed the attribute\n * @param attribute the string attribut in a format \"key:value\" or just \"key\" to remove the whole attribute and all its values\n * @returns the key part of the attribute removed (or if value is empty it returns the same attribute as passed in argument)\n */\n removeAttribute(sdp, attribute) {\n const a = SDP.parseAttribute(attribute);\n const obj = sdp;\n if (a.value === undefined) {\n delete obj[attribute];\n return attribute;\n }\n const current = obj[attribute];\n if (Array.isArray(a.value)) {\n const i = current.findIndex((current) => current === a.value);\n if (i >= 0) {\n current.splice(i, 1);\n }\n }\n else if (current === a.value) {\n delete obj[attribute];\n }\n return a.key;\n },\n /**\n * Parse an attribute in a format \"key:value\"\n * @param attribute string attribute to parse\n * @returns the {key, value} result, with value undefined if attribute was a \"key\" without value\n */\n parseAttribute(attribute) {\n const found = attribute.indexOf(':');\n return {\n key: (found >= 0 ? attribute.substring(0, found) : attribute).trim(),\n value: found >= 0 ? attribute.substring(found + 1).trim() : undefined\n };\n }\n};\nObject.freeze(SDP);/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * The WebSocketReliable class extends WebSocket to bring up the following improvements:\n * - Fix all possible unintentional closing ways to get always a related error message, {@link onClose | onClose(error?) event}\n * - Make possible message sending while connecting. Indeed no need to wait {@link onOpen} before to send message,\n * you can open the socket and immediately send messages, it will be queue and flushs on connection etablishment\n * - Make possible a delayed connection, or a reconnection. Indeed you can create an unconnected Websocket instance\n * without passing any url argument and starts the conneciton more later with {@link WebSocketReliable.open(url) | open(url)} method\n * - Make possible to control sending/queueing message: send method take an optional queueing=true argument to\n * queue message rather send it, a futur call to flush will send it. Then queueing getter allows to handle the queue\n * if need to purge it or remove some queued message. Use it all together can help to prioritize messages or control overload.\n * @example\n * const ws = new WebSocketReliable(url);\n * ws.onClose = (error?:string) => {\n * if(error) {\n * console.error(error);\n * }\n * // reconnection attempt every seconds\n * setTimeout(() => ws.open(url), 1000);\n * }\n * ws.onMessage = (message:string) => {\n * console.log(message);\n * }\n * ws.send('hello'); // send immediatly a hello message is possible (no need to wait onOpen)\n */\nclass WebSocketReliable extends EventEmitter {\n /**\n * Fired when socket is connected\n * @event\n */\n onOpen() { }\n /**\n * Fired on message reception\n * @param message can be binary or string.\n * If you subscribe to the event with message as string type (and not union),\n * it means that you know that all your messages are distributed in a string format\n * @event\n */\n onMessage(message) { }\n /**\n * Fired on websocket close\n * @param error error description on an improper closure\n * @event\n */\n onClose(error) {\n if (error) {\n this.log('onClose', error).error();\n }\n else {\n this.log('onClose').info();\n }\n }\n /**\n * binaryType, fix binary type to arrayBuffer\n */\n get binaryType() {\n return 'arraybuffer';\n }\n get recvByteRate() {\n return this._recvByteRate.value();\n }\n get sendByteRate() {\n return this._sendByteRate.value();\n }\n /**\n * url of connection\n */\n get url() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * extensions negociated by the server\n */\n get extensions() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.extensions) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * protocol negociated by the server\n */\n get protocol() {\n var _a, _b;\n return (_b = (_a = this._ws) === null || _a === void 0 ? void 0 : _a.protocol) !== null && _b !== void 0 ? _b : '';\n }\n /**\n * opened equals true when connection is etablished, in other word when onOpen event is fired\n */\n get opened() {\n return this._opened;\n }\n /**\n * {@link https://developer.mozilla.org/docs/Web/API/WebSocket/readyState | Official websocket readyState}\n */\n get readyState() {\n return this._ws ? this._ws.readyState : 3;\n }\n /**\n * True when connection is closed, in other words when {@link onClose} event is fired\n * or when WebSocketReliable is build without url (disconnected creation)\n */\n get closed() {\n return this._closed;\n }\n /**\n * The number of bytes of data that were queued during calls to send() but not yet transmitted to the network\n */\n get bufferedAmount() {\n var _a;\n return this._queueingBytes + (((_a = this._ws) === null || _a === void 0 ? void 0 : _a.bufferedAmount) || 0);\n }\n /**\n * Queued messages from a call to send() waiting to be transmit one time websocket connection opened (or with an explicit call to flush() method)\n */\n get queueing() {\n return this._queueing;\n }\n /**\n * Create a WebSocketReliable object, and open it if an url is passed in argument\n * @param url URL of the WebSocket endpoint or null to start the connection later\n */\n constructor(url, protocols) {\n super();\n this._queueing = [];\n this._queueingBytes = 0;\n this._opened = false;\n this._closed = true;\n this._recvByteRate = new ByteRate();\n this._sendByteRate = new ByteRate();\n if (url) {\n this.open(url, protocols);\n }\n }\n /**\n * Open a WebSocket connection\n * @param url url of the websocket endpoint\n * @returns this\n */\n open(url, protocols) {\n this._closed = false;\n const ws = (this._ws = new WebSocket(url, protocols));\n ws.binaryType = this.binaryType;\n ws.onmessage = e => {\n var _a;\n this._recvByteRate.addBytes((_a = e.data.byteLength) !== null && _a !== void 0 ? _a : e.data.length);\n this.onMessage(e.data);\n };\n // Add details and fix close ways\n ws.onclose = (e) => {\n if (!this._opened) {\n // close during connection!\n this.close({\n type: 'WebSocketReliableError',\n name: 'Connection failed',\n url: url.toString(),\n reason: String(e.reason || e.code)\n });\n }\n else if (e.code === 1000 || e.code === 1005) {\n // normal disconnection from server\n this.close({\n type: 'WebSocketReliableError',\n name: 'Server shutdown',\n url: url.toString()\n });\n }\n else {\n // abnormal disconnection from server\n this.close({\n type: 'WebSocketReliableError',\n name: 'Socket disconnection',\n url: url.toString(),\n reason: String(e.reason || e.code)\n });\n }\n };\n // Wrap send method to queue messages until connection is established.\n ws.onopen = _ => {\n this._opened = true;\n this.flush();\n this.onOpen();\n };\n return this;\n }\n /**\n * Send a message\n * @param message\n * @param queueing When set it reports the sending to a more later call to flush\n * @returns this\n */\n send(message, queueing = false) {\n if (this._closed) {\n throw Error('Open socket before to send data');\n }\n if (queueing || !this._opened) {\n this._queueing.push(message);\n this._queueingBytes += typeof message === 'string' ? message.length : message.byteLength;\n }\n else {\n this._send(message);\n }\n return this;\n }\n /**\n * Send queueing messages\n */\n flush() {\n if (this._ws) {\n for (const message of this._queueing) {\n this._send(message);\n }\n }\n this._queueing.length = 0;\n this._queueingBytes = 0;\n }\n /**\n * Close websocket\n * @param error the error reason if is not a proper close\n */\n close(error) {\n if (!this._ws || this._closed) {\n return;\n }\n this._closed = true;\n this._ws.onopen = this._ws.onclose = this._ws.onmessage = null; // otherwise can receive message AFTER close!\n this._ws.close(); // Don't set to undefined to keep this._ws properties valid!\n // release resources!\n this._queueing.length = 0;\n this._queueingBytes = 0;\n this.onClose(error);\n // Reset _opened in last to allow to differenciate in onClose an error while connecting OR while connected\n this._opened = false;\n }\n _send(message) {\n if (!this._ws) {\n return;\n }\n this._sendByteRate.addBytes(typeof message === 'string' ? message.length : message.byteLength);\n this._ws.send(message);\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * Decode the timestamp from a video element and compute the latency between the timestamp and the current date.\n *\n * @param {HTMLVideoElement} sourceEl the video element to get the image from\n * @param {HTMLCanvasElement} canvas\n * @param {CanvasRenderingContext2D} context\n * @param {Date} now current date, new Date() by default\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Number} tolerance percentage of tolerance for the black and white threshold, 0.2 by default\n * @returns {Number} The latency in millisecond between 'now' and the decoded timestamp, 0 if the timestamp cannot be decoded\n */\nfunction getLatency(sourceEl, canvas, context, now = new Date(), blocksPerRow = 32, tolerance = 0.2) {\n canvas.width = sourceEl.videoWidth;\n canvas.height = Math.floor(canvas.width / blocksPerRow);\n if (!canvas.width || !canvas.height) {\n // No pixel to parse!\n return 0;\n }\n context.drawImage(sourceEl, 0, 0, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height);\n const timestamp = decodeTimestamp(context, canvas.width, blocksPerRow, tolerance);\n return timestamp == null ? 0 : now.getTime() - timestamp.getTime();\n}\n/**\n * Decode a previously encoded timestamp from a canvas\n *\n * @param {CanvasRenderingContext2D} context\n * @param {Number} lineWidth width of the line in pixels\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Number} tolerance percentage of tolerance for the black and white threshold, 0.2 by default\n * @returns {Date|null} The Date object representing the timestamp or null if the timestamp cannot be decoded\n */\nfunction decodeTimestamp(context, lineWidth, blocksPerRow = 32, tolerance = 0.2) {\n const blockSize = lineWidth / blocksPerRow;\n let binaryTime = '';\n let i = blockSize / 2;\n const data = context.getImageData(0, Math.round(i), lineWidth, 1).data;\n const pixels = new Uint32Array(data.buffer);\n const blackThreshold = 0xff * tolerance;\n const whiteThreshold = 0xff * (1 - tolerance);\n while (i < pixels.length) {\n const pixel = pixels[Math.round(i)] & 0xffffff;\n // Extract luminance from RGB\n const Y = 0.299 * ((pixel >> 16) & 0xff) + 0.587 * ((pixel >> 8) & 0xff) + 0.114 * (pixel & 0xff);\n if (Y < blackThreshold) {\n // Black\n binaryTime += '1';\n }\n else if (Y > whiteThreshold) {\n // White\n binaryTime += '0';\n }\n else {\n return;\n }\n i += blockSize;\n }\n const day = parseInt(binaryTime.slice(0, 5), 2);\n const hour = parseInt(binaryTime.slice(5, 10), 2);\n const minute = parseInt(binaryTime.slice(10, 16), 2);\n const second = parseInt(binaryTime.slice(16, 22), 2);\n const millisecond = parseInt(binaryTime.slice(22, 32), 2);\n const now = new Date();\n return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute, second, millisecond));\n}\n/**\n * Encode the current timestamp into a line composed of blocks of black and white pixels\n * written on the top of the canvas.\n *\n * @param {CanvasRenderingContext2D} context\n * @param {Number} lineWidth width of the line in pixels\n * @param {Number} blocksPerRow number of blocks in the line, 32 by default\n * @param {Date} now current date, new Date() by default\n */\nfunction encodeTimestamp(context, lineWidth, blocksPerRow = 32, now = new Date()) {\n const blockSize = Math.floor(lineWidth / blocksPerRow);\n const day = now.getUTCDate();\n const hour = now.getUTCHours();\n const minute = now.getUTCMinutes();\n const second = now.getUTCSeconds();\n const millisecond = now.getUTCMilliseconds();\n const binaryDay = day.toString(2).padStart(5, '0');\n const binaryHour = hour.toString(2).padStart(5, '0');\n const binaryMinute = minute.toString(2).padStart(6, '0');\n const binarySecond = second.toString(2).padStart(6, '0');\n const binaryMillisecond = millisecond.toString(2).padStart(10, '0');\n const binaryTime = binaryDay + binaryHour + binaryMinute + binarySecond + binaryMillisecond;\n for (let i = 0; i < binaryTime.length; i++) {\n const x = (i % blocksPerRow) * blockSize;\n const y = Math.floor(i / blocksPerRow) * blockSize;\n context.fillStyle = binaryTime[i] === '1' ? 'black' : 'white';\n context.fillRect(x, y, blockSize, blockSize);\n }\n}var EpochTime=/*#__PURE__*/Object.freeze({__proto__:null,decodeTimestamp:decodeTimestamp,encodeTimestamp:encodeTimestamp,getLatency:getLatency});/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\n/**\n * An user-interface compoment to vizualize real-time metrics\n */\nclass UIMetrics {\n /**\n * get graph margin in pixels\n */\n get graphMargin() {\n return this._graphMargin;\n }\n /**\n * set graph margin in pixels\n */\n set graphMargin(value) {\n this._graphMargin = value;\n }\n /**\n * get text margin in pixels\n */\n get textMargin() {\n return this._textMargin;\n }\n /**\n * set text margin in pixels\n */\n set textMargin(value) {\n this._textMargin = value;\n }\n /**\n * get metric line height in pixels\n */\n get lineHeight() {\n return this._lineHeight;\n }\n /**\n * set metric line height in pixels\n */\n set lineHeight(value) {\n this._lineHeight = value;\n }\n /**\n * get label width in pixels\n */\n get labelWidth() {\n return this._labelWidth;\n }\n /**\n * set label width in pixels\n */\n set labelWidth(value) {\n this._labelWidth = value;\n }\n /**\n * get legend font size in pixels\n */\n get legendFontSize() {\n return this._legendFontSize;\n }\n /**\n * set legend font size in pixels\n */\n set legendFontSize(value) {\n this._legendFontSize = value;\n }\n /**\n * get the metric unit-step in pixels\n */\n get stepSize() {\n return this._stepSize;\n }\n /**\n * set the metric unit-step in pixels\n */\n set stepSize(value) {\n this._stepSize = value;\n }\n /**\n * Return the space width available to display average metric\n */\n get averageDisplayWidth() {\n // 7 chars (1 char width ≈ fontSize/2)\n return (this._legendFontSize / 2) * 7;\n }\n /**\n * Return the count of displayable metrics regarding the space available on the screen\n */\n get displayableCount() {\n const width = this._ui.clientWidth - this.averageDisplayWidth;\n return Math.ceil((width - this._labelWidth) / this._stepSize);\n }\n constructor(ui) {\n this._ui = ui;\n // default values in pixels\n this._lineHeight = 40;\n this._labelWidth = 170;\n this._graphMargin = 5;\n this._textMargin = 5;\n this._legendFontSize = 13;\n this._stepSize = 10;\n this._ranges = {};\n }\n /**\n * Reset metrics stats, essentially rescaling the metrics\n */\n reset() {\n this._ranges = {};\n }\n /**\n * build metric from stats\n * @param stats Map with stats per entry\n * @returns\n */\n display(stats) {\n if (this._html != null) {\n // CPU processing, skip one stats!\n return;\n }\n this._html = '';\n const averageDisplayWidth = this.averageDisplayWidth;\n const averageCenter = averageDisplayWidth / 2;\n const width = this._ui.clientWidth - averageDisplayWidth;\n const graphHeight = this._lineHeight - 2 * this._graphMargin;\n const graphMiddle = Math.round(this._lineHeight / 2);\n const textY = Math.round(this._lineHeight / 2 + this._textMargin);\n const titleWidth = this._labelWidth - 2 * this._textMargin;\n for (const [key, fullValues] of stats) {\n const displayableCount = Math.ceil((width - this._labelWidth) / this._stepSize);\n const values = fullValues.slice(Math.max(0, fullValues.length - displayableCount));\n if (!values.length) {\n continue;\n }\n let x = this._labelWidth + values.length * this._stepSize;\n /*\n <svg class=\"list-group-item p-0\" style=\"height: 40px;\" xmlns=\"http://www.w3.org/2000/svg\">\n <text x=\"5\" y=\"22\">M text</text>\n <path fill=\"none\" d=\"M100 0 110 22 120 0 130 20\" stroke-width=\"1\" stroke=\"brown\"/>\n </svg>\n */\n this._html +=\n '<svg class=\"list-group-item p-0\" style=\"height: ' +\n this._lineHeight +\n 'px\" xmlns=\"http://www.w3.org/2000/svg\">';\n this._html += '<text x=\"' + this._textMargin + '\" y=\"' + textY + '\">' + key + '</text>';\n this._html +=\n '<text x=\"' +\n titleWidth +\n '\" y=\"' +\n textY +\n '\" text-anchor=\"end\">' +\n values[values.length - 1].toString() +\n '</text>';\n this._html += '<path fill=\"none\" d=\"M' + this._labelWidth + ' ' + graphMiddle;\n this._html += 'H' + (width + averageCenter);\n this._html += '\" stroke-width=\"1\" stroke=\"lightgray\" stroke-dasharray=\"10,10\"/>';\n this._html += '<path fill=\"none\" stroke-width=\"1\" stroke=\"brown\" d=\"M';\n let min = Number.POSITIVE_INFINITY;\n let max = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < values.length; ++i) {\n const value = parseFloat(values[i].toString());\n if (value < min) {\n min = value;\n }\n if (value > max) {\n max = value;\n }\n }\n let range = this._ranges[key];\n if (!range) {\n this._ranges[key] = range = { min: Number.POSITIVE_INFINITY, max: Number.NEGATIVE_INFINITY };\n }\n range.min = Math.min(range.min, min);\n range.max = Math.max(range.max, max);\n const delta = range.max - range.min;\n let minCircle = '';\n let maxCircle = '';\n for (let i = 0; i < values.length; ++i) {\n x -= this._stepSize;\n const value = parseFloat(values[i].toString());\n const y = graphMiddle + (delta ? Math.round((0.5 - (value - range.min) / delta) * graphHeight) : 0);\n this._html += x + ' ' + y + ' ';\n if (value === min) {\n maxCircle = maxCircle || this._drawCircle(x, y, value);\n }\n else if (value === max) {\n minCircle = minCircle || this._drawCircle(x, y, value);\n }\n }\n this._html += '\" />'; // end path\n // Average\n const average = Math.round((max - min) / 2);\n this._html += '<text text-anchor=\"middle\" font-size=\"' + this._legendFontSize + '\" y=\"' + textY + '\">';\n this._html +=\n '<tspan x=\"' +\n (width + averageCenter) +\n '\" dy=\"-0.5em\">' +\n (min !== max ? '≈' : '=') +\n (min + average) +\n '</tspan>';\n this._html += '<tspan x=\"' + (width + averageCenter) + '\" dy=\"1em\">±' + average + '</tspan>';\n this._html += '</text>';\n this._html += minCircle + maxCircle;\n this._html += '</svg>';\n }\n requestAnimationFrame(() => {\n if (this._html != null) {\n this._ui.innerHTML = this._html;\n this._html = undefined;\n }\n });\n }\n _drawCircle(x, y, value) {\n let circle = '<circle cx=\"' + x + '\" cy=\"' + y + '\" r=\"2\" fill=\"green\" />';\n const legendFontHeight = 0.7 * this._legendFontSize;\n const graphMiddle = Math.round(this._lineHeight / 2);\n if (y < graphMiddle) {\n // legend below\n y += this.textMargin + legendFontHeight;\n }\n else {\n // legend above\n y -= this.textMargin;\n }\n circle +=\n '<text font-style=\"italic\" font-size=\"' +\n this._legendFontSize +\n '\" x=\"' +\n (x - this._legendFontSize) +\n '\" y=\"' +\n y +\n '\">' +\n value +\n '</text>';\n return circle;\n }\n}/**\n * Copyright 2024 Ceeblue B.V.\n * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.\n * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.\n */\nconst VERSION = '3.2.1';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map\n"],"names":["_decoder$1","TextDecoder","BinaryReader","constructor","data","this","_data","Uint8Array","buffer","byteOffset","byteLength","_size","_position","_view","DataView","size","available","value","position","reset","Math","max","shrink","rest","next","count","read8","getUint8","read16","getUint16","read24","read32","getUint32","read64","readFloat","getFloat32","readDouble","getFloat64","read7Bit","bytes","result","factor","byte","readString","i","read","decode","readHex","hex","toString","slice","pos","subarray","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","e","rejected","done","then","apply","SuppressedError","_decoder","_encoder","TextEncoder","_perf","performance","EMPTY_FUNCTION","time","floor","now","options","urlOrQueryOrSearch","location","undefined","URL","searchParams","startsWith","substring","URLSearchParams","objectFrom","withType","noEmptyString","params","Object","assign","obj","key","val","objectEntries","number","Number","isNaN","toLowerCase","Array","isArray","push","entries","from","Symbol","iterator","toBin","encode","getExtension","path","dot","lastIndexOf","getFile","codesFromString","codes","length","charCodeAt","trimStart","chars","includes","LogLevel","Util","freeze","__proto__","equal","a","b","fetch","input","init","response","self","status","error","body","text","statusText","getBaseFile","file","safePromise","timeout","promise","timer","race","setTimeout","finally","clearTimeout","sleep","ms","stringify","space","decimal","recursion","noBin","String","message","toFixed","res","name","timeOrigin","trim","start","end","trimEnd","BinaryWriter","view","capacity","dataOrSize","offset","_isConst","reserve","clear","write","_a","bin","ArrayBuffer","set","write8","write16","setUint16","write24","setUint8","write32","setUint32","write64","writeFloat","setFloat32","writeDouble","setFloat64","write7Bit","writeString","writeHex","parseInt","Error","_logging","setInterval","console","assert","_overrideLogLevel","_charLevels","Log","_bind","ERROR","warn","WARN","info","INFO","debug","DEBUG","log","args","_args","_log","_onLog","localLog","level","_b","logLevel","on","_done","bind","Loggable","BitReader","super","_bit","gotten","readExpGolomb","ByteRate","onBytes","interval","_interval","updateSamples","round","exact","duration","_time","_bytes","addBytes","time$1","lastSample","_samples","clip","_clip","removes","sample","splice","timeOK","NetAddress","fixProtocol","protocol","address","found","indexOf","charAt","endsWith","domain","_domain","port","_port","_address","valueOf","defaultPort","Type","defineMediaExt","type","HESP","mediaExt","WEBRTC","WRTS","ext","endPoint","pathname","_","META","DATA","Connect","buildURL","url","streamName","accessToken","query","EventEmitter","_events","Map","proto","getPrototypeOf","prototype","getOwnPropertyNames","Function","events","Set","defaultEvent","raise","call","event","defineProperties","get","_event","add","signal","addEventListener","delete","once","off","FixMap","_map","_initValue","find","has","forEach","callbackfn","Queue","_queue","_capacity","front","back","pop","shift","Numbers","minimum","_min","maximum","_max","average","_average","_sum","min","SDP","fromString","lines","sdp","fingerprint","media","line","split","addAttribute","m","medias","v","o","s","keys","index","attribute","parseAttribute","oldValue","removeAttribute","current","findIndex","WebSocketReliable","onOpen","onMessage","onClose","binaryType","recvByteRate","_recvByteRate","sendByteRate","_sendByteRate","_ws","extensions","opened","_opened","readyState","closed","_closed","bufferedAmount","_queueingBytes","queueing","_queueing","protocols","open","ws","WebSocket","onmessage","onclose","code","close","reason","onopen","flush","send","_send","decodeTimestamp","context","lineWidth","blocksPerRow","tolerance","blockSize","binaryTime","getImageData","pixels","Uint32Array","blackThreshold","whiteThreshold","pixel","Y","day","hour","minute","second","millisecond","Date","UTC","getUTCFullYear","getUTCMonth","EpochTime","encodeTimestamp","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","getUTCMilliseconds","padStart","x","y","fillStyle","fillRect","getLatency","sourceEl","canvas","width","videoWidth","height","drawImage","timestamp","getTime","UIMetrics","graphMargin","_graphMargin","textMargin","_textMargin","lineHeight","_lineHeight","labelWidth","_labelWidth","legendFontSize","_legendFontSize","stepSize","_stepSize","averageDisplayWidth","displayableCount","_ui","clientWidth","ceil","ui","_ranges","display","stats","_html","averageCenter","graphHeight","graphMiddle","textY","titleWidth","fullValues","values","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat","range","delta","minCircle","maxCircle","_drawCircle","requestAnimationFrame","innerHTML","circle","legendFontHeight","VERSION"],"mappings":"AAQA,MAAMA,EAAa,IAAIC,YACvB,MAAMC,EACF,WAAAC,CAAYC,GACRC,KAAKC,MACD,WAAYF,EAAO,IAAIG,WAAWH,EAAKI,OAAQJ,EAAKK,WAAYL,EAAKM,YAAc,IAAIH,WAAWH,GACtGC,KAAKM,MAAQN,KAAKC,MAAMI,WACxBL,KAAKO,UAAY,EACjBP,KAAKQ,MAAQ,IAAIC,SAAST,KAAKC,MAAME,OAAQH,KAAKC,MAAMG,WAAYJ,KAAKM,MAC5E,CACD,IAAAP,GACI,OAAOC,KAAKC,KACf,CACD,IAAAS,GACI,OAAOV,KAAKM,KACf,CACD,SAAAK,GACI,OAAOX,KAAKM,MAAQN,KAAKO,SAC5B,CACD,KAAAK,CAAMC,EAAWb,KAAKO,WAClB,OAAOP,KAAKC,MAAMY,EACrB,CACD,QAAAA,GACI,OAAOb,KAAKO,SACf,CACD,KAAAO,CAAMD,EAAW,GACbb,KAAKO,UAAYQ,KAAKC,IAAI,EAAGH,EAAWb,KAAKM,MAAQN,KAAKM,MAAQO,EACrE,CACD,MAAAI,CAAON,GACH,MAAMO,EAAOlB,KAAKM,MAAQN,KAAKO,UAC/B,OAAII,EAAYO,EACLA,GAEXlB,KAAKM,MAAQN,KAAKO,UAAYI,EACvBA,EACV,CACD,IAAAQ,CAAKC,EAAQ,GACT,MAAMF,EAAOlB,KAAKM,MAAQN,KAAKO,UAK/B,OAJIa,EAAQF,IACRE,EAAQF,GAEZ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