UNPKG

videomail-client

Version:

A wicked npm package to record videos directly in the browser, wohooo!

1,143 lines (1,116 loc) 360 kB
import { deserializeError, serializeError } from "serialize-error"; import superagent from "superagent"; import defined from "defined"; import { UAParser } from "ua-parser-js"; import get_form_data from "get-form-data"; import { createNanoEvents } from "nanoevents"; import deepmerge from "deepmerge"; import document_visibility from "document-visibility"; import contains from "contains"; import animitter from "animitter"; import canvas_to_buffer from "canvas-to-buffer"; import websocket_stream from "websocket-stream"; import audio_sample from "audio-sample"; import is_power_of_two from "is-power-of-two"; var __webpack_modules__ = {}; var __webpack_module_cache__ = {}; function __webpack_require__(moduleId) { var cachedModule = __webpack_module_cache__[moduleId]; if (void 0 !== cachedModule) return cachedModule.exports; var module = __webpack_module_cache__[moduleId] = { id: moduleId, exports: {} }; __webpack_modules__[moduleId](module, module.exports, __webpack_require__); return module.exports; } __webpack_require__.m = __webpack_modules__; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.add = function(modules) { Object.assign(__webpack_require__.m, modules); }; })(); (()=>{ __webpack_require__.g = (()=>{ if ('object' == typeof globalThis) return globalThis; try { return this || new Function('return this')(); } catch (e) { if ('object' == typeof window) return window; } })(); })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.nc = void 0; })(); __webpack_require__.add({ "./node_modules/@rsbuild/core/compiled/css-loader/index.js??ruleSet[1].rules[10].oneOf[2].use[1]!builtin:lightningcss-loader??ruleSet[1].rules[10].oneOf[2].use[2]!./node_modules/stylus-loader/dist/cjs.js??ruleSet[1].rules[10].oneOf[2].use[3]!./src/styles/main.styl" (module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { A: ()=>__rspack_default_export }); var _node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0 = __webpack_require__("./node_modules/@rsbuild/core/compiled/css-loader/noSourceMaps.js"); var _node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0); var _node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1 = __webpack_require__("./node_modules/@rsbuild/core/compiled/css-loader/api.js"); var _node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1); var ___CSS_LOADER_EXPORT___ = _node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default()(_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default()); ___CSS_LOADER_EXPORT___.push([ module.id, `@keyframes blink { 0% { opacity: .9; } 35% { opacity: .9; } 50% { opacity: .1; } 85% { opacity: .1; } 100% { opacity: .9; } } .videomail .visuals { position: relative; } .videomail .visuals video.replay { width: 100%; height: 100%; } .videomail .countdown, .videomail .recordTimer, .videomail .recordNote, .videomail .pausedHeader, .videomail .pausedHint { height: auto; margin: 0; } .videomail .countdown, .videomail .recordTimer, .videomail .recordNote, .videomail .paused, .videomail .facingMode, .videomail noscript { z-index: 100; position: absolute; } .videomail .countdown, .videomail .recordTimer, .videomail .recordNote, .videomail .pausedHeader, .videomail .pausedHint, .videomail noscript { font-weight: bold; } .videomail .countdown, .videomail .paused, .videomail noscript { width: 100%; top: 50%; transform: translateY(-50%); } .videomail .pausedHeader, .videomail .pausedHint, .videomail .countdown { text-align: center; letter-spacing: 4px; text-shadow: -2px 0 #fff, 0 2px #fff, 2px 0 #fff, 0 -2px #fff; } .videomail .pausedHeader, .videomail .countdown { opacity: .9; font-size: 460%; } .videomail .pausedHint { font-size: 150%; } .videomail .facingMode { color: #f5f5f5e6; z-index: 10; background: #1e1e1e80; border: none; outline: none; padding: .1em .3em; font-family: monospace; font-size: 1.2em; transition: all .2s; bottom: .6em; right: .7em; } .videomail .facingMode:hover { cursor: pointer; background: #323232b3; } .videomail .recordTimer, .videomail .recordNote { color: #00d814; opacity: .9; background: #0a0a0acc; padding: .3em .4em; font-family: monospace; transition: all 1s; right: .7em; } .videomail .recordTimer.near, .videomail .recordNote.near { color: #eb9369; } .videomail .recordTimer.nigh, .videomail .recordNote.nigh { color: #ea4b2a; } .videomail .recordTimer { top: .7em; } .videomail .recordNote { top: 3.6em; } .videomail .recordNote:before { content: "REC"; animation: 1s infinite blink; } .videomail .notifier { box-sizing: border-box; overflow: hidden; } .videomail .radioGroup { display: block; } .videomail .radioGroup label { cursor: pointer; } .videomail video { margin-bottom: 0; } .videomail video.userMedia { background-color: #3232321a; } `, "" ]); const __rspack_default_export = ___CSS_LOADER_EXPORT___; }, "./node_modules/base64-js/index.js" (__unused_rspack_module, exports) { exports.byteLength = byteLength; exports.toByteArray = toByteArray; exports.fromByteArray = fromByteArray; var lookup = []; var revLookup = []; var Arr = "u" > typeof Uint8Array ? Uint8Array : Array; var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; for(var i = 0, len = code.length; i < len; ++i){ lookup[i] = code[i]; revLookup[code.charCodeAt(i)] = i; } revLookup['-'.charCodeAt(0)] = 62; revLookup['_'.charCodeAt(0)] = 63; function getLens(b64) { var len = b64.length; if (len % 4 > 0) throw new Error('Invalid string. Length must be a multiple of 4'); var validLen = b64.indexOf('='); if (-1 === validLen) validLen = len; var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; return [ validLen, placeHoldersLen ]; } function byteLength(b64) { var lens = getLens(b64); var validLen = lens[0]; var placeHoldersLen = lens[1]; return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; } function _byteLength(b64, validLen, placeHoldersLen) { return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; } function toByteArray(b64) { var tmp; var lens = getLens(b64); var validLen = lens[0]; var placeHoldersLen = lens[1]; var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); var curByte = 0; var len = placeHoldersLen > 0 ? validLen - 4 : validLen; var i; for(i = 0; i < len; i += 4){ tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; arr[curByte++] = tmp >> 16 & 0xFF; arr[curByte++] = tmp >> 8 & 0xFF; arr[curByte++] = 0xFF & tmp; } if (2 === placeHoldersLen) { tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; arr[curByte++] = 0xFF & tmp; } if (1 === placeHoldersLen) { tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; arr[curByte++] = tmp >> 8 & 0xFF; arr[curByte++] = 0xFF & tmp; } return arr; } function tripletToBase64(num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[0x3F & num]; } function encodeChunk(uint8, start, end) { var tmp; var output = []; for(var i = start; i < end; i += 3){ tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (0xFF & uint8[i + 2]); output.push(tripletToBase64(tmp)); } return output.join(''); } function fromByteArray(uint8) { var tmp; var len = uint8.length; var extraBytes = len % 3; var parts = []; var maxChunkLength = 16383; for(var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength)parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); if (1 === extraBytes) { tmp = uint8[len - 1]; parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '=='); } else if (2 === extraBytes) { tmp = (uint8[len - 2] << 8) + uint8[len - 1]; parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '='); } return parts.join(''); } }, "./node_modules/buffer/index.js" (__unused_rspack_module, exports, __webpack_require__) { /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ var base64 = __webpack_require__("./node_modules/base64-js/index.js"); var ieee754 = __webpack_require__("./node_modules/ieee754/index.js"); var customInspectSymbol = 'function' == typeof Symbol && 'function' == typeof Symbol['for'] ? Symbol['for']('nodejs.util.inspect.custom') : null; exports.Buffer = Buffer; exports.SlowBuffer = SlowBuffer; exports.INSPECT_MAX_BYTES = 50; var K_MAX_LENGTH = 0x7fffffff; exports.kMaxLength = K_MAX_LENGTH; Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); if (!Buffer.TYPED_ARRAY_SUPPORT && "u" > typeof console && 'function' == typeof console.error) console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."); function typedArraySupport() { try { var arr = new Uint8Array(1); var proto = { foo: function() { return 42; } }; Object.setPrototypeOf(proto, Uint8Array.prototype); Object.setPrototypeOf(arr, proto); return 42 === arr.foo(); } catch (e) { return false; } } Object.defineProperty(Buffer.prototype, 'parent', { enumerable: true, get: function() { if (!Buffer.isBuffer(this)) return; return this.buffer; } }); Object.defineProperty(Buffer.prototype, 'offset', { enumerable: true, get: function() { if (!Buffer.isBuffer(this)) return; return this.byteOffset; } }); function createBuffer(length) { if (length > K_MAX_LENGTH) throw new RangeError('The value "' + length + '" is invalid for option "size"'); var buf = new Uint8Array(length); Object.setPrototypeOf(buf, Buffer.prototype); return buf; } function Buffer(arg, encodingOrOffset, length) { if ('number' == typeof arg) { if ('string' == typeof encodingOrOffset) throw new TypeError('The "string" argument must be of type string. Received type number'); return allocUnsafe(arg); } return from(arg, encodingOrOffset, length); } Buffer.poolSize = 8192; function from(value, encodingOrOffset, length) { if ('string' == typeof value) return fromString(value, encodingOrOffset); if (ArrayBuffer.isView(value)) return fromArrayView(value); if (null == value) throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) return fromArrayBuffer(value, encodingOrOffset, length); if ("u" > typeof SharedArrayBuffer && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) return fromArrayBuffer(value, encodingOrOffset, length); if ('number' == typeof value) throw new TypeError('The "value" argument must not be of type number. Received type number'); var valueOf = value.valueOf && value.valueOf(); if (null != valueOf && valueOf !== value) return Buffer.from(valueOf, encodingOrOffset, length); var b = fromObject(value); if (b) return b; if ("u" > typeof Symbol && null != Symbol.toPrimitive && 'function' == typeof value[Symbol.toPrimitive]) return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); } Buffer.from = function(value, encodingOrOffset, length) { return from(value, encodingOrOffset, length); }; Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); Object.setPrototypeOf(Buffer, Uint8Array); function assertSize(size) { if ('number' != typeof size) throw new TypeError('"size" argument must be of type number'); if (size < 0) throw new RangeError('The value "' + size + '" is invalid for option "size"'); } function alloc(size, fill, encoding) { assertSize(size); if (size <= 0) return createBuffer(size); if (void 0 !== fill) return 'string' == typeof encoding ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); return createBuffer(size); } Buffer.alloc = function(size, fill, encoding) { return alloc(size, fill, encoding); }; function allocUnsafe(size) { assertSize(size); return createBuffer(size < 0 ? 0 : 0 | checked(size)); } Buffer.allocUnsafe = function(size) { return allocUnsafe(size); }; Buffer.allocUnsafeSlow = function(size) { return allocUnsafe(size); }; function fromString(string, encoding) { if ('string' != typeof encoding || '' === encoding) encoding = 'utf8'; if (!Buffer.isEncoding(encoding)) throw new TypeError('Unknown encoding: ' + encoding); var length = 0 | byteLength(string, encoding); var buf = createBuffer(length); var actual = buf.write(string, encoding); if (actual !== length) buf = buf.slice(0, actual); return buf; } function fromArrayLike(array) { var length = array.length < 0 ? 0 : 0 | checked(array.length); var buf = createBuffer(length); for(var i = 0; i < length; i += 1)buf[i] = 255 & array[i]; return buf; } function fromArrayView(arrayView) { if (isInstance(arrayView, Uint8Array)) { var copy = new Uint8Array(arrayView); return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); } return fromArrayLike(arrayView); } function fromArrayBuffer(array, byteOffset, length) { if (byteOffset < 0 || array.byteLength < byteOffset) throw new RangeError('"offset" is outside of buffer bounds'); if (array.byteLength < byteOffset + (length || 0)) throw new RangeError('"length" is outside of buffer bounds'); var buf; buf = void 0 === byteOffset && void 0 === length ? new Uint8Array(array) : void 0 === length ? new Uint8Array(array, byteOffset) : new Uint8Array(array, byteOffset, length); Object.setPrototypeOf(buf, Buffer.prototype); return buf; } function fromObject(obj) { if (Buffer.isBuffer(obj)) { var len = 0 | checked(obj.length); var buf = createBuffer(len); if (0 === buf.length) return buf; obj.copy(buf, 0, 0, len); return buf; } if (void 0 !== obj.length) { if ('number' != typeof obj.length || numberIsNaN(obj.length)) return createBuffer(0); return fromArrayLike(obj); } if ('Buffer' === obj.type && Array.isArray(obj.data)) return fromArrayLike(obj.data); } function checked(length) { if (length >= K_MAX_LENGTH) throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + ' bytes'); return 0 | length; } function SlowBuffer(length) { if (+length != length) length = 0; return Buffer.alloc(+length); } Buffer.isBuffer = function(b) { return null != b && true === b._isBuffer && b !== Buffer.prototype; }; Buffer.compare = function(a, b) { if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'); if (a === b) return 0; var x = a.length; var y = b.length; for(var i = 0, len = Math.min(x, y); i < len; ++i)if (a[i] !== b[i]) { x = a[i]; y = b[i]; break; } if (x < y) return -1; if (y < x) return 1; return 0; }; Buffer.isEncoding = function(encoding) { switch(String(encoding).toLowerCase()){ case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'latin1': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return true; default: return false; } }; Buffer.concat = function(list, length) { if (!Array.isArray(list)) throw new TypeError('"list" argument must be an Array of Buffers'); if (0 === list.length) return Buffer.alloc(0); var i; if (void 0 === length) { length = 0; for(i = 0; i < list.length; ++i)length += list[i].length; } var buffer = Buffer.allocUnsafe(length); var pos = 0; for(i = 0; i < list.length; ++i){ var buf = list[i]; if (isInstance(buf, Uint8Array)) if (pos + buf.length > buffer.length) Buffer.from(buf).copy(buffer, pos); else Uint8Array.prototype.set.call(buffer, buf, pos); else if (Buffer.isBuffer(buf)) buf.copy(buffer, pos); else throw new TypeError('"list" argument must be an Array of Buffers'); pos += buf.length; } return buffer; }; function byteLength(string, encoding) { if (Buffer.isBuffer(string)) return string.length; if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) return string.byteLength; if ('string' != typeof string) throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string); var len = string.length; var mustMatch = arguments.length > 2 && true === arguments[2]; if (!mustMatch && 0 === len) return 0; var loweredCase = false; for(;;)switch(encoding){ case 'ascii': case 'latin1': case 'binary': return len; case 'utf8': case 'utf-8': return utf8ToBytes(string).length; case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return 2 * len; case 'hex': return len >>> 1; case 'base64': return base64ToBytes(string).length; default: if (loweredCase) return mustMatch ? -1 : utf8ToBytes(string).length; encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } Buffer.byteLength = byteLength; function slowToString(encoding, start, end) { var loweredCase = false; if (void 0 === start || start < 0) start = 0; if (start > this.length) return ''; if (void 0 === end || end > this.length) end = this.length; if (end <= 0) return ''; end >>>= 0; start >>>= 0; if (end <= start) return ''; if (!encoding) encoding = 'utf8'; while(true)switch(encoding){ case 'hex': return hexSlice(this, start, end); case 'utf8': case 'utf-8': return utf8Slice(this, start, end); case 'ascii': return asciiSlice(this, start, end); case 'latin1': case 'binary': return latin1Slice(this, start, end); case 'base64': return base64Slice(this, start, end); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return utf16leSlice(this, start, end); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = (encoding + '').toLowerCase(); loweredCase = true; } } Buffer.prototype._isBuffer = true; function swap(b, n, m) { var i = b[n]; b[n] = b[m]; b[m] = i; } Buffer.prototype.swap16 = function() { var len = this.length; if (len % 2 !== 0) throw new RangeError('Buffer size must be a multiple of 16-bits'); for(var i = 0; i < len; i += 2)swap(this, i, i + 1); return this; }; Buffer.prototype.swap32 = function() { var len = this.length; if (len % 4 !== 0) throw new RangeError('Buffer size must be a multiple of 32-bits'); for(var i = 0; i < len; i += 4){ swap(this, i, i + 3); swap(this, i + 1, i + 2); } return this; }; Buffer.prototype.swap64 = function() { var len = this.length; if (len % 8 !== 0) throw new RangeError('Buffer size must be a multiple of 64-bits'); for(var i = 0; i < len; i += 8){ swap(this, i, i + 7); swap(this, i + 1, i + 6); swap(this, i + 2, i + 5); swap(this, i + 3, i + 4); } return this; }; Buffer.prototype.toString = function() { var length = this.length; if (0 === length) return ''; if (0 === arguments.length) return utf8Slice(this, 0, length); return slowToString.apply(this, arguments); }; Buffer.prototype.toLocaleString = Buffer.prototype.toString; Buffer.prototype.equals = function(b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); if (this === b) return true; return 0 === Buffer.compare(this, b); }; Buffer.prototype.inspect = function() { var str = ''; var max = exports.INSPECT_MAX_BYTES; str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); if (this.length > max) str += ' ... '; return '<Buffer ' + str + '>'; }; if (customInspectSymbol) Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; Buffer.prototype.compare = function(target, start, end, thisStart, thisEnd) { if (isInstance(target, Uint8Array)) target = Buffer.from(target, target.offset, target.byteLength); if (!Buffer.isBuffer(target)) throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target); if (void 0 === start) start = 0; if (void 0 === end) end = target ? target.length : 0; if (void 0 === thisStart) thisStart = 0; if (void 0 === thisEnd) thisEnd = this.length; if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) throw new RangeError('out of range index'); if (thisStart >= thisEnd && start >= end) return 0; if (thisStart >= thisEnd) return -1; if (start >= end) return 1; start >>>= 0; end >>>= 0; thisStart >>>= 0; thisEnd >>>= 0; if (this === target) return 0; var x = thisEnd - thisStart; var y = end - start; var len = Math.min(x, y); var thisCopy = this.slice(thisStart, thisEnd); var targetCopy = target.slice(start, end); for(var i = 0; i < len; ++i)if (thisCopy[i] !== targetCopy[i]) { x = thisCopy[i]; y = targetCopy[i]; break; } if (x < y) return -1; if (y < x) return 1; return 0; }; function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { if (0 === buffer.length) return -1; if ('string' == typeof byteOffset) { encoding = byteOffset; byteOffset = 0; } else if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff; else if (byteOffset < -2147483648) byteOffset = -2147483648; byteOffset *= 1; if (numberIsNaN(byteOffset)) byteOffset = dir ? 0 : buffer.length - 1; if (byteOffset < 0) byteOffset = buffer.length + byteOffset; if (byteOffset >= buffer.length) if (dir) return -1; else byteOffset = buffer.length - 1; else if (byteOffset < 0) if (!dir) return -1; else byteOffset = 0; if ('string' == typeof val) val = Buffer.from(val, encoding); if (Buffer.isBuffer(val)) { if (0 === val.length) return -1; return arrayIndexOf(buffer, val, byteOffset, encoding, dir); } if ('number' == typeof val) { val &= 0xFF; if ('function' == typeof Uint8Array.prototype.indexOf) if (dir) return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); else return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir); } throw new TypeError('val must be string, number or Buffer'); } function arrayIndexOf(arr, val, byteOffset, encoding, dir) { var indexSize = 1; var arrLength = arr.length; var valLength = val.length; if (void 0 !== encoding) { encoding = String(encoding).toLowerCase(); if ('ucs2' === encoding || 'ucs-2' === encoding || 'utf16le' === encoding || 'utf-16le' === encoding) { if (arr.length < 2 || val.length < 2) return -1; indexSize = 2; arrLength /= 2; valLength /= 2; byteOffset /= 2; } } function read(buf, i) { if (1 === indexSize) return buf[i]; return buf.readUInt16BE(i * indexSize); } var i; if (dir) { var foundIndex = -1; for(i = byteOffset; i < arrLength; i++)if (read(arr, i) === read(val, -1 === foundIndex ? 0 : i - foundIndex)) { if (-1 === foundIndex) foundIndex = i; if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; } else { if (-1 !== foundIndex) i -= i - foundIndex; foundIndex = -1; } } else { if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; for(i = byteOffset; i >= 0; i--){ var found = true; for(var j = 0; j < valLength; j++)if (read(arr, i + j) !== read(val, j)) { found = false; break; } if (found) return i; } } return -1; } Buffer.prototype.includes = function(val, byteOffset, encoding) { return -1 !== this.indexOf(val, byteOffset, encoding); }; Buffer.prototype.indexOf = function(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, true); }; Buffer.prototype.lastIndexOf = function(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false); }; function hexWrite(buf, string, offset, length) { offset = Number(offset) || 0; var remaining = buf.length - offset; if (length) { length = Number(length); if (length > remaining) length = remaining; } else length = remaining; var strLen = string.length; if (length > strLen / 2) length = strLen / 2; for(var i = 0; i < length; ++i){ var parsed = parseInt(string.substr(2 * i, 2), 16); if (numberIsNaN(parsed)) break; buf[offset + i] = parsed; } return i; } function utf8Write(buf, string, offset, length) { return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); } function asciiWrite(buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length); } function base64Write(buf, string, offset, length) { return blitBuffer(base64ToBytes(string), buf, offset, length); } function ucs2Write(buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); } Buffer.prototype.write = function(string, offset, length, encoding) { if (void 0 === offset) { encoding = 'utf8'; length = this.length; offset = 0; } else if (void 0 === length && 'string' == typeof offset) { encoding = offset; length = this.length; offset = 0; } else if (isFinite(offset)) { offset >>>= 0; if (isFinite(length)) { length >>>= 0; if (void 0 === encoding) encoding = 'utf8'; } else { encoding = length; length = void 0; } } else throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); var remaining = this.length - offset; if (void 0 === length || length > remaining) length = remaining; if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) throw new RangeError('Attempt to write outside buffer bounds'); if (!encoding) encoding = 'utf8'; var loweredCase = false; for(;;)switch(encoding){ case 'hex': return hexWrite(this, string, offset, length); case 'utf8': case 'utf-8': return utf8Write(this, string, offset, length); case 'ascii': case 'latin1': case 'binary': return asciiWrite(this, string, offset, length); case 'base64': return base64Write(this, string, offset, length); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return ucs2Write(this, string, offset, length); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = ('' + encoding).toLowerCase(); loweredCase = true; } }; Buffer.prototype.toJSON = function() { return { type: 'Buffer', data: Array.prototype.slice.call(this._arr || this, 0) }; }; function base64Slice(buf, start, end) { if (0 === start && end === buf.length) return base64.fromByteArray(buf); return base64.fromByteArray(buf.slice(start, end)); } function utf8Slice(buf, start, end) { end = Math.min(buf.length, end); var res = []; var i = start; while(i < end){ var firstByte = buf[i]; var codePoint = null; var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint; switch(bytesPerSequence){ case 1: if (firstByte < 0x80) codePoint = firstByte; break; case 2: secondByte = buf[i + 1]; if ((0xC0 & secondByte) === 0x80) { tempCodePoint = (0x1F & firstByte) << 0x6 | 0x3F & secondByte; if (tempCodePoint > 0x7F) codePoint = tempCodePoint; } break; case 3: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; if ((0xC0 & secondByte) === 0x80 && (0xC0 & thirdByte) === 0x80) { tempCodePoint = (0xF & firstByte) << 0xC | (0x3F & secondByte) << 0x6 | 0x3F & thirdByte; if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) codePoint = tempCodePoint; } break; case 4: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; fourthByte = buf[i + 3]; if ((0xC0 & secondByte) === 0x80 && (0xC0 & thirdByte) === 0x80 && (0xC0 & fourthByte) === 0x80) { tempCodePoint = (0xF & firstByte) << 0x12 | (0x3F & secondByte) << 0xC | (0x3F & thirdByte) << 0x6 | 0x3F & fourthByte; if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) codePoint = tempCodePoint; } } } if (null === codePoint) { codePoint = 0xFFFD; bytesPerSequence = 1; } else if (codePoint > 0xFFFF) { codePoint -= 0x10000; res.push(codePoint >>> 10 & 0x3FF | 0xD800); codePoint = 0xDC00 | 0x3FF & codePoint; } res.push(codePoint); i += bytesPerSequence; } return decodeCodePointsArray(res); } var MAX_ARGUMENTS_LENGTH = 0x1000; function decodeCodePointsArray(codePoints) { var len = codePoints.length; if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints); var res = ''; var i = 0; while(i < len)res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); return res; } function asciiSlice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for(var i = start; i < end; ++i)ret += String.fromCharCode(0x7F & buf[i]); return ret; } function latin1Slice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for(var i = start; i < end; ++i)ret += String.fromCharCode(buf[i]); return ret; } function hexSlice(buf, start, end) { var len = buf.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for(var i = start; i < end; ++i)out += hexSliceLookupTable[buf[i]]; return out; } function utf16leSlice(buf, start, end) { var bytes = buf.slice(start, end); var res = ''; for(var i = 0; i < bytes.length - 1; i += 2)res += String.fromCharCode(bytes[i] + 256 * bytes[i + 1]); return res; } Buffer.prototype.slice = function(start, end) { var len = this.length; start = ~~start; end = void 0 === end ? len : ~~end; if (start < 0) { start += len; if (start < 0) start = 0; } else if (start > len) start = len; if (end < 0) { end += len; if (end < 0) end = 0; } else if (end > len) end = len; if (end < start) end = start; var newBuf = this.subarray(start, end); Object.setPrototypeOf(newBuf, Buffer.prototype); return newBuf; }; function checkOffset(offset, ext, length) { if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); } Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function(offset, byteLength, noAssert) { offset >>>= 0; byteLength >>>= 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while(++i < byteLength && (mul *= 0x100))val += this[offset + i] * mul; return val; }; Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function(offset, byteLength, noAssert) { offset >>>= 0; byteLength >>>= 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset + --byteLength]; var mul = 1; while(byteLength > 0 && (mul *= 0x100))val += this[offset + --byteLength] * mul; return val; }; Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 1, this.length); return this[offset]; }; Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] | this[offset + 1] << 8; }; Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 2, this.length); return this[offset] << 8 | this[offset + 1]; }; Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + 0x1000000 * this[offset + 3]; }; Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return 0x1000000 * this[offset] + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); }; Buffer.prototype.readIntLE = function(offset, byteLength, noAssert) { offset >>>= 0; byteLength >>>= 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while(++i < byteLength && (mul *= 0x100))val += this[offset + i] * mul; mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readIntBE = function(offset, byteLength, noAssert) { offset >>>= 0; byteLength >>>= 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var i = byteLength; var mul = 1; var val = this[offset + --i]; while(i > 0 && (mul *= 0x100))val += this[offset + --i] * mul; mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readInt8 = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 1, this.length); if (!(0x80 & this[offset])) return this[offset]; return (0xff - this[offset] + 1) * -1; }; Buffer.prototype.readInt16LE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset] | this[offset + 1] << 8; return 0x8000 & val ? 0xFFFF0000 | val : val; }; Buffer.prototype.readInt16BE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset + 1] | this[offset] << 8; return 0x8000 & val ? 0xFFFF0000 | val : val; }; Buffer.prototype.readInt32LE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; }; Buffer.prototype.readInt32BE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; }; Buffer.prototype.readFloatLE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return ieee754.read(this, offset, true, 23, 4); }; Buffer.prototype.readFloatBE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 4, this.length); return ieee754.read(this, offset, false, 23, 4); }; Buffer.prototype.readDoubleLE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 8, this.length); return ieee754.read(this, offset, true, 52, 8); }; Buffer.prototype.readDoubleBE = function(offset, noAssert) { offset >>>= 0; if (!noAssert) checkOffset(offset, 8, this.length); return ieee754.read(this, offset, false, 52, 8); }; function checkInt(buf, value, offset, ext, max, min) { if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance'); if (value > max || value < min) throw new RangeError('"value" argument is out of bounds'); if (offset + ext > buf.length) throw new RangeError('Index out of range'); } Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function(value, offset, byteLength, noAssert) { value *= 1; offset >>>= 0; byteLength >>>= 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1; checkInt(this, value, offset, byteLength, maxBytes, 0); } var mul = 1; var i = 0; this[offset] = 0xFF & value; while(++i < byteLength && (mul *= 0x100))this[offset + i] = value / mul & 0xFF; return offset + byteLength; }; Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function(value, offset, byteLength, noAssert) { value *= 1; offset >>>= 0; byteLength >>>= 0; if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1; checkInt(this, value, offset, byteLength, maxBytes, 0); } var i = byteLength - 1; var mul = 1; this[offset + i] = 0xFF & value; while(--i >= 0 && (mul *= 0x100))this[offset + i] = value / mul & 0xFF; return offset + byteLength; }; Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); this[offset] = 0xff & value; return offset + 1; }; Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); this[offset] = 0xff & value; this[offset + 1] = value >>> 8; return offset + 2; }; Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); this[offset] = value >>> 8; this[offset + 1] = 0xff & value; return offset + 2; }; Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); this[offset + 3] = value >>> 24; this[offset + 2] = value >>> 16; this[offset + 1] = value >>> 8; this[offset] = 0xff & value; return offset + 4; }; Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); this[offset] = value >>> 24; this[offset + 1] = value >>> 16; this[offset + 2] = value >>> 8; this[offset + 3] = 0xff & value; return offset + 4; }; Buffer.prototype.writeIntLE = function(value, offset, byteLength, noAssert) { value *= 1; offset >>>= 0; if (!noAssert) { var limit = Math.pow(2, 8 * byteLength - 1); checkInt(this, value, offset, byteLength, limit - 1, -limit); } var i = 0; var mul = 1; var sub = 0; this[offset] = 0xFF & value; while(++i < byteLength && (mul *= 0x100)){ if (value < 0 && 0 === sub && 0 !== this[offset + i - 1]) sub = 1;