UNPKG

benbang

Version:
114 lines (93 loc) 2.72 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const logger = { DEBUG: 'debug', INFO: 'info', WARN: 'warn', ERROR: 'error', log(level, message, ...params) { /* eslint-disable no-console */ const method = console[level] ? level : 'log'; console[method]('[griffith] ' + message, ...params); /* eslint-enable no-console */ }, debug(...args) { this.log(this.DEBUG, ...args); }, info(...args) { this.log(this.INFO, ...args); }, warn(...args) { this.log(this.WARN, ...args); }, error(...args) { this.log(this.ERROR, ...args); } }; const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); const isAndroid = /(android)/i.test(navigator.userAgent); const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); var ua = { isMobile, isAndroid, isSafari }; /** * Copied from https://github.com/video-dev/hls.js/blob/master/src/is-supported.js */ function getMediaSource() { if (typeof window !== 'undefined') { return window.MediaSource || window.WebKitMediaSource; } } function isMSESupported() { const mediaSource = getMediaSource(); const sourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer; const isTypeSupported = mediaSource && typeof mediaSource.isTypeSupported === 'function' && mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'); const sourceBufferValidAPI = !sourceBuffer || sourceBuffer.prototype && typeof sourceBuffer.prototype.appendBuffer === 'function' && typeof sourceBuffer.prototype.remove === 'function'; return !!isTypeSupported && !!sourceBufferValidAPI; } function isHlsNativeSupported() { const video = document.createElement('video'); return Boolean(video.canPlayType('application/vnd.apple.mpegURL')); } /** * 获得最大公约数 * @param {number} a * @param {number} b */ function getGCD(a, b) { if (!Number.isInteger(a) || !Number.isInteger(b)) { throw new Error('params must be interger number'); } if (a === 0) { return Math.abs(b); } if (b === 0) { return Math.abs(a); } return getGCD(b, a % b); } /** * 约分 * @param {number} a * @param {number} b */ function reduce(a, b) { if (a === 0 || b === 0) { throw new Error('params must not be zero'); } const gcd = getGCD(a, b); return [a / gcd, b / gcd]; } function sequence(...fns) { return (...args) => fns.reduce((_, fn) => fn(...args), null); } exports.getGCD = getGCD; exports.isHlsNativeSupported = isHlsNativeSupported; exports.isMSESupported = isMSESupported; exports.logger = logger; exports.reduce = reduce; exports.sequence = sequence; exports.ua = ua; //# sourceMappingURL=index.js.map