UNPKG

dashjs

Version:

A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.

1,328 lines (1,128 loc) 360 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["dashjs"] = factory(); else root["dashjs"] = factory(); })(self, function() { return /******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./src/core/FactoryMaker.js": /*!**********************************!*\ !*** ./src/core/FactoryMaker.js ***! \**********************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @module FactoryMaker * @ignore */ var FactoryMaker = function () { var instance; var singletonContexts = []; var singletonFactories = {}; var classFactories = {}; function extend(name, childInstance, override, context) { if (!context[name] && childInstance) { context[name] = { instance: childInstance, override: override }; } } /** * Use this method from your extended object. this.factory is injected into your object. * this.factory.getSingletonInstance(this.context, 'VideoModel') * will return the video model for use in the extended object. * * @param {Object} context - injected into extended object as this.context * @param {string} className - string name found in all dash.js objects * with name __dashjs_factory_name Will be at the bottom. Will be the same as the object's name. * @returns {*} Context aware instance of specified singleton name. * @memberof module:FactoryMaker * @instance */ function getSingletonInstance(context, className) { for (var i in singletonContexts) { var obj = singletonContexts[i]; if (obj.context === context && obj.name === className) { return obj.instance; } } return null; } /** * Use this method to add an singleton instance to the system. Useful for unit testing to mock objects etc. * * @param {Object} context * @param {string} className * @param {Object} instance * @memberof module:FactoryMaker * @instance */ function setSingletonInstance(context, className, instance) { for (var i in singletonContexts) { var obj = singletonContexts[i]; if (obj.context === context && obj.name === className) { singletonContexts[i].instance = instance; return; } } singletonContexts.push({ name: className, context: context, instance: instance }); } /** * Use this method to remove all singleton instances associated with a particular context. * * @param {Object} context * @memberof module:FactoryMaker * @instance */ function deleteSingletonInstances(context) { singletonContexts = singletonContexts.filter(function (x) { return x.context !== context; }); } /*------------------------------------------------------------------------------------------*/ // Factories storage Management /*------------------------------------------------------------------------------------------*/ function getFactoryByName(name, factoriesArray) { return factoriesArray[name]; } function updateFactory(name, factory, factoriesArray) { if (name in factoriesArray) { factoriesArray[name] = factory; } } /*------------------------------------------------------------------------------------------*/ // Class Factories Management /*------------------------------------------------------------------------------------------*/ function updateClassFactory(name, factory) { updateFactory(name, factory, classFactories); } function getClassFactoryByName(name) { return getFactoryByName(name, classFactories); } function getClassFactory(classConstructor) { var factory = getFactoryByName(classConstructor.__dashjs_factory_name, classFactories); if (!factory) { factory = function factory(context) { if (context === undefined) { context = {}; } return { create: function create() { return merge(classConstructor, context, arguments); } }; }; classFactories[classConstructor.__dashjs_factory_name] = factory; // store factory } return factory; } /*------------------------------------------------------------------------------------------*/ // Singleton Factory MAangement /*------------------------------------------------------------------------------------------*/ function updateSingletonFactory(name, factory) { updateFactory(name, factory, singletonFactories); } function getSingletonFactoryByName(name) { return getFactoryByName(name, singletonFactories); } function getSingletonFactory(classConstructor) { var factory = getFactoryByName(classConstructor.__dashjs_factory_name, singletonFactories); if (!factory) { factory = function factory(context) { var instance; if (context === undefined) { context = {}; } return { getInstance: function getInstance() { // If we don't have an instance yet check for one on the context if (!instance) { instance = getSingletonInstance(context, classConstructor.__dashjs_factory_name); } // If there's no instance on the context then create one if (!instance) { instance = merge(classConstructor, context, arguments); singletonContexts.push({ name: classConstructor.__dashjs_factory_name, context: context, instance: instance }); } return instance; } }; }; singletonFactories[classConstructor.__dashjs_factory_name] = factory; // store factory } return factory; } function merge(classConstructor, context, args) { var classInstance; var className = classConstructor.__dashjs_factory_name; var extensionObject = context[className]; if (extensionObject) { var extension = extensionObject.instance; if (extensionObject.override) { //Override public methods in parent but keep parent. classInstance = classConstructor.apply({ context: context }, args); extension = extension.apply({ context: context, factory: instance, parent: classInstance }, args); for (var prop in extension) { if (classInstance.hasOwnProperty(prop)) { classInstance[prop] = extension[prop]; } } } else { //replace parent object completely with new object. Same as dijon. return extension.apply({ context: context, factory: instance }, args); } } else { // Create new instance of the class classInstance = classConstructor.apply({ context: context }, args); } // Add getClassName function to class instance prototype (used by Debug) classInstance.getClassName = function () { return className; }; return classInstance; } instance = { extend: extend, getSingletonInstance: getSingletonInstance, setSingletonInstance: setSingletonInstance, deleteSingletonInstances: deleteSingletonInstances, getSingletonFactory: getSingletonFactory, getSingletonFactoryByName: getSingletonFactoryByName, updateSingletonFactory: updateSingletonFactory, getClassFactory: getClassFactory, getClassFactoryByName: getClassFactoryByName, updateClassFactory: updateClassFactory }; return instance; }(); /* harmony default export */ __webpack_exports__["default"] = (FactoryMaker); /***/ }), /***/ "./src/core/Utils.js": /*!***************************!*\ !*** ./src/core/Utils.js ***! \***************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */ var path_browserify__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! path-browserify */ "./node_modules/path-browserify/index.js"); /* harmony import */ var path_browserify__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path_browserify__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var ua_parser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ua-parser-js */ "./node_modules/ua-parser-js/src/ua-parser.js"); /* harmony import */ var ua_parser_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(ua_parser_js__WEBPACK_IMPORTED_MODULE_1__); function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @class * @ignore */ var Utils = /*#__PURE__*/function () { function Utils() { _classCallCheck(this, Utils); } _createClass(Utils, null, [{ key: "mixin", value: function mixin(dest, source, copy) { var s; var empty = {}; if (dest) { for (var name in source) { if (source.hasOwnProperty(name)) { s = source[name]; if (!(name in dest) || dest[name] !== s && (!(name in empty) || empty[name] !== s)) { if (_typeof(dest[name]) === 'object' && dest[name] !== null) { dest[name] = Utils.mixin(dest[name], s, copy); } else { dest[name] = copy(s); } } } } } return dest; } }, { key: "clone", value: function clone(src) { if (!src || _typeof(src) !== 'object') { return src; // anything } var r; if (src instanceof Array) { // array r = []; for (var i = 0, l = src.length; i < l; ++i) { if (i in src) { r.push(Utils.clone(src[i])); } } } else { r = {}; } return Utils.mixin(r, src, Utils.clone); } }, { key: "addAditionalQueryParameterToUrl", value: function addAditionalQueryParameterToUrl(url, params) { try { if (!params || params.length === 0) { return url; } var modifiedUrl = new URL(url); params.forEach(function (param) { if (param.key && param.value) { modifiedUrl.searchParams.set(param.key, param.value); } }); return modifiedUrl.href; } catch (e) { return url; } } }, { key: "parseHttpHeaders", value: function parseHttpHeaders(headerStr) { var headers = {}; if (!headerStr) { return headers; } // Trim headerStr to fix a MS Edge bug with xhr.getAllResponseHeaders method // which send a string starting with a "\n" character var headerPairs = headerStr.trim().split("\r\n"); for (var i = 0, ilen = headerPairs.length; i < ilen; i++) { var headerPair = headerPairs[i]; var index = headerPair.indexOf(": "); if (index > 0) { headers[headerPair.substring(0, index)] = headerPair.substring(index + 2); } } return headers; } }, { key: "generateUuid", value: function generateUuid() { var dt = new Date().getTime(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (dt + Math.random() * 16) % 16 | 0; dt = Math.floor(dt / 16); return (c == 'x' ? r : r & 0x3 | 0x8).toString(16); }); return uuid; } }, { key: "generateHashCode", value: function generateHashCode(string) { var hash = 0; if (string.length === 0) { return hash; } for (var i = 0; i < string.length; i++) { var chr = string.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; } return hash; } /** * Compares both urls and returns a relative url (target relative to original) * @param {string} originalUrl * @param {string} targetUrl * @return {string|*} */ }, { key: "getRelativeUrl", value: function getRelativeUrl(originalUrl, targetUrl) { try { var original = new URL(originalUrl); var target = new URL(targetUrl); // Unify the protocol to compare the origins original.protocol = target.protocol; if (original.origin !== target.origin) { return targetUrl; } // Use the relative path implementation of the path library. We need to cut off the actual filename in the end to get the relative path var relativePath = path_browserify__WEBPACK_IMPORTED_MODULE_0___default().relative(original.pathname.substr(0, original.pathname.lastIndexOf('/')), target.pathname.substr(0, target.pathname.lastIndexOf('/'))); // In case the relative path is empty (both path are equal) return the filename only. Otherwise add a slash in front of the filename var startIndexOffset = relativePath.length === 0 ? 1 : 0; relativePath += target.pathname.substr(target.pathname.lastIndexOf('/') + startIndexOffset, target.pathname.length - 1); // Build the other candidate, e.g. the 'host relative' path that starts with "/", and return the shortest of the two candidates. if (target.pathname.length < relativePath.length) { return target.pathname; } return relativePath; } catch (e) { return targetUrl; } } }, { key: "parseUserAgent", value: function parseUserAgent() { var ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; try { var uaString = ua === null ? typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '' : ''; return (0,ua_parser_js__WEBPACK_IMPORTED_MODULE_1__.UAParser)(uaString); } catch (e) { return {}; } } /** * Checks for existence of "http" or "https" in a string * @param string * @returns {boolean} */ }, { key: "stringHasProtocol", value: function stringHasProtocol(string) { return /(http(s?)):\/\//i.test(string); } }]); return Utils; }(); /* harmony default export */ __webpack_exports__["default"] = (Utils); /***/ }), /***/ "./src/core/errors/ErrorsBase.js": /*!***************************************!*\ !*** ./src/core/errors/ErrorsBase.js ***! \***************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @class * @ignore */ var ErrorsBase = /*#__PURE__*/function () { function ErrorsBase() { _classCallCheck(this, ErrorsBase); } _createClass(ErrorsBase, [{ key: "extend", value: function extend(errors, config) { if (!errors) return; var override = config ? config.override : false; var publicOnly = config ? config.publicOnly : false; for (var err in errors) { if (!errors.hasOwnProperty(err) || this[err] && !override) continue; if (publicOnly && errors[err].indexOf('public_') === -1) continue; this[err] = errors[err]; } } }]); return ErrorsBase; }(); /* harmony default export */ __webpack_exports__["default"] = (ErrorsBase); /***/ }), /***/ "./src/core/events/EventsBase.js": /*!***************************************!*\ !*** ./src/core/events/EventsBase.js ***! \***************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @class * @ignore */ var EventsBase = /*#__PURE__*/function () { function EventsBase() { _classCallCheck(this, EventsBase); } _createClass(EventsBase, [{ key: "extend", value: function extend(events, config) { if (!events) return; var override = config ? config.override : false; var publicOnly = config ? config.publicOnly : false; for (var evt in events) { if (!events.hasOwnProperty(evt) || this[evt] && !override) continue; if (publicOnly && events[evt].indexOf('public_') === -1) continue; this[evt] = events[evt]; } } }]); return EventsBase; }(); /* harmony default export */ __webpack_exports__["default"] = (EventsBase); /***/ }), /***/ "./src/streaming/constants/Constants.js": /*!**********************************************!*\ !*** ./src/streaming/constants/Constants.js ***! \**********************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * Constants declaration * @class * @ignore * @hideconstructor */ var Constants = /*#__PURE__*/function () { function Constants() { _classCallCheck(this, Constants); this.init(); } _createClass(Constants, [{ key: "init", value: function init() { /** * @constant {string} STREAM Stream media type. Mainly used to report metrics relative to the full stream * @memberof Constants# * @static */ this.STREAM = 'stream'; /** * @constant {string} VIDEO Video media type * @memberof Constants# * @static */ this.VIDEO = 'video'; /** * @constant {string} AUDIO Audio media type * @memberof Constants# * @static */ this.AUDIO = 'audio'; /** * @constant {string} TEXT Text media type * @memberof Constants# * @static */ this.TEXT = 'text'; /** * @constant {string} MUXED Muxed (video/audio in the same chunk) media type * @memberof Constants# * @static */ this.MUXED = 'muxed'; /** * @constant {string} IMAGE Image media type * @memberof Constants# * @static */ this.IMAGE = 'image'; /** * @constant {string} STPP STTP Subtitles format * @memberof Constants# * @static */ this.STPP = 'stpp'; /** * @constant {string} TTML STTP Subtitles format * @memberof Constants# * @static */ this.TTML = 'ttml'; /** * @constant {string} VTT STTP Subtitles format * @memberof Constants# * @static */ this.VTT = 'vtt'; /** * @constant {string} WVTT STTP Subtitles format * @memberof Constants# * @static */ this.WVTT = 'wvtt'; /** * @constant {string} Content Steering * @memberof Constants# * @static */ this.CONTENT_STEERING = 'contentSteering'; /** * @constant {string} ABR_STRATEGY_DYNAMIC Dynamic Adaptive bitrate algorithm * @memberof Constants# * @static */ this.ABR_STRATEGY_DYNAMIC = 'abrDynamic'; /** * @constant {string} ABR_STRATEGY_BOLA Adaptive bitrate algorithm based on Bola (buffer level) * @memberof Constants# * @static */ this.ABR_STRATEGY_BOLA = 'abrBola'; /** * @constant {string} ABR_STRATEGY_L2A Adaptive bitrate algorithm based on L2A (online learning) * @memberof Constants# * @static */ this.ABR_STRATEGY_L2A = 'abrL2A'; /** * @constant {string} ABR_STRATEGY_LoLP Adaptive bitrate algorithm based on LoL+ * @memberof Constants# * @static */ this.ABR_STRATEGY_LoLP = 'abrLoLP'; /** * @constant {string} ABR_STRATEGY_THROUGHPUT Adaptive bitrate algorithm based on throughput * @memberof Constants# * @static */ this.ABR_STRATEGY_THROUGHPUT = 'abrThroughput'; /** * @constant {string} ABR_FETCH_THROUGHPUT_CALUCUALTION_DOWNLOADED_DATA Throughput calculation based on downloaded data array * @memberof Constants# * @static */ this.ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA = 'abrFetchThroughputCalculationDownloadedData'; /** * @constant {string} ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING Throughput calculation based on moof parsing * @memberof Constants# * @static */ this.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING = 'abrFetchThroughputCalculationMoofParsing'; /** * @constant {string} ABR_FETCH_THROUGHPUT_CALCULATION_AAST Throughput calculation based on adjusted availability start time in low latency mode * @memberof Constants# * @static */ this.ABR_FETCH_THROUGHPUT_CALCULATION_AAST = 'abrFetchThroughputCalculationAAST'; /** * @constant {string} LIVE_CATCHUP_MODE_DEFAULT Throughput calculation based on moof parsing * @memberof Constants# * @static */ this.LIVE_CATCHUP_MODE_DEFAULT = 'liveCatchupModeDefault'; /** * @constant {string} LIVE_CATCHUP_MODE_LOLP Throughput calculation based on moof parsing * @memberof Constants# * @static */ this.LIVE_CATCHUP_MODE_LOLP = 'liveCatchupModeLoLP'; /** * @constant {string} MOVING_AVERAGE_SLIDING_WINDOW Moving average sliding window * @memberof Constants# * @static */ this.MOVING_AVERAGE_SLIDING_WINDOW = 'slidingWindow'; /** * @constant {string} EWMA Exponential moving average * @memberof Constants# * @static */ this.MOVING_AVERAGE_EWMA = 'ewma'; /** * @constant {string} BAD_ARGUMENT_ERROR Invalid Arguments type of error * @memberof Constants# * @static */ this.BAD_ARGUMENT_ERROR = 'Invalid Arguments'; /** * @constant {string} MISSING_CONFIG_ERROR Missing configuration parameters type of error * @memberof Constants# * @static */ this.MISSING_CONFIG_ERROR = 'Missing config parameter(s)'; /** * @constant {string} TRACK_SWITCH_MODE_ALWAYS_REPLACE used to clear the buffered data (prior to current playback position) after track switch. Default for audio * @memberof Constants# * @static */ this.TRACK_SWITCH_MODE_ALWAYS_REPLACE = 'alwaysReplace'; /** * @constant {string} TRACK_SWITCH_MODE_NEVER_REPLACE used to forbid clearing the buffered data (prior to current playback position) after track switch. Defers to fastSwitchEnabled for placement of new data. Default for video * @memberof Constants# * @static */ this.TRACK_SWITCH_MODE_NEVER_REPLACE = 'neverReplace'; /** * @constant {string} TRACK_SELECTION_MODE_FIRST_TRACK makes the player select the first track found in the manifest. * @memberof Constants# * @static */ this.TRACK_SELECTION_MODE_FIRST_TRACK = 'firstTrack'; /** * @constant {string} TRACK_SELECTION_MODE_HIGHEST_BITRATE makes the player select the track with a highest bitrate. This mode is a default mode. * @memberof Constants# * @static */ this.TRACK_SELECTION_MODE_HIGHEST_BITRATE = 'highestBitrate'; /** * @constant {string} TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY makes the player select the track with the lowest bitrate per pixel average. * @memberof Constants# * @static */ this.TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY = 'highestEfficiency'; /** * @constant {string} TRACK_SELECTION_MODE_WIDEST_RANGE makes the player select the track with a widest range of bitrates. * @memberof Constants# * @static */ this.TRACK_SELECTION_MODE_WIDEST_RANGE = 'widestRange'; /** * @constant {string} TRACK_SELECTION_MODE_WIDEST_RANGE makes the player select the track with the highest selectionPriority as defined in the manifest * @memberof Constants# * @static */ this.TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY = 'highestSelectionPriority'; /** * @constant {string} CMCD_MODE_QUERY specifies to attach CMCD metrics as query parameters. * @memberof Constants# * @static */ this.CMCD_MODE_QUERY = 'query'; /** * @constant {string} CMCD_MODE_HEADER specifies to attach CMCD metrics as HTTP headers. * @memberof Constants# * @static */ this.CMCD_MODE_HEADER = 'header'; this.INITIALIZE = 'initialize'; this.TEXT_SHOWING = 'showing'; this.TEXT_HIDDEN = 'hidden'; this.TEXT_DISABLED = 'disabled'; this.CC1 = 'CC1'; this.CC3 = 'CC3'; this.UTF8 = 'utf-8'; this.SCHEME_ID_URI = 'schemeIdUri'; this.START_TIME = 'starttime'; this.SERVICE_DESCRIPTION_DVB_LL_SCHEME = 'urn:dvb:dash:lowlatency:scope:2019'; this.SUPPLEMENTAL_PROPERTY_DVB_LL_SCHEME = 'urn:dvb:dash:lowlatency:critical:2019'; this.FONT_DOWNLOAD_DVB_SCHEME = 'urn:dvb:dash:fontdownload:2014'; this.XML = 'XML'; this.ARRAY_BUFFER = 'ArrayBuffer'; this.DVB_REPORTING_URL = 'dvb:reportingUrl'; this.DVB_PROBABILITY = 'dvb:probability'; this.OFF_MIMETYPE = 'application/font-sfnt'; this.WOFF_MIMETYPE = 'application/font-woff'; this.VIDEO_ELEMENT_READY_STATES = { HAVE_NOTHING: 0, HAVE_METADATA: 1, HAVE_CURRENT_DATA: 2, HAVE_FUTURE_DATA: 3, HAVE_ENOUGH_DATA: 4 }; this.FILE_LOADER_TYPES = { FETCH: 'fetch_loader', XHR: 'xhr_loader' }; } }]); return Constants; }(); var constants = new Constants(); /* harmony default export */ __webpack_exports__["default"] = (constants); /***/ }), /***/ "./src/streaming/constants/ProtectionConstants.js": /*!********************************************************!*\ !*** ./src/streaming/constants/ProtectionConstants.js ***! \********************************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * Protection Constants declaration * @class * @ignore */ var ProtectionConstants = /*#__PURE__*/function () { function ProtectionConstants() { _classCallCheck(this, ProtectionConstants); this.init(); } _createClass(ProtectionConstants, [{ key: "init", value: function init() { this.CLEARKEY_KEYSTEM_STRING = 'org.w3.clearkey'; this.WIDEVINE_KEYSTEM_STRING = 'com.widevine.alpha'; this.PLAYREADY_KEYSTEM_STRING = 'com.microsoft.playready'; this.PLAYREADY_RECOMMENDATION_KEYSTEM_STRING = 'com.microsoft.playready.recommendation'; this.INITIALIZATION_DATA_TYPE_CENC = 'cenc'; this.INITIALIZATION_DATA_TYPE_KEYIDS = 'keyids'; this.INITIALIZATION_DATA_TYPE_WEBM = 'webm'; } }]); return ProtectionConstants; }(); var constants = new ProtectionConstants(); /* harmony default export */ __webpack_exports__["default"] = (constants); /***/ }), /***/ "./src/streaming/protection/CommonEncryption.js": /*!******************************************************!*\ !*** ./src/streaming/protection/CommonEncryption.js ***! \******************************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ var LICENSE_SERVER_MANIFEST_CONFIGURATIONS = { attributes: ['Laurl', 'laurl'], prefixes: ['clearkey', 'dashif'] }; /** * @class * @ignore */ var CommonEncryption = /*#__PURE__*/function () { function CommonEncryption() { _classCallCheck(this, CommonEncryption); } _createClass(CommonEncryption, null, [{ key: "findCencContentProtection", value: /** * Find and return the ContentProtection element in the given array * that indicates support for MPEG Common Encryption * * @param {Array} cpArray array of content protection elements * @returns {Object|null} the Common Encryption content protection element or * null if one was not found */ function findCencContentProtection(cpArray) { var retVal = null; for (var i = 0; i < cpArray.length; ++i) { var cp = cpArray[i]; if (cp.schemeIdUri.toLowerCase() === 'urn:mpeg:dash:mp4protection:2011' && (cp.value.toLowerCase() === 'cenc' || cp.value.toLowerCase() === 'cbcs')) retVal = cp; } return retVal; } /** * Returns just the data portion of a single PSSH * * @param {ArrayBuffer} pssh - the PSSH * @return {ArrayBuffer} data portion of the PSSH */ }, { key: "getPSSHData", value: function getPSSHData(pssh) { var offset = 8; // Box size and type fields var view = new DataView(pssh); // Read version var version = view.getUint8(offset); offset += 20; // Version (1), flags (3), system ID (16) if (version > 0) { offset += 4 + 16 * view.getUint32(offset); // Key ID count (4) and All key IDs (16*count) } offset += 4; // Data size return pssh.slice(offset); } /** * Returns the PSSH associated with the given key system from the concatenated * list of PSSH boxes in the given initData * * @param {KeySystem} keySystem the desired * key system * @param {ArrayBuffer} initData 'cenc' initialization data. Concatenated list of PSSH. * @returns {ArrayBuffer|null} The PSSH box data corresponding to the given key system, null if not found * or null if a valid association could not be found. */ }, { key: "getPSSHForKeySystem", value: function getPSSHForKeySystem(keySystem, initData) { var psshList = CommonEncryption.parsePSSHList(initData); if (keySystem && psshList.hasOwnProperty(keySystem.uuid.toLowerCase())) { return psshList[keySystem.uuid.toLowerCase()]; } return null; } /** * Parse a standard common encryption PSSH which contains a simple * base64-encoding of the init data * * @param {Object} cpData the ContentProtection element * @param {BASE64} BASE64 reference * @returns {ArrayBuffer|null} the init data or null if not found */ }, { key: "parseInitDataFromContentProtection", value: function parseInitDataFromContentProtection(cpData, BASE64) { if ('pssh' in cpData) { // Remove whitespaces and newlines from pssh text cpData.pssh.__text = cpData.pssh.__text.replace(/\r?\n|\r/g, '').replace(/\s+/g, ''); return BASE64.decodeArray(cpData.pssh.__text).buffer; } return null; } /** * Parses list of PSSH boxes into keysystem-specific PSSH data * * @param {ArrayBuffer} data - the concatenated list of PSSH boxes as provided by * CDM as initialization data when CommonEncryption content is detected * @returns {Object|Array} an object that has a property named according to each of * the detected key system UUIDs (e.g. 00000000-0000-0000-0000-0000000000) * and a ArrayBuffer (the entire PSSH box) as the property value */ }, { key: "parsePSSHList", value: function parsePSSHList(data) { if (data === null || data === undefined) return []; var dv = new DataView(data.buffer || data); // data.buffer first for Uint8Array support var done = false; var pssh = {}; // TODO: Need to check every data read for end of buffer var byteCursor = 0; while (!done) { var size = void 0, nextBox = void 0, version = void 0, systemID = void 0; var boxStart = byteCursor; if (byteCursor >= dv.buffer.byteLength) break; /* Box size */ size = dv.getUint32(byteCursor); nextBox = byteCursor + size; byteCursor += 4; /* Verify PSSH */ if (dv.getUint32(byteCursor) !== 0x70737368) { byteCursor = nextBox; continue; } byteCursor += 4; /* Version must be 0 or 1 */ version = dv.getUint8(byteCursor); if (version !== 0 && version !== 1) { byteCursor = nextBox; continue; } byteCursor++; byteCursor += 3; /* skip flags */ // 16-byte UUID/SystemID systemID = ''; var i = void 0, val = void 0; for (i = 0; i < 4; i++) { val = dv.getUint8(byteCurs