media-stream-library
Version:
Media stream library for Node & the Web.
1,543 lines (1,526 loc) • 188 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// ../node_modules/ts-md5/dist/cjs/md5.js
var require_md5 = __commonJS({
"../node_modules/ts-md5/dist/cjs/md5.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Md5 = void 0;
var Md5 = (
/** @class */
function() {
function Md52() {
this._dataLength = 0;
this._bufferLength = 0;
this._state = new Int32Array(4);
this._buffer = new ArrayBuffer(68);
this._buffer8 = new Uint8Array(this._buffer, 0, 68);
this._buffer32 = new Uint32Array(this._buffer, 0, 17);
this.start();
}
Md52.hashStr = function(str, raw) {
if (raw === void 0) {
raw = false;
}
return this.onePassHasher.start().appendStr(str).end(raw);
};
Md52.hashAsciiStr = function(str, raw) {
if (raw === void 0) {
raw = false;
}
return this.onePassHasher.start().appendAsciiStr(str).end(raw);
};
Md52._hex = function(x) {
var hc = Md52.hexChars;
var ho = Md52.hexOut;
var n;
var offset;
var j;
var i;
for (i = 0; i < 4; i += 1) {
offset = i * 8;
n = x[i];
for (j = 0; j < 8; j += 2) {
ho[offset + 1 + j] = hc.charAt(n & 15);
n >>>= 4;
ho[offset + 0 + j] = hc.charAt(n & 15);
n >>>= 4;
}
}
return ho.join("");
};
Md52._md5cycle = function(x, k) {
var a = x[0];
var b = x[1];
var c = x[2];
var d = x[3];
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
a = (a << 7 | a >>> 25) + b | 0;
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
d = (d << 12 | d >>> 20) + a | 0;
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
c = (c << 17 | c >>> 15) + d | 0;
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
b = (b << 22 | b >>> 10) + c | 0;
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
a = (a << 7 | a >>> 25) + b | 0;
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
d = (d << 12 | d >>> 20) + a | 0;
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
c = (c << 17 | c >>> 15) + d | 0;
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
b = (b << 22 | b >>> 10) + c | 0;
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
a = (a << 7 | a >>> 25) + b | 0;
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
d = (d << 12 | d >>> 20) + a | 0;
c += (d & a | ~d & b) + k[10] - 42063 | 0;
c = (c << 17 | c >>> 15) + d | 0;
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
b = (b << 22 | b >>> 10) + c | 0;
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
a = (a << 7 | a >>> 25) + b | 0;
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
d = (d << 12 | d >>> 20) + a | 0;
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
c = (c << 17 | c >>> 15) + d | 0;
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
b = (b << 22 | b >>> 10) + c | 0;
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
a = (a << 5 | a >>> 27) + b | 0;
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
d = (d << 9 | d >>> 23) + a | 0;
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
c = (c << 14 | c >>> 18) + d | 0;
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
b = (b << 20 | b >>> 12) + c | 0;
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
a = (a << 5 | a >>> 27) + b | 0;
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
d = (d << 9 | d >>> 23) + a | 0;
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
c = (c << 14 | c >>> 18) + d | 0;
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
b = (b << 20 | b >>> 12) + c | 0;
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
a = (a << 5 | a >>> 27) + b | 0;
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
d = (d << 9 | d >>> 23) + a | 0;
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
c = (c << 14 | c >>> 18) + d | 0;
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
b = (b << 20 | b >>> 12) + c | 0;
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
a = (a << 5 | a >>> 27) + b | 0;
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
d = (d << 9 | d >>> 23) + a | 0;
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
c = (c << 14 | c >>> 18) + d | 0;
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
b = (b << 20 | b >>> 12) + c | 0;
a += (b ^ c ^ d) + k[5] - 378558 | 0;
a = (a << 4 | a >>> 28) + b | 0;
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
d = (d << 11 | d >>> 21) + a | 0;
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
c = (c << 16 | c >>> 16) + d | 0;
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
b = (b << 23 | b >>> 9) + c | 0;
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
a = (a << 4 | a >>> 28) + b | 0;
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
d = (d << 11 | d >>> 21) + a | 0;
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
c = (c << 16 | c >>> 16) + d | 0;
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
b = (b << 23 | b >>> 9) + c | 0;
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
a = (a << 4 | a >>> 28) + b | 0;
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
d = (d << 11 | d >>> 21) + a | 0;
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
c = (c << 16 | c >>> 16) + d | 0;
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
b = (b << 23 | b >>> 9) + c | 0;
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
a = (a << 4 | a >>> 28) + b | 0;
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
d = (d << 11 | d >>> 21) + a | 0;
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
c = (c << 16 | c >>> 16) + d | 0;
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
b = (b << 23 | b >>> 9) + c | 0;
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
a = (a << 6 | a >>> 26) + b | 0;
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
d = (d << 10 | d >>> 22) + a | 0;
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
c = (c << 15 | c >>> 17) + d | 0;
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
b = (b << 21 | b >>> 11) + c | 0;
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
a = (a << 6 | a >>> 26) + b | 0;
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
d = (d << 10 | d >>> 22) + a | 0;
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
c = (c << 15 | c >>> 17) + d | 0;
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
b = (b << 21 | b >>> 11) + c | 0;
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
a = (a << 6 | a >>> 26) + b | 0;
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
d = (d << 10 | d >>> 22) + a | 0;
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
c = (c << 15 | c >>> 17) + d | 0;
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
b = (b << 21 | b >>> 11) + c | 0;
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
a = (a << 6 | a >>> 26) + b | 0;
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
d = (d << 10 | d >>> 22) + a | 0;
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
c = (c << 15 | c >>> 17) + d | 0;
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
b = (b << 21 | b >>> 11) + c | 0;
x[0] = a + x[0] | 0;
x[1] = b + x[1] | 0;
x[2] = c + x[2] | 0;
x[3] = d + x[3] | 0;
};
Md52.prototype.start = function() {
this._dataLength = 0;
this._bufferLength = 0;
this._state.set(Md52.stateIdentity);
return this;
};
Md52.prototype.appendStr = function(str) {
var buf8 = this._buffer8;
var buf32 = this._buffer32;
var bufLen = this._bufferLength;
var code;
var i;
for (i = 0; i < str.length; i += 1) {
code = str.charCodeAt(i);
if (code < 128) {
buf8[bufLen++] = code;
} else if (code < 2048) {
buf8[bufLen++] = (code >>> 6) + 192;
buf8[bufLen++] = code & 63 | 128;
} else if (code < 55296 || code > 56319) {
buf8[bufLen++] = (code >>> 12) + 224;
buf8[bufLen++] = code >>> 6 & 63 | 128;
buf8[bufLen++] = code & 63 | 128;
} else {
code = (code - 55296) * 1024 + (str.charCodeAt(++i) - 56320) + 65536;
if (code > 1114111) {
throw new Error("Unicode standard supports code points up to U+10FFFF");
}
buf8[bufLen++] = (code >>> 18) + 240;
buf8[bufLen++] = code >>> 12 & 63 | 128;
buf8[bufLen++] = code >>> 6 & 63 | 128;
buf8[bufLen++] = code & 63 | 128;
}
if (bufLen >= 64) {
this._dataLength += 64;
Md52._md5cycle(this._state, buf32);
bufLen -= 64;
buf32[0] = buf32[16];
}
}
this._bufferLength = bufLen;
return this;
};
Md52.prototype.appendAsciiStr = function(str) {
var buf8 = this._buffer8;
var buf32 = this._buffer32;
var bufLen = this._bufferLength;
var i;
var j = 0;
for (; ; ) {
i = Math.min(str.length - j, 64 - bufLen);
while (i--) {
buf8[bufLen++] = str.charCodeAt(j++);
}
if (bufLen < 64) {
break;
}
this._dataLength += 64;
Md52._md5cycle(this._state, buf32);
bufLen = 0;
}
this._bufferLength = bufLen;
return this;
};
Md52.prototype.appendByteArray = function(input) {
var buf8 = this._buffer8;
var buf32 = this._buffer32;
var bufLen = this._bufferLength;
var i;
var j = 0;
for (; ; ) {
i = Math.min(input.length - j, 64 - bufLen);
while (i--) {
buf8[bufLen++] = input[j++];
}
if (bufLen < 64) {
break;
}
this._dataLength += 64;
Md52._md5cycle(this._state, buf32);
bufLen = 0;
}
this._bufferLength = bufLen;
return this;
};
Md52.prototype.getState = function() {
var s = this._state;
return {
buffer: String.fromCharCode.apply(null, Array.from(this._buffer8)),
buflen: this._bufferLength,
length: this._dataLength,
state: [s[0], s[1], s[2], s[3]]
};
};
Md52.prototype.setState = function(state) {
var buf = state.buffer;
var x = state.state;
var s = this._state;
var i;
this._dataLength = state.length;
this._bufferLength = state.buflen;
s[0] = x[0];
s[1] = x[1];
s[2] = x[2];
s[3] = x[3];
for (i = 0; i < buf.length; i += 1) {
this._buffer8[i] = buf.charCodeAt(i);
}
};
Md52.prototype.end = function(raw) {
if (raw === void 0) {
raw = false;
}
var bufLen = this._bufferLength;
var buf8 = this._buffer8;
var buf32 = this._buffer32;
var i = (bufLen >> 2) + 1;
this._dataLength += bufLen;
var dataBitsLen = this._dataLength * 8;
buf8[bufLen] = 128;
buf8[bufLen + 1] = buf8[bufLen + 2] = buf8[bufLen + 3] = 0;
buf32.set(Md52.buffer32Identity.subarray(i), i);
if (bufLen > 55) {
Md52._md5cycle(this._state, buf32);
buf32.set(Md52.buffer32Identity);
}
if (dataBitsLen <= 4294967295) {
buf32[14] = dataBitsLen;
} else {
var matches = dataBitsLen.toString(16).match(/(.*?)(.{0,8})$/);
if (matches === null) {
return;
}
var lo = parseInt(matches[2], 16);
var hi = parseInt(matches[1], 16) || 0;
buf32[14] = lo;
buf32[15] = hi;
}
Md52._md5cycle(this._state, buf32);
return raw ? this._state : Md52._hex(this._state);
};
Md52.stateIdentity = new Int32Array([1732584193, -271733879, -1732584194, 271733878]);
Md52.buffer32Identity = new Int32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
Md52.hexChars = "0123456789abcdef";
Md52.hexOut = [];
Md52.onePassHasher = new Md52();
return Md52;
}()
);
exports.Md5 = Md5;
if (Md5.hashStr("hello") !== "5d41402abc4b2a76b9719d911017c592") {
throw new Error("Md5 self test failed.");
}
}
});
// ../node_modules/ts-md5/dist/cjs/md5_file_hasher.js
var require_md5_file_hasher = __commonJS({
"../node_modules/ts-md5/dist/cjs/md5_file_hasher.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Md5FileHasher = void 0;
var md5_1 = require_md5();
var Md5FileHasher = (
/** @class */
function() {
function Md5FileHasher2(_callback, _async, _partSize) {
if (_async === void 0) {
_async = true;
}
if (_partSize === void 0) {
_partSize = 1048576;
}
this._callback = _callback;
this._async = _async;
this._partSize = _partSize;
this._configureReader();
}
Md5FileHasher2.prototype.hash = function(blob) {
var self = this;
self._blob = blob;
self._part = 0;
self._md5 = new md5_1.Md5();
self._processPart();
};
Md5FileHasher2.prototype._fail = function() {
this._callback({
success: false,
result: "data read failed"
});
};
Md5FileHasher2.prototype._hashData = function(e) {
var self = this;
self._md5.appendByteArray(new Uint8Array(e.target.result));
if (self._part * self._partSize >= self._blob.size) {
self._callback({
success: true,
result: self._md5.end()
});
} else {
self._processPart();
}
};
Md5FileHasher2.prototype._processPart = function() {
var self = this;
var endbyte = 0;
var current_part;
self._part += 1;
if (self._blob.size > self._partSize) {
endbyte = self._part * self._partSize;
if (endbyte > self._blob.size) {
endbyte = self._blob.size;
}
current_part = self._blob.slice((self._part - 1) * self._partSize, endbyte);
} else {
current_part = self._blob;
}
if (self._async) {
self._reader.readAsArrayBuffer(current_part);
} else {
setTimeout(function() {
try {
self._hashData({
target: {
result: self._reader.readAsArrayBuffer(current_part)
}
});
} catch (e) {
self._fail();
}
}, 0);
}
};
Md5FileHasher2.prototype._configureReader = function() {
var self = this;
if (self._async) {
self._reader = new FileReader();
self._reader.onload = self._hashData.bind(self);
self._reader.onerror = self._fail.bind(self);
self._reader.onabort = self._fail.bind(self);
} else {
self._reader = new FileReaderSync();
}
};
return Md5FileHasher2;
}()
);
exports.Md5FileHasher = Md5FileHasher;
}
});
// ../node_modules/ts-md5/dist/cjs/parallel_hasher.js
var require_parallel_hasher = __commonJS({
"../node_modules/ts-md5/dist/cjs/parallel_hasher.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParallelHasher = void 0;
var ParallelHasher = (
/** @class */
function() {
function ParallelHasher2(workerUri, workerOptions) {
this._queue = [];
this._ready = true;
var self = this;
if (Worker) {
self._hashWorker = new Worker(workerUri, workerOptions);
self._hashWorker.onmessage = self._recievedMessage.bind(self);
self._hashWorker.onerror = function(err) {
self._ready = false;
console.error("Hash worker failure", err);
};
} else {
self._ready = false;
console.error("Web Workers are not supported in this browser");
}
}
ParallelHasher2.prototype.hash = function(blob) {
var self = this;
var promise;
promise = new Promise(function(resolve, reject) {
self._queue.push({
blob,
resolve,
reject
});
self._processNext();
});
return promise;
};
ParallelHasher2.prototype.terminate = function() {
this._ready = false;
this._hashWorker.terminate();
};
ParallelHasher2.prototype._processNext = function() {
if (this._ready && !this._processing && this._queue.length > 0) {
this._processing = this._queue.pop();
this._hashWorker.postMessage(this._processing.blob);
}
};
ParallelHasher2.prototype._recievedMessage = function(evt) {
var _a, _b;
var data = evt.data;
if (data.success) {
(_a = this._processing) === null || _a === void 0 ? void 0 : _a.resolve(data.result);
} else {
(_b = this._processing) === null || _b === void 0 ? void 0 : _b.reject(data.result);
}
this._processing = void 0;
this._processNext();
};
return ParallelHasher2;
}()
);
exports.ParallelHasher = ParallelHasher;
}
});
// ../node_modules/ts-md5/dist/cjs/index.js
var require_cjs = __commonJS({
"../node_modules/ts-md5/dist/cjs/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParallelHasher = exports.Md5FileHasher = exports.Md5 = void 0;
var md5_1 = require_md5();
Object.defineProperty(exports, "Md5", { enumerable: true, get: function() {
return md5_1.Md5;
} });
var md5_file_hasher_1 = require_md5_file_hasher();
Object.defineProperty(exports, "Md5FileHasher", { enumerable: true, get: function() {
return md5_file_hasher_1.Md5FileHasher;
} });
var parallel_hasher_1 = require_parallel_hasher();
Object.defineProperty(exports, "ParallelHasher", { enumerable: true, get: function() {
return parallel_hasher_1.ParallelHasher;
} });
}
});
// ../node_modules/ms/index.js
var require_ms = __commonJS({
"../node_modules/ms/index.js"(exports, module) {
var s = 1e3;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var w = d * 7;
var y = d * 365.25;
module.exports = function(val, options) {
options = options || {};
var type = typeof val;
if (type === "string" && val.length > 0) {
return parse3(val);
} else if (type === "number" && isFinite(val)) {
return options.long ? fmtLong(val) : fmtShort(val);
}
throw new Error(
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
);
};
function parse3(str) {
str = String(str);
if (str.length > 100) {
return;
}
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
str
);
if (!match) {
return;
}
var n = parseFloat(match[1]);
var type = (match[2] || "ms").toLowerCase();
switch (type) {
case "years":
case "year":
case "yrs":
case "yr":
case "y":
return n * y;
case "weeks":
case "week":
case "w":
return n * w;
case "days":
case "day":
case "d":
return n * d;
case "hours":
case "hour":
case "hrs":
case "hr":
case "h":
return n * h;
case "minutes":
case "minute":
case "mins":
case "min":
case "m":
return n * m;
case "seconds":
case "second":
case "secs":
case "sec":
case "s":
return n * s;
case "milliseconds":
case "millisecond":
case "msecs":
case "msec":
case "ms":
return n;
default:
return void 0;
}
}
function fmtShort(ms) {
var msAbs = Math.abs(ms);
if (msAbs >= d) {
return Math.round(ms / d) + "d";
}
if (msAbs >= h) {
return Math.round(ms / h) + "h";
}
if (msAbs >= m) {
return Math.round(ms / m) + "m";
}
if (msAbs >= s) {
return Math.round(ms / s) + "s";
}
return ms + "ms";
}
function fmtLong(ms) {
var msAbs = Math.abs(ms);
if (msAbs >= d) {
return plural(ms, msAbs, d, "day");
}
if (msAbs >= h) {
return plural(ms, msAbs, h, "hour");
}
if (msAbs >= m) {
return plural(ms, msAbs, m, "minute");
}
if (msAbs >= s) {
return plural(ms, msAbs, s, "second");
}
return ms + " ms";
}
function plural(ms, msAbs, n, name) {
var isPlural = msAbs >= n * 1.5;
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
}
}
});
// ../node_modules/debug/src/common.js
var require_common = __commonJS({
"../node_modules/debug/src/common.js"(exports, module) {
function setup(env) {
createDebug.debug = createDebug;
createDebug.default = createDebug;
createDebug.coerce = coerce;
createDebug.disable = disable;
createDebug.enable = enable;
createDebug.enabled = enabled;
createDebug.humanize = require_ms();
createDebug.destroy = destroy;
Object.keys(env).forEach((key) => {
createDebug[key] = env[key];
});
createDebug.names = [];
createDebug.skips = [];
createDebug.formatters = {};
function selectColor(namespace) {
let hash = 0;
for (let i = 0; i < namespace.length; i++) {
hash = (hash << 5) - hash + namespace.charCodeAt(i);
hash |= 0;
}
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
}
createDebug.selectColor = selectColor;
function createDebug(namespace) {
let prevTime;
let enableOverride = null;
let namespacesCache;
let enabledCache;
function debug6(...args) {
if (!debug6.enabled) {
return;
}
const self = debug6;
const curr = Number(/* @__PURE__ */ new Date());
const ms = curr - (prevTime || curr);
self.diff = ms;
self.prev = prevTime;
self.curr = curr;
prevTime = curr;
args[0] = createDebug.coerce(args[0]);
if (typeof args[0] !== "string") {
args.unshift("%O");
}
let index = 0;
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
if (match === "%%") {
return "%";
}
index++;
const formatter = createDebug.formatters[format];
if (typeof formatter === "function") {
const val = args[index];
match = formatter.call(self, val);
args.splice(index, 1);
index--;
}
return match;
});
createDebug.formatArgs.call(self, args);
const logFn = self.log || createDebug.log;
logFn.apply(self, args);
}
debug6.namespace = namespace;
debug6.useColors = createDebug.useColors();
debug6.color = createDebug.selectColor(namespace);
debug6.extend = extend;
debug6.destroy = createDebug.destroy;
Object.defineProperty(debug6, "enabled", {
enumerable: true,
configurable: false,
get: () => {
if (enableOverride !== null) {
return enableOverride;
}
if (namespacesCache !== createDebug.namespaces) {
namespacesCache = createDebug.namespaces;
enabledCache = createDebug.enabled(namespace);
}
return enabledCache;
},
set: (v) => {
enableOverride = v;
}
});
if (typeof createDebug.init === "function") {
createDebug.init(debug6);
}
return debug6;
}
function extend(namespace, delimiter) {
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}
function enable(namespaces) {
createDebug.save(namespaces);
createDebug.namespaces = namespaces;
createDebug.names = [];
createDebug.skips = [];
let i;
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
const len = split.length;
for (i = 0; i < len; i++) {
if (!split[i]) {
continue;
}
namespaces = split[i].replace(/\*/g, ".*?");
if (namespaces[0] === "-") {
createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
} else {
createDebug.names.push(new RegExp("^" + namespaces + "$"));
}
}
}
function disable() {
const namespaces = [
...createDebug.names.map(toNamespace),
...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
].join(",");
createDebug.enable("");
return namespaces;
}
function enabled(name) {
if (name[name.length - 1] === "*") {
return true;
}
let i;
let len;
for (i = 0, len = createDebug.skips.length; i < len; i++) {
if (createDebug.skips[i].test(name)) {
return false;
}
}
for (i = 0, len = createDebug.names.length; i < len; i++) {
if (createDebug.names[i].test(name)) {
return true;
}
}
return false;
}
function toNamespace(regexp) {
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
}
function coerce(val) {
if (val instanceof Error) {
return val.stack || val.message;
}
return val;
}
function destroy() {
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
}
createDebug.enable(createDebug.load());
return createDebug;
}
module.exports = setup;
}
});
// ../node_modules/debug/src/browser.js
var require_browser = __commonJS({
"../node_modules/debug/src/browser.js"(exports, module) {
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = localstorage();
exports.destroy = /* @__PURE__ */ (() => {
let warned = false;
return () => {
if (!warned) {
warned = true;
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
}
};
})();
exports.colors = [
"#0000CC",
"#0000FF",
"#0033CC",
"#0033FF",
"#0066CC",
"#0066FF",
"#0099CC",
"#0099FF",
"#00CC00",
"#00CC33",
"#00CC66",
"#00CC99",
"#00CCCC",
"#00CCFF",
"#3300CC",
"#3300FF",
"#3333CC",
"#3333FF",
"#3366CC",
"#3366FF",
"#3399CC",
"#3399FF",
"#33CC00",
"#33CC33",
"#33CC66",
"#33CC99",
"#33CCCC",
"#33CCFF",
"#6600CC",
"#6600FF",
"#6633CC",
"#6633FF",
"#66CC00",
"#66CC33",
"#9900CC",
"#9900FF",
"#9933CC",
"#9933FF",
"#99CC00",
"#99CC33",
"#CC0000",
"#CC0033",
"#CC0066",
"#CC0099",
"#CC00CC",
"#CC00FF",
"#CC3300",
"#CC3333",
"#CC3366",
"#CC3399",
"#CC33CC",
"#CC33FF",
"#CC6600",
"#CC6633",
"#CC9900",
"#CC9933",
"#CCCC00",
"#CCCC33",
"#FF0000",
"#FF0033",
"#FF0066",
"#FF0099",
"#FF00CC",
"#FF00FF",
"#FF3300",
"#FF3333",
"#FF3366",
"#FF3399",
"#FF33CC",
"#FF33FF",
"#FF6600",
"#FF6633",
"#FF9900",
"#FF9933",
"#FFCC00",
"#FFCC33"
];
function useColors() {
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
return true;
}
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
return false;
}
let m;
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
}
function formatArgs(args) {
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
if (!this.useColors) {
return;
}
const c = "color: " + this.color;
args.splice(1, 0, c, "color: inherit");
let index = 0;
let lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, (match) => {
if (match === "%%") {
return;
}
index++;
if (match === "%c") {
lastC = index;
}
});
args.splice(lastC, 0, c);
}
exports.log = console.debug || console.log || (() => {
});
function save(namespaces) {
try {
if (namespaces) {
exports.storage.setItem("debug", namespaces);
} else {
exports.storage.removeItem("debug");
}
} catch (error) {
}
}
function load() {
let r;
try {
r = exports.storage.getItem("debug");
} catch (error) {
}
if (!r && typeof process !== "undefined" && "env" in process) {
r = process.env.DEBUG;
}
return r;
}
function localstorage() {
try {
return localStorage;
} catch (error) {
}
}
module.exports = require_common()(exports);
var { formatters } = module.exports;
formatters.j = function(v) {
try {
return JSON.stringify(v);
} catch (error) {
return "[UnexpectedJSONParseError]: " + error.message;
}
};
}
});
// ../node_modules/has-flag/index.js
var require_has_flag = __commonJS({
"../node_modules/has-flag/index.js"(exports, module) {
"use strict";
module.exports = (flag, argv = process.argv) => {
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf("--");
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
};
}
});
// ../node_modules/supports-color/index.js
var require_supports_color = __commonJS({
"../node_modules/supports-color/index.js"(exports, module) {
"use strict";
var os = __require("os");
var tty = __require("tty");
var hasFlag = require_has_flag();
var { env } = process;
var flagForceColor;
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
flagForceColor = 0;
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
flagForceColor = 1;
}
function envForceColor() {
if ("FORCE_COLOR" in env) {
if (env.FORCE_COLOR === "true") {
return 1;
}
if (env.FORCE_COLOR === "false") {
return 0;
}
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
}
}
function translateLevel(level) {
if (level === 0) {
return false;
}
return {
level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3
};
}
function supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
const noFlagForceColor = envForceColor();
if (noFlagForceColor !== void 0) {
flagForceColor = noFlagForceColor;
}
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
if (forceColor === 0) {
return 0;
}
if (sniffFlags) {
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
return 3;
}
if (hasFlag("color=256")) {
return 2;
}
}
if (haveStream && !streamIsTTY && forceColor === void 0) {
return 0;
}
const min = forceColor || 0;
if (env.TERM === "dumb") {
return min;
}
if (process.platform === "win32") {
const osRelease = os.release().split(".");
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}
return 1;
}
if ("CI" in env) {
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
return 1;
}
return min;
}
if ("TEAMCITY_VERSION" in env) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
}
if (env.COLORTERM === "truecolor") {
return 3;
}
if ("TERM_PROGRAM" in env) {
const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
switch (env.TERM_PROGRAM) {
case "iTerm.app":
return version2 >= 3 ? 3 : 2;
case "Apple_Terminal":
return 2;
}
}
if (/-256(color)?$/i.test(env.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
return 1;
}
if ("COLORTERM" in env) {
return 1;
}
return min;
}
function getSupportLevel(stream, options = {}) {
const level = supportsColor(stream, {
streamIsTTY: stream && stream.isTTY,
...options
});
return translateLevel(level);
}
module.exports = {
supportsColor: getSupportLevel,
stdout: getSupportLevel({ isTTY: tty.isatty(1) }),
stderr: getSupportLevel({ isTTY: tty.isatty(2) })
};
}
});
// ../node_modules/debug/src/node.js
var require_node = __commonJS({
"../node_modules/debug/src/node.js"(exports, module) {
var tty = __require("tty");
var util = __require("util");
exports.init = init;
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.destroy = util.deprecate(
() => {
},
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
);
exports.colors = [6, 2, 3, 4, 5, 1];
try {
const supportsColor = require_supports_color();
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
exports.colors = [
20,
21,
26,
27,
32,
33,
38,
39,
40,
41,
42,
43,
44,
45,
56,
57,
62,
63,
68,
69,
74,
75,
76,
77,
78,
79,
80,
81,
92,
93,
98,
99,
112,
113,
128,
129,
134,
135,
148,
149,
160,
161,
162,
163,
164,
165,
166,
167,
168,
169,
170,
171,
172,
173,
178,
179,
184,
185,
196,
197,
198,
199,
200,
201,
202,
203,
204,
205,
206,
207,
208,
209,
214,
215,
220,
221
];
}
} catch (error) {
}
exports.inspectOpts = Object.keys(process.env).filter((key) => {
return /^debug_/i.test(key);
}).reduce((obj, key) => {
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
return k.toUpperCase();
});
let val = process.env[key];
if (/^(yes|on|true|enabled)$/i.test(val)) {
val = true;
} else if (/^(no|off|false|disabled)$/i.test(val)) {
val = false;
} else if (val === "null") {
val = null;
} else {
val = Number(val);
}
obj[prop] = val;
return obj;
}, {});
function useColors() {
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
}
function formatArgs(args) {
const { namespace: name, useColors: useColors2 } = this;
if (useColors2) {
const c = this.color;
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
} else {
args[0] = getDate() + name + " " + args[0];
}
}
function getDate() {
if (exports.inspectOpts.hideDate) {
return "";
}
return (/* @__PURE__ */ new Date()).toISOString() + " ";
}
function log(...args) {
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
}
function save(namespaces) {
if (namespaces) {
process.env.DEBUG = namespaces;
} else {
delete process.env.DEBUG;
}
}
function load() {
return process.env.DEBUG;
}
function init(debug6) {
debug6.inspectOpts = {};
const keys = Object.keys(exports.inspectOpts);
for (let i = 0; i < keys.length; i++) {
debug6.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
}
}
module.exports = require_common()(exports);
var { formatters } = module.exports;
formatters.o = function(v) {
this.inspectOpts.colors = this.useColors;
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
};
formatters.O = function(v) {
this.inspectOpts.colors = this.useColors;
return util.inspect(v, this.inspectOpts);
};
}
});
// ../node_modules/debug/src/index.js
var require_src = __commonJS({
"../node_modules/debug/src/index.js"(exports, module) {
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
module.exports = require_browser();
} else {
module.exports = require_node();
}
}
});
// src/components/index.node.ts
var index_node_exports = {};
__export(index_node_exports, {
AACDepay: () => AACDepay,
Auth: () => Auth,
BasicDepay: () => BasicDepay,
H264Depay: () => H264Depay,
Inspector: () => Inspector,
JPEGDepay: () => JPEGDepay,
MessageType: () => MessageType,
Mp4Capture: () => Mp4Capture,
Mp4Muxer: () => Mp4Muxer,
ONVIFDepay: () => ONVIFDepay,
RTSPResponseError: () => RTSPResponseError,
RTSP_METHOD: () => RTSP_METHOD,
Recorder: () => Recorder,
Replayer: () => Replayer,
RtspParser: () => RtspParser,
RtspSession: () => RtspSession,
Sink: () => Sink,
Source: () => Source,
TcpSource: () => TcpSource,
Tube: () => Tube,
WSSink: () => WSSink,
createTransform: () => createTransform
});
// src/utils/bits.ts
var POS = [128, 64, 32, 16, 8, 4, 2, 1];
// src/utils/protocols/rtp.ts
var version = (buffer) => {
return buffer[0] >>> 6;
};
var padding = (buffer) => {
return !!(buffer[0] & POS[2]);
};
var extension = (buffer) => {
return !!(buffer[0] & POS[3]);
};
var cSrcCount = (buffer) => {
return buffer[0] & 15;
};
var marker = (buffer) => {
return !!(buffer[1] & POS[0]);
};
var payloadType = (buffer) => {
return buffer[1] & 127;
};
var sequenceNumber = (buffer) => {
return buffer.readUInt16BE(2);
};
var timestamp = (buffer) => {
return buffer.readUInt32BE(4);
};
var sSrc = (buffer) => {
return buffer.readUInt32BE(8);
};
var cSrc = (buffer, rank = 0) => {
return cSrcCount(buffer) > rank ? buffer.readUInt32BE(12 + rank * 4) : 0;
};
var extHeaderLength = (buffer) => {
return !extension(buffer) ? 0 : buffer.readUInt16BE(12 + cSrcCount(buffer) * 4 + 2);
};
var extHeader = (buffer) => {
return extHeaderLength(buffer) === 0 ? Buffer.from([]) : buffer.slice(
12 + cSrcCount(buffer) * 4,
12 + cSrcCount(buffer) * 4 + 4 + extHeaderLength(buffer) * 4
);
};
var payload = (buffer) => {
return !extension(buffer) ? buffer.slice(12 + cSrcCount(buffer) * 4) : buffer.slice(12 + cSrcCount(buffer) * 4 + 4 + extHeaderLength(buffer) * 4);
};
// src/components/component.ts
import { PassThrough, Readable as Readable2, Writable as Writable2 } from "stream";
// src/components/helpers/stream-factory.ts
import { Readable, Transform, Writable } from "stream";
var StreamFactory = class {
/**
* Creates a writable stream that sends all messages written to the stream
* to a callback function and then considers it written.
* @param fn The callback to be invoked on the message
*/
static consumer(fn = () => {
}) {
return new Writable({
objectMode: true,
write(msg, _encoding, callback) {
fn(msg);
callback();
}
});
}
static peeker(fn) {
if (typeof fn !== "function") {
throw new Error("you must supply a function");
}
return new Transform({
objectMode: true,
transform(msg, _encoding, callback) {
fn(msg);
callback(void 0, msg);
}
});
}
/**
* Creates a readable stream that sends a message for each element of an array.
* @param arr The array with elements to be turned into a stream.
*/
static producer(messages) {
let counter = 0;
return new Readable({
objectMode: true,
read() {
if (messages !== void 0) {
if (counter < messages.length) {
this.push(messages[counter++]);
} else {
this.push(null);
}
}
}
});
}
static recorder(type, fileStream) {
return new Transform({
objectMode: true,
transform(msg, encoding, callback) {
const timestamp2 = Date.now();
const message = Object.assign({}, msg, {
data: msg.data.toString("base64")
});
fileStream.write(JSON.stringify({ type, timestamp: timestamp2, message }, null, 2));
fileStream.write(",\n");
callback(void 0, msg);
}
});
}
/**
* Yield binary messages from JSON packet array until depleted.
* @return {Generator} Returns a JSON packet iterator.
*/
static replayer(packets) {
let packetCounter = 0;
let lastTimestamp = packets[0].timestamp;
return new Readable({
objectMode: true,
read() {
const packet = packets[packetCounter++];
if (packet) {
const { type, timestamp: timestamp2, message } = packet;
const delay = timestamp2 - lastTimestamp;
lastTimestamp = timestamp2;
if (message) {
const data = message.data ? Buffer.from(message.data, "base64") : Buffer.alloc(0);
const msg = Object.assign({}, message, { data });
this.push({ type, delay, msg });
} else {
this.push({ type, delay, msg: null });
}
} else {
this.push(null);
}
}
});
}
};
// src/components/component.ts
var AbstractComponent = class {
_incomingErrorHandler;
_outgoingErrorHandler;
};
var Source = class _Source extends AbstractComponent {
/**
* Set up a source component that has a message list as data source.
*
* @param messages - List of objects (with data property) to emit on the
* incoming stream
*/
static fromMessages(messages) {
const component = new _Source(
StreamFactory.producer(messages),
StreamFactory.consumer()
);
return component;
}
incoming;
outgoing;
next;
prev;
constructor(incoming = new Readable2({ objectMode: true }), outgoing = new Writable2({ objectMode: true })) {
super();
this.incoming = incoming;
this.outgoing = outgoing;
this.next = null;
this.prev = null;
}
/**
* Attach another component so the the 'down' stream flows into the
* next component 'down' stream and the 'up' stream of the other component
* flows into the 'up' stream of this component. This is what establishes the
* meaning of 'up' and 'down'.
* @param next - The component to connect.
* @return A reference to the connected component.
*
* -------------- pipe --------------
* <- | outgoing | <- | outgoing | <-
* | this | | next |
* -> | incoming | -> | incoming | ->
* -------------- pipe --------------
*/
connect(next) {
if (next === null) {
return this;
} else if (this.next !== null || next.prev !== null) {
throw new Error("connection failed: component(s) already connected");
}
if (!this.incoming.readable || !this.outgoing.writable