element; its readystatechange event will be fired asynchronously once it is inserted\n // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.\n var scriptEl = global.document.createElement('script');\n scriptEl.onreadystatechange = function () {\n nextTick();\n\n scriptEl.onreadystatechange = null;\n scriptEl.parentNode.removeChild(scriptEl);\n scriptEl = null;\n };\n global.document.documentElement.appendChild(scriptEl);\n };\n } else {\n scheduleDrain = function () {\n setTimeout(nextTick, 0);\n };\n }\n}\n\nvar draining;\nvar queue = [];\n//named nextTick for less confusing stack traces\nfunction nextTick() {\n draining = true;\n var i, oldQueue;\n var len = queue.length;\n while (len) {\n oldQueue = queue;\n queue = [];\n i = -1;\n while (++i < len) {\n oldQueue[i]();\n }\n len = queue.length;\n }\n draining = false;\n}\n\nmodule.exports = immediate;\nfunction immediate(task) {\n if (queue.push(task) === 1 && !draining) {\n scheduleDrain();\n }\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],2:[function(_dereq_,module,exports){\n'use strict';\nvar immediate = _dereq_(1);\n\n/* istanbul ignore next */\nfunction INTERNAL() {}\n\nvar handlers = {};\n\nvar REJECTED = ['REJECTED'];\nvar FULFILLED = ['FULFILLED'];\nvar PENDING = ['PENDING'];\n\nmodule.exports = Promise;\n\nfunction Promise(resolver) {\n if (typeof resolver !== 'function') {\n throw new TypeError('resolver must be a function');\n }\n this.state = PENDING;\n this.queue = [];\n this.outcome = void 0;\n if (resolver !== INTERNAL) {\n safelyResolveThenable(this, resolver);\n }\n}\n\nPromise.prototype[\"catch\"] = function (onRejected) {\n return this.then(null, onRejected);\n};\nPromise.prototype.then = function (onFulfilled, onRejected) {\n if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||\n typeof onRejected !== 'function' && this.state === REJECTED) {\n return this;\n }\n var promise = new this.constructor(INTERNAL);\n if (this.state !== PENDING) {\n var resolver = this.state === FULFILLED ? onFulfilled : onRejected;\n unwrap(promise, resolver, this.outcome);\n } else {\n this.queue.push(new QueueItem(promise, onFulfilled, onRejected));\n }\n\n return promise;\n};\nfunction QueueItem(promise, onFulfilled, onRejected) {\n this.promise = promise;\n if (typeof onFulfilled === 'function') {\n this.onFulfilled = onFulfilled;\n this.callFulfilled = this.otherCallFulfilled;\n }\n if (typeof onRejected === 'function') {\n this.onRejected = onRejected;\n this.callRejected = this.otherCallRejected;\n }\n}\nQueueItem.prototype.callFulfilled = function (value) {\n handlers.resolve(this.promise, value);\n};\nQueueItem.prototype.otherCallFulfilled = function (value) {\n unwrap(this.promise, this.onFulfilled, value);\n};\nQueueItem.prototype.callRejected = function (value) {\n handlers.reject(this.promise, value);\n};\nQueueItem.prototype.otherCallRejected = function (value) {\n unwrap(this.promise, this.onRejected, value);\n};\n\nfunction unwrap(promise, func, value) {\n immediate(function () {\n var returnValue;\n try {\n returnValue = func(value);\n } catch (e) {\n return handlers.reject(promise, e);\n }\n if (returnValue === promise) {\n handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));\n } else {\n handlers.resolve(promise, returnValue);\n }\n });\n}\n\nhandlers.resolve = function (self, value) {\n var result = tryCatch(getThen, value);\n if (result.status === 'error') {\n return handlers.reject(self, result.value);\n }\n var thenable = result.value;\n\n if (thenable) {\n safelyResolveThenable(self, thenable);\n } else {\n self.state = FULFILLED;\n self.outcome = value;\n var i = -1;\n var len = self.queue.length;\n while (++i < len) {\n self.queue[i].callFulfilled(value);\n }\n }\n return self;\n};\nhandlers.reject = function (self, error) {\n self.state = REJECTED;\n self.outcome = error;\n var i = -1;\n var len = self.queue.length;\n while (++i < len) {\n self.queue[i].callRejected(error);\n }\n return self;\n};\n\nfunction getThen(obj) {\n // Make sure we only access the accessor once as required by the spec\n var then = obj && obj.then;\n if (obj && (typeof obj === 'object' || typeof obj === 'function') && typeof then === 'function') {\n return function appyThen() {\n then.apply(obj, arguments);\n };\n }\n}\n\nfunction safelyResolveThenable(self, thenable) {\n // Either fulfill, reject or reject with error\n var called = false;\n function onError(value) {\n if (called) {\n return;\n }\n called = true;\n handlers.reject(self, value);\n }\n\n function onSuccess(value) {\n if (called) {\n return;\n }\n called = true;\n handlers.resolve(self, value);\n }\n\n function tryToUnwrap() {\n thenable(onSuccess, onError);\n }\n\n var result = tryCatch(tryToUnwrap);\n if (result.status === 'error') {\n onError(result.value);\n }\n}\n\nfunction tryCatch(func, value) {\n var out = {};\n try {\n out.value = func(value);\n out.status = 'success';\n } catch (e) {\n out.status = 'error';\n out.value = e;\n }\n return out;\n}\n\nPromise.resolve = resolve;\nfunction resolve(value) {\n if (value instanceof this) {\n return value;\n }\n return handlers.resolve(new this(INTERNAL), value);\n}\n\nPromise.reject = reject;\nfunction reject(reason) {\n var promise = new this(INTERNAL);\n return handlers.reject(promise, reason);\n}\n\nPromise.all = all;\nfunction all(iterable) {\n var self = this;\n if (Object.prototype.toString.call(iterable) !== '[object Array]') {\n return this.reject(new TypeError('must be an array'));\n }\n\n var len = iterable.length;\n var called = false;\n if (!len) {\n return this.resolve([]);\n }\n\n var values = new Array(len);\n var resolved = 0;\n var i = -1;\n var promise = new this(INTERNAL);\n\n while (++i < len) {\n allResolver(iterable[i], i);\n }\n return promise;\n function allResolver(value, i) {\n self.resolve(value).then(resolveFromAll, function (error) {\n if (!called) {\n called = true;\n handlers.reject(promise, error);\n }\n });\n function resolveFromAll(outValue) {\n values[i] = outValue;\n if (++resolved === len && !called) {\n called = true;\n handlers.resolve(promise, values);\n }\n }\n }\n}\n\nPromise.race = race;\nfunction race(iterable) {\n var self = this;\n if (Object.prototype.toString.call(iterable) !== '[object Array]') {\n return this.reject(new TypeError('must be an array'));\n }\n\n var len = iterable.length;\n var called = false;\n if (!len) {\n return this.resolve([]);\n }\n\n var i = -1;\n var promise = new this(INTERNAL);\n\n while (++i < len) {\n resolver(iterable[i]);\n }\n return promise;\n function resolver(value) {\n self.resolve(value).then(function (response) {\n if (!called) {\n called = true;\n handlers.resolve(promise, response);\n }\n }, function (error) {\n if (!called) {\n called = true;\n handlers.reject(promise, error);\n }\n });\n }\n}\n\n},{\"1\":1}],3:[function(_dereq_,module,exports){\n(function (global){\n'use strict';\nif (typeof global.Promise !== 'function') {\n global.Promise = _dereq_(2);\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"2\":2}],4:[function(_dereq_,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction getIDB() {\n /* global indexedDB,webkitIndexedDB,mozIndexedDB,OIndexedDB,msIndexedDB */\n try {\n if (typeof indexedDB !== 'undefined') {\n return indexedDB;\n }\n if (typeof webkitIndexedDB !== 'undefined') {\n return webkitIndexedDB;\n }\n if (typeof mozIndexedDB !== 'undefined') {\n return mozIndexedDB;\n }\n if (typeof OIndexedDB !== 'undefined') {\n return OIndexedDB;\n }\n if (typeof msIndexedDB !== 'undefined') {\n return msIndexedDB;\n }\n } catch (e) {\n return;\n }\n}\n\nvar idb = getIDB();\n\nfunction isIndexedDBValid() {\n try {\n // Initialize IndexedDB; fall back to vendor-prefixed versions\n // if needed.\n if (!idb) {\n return false;\n }\n // We mimic PouchDB here;\n //\n // We test for openDatabase because IE Mobile identifies itself\n // as Safari. Oh the lulz...\n var isSafari = typeof openDatabase !== 'undefined' && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform);\n\n var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1;\n\n // Safari <10.1 does not meet our requirements for IDB support (#5572)\n // since Safari 10.1 shipped with fetch, we can use that to detect it\n return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' &&\n // some outdated implementations of IDB that appear on Samsung\n // and HTC Android devices <4.4 are missing IDBKeyRange\n // See: https://github.com/mozilla/localForage/issues/128\n // See: https://github.com/mozilla/localForage/issues/272\n typeof IDBKeyRange !== 'undefined';\n } catch (e) {\n return false;\n }\n}\n\n// Abstracts constructing a Blob object, so it also works in older\n// browsers that don't support the native Blob constructor. (i.e.\n// old QtWebKit versions, at least).\n// Abstracts constructing a Blob object, so it also works in older\n// browsers that don't support the native Blob constructor. (i.e.\n// old QtWebKit versions, at least).\nfunction createBlob(parts, properties) {\n /* global BlobBuilder,MSBlobBuilder,MozBlobBuilder,WebKitBlobBuilder */\n parts = parts || [];\n properties = properties || {};\n try {\n return new Blob(parts, properties);\n } catch (e) {\n if (e.name !== 'TypeError') {\n throw e;\n }\n var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : WebKitBlobBuilder;\n var builder = new Builder();\n for (var i = 0; i < parts.length; i += 1) {\n builder.append(parts[i]);\n }\n return builder.getBlob(properties.type);\n }\n}\n\n// This is CommonJS because lie is an external dependency, so Rollup\n// can just ignore it.\nif (typeof Promise === 'undefined') {\n // In the \"nopromises\" build this will just throw if you don't have\n // a global promise object, but it would throw anyway later.\n _dereq_(3);\n}\nvar Promise$1 = Promise;\n\nfunction executeCallback(promise, callback) {\n if (callback) {\n promise.then(function (result) {\n callback(null, result);\n }, function (error) {\n callback(error);\n });\n }\n}\n\nfunction executeTwoCallbacks(promise, callback, errorCallback) {\n if (typeof callback === 'function') {\n promise.then(callback);\n }\n\n if (typeof errorCallback === 'function') {\n promise[\"catch\"](errorCallback);\n }\n}\n\nfunction normalizeKey(key) {\n // Cast the key to a string, as that's all we can set as a key.\n if (typeof key !== 'string') {\n console.warn(key + ' used as a key, but it is not a string.');\n key = String(key);\n }\n\n return key;\n}\n\nfunction getCallback() {\n if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {\n return arguments[arguments.length - 1];\n }\n}\n\n// Some code originally from async_storage.js in\n// [Gaia](https://github.com/mozilla-b2g/gaia).\n\nvar DETECT_BLOB_SUPPORT_STORE = 'local-forage-detect-blob-support';\nvar supportsBlobs = void 0;\nvar dbContexts = {};\nvar toString = Object.prototype.toString;\n\n// Transaction Modes\nvar READ_ONLY = 'readonly';\nvar READ_WRITE = 'readwrite';\n\n// Transform a binary string to an array buffer, because otherwise\n// weird stuff happens when you try to work with the binary string directly.\n// It is known.\n// From http://stackoverflow.com/questions/14967647/ (continues on next line)\n// encode-decode-image-with-base64-breaks-image (2013-04-21)\nfunction _binStringToArrayBuffer(bin) {\n var length = bin.length;\n var buf = new ArrayBuffer(length);\n var arr = new Uint8Array(buf);\n for (var i = 0; i < length; i++) {\n arr[i] = bin.charCodeAt(i);\n }\n return buf;\n}\n\n//\n// Blobs are not supported in all versions of IndexedDB, notably\n// Chrome <37 and Android <5. In those versions, storing a blob will throw.\n//\n// Various other blob bugs exist in Chrome v37-42 (inclusive).\n// Detecting them is expensive and confusing to users, and Chrome 37-42\n// is at very low usage worldwide, so we do a hacky userAgent check instead.\n//\n// content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120\n// 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916\n// FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836\n//\n// Code borrowed from PouchDB. See:\n// https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-adapter-idb/src/blobSupport.js\n//\nfunction _checkBlobSupportWithoutCaching(idb) {\n return new Promise$1(function (resolve) {\n var txn = idb.transaction(DETECT_BLOB_SUPPORT_STORE, READ_WRITE);\n var blob = createBlob(['']);\n txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key');\n\n txn.onabort = function (e) {\n // If the transaction aborts now its due to not being able to\n // write to the database, likely due to the disk being full\n e.preventDefault();\n e.stopPropagation();\n resolve(false);\n };\n\n txn.oncomplete = function () {\n var matchedChrome = navigator.userAgent.match(/Chrome\\/(\\d+)/);\n var matchedEdge = navigator.userAgent.match(/Edge\\//);\n // MS Edge pretends to be Chrome 42:\n // https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx\n resolve(matchedEdge || !matchedChrome || parseInt(matchedChrome[1], 10) >= 43);\n };\n })[\"catch\"](function () {\n return false; // error, so assume unsupported\n });\n}\n\nfunction _checkBlobSupport(idb) {\n if (typeof supportsBlobs === 'boolean') {\n return Promise$1.resolve(supportsBlobs);\n }\n return _checkBlobSupportWithoutCaching(idb).then(function (value) {\n supportsBlobs = value;\n return supportsBlobs;\n });\n}\n\nfunction _deferReadiness(dbInfo) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Create a deferred object representing the current database operation.\n var deferredOperation = {};\n\n deferredOperation.promise = new Promise$1(function (resolve, reject) {\n deferredOperation.resolve = resolve;\n deferredOperation.reject = reject;\n });\n\n // Enqueue the deferred operation.\n dbContext.deferredOperations.push(deferredOperation);\n\n // Chain its promise to the database readiness.\n if (!dbContext.dbReady) {\n dbContext.dbReady = deferredOperation.promise;\n } else {\n dbContext.dbReady = dbContext.dbReady.then(function () {\n return deferredOperation.promise;\n });\n }\n}\n\nfunction _advanceReadiness(dbInfo) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Dequeue a deferred operation.\n var deferredOperation = dbContext.deferredOperations.pop();\n\n // Resolve its promise (which is part of the database readiness\n // chain of promises).\n if (deferredOperation) {\n deferredOperation.resolve();\n return deferredOperation.promise;\n }\n}\n\nfunction _rejectReadiness(dbInfo, err) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Dequeue a deferred operation.\n var deferredOperation = dbContext.deferredOperations.pop();\n\n // Reject its promise (which is part of the database readiness\n // chain of promises).\n if (deferredOperation) {\n deferredOperation.reject(err);\n return deferredOperation.promise;\n }\n}\n\nfunction _getConnection(dbInfo, upgradeNeeded) {\n return new Promise$1(function (resolve, reject) {\n dbContexts[dbInfo.name] = dbContexts[dbInfo.name] || createDbContext();\n\n if (dbInfo.db) {\n if (upgradeNeeded) {\n _deferReadiness(dbInfo);\n dbInfo.db.close();\n } else {\n return resolve(dbInfo.db);\n }\n }\n\n var dbArgs = [dbInfo.name];\n\n if (upgradeNeeded) {\n dbArgs.push(dbInfo.version);\n }\n\n var openreq = idb.open.apply(idb, dbArgs);\n\n if (upgradeNeeded) {\n openreq.onupgradeneeded = function (e) {\n var db = openreq.result;\n try {\n db.createObjectStore(dbInfo.storeName);\n if (e.oldVersion <= 1) {\n // Added when support for blob shims was added\n db.createObjectStore(DETECT_BLOB_SUPPORT_STORE);\n }\n } catch (ex) {\n if (ex.name === 'ConstraintError') {\n console.warn('The database \"' + dbInfo.name + '\"' + ' has been upgraded from version ' + e.oldVersion + ' to version ' + e.newVersion + ', but the storage \"' + dbInfo.storeName + '\" already exists.');\n } else {\n throw ex;\n }\n }\n };\n }\n\n openreq.onerror = function (e) {\n e.preventDefault();\n reject(openreq.error);\n };\n\n openreq.onsuccess = function () {\n resolve(openreq.result);\n _advanceReadiness(dbInfo);\n };\n });\n}\n\nfunction _getOriginalConnection(dbInfo) {\n return _getConnection(dbInfo, false);\n}\n\nfunction _getUpgradedConnection(dbInfo) {\n return _getConnection(dbInfo, true);\n}\n\nfunction _isUpgradeNeeded(dbInfo, defaultVersion) {\n if (!dbInfo.db) {\n return true;\n }\n\n var isNewStore = !dbInfo.db.objectStoreNames.contains(dbInfo.storeName);\n var isDowngrade = dbInfo.version < dbInfo.db.version;\n var isUpgrade = dbInfo.version > dbInfo.db.version;\n\n if (isDowngrade) {\n // If the version is not the default one\n // then warn for impossible downgrade.\n if (dbInfo.version !== defaultVersion) {\n console.warn('The database \"' + dbInfo.name + '\"' + \" can't be downgraded from version \" + dbInfo.db.version + ' to version ' + dbInfo.version + '.');\n }\n // Align the versions to prevent errors.\n dbInfo.version = dbInfo.db.version;\n }\n\n if (isUpgrade || isNewStore) {\n // If the store is new then increment the version (if needed).\n // This will trigger an \"upgradeneeded\" event which is required\n // for creating a store.\n if (isNewStore) {\n var incVersion = dbInfo.db.version + 1;\n if (incVersion > dbInfo.version) {\n dbInfo.version = incVersion;\n }\n }\n\n return true;\n }\n\n return false;\n}\n\n// encode a blob for indexeddb engines that don't support blobs\nfunction _encodeBlob(blob) {\n return new Promise$1(function (resolve, reject) {\n var reader = new FileReader();\n reader.onerror = reject;\n reader.onloadend = function (e) {\n var base64 = btoa(e.target.result || '');\n resolve({\n __local_forage_encoded_blob: true,\n data: base64,\n type: blob.type\n });\n };\n reader.readAsBinaryString(blob);\n });\n}\n\n// decode an encoded blob\nfunction _decodeBlob(encodedBlob) {\n var arrayBuff = _binStringToArrayBuffer(atob(encodedBlob.data));\n return createBlob([arrayBuff], { type: encodedBlob.type });\n}\n\n// is this one of our fancy encoded blobs?\nfunction _isEncodedBlob(value) {\n return value && value.__local_forage_encoded_blob;\n}\n\n// Specialize the default `ready()` function by making it dependent\n// on the current database operations. Thus, the driver will be actually\n// ready when it's been initialized (default) *and* there are no pending\n// operations on the database (initiated by some other instances).\nfunction _fullyReady(callback) {\n var self = this;\n\n var promise = self._initReady().then(function () {\n var dbContext = dbContexts[self._dbInfo.name];\n\n if (dbContext && dbContext.dbReady) {\n return dbContext.dbReady;\n }\n });\n\n executeTwoCallbacks(promise, callback, callback);\n return promise;\n}\n\n// Try to establish a new db connection to replace the\n// current one which is broken (i.e. experiencing\n// InvalidStateError while creating a transaction).\nfunction _tryReconnect(dbInfo) {\n _deferReadiness(dbInfo);\n\n var dbContext = dbContexts[dbInfo.name];\n var forages = dbContext.forages;\n\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n if (forage._dbInfo.db) {\n forage._dbInfo.db.close();\n forage._dbInfo.db = null;\n }\n }\n dbInfo.db = null;\n\n return _getOriginalConnection(dbInfo).then(function (db) {\n dbInfo.db = db;\n if (_isUpgradeNeeded(dbInfo)) {\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n return db;\n }).then(function (db) {\n // store the latest db reference\n // in case the db was upgraded\n dbInfo.db = dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n forages[i]._dbInfo.db = db;\n }\n })[\"catch\"](function (err) {\n _rejectReadiness(dbInfo, err);\n throw err;\n });\n}\n\n// FF doesn't like Promises (micro-tasks) and IDDB store operations,\n// so we have to do it with callbacks\nfunction createTransaction(dbInfo, mode, callback, retries) {\n if (retries === undefined) {\n retries = 1;\n }\n\n try {\n var tx = dbInfo.db.transaction(dbInfo.storeName, mode);\n callback(null, tx);\n } catch (err) {\n if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) {\n return Promise$1.resolve().then(function () {\n if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) {\n // increase the db version, to create the new ObjectStore\n if (dbInfo.db) {\n dbInfo.version = dbInfo.db.version + 1;\n }\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n }).then(function () {\n return _tryReconnect(dbInfo).then(function () {\n createTransaction(dbInfo, mode, callback, retries - 1);\n });\n })[\"catch\"](callback);\n }\n\n callback(err);\n }\n}\n\nfunction createDbContext() {\n return {\n // Running localForages sharing a database.\n forages: [],\n // Shared database.\n db: null,\n // Database readiness (promise).\n dbReady: null,\n // Deferred operations on the database.\n deferredOperations: []\n };\n}\n\n// Open the IndexedDB database (automatically creates one if one didn't\n// previously exist), using any options set in the config.\nfunction _initStorage(options) {\n var self = this;\n var dbInfo = {\n db: null\n };\n\n if (options) {\n for (var i in options) {\n dbInfo[i] = options[i];\n }\n }\n\n // Get the current context of the database;\n var dbContext = dbContexts[dbInfo.name];\n\n // ...or create a new context.\n if (!dbContext) {\n dbContext = createDbContext();\n // Register the new context in the global container.\n dbContexts[dbInfo.name] = dbContext;\n }\n\n // Register itself as a running localForage in the current context.\n dbContext.forages.push(self);\n\n // Replace the default `ready()` function with the specialized one.\n if (!self._initReady) {\n self._initReady = self.ready;\n self.ready = _fullyReady;\n }\n\n // Create an array of initialization states of the related localForages.\n var initPromises = [];\n\n function ignoreErrors() {\n // Don't handle errors here,\n // just makes sure related localForages aren't pending.\n return Promise$1.resolve();\n }\n\n for (var j = 0; j < dbContext.forages.length; j++) {\n var forage = dbContext.forages[j];\n if (forage !== self) {\n // Don't wait for itself...\n initPromises.push(forage._initReady()[\"catch\"](ignoreErrors));\n }\n }\n\n // Take a snapshot of the related localForages.\n var forages = dbContext.forages.slice(0);\n\n // Initialize the connection process only when\n // all the related localForages aren't pending.\n return Promise$1.all(initPromises).then(function () {\n dbInfo.db = dbContext.db;\n // Get the connection or open a new one without upgrade.\n return _getOriginalConnection(dbInfo);\n }).then(function (db) {\n dbInfo.db = db;\n if (_isUpgradeNeeded(dbInfo, self._defaultConfig.version)) {\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n return db;\n }).then(function (db) {\n dbInfo.db = dbContext.db = db;\n self._dbInfo = dbInfo;\n // Share the final connection amongst related localForages.\n for (var k = 0; k < forages.length; k++) {\n var forage = forages[k];\n if (forage !== self) {\n // Self is already up-to-date.\n forage._dbInfo.db = dbInfo.db;\n forage._dbInfo.version = dbInfo.version;\n }\n }\n });\n}\n\nfunction getItem(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.get(key);\n\n req.onsuccess = function () {\n var value = req.result;\n if (value === undefined) {\n value = null;\n }\n if (_isEncodedBlob(value)) {\n value = _decodeBlob(value);\n }\n resolve(value);\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Iterate over all items stored in database.\nfunction iterate(iterator, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.openCursor();\n var iterationNumber = 1;\n\n req.onsuccess = function () {\n var cursor = req.result;\n\n if (cursor) {\n var value = cursor.value;\n if (_isEncodedBlob(value)) {\n value = _decodeBlob(value);\n }\n var result = iterator(value, cursor.key, iterationNumber++);\n\n // when the iterator callback retuns any\n // (non-`undefined`) value, then we stop\n // the iteration immediately\n if (result !== void 0) {\n resolve(result);\n } else {\n cursor[\"continue\"]();\n }\n } else {\n resolve();\n }\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n\n return promise;\n}\n\nfunction setItem(key, value, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n var dbInfo;\n self.ready().then(function () {\n dbInfo = self._dbInfo;\n if (toString.call(value) === '[object Blob]') {\n return _checkBlobSupport(dbInfo.db).then(function (blobSupport) {\n if (blobSupport) {\n return value;\n }\n return _encodeBlob(value);\n });\n }\n return value;\n }).then(function (value) {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n\n // The reason we don't _save_ null is because IE 10 does\n // not support saving the `null` type in IndexedDB. How\n // ironic, given the bug below!\n // See: https://github.com/mozilla/localForage/issues/161\n if (value === null) {\n value = undefined;\n }\n\n var req = store.put(value, key);\n\n transaction.oncomplete = function () {\n // Cast to undefined so the value passed to\n // callback/promise is the same as what one would get out\n // of `getItem()` later. This leads to some weirdness\n // (setItem('foo', undefined) will return `null`), but\n // it's not my fault localStorage is our baseline and that\n // it's weird.\n if (value === undefined) {\n value = null;\n }\n\n resolve(value);\n };\n transaction.onabort = transaction.onerror = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction removeItem(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n // We use a Grunt task to make this safe for IE and some\n // versions of Android (including those used by Cordova).\n // Normally IE won't like `.delete()` and will insist on\n // using `['delete']()`, but we have a build step that\n // fixes this for us now.\n var req = store[\"delete\"](key);\n transaction.oncomplete = function () {\n resolve();\n };\n\n transaction.onerror = function () {\n reject(req.error);\n };\n\n // The request will be also be aborted if we've exceeded our storage\n // space.\n transaction.onabort = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction clear(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.clear();\n\n transaction.oncomplete = function () {\n resolve();\n };\n\n transaction.onabort = transaction.onerror = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction length(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.count();\n\n req.onsuccess = function () {\n resolve(req.result);\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction key(n, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n if (n < 0) {\n resolve(null);\n\n return;\n }\n\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var advanced = false;\n var req = store.openCursor();\n\n req.onsuccess = function () {\n var cursor = req.result;\n if (!cursor) {\n // this means there weren't enough keys\n resolve(null);\n\n return;\n }\n\n if (n === 0) {\n // We have the first key, return it if that's what they\n // wanted.\n resolve(cursor.key);\n } else {\n if (!advanced) {\n // Otherwise, ask the cursor to skip ahead n\n // records.\n advanced = true;\n cursor.advance(n);\n } else {\n // When we get here, we've got the nth key.\n resolve(cursor.key);\n }\n }\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.openCursor();\n var keys = [];\n\n req.onsuccess = function () {\n var cursor = req.result;\n\n if (!cursor) {\n resolve(keys);\n return;\n }\n\n keys.push(cursor.key);\n cursor[\"continue\"]();\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction dropInstance(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n var currentConfig = this.config();\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n var isCurrentDb = options.name === currentConfig.name && self._dbInfo.db;\n\n var dbPromise = isCurrentDb ? Promise$1.resolve(self._dbInfo.db) : _getOriginalConnection(options).then(function (db) {\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n forages[i]._dbInfo.db = db;\n }\n return db;\n });\n\n if (!options.storeName) {\n promise = dbPromise.then(function (db) {\n _deferReadiness(options);\n\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n\n db.close();\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n forage._dbInfo.db = null;\n }\n\n var dropDBPromise = new Promise$1(function (resolve, reject) {\n var req = idb.deleteDatabase(options.name);\n\n req.onerror = req.onblocked = function (err) {\n var db = req.result;\n if (db) {\n db.close();\n }\n reject(err);\n };\n\n req.onsuccess = function () {\n var db = req.result;\n if (db) {\n db.close();\n }\n resolve(db);\n };\n });\n\n return dropDBPromise.then(function (db) {\n dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n var _forage = forages[i];\n _advanceReadiness(_forage._dbInfo);\n }\n })[\"catch\"](function (err) {\n (_rejectReadiness(options, err) || Promise$1.resolve())[\"catch\"](function () {});\n throw err;\n });\n });\n } else {\n promise = dbPromise.then(function (db) {\n if (!db.objectStoreNames.contains(options.storeName)) {\n return;\n }\n\n var newVersion = db.version + 1;\n\n _deferReadiness(options);\n\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n\n db.close();\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n forage._dbInfo.db = null;\n forage._dbInfo.version = newVersion;\n }\n\n var dropObjectPromise = new Promise$1(function (resolve, reject) {\n var req = idb.open(options.name, newVersion);\n\n req.onerror = function (err) {\n var db = req.result;\n db.close();\n reject(err);\n };\n\n req.onupgradeneeded = function () {\n var db = req.result;\n db.deleteObjectStore(options.storeName);\n };\n\n req.onsuccess = function () {\n var db = req.result;\n db.close();\n resolve(db);\n };\n });\n\n return dropObjectPromise.then(function (db) {\n dbContext.db = db;\n for (var j = 0; j < forages.length; j++) {\n var _forage2 = forages[j];\n _forage2._dbInfo.db = db;\n _advanceReadiness(_forage2._dbInfo);\n }\n })[\"catch\"](function (err) {\n (_rejectReadiness(options, err) || Promise$1.resolve())[\"catch\"](function () {});\n throw err;\n });\n });\n }\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar asyncStorage = {\n _driver: 'asyncStorage',\n _initStorage: _initStorage,\n _support: isIndexedDBValid(),\n iterate: iterate,\n getItem: getItem,\n setItem: setItem,\n removeItem: removeItem,\n clear: clear,\n length: length,\n key: key,\n keys: keys,\n dropInstance: dropInstance\n};\n\nfunction isWebSQLValid() {\n return typeof openDatabase === 'function';\n}\n\n// Sadly, the best way to save binary data in WebSQL/localStorage is serializing\n// it to Base64, so this is how we store it to prevent very strange errors with less\n// verbose ways of binary <-> string data storage.\nvar BASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nvar BLOB_TYPE_PREFIX = '~~local_forage_type~';\nvar BLOB_TYPE_PREFIX_REGEX = /^~~local_forage_type~([^~]+)~/;\n\nvar SERIALIZED_MARKER = '__lfsc__:';\nvar SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER.length;\n\n// OMG the serializations!\nvar TYPE_ARRAYBUFFER = 'arbf';\nvar TYPE_BLOB = 'blob';\nvar TYPE_INT8ARRAY = 'si08';\nvar TYPE_UINT8ARRAY = 'ui08';\nvar TYPE_UINT8CLAMPEDARRAY = 'uic8';\nvar TYPE_INT16ARRAY = 'si16';\nvar TYPE_INT32ARRAY = 'si32';\nvar TYPE_UINT16ARRAY = 'ur16';\nvar TYPE_UINT32ARRAY = 'ui32';\nvar TYPE_FLOAT32ARRAY = 'fl32';\nvar TYPE_FLOAT64ARRAY = 'fl64';\nvar TYPE_SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER_LENGTH + TYPE_ARRAYBUFFER.length;\n\nvar toString$1 = Object.prototype.toString;\n\nfunction stringToBuffer(serializedString) {\n // Fill the string into a ArrayBuffer.\n var bufferLength = serializedString.length * 0.75;\n var len = serializedString.length;\n var i;\n var p = 0;\n var encoded1, encoded2, encoded3, encoded4;\n\n if (serializedString[serializedString.length - 1] === '=') {\n bufferLength--;\n if (serializedString[serializedString.length - 2] === '=') {\n bufferLength--;\n }\n }\n\n var buffer = new ArrayBuffer(bufferLength);\n var bytes = new Uint8Array(buffer);\n\n for (i = 0; i < len; i += 4) {\n encoded1 = BASE_CHARS.indexOf(serializedString[i]);\n encoded2 = BASE_CHARS.indexOf(serializedString[i + 1]);\n encoded3 = BASE_CHARS.indexOf(serializedString[i + 2]);\n encoded4 = BASE_CHARS.indexOf(serializedString[i + 3]);\n\n /*jslint bitwise: true */\n bytes[p++] = encoded1 << 2 | encoded2 >> 4;\n bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;\n bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;\n }\n return buffer;\n}\n\n// Converts a buffer to a string to store, serialized, in the backend\n// storage library.\nfunction bufferToString(buffer) {\n // base64-arraybuffer\n var bytes = new Uint8Array(buffer);\n var base64String = '';\n var i;\n\n for (i = 0; i < bytes.length; i += 3) {\n /*jslint bitwise: true */\n base64String += BASE_CHARS[bytes[i] >> 2];\n base64String += BASE_CHARS[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4];\n base64String += BASE_CHARS[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6];\n base64String += BASE_CHARS[bytes[i + 2] & 63];\n }\n\n if (bytes.length % 3 === 2) {\n base64String = base64String.substring(0, base64String.length - 1) + '=';\n } else if (bytes.length % 3 === 1) {\n base64String = base64String.substring(0, base64String.length - 2) + '==';\n }\n\n return base64String;\n}\n\n// Serialize a value, afterwards executing a callback (which usually\n// instructs the `setItem()` callback/promise to be executed). This is how\n// we store binary data with localStorage.\nfunction serialize(value, callback) {\n var valueType = '';\n if (value) {\n valueType = toString$1.call(value);\n }\n\n // Cannot use `value instanceof ArrayBuffer` or such here, as these\n // checks fail when running the tests using casper.js...\n //\n // TODO: See why those tests fail and use a better solution.\n if (value && (valueType === '[object ArrayBuffer]' || value.buffer && toString$1.call(value.buffer) === '[object ArrayBuffer]')) {\n // Convert binary arrays to a string and prefix the string with\n // a special marker.\n var buffer;\n var marker = SERIALIZED_MARKER;\n\n if (value instanceof ArrayBuffer) {\n buffer = value;\n marker += TYPE_ARRAYBUFFER;\n } else {\n buffer = value.buffer;\n\n if (valueType === '[object Int8Array]') {\n marker += TYPE_INT8ARRAY;\n } else if (valueType === '[object Uint8Array]') {\n marker += TYPE_UINT8ARRAY;\n } else if (valueType === '[object Uint8ClampedArray]') {\n marker += TYPE_UINT8CLAMPEDARRAY;\n } else if (valueType === '[object Int16Array]') {\n marker += TYPE_INT16ARRAY;\n } else if (valueType === '[object Uint16Array]') {\n marker += TYPE_UINT16ARRAY;\n } else if (valueType === '[object Int32Array]') {\n marker += TYPE_INT32ARRAY;\n } else if (valueType === '[object Uint32Array]') {\n marker += TYPE_UINT32ARRAY;\n } else if (valueType === '[object Float32Array]') {\n marker += TYPE_FLOAT32ARRAY;\n } else if (valueType === '[object Float64Array]') {\n marker += TYPE_FLOAT64ARRAY;\n } else {\n callback(new Error('Failed to get type for BinaryArray'));\n }\n }\n\n callback(marker + bufferToString(buffer));\n } else if (valueType === '[object Blob]') {\n // Conver the blob to a binaryArray and then to a string.\n var fileReader = new FileReader();\n\n fileReader.onload = function () {\n // Backwards-compatible prefix for the blob type.\n var str = BLOB_TYPE_PREFIX + value.type + '~' + bufferToString(this.result);\n\n callback(SERIALIZED_MARKER + TYPE_BLOB + str);\n };\n\n fileReader.readAsArrayBuffer(value);\n } else {\n try {\n callback(JSON.stringify(value));\n } catch (e) {\n console.error(\"Couldn't convert value into a JSON string: \", value);\n\n callback(null, e);\n }\n }\n}\n\n// Deserialize data we've inserted into a value column/field. We place\n// special markers into our strings to mark them as encoded; this isn't\n// as nice as a meta field, but it's the only sane thing we can do whilst\n// keeping localStorage support intact.\n//\n// Oftentimes this will just deserialize JSON content, but if we have a\n// special marker (SERIALIZED_MARKER, defined above), we will extract\n// some kind of arraybuffer/binary data/typed array out of the string.\nfunction deserialize(value) {\n // If we haven't marked this string as being specially serialized (i.e.\n // something other than serialized JSON), we can just return it and be\n // done with it.\n if (value.substring(0, SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) {\n return JSON.parse(value);\n }\n\n // The following code deals with deserializing some kind of Blob or\n // TypedArray. First we separate out the type of data we're dealing\n // with from the data itself.\n var serializedString = value.substring(TYPE_SERIALIZED_MARKER_LENGTH);\n var type = value.substring(SERIALIZED_MARKER_LENGTH, TYPE_SERIALIZED_MARKER_LENGTH);\n\n var blobType;\n // Backwards-compatible blob type serialization strategy.\n // DBs created with older versions of localForage will simply not have the blob type.\n if (type === TYPE_BLOB && BLOB_TYPE_PREFIX_REGEX.test(serializedString)) {\n var matcher = serializedString.match(BLOB_TYPE_PREFIX_REGEX);\n blobType = matcher[1];\n serializedString = serializedString.substring(matcher[0].length);\n }\n var buffer = stringToBuffer(serializedString);\n\n // Return the right type based on the code/type set during\n // serialization.\n switch (type) {\n case TYPE_ARRAYBUFFER:\n return buffer;\n case TYPE_BLOB:\n return createBlob([buffer], { type: blobType });\n case TYPE_INT8ARRAY:\n return new Int8Array(buffer);\n case TYPE_UINT8ARRAY:\n return new Uint8Array(buffer);\n case TYPE_UINT8CLAMPEDARRAY:\n return new Uint8ClampedArray(buffer);\n case TYPE_INT16ARRAY:\n return new Int16Array(buffer);\n case TYPE_UINT16ARRAY:\n return new Uint16Array(buffer);\n case TYPE_INT32ARRAY:\n return new Int32Array(buffer);\n case TYPE_UINT32ARRAY:\n return new Uint32Array(buffer);\n case TYPE_FLOAT32ARRAY:\n return new Float32Array(buffer);\n case TYPE_FLOAT64ARRAY:\n return new Float64Array(buffer);\n default:\n throw new Error('Unkown type: ' + type);\n }\n}\n\nvar localforageSerializer = {\n serialize: serialize,\n deserialize: deserialize,\n stringToBuffer: stringToBuffer,\n bufferToString: bufferToString\n};\n\n/*\n * Includes code from:\n *\n * base64-arraybuffer\n * https://github.com/niklasvh/base64-arraybuffer\n *\n * Copyright (c) 2012 Niklas von Hertzen\n * Licensed under the MIT license.\n */\n\nfunction createDbTable(t, dbInfo, callback, errorCallback) {\n t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' ' + '(id INTEGER PRIMARY KEY, key unique, value)', [], callback, errorCallback);\n}\n\n// Open the WebSQL database (automatically creates one if one didn't\n// previously exist), using any options set in the config.\nfunction _initStorage$1(options) {\n var self = this;\n var dbInfo = {\n db: null\n };\n\n if (options) {\n for (var i in options) {\n dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];\n }\n }\n\n var dbInfoPromise = new Promise$1(function (resolve, reject) {\n // Open the database; the openDatabase API will automatically\n // create it for us if it doesn't exist.\n try {\n dbInfo.db = openDatabase(dbInfo.name, String(dbInfo.version), dbInfo.description, dbInfo.size);\n } catch (e) {\n return reject(e);\n }\n\n // Create our key/value table if it doesn't exist.\n dbInfo.db.transaction(function (t) {\n createDbTable(t, dbInfo, function () {\n self._dbInfo = dbInfo;\n resolve();\n }, function (t, error) {\n reject(error);\n });\n }, reject);\n });\n\n dbInfo.serializer = localforageSerializer;\n return dbInfoPromise;\n}\n\nfunction tryExecuteSql(t, dbInfo, sqlStatement, args, callback, errorCallback) {\n t.executeSql(sqlStatement, args, callback, function (t, error) {\n if (error.code === error.SYNTAX_ERR) {\n t.executeSql('SELECT name FROM sqlite_master ' + \"WHERE type='table' AND name = ?\", [dbInfo.storeName], function (t, results) {\n if (!results.rows.length) {\n // if the table is missing (was deleted)\n // re-create it table and retry\n createDbTable(t, dbInfo, function () {\n t.executeSql(sqlStatement, args, callback, errorCallback);\n }, errorCallback);\n } else {\n errorCallback(t, error);\n }\n }, errorCallback);\n } else {\n errorCallback(t, error);\n }\n }, errorCallback);\n}\n\nfunction getItem$1(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName + ' WHERE key = ? LIMIT 1', [key], function (t, results) {\n var result = results.rows.length ? results.rows.item(0).value : null;\n\n // Check to see if this is serialized content we need to\n // unpack.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction iterate$1(iterator, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName, [], function (t, results) {\n var rows = results.rows;\n var length = rows.length;\n\n for (var i = 0; i < length; i++) {\n var item = rows.item(i);\n var result = item.value;\n\n // Check to see if this is serialized content\n // we need to unpack.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n result = iterator(result, item.key, i + 1);\n\n // void(0) prevents problems with redefinition\n // of `undefined`.\n if (result !== void 0) {\n resolve(result);\n return;\n }\n }\n\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction _setItem(key, value, callback, retriesLeft) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n // The localStorage API doesn't return undefined values in an\n // \"expected\" way, so undefined is always cast to null in all\n // drivers. See: https://github.com/mozilla/localForage/pull/42\n if (value === undefined) {\n value = null;\n }\n\n // Save the original value to pass to the callback.\n var originalValue = value;\n\n var dbInfo = self._dbInfo;\n dbInfo.serializer.serialize(value, function (value, error) {\n if (error) {\n reject(error);\n } else {\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'INSERT OR REPLACE INTO ' + dbInfo.storeName + ' ' + '(key, value) VALUES (?, ?)', [key, value], function () {\n resolve(originalValue);\n }, function (t, error) {\n reject(error);\n });\n }, function (sqlError) {\n // The transaction failed; check\n // to see if it's a quota error.\n if (sqlError.code === sqlError.QUOTA_ERR) {\n // We reject the callback outright for now, but\n // it's worth trying to re-run the transaction.\n // Even if the user accepts the prompt to use\n // more storage on Safari, this error will\n // be called.\n //\n // Try to re-run the transaction.\n if (retriesLeft > 0) {\n resolve(_setItem.apply(self, [key, originalValue, callback, retriesLeft - 1]));\n return;\n }\n reject(sqlError);\n }\n });\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction setItem$1(key, value, callback) {\n return _setItem.apply(this, [key, value, callback, 1]);\n}\n\nfunction removeItem$1(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Deletes every item in the table.\n// TODO: Find out if this resets the AUTO_INCREMENT number.\nfunction clear$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName, [], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Does a simple `COUNT(key)` to get the number of items stored in\n// localForage.\nfunction length$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n // Ahhh, SQL makes this one soooooo easy.\n tryExecuteSql(t, dbInfo, 'SELECT COUNT(key) as c FROM ' + dbInfo.storeName, [], function (t, results) {\n var result = results.rows.item(0).c;\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Return the key located at key index X; essentially gets the key from a\n// `WHERE id = ?`. This is the most efficient way I can think to implement\n// this rarely-used (in my experience) part of the API, but it can seem\n// inconsistent, because we do `INSERT OR REPLACE INTO` on `setItem()`, so\n// the ID of each key will change every time it's updated. Perhaps a stored\n// procedure for the `setItem()` SQL would solve this problem?\n// TODO: Don't change ID on `setItem()`.\nfunction key$1(n, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName + ' WHERE id = ? LIMIT 1', [n + 1], function (t, results) {\n var result = results.rows.length ? results.rows.item(0).key : null;\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName, [], function (t, results) {\n var keys = [];\n\n for (var i = 0; i < results.rows.length; i++) {\n keys.push(results.rows.item(i).key);\n }\n\n resolve(keys);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// https://www.w3.org/TR/webdatabase/#databases\n// > There is no way to enumerate or delete the databases available for an origin from this API.\nfunction getAllStoreNames(db) {\n return new Promise$1(function (resolve, reject) {\n db.transaction(function (t) {\n t.executeSql('SELECT name FROM sqlite_master ' + \"WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'\", [], function (t, results) {\n var storeNames = [];\n\n for (var i = 0; i < results.rows.length; i++) {\n storeNames.push(results.rows.item(i).name);\n }\n\n resolve({\n db: db,\n storeNames: storeNames\n });\n }, function (t, error) {\n reject(error);\n });\n }, function (sqlError) {\n reject(sqlError);\n });\n });\n}\n\nfunction dropInstance$1(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n var currentConfig = this.config();\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n promise = new Promise$1(function (resolve) {\n var db;\n if (options.name === currentConfig.name) {\n // use the db reference of the current instance\n db = self._dbInfo.db;\n } else {\n db = openDatabase(options.name, '', '', 0);\n }\n\n if (!options.storeName) {\n // drop all database tables\n resolve(getAllStoreNames(db));\n } else {\n resolve({\n db: db,\n storeNames: [options.storeName]\n });\n }\n }).then(function (operationInfo) {\n return new Promise$1(function (resolve, reject) {\n operationInfo.db.transaction(function (t) {\n function dropTable(storeName) {\n return new Promise$1(function (resolve, reject) {\n t.executeSql('DROP TABLE IF EXISTS ' + storeName, [], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n }\n\n var operations = [];\n for (var i = 0, len = operationInfo.storeNames.length; i < len; i++) {\n operations.push(dropTable(operationInfo.storeNames[i]));\n }\n\n Promise$1.all(operations).then(function () {\n resolve();\n })[\"catch\"](function (e) {\n reject(e);\n });\n }, function (sqlError) {\n reject(sqlError);\n });\n });\n });\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar webSQLStorage = {\n _driver: 'webSQLStorage',\n _initStorage: _initStorage$1,\n _support: isWebSQLValid(),\n iterate: iterate$1,\n getItem: getItem$1,\n setItem: setItem$1,\n removeItem: removeItem$1,\n clear: clear$1,\n length: length$1,\n key: key$1,\n keys: keys$1,\n dropInstance: dropInstance$1\n};\n\nfunction isLocalStorageValid() {\n try {\n return typeof localStorage !== 'undefined' && 'setItem' in localStorage &&\n // in IE8 typeof localStorage.setItem === 'object'\n !!localStorage.setItem;\n } catch (e) {\n return false;\n }\n}\n\nfunction _getKeyPrefix(options, defaultConfig) {\n var keyPrefix = options.name + '/';\n\n if (options.storeName !== defaultConfig.storeName) {\n keyPrefix += options.storeName + '/';\n }\n return keyPrefix;\n}\n\n// Check if localStorage throws when saving an item\nfunction checkIfLocalStorageThrows() {\n var localStorageTestKey = '_localforage_support_test';\n\n try {\n localStorage.setItem(localStorageTestKey, true);\n localStorage.removeItem(localStorageTestKey);\n\n return false;\n } catch (e) {\n return true;\n }\n}\n\n// Check if localStorage is usable and allows to save an item\n// This method checks if localStorage is usable in Safari Private Browsing\n// mode, or in any other case where the available quota for localStorage\n// is 0 and there wasn't any saved items yet.\nfunction _isLocalStorageUsable() {\n return !checkIfLocalStorageThrows() || localStorage.length > 0;\n}\n\n// Config the localStorage backend, using options set in the config.\nfunction _initStorage$2(options) {\n var self = this;\n var dbInfo = {};\n if (options) {\n for (var i in options) {\n dbInfo[i] = options[i];\n }\n }\n\n dbInfo.keyPrefix = _getKeyPrefix(options, self._defaultConfig);\n\n if (!_isLocalStorageUsable()) {\n return Promise$1.reject();\n }\n\n self._dbInfo = dbInfo;\n dbInfo.serializer = localforageSerializer;\n\n return Promise$1.resolve();\n}\n\n// Remove all keys from the datastore, effectively destroying all data in\n// the app's key/value store!\nfunction clear$2(callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var keyPrefix = self._dbInfo.keyPrefix;\n\n for (var i = localStorage.length - 1; i >= 0; i--) {\n var key = localStorage.key(i);\n\n if (key.indexOf(keyPrefix) === 0) {\n localStorage.removeItem(key);\n }\n }\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Retrieve an item from the store. Unlike the original async_storage\n// library in Gaia, we don't modify return values at all. If a key's value\n// is `undefined`, we pass that value to the callback function.\nfunction getItem$2(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var result = localStorage.getItem(dbInfo.keyPrefix + key);\n\n // If a result was found, parse it from the serialized\n // string into a JS object. If result isn't truthy, the key\n // is likely undefined and we'll pass it straight to the\n // callback.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n return result;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Iterate over all items in the store.\nfunction iterate$2(iterator, callback) {\n var self = this;\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var keyPrefix = dbInfo.keyPrefix;\n var keyPrefixLength = keyPrefix.length;\n var length = localStorage.length;\n\n // We use a dedicated iterator instead of the `i` variable below\n // so other keys we fetch in localStorage aren't counted in\n // the `iterationNumber` argument passed to the `iterate()`\n // callback.\n //\n // See: github.com/mozilla/localForage/pull/435#discussion_r38061530\n var iterationNumber = 1;\n\n for (var i = 0; i < length; i++) {\n var key = localStorage.key(i);\n if (key.indexOf(keyPrefix) !== 0) {\n continue;\n }\n var value = localStorage.getItem(key);\n\n // If a result was found, parse it from the serialized\n // string into a JS object. If result isn't truthy, the\n // key is likely undefined and we'll pass it straight\n // to the iterator.\n if (value) {\n value = dbInfo.serializer.deserialize(value);\n }\n\n value = iterator(value, key.substring(keyPrefixLength), iterationNumber++);\n\n if (value !== void 0) {\n return value;\n }\n }\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Same as localStorage's key() method, except takes a callback.\nfunction key$2(n, callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var result;\n try {\n result = localStorage.key(n);\n } catch (error) {\n result = null;\n }\n\n // Remove the prefix from the key, if a key is found.\n if (result) {\n result = result.substring(dbInfo.keyPrefix.length);\n }\n\n return result;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys$2(callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var length = localStorage.length;\n var keys = [];\n\n for (var i = 0; i < length; i++) {\n var itemKey = localStorage.key(i);\n if (itemKey.indexOf(dbInfo.keyPrefix) === 0) {\n keys.push(itemKey.substring(dbInfo.keyPrefix.length));\n }\n }\n\n return keys;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Supply the number of keys in the datastore to the callback function.\nfunction length$2(callback) {\n var self = this;\n var promise = self.keys().then(function (keys) {\n return keys.length;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Remove an item from the store, nice and simple.\nfunction removeItem$2(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n localStorage.removeItem(dbInfo.keyPrefix + key);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Set a key's value and run an optional callback once the value is set.\n// Unlike Gaia's implementation, the callback function is passed the value,\n// in case you want to operate on that value only after you're sure it\n// saved, or something like that.\nfunction setItem$2(key, value, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n // Convert undefined values to null.\n // https://github.com/mozilla/localForage/pull/42\n if (value === undefined) {\n value = null;\n }\n\n // Save the original value to pass to the callback.\n var originalValue = value;\n\n return new Promise$1(function (resolve, reject) {\n var dbInfo = self._dbInfo;\n dbInfo.serializer.serialize(value, function (value, error) {\n if (error) {\n reject(error);\n } else {\n try {\n localStorage.setItem(dbInfo.keyPrefix + key, value);\n resolve(originalValue);\n } catch (e) {\n // localStorage capacity exceeded.\n // TODO: Make this a specific error/event.\n if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {\n reject(e);\n }\n reject(e);\n }\n }\n });\n });\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction dropInstance$2(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n var currentConfig = this.config();\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n promise = new Promise$1(function (resolve) {\n if (!options.storeName) {\n resolve(options.name + '/');\n } else {\n resolve(_getKeyPrefix(options, self._defaultConfig));\n }\n }).then(function (keyPrefix) {\n for (var i = localStorage.length - 1; i >= 0; i--) {\n var key = localStorage.key(i);\n\n if (key.indexOf(keyPrefix) === 0) {\n localStorage.removeItem(key);\n }\n }\n });\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar localStorageWrapper = {\n _driver: 'localStorageWrapper',\n _initStorage: _initStorage$2,\n _support: isLocalStorageValid(),\n iterate: iterate$2,\n getItem: getItem$2,\n setItem: setItem$2,\n removeItem: removeItem$2,\n clear: clear$2,\n length: length$2,\n key: key$2,\n keys: keys$2,\n dropInstance: dropInstance$2\n};\n\nvar sameValue = function sameValue(x, y) {\n return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);\n};\n\nvar includes = function includes(array, searchElement) {\n var len = array.length;\n var i = 0;\n while (i < len) {\n if (sameValue(array[i], searchElement)) {\n return true;\n }\n i++;\n }\n\n return false;\n};\n\nvar isArray = Array.isArray || function (arg) {\n return Object.prototype.toString.call(arg) === '[object Array]';\n};\n\n// Drivers are stored here when `defineDriver()` is called.\n// They are shared across all instances of localForage.\nvar DefinedDrivers = {};\n\nvar DriverSupport = {};\n\nvar DefaultDrivers = {\n INDEXEDDB: asyncStorage,\n WEBSQL: webSQLStorage,\n LOCALSTORAGE: localStorageWrapper\n};\n\nvar DefaultDriverOrder = [DefaultDrivers.INDEXEDDB._driver, DefaultDrivers.WEBSQL._driver, DefaultDrivers.LOCALSTORAGE._driver];\n\nvar OptionalDriverMethods = ['dropInstance'];\n\nvar LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'].concat(OptionalDriverMethods);\n\nvar DefaultConfig = {\n description: '',\n driver: DefaultDriverOrder.slice(),\n name: 'localforage',\n // Default DB size is _JUST UNDER_ 5MB, as it's the highest size\n // we can use without a prompt.\n size: 4980736,\n storeName: 'keyvaluepairs',\n version: 1.0\n};\n\nfunction callWhenReady(localForageInstance, libraryMethod) {\n localForageInstance[libraryMethod] = function () {\n var _args = arguments;\n return localForageInstance.ready().then(function () {\n return localForageInstance[libraryMethod].apply(localForageInstance, _args);\n });\n };\n}\n\nfunction extend() {\n for (var i = 1; i < arguments.length; i++) {\n var arg = arguments[i];\n\n if (arg) {\n for (var _key in arg) {\n if (arg.hasOwnProperty(_key)) {\n if (isArray(arg[_key])) {\n arguments[0][_key] = arg[_key].slice();\n } else {\n arguments[0][_key] = arg[_key];\n }\n }\n }\n }\n }\n\n return arguments[0];\n}\n\nvar LocalForage = function () {\n function LocalForage(options) {\n _classCallCheck(this, LocalForage);\n\n for (var driverTypeKey in DefaultDrivers) {\n if (DefaultDrivers.hasOwnProperty(driverTypeKey)) {\n var driver = DefaultDrivers[driverTypeKey];\n var driverName = driver._driver;\n this[driverTypeKey] = driverName;\n\n if (!DefinedDrivers[driverName]) {\n // we don't need to wait for the promise,\n // since the default drivers can be defined\n // in a blocking manner\n this.defineDriver(driver);\n }\n }\n }\n\n this._defaultConfig = extend({}, DefaultConfig);\n this._config = extend({}, this._defaultConfig, options);\n this._driverSet = null;\n this._initDriver = null;\n this._ready = false;\n this._dbInfo = null;\n\n this._wrapLibraryMethodsWithReady();\n this.setDriver(this._config.driver)[\"catch\"](function () {});\n }\n\n // Set any config values for localForage; can be called anytime before\n // the first API call (e.g. `getItem`, `setItem`).\n // We loop through options so we don't overwrite existing config\n // values.\n\n\n LocalForage.prototype.config = function config(options) {\n // If the options argument is an object, we use it to set values.\n // Otherwise, we return either a specified config value or all\n // config values.\n if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') {\n // If localforage is ready and fully initialized, we can't set\n // any new configuration values. Instead, we return an error.\n if (this._ready) {\n return new Error(\"Can't call config() after localforage \" + 'has been used.');\n }\n\n for (var i in options) {\n if (i === 'storeName') {\n options[i] = options[i].replace(/\\W/g, '_');\n }\n\n if (i === 'version' && typeof options[i] !== 'number') {\n return new Error('Database version must be a number.');\n }\n\n this._config[i] = options[i];\n }\n\n // after all config options are set and\n // the driver option is used, try setting it\n if ('driver' in options && options.driver) {\n return this.setDriver(this._config.driver);\n }\n\n return true;\n } else if (typeof options === 'string') {\n return this._config[options];\n } else {\n return this._config;\n }\n };\n\n // Used to define a custom driver, shared across all instances of\n // localForage.\n\n\n LocalForage.prototype.defineDriver = function defineDriver(driverObject, callback, errorCallback) {\n var promise = new Promise$1(function (resolve, reject) {\n try {\n var driverName = driverObject._driver;\n var complianceError = new Error('Custom driver not compliant; see ' + 'https://mozilla.github.io/localForage/#definedriver');\n\n // A driver name should be defined and not overlap with the\n // library-defined, default drivers.\n if (!driverObject._driver) {\n reject(complianceError);\n return;\n }\n\n var driverMethods = LibraryMethods.concat('_initStorage');\n for (var i = 0, len = driverMethods.length; i < len; i++) {\n var driverMethodName = driverMethods[i];\n\n // when the property is there,\n // it should be a method even when optional\n var isRequired = !includes(OptionalDriverMethods, driverMethodName);\n if ((isRequired || driverObject[driverMethodName]) && typeof driverObject[driverMethodName] !== 'function') {\n reject(complianceError);\n return;\n }\n }\n\n var configureMissingMethods = function configureMissingMethods() {\n var methodNotImplementedFactory = function methodNotImplementedFactory(methodName) {\n return function () {\n var error = new Error('Method ' + methodName + ' is not implemented by the current driver');\n var promise = Promise$1.reject(error);\n executeCallback(promise, arguments[arguments.length - 1]);\n return promise;\n };\n };\n\n for (var _i = 0, _len = OptionalDriverMethods.length; _i < _len; _i++) {\n var optionalDriverMethod = OptionalDriverMethods[_i];\n if (!driverObject[optionalDriverMethod]) {\n driverObject[optionalDriverMethod] = methodNotImplementedFactory(optionalDriverMethod);\n }\n }\n };\n\n configureMissingMethods();\n\n var setDriverSupport = function setDriverSupport(support) {\n if (DefinedDrivers[driverName]) {\n console.info('Redefining LocalForage driver: ' + driverName);\n }\n DefinedDrivers[driverName] = driverObject;\n DriverSupport[driverName] = support;\n // don't use a then, so that we can define\n // drivers that have simple _support methods\n // in a blocking manner\n resolve();\n };\n\n if ('_support' in driverObject) {\n if (driverObject._support && typeof driverObject._support === 'function') {\n driverObject._support().then(setDriverSupport, reject);\n } else {\n setDriverSupport(!!driverObject._support);\n }\n } else {\n setDriverSupport(true);\n }\n } catch (e) {\n reject(e);\n }\n });\n\n executeTwoCallbacks(promise, callback, errorCallback);\n return promise;\n };\n\n LocalForage.prototype.driver = function driver() {\n return this._driver || null;\n };\n\n LocalForage.prototype.getDriver = function getDriver(driverName, callback, errorCallback) {\n var getDriverPromise = DefinedDrivers[driverName] ? Promise$1.resolve(DefinedDrivers[driverName]) : Promise$1.reject(new Error('Driver not found.'));\n\n executeTwoCallbacks(getDriverPromise, callback, errorCallback);\n return getDriverPromise;\n };\n\n LocalForage.prototype.getSerializer = function getSerializer(callback) {\n var serializerPromise = Promise$1.resolve(localforageSerializer);\n executeTwoCallbacks(serializerPromise, callback);\n return serializerPromise;\n };\n\n LocalForage.prototype.ready = function ready(callback) {\n var self = this;\n\n var promise = self._driverSet.then(function () {\n if (self._ready === null) {\n self._ready = self._initDriver();\n }\n\n return self._ready;\n });\n\n executeTwoCallbacks(promise, callback, callback);\n return promise;\n };\n\n LocalForage.prototype.setDriver = function setDriver(drivers, callback, errorCallback) {\n var self = this;\n\n if (!isArray(drivers)) {\n drivers = [drivers];\n }\n\n var supportedDrivers = this._getSupportedDrivers(drivers);\n\n function setDriverToConfig() {\n self._config.driver = self.driver();\n }\n\n function extendSelfWithDriver(driver) {\n self._extend(driver);\n setDriverToConfig();\n\n self._ready = self._initStorage(self._config);\n return self._ready;\n }\n\n function initDriver(supportedDrivers) {\n return function () {\n var currentDriverIndex = 0;\n\n function driverPromiseLoop() {\n while (currentDriverIndex < supportedDrivers.length) {\n var driverName = supportedDrivers[currentDriverIndex];\n currentDriverIndex++;\n\n self._dbInfo = null;\n self._ready = null;\n\n return self.getDriver(driverName).then(extendSelfWithDriver)[\"catch\"](driverPromiseLoop);\n }\n\n setDriverToConfig();\n var error = new Error('No available storage method found.');\n self._driverSet = Promise$1.reject(error);\n return self._driverSet;\n }\n\n return driverPromiseLoop();\n };\n }\n\n // There might be a driver initialization in progress\n // so wait for it to finish in order to avoid a possible\n // race condition to set _dbInfo\n var oldDriverSetDone = this._driverSet !== null ? this._driverSet[\"catch\"](function () {\n return Promise$1.resolve();\n }) : Promise$1.resolve();\n\n this._driverSet = oldDriverSetDone.then(function () {\n var driverName = supportedDrivers[0];\n self._dbInfo = null;\n self._ready = null;\n\n return self.getDriver(driverName).then(function (driver) {\n self._driver = driver._driver;\n setDriverToConfig();\n self._wrapLibraryMethodsWithReady();\n self._initDriver = initDriver(supportedDrivers);\n });\n })[\"catch\"](function () {\n setDriverToConfig();\n var error = new Error('No available storage method found.');\n self._driverSet = Promise$1.reject(error);\n return self._driverSet;\n });\n\n executeTwoCallbacks(this._driverSet, callback, errorCallback);\n return this._driverSet;\n };\n\n LocalForage.prototype.supports = function supports(driverName) {\n return !!DriverSupport[driverName];\n };\n\n LocalForage.prototype._extend = function _extend(libraryMethodsAndProperties) {\n extend(this, libraryMethodsAndProperties);\n };\n\n LocalForage.prototype._getSupportedDrivers = function _getSupportedDrivers(drivers) {\n var supportedDrivers = [];\n for (var i = 0, len = drivers.length; i < len; i++) {\n var driverName = drivers[i];\n if (this.supports(driverName)) {\n supportedDrivers.push(driverName);\n }\n }\n return supportedDrivers;\n };\n\n LocalForage.prototype._wrapLibraryMethodsWithReady = function _wrapLibraryMethodsWithReady() {\n // Add a stub for each driver API method that delays the call to the\n // corresponding driver method until localForage is ready. These stubs\n // will be replaced by the driver methods as soon as the driver is\n // loaded, so there is no performance impact.\n for (var i = 0, len = LibraryMethods.length; i < len; i++) {\n callWhenReady(this, LibraryMethods[i]);\n }\n };\n\n LocalForage.prototype.createInstance = function createInstance(options) {\n return new LocalForage(options);\n };\n\n return LocalForage;\n}();\n\n// The actual localForage object that we expose as a module or via a\n// global. It's extended by pulling in one of our other libraries.\n\n\nvar localforage_js = new LocalForage();\n\nmodule.exports = localforage_js;\n\n},{\"3\":3}]},{},[4])(4)\n});\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport EventBus from './EventBus';\nimport Events from './events/Events';\nimport FactoryMaker from './FactoryMaker';\n\nconst LOG_LEVEL_NONE = 0;\nconst LOG_LEVEL_FATAL = 1;\nconst LOG_LEVEL_ERROR = 2;\nconst LOG_LEVEL_WARNING = 3;\nconst LOG_LEVEL_INFO = 4;\nconst LOG_LEVEL_DEBUG = 5;\n\n/**\n * @module Debug\n * @param {object} config\n * @ignore\n */\nfunction Debug(config) {\n\n config = config || {};\n const context = this.context;\n const eventBus = EventBus(context).getInstance();\n const settings = config.settings;\n\n const logFn = [];\n\n let instance,\n showLogTimestamp,\n showCalleeName,\n startTime;\n\n function setup() {\n showLogTimestamp = true;\n showCalleeName = true;\n startTime = new Date().getTime();\n\n if (typeof window !== 'undefined' && window.console) {\n logFn[LOG_LEVEL_FATAL] = getLogFn(window.console.error);\n logFn[LOG_LEVEL_ERROR] = getLogFn(window.console.error);\n logFn[LOG_LEVEL_WARNING] = getLogFn(window.console.warn);\n logFn[LOG_LEVEL_INFO] = getLogFn(window.console.info);\n logFn[LOG_LEVEL_DEBUG] = getLogFn(window.console.debug);\n }\n }\n\n function getLogFn(fn) {\n if (fn && fn.bind) {\n return fn.bind(window.console);\n }\n // if not define, return the default function for reporting logs\n return window.console.log.bind(window.console);\n }\n\n /**\n * Retrieves a logger which can be used to write logging information in browser console.\n * @param {object} instance Object for which the logger is created. It is used\n * to include calle object information in log messages.\n * @memberof module:Debug\n * @returns {Logger}\n * @instance\n */\n function getLogger(instance) {\n return {\n fatal: fatal.bind(instance),\n error: error.bind(instance),\n warn: warn.bind(instance),\n info: info.bind(instance),\n debug: debug.bind(instance)\n };\n }\n\n /**\n * Prepends a timestamp in milliseconds to each log message.\n * @param {boolean} value Set to true if you want to see a timestamp in each log message.\n * @default LOG_LEVEL_WARNING\n * @memberof module:Debug\n * @instance\n */\n function setLogTimestampVisible(value) {\n showLogTimestamp = value;\n }\n /**\n * Prepends the callee object name, and media type if available, to each log message.\n * @param {boolean} value Set to true if you want to see the callee object name and media type in each log message.\n * @default true\n * @memberof module:Debug\n * @instance\n */\n function setCalleeNameVisible(value) {\n showCalleeName = value;\n }\n\n function fatal(...params) {\n doLog(LOG_LEVEL_FATAL, this, ...params);\n }\n\n function error(...params) {\n doLog(LOG_LEVEL_ERROR, this, ...params);\n }\n\n function warn(...params) {\n doLog(LOG_LEVEL_WARNING, this, ...params);\n }\n\n function info(...params) {\n doLog(LOG_LEVEL_INFO, this, ...params);\n }\n\n function debug(...params) {\n doLog(LOG_LEVEL_DEBUG, this, ...params);\n }\n\n function doLog(level, _this, ...params) {\n let message = '';\n let logTime = null;\n\n if (showLogTimestamp) {\n logTime = new Date().getTime();\n message += '[' + (logTime - startTime) + ']';\n }\n\n if (showCalleeName && _this && _this.getClassName) {\n message += '[' + _this.getClassName() + ']';\n if (_this.getType) {\n message += '[' + _this.getType() + ']';\n }\n }\n\n if (message.length > 0) {\n message += ' ';\n }\n\n Array.apply(null, params).forEach(function (item) {\n message += item + ' ';\n });\n\n // log to console if the log level is high enough\n if (logFn[level] && settings.get().debug.logLevel >= level) {\n logFn[level](message);\n }\n\n // send log event regardless of log level\n eventBus.trigger(Events.LOG, {message: message, level: level});\n }\n\n instance = {\n getLogger: getLogger,\n setLogTimestampVisible: setLogTimestampVisible,\n setCalleeNameVisible: setCalleeNameVisible\n };\n\n setup();\n\n return instance;\n}\n\nDebug.__dashjs_factory_name = 'Debug';\n\nconst factory = FactoryMaker.getSingletonFactory(Debug);\nfactory.LOG_LEVEL_NONE = LOG_LEVEL_NONE;\nfactory.LOG_LEVEL_FATAL = LOG_LEVEL_FATAL;\nfactory.LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;\nfactory.LOG_LEVEL_WARNING = LOG_LEVEL_WARNING;\nfactory.LOG_LEVEL_INFO = LOG_LEVEL_INFO;\nfactory.LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;\nFactoryMaker.updateSingletonFactory(Debug.__dashjs_factory_name, factory);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from './FactoryMaker';\n\nconst EVENT_PRIORITY_LOW = 0;\nconst EVENT_PRIORITY_HIGH = 5000;\n\nfunction EventBus() {\n\n let handlers = {};\n\n function on(type, listener, scope, priority = EVENT_PRIORITY_LOW) {\n\n if (!type) {\n throw new Error('event type cannot be null or undefined');\n }\n if (!listener || typeof (listener) !== 'function') {\n throw new Error('listener must be a function: ' + listener);\n }\n\n if (getHandlerIdx(type, listener, scope) >= 0) return;\n\n handlers[type] = handlers[type] || [];\n\n const handler = {\n callback: listener,\n scope: scope,\n priority: priority\n };\n\n const inserted = handlers[type].some((item , idx) => {\n if (item && priority > item.priority ) {\n handlers[type].splice(idx, 0, handler);\n return true;\n }\n });\n\n if (!inserted) {\n handlers[type].push(handler);\n }\n }\n\n function off(type, listener, scope) {\n if (!type || !listener || !handlers[type]) return;\n const idx = getHandlerIdx(type, listener, scope);\n if (idx < 0) return;\n handlers[type][idx] = null;\n }\n\n function trigger(type, payload) {\n if (!type || !handlers[type]) return;\n\n payload = payload || {};\n\n if (payload.hasOwnProperty('type')) throw new Error('\\'type\\' is a reserved word for event dispatching');\n\n payload.type = type;\n\n handlers[type] = handlers[type].filter((item) => item);\n handlers[type].forEach( handler => handler && handler.callback.call(handler.scope, payload) );\n }\n\n function getHandlerIdx(type, listener, scope) {\n\n let idx = -1;\n\n if (!handlers[type]) return idx;\n\n handlers[type].some( (item, index) => {\n if (item && item.callback === listener && (!scope || scope === item.scope)) {\n idx = index;\n return true;\n }\n });\n return idx;\n }\n\n function reset() {\n handlers = {};\n }\n\n const instance = {\n on: on,\n off: off,\n trigger: trigger,\n reset: reset\n };\n\n return instance;\n}\n\nEventBus.__dashjs_factory_name = 'EventBus';\nconst factory = FactoryMaker.getSingletonFactory(EventBus);\nfactory.EVENT_PRIORITY_LOW = EVENT_PRIORITY_LOW;\nfactory.EVENT_PRIORITY_HIGH = EVENT_PRIORITY_HIGH;\nFactoryMaker.updateSingletonFactory(EventBus.__dashjs_factory_name, factory);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @module FactoryMaker\n * @ignore\n */\nconst FactoryMaker = (function () {\n\n let instance;\n const singletonContexts = [];\n const singletonFactories = {};\n const classFactories = {};\n\n function extend(name, childInstance, override, context) {\n if (!context[name] && childInstance) {\n context[name] = {\n instance: childInstance,\n override: override\n };\n }\n }\n\n /**\n * Use this method from your extended object. this.factory is injected into your object.\n * this.factory.getSingletonInstance(this.context, 'VideoModel')\n * will return the video model for use in the extended object.\n *\n * @param {Object} context - injected into extended object as this.context\n * @param {string} className - string name found in all dash.js objects\n * with name __dashjs_factory_name Will be at the bottom. Will be the same as the object's name.\n * @returns {*} Context aware instance of specified singleton name.\n * @memberof module:FactoryMaker\n * @instance\n */\n function getSingletonInstance(context, className) {\n for (const i in singletonContexts) {\n const obj = singletonContexts[i];\n if (obj.context === context && obj.name === className) {\n return obj.instance;\n }\n }\n return null;\n }\n\n /**\n * Use this method to add an singleton instance to the system. Useful for unit testing to mock objects etc.\n *\n * @param {Object} context\n * @param {string} className\n * @param {Object} instance\n * @memberof module:FactoryMaker\n * @instance\n */\n function setSingletonInstance(context, className, instance) {\n for (const i in singletonContexts) {\n const obj = singletonContexts[i];\n if (obj.context === context && obj.name === className) {\n singletonContexts[i].instance = instance;\n return;\n }\n }\n singletonContexts.push({\n name: className,\n context: context,\n instance: instance\n });\n }\n\n /*------------------------------------------------------------------------------------------*/\n\n // Factories storage Management\n\n /*------------------------------------------------------------------------------------------*/\n\n function getFactoryByName(name, factoriesArray) {\n return factoriesArray[name];\n }\n\n function updateFactory(name, factory, factoriesArray) {\n if (name in factoriesArray) {\n factoriesArray[name] = factory;\n }\n }\n\n /*------------------------------------------------------------------------------------------*/\n\n // Class Factories Management\n\n /*------------------------------------------------------------------------------------------*/\n\n function updateClassFactory(name, factory) {\n updateFactory(name, factory, classFactories);\n }\n\n function getClassFactoryByName(name) {\n return getFactoryByName(name, classFactories);\n }\n\n function getClassFactory(classConstructor) {\n let factory = getFactoryByName(classConstructor.__dashjs_factory_name, classFactories);\n\n if (!factory) {\n factory = function (context) {\n if (context === undefined) {\n context = {};\n }\n return {\n create: function () {\n return merge(classConstructor, context, arguments);\n }\n };\n };\n\n classFactories[classConstructor.__dashjs_factory_name] = factory; // store factory\n }\n return factory;\n }\n\n /*------------------------------------------------------------------------------------------*/\n\n // Singleton Factory MAangement\n\n /*------------------------------------------------------------------------------------------*/\n\n function updateSingletonFactory(name, factory) {\n updateFactory(name, factory, singletonFactories);\n }\n\n function getSingletonFactoryByName(name) {\n return getFactoryByName(name, singletonFactories);\n }\n\n function getSingletonFactory(classConstructor) {\n let factory = getFactoryByName(classConstructor.__dashjs_factory_name, singletonFactories);\n if (!factory) {\n factory = function (context) {\n let instance;\n if (context === undefined) {\n context = {};\n }\n return {\n getInstance: function () {\n // If we don't have an instance yet check for one on the context\n if (!instance) {\n instance = getSingletonInstance(context, classConstructor.__dashjs_factory_name);\n }\n // If there's no instance on the context then create one\n if (!instance) {\n instance = merge(classConstructor, context, arguments);\n singletonContexts.push({\n name: classConstructor.__dashjs_factory_name,\n context: context,\n instance: instance\n });\n }\n return instance;\n }\n };\n };\n singletonFactories[classConstructor.__dashjs_factory_name] = factory; // store factory\n }\n\n return factory;\n }\n\n function merge(classConstructor, context, args) {\n\n let classInstance;\n const className = classConstructor.__dashjs_factory_name;\n const extensionObject = context[className];\n\n if (extensionObject) {\n\n let extension = extensionObject.instance;\n\n if (extensionObject.override) { //Override public methods in parent but keep parent.\n\n classInstance = classConstructor.apply({context}, args);\n extension = extension.apply({\n context,\n factory: instance,\n parent: classInstance\n }, args);\n\n for (const prop in extension) {\n if (classInstance.hasOwnProperty(prop)) {\n classInstance[prop] = extension[prop];\n }\n }\n\n } else { //replace parent object completely with new object. Same as dijon.\n\n return extension.apply({\n context,\n factory: instance\n }, args);\n\n }\n } else {\n // Create new instance of the class\n classInstance = classConstructor.apply({context}, args);\n }\n\n // Add getClassName function to class instance prototype (used by Debug)\n classInstance.getClassName = function () {return className;};\n\n return classInstance;\n }\n\n instance = {\n extend: extend,\n getSingletonInstance: getSingletonInstance,\n setSingletonInstance: setSingletonInstance,\n getSingletonFactory: getSingletonFactory,\n getSingletonFactoryByName: getSingletonFactoryByName,\n updateSingletonFactory: updateSingletonFactory,\n getClassFactory: getClassFactory,\n getClassFactoryByName: getClassFactoryByName,\n updateClassFactory: updateClassFactory\n };\n\n return instance;\n\n}());\n\nexport default FactoryMaker;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from './FactoryMaker';\nimport Utils from './Utils.js';\nimport Debug from '../core/Debug';\nimport Constants from '../streaming/constants/Constants';\nimport {HTTPRequest} from '../streaming/vo/metrics/HTTPRequest';\n\n/** @module Settings\n * @description Define the configuration parameters of Dash.js MediaPlayer.\n * @see {@link module:Settings~PlayerSettings PlayerSettings} for further information about the supported configuration properties\n */\n\n\n/**\n * @typedef {Object} PlayerSettings\n * @property {module:Settings~DebugSettings} [debug] Debug related settings\n * @property {module:Settings~StreamingSettings} [streaming] Streaming related settings\n * @example\n *\n * // Full settings object\n * settings = {\n * debug: {\n * logLevel: Debug.LOG_LEVEL_WARNING\n * },\n * streaming: {\n * metricsMaxListDepth: 1000,\n * abandonLoadTimeout: 10000,\n * liveDelayFragmentCount: NaN,\n * liveDelay: null,\n * scheduleWhilePaused: true,\n * fastSwitchEnabled: false,\n * bufferPruningInterval: 10,\n * bufferToKeep: 20,\n * bufferAheadToKeep: 80,\n * jumpGaps: true,\n * smallGapLimit: 1.5,\n * stableBufferTime: 12,\n * bufferTimeAtTopQuality: 30,\n * bufferTimeAtTopQualityLongForm: 60,\n * longFormContentDurationThreshold: 600,\n * wallclockTimeUpdateInterval: 50,\n * lowLatencyEnabled: false,\n * keepProtectionMediaKeys: false,\n * useManifestDateHeaderTimeSource: true,\n * useSuggestedPresentationDelay: true,\n * useAppendWindowEnd: true,\n * manifestUpdateRetryInterval: 100,\n * liveCatchUpMinDrift: 0.02,\n * liveCatchUpMaxDrift: 0,\n * liveCatchUpPlaybackRate: 0.5,\n * lastBitrateCachingInfo: { enabled: true, ttl: 360000 },\n * lastMediaSettingsCachingInfo: { enabled: true, ttl: 360000 },\n * cacheLoadThresholds: { video: 50, audio: 5 },\n * retryIntervals: {\n * MPD: 500,\n * XLinkExpansion: 500,\n * InitializationSegment: 1000,\n * IndexSegment: 1000,\n * MediaSegment: 1000,\n * BitstreamSwitchingSegment: 1000,\n * other: 1000,\n * lowLatencyReductionFactor: 10\n * },\n * retryAttempts: {\n * MPD: 3,\n * XLinkExpansion: 1,\n * InitializationSegment: 3,\n * IndexSegment: 3,\n * MediaSegment: 3,\n * BitstreamSwitchingSegment: 3,\n * other: 3,\n * lowLatencyMultiplyFactor: 5\n * },\n * abr: {\n * movingAverageMethod: Constants.MOVING_AVERAGE_SLIDING_WINDOW,\n * ABRStrategy: Constants.ABR_STRATEGY_DYNAMIC,\n * bandwidthSafetyFactor: 0.9,\n * useDefaultABRRules: true,\n * useBufferOccupancyABR: false,\n * useDeadTimeLatency: true,\n * limitBitrateByPortal: false,\n * usePixelRatioInLimitBitrateByPortal: false,\n * maxBitrate: { audio: -1, video: -1 },\n * minBitrate: { audio: -1, video: -1 },\n * maxRepresentationRatio: { audio: 1, video: 1 },\n * initialBitrate: { audio: -1, video: -1 },\n * initialRepresentationRatio: { audio: -1, video: -1 },\n * autoSwitchBitrate: { audio: true, video: true }\n * },\n * cmcd: {\n * enabled: false,\n * sid: null,\n * cid: null,\n * did: null\n * }\n * }\n * }\n */\n\n\n/**\n * @typedef {Object} DebugSettings\n * @property {number} [logLevel=dashjs.Debug.LOG_LEVEL_WARNING]\n * Sets up the log level. The levels are cumulative. For example, if you set the log level\n * to dashjs.Debug.LOG_LEVEL_WARNING all warnings, errors and fatals will be logged. Possible values.\n *\n * \n * - dashjs.Debug.LOG_LEVEL_NONE
\n * No message is written in the browser console.\n *\n * - dashjs.Debug.LOG_LEVEL_FATAL
\n * Log fatal errors. An error is considered fatal when it causes playback to fail completely.\n *\n * - dashjs.Debug.LOG_LEVEL_ERROR
\n * Log error messages.\n *\n * - dashjs.Debug.LOG_LEVEL_WARNING
\n * Log warning messages.\n *\n * - dashjs.Debug.LOG_LEVEL_INFO
\n * Log info messages.\n *\n * - dashjs.Debug.LOG_LEVEL_DEBUG
\n * Log debug messages.\n *
\n */\n\n/**\n * @typedef {Object} AbrSettings\n * @property {string} [movingAverageMethod=\"slidingWindow\"]\n * Sets the moving average method used for smoothing throughput estimates. Valid methods are\n * \"slidingWindow\" and \"ewma\". The call has no effect if an invalid method is passed.\n *\n * The sliding window moving average method computes the average throughput using the last four segments downloaded.\n * If the stream is live (as opposed to VOD), then only the last three segments are used.\n * If wide variations in throughput are detected, the number of segments can be dynamically increased to avoid oscillations.\n *\n * The exponentially weighted moving average (EWMA) method computes the average using exponential smoothing.\n * Two separate estimates are maintained, a fast one with a three-second half life and a slow one with an eight-second half life.\n * The throughput estimate at any time is the minimum of the fast and slow estimates.\n * This allows a fast reaction to a bandwidth drop and prevents oscillations on bandwidth spikes.\n * @property {string} [ABRStrategy=\"abrDynamic\"] Returns the current ABR strategy being used: \"abrDynamic\", \"abrBola\" or \"abrThroughput\".\n * @property {number} [bandwidthSafetyFactor=0.9]\n * Standard ABR throughput rules multiply the throughput by this value. It should be between 0 and 1,\n * with lower values giving less rebuffering (but also lower quality).\n * @property {boolean} [useDefaultABRRules=true] Should the default ABR rules be used, or the custom ones added.\n * @property {boolean} [useBufferOccupancyABR=false] Whether to use the BOLA abr rule.\n * @property {boolean} [useDeadTimeLatency=true]\n * If true, only the download portion will be considered part of the download bitrate\n * and latency will be regarded as static. If false, the reciprocal of the whole\n * transfer time will be used.\n * @property {boolean} [limitBitrateByPortal=false] If true, the size of the video portal will limit the max chosen video resolution.\n * @property {boolean} [usePixelRatioInLimitBitrateByPortal=false]\n * Sets whether to take into account the device's pixel ratio when defining the portal dimensions.\n * Useful on, for example, retina displays.\n * @property {module:Settings~AudioVideoSettings} [maxBitrate={audio: -1, video: -1}] The maximum bitrate that the ABR algorithms will choose. Use NaN for no limit.\n * @property {module:Settings~AudioVideoSettings} [minBitrate={audio: -1, video: -1}] The minimum bitrate that the ABR algorithms will choose. Use NaN for no limit.\n * @property {module:Settings~AudioVideoSettings} [maxRepresentationRatio={audio: 1, video: 1}]\n * When switching multi-bitrate content (auto or manual mode) this property specifies the maximum representation allowed,\n * as a proportion of the size of the representation set.\n *\n * You can set or remove this cap at anytime before or during playback. To clear this setting you set the value to 1.\n *\n * If both this and maxAllowedBitrate are defined, maxAllowedBitrate is evaluated first, then maxAllowedRepresentation,\n * i.e. the lowest value from executing these rules is used.\n *\n * This feature is typically used to reserve higher representations for playback only when connected over a fast connection.\n * @property {module:Settings~AudioVideoSettings} [initialBitrate={audio: -1, video: -1}] Explicitly set the starting bitrate for audio or video\n * @property {module:Settings~AudioVideoSettings} [initialRepresentationRatio={audio: -1, video: -1}] Explicitly set the initial representation ratio. If initalBitrate is specified, this is ignored.\n * @property {module:Settings~AudioVideoSettings} [autoSwitchBitrate={audio: true, video: true}] Indicates whether the player should enable ABR algorithms to switch the bitrate.\n */\n\n/**\n * @typedef {Object} StreamingSettings\n * @property {number} [metricsMaxListDepth=1000] Maximum list depth of metrics.\n * @property {number} [abandonLoadTimeout=10000]\n * A timeout value in seconds, which during the ABRController will block switch-up events.\n * This will only take effect after an abandoned fragment event occurs.\n * @property {number} [liveDelayFragmentCount=NaN]\n * Changing this value will lower or increase live stream latency. The detected segment duration will be multiplied by this value\n * to define a time in seconds to delay a live stream from the live edge. Lowering this value will lower latency but may decrease\n * the player's ability to build a stable buffer.\n * @property {number} [liveDelay]\n * Equivalent in seconds of setLiveDelayFragmentCount
\n * Lowering this value will lower latency but may decrease the player's ability to build a stable buffer.
\n * This value should be less than the manifest duration by a couple of segment durations to avoid playback issues
\n * If set, this parameter will take precedence over setLiveDelayFragmentCount and manifest info
\n * @property {boolean} [scheduleWhilePaused=true]\n * Set to true if you would like dash.js to keep downloading fragments in the background\n * when the video element is paused.\n * @property {boolean} [fastSwitchEnabled=false]\n * When enabled, after an ABR up-switch in quality, instead of requesting and appending the next fragment\n * at the end of the current buffer range it is requested and appended closer to the current time\n * When enabled, The maximum time to render a higher quality is current time + (1.5 * fragment duration).\n *\n * Note, When ABR down-switch is detected, we appended the lower quality at the end of the buffer range to preserve the\n * higher quality media for as long as possible.\n *\n * If enabled, it should be noted there are a few cases when the client will not replace inside buffer range but rather\n * just append at the end. 1. When the buffer level is less than one fragment duration 2. The client\n * is in an Abandonment State due to recent fragment abandonment event.\n *\n * Known issues:\n * 1. In IE11 with auto switching off, if a user switches to a quality they can not download in time the\n * fragment may be appended in the same range as the playhead or even in the past, in IE11 it may cause a stutter\n * or stall in playback.\n * @property {number} [bufferPruningInterval=10] The interval of pruning buffer in sconds.\n * @property {number} [bufferToKeep=20]\n * This value influences the buffer pruning logic.\n * Allows you to modify the buffer that is kept in source buffer in seconds.\n * 0|-----------bufferToPrune-----------|-----bufferToKeep-----|currentTime|\n * @property {number} [bufferAheadToKeep=80]\n * This value influences the buffer pruning logic.\n * Allows you to modify the buffer ahead of current time position that is kept in source buffer in seconds.\n * 0|--------|currentTime|-----bufferAheadToKeep----|----bufferToPrune-----------|end|
\n * @property {boolean} [jumpGaps=true] Sets whether player should jump small gaps (discontinuities) in the buffer.\n * @property {number} [smallGapLimit=1.8] Time in seconds for a gap to be considered small.\n * @property {number} [stableBufferTime=12]\n * The time that the internal buffer target will be set to post startup/seeks (NOT top quality).\n *\n * When the time is set higher than the default you will have to wait longer\n * to see automatic bitrate switches but will have a larger buffer which\n * will increase stability.\n * @property {number} [bufferTimeAtTopQuality=30]\n * The time that the internal buffer target will be set to once playing the top quality.\n * If there are multiple bitrates in your adaptation, and the media is playing at the highest\n * bitrate, then we try to build a larger buffer at the top quality to increase stability\n * and to maintain media quality.\n * @property {number} [bufferTimeAtTopQualityLongForm=60] The time that the internal buffer target will be set to once playing the top quality for long form content.\n * @property {number} [longFormContentDurationThreshold=600]\n * The threshold which defines if the media is considered long form content.\n * This will directly affect the buffer targets when playing back at the top quality.\n * @property {number} [wallclockTimeUpdateInterval=50] How frequently the wallclockTimeUpdated internal event is triggered (in milliseconds).\n * @property {boolean} [lowLatencyEnabled=false] Enable or disable low latency mode\n * @property {boolean} [keepProtectionMediaKeys=false]\n * Set the value for the ProtectionController and MediaKeys life cycle. If true, the\n * ProtectionController and then created MediaKeys and MediaKeySessions will be preserved during\n * the MediaPlayer lifetime.\n * @property {boolean} [useManifestDateHeaderTimeSource=true]\n * Allows you to enable the use of the Date Header, if exposed with CORS, as a timing source for live edge detection. The\n * use of the date header will happen only after the other timing source that take precedence fail or are omitted as described.\n * @property {boolean} [useSuggestedPresentationDelay=true]\n *
Set to true if you would like to override the default live delay and honor the SuggestedPresentationDelay attribute in by the manifest.
\n * @property {boolean} [useAppendWindowEnd=true]\n * Specifies if the appendWindowEnd attribute of the MSE SourceBuffers should be set according to content duration from manifest.\n * @property {number} [manifestUpdateRetryInterval=100]\n * For live streams, set the interval-frequency in milliseconds at which\n * dash.js will check if the current manifest is still processed before\n * downloading the next manifest once the minimumUpdatePeriod time has\n * @property {number} [liveCatchUpMinDrift=0.02]\n * Use this method to set the minimum latency deviation allowed before activating catch-up mechanism. In low latency mode,\n * when the difference between the measured latency and the target one,\n * as an absolute number, is higher than the one sets with this method, then dash.js increases/decreases\n * playback rate until target latency is reached.\n *\n * LowLatencyMinDrift should be provided in seconds, and it uses values between 0.0 and 0.5.\n *\n * Note: Catch-up mechanism is only applied when playing low latency live streams.\n * @property {number} [liveCatchUpMaxDrift=0]\n * Use this method to set the maximum latency deviation allowed before dash.js to do a seeking to live position. In low latency mode,\n * when the difference between the measured latency and the target one,\n * as an absolute number, is higher than the one sets with this method, then dash.js does a seek to live edge position minus\n * the target live delay.\n *\n * LowLatencyMaxDriftBeforeSeeking should be provided in seconds. If 0, then seeking operations won't be used for\n * fixing latency deviations.\n *\n * Note: Catch-up mechanism is only applied when playing low latency live streams.\n * @property {number} [liveCatchUpPlaybackRate=0.5]\n * Use this parameter to set the maximum catch up rate, as a percentage, for low latency live streams. In low latency mode,\n * when measured latency is higher/lower than the target one,\n * dash.js increases/decreases playback rate respectively up to (+/-) the percentage defined with this method until target is reached.\n *\n * Valid values for catch up rate are in range 0-0.5 (0-50%). Set it to 0 to turn off live catch up feature.\n *\n * Note: Catch-up mechanism is only applied when playing low latency live streams.\n * @property {number} [liveCatchupLatencyThreshold=NaN]\n * Use this parameter to set the maximum threshold for which live catch up is applied. For instance, if this value is set to 8 seconds,\n * then live catchup is only applied if the current live latency is equal or below 8 seconds. The reason behind this parameter is to avoid an increase\n * of the playback rate if the user seeks within the DVR window.\n *\n * If no value is specified this will be twice the maximum live delay. The maximum live delay is either specified in the manifest as part of a ServiceDescriptor or calculated the following:\n * maximumLiveDelay = targetDelay + liveCatchupMinDrift\n *\n * Note: Catch-up mechanism is only applied when playing low latency live streams.\n * @property {module:Settings~CachingInfoSettings} [lastBitrateCachingInfo={enabled: true, ttl: 360000}]\n * Set to false if you would like to disable the last known bit rate from being stored during playback and used\n * to set the initial bit rate for subsequent playback within the expiration window.\n *\n * The default expiration is one hour, defined in milliseconds. If expired, the default initial bit rate (closest to 1000 kbps) will be used\n * for that session and a new bit rate will be stored during that session.\n * @property {module:Settings~CachingInfoSettings} [lastMediaSettingsCachingInfo={enabled: true, ttl: 360000}]\n * Set to false if you would like to disable the last known lang for audio (or camera angle for video) from being stored during playback and used\n * to set the initial settings for subsequent playback within the expiration window.\n *\n * The default expiration is one hour, defined in milliseconds. If expired, the default settings will be used\n * for that session and a new settings will be stored during that session.\n * @property {module:Settings~AudioVideoSettings} [cacheLoadThresholds={video: 50, audio: 5}]\n * For a given media type, the threshold which defines if the response to a fragment\n * request is coming from browser cache or not.\n * @property {module:Settings~RequestTypeSettings} [retryIntervals] Time in milliseconds of which to reload a failed file load attempt. For low latency mode these values are divided by lowLatencyReductionFactor.\n * @property {module:Settings~RequestTypeSettings} [retryAttempts] Total number of retry attempts that will occur on a file load before it fails. For low latency mode these values are multiplied by lowLatencyMultiplyFactor.\n * @property {module:Settings~AbrSettings} abr Adaptive Bitrate algorithm related settings.\n * @property {module:Settings~CmcdSettings} cmcd Settings related to Common Media Client Data reporting.\n */\n\n/**\n * @typedef {Object} CachingInfoSettings\n * @property {boolean} [enable] Enable or disable the caching feature.\n * @property {number} [ttl] Time to live. A value defined in milliseconds representing how log to cache the settings for.\n */\n\n/**\n * @typedef {Object} module:Settings~AudioVideoSettings\n * @property {number|boolean} [audio] Configuration for audio media type of tracks.\n * @property {number|boolean} [video] Configuration for video media type of tracks.\n */\n\n/**\n * @typedef {Object} RequestTypeSettings\n * @property {number} [MPD] Manifest type of requests\n * @property {number} [XLinkExpansion] XLink expansion type of requests\n * @property {number} [InitializationSegment] Request to retrieve an initialization segment\n * @property {number} [IndexSegment] Request to retrieve an index segment (SegmentBase)\n * @property {number} [MediaSegment] Request to retrieve a media segment (video/audio/image/text chunk)\n * @property {number} [BitstreamSwitchingSegment] Bitrate stream switching type of request\n * @property {number} [other] Other type of request\n *\n */\n\n/**\n * @typedef {Object} module:Settings~CmcdSettings\n * @property {boolean} [enable=false] Enable or disable the CMCD reporting.\n * @property {string} [sid] GUID identifying the current playback session. Should be in UUID format. If not specified a UUID will be automatically generated.\n * @property {string} [cid] A unique string to identify the current content. If not specified it will be a hash of the MPD url.\n * @property {string} [did=dash.js-cmcd-default-id] A unique string identifying the current device.\n */\n\n\n/**\n * @class\n * @ignore\n */\nfunction Settings() {\n let instance;\n\n /**\n * @const {PlayerSettings} defaultSettings\n * @ignore\n */\n const defaultSettings = {\n debug: {\n logLevel: Debug.LOG_LEVEL_WARNING\n },\n streaming: {\n metricsMaxListDepth: 1000,\n abandonLoadTimeout: 10000,\n liveDelayFragmentCount: NaN,\n liveDelay: null,\n scheduleWhilePaused: true,\n fastSwitchEnabled: false,\n bufferPruningInterval: 10,\n bufferToKeep: 20,\n bufferAheadToKeep: 80,\n jumpGaps: true,\n smallGapLimit: 1.5,\n stableBufferTime: 12,\n bufferTimeAtTopQuality: 30,\n bufferTimeAtTopQualityLongForm: 60,\n longFormContentDurationThreshold: 600,\n wallclockTimeUpdateInterval: 50,\n lowLatencyEnabled: false,\n keepProtectionMediaKeys: false,\n useManifestDateHeaderTimeSource: true,\n useSuggestedPresentationDelay: true,\n useAppendWindowEnd: true,\n manifestUpdateRetryInterval: 100,\n liveCatchUpMinDrift: 0.02,\n liveCatchUpMaxDrift: 0,\n liveCatchUpPlaybackRate: 0.5,\n liveCatchupLatencyThreshold: NaN,\n lastBitrateCachingInfo: {enabled: true, ttl: 360000},\n lastMediaSettingsCachingInfo: {enabled: true, ttl: 360000},\n cacheLoadThresholds: {video: 50, audio: 5},\n retryIntervals: {\n [HTTPRequest.MPD_TYPE]: 500,\n [HTTPRequest.XLINK_EXPANSION_TYPE]: 500,\n [HTTPRequest.MEDIA_SEGMENT_TYPE]: 1000,\n [HTTPRequest.INIT_SEGMENT_TYPE]: 1000,\n [HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE]: 1000,\n [HTTPRequest.INDEX_SEGMENT_TYPE]: 1000,\n [HTTPRequest.OTHER_TYPE]: 1000,\n lowLatencyReductionFactor: 10\n },\n retryAttempts: {\n [HTTPRequest.MPD_TYPE]: 3,\n [HTTPRequest.XLINK_EXPANSION_TYPE]: 1,\n [HTTPRequest.MEDIA_SEGMENT_TYPE]: 3,\n [HTTPRequest.INIT_SEGMENT_TYPE]: 3,\n [HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE]: 3,\n [HTTPRequest.INDEX_SEGMENT_TYPE]: 3,\n [HTTPRequest.OTHER_TYPE]: 3,\n lowLatencyMultiplyFactor: 5\n },\n abr: {\n movingAverageMethod: Constants.MOVING_AVERAGE_SLIDING_WINDOW,\n ABRStrategy: Constants.ABR_STRATEGY_DYNAMIC,\n bandwidthSafetyFactor: 0.9,\n useDefaultABRRules: true,\n useBufferOccupancyABR: false,\n useDeadTimeLatency: true,\n limitBitrateByPortal: false,\n usePixelRatioInLimitBitrateByPortal: false,\n maxBitrate: {audio: -1, video: -1},\n minBitrate: {audio: -1, video: -1},\n maxRepresentationRatio: {audio: 1, video: 1},\n initialBitrate: {audio: -1, video: -1},\n initialRepresentationRatio: {audio: -1, video: -1},\n autoSwitchBitrate: {audio: true, video: true}\n },\n cmcd: {\n enabled: false,\n sid: null,\n cid: null,\n did: null\n }\n }\n };\n\n let settings = Utils.clone(defaultSettings);\n\n //Merge in the settings. If something exists in the new config that doesn't match the schema of the default config,\n //regard it as an error and log it.\n function mixinSettings(source, dest, path) {\n for (let n in source) {\n if (source.hasOwnProperty(n)) {\n if (dest.hasOwnProperty(n)) {\n if (typeof source[n] === 'object' && source[n] !== null) {\n mixinSettings(source[n], dest[n], path.slice() + n + '.');\n } else {\n dest[n] = Utils.clone(source[n]);\n }\n }\n }\n }\n }\n\n /**\n * Return the settings object. Don't copy/store this object, you won't get updates.\n * @func\n * @instance\n */\n function get() {\n return settings;\n }\n\n /**\n * @func\n * @instance\n * @param {object} settingsObj - This should be a partial object of the Settings.Schema type. That is, fields defined should match the path (e.g.\n * settingsObj.streaming.abr.autoSwitchBitrate.audio -> defaultSettings.streaming.abr.autoSwitchBitrate.audio). Where an element's path does\n * not match it is ignored, and a warning is logged.\n *\n * Use to change the settings object. Any new values defined will overwrite the settings and anything undefined will not change.\n * Implementers of new settings should add it in an approriate namespace to the defaultSettings object and give it a default value (that is not undefined).\n *\n */\n function update(settingsObj) {\n if (typeof settingsObj === 'object') {\n mixinSettings(settingsObj, settings, '');\n }\n }\n\n /**\n * Resets the settings object. Everything is set to its default value.\n * @func\n * @instance\n *\n */\n function reset() {\n settings = Utils.clone(defaultSettings);\n }\n\n instance = {\n get: get,\n update: update,\n reset: reset\n };\n\n return instance;\n}\n\n\nSettings.__dashjs_factory_name = 'Settings';\nlet factory = FactoryMaker.getSingletonFactory(Settings);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * @class\n * @ignore\n */\n\nclass Utils {\n static mixin(dest, source, copy) {\n let s;\n let empty = {};\n if (dest) {\n for (let name in source) {\n if (source.hasOwnProperty(name)) {\n s = source[name];\n if (!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))) {\n if (typeof dest[name] === 'object' && dest[name] !== null) {\n dest[name] = Utils.mixin(dest[name], s, copy);\n } else {\n dest[name] = copy(s);\n }\n }\n }\n }\n }\n return dest;\n }\n\n static clone(src) {\n if (!src || typeof src !== 'object') {\n return src; // anything\n }\n let r;\n if (src instanceof Array) {\n // array\n r = [];\n for (let i = 0, l = src.length; i < l; ++i) {\n if (i in src) {\n r.push(Utils.clone(src[i]));\n }\n }\n } else {\n r = {};\n }\n return Utils.mixin(r, src, Utils.clone);\n }\n\n static addAditionalQueryParameterToUrl(url, params) {\n try {\n if (!params || params.length === 0) {\n return url;\n }\n\n let modifiedUrl = new URL(url);\n\n params.forEach((param) => {\n if (param.key && param.value) {\n modifiedUrl.searchParams.set(param.key, param.value);\n }\n });\n\n return modifiedUrl.href;\n\n\n } catch (e) {\n return url;\n }\n }\n\n static generateUuid() {\n let dt = new Date().getTime();\n const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r = (dt + Math.random() * 16) % 16 | 0;\n dt = Math.floor(dt / 16);\n return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);\n });\n return uuid;\n }\n\n static generateHashCode(string) {\n let hash = 0;\n\n if (string.length === 0) {\n return hash;\n }\n\n for (let i = 0; i < string.length; i++) {\n const chr = string.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0;\n }\n return hash;\n }\n}\n\nexport default Utils;\n",
"const VERSION = '3.1.2';\nexport function getVersionString() {\n return VERSION;\n}\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport ErrorsBase from './ErrorsBase';\n/**\n * Errors declaration\n * @class\n */\nclass Errors extends ErrorsBase {\n constructor () {\n super();\n /**\n * Error code returned when a manifest parsing error occurs\n */\n this.MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE = 10;\n /**\n * Error code returned when a manifest loading error occurs\n */\n this.MANIFEST_LOADER_LOADING_FAILURE_ERROR_CODE = 11;\n /**\n * Error code returned when a xlink loading error occurs\n */\n this.XLINK_LOADER_LOADING_FAILURE_ERROR_CODE = 12;\n /**\n * Error code returned when the update of segments list has failed\n */\n this.SEGMENTS_UPDATE_FAILED_ERROR_CODE = 13;\n this.SEGMENTS_UNAVAILABLE_ERROR_CODE = 14;\n this.SEGMENT_BASE_LOADER_ERROR_CODE = 15;\n this.TIME_SYNC_FAILED_ERROR_CODE = 16;\n this.FRAGMENT_LOADER_LOADING_FAILURE_ERROR_CODE = 17;\n this.FRAGMENT_LOADER_NULL_REQUEST_ERROR_CODE = 18;\n this.URL_RESOLUTION_FAILED_GENERIC_ERROR_CODE = 19;\n this.APPEND_ERROR_CODE = 20;\n this.REMOVE_ERROR_CODE = 21;\n this.DATA_UPDATE_FAILED_ERROR_CODE = 22;\n /**\n * Error code returned when MediaSource is not supported by the browser\n */\n this.CAPABILITY_MEDIASOURCE_ERROR_CODE = 23;\n /**\n * Error code returned when Protected contents are not supported\n */\n this.CAPABILITY_MEDIAKEYS_ERROR_CODE = 24;\n\n this.DOWNLOAD_ERROR_ID_MANIFEST_CODE = 25;\n\n this.DOWNLOAD_ERROR_ID_SIDX_CODE = 26;\n this.DOWNLOAD_ERROR_ID_CONTENT_CODE = 27;\n\n this.DOWNLOAD_ERROR_ID_INITIALIZATION_CODE = 28;\n\n this.DOWNLOAD_ERROR_ID_XLINK_CODE = 29;\n\n this.MANIFEST_ERROR_ID_CODEC_CODE = 30;\n this.MANIFEST_ERROR_ID_PARSE_CODE = 31;\n\n /**\n * Error code returned when no stream (period) has been detected in the manifest\n */\n this.MANIFEST_ERROR_ID_NOSTREAMS_CODE = 32;\n /**\n * Error code returned when something wrong has append during subtitles parsing (TTML or VTT)\n */\n this.TIMED_TEXT_ERROR_ID_PARSE_CODE = 33;\n /**\n * Error code returned when a 'muxed' media type has been detected in the manifest. This type is not supported\n */\n this.MANIFEST_ERROR_ID_MULTIPLEXED_CODE = 34;\n /**\n * Error code returned when a media source type is not supported\n */\n this.MEDIASOURCE_TYPE_UNSUPPORTED_CODE = 35;\n\n this.MANIFEST_LOADER_PARSING_FAILURE_ERROR_MESSAGE = 'parsing failed for ';\n this.MANIFEST_LOADER_LOADING_FAILURE_ERROR_MESSAGE = 'Failed loading manifest: ';\n this.XLINK_LOADER_LOADING_FAILURE_ERROR_MESSAGE = 'Failed loading Xlink element: ';\n this.SEGMENTS_UPDATE_FAILED_ERROR_MESSAGE = 'Segments update failed';\n this.SEGMENTS_UNAVAILABLE_ERROR_MESSAGE = 'no segments are available yet';\n this.SEGMENT_BASE_LOADER_ERROR_MESSAGE = 'error loading segments';\n this.TIME_SYNC_FAILED_ERROR_MESSAGE = 'Failed to synchronize time';\n this.FRAGMENT_LOADER_NULL_REQUEST_ERROR_MESSAGE = 'request is null';\n this.URL_RESOLUTION_FAILED_GENERIC_ERROR_MESSAGE = 'Failed to resolve a valid URL';\n this.APPEND_ERROR_MESSAGE = 'chunk is not defined';\n this.REMOVE_ERROR_MESSAGE = 'buffer is not defined';\n this.DATA_UPDATE_FAILED_ERROR_MESSAGE = 'Data update failed';\n\n this.CAPABILITY_MEDIASOURCE_ERROR_MESSAGE = 'mediasource is not supported';\n this.CAPABILITY_MEDIAKEYS_ERROR_MESSAGE = 'mediakeys is not supported';\n this.TIMED_TEXT_ERROR_MESSAGE_PARSE = 'parsing error :';\n this.MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE = 'Error creating source buffer of type : ';\n }\n}\n\nlet errors = new Errors();\nexport default errors;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass ErrorsBase {\n extend (errors, config) {\n if (!errors) return;\n\n let override = config ? config.override : false;\n let publicOnly = config ? config.publicOnly : false;\n\n\n for (const err in errors) {\n if (!errors.hasOwnProperty(err) || (this[err] && !override)) continue;\n if (publicOnly && errors[err].indexOf('public_') === -1) continue;\n this[err] = errors[err];\n\n }\n }\n}\n\nexport default ErrorsBase;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport EventsBase from './EventsBase';\n\n/**\n * These are internal events that should not be needed at the player level.\n * If you find and event in here that you would like access to from MediaPlayer level\n * please add an issue at https://github.com/Dash-Industry-Forum/dash.js/issues/new\n * @class\n * @ignore\n */\nclass CoreEvents extends EventsBase {\n constructor () {\n super();\n this.BUFFERING_COMPLETED = 'bufferingCompleted';\n this.BUFFER_CLEARED = 'bufferCleared';\n this.BUFFER_LEVEL_UPDATED = 'bufferLevelUpdated';\n this.BYTES_APPENDED = 'bytesAppended';\n this.BYTES_APPENDED_END_FRAGMENT = 'bytesAppendedEndFragment';\n this.CHECK_FOR_EXISTENCE_COMPLETED = 'checkForExistenceCompleted';\n this.CURRENT_TRACK_CHANGED = 'currentTrackChanged';\n this.DATA_UPDATE_COMPLETED = 'dataUpdateCompleted';\n this.DATA_UPDATE_STARTED = 'dataUpdateStarted';\n this.INBAND_EVENTS = 'inbandEvents';\n this.INITIALIZATION_LOADED = 'initializationLoaded';\n this.INIT_FRAGMENT_LOADED = 'initFragmentLoaded';\n this.INIT_FRAGMENT_NEEDED = 'initFragmentNeeded';\n this.INTERNAL_MANIFEST_LOADED = 'internalManifestLoaded';\n this.ORIGINAL_MANIFEST_LOADED = 'originalManifestLoaded';\n this.LIVE_EDGE_SEARCH_COMPLETED = 'liveEdgeSearchCompleted';\n this.LOADING_COMPLETED = 'loadingCompleted';\n this.LOADING_PROGRESS = 'loadingProgress';\n this.LOADING_DATA_PROGRESS = 'loadingDataProgress';\n this.LOADING_ABANDONED = 'loadingAborted';\n this.MANIFEST_UPDATED = 'manifestUpdated';\n this.MEDIA_FRAGMENT_LOADED = 'mediaFragmentLoaded';\n this.MEDIA_FRAGMENT_NEEDED = 'mediaFragmentNeeded';\n this.QUOTA_EXCEEDED = 'quotaExceeded';\n this.REPRESENTATION_UPDATE_STARTED = 'representationUpdateStarted';\n this.REPRESENTATION_UPDATE_COMPLETED = 'representationUpdateCompleted';\n this.SEGMENTS_LOADED = 'segmentsLoaded';\n this.SERVICE_LOCATION_BLACKLIST_ADD = 'serviceLocationBlacklistAdd';\n this.SERVICE_LOCATION_BLACKLIST_CHANGED = 'serviceLocationBlacklistChanged';\n this.SOURCEBUFFER_REMOVE_COMPLETED = 'sourceBufferRemoveCompleted';\n this.STREAMS_COMPOSED = 'streamsComposed';\n this.STREAM_BUFFERING_COMPLETED = 'streamBufferingCompleted';\n this.STREAM_COMPLETED = 'streamCompleted';\n this.TEXT_TRACKS_QUEUE_INITIALIZED = 'textTracksQueueInitialized';\n this.TIME_SYNCHRONIZATION_COMPLETED = 'timeSynchronizationComplete';\n this.URL_RESOLUTION_FAILED = 'urlResolutionFailed';\n this.VIDEO_CHUNK_RECEIVED = 'videoChunkReceived';\n this.WALLCLOCK_TIME_UPDATED = 'wallclockTimeUpdated';\n this.XLINK_ELEMENT_LOADED = 'xlinkElementLoaded';\n this.XLINK_READY = 'xlinkReady';\n this.SEGMENTBASE_INIT_REQUEST_NEEDED = 'segmentBaseInitRequestNeeded';\n this.SEGMENTBASE_SEGMENTSLIST_REQUEST_NEEDED = 'segmentBaseSegmentsListRequestNeeded';\n this.SEEK_TARGET = 'seekTarget';\n this.DYNAMIC_STREAM_COMPLETED = 'dynamicStreamCompleted';\n }\n}\n\nexport default CoreEvents;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nimport CoreEvents from './CoreEvents';\nclass Events extends CoreEvents {\n}\nlet events = new Events();\nexport default events;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass EventsBase {\n extend (events, config) {\n if (!events) return;\n\n let override = config ? config.override : false;\n let publicOnly = config ? config.publicOnly : false;\n\n\n for (const evt in events) {\n if (!events.hasOwnProperty(evt) || (this[evt] && !override)) continue;\n if (publicOnly && events[evt].indexOf('public_') === -1) continue;\n this[evt] = events[evt];\n\n }\n }\n}\n\nexport default EventsBase;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FragmentRequest from '../streaming/vo/FragmentRequest';\nimport { HTTPRequest } from '../streaming/vo/metrics/HTTPRequest';\nimport FactoryMaker from '../core/FactoryMaker';\nimport {\n replaceIDForTemplate,\n unescapeDollarsInTemplate,\n replaceTokenForTemplate,\n getTimeBasedSegment\n} from './utils/SegmentsUtils';\n\nimport SegmentsController from './controllers/SegmentsController';\n\nfunction DashHandler(config) {\n\n config = config || {};\n const context = this.context;\n\n const eventBus = config.eventBus;\n const events = config.events;\n const debug = config.debug;\n const dashConstants = config.dashConstants;\n const urlUtils = config.urlUtils;\n const type = config.type;\n const streamInfo = config.streamInfo;\n\n const timelineConverter = config.timelineConverter;\n const dashMetrics = config.dashMetrics;\n const baseURLController = config.baseURLController;\n\n let instance,\n logger,\n segmentIndex,\n lastSegment,\n requestedTime,\n currentTime,\n isDynamicManifest,\n dynamicStreamCompleted,\n selectedMimeType,\n segmentsController;\n\n function setup() {\n logger = debug.getLogger(instance);\n resetInitialSettings();\n\n segmentsController = SegmentsController(context).create(config);\n\n eventBus.on(events.INITIALIZATION_LOADED, onInitializationLoaded, instance);\n eventBus.on(events.SEGMENTS_LOADED, onSegmentsLoaded, instance);\n eventBus.on(events.REPRESENTATION_UPDATE_STARTED, onRepresentationUpdateStarted, instance);\n eventBus.on(events.DYNAMIC_STREAM_COMPLETED, onDynamicStreamCompleted, instance);\n }\n\n function initialize(isDynamic) {\n isDynamicManifest = isDynamic;\n dynamicStreamCompleted = false;\n segmentsController.initialize(isDynamic);\n }\n\n function getType() {\n return type;\n }\n\n function getStreamInfo() {\n return streamInfo;\n }\n\n function setCurrentTime(value) {\n currentTime = value;\n }\n\n function getCurrentTime() {\n return currentTime;\n }\n\n function setCurrentIndex (value) {\n segmentIndex = value;\n }\n\n function getCurrentIndex () {\n return segmentIndex;\n }\n\n function resetIndex() {\n segmentIndex = -1;\n lastSegment = null;\n }\n\n function resetInitialSettings() {\n resetIndex();\n currentTime = 0;\n requestedTime = null;\n segmentsController = null;\n selectedMimeType = null;\n }\n\n function reset() {\n resetInitialSettings();\n\n eventBus.off(events.INITIALIZATION_LOADED, onInitializationLoaded, instance);\n eventBus.off(events.SEGMENTS_LOADED, onSegmentsLoaded, instance);\n eventBus.off(events.REPRESENTATION_UPDATE_STARTED, onRepresentationUpdateStarted, instance);\n eventBus.off(events.DYNAMIC_STREAM_COMPLETED, onDynamicStreamCompleted, instance);\n }\n\n function setRequestUrl(request, destination, representation) {\n const baseURL = baseURLController.resolve(representation.path);\n let url,\n serviceLocation;\n\n if (!baseURL || (destination === baseURL.url) || (!urlUtils.isRelative(destination))) {\n url = destination;\n } else {\n url = baseURL.url;\n serviceLocation = baseURL.serviceLocation;\n\n if (destination) {\n url = urlUtils.resolve(destination, url);\n }\n }\n\n if (urlUtils.isRelative(url)) {\n return false;\n }\n\n request.url = url;\n request.serviceLocation = serviceLocation;\n\n return true;\n }\n\n function generateInitRequest(mediaInfo, representation, mediaType) {\n const request = new FragmentRequest();\n const period = representation.adaptation.period;\n const presentationStartTime = period.start;\n\n request.mediaType = mediaType;\n request.type = HTTPRequest.INIT_SEGMENT_TYPE;\n request.range = representation.range;\n request.availabilityStartTime = timelineConverter.calcAvailabilityStartTimeFromPresentationTime(presentationStartTime, period.mpd, isDynamicManifest);\n request.availabilityEndTime = timelineConverter.calcAvailabilityEndTimeFromPresentationTime(presentationStartTime + period.duration, period.mpd, isDynamicManifest);\n request.quality = representation.index;\n request.mediaInfo = mediaInfo;\n request.representationId = representation.id;\n\n if (setRequestUrl(request, representation.initialization, representation)) {\n request.url = replaceTokenForTemplate(request.url, 'Bandwidth', representation.bandwidth);\n return request;\n }\n }\n\n function getInitRequest(mediaInfo, representation) {\n if (!representation) return null;\n const request = generateInitRequest(mediaInfo, representation, getType());\n return request;\n }\n\n function setMimeType(newMimeType) {\n selectedMimeType = newMimeType;\n }\n\n function setExpectedLiveEdge(liveEdge) {\n timelineConverter.setExpectedLiveEdge(liveEdge);\n dashMetrics.updateManifestUpdateInfo({presentationStartTime: liveEdge});\n }\n\n function onRepresentationUpdateStarted(eventObj) {\n if (eventObj.sender.getType() !== getType()) return;\n\n processRepresentation(eventObj.representation);\n }\n\n function processRepresentation(voRepresentation) {\n const hasInitialization = voRepresentation.hasInitialization();\n const hasSegments = voRepresentation.hasSegments();\n\n //if representation has initialization and segments information, REPRESENTATION_UPDATE_COMPLETED can be triggered immediately\n //otherwise, it means that a request has to be made to get initialization and/or segments informations\n if (hasInitialization && hasSegments) {\n eventBus.trigger(events.REPRESENTATION_UPDATE_COMPLETED, {sender: instance, representation: voRepresentation});\n } else {\n segmentsController.update(voRepresentation, getType(), selectedMimeType, hasInitialization, hasSegments);\n }\n }\n\n function getRequestForSegment(mediaInfo, segment) {\n if (segment === null || segment === undefined) {\n return null;\n }\n\n const request = new FragmentRequest();\n const representation = segment.representation;\n const bandwidth = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].\n AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].bandwidth;\n let url = segment.media;\n\n url = replaceTokenForTemplate(url, 'Number', segment.replacementNumber);\n url = replaceTokenForTemplate(url, 'Time', segment.replacementTime);\n url = replaceTokenForTemplate(url, 'Bandwidth', bandwidth);\n url = replaceIDForTemplate(url, representation.id);\n url = unescapeDollarsInTemplate(url);\n\n request.mediaType = getType();\n request.type = HTTPRequest.MEDIA_SEGMENT_TYPE;\n request.range = segment.mediaRange;\n request.startTime = segment.presentationStartTime;\n request.duration = segment.duration;\n request.timescale = representation.timescale;\n request.availabilityStartTime = segment.availabilityStartTime;\n request.availabilityEndTime = segment.availabilityEndTime;\n request.wallStartTime = segment.wallStartTime;\n request.quality = representation.index;\n request.index = segment.availabilityIdx;\n request.mediaInfo = mediaInfo;\n request.adaptationIndex = representation.adaptation.index;\n request.representationId = representation.id;\n\n if (setRequestUrl(request, url, representation)) {\n return request;\n }\n }\n\n function isMediaFinished(representation) {\n let isFinished = false;\n\n if (!representation) return isFinished;\n\n if (!isDynamicManifest) {\n if (segmentIndex >= representation.availableSegmentsNumber) {\n isFinished = true;\n }\n } else {\n if (dynamicStreamCompleted) {\n isFinished = true;\n } else if (lastSegment) {\n const time = parseFloat((lastSegment.presentationStartTime - representation.adaptation.period.start).toFixed(5));\n const endTime = lastSegment.duration > 0 ? time + 1.5 * lastSegment.duration : time;\n const duration = representation.adaptation.period.duration;\n\n isFinished = endTime >= duration;\n }\n }\n\n return isFinished;\n }\n\n function getSegmentRequestForTime(mediaInfo, representation, time, options) {\n let request = null;\n\n if (!representation || !representation.segmentInfoType) {\n return request;\n }\n\n const idx = segmentIndex;\n const keepIdx = options ? options.keepIdx : false;\n const ignoreIsFinished = (options && options.ignoreIsFinished) ? true : false;\n\n if (requestedTime !== time) { // When playing at live edge with 0 delay we may loop back with same time and index until it is available. Reduces verboseness of logs.\n requestedTime = time;\n logger.debug('Getting the request for time : ' + time);\n }\n\n const segment = segmentsController.getSegmentByTime(representation, time);\n if (segment) {\n segmentIndex = segment.availabilityIdx;\n lastSegment = segment;\n logger.debug('Index for time ' + time + ' is ' + segmentIndex);\n request = getRequestForSegment(mediaInfo, segment);\n } else {\n const finished = !ignoreIsFinished ? isMediaFinished(representation) : false;\n if (finished) {\n request = new FragmentRequest();\n request.action = FragmentRequest.ACTION_COMPLETE;\n request.index = segmentIndex - 1;\n request.mediaType = type;\n request.mediaInfo = mediaInfo;\n logger.debug('Signal complete in getSegmentRequestForTime');\n }\n }\n\n if (keepIdx && idx >= 0) {\n segmentIndex = representation.segmentInfoType === dashConstants.SEGMENT_TIMELINE && isDynamicManifest ? segmentIndex : idx;\n }\n\n return request;\n }\n\n function getNextSegmentRequest(mediaInfo, representation) {\n let request = null;\n\n if (!representation || !representation.segmentInfoType) {\n return null;\n }\n\n requestedTime = null;\n\n const indexToRequest = segmentIndex + 1;\n logger.debug('Getting the next request at index: ' + indexToRequest);\n\n // check that there is a segment in this index\n const segment = segmentsController.getSegmentByIndex(representation, indexToRequest, lastSegment ? lastSegment.mediaStartTime : -1);\n if (!segment && isEndlessMedia(representation) && !dynamicStreamCompleted) {\n logger.debug('No segment found at index: ' + indexToRequest + '. Wait for next loop');\n return null;\n } else {\n if (segment) {\n request = getRequestForSegment(mediaInfo, segment);\n segmentIndex = segment.availabilityIdx;\n } else {\n if (isDynamicManifest) {\n segmentIndex = indexToRequest - 1;\n } else {\n segmentIndex = indexToRequest;\n }\n }\n }\n\n if (segment) {\n lastSegment = segment;\n } else {\n const finished = isMediaFinished(representation, segment);\n if (finished) {\n request = new FragmentRequest();\n request.action = FragmentRequest.ACTION_COMPLETE;\n request.index = segmentIndex - 1;\n request.mediaType = getType();\n request.mediaInfo = mediaInfo;\n logger.debug('Signal complete');\n }\n }\n\n return request;\n }\n\n function isEndlessMedia(representation) {\n return !isFinite(representation.adaptation.period.duration);\n }\n\n function onInitializationLoaded(e) {\n const representation = e.representation;\n if (!representation.segments) return;\n\n eventBus.trigger(events.REPRESENTATION_UPDATE_COMPLETED, {sender: this, representation: representation});\n }\n\n function onSegmentsLoaded(e) {\n if (e.error || (getType() !== e.mediaType)) return;\n\n const fragments = e.segments;\n const representation = e.representation;\n const segments = [];\n let count = 0;\n\n let i,\n len,\n s,\n seg;\n\n for (i = 0, len = fragments ? fragments.length : 0; i < len; i++) {\n s = fragments[i];\n\n seg = getTimeBasedSegment(\n timelineConverter,\n isDynamicManifest,\n representation,\n s.startTime,\n s.duration,\n s.timescale,\n s.media,\n s.mediaRange,\n count);\n\n if (seg) {\n segments.push(seg);\n seg = null;\n count++;\n }\n }\n\n if (segments.length > 0) {\n representation.segmentAvailabilityRange = {start: segments[0].presentationStartTime, end: segments[segments.length - 1].presentationStartTime};\n representation.availableSegmentsNumber = segments.length;\n representation.segments = segments;\n\n if (isDynamicManifest) {\n const lastSegment = segments[segments.length - 1];\n const liveEdge = lastSegment.presentationStartTime - 8;\n // the last segment is the Expected, not calculated, live edge.\n setExpectedLiveEdge(liveEdge);\n }\n }\n\n if (!representation.hasInitialization()) {\n return;\n }\n\n eventBus.trigger(events.REPRESENTATION_UPDATE_COMPLETED, {sender: this, representation: representation});\n }\n\n function onDynamicStreamCompleted() {\n logger.debug('Dynamic stream complete');\n dynamicStreamCompleted = true;\n }\n\n instance = {\n initialize: initialize,\n getType: getType, //need to be public in order to be used by logger\n getStreamInfo: getStreamInfo,\n getInitRequest: getInitRequest,\n getRequestForSegment: getRequestForSegment,\n getSegmentRequestForTime: getSegmentRequestForTime,\n getNextSegmentRequest: getNextSegmentRequest,\n setCurrentTime: setCurrentTime,\n getCurrentTime: getCurrentTime,\n setCurrentIndex: setCurrentIndex,\n getCurrentIndex: getCurrentIndex,\n isMediaFinished: isMediaFinished,\n reset: reset,\n resetIndex: resetIndex,\n setMimeType: setMimeType\n };\n\n setup();\n\n return instance;\n}\n\nDashHandler.__dashjs_factory_name = 'DashHandler';\nexport default FactoryMaker.getClassFactory(DashHandler);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * Dash constants declaration\n * @class\n * @ignore\n */\nclass DashConstants {\n\n init() {\n this.BASE_URL = 'BaseURL';\n this.SEGMENT_BASE = 'SegmentBase';\n this.SEGMENT_TEMPLATE = 'SegmentTemplate';\n this.SEGMENT_LIST = 'SegmentList';\n this.SEGMENT_URL = 'SegmentURL';\n this.SEGMENT_TIMELINE = 'SegmentTimeline';\n this.SEGMENT_PROFILES = 'segmentProfiles';\n this.ADAPTATION_SET = 'AdaptationSet';\n this.REPRESENTATION = 'Representation';\n this.REPRESENTATION_INDEX = 'RepresentationIndex';\n this.SUB_REPRESENTATION = 'SubRepresentation';\n this.INITIALIZATION = 'Initialization';\n this.INITIALIZATION_MINUS = 'initialization';\n this.MPD = 'MPD';\n this.PERIOD = 'Period';\n this.ASSET_IDENTIFIER = 'AssetIdentifier';\n this.EVENT_STREAM = 'EventStream';\n this.ID = 'id';\n this.PROFILES = 'profiles';\n this.SERVICE_LOCATION = 'serviceLocation';\n this.RANGE = 'range';\n this.INDEX = 'index';\n this.MEDIA = 'media';\n this.BYTE_RANGE = 'byteRange';\n this.INDEX_RANGE = 'indexRange';\n this.MEDIA_RANGE = 'mediaRange';\n this.VALUE = 'value';\n this.CONTENT_TYPE = 'contentType';\n this.MIME_TYPE = 'mimeType';\n this.BITSTREAM_SWITCHING = 'BitstreamSwitching';\n this.BITSTREAM_SWITCHING_MINUS = 'bitstreamSwitching';\n this.CODECS = 'codecs';\n this.DEPENDENCY_ID = 'dependencyId';\n this.MEDIA_STREAM_STRUCTURE_ID = 'mediaStreamStructureId';\n this.METRICS = 'Metrics';\n this.METRICS_MINUS = 'metrics';\n this.REPORTING = 'Reporting';\n this.WIDTH = 'width';\n this.HEIGHT = 'height';\n this.SAR = 'sar';\n this.FRAMERATE = 'frameRate';\n this.AUDIO_SAMPLING_RATE = 'audioSamplingRate';\n this.MAXIMUM_SAP_PERIOD = 'maximumSAPPeriod';\n this.START_WITH_SAP = 'startWithSAP';\n this.MAX_PLAYOUT_RATE = 'maxPlayoutRate';\n this.CODING_DEPENDENCY = 'codingDependency';\n this.SCAN_TYPE = 'scanType';\n this.FRAME_PACKING = 'FramePacking';\n this.AUDIO_CHANNEL_CONFIGURATION = 'AudioChannelConfiguration';\n this.CONTENT_PROTECTION = 'ContentProtection';\n this.ESSENTIAL_PROPERTY = 'EssentialProperty';\n this.SUPPLEMENTAL_PROPERTY = 'SupplementalProperty';\n this.INBAND_EVENT_STREAM = 'InbandEventStream';\n this.ACCESSIBILITY = 'Accessibility';\n this.ROLE = 'Role';\n this.RATING = 'Rating';\n this.CONTENT_COMPONENT = 'ContentComponent';\n this.SUBSET = 'Subset';\n this.LANG = 'lang';\n this.VIEWPOINT = 'Viewpoint';\n this.ROLE_ASARRAY = 'Role_asArray';\n this.ACCESSIBILITY_ASARRAY = 'Accessibility_asArray';\n this.AUDIOCHANNELCONFIGURATION_ASARRAY = 'AudioChannelConfiguration_asArray';\n this.CONTENTPROTECTION_ASARRAY = 'ContentProtection_asArray';\n this.MAIN = 'main';\n this.DYNAMIC = 'dynamic';\n this.STATIC = 'static';\n this.MEDIA_PRESENTATION_DURATION = 'mediaPresentationDuration';\n this.MINIMUM_UPDATE_PERIOD = 'minimumUpdatePeriod';\n this.CODEC_PRIVATE_DATA = 'codecPrivateData';\n this.BANDWITH = 'bandwidth';\n this.SOURCE_URL = 'sourceURL';\n this.TIMESCALE = 'timescale';\n this.DURATION = 'duration';\n this.START_NUMBER = 'startNumber';\n this.PRESENTATION_TIME_OFFSET = 'presentationTimeOffset';\n this.AVAILABILITY_START_TIME = 'availabilityStartTime';\n this.AVAILABILITY_END_TIME = 'availabilityEndTime';\n this.TIMESHIFT_BUFFER_DEPTH = 'timeShiftBufferDepth';\n this.MAX_SEGMENT_DURATION = 'maxSegmentDuration';\n this.PRESENTATION_TIME = 'presentationTime';\n this.MIN_BUFFER_TIME = 'minBufferTime';\n this.MAX_SUBSEGMENT_DURATION = 'maxSubsegmentDuration';\n this.START = 'start';\n this.AVAILABILITY_TIME_OFFSET = 'availabilityTimeOffset';\n this.AVAILABILITY_TIME_COMPLETE = 'availabilityTimeComplete';\n this.CENC_DEFAULT_KID = 'cenc:default_KID';\n this.DVB_PRIORITY = 'dvb:priority';\n this.DVB_WEIGHT = 'dvb:weight';\n this.SUGGESTED_PRESENTATION_DELAY = 'suggestedPresentationDelay';\n this.SERVICE_DESCRIPTION = 'ServiceDescription';\n this.SERVICE_DESCRIPTION_SCOPE = 'Scope';\n this.SERVICE_DESCRIPTION_LATENCY = 'Latency';\n this.SERVICE_DESCRIPTION_PLAYBACK_RATE = 'PlaybackRate';\n }\n\n constructor () {\n this.init();\n }\n}\n\nlet constants = new DashConstants();\nexport default constants;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport Constants from '../../streaming/constants/Constants';\nimport DashJSError from '../../streaming/vo/DashJSError';\nimport FactoryMaker from '../../core/FactoryMaker';\n\nfunction RepresentationController(config) {\n\n config = config || {};\n const eventBus = config.eventBus;\n const events = config.events;\n const errors = config.errors;\n const abrController = config.abrController;\n const dashMetrics = config.dashMetrics;\n const playbackController = config.playbackController;\n const timelineConverter = config.timelineConverter;\n const type = config.type;\n const streamId = config.streamId;\n const dashConstants = config.dashConstants;\n\n let instance,\n realAdaptation,\n updating,\n voAvailableRepresentations,\n currentVoRepresentation;\n\n function setup() {\n resetInitialSettings();\n\n eventBus.on(events.QUALITY_CHANGE_REQUESTED, onQualityChanged, instance);\n eventBus.on(events.REPRESENTATION_UPDATE_COMPLETED, onRepresentationUpdated, instance);\n eventBus.on(events.WALLCLOCK_TIME_UPDATED, onWallclockTimeUpdated, instance);\n eventBus.on(events.MANIFEST_VALIDITY_CHANGED, onManifestValidityChanged, instance);\n }\n\n function checkConfig() {\n if (!abrController || !dashMetrics || !playbackController || !timelineConverter) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function getData() {\n return realAdaptation;\n }\n\n function isUpdating() {\n return updating;\n }\n\n function getCurrentRepresentation() {\n return currentVoRepresentation;\n }\n\n function resetInitialSettings() {\n realAdaptation = null;\n updating = true;\n voAvailableRepresentations = [];\n }\n\n function reset() {\n\n eventBus.off(events.QUALITY_CHANGE_REQUESTED, onQualityChanged, instance);\n eventBus.off(events.REPRESENTATION_UPDATE_COMPLETED, onRepresentationUpdated, instance);\n eventBus.off(events.WALLCLOCK_TIME_UPDATED, onWallclockTimeUpdated, instance);\n eventBus.off(events.MANIFEST_VALIDITY_CHANGED, onManifestValidityChanged, instance);\n\n resetInitialSettings();\n }\n\n function getType() {\n return type;\n }\n\n function getStreamId() {\n return streamId;\n }\n\n function updateData(newRealAdaptation, availableRepresentations, type, quality) {\n checkConfig();\n\n startDataUpdate();\n\n voAvailableRepresentations = availableRepresentations;\n\n currentVoRepresentation = getRepresentationForQuality(quality);\n realAdaptation = newRealAdaptation;\n\n if (type !== Constants.VIDEO && type !== Constants.AUDIO && type !== Constants.FRAGMENTED_TEXT) {\n endDataUpdate();\n return;\n }\n\n updateAvailabilityWindow(playbackController.getIsDynamic(), true);\n }\n\n function addRepresentationSwitch() {\n checkConfig();\n const now = new Date();\n const currentRepresentation = getCurrentRepresentation();\n const currentVideoTimeMs = playbackController.getTime() * 1000;\n if (currentRepresentation) {\n dashMetrics.addRepresentationSwitch(currentRepresentation.adaptation.type, now, currentVideoTimeMs, currentRepresentation.id);\n }\n }\n\n function getRepresentationForQuality(quality) {\n return quality === null || quality === undefined || quality >= voAvailableRepresentations.length ? null : voAvailableRepresentations[quality];\n }\n\n function getQualityForRepresentation(voRepresentation) {\n return voAvailableRepresentations.indexOf(voRepresentation);\n }\n\n function isAllRepresentationsUpdated() {\n for (let i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {\n let segmentInfoType = voAvailableRepresentations[i].segmentInfoType;\n if (voAvailableRepresentations[i].segmentAvailabilityRange === null || !voAvailableRepresentations[i].hasInitialization() ||\n ((segmentInfoType === dashConstants.SEGMENT_BASE || segmentInfoType === dashConstants.BASE_URL) && !voAvailableRepresentations[i].segments)\n ) {\n return false;\n }\n }\n\n return true;\n }\n\n function setExpectedLiveEdge(liveEdge) {\n timelineConverter.setExpectedLiveEdge(liveEdge);\n dashMetrics.updateManifestUpdateInfo({presentationStartTime: liveEdge});\n }\n\n function updateRepresentation(representation, isDynamic) {\n representation.segmentAvailabilityRange = timelineConverter.calcSegmentAvailabilityRange(representation, isDynamic);\n\n if ((representation.segmentAvailabilityRange.end < representation.segmentAvailabilityRange.start) && !representation.useCalculatedLiveEdgeTime) {\n let error = new DashJSError(errors.SEGMENTS_UNAVAILABLE_ERROR_CODE, errors.SEGMENTS_UNAVAILABLE_ERROR_MESSAGE, {availabilityDelay: representation.segmentAvailabilityRange.start - representation.segmentAvailabilityRange.end});\n endDataUpdate(error);\n return;\n }\n\n if (isDynamic) {\n setExpectedLiveEdge(representation.segmentAvailabilityRange.end);\n }\n }\n\n function updateAvailabilityWindow(isDynamic, notifyUpdate) {\n checkConfig();\n\n for (let i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {\n updateRepresentation(voAvailableRepresentations[i], isDynamic);\n if (notifyUpdate) {\n eventBus.trigger(events.REPRESENTATION_UPDATE_STARTED, {\n sender: instance,\n representation: voAvailableRepresentations[i]\n });\n }\n }\n }\n\n function resetAvailabilityWindow() {\n voAvailableRepresentations.forEach(rep => {\n rep.segmentAvailabilityRange = null;\n });\n }\n\n function startDataUpdate() {\n updating = true;\n eventBus.trigger(events.DATA_UPDATE_STARTED, {sender: instance});\n }\n\n function endDataUpdate(error) {\n updating = false;\n let eventArg = {sender: instance, data: realAdaptation, currentRepresentation: currentVoRepresentation};\n if (error) {\n eventArg.error = error;\n }\n eventBus.trigger(events.DATA_UPDATE_COMPLETED, eventArg);\n }\n\n function postponeUpdate(postponeTimePeriod) {\n let delay = postponeTimePeriod;\n let update = function () {\n if (isUpdating()) return;\n\n startDataUpdate();\n\n // clear the segmentAvailabilityRange for all reps.\n // this ensures all are updated before the live edge search starts\n resetAvailabilityWindow();\n\n updateAvailabilityWindow(playbackController.getIsDynamic(), true);\n };\n eventBus.trigger(events.AST_IN_FUTURE, {delay: delay});\n setTimeout(update, delay);\n }\n\n function onRepresentationUpdated(e) {\n if (e.sender.getType() !== getType() || e.sender.getStreamInfo().id !== streamId || !isUpdating()) return;\n\n if (e.error) {\n endDataUpdate(e.error);\n return;\n }\n\n let streamInfo = e.sender.getStreamInfo();\n let r = e.representation;\n let manifestUpdateInfo = dashMetrics.getCurrentManifestUpdate();\n let alreadyAdded = false;\n let postponeTimePeriod = 0;\n let repInfo,\n err,\n repSwitch;\n\n if (r.adaptation.period.mpd.manifest.type === dashConstants.DYNAMIC && !r.adaptation.period.mpd.manifest.ignorePostponeTimePeriod) {\n // We must put things to sleep unless till e.g. the startTime calculation in ScheduleController.onLiveEdgeSearchCompleted fall after the segmentAvailabilityRange.start\n postponeTimePeriod = getRepresentationUpdatePostponeTimePeriod(r, streamInfo);\n }\n\n if (postponeTimePeriod > 0) {\n postponeUpdate(postponeTimePeriod);\n err = new DashJSError(errors.SEGMENTS_UPDATE_FAILED_ERROR_CODE, errors.SEGMENTS_UPDATE_FAILED_ERROR_MESSAGE);\n endDataUpdate(err);\n return;\n }\n\n if (manifestUpdateInfo) {\n for (let i = 0; i < manifestUpdateInfo.representationInfo.length; i++) {\n repInfo = manifestUpdateInfo.representationInfo[i];\n if (repInfo.index === r.index && repInfo.mediaType === getType()) {\n alreadyAdded = true;\n break;\n }\n }\n\n if (!alreadyAdded) {\n dashMetrics.addManifestUpdateRepresentationInfo(r, getType());\n }\n }\n\n if (isAllRepresentationsUpdated()) {\n abrController.setPlaybackQuality(getType(), streamInfo, getQualityForRepresentation(currentVoRepresentation));\n dashMetrics.updateManifestUpdateInfo({latency: currentVoRepresentation.segmentAvailabilityRange.end - playbackController.getTime()});\n\n repSwitch = dashMetrics.getCurrentRepresentationSwitch(getCurrentRepresentation().adaptation.type);\n\n if (!repSwitch) {\n addRepresentationSwitch();\n }\n endDataUpdate();\n }\n }\n\n function getRepresentationUpdatePostponeTimePeriod(representation, streamInfo) {\n try {\n const streamController = playbackController.getStreamController();\n const activeStreamInfo = streamController.getActiveStreamInfo();\n let startTimeAnchor = representation.segmentAvailabilityRange.start;\n\n if (activeStreamInfo && activeStreamInfo.id && activeStreamInfo.id !== streamInfo.id) {\n // We need to consider the currently playing period if a period switch is performed.\n startTimeAnchor = Math.min(playbackController.getTime(), startTimeAnchor);\n }\n\n let segmentAvailabilityTimePeriod = representation.segmentAvailabilityRange.end - startTimeAnchor;\n let liveDelay = playbackController.getLiveDelay();\n\n return (liveDelay - segmentAvailabilityTimePeriod) * 1000;\n } catch (e) {\n return 0;\n }\n }\n\n function onWallclockTimeUpdated(e) {\n if (e.isDynamic) {\n updateAvailabilityWindow(e.isDynamic);\n }\n }\n\n function onQualityChanged(e) {\n if (e.mediaType !== getType() || streamId !== e.streamInfo.id) return;\n\n currentVoRepresentation = getRepresentationForQuality(e.newQuality);\n addRepresentationSwitch();\n }\n\n function onManifestValidityChanged(e) {\n if (e.newDuration) {\n const representation = getCurrentRepresentation();\n if (representation && representation.adaptation.period) {\n const period = representation.adaptation.period;\n period.duration = e.newDuration;\n }\n }\n }\n\n instance = {\n getData: getData,\n isUpdating: isUpdating,\n updateData: updateData,\n updateRepresentation: updateRepresentation,\n getCurrentRepresentation: getCurrentRepresentation,\n getRepresentationForQuality: getRepresentationForQuality,\n getType: getType,\n getStreamId: getStreamId,\n reset: reset\n };\n\n setup();\n return instance;\n}\n\nRepresentationController.__dashjs_factory_name = 'RepresentationController';\nexport default FactoryMaker.getClassFactory(RepresentationController);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\nimport TimelineSegmentsGetter from '../utils/TimelineSegmentsGetter';\nimport TemplateSegmentsGetter from '../utils/TemplateSegmentsGetter';\nimport ListSegmentsGetter from '../utils/ListSegmentsGetter';\nimport SegmentBaseGetter from '../utils/SegmentBaseGetter';\n\nfunction SegmentsController(config) {\n config = config || {};\n\n const context = this.context;\n const events = config.events;\n const eventBus = config.eventBus;\n const dashConstants = config.dashConstants;\n\n let instance,\n getters;\n\n function setup() {\n getters = {};\n }\n\n function initialize(isDynamic) {\n getters[dashConstants.SEGMENT_TIMELINE] = TimelineSegmentsGetter(context).create(config, isDynamic);\n getters[dashConstants.SEGMENT_TEMPLATE] = TemplateSegmentsGetter(context).create(config, isDynamic);\n getters[dashConstants.SEGMENT_LIST] = ListSegmentsGetter(context).create(config, isDynamic);\n getters[dashConstants.SEGMENT_BASE] = SegmentBaseGetter(context).create(config, isDynamic);\n }\n\n function update(voRepresentation, type, mimeType, hasInitialization, hasSegments) {\n if (!hasInitialization) {\n eventBus.trigger(events.SEGMENTBASE_INIT_REQUEST_NEEDED, {mimeType: mimeType, representation: voRepresentation});\n }\n\n if (!hasSegments) {\n eventBus.trigger(events.SEGMENTBASE_SEGMENTSLIST_REQUEST_NEEDED, {mimeType: mimeType, mediaType: type, representation: voRepresentation});\n }\n }\n\n function getSegmentsGetter(representation) {\n return representation ? representation.segments ? getters[dashConstants.SEGMENT_BASE] : getters[representation.segmentInfoType] : null;\n }\n\n function getSegmentByIndex(representation, index, lastSegmentTime) {\n const getter = getSegmentsGetter(representation);\n return getter ? getter.getSegmentByIndex(representation, index, lastSegmentTime) : null;\n }\n\n function getSegmentByTime(representation, time) {\n const getter = getSegmentsGetter(representation);\n return getter ? getter.getSegmentByTime(representation, time) : null;\n }\n\n instance = {\n initialize: initialize,\n update: update,\n getSegmentByIndex: getSegmentByIndex,\n getSegmentByTime: getSegmentByTime\n };\n\n setup();\n\n return instance;\n}\n\nSegmentsController.__dashjs_factory_name = 'SegmentsController';\nconst factory = FactoryMaker.getClassFactory(SegmentsController);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport Constants from '../../streaming/constants/Constants';\nimport DashConstants from '../constants/DashConstants';\nimport Representation from '../vo/Representation';\nimport AdaptationSet from '../vo/AdaptationSet';\nimport Period from '../vo/Period';\nimport Mpd from '../vo/Mpd';\nimport UTCTiming from '../vo/UTCTiming';\nimport Event from '../vo/Event';\nimport BaseURL from '../vo/BaseURL';\nimport EventStream from '../vo/EventStream';\nimport ObjectUtils from '../../streaming/utils/ObjectUtils';\nimport URLUtils from '../../streaming/utils/URLUtils';\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Debug from '../../core/Debug';\nimport DashJSError from '../../streaming/vo/DashJSError';\nimport Errors from '../../core/errors/Errors';\nimport { THUMBNAILS_SCHEME_ID_URIS } from '../../streaming/thumbnail/ThumbnailTracks';\n\nfunction DashManifestModel() {\n let instance,\n logger,\n errHandler,\n BASE64;\n\n const context = this.context;\n const urlUtils = URLUtils(context).getInstance();\n\n const isInteger = Number.isInteger || function (value) {\n return typeof value === 'number' &&\n isFinite(value) &&\n Math.floor(value) === value;\n };\n\n function setup () {\n logger = Debug(context).getInstance().getLogger(instance);\n }\n\n function getIsTypeOf(adaptation, type) {\n\n let i,\n len,\n representation,\n col,\n mimeTypeRegEx,\n codecs;\n let result = false;\n let found = false;\n\n if (!adaptation) {\n throw new Error('adaptation is not defined');\n }\n\n if (!type) {\n throw new Error('type is not defined');\n }\n\n if (adaptation.hasOwnProperty('ContentComponent_asArray')) {\n col = adaptation.ContentComponent_asArray;\n }\n\n mimeTypeRegEx = (type !== Constants.TEXT) ? new RegExp(type) : new RegExp('(vtt|ttml)');\n\n if (adaptation.Representation_asArray && adaptation.Representation_asArray.length && adaptation.Representation_asArray.length > 0) {\n let essentialProperties = getEssentialPropertiesForRepresentation(adaptation.Representation_asArray[0]);\n if (essentialProperties && essentialProperties.length > 0 && THUMBNAILS_SCHEME_ID_URIS.indexOf(essentialProperties[0].schemeIdUri) >= 0) {\n return type === Constants.IMAGE;\n }\n if (adaptation.Representation_asArray[0].hasOwnProperty(DashConstants.CODECS)) {\n // Just check the start of the codecs string\n codecs = adaptation.Representation_asArray[0].codecs;\n if (codecs.search(Constants.STPP) === 0 || codecs.search(Constants.WVTT) === 0) {\n return type === Constants.FRAGMENTED_TEXT;\n }\n }\n }\n\n if (col) {\n if (col.length > 1) {\n return (type === Constants.MUXED);\n } else if (col[0] && col[0].contentType === type) {\n result = true;\n found = true;\n }\n }\n\n if (adaptation.hasOwnProperty(DashConstants.MIME_TYPE)) {\n result = mimeTypeRegEx.test(adaptation.mimeType);\n found = true;\n }\n\n // couldn't find on adaptationset, so check a representation\n if (!found) {\n i = 0;\n len = adaptation.Representation_asArray && adaptation.Representation_asArray.length ? adaptation.Representation_asArray.length : 0;\n while (!found && i < len) {\n representation = adaptation.Representation_asArray[i];\n\n if (representation.hasOwnProperty(DashConstants.MIME_TYPE)) {\n result = mimeTypeRegEx.test(representation.mimeType);\n found = true;\n }\n\n i++;\n }\n }\n\n return result;\n }\n\n function getIsAudio(adaptation) {\n return getIsTypeOf(adaptation, Constants.AUDIO);\n }\n\n function getIsVideo(adaptation) {\n return getIsTypeOf(adaptation, Constants.VIDEO);\n }\n\n function getIsFragmentedText(adaptation) {\n return getIsTypeOf(adaptation, Constants.FRAGMENTED_TEXT);\n }\n\n function getIsMuxed(adaptation) {\n return getIsTypeOf(adaptation, Constants.MUXED);\n }\n\n function getIsImage(adaptation) {\n return getIsTypeOf(adaptation, Constants.IMAGE);\n }\n\n function getIsTextTrack(type) {\n return (type === 'text/vtt' || type === 'application/ttml+xml');\n }\n\n function getLanguageForAdaptation(adaptation) {\n let lang = '';\n\n if (adaptation && adaptation.hasOwnProperty(DashConstants.LANG)) {\n //Filter out any other characters not allowed according to RFC5646\n lang = adaptation.lang.replace(/[^A-Za-z0-9-]/g, '');\n }\n\n return lang;\n }\n\n function getViewpointForAdaptation(adaptation) {\n return adaptation && adaptation.hasOwnProperty(DashConstants.VIEWPOINT) ? adaptation.Viewpoint : null;\n }\n\n function getRolesForAdaptation(adaptation) {\n return adaptation && adaptation.hasOwnProperty(DashConstants.ROLE_ASARRAY) ? adaptation.Role_asArray : [];\n }\n\n function getAccessibilityForAdaptation(adaptation) {\n return adaptation && adaptation.hasOwnProperty(DashConstants.ACCESSIBILITY_ASARRAY) ? adaptation.Accessibility_asArray : [];\n }\n\n function getAudioChannelConfigurationForAdaptation(adaptation) {\n return adaptation && adaptation.hasOwnProperty(DashConstants.AUDIOCHANNELCONFIGURATION_ASARRAY) ? adaptation.AudioChannelConfiguration_asArray : [];\n }\n\n function getAudioChannelConfigurationForRepresentation(representation) {\n return representation && representation.hasOwnProperty(DashConstants.AUDIOCHANNELCONFIGURATION_ASARRAY) ? representation.AudioChannelConfiguration_asArray : [];\n }\n\n function getRepresentationSortFunction() {\n return (a, b) => a.bandwidth - b.bandwidth;\n }\n\n function processAdaptation(realAdaptation) {\n if (realAdaptation && Array.isArray(realAdaptation.Representation_asArray)) {\n realAdaptation.Representation_asArray.sort(getRepresentationSortFunction());\n }\n\n return realAdaptation;\n }\n\n function getRealAdaptations(manifest, periodIndex) {\n return manifest && manifest.Period_asArray && isInteger(periodIndex) ? manifest.Period_asArray[periodIndex] ? manifest.Period_asArray[periodIndex].AdaptationSet_asArray : [] : [];\n }\n\n function getAdaptationForId(id, manifest, periodIndex) {\n const realAdaptations = getRealAdaptations(manifest, periodIndex);\n let i,\n len;\n\n for (i = 0, len = realAdaptations.length; i < len; i++) {\n if (realAdaptations[i].hasOwnProperty(DashConstants.ID) && realAdaptations[i].id === id) {\n return realAdaptations[i];\n }\n }\n\n return null;\n }\n\n function getAdaptationForIndex(index, manifest, periodIndex) {\n const realAdaptations = getRealAdaptations(manifest, periodIndex);\n if (realAdaptations.length > 0 && isInteger(index)) {\n return realAdaptations[index];\n } else {\n return null;\n }\n }\n\n function getIndexForAdaptation(realAdaptation, manifest, periodIndex) {\n if (!realAdaptation) {\n return -1;\n }\n\n const realAdaptations = getRealAdaptations(manifest, periodIndex);\n\n for (let i = 0; i < realAdaptations.length; i++) {\n let objectUtils = ObjectUtils(context).getInstance();\n if (objectUtils.areEqual(realAdaptations[i], realAdaptation)) {\n return i;\n }\n }\n\n return -1;\n }\n\n function getAdaptationsForType(manifest, periodIndex, type) {\n const realAdaptations = getRealAdaptations(manifest, periodIndex);\n let i,\n len;\n const adaptations = [];\n\n for (i = 0, len = realAdaptations.length; i < len; i++) {\n if (getIsTypeOf(realAdaptations[i], type)) {\n adaptations.push(processAdaptation(realAdaptations[i]));\n }\n }\n\n return adaptations;\n }\n\n function getCodec(adaptation, representationId, addResolutionInfo) {\n let codec = null;\n\n if (adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0) {\n const representation = isInteger(representationId) && representationId >= 0 && representationId < adaptation.Representation_asArray.length ?\n adaptation.Representation_asArray[representationId] : adaptation.Representation_asArray[0];\n if (representation) {\n codec = representation.mimeType + ';codecs=\"' + representation.codecs + '\"';\n if (addResolutionInfo && representation.width !== undefined) {\n codec += ';width=\"' + representation.width + '\";height=\"' + representation.height + '\"';\n }\n }\n }\n\n // If the codec contains a profiles parameter we remove it. Otherwise it will cause problems when checking for codec capabilities of the platform\n if (codec) {\n codec = codec.replace(/\\sprofiles=[^;]*/g, '');\n }\n\n return codec;\n }\n\n function getMimeType(adaptation) {\n return adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0 ? adaptation.Representation_asArray[0].mimeType : null;\n }\n\n function getKID(adaptation) {\n if (!adaptation || !adaptation.hasOwnProperty(DashConstants.CENC_DEFAULT_KID)) {\n return null;\n }\n return adaptation[DashConstants.CENC_DEFAULT_KID];\n }\n\n function getLabelsForAdaptation(adaptation) {\n if (!adaptation || !Array.isArray(adaptation.Label_asArray)) {\n return [];\n }\n\n const labelArray = [];\n\n for (let i = 0; i < adaptation.Label_asArray.length; i++) {\n labelArray.push({\n lang: adaptation.Label_asArray[i].lang,\n text: adaptation.Label_asArray[i].__text || adaptation.Label_asArray[i]\n });\n }\n\n return labelArray;\n }\n\n function getContentProtectionData(adaptation) {\n if (!adaptation || !adaptation.hasOwnProperty(DashConstants.CONTENTPROTECTION_ASARRAY) || adaptation.ContentProtection_asArray.length === 0) {\n return null;\n }\n return adaptation.ContentProtection_asArray;\n }\n\n function getIsDynamic(manifest) {\n let isDynamic = false;\n if (manifest && manifest.hasOwnProperty('type')) {\n isDynamic = (manifest.type === DashConstants.DYNAMIC);\n }\n return isDynamic;\n }\n\n function hasProfile(manifest, profile) {\n let has = false;\n\n if (manifest && manifest.profiles && manifest.profiles.length > 0) {\n has = (manifest.profiles.indexOf(profile) !== -1);\n }\n\n return has;\n }\n\n function getDuration(manifest) {\n let mpdDuration;\n //@mediaPresentationDuration specifies the duration of the entire Media Presentation.\n //If the attribute is not present, the duration of the Media Presentation is unknown.\n if (manifest && manifest.hasOwnProperty(DashConstants.MEDIA_PRESENTATION_DURATION)) {\n mpdDuration = manifest.mediaPresentationDuration;\n } else if (manifest && manifest.type == 'dynamic') {\n mpdDuration = Number.POSITIVE_INFINITY;\n } else {\n mpdDuration = Number.MAX_SAFE_INTEGER || Number.MAX_VALUE;\n }\n\n return mpdDuration;\n }\n\n function getBandwidth(representation) {\n return representation && representation.bandwidth ? representation.bandwidth : NaN;\n }\n\n function getManifestUpdatePeriod(manifest, latencyOfLastUpdate = 0) {\n let delay = NaN;\n if (manifest && manifest.hasOwnProperty(DashConstants.MINIMUM_UPDATE_PERIOD)) {\n delay = manifest.minimumUpdatePeriod;\n }\n return isNaN(delay) ? delay : Math.max(delay - latencyOfLastUpdate, 1);\n }\n\n function getRepresentationCount(adaptation) {\n return adaptation && Array.isArray(adaptation.Representation_asArray) ? adaptation.Representation_asArray.length : 0;\n }\n\n function getBitrateListForAdaptation(realAdaptation) {\n const processedRealAdaptation = processAdaptation(realAdaptation);\n const realRepresentations = processedRealAdaptation && Array.isArray(processedRealAdaptation.Representation_asArray) ? processedRealAdaptation.Representation_asArray : [];\n\n return realRepresentations.map((realRepresentation) => {\n return {\n bandwidth: realRepresentation.bandwidth,\n width: realRepresentation.width || 0,\n height: realRepresentation.height || 0,\n scanType: realRepresentation.scanType || null,\n id: realRepresentation.id || null\n };\n });\n }\n\n function getEssentialPropertiesForRepresentation(realRepresentation) {\n if (!realRepresentation || ! realRepresentation.EssentialProperty_asArray || !realRepresentation.EssentialProperty_asArray.length) return null;\n\n return realRepresentation.EssentialProperty_asArray.map( (prop) => {\n return {\n schemeIdUri: prop.schemeIdUri,\n value: prop.value\n };\n });\n }\n\n function getRepresentationFor(index, adaptation) {\n return adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0 &&\n isInteger(index) ? adaptation.Representation_asArray[index] : null;\n }\n\n function getRealAdaptationFor(voAdaptation) {\n if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {\n const periodArray = voAdaptation.period.mpd.manifest.Period_asArray[voAdaptation.period.index];\n if (periodArray && periodArray.AdaptationSet_asArray && isInteger(voAdaptation.index)) {\n return processAdaptation(periodArray.AdaptationSet_asArray[voAdaptation.index]);\n }\n }\n }\n\n function isLastRepeatAttributeValid(segmentTimeline) {\n let s = segmentTimeline.S_asArray[segmentTimeline.S_asArray.length - 1];\n return !s.hasOwnProperty('r') || s.r >= 0;\n }\n\n function getUseCalculatedLiveEdgeTimeForAdaptation(voAdaptation) {\n let realAdaptation = getRealAdaptationFor(voAdaptation);\n let realRepresentation = realAdaptation && Array.isArray(realAdaptation.Representation_asArray) ? realAdaptation.Representation_asArray[0] : null;\n let segmentInfo;\n if (realRepresentation) {\n if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_LIST)) {\n segmentInfo = realRepresentation.SegmentList;\n return segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE) ?\n isLastRepeatAttributeValid(segmentInfo.SegmentTimeline) :\n true;\n } else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE)) {\n segmentInfo = realRepresentation.SegmentTemplate;\n if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {\n return isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);\n }\n }\n }\n\n return false;\n }\n\n function getRepresentationsForAdaptation(voAdaptation) {\n const voRepresentations = [];\n const processedRealAdaptation = getRealAdaptationFor(voAdaptation);\n let segmentInfo,\n baseUrl;\n\n if (processedRealAdaptation && processedRealAdaptation.Representation_asArray) {\n // TODO: TO BE REMOVED. We should get just the baseUrl elements that affects to the representations\n // that we are processing. Making it works properly will require much further changes and given\n // parsing base Urls parameters is needed for our ultra low latency examples, we will\n // keep this \"tricky\" code until the real (and good) solution comes\n if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {\n const baseUrls = getBaseURLsFromElement(voAdaptation.period.mpd.manifest);\n if (baseUrls) {\n baseUrl = baseUrls[0];\n }\n }\n for (let i = 0, len = processedRealAdaptation.Representation_asArray.length; i < len; ++i) {\n const realRepresentation = processedRealAdaptation.Representation_asArray[i];\n const voRepresentation = new Representation();\n voRepresentation.index = i;\n voRepresentation.adaptation = voAdaptation;\n\n if (realRepresentation.hasOwnProperty(DashConstants.ID)) {\n voRepresentation.id = realRepresentation.id;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.CODECS)) {\n voRepresentation.codecs = realRepresentation.codecs;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.CODEC_PRIVATE_DATA)) {\n voRepresentation.codecPrivateData = realRepresentation.codecPrivateData;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.BANDWITH)) {\n voRepresentation.bandwidth = realRepresentation.bandwidth;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.WIDTH)) {\n voRepresentation.width = realRepresentation.width;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.HEIGHT)) {\n voRepresentation.height = realRepresentation.height;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.SCAN_TYPE)) {\n voRepresentation.scanType = realRepresentation.scanType;\n }\n if (realRepresentation.hasOwnProperty(DashConstants.MAX_PLAYOUT_RATE)) {\n voRepresentation.maxPlayoutRate = realRepresentation.maxPlayoutRate;\n }\n\n if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_BASE)) {\n segmentInfo = realRepresentation.SegmentBase;\n voRepresentation.segmentInfoType = DashConstants.SEGMENT_BASE;\n } else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_LIST)) {\n segmentInfo = realRepresentation.SegmentList;\n\n if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {\n voRepresentation.segmentInfoType = DashConstants.SEGMENT_TIMELINE;\n voRepresentation.useCalculatedLiveEdgeTime = isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);\n } else {\n voRepresentation.segmentInfoType = DashConstants.SEGMENT_LIST;\n voRepresentation.useCalculatedLiveEdgeTime = true;\n }\n } else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE)) {\n segmentInfo = realRepresentation.SegmentTemplate;\n\n if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {\n voRepresentation.segmentInfoType = DashConstants.SEGMENT_TIMELINE;\n voRepresentation.useCalculatedLiveEdgeTime = isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);\n } else {\n voRepresentation.segmentInfoType = DashConstants.SEGMENT_TEMPLATE;\n }\n\n if (segmentInfo.hasOwnProperty(DashConstants.INITIALIZATION_MINUS)) {\n voRepresentation.initialization = segmentInfo.initialization.split('$Bandwidth$')\n .join(realRepresentation.bandwidth).split('$RepresentationID$').join(realRepresentation.id);\n }\n } else {\n voRepresentation.segmentInfoType = DashConstants.BASE_URL;\n }\n\n voRepresentation.essentialProperties = getEssentialPropertiesForRepresentation(realRepresentation);\n\n if (segmentInfo) {\n if (segmentInfo.hasOwnProperty(DashConstants.INITIALIZATION)) {\n const initialization = segmentInfo.Initialization;\n\n if (initialization.hasOwnProperty(DashConstants.SOURCE_URL)) {\n voRepresentation.initialization = initialization.sourceURL;\n }\n\n if (initialization.hasOwnProperty(DashConstants.RANGE)) {\n voRepresentation.range = initialization.range;\n // initialization source url will be determined from\n // BaseURL when resolved at load time.\n }\n } else if (realRepresentation.hasOwnProperty(DashConstants.MIME_TYPE) && getIsTextTrack(realRepresentation.mimeType)) {\n voRepresentation.range = 0;\n }\n\n if (segmentInfo.hasOwnProperty(DashConstants.TIMESCALE)) {\n voRepresentation.timescale = segmentInfo.timescale;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.DURATION)) {\n // TODO according to the spec @maxSegmentDuration specifies the maximum duration of any Segment in any Representation in the Media Presentation\n // It is also said that for a SegmentTimeline any @d value shall not exceed the value of MPD@maxSegmentDuration, but nothing is said about\n // SegmentTemplate @duration attribute. We need to find out if @maxSegmentDuration should be used instead of calculated duration if the the duration\n // exceeds @maxSegmentDuration\n voRepresentation.segmentDuration = segmentInfo.duration / voRepresentation.timescale;\n } else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE)) {\n segmentInfo = realRepresentation.SegmentTemplate;\n\n if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {\n voRepresentation.segmentDuration = calcSegmentDuration(segmentInfo.SegmentTimeline) / voRepresentation.timescale;\n }\n }\n if (segmentInfo.hasOwnProperty(DashConstants.MEDIA)) {\n voRepresentation.media = segmentInfo.media;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.START_NUMBER)) {\n voRepresentation.startNumber = segmentInfo.startNumber;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.INDEX_RANGE)) {\n voRepresentation.indexRange = segmentInfo.indexRange;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.PRESENTATION_TIME_OFFSET)) {\n voRepresentation.presentationTimeOffset = segmentInfo.presentationTimeOffset / voRepresentation.timescale;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.AVAILABILITY_TIME_OFFSET)) {\n voRepresentation.availabilityTimeOffset = segmentInfo.availabilityTimeOffset;\n } else if (baseUrl && baseUrl.availabilityTimeOffset !== undefined) {\n voRepresentation.availabilityTimeOffset = baseUrl.availabilityTimeOffset;\n }\n if (segmentInfo.hasOwnProperty(DashConstants.AVAILABILITY_TIME_COMPLETE)) {\n voRepresentation.availabilityTimeComplete = segmentInfo.availabilityTimeComplete !== 'false';\n } else if (baseUrl && baseUrl.availabilityTimeComplete !== undefined) {\n voRepresentation.availabilityTimeComplete = baseUrl.availabilityTimeComplete;\n }\n }\n\n voRepresentation.MSETimeOffset = calcMSETimeOffset(voRepresentation);\n voRepresentation.path = [voAdaptation.period.index, voAdaptation.index, i];\n voRepresentations.push(voRepresentation);\n }\n }\n\n return voRepresentations;\n }\n\n function calcSegmentDuration(segmentTimeline) {\n let s0 = segmentTimeline.S_asArray[0];\n let s1 = segmentTimeline.S_asArray[1];\n return s0.hasOwnProperty('d') ? s0.d : (s1.t - s0.t);\n }\n\n function calcMSETimeOffset(representation) {\n // The MSEOffset is offset from AST for media. It is Period@start - presentationTimeOffset\n const presentationOffset = representation.presentationTimeOffset;\n const periodStart = representation.adaptation.period.start;\n return (periodStart - presentationOffset);\n }\n\n function getAdaptationsForPeriod(voPeriod) {\n const realPeriod = voPeriod && isInteger(voPeriod.index) ? voPeriod.mpd.manifest.Period_asArray[voPeriod.index] : null;\n const voAdaptations = [];\n let voAdaptationSet,\n realAdaptationSet,\n i;\n\n if (realPeriod && realPeriod.AdaptationSet_asArray) {\n for (i = 0; i < realPeriod.AdaptationSet_asArray.length; i++) {\n realAdaptationSet = realPeriod.AdaptationSet_asArray[i];\n voAdaptationSet = new AdaptationSet();\n if (realAdaptationSet.hasOwnProperty(DashConstants.ID)) {\n voAdaptationSet.id = realAdaptationSet.id;\n }\n voAdaptationSet.index = i;\n voAdaptationSet.period = voPeriod;\n\n if (getIsMuxed(realAdaptationSet)) {\n voAdaptationSet.type = Constants.MUXED;\n } else if (getIsAudio(realAdaptationSet)) {\n voAdaptationSet.type = Constants.AUDIO;\n } else if (getIsVideo(realAdaptationSet)) {\n voAdaptationSet.type = Constants.VIDEO;\n } else if (getIsFragmentedText(realAdaptationSet)) {\n voAdaptationSet.type = Constants.FRAGMENTED_TEXT;\n } else if (getIsImage(realAdaptationSet)) {\n voAdaptationSet.type = Constants.IMAGE;\n } else {\n voAdaptationSet.type = Constants.TEXT;\n }\n voAdaptations.push(voAdaptationSet);\n }\n }\n\n return voAdaptations;\n }\n\n function getRegularPeriods(mpd) {\n const isDynamic = mpd ? getIsDynamic(mpd.manifest) : false;\n const voPeriods = [];\n let realPreviousPeriod = null;\n let realPeriod = null;\n let voPreviousPeriod = null;\n let voPeriod = null;\n let len,\n i;\n\n for (i = 0, len = mpd && mpd.manifest && mpd.manifest.Period_asArray ? mpd.manifest.Period_asArray.length : 0; i < len; i++) {\n realPeriod = mpd.manifest.Period_asArray[i];\n\n // If the attribute @start is present in the Period, then the\n // Period is a regular Period and the PeriodStart is equal\n // to the value of this attribute.\n if (realPeriod.hasOwnProperty(DashConstants.START)) {\n voPeriod = new Period();\n voPeriod.start = realPeriod.start;\n }\n // If the @start attribute is absent, but the previous Period\n // element contains a @duration attribute then then this new\n // Period is also a regular Period. The start time of the new\n // Period PeriodStart is the sum of the start time of the previous\n // Period PeriodStart and the value of the attribute @duration\n // of the previous Period.\n else if (realPreviousPeriod !== null && realPreviousPeriod.hasOwnProperty(DashConstants.DURATION) && voPreviousPeriod !== null) {\n voPeriod = new Period();\n voPeriod.start = parseFloat((voPreviousPeriod.start + voPreviousPeriod.duration).toFixed(5));\n }\n // If (i) @start attribute is absent, and (ii) the Period element\n // is the first in the MPD, and (iii) the MPD@type is 'static',\n // then the PeriodStart time shall be set to zero.\n else if (i === 0 && !isDynamic) {\n voPeriod = new Period();\n voPeriod.start = 0;\n }\n\n // The Period extends until the PeriodStart of the next Period.\n // The difference between the PeriodStart time of a Period and\n // the PeriodStart time of the following Period.\n if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {\n if (voPeriod !== null) {\n voPreviousPeriod.duration = parseFloat((voPeriod.start - voPreviousPeriod.start).toFixed(5));\n } else {\n logger.warn('First period duration could not be calculated because lack of start and duration period properties. This will cause timing issues during playback');\n }\n }\n\n if (voPeriod !== null) {\n voPeriod.id = getPeriodId(realPeriod, i);\n voPeriod.index = i;\n voPeriod.mpd = mpd;\n\n if (realPeriod.hasOwnProperty(DashConstants.DURATION)) {\n voPeriod.duration = realPeriod.duration;\n }\n\n voPeriods.push(voPeriod);\n realPreviousPeriod = realPeriod;\n voPreviousPeriod = voPeriod;\n }\n\n realPeriod = null;\n voPeriod = null;\n }\n\n if (voPeriods.length === 0) {\n return voPeriods;\n }\n\n // The last Period extends until the end of the Media Presentation.\n // The difference between the PeriodStart time of the last Period\n // and the mpd duration\n if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {\n voPreviousPeriod.duration = parseFloat((getEndTimeForLastPeriod(voPreviousPeriod) - voPreviousPeriod.start).toFixed(5));\n }\n\n return voPeriods;\n }\n\n function getPeriodId(realPeriod, i) {\n if (!realPeriod) {\n throw new Error('Period cannot be null or undefined');\n }\n\n let id = Period.DEFAULT_ID + '_' + i;\n\n if (realPeriod.hasOwnProperty(DashConstants.ID) && realPeriod.id.length > 0 && realPeriod.id !== '__proto__') {\n id = realPeriod.id;\n }\n\n return id;\n }\n\n function getMpd(manifest) {\n const mpd = new Mpd();\n\n if (manifest) {\n mpd.manifest = manifest;\n\n if (manifest.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME)) {\n mpd.availabilityStartTime = new Date(manifest.availabilityStartTime.getTime());\n } else {\n if (manifest.loadedTime) {\n mpd.availabilityStartTime = new Date(manifest.loadedTime.getTime());\n }\n }\n\n if (manifest.hasOwnProperty(DashConstants.AVAILABILITY_END_TIME)) {\n mpd.availabilityEndTime = new Date(manifest.availabilityEndTime.getTime());\n }\n\n if (manifest.hasOwnProperty(DashConstants.MINIMUM_UPDATE_PERIOD)) {\n mpd.minimumUpdatePeriod = manifest.minimumUpdatePeriod;\n }\n\n if (manifest.hasOwnProperty(DashConstants.MEDIA_PRESENTATION_DURATION)) {\n mpd.mediaPresentationDuration = manifest.mediaPresentationDuration;\n }\n\n if (manifest.hasOwnProperty(DashConstants.SUGGESTED_PRESENTATION_DELAY)) {\n mpd.suggestedPresentationDelay = manifest.suggestedPresentationDelay;\n }\n\n if (manifest.hasOwnProperty(DashConstants.TIMESHIFT_BUFFER_DEPTH)) {\n mpd.timeShiftBufferDepth = manifest.timeShiftBufferDepth;\n }\n\n if (manifest.hasOwnProperty(DashConstants.MAX_SEGMENT_DURATION)) {\n mpd.maxSegmentDuration = manifest.maxSegmentDuration;\n }\n }\n\n return mpd;\n }\n\n function checkConfig() {\n if (!errHandler || !errHandler.hasOwnProperty('error')) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function getEndTimeForLastPeriod(voPeriod) {\n checkConfig();\n const isDynamic = getIsDynamic(voPeriod.mpd.manifest);\n\n let periodEnd;\n if (voPeriod.mpd.manifest.mediaPresentationDuration) {\n periodEnd = voPeriod.mpd.manifest.mediaPresentationDuration;\n } else if (voPeriod.duration) {\n periodEnd = voPeriod.duration;\n } else if (isDynamic) {\n periodEnd = Number.POSITIVE_INFINITY;\n } else {\n errHandler.error(new DashJSError(Errors.MANIFEST_ERROR_ID_PARSE_CODE, 'Must have @mediaPresentationDuration on MPD or an explicit @duration on the last period.', voPeriod));\n }\n\n return periodEnd;\n }\n\n function getEventsForPeriod(period) {\n const manifest = period && period.mpd && period.mpd.manifest ? period.mpd.manifest : null;\n const periodArray = manifest ? manifest.Period_asArray : null;\n const eventStreams = periodArray && period && isInteger(period.index) ? periodArray[period.index].EventStream_asArray : null;\n const events = [];\n let i,\n j;\n\n if (eventStreams) {\n for (i = 0; i < eventStreams.length; i++) {\n const eventStream = new EventStream();\n eventStream.period = period;\n eventStream.timescale = 1;\n\n if (eventStreams[i].hasOwnProperty(Constants.SCHEME_ID_URI)) {\n eventStream.schemeIdUri = eventStreams[i].schemeIdUri;\n } else {\n throw new Error('Invalid EventStream. SchemeIdUri has to be set');\n }\n if (eventStreams[i].hasOwnProperty(DashConstants.TIMESCALE)) {\n eventStream.timescale = eventStreams[i].timescale;\n }\n if (eventStreams[i].hasOwnProperty(DashConstants.VALUE)) {\n eventStream.value = eventStreams[i].value;\n }\n for (j = 0; eventStreams[i].Event_asArray && j < eventStreams[i].Event_asArray.length; j++) {\n const event = new Event();\n event.presentationTime = 0;\n event.eventStream = eventStream;\n\n if (eventStreams[i].Event_asArray[j].hasOwnProperty(DashConstants.PRESENTATION_TIME)) {\n event.presentationTime = eventStreams[i].Event_asArray[j].presentationTime;\n const presentationTimeOffset = eventStream.presentationTimeOffset ? eventStream.presentationTimeOffset * eventStream.timescale : 0;\n event.calculatedPresentationTime = event.presentationTime + (period.start * eventStream.timescale) + presentationTimeOffset;\n }\n if (eventStreams[i].Event_asArray[j].hasOwnProperty(DashConstants.DURATION)) {\n event.duration = eventStreams[i].Event_asArray[j].duration;\n }\n if (eventStreams[i].Event_asArray[j].hasOwnProperty(DashConstants.ID)) {\n event.id = eventStreams[i].Event_asArray[j].id;\n }\n\n if (eventStreams[i].Event_asArray[j].Signal && eventStreams[i].Event_asArray[j].Signal.Binary) {\n // toString is used to manage both regular and namespaced tags\n event.messageData = BASE64.decodeArray(eventStreams[i].Event_asArray[j].Signal.Binary.toString());\n } else {\n // From Cor.1: 'NOTE: this attribute is an alternative\n // to specifying a complete XML element(s) in the Event.\n // It is useful when an event leans itself to a compact\n // string representation'.\n event.messageData =\n eventStreams[i].Event_asArray[j].messageData ||\n eventStreams[i].Event_asArray[j].__text;\n }\n\n events.push(event);\n }\n }\n }\n\n return events;\n }\n\n function getEventStreams(inbandStreams, representation) {\n const eventStreams = [];\n let i;\n\n if (!inbandStreams) return eventStreams;\n\n for (i = 0; i < inbandStreams.length; i++) {\n const eventStream = new EventStream();\n eventStream.timescale = 1;\n eventStream.representation = representation;\n\n if (inbandStreams[i].hasOwnProperty(Constants.SCHEME_ID_URI)) {\n eventStream.schemeIdUri = inbandStreams[i].schemeIdUri;\n } else {\n throw new Error('Invalid EventStream. SchemeIdUri has to be set');\n }\n if (inbandStreams[i].hasOwnProperty(DashConstants.TIMESCALE)) {\n eventStream.timescale = inbandStreams[i].timescale;\n }\n if (inbandStreams[i].hasOwnProperty(DashConstants.VALUE)) {\n eventStream.value = inbandStreams[i].value;\n }\n eventStreams.push(eventStream);\n }\n\n return eventStreams;\n }\n\n function getEventStreamForAdaptationSet(manifest, adaptation) {\n let inbandStreams,\n periodArray,\n adaptationArray;\n\n if (manifest && manifest.Period_asArray && adaptation && adaptation.period && isInteger(adaptation.period.index)) {\n periodArray = manifest.Period_asArray[adaptation.period.index];\n if (periodArray && periodArray.AdaptationSet_asArray && isInteger(adaptation.index)) {\n adaptationArray = periodArray.AdaptationSet_asArray[adaptation.index];\n if (adaptationArray) {\n inbandStreams = adaptationArray.InbandEventStream_asArray;\n }\n }\n }\n\n return getEventStreams(inbandStreams, null);\n }\n\n function getEventStreamForRepresentation(manifest, representation) {\n let inbandStreams,\n periodArray,\n adaptationArray,\n representationArray;\n\n if (manifest && manifest.Period_asArray && representation && representation.adaptation && representation.adaptation.period && isInteger(representation.adaptation.period.index)) {\n periodArray = manifest.Period_asArray[representation.adaptation.period.index];\n if (periodArray && periodArray.AdaptationSet_asArray && isInteger(representation.adaptation.index)) {\n adaptationArray = periodArray.AdaptationSet_asArray[representation.adaptation.index];\n if (adaptationArray && adaptationArray.Representation_asArray && isInteger(representation.index)) {\n representationArray = adaptationArray.Representation_asArray[representation.index];\n if (representationArray) {\n inbandStreams = representationArray.InbandEventStream_asArray;\n }\n }\n }\n }\n\n return getEventStreams(inbandStreams, representation);\n }\n\n function getUTCTimingSources(manifest) {\n const isDynamic = getIsDynamic(manifest);\n const hasAST = manifest ? manifest.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME) : false;\n const utcTimingsArray = manifest ? manifest.UTCTiming_asArray : null;\n const utcTimingEntries = [];\n\n // do not bother synchronizing the clock unless MPD is live,\n // or it is static and has availabilityStartTime attribute\n if ((isDynamic || hasAST)) {\n if (utcTimingsArray) {\n // the order is important here - 23009-1 states that the order\n // in the manifest \"indicates relative preference, first having\n // the highest, and the last the lowest priority\".\n utcTimingsArray.forEach(function (utcTiming) {\n const entry = new UTCTiming();\n\n if (utcTiming.hasOwnProperty(Constants.SCHEME_ID_URI)) {\n entry.schemeIdUri = utcTiming.schemeIdUri;\n } else {\n // entries of type DescriptorType with no schemeIdUri\n // are meaningless. let's just ignore this entry and\n // move on.\n return;\n }\n\n // this is (incorrectly) interpreted as a number - schema\n // defines it as a string\n if (utcTiming.hasOwnProperty(DashConstants.VALUE)) {\n entry.value = utcTiming.value.toString();\n } else {\n // without a value, there's not a lot we can do with\n // this entry. let's just ignore this one and move on\n return;\n }\n\n // we're not interested in the optional id or any other\n // attributes which might be attached to the entry\n\n utcTimingEntries.push(entry);\n });\n }\n }\n\n return utcTimingEntries;\n }\n\n function getBaseURLsFromElement(node) {\n const baseUrls = [];\n // if node.BaseURL_asArray and node.baseUri are undefined entries\n // will be [undefined] which entries.some will just skip\n const entries = node.BaseURL_asArray || [node.baseUri];\n let earlyReturn = false;\n\n entries.some(entry => {\n if (entry) {\n const baseUrl = new BaseURL();\n let text = entry.__text || entry;\n\n if (urlUtils.isRelative(text)) {\n // it doesn't really make sense to have relative and\n // absolute URLs at the same level, or multiple\n // relative URLs at the same level, so assume we are\n // done from this level of the MPD\n earlyReturn = true;\n\n // deal with the specific case where the MPD@BaseURL\n // is specified and is relative. when no MPD@BaseURL\n // entries exist, that case is handled by the\n // [node.baseUri] in the entries definition.\n if (node.baseUri) {\n text = urlUtils.resolve(text, node.baseUri);\n }\n }\n\n baseUrl.url = text;\n\n // serviceLocation is optional, but we need it in order\n // to blacklist correctly. if it's not available, use\n // anything unique since there's no relationship to any\n // other BaseURL and, in theory, the url should be\n // unique so use this instead.\n if (entry.hasOwnProperty(DashConstants.SERVICE_LOCATION) &&\n entry.serviceLocation.length) {\n baseUrl.serviceLocation = entry.serviceLocation;\n } else {\n baseUrl.serviceLocation = text;\n }\n\n if (entry.hasOwnProperty(DashConstants.DVB_PRIORITY)) {\n baseUrl.dvb_priority = entry[DashConstants.DVB_PRIORITY];\n }\n\n if (entry.hasOwnProperty(DashConstants.DVB_WEIGHT)) {\n baseUrl.dvb_weight = entry[DashConstants.DVB_WEIGHT];\n }\n\n if (entry.hasOwnProperty(DashConstants.AVAILABILITY_TIME_OFFSET)) {\n baseUrl.availabilityTimeOffset = entry[DashConstants.AVAILABILITY_TIME_OFFSET];\n }\n\n if (entry.hasOwnProperty(DashConstants.AVAILABILITY_TIME_COMPLETE)) {\n baseUrl.availabilityTimeComplete = entry[DashConstants.AVAILABILITY_TIME_COMPLETE] !== 'false';\n }\n /* NOTE: byteRange currently unused\n */\n\n baseUrls.push(baseUrl);\n\n return earlyReturn;\n }\n });\n\n return baseUrls;\n }\n\n function getLocation(manifest) {\n if (manifest && manifest.hasOwnProperty(Constants.LOCATION)) {\n // for now, do not support multiple Locations -\n // just set Location to the first Location.\n manifest.Location = manifest.Location_asArray[0];\n\n return manifest.Location;\n }\n\n // may well be undefined\n return undefined;\n }\n\n function getSuggestedPresentationDelay(mpd) {\n return mpd && mpd.hasOwnProperty(DashConstants.SUGGESTED_PRESENTATION_DELAY) ? mpd.suggestedPresentationDelay : null;\n }\n\n function getAvailabilityStartTime(mpd) {\n return mpd && mpd.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME) && mpd.availabilityStartTime !== null ? mpd.availabilityStartTime.getTime() : null;\n }\n\n function getServiceDescriptions(manifest) {\n const serviceDescriptions = [];\n if (manifest && manifest.hasOwnProperty(DashConstants.SERVICE_DESCRIPTION)) {\n for (const sd of manifest.ServiceDescription_asArray) {\n // Convert each of the properties defined in\n let id, schemeIdUri, latency, playbackRate;\n for (const prop in sd) {\n if (sd.hasOwnProperty(prop)) {\n if (prop === DashConstants.ID) {\n id = sd[prop];\n } else if (prop === DashConstants.SERVICE_DESCRIPTION_SCOPE) {\n schemeIdUri = sd[prop].schemeIdUri;\n } else if (prop === DashConstants.SERVICE_DESCRIPTION_LATENCY) {\n latency = {\n target: sd[prop].target,\n max: sd[prop].max,\n min: sd[prop].min\n };\n } else if (prop === DashConstants.SERVICE_DESCRIPTION_PLAYBACK_RATE) {\n playbackRate = {\n max: sd[prop].max,\n min: sd[prop].min\n };\n }\n }\n }\n // we have a ServiceDescription for low latency. Add it if it really has parameters defined\n if (schemeIdUri === Constants.SERVICE_DESCRIPTION_LL_SCHEME && (latency || playbackRate)) {\n serviceDescriptions.push({\n id,\n schemeIdUri,\n latency,\n playbackRate\n });\n }\n }\n }\n\n return serviceDescriptions;\n }\n\n function getSupplementalPropperties(adaptation) {\n const supplementalProperties = {};\n\n if (adaptation && adaptation.hasOwnProperty(DashConstants.SUPPLEMENTAL_PROPERTY)) {\n for (const sp of adaptation.SupplementalProperty_asArray) {\n if (sp.hasOwnProperty(Constants.SCHEME_ID_URI) && sp.hasOwnProperty(DashConstants.VALUE)) {\n supplementalProperties[sp[Constants.SCHEME_ID_URI]] = sp[DashConstants.VALUE];\n }\n }\n }\n return supplementalProperties;\n }\n\n function setConfig(config) {\n if (!config) return;\n\n if (config.errHandler) {\n errHandler = config.errHandler;\n }\n\n if (config.BASE64) {\n BASE64 = config.BASE64;\n }\n }\n\n instance = {\n getIsTypeOf: getIsTypeOf,\n getIsTextTrack: getIsTextTrack,\n getLanguageForAdaptation: getLanguageForAdaptation,\n getViewpointForAdaptation: getViewpointForAdaptation,\n getRolesForAdaptation: getRolesForAdaptation,\n getAccessibilityForAdaptation: getAccessibilityForAdaptation,\n getAudioChannelConfigurationForAdaptation: getAudioChannelConfigurationForAdaptation,\n getAudioChannelConfigurationForRepresentation: getAudioChannelConfigurationForRepresentation,\n getAdaptationForIndex: getAdaptationForIndex,\n getIndexForAdaptation: getIndexForAdaptation,\n getAdaptationForId: getAdaptationForId,\n getAdaptationsForType: getAdaptationsForType,\n getCodec: getCodec,\n getMimeType: getMimeType,\n getKID: getKID,\n getLabelsForAdaptation: getLabelsForAdaptation,\n getContentProtectionData: getContentProtectionData,\n getIsDynamic: getIsDynamic,\n hasProfile: hasProfile,\n getDuration: getDuration,\n getBandwidth: getBandwidth,\n getManifestUpdatePeriod: getManifestUpdatePeriod,\n getRepresentationCount: getRepresentationCount,\n getBitrateListForAdaptation: getBitrateListForAdaptation,\n getRepresentationFor: getRepresentationFor,\n getRepresentationsForAdaptation: getRepresentationsForAdaptation,\n getAdaptationsForPeriod: getAdaptationsForPeriod,\n getRegularPeriods: getRegularPeriods,\n getMpd: getMpd,\n getEventsForPeriod: getEventsForPeriod,\n getEventStreamForAdaptationSet: getEventStreamForAdaptationSet,\n getEventStreamForRepresentation: getEventStreamForRepresentation,\n getUTCTimingSources: getUTCTimingSources,\n getBaseURLsFromElement: getBaseURLsFromElement,\n getRepresentationSortFunction: getRepresentationSortFunction,\n getLocation: getLocation,\n getUseCalculatedLiveEdgeTimeForAdaptation: getUseCalculatedLiveEdgeTimeForAdaptation,\n getSuggestedPresentationDelay: getSuggestedPresentationDelay,\n getAvailabilityStartTime: getAvailabilityStartTime,\n getServiceDescriptions: getServiceDescriptions,\n getSupplementalPropperties: getSupplementalPropperties,\n setConfig: setConfig\n };\n\n setup();\n\n return instance;\n}\n\nDashManifestModel.__dashjs_factory_name = 'DashManifestModel';\nexport default FactoryMaker.getSingletonFactory(DashManifestModel);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\nimport ObjectIron from './objectiron';\nimport X2JS from '../../../externals/xml2json';\nimport StringMatcher from './matchers/StringMatcher';\nimport DurationMatcher from './matchers/DurationMatcher';\nimport DateTimeMatcher from './matchers/DateTimeMatcher';\nimport NumericMatcher from './matchers/NumericMatcher';\nimport RepresentationBaseValuesMap from './maps/RepresentationBaseValuesMap';\nimport SegmentValuesMap from './maps/SegmentValuesMap';\n\nfunction DashParser(config) {\n\n config = config || {};\n const context = this.context;\n const debug = config.debug;\n\n let instance,\n logger,\n matchers,\n converter,\n objectIron;\n\n function setup() {\n logger = debug.getLogger(instance);\n matchers = [\n new DurationMatcher(),\n new DateTimeMatcher(),\n new NumericMatcher(),\n new StringMatcher() // last in list to take precedence over NumericMatcher\n ];\n\n converter = new X2JS({\n escapeMode: false,\n attributePrefix: '',\n arrayAccessForm: 'property',\n emptyNodeForm: 'object',\n stripWhitespaces: false,\n enableToStringFunc: true,\n ignoreRoot: true,\n matchers: matchers\n });\n\n objectIron = ObjectIron(context).create({\n adaptationset: new RepresentationBaseValuesMap(),\n period: new SegmentValuesMap()\n });\n }\n\n function getMatchers() {\n return matchers;\n }\n\n function getIron() {\n return objectIron;\n }\n\n function parse(data) {\n let manifest;\n const startTime = window.performance.now();\n\n manifest = converter.xml_str2json(data);\n\n if (!manifest) {\n throw new Error('parsing the manifest failed');\n }\n\n const jsonTime = window.performance.now();\n objectIron.run(manifest);\n\n const ironedTime = window.performance.now();\n logger.info('Parsing complete: ( xml2json: ' + (jsonTime - startTime).toPrecision(3) + 'ms, objectiron: ' + (ironedTime - jsonTime).toPrecision(3) + 'ms, total: ' + ((ironedTime - startTime) / 1000).toPrecision(3) + 's)');\n\n manifest.protocol = 'DASH';\n\n return manifest;\n }\n\n instance = {\n parse: parse,\n getMatchers: getMatchers,\n getIron: getIron\n };\n\n setup();\n\n return instance;\n}\n\nDashParser.__dashjs_factory_name = 'DashParser';\nexport default FactoryMaker.getClassFactory(DashParser);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc a property belonging to a MapNode\n * @ignore\n */\n\nclass CommonProperty {\n constructor(name) {\n const getDefaultMergeForName =\n (n) => n && n.length && n.charAt(0) === n.charAt(0).toUpperCase();\n\n this._name = name;\n this._merge = getDefaultMergeForName(name);\n }\n\n get name() {\n return this._name;\n }\n\n get merge() {\n return this._merge;\n }\n}\n\nexport default CommonProperty;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc a node at some level in a ValueMap\n */\nimport CommonProperty from './CommonProperty';\n\nclass MapNode {\n constructor(name, properties, children) {\n this._name = name || '';\n this._properties = [];\n this._children = children || [];\n\n if (Array.isArray(properties)) {\n properties.forEach(p => {\n this._properties.push(new CommonProperty(p));\n });\n }\n }\n\n get name() {\n return this._name;\n }\n\n get children() {\n return this._children;\n }\n\n get properties() {\n return this._properties;\n }\n}\n\nexport default MapNode;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc a RepresentationBaseValuesMap type for input to objectiron\n */\nimport MapNode from './MapNode';\nimport DashConstants from '../../constants/DashConstants';\n\nclass RepresentationBaseValuesMap extends MapNode {\n constructor() {\n const commonProperties = [\n DashConstants.PROFILES, DashConstants.WIDTH, DashConstants.HEIGHT, DashConstants.SAR, DashConstants.FRAMERATE, DashConstants.AUDIO_SAMPLING_RATE, DashConstants.MIME_TYPE, DashConstants.SEGMENT_PROFILES, DashConstants.CODECS, DashConstants.MAXIMUM_SAP_PERIOD, DashConstants.START_WITH_SAP, DashConstants.MAX_PLAYOUT_RATE, DashConstants.CODING_DEPENDENCY, DashConstants.SCAN_TYPE, DashConstants.FRAME_PACKING, DashConstants.AUDIO_CHANNEL_CONFIGURATION, DashConstants.CONTENT_PROTECTION, DashConstants.ESSENTIAL_PROPERTY, DashConstants.SUPPLEMENTAL_PROPERTY, DashConstants.INBAND_EVENT_STREAM\n ];\n\n super(DashConstants.ADAPTATION_SET, commonProperties, [\n new MapNode(DashConstants.REPRESENTATION, commonProperties, [\n new MapNode(DashConstants.SUB_REPRESENTATION, commonProperties)\n ])\n ]);\n }\n}\n\nexport default RepresentationBaseValuesMap;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc a SegmentValuesMap type for input to objectiron\n */\nimport MapNode from './MapNode';\nimport DashConstants from '../../constants/DashConstants';\n\nclass SegmentValuesMap extends MapNode {\n constructor() {\n const commonProperties = [\n DashConstants.SEGMENT_BASE, DashConstants.SEGMENT_TEMPLATE, DashConstants.SEGMENT_LIST\n ];\n\n super(DashConstants.PERIOD, commonProperties, [\n new MapNode(DashConstants.ADAPTATION_SET, commonProperties, [\n new MapNode(DashConstants.REPRESENTATION, commonProperties)\n ])\n ]);\n }\n}\n\nexport default SegmentValuesMap;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n\n/**\n * @classdesc a base type for matching and converting types in manifest to\n * something more useful\n * @ignore\n */\nclass BaseMatcher {\n constructor(test, converter) {\n this._test = test;\n this._converter = converter;\n }\n\n get test() {\n return this._test;\n }\n\n get converter() {\n return this._converter;\n }\n}\n\nexport default BaseMatcher;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc matches and converts xs:datetime to Date\n */\nimport BaseMatcher from './BaseMatcher';\n\nconst SECONDS_IN_MIN = 60;\nconst MINUTES_IN_HOUR = 60;\nconst MILLISECONDS_IN_SECONDS = 1000;\n\nconst datetimeRegex = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\\.[0-9]*)?)?(?:([+-])([0-9]{2})(?::?)([0-9]{2}))?/;\n\nclass DateTimeMatcher extends BaseMatcher {\n constructor() {\n super(\n attr => datetimeRegex.test(attr.value),\n str => {\n const match = datetimeRegex.exec(str);\n let utcDate;\n\n // If the string does not contain a timezone offset different browsers can interpret it either\n // as UTC or as a local time so we have to parse the string manually to normalize the given date value for\n // all browsers\n utcDate = Date.UTC(\n parseInt(match[1], 10),\n parseInt(match[2], 10) - 1, // months start from zero\n parseInt(match[3], 10),\n parseInt(match[4], 10),\n parseInt(match[5], 10),\n (match[6] && parseInt(match[6], 10) || 0),\n (match[7] && parseFloat(match[7]) * MILLISECONDS_IN_SECONDS) || 0);\n\n // If the date has timezone offset take it into account as well\n if (match[9] && match[10]) {\n const timezoneOffset = parseInt(match[9], 10) * MINUTES_IN_HOUR + parseInt(match[10], 10);\n utcDate += (match[8] === '+' ? -1 : +1) * timezoneOffset * SECONDS_IN_MIN * MILLISECONDS_IN_SECONDS;\n }\n\n return new Date(utcDate);\n }\n );\n }\n}\n\nexport default DateTimeMatcher;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc matches and converts xs:duration to seconds\n */\nimport BaseMatcher from './BaseMatcher';\nimport Constants from '../../../streaming/constants/Constants';\nimport DashConstants from '../../constants/DashConstants';\n\nconst durationRegex = /^([-])?P(([\\d.]*)Y)?(([\\d.]*)M)?(([\\d.]*)D)?T?(([\\d.]*)H)?(([\\d.]*)M)?(([\\d.]*)S)?/;\n\nconst SECONDS_IN_YEAR = 365 * 24 * 60 * 60;\nconst SECONDS_IN_MONTH = 30 * 24 * 60 * 60;\nconst SECONDS_IN_DAY = 24 * 60 * 60;\nconst SECONDS_IN_HOUR = 60 * 60;\nconst SECONDS_IN_MIN = 60;\n\nclass DurationMatcher extends BaseMatcher {\n constructor() {\n super(\n attr => {\n const attributeList = [\n DashConstants.MIN_BUFFER_TIME, DashConstants.MEDIA_PRESENTATION_DURATION,\n DashConstants.MINIMUM_UPDATE_PERIOD, DashConstants.TIMESHIFT_BUFFER_DEPTH, DashConstants.MAX_SEGMENT_DURATION,\n DashConstants.MAX_SUBSEGMENT_DURATION, DashConstants.SUGGESTED_PRESENTATION_DELAY, DashConstants.START,\n Constants.START_TIME, DashConstants.DURATION\n ];\n const len = attributeList.length;\n\n for (let i = 0; i < len; i++) {\n if (attr.nodeName === attributeList[i]) {\n return durationRegex.test(attr.value);\n }\n }\n\n return false;\n },\n str => {\n //str = \"P10Y10M10DT10H10M10.1S\";\n const match = durationRegex.exec(str);\n let result = (parseFloat(match[3] || 0) * SECONDS_IN_YEAR +\n parseFloat(match[5] || 0) * SECONDS_IN_MONTH +\n parseFloat(match[7] || 0) * SECONDS_IN_DAY +\n parseFloat(match[9] || 0) * SECONDS_IN_HOUR +\n parseFloat(match[11] || 0) * SECONDS_IN_MIN +\n parseFloat(match[13] || 0));\n\n if (match[1] !== undefined) {\n result = -result;\n }\n\n return result;\n }\n );\n }\n}\n\nexport default DurationMatcher;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc Matches and converts xs:numeric to float\n */\nimport BaseMatcher from './BaseMatcher';\n\nconst numericRegex = /^[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?$/;\n\nclass NumericMatcher extends BaseMatcher {\n constructor() {\n super(\n attr => numericRegex.test(attr.value),\n str => parseFloat(str)\n );\n }\n}\n\nexport default NumericMatcher;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc Matches and converts xs:string to string, but only for specific attributes on specific nodes\n */\nimport BaseMatcher from './BaseMatcher';\nimport DashConstants from '../../constants/DashConstants';\n\nclass StringMatcher extends BaseMatcher {\n constructor() {\n super(\n (attr, nodeName) => {\n const stringAttrsInElements = {\n [DashConstants.MPD]: [ DashConstants.ID, DashConstants.PROFILES ],\n [DashConstants.PERIOD]: [ DashConstants.ID ],\n [DashConstants.BASE_URL]: [ DashConstants.SERVICE_LOCATION, DashConstants.BYTE_RANGE ],\n [DashConstants.SEGMENT_BASE]: [ DashConstants.INDEX_RANGE ],\n [DashConstants.INITIALIZATION]: [ DashConstants.RANGE ],\n [DashConstants.REPRESENTATION_INDEX]: [ DashConstants.RANGE ],\n [DashConstants.SEGMENT_LIST]: [ DashConstants.INDEX_RANGE ],\n [DashConstants.BITSTREAM_SWITCHING]: [ DashConstants.RANGE ],\n [DashConstants.SEGMENT_URL]: [ DashConstants.MEDIA_RANGE, DashConstants.INDEX_RANGE ],\n [DashConstants.SEGMENT_TEMPLATE]: [ DashConstants.INDEX_RANGE, DashConstants.MEDIA, DashConstants.INDEX, DashConstants.INITIALIZATION_MINUS, DashConstants.BITSTREAM_SWITCHING_MINUS ],\n [DashConstants.ASSET_IDENTIFIER]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.EVENT_STREAM]: [ DashConstants.VALUE ],\n [DashConstants.ADAPTATION_SET]: [ DashConstants.PROFILES, DashConstants.MIME_TYPE, DashConstants.SEGMENT_PROFILES, DashConstants.CODECS, DashConstants.CONTENT_TYPE ],\n [DashConstants.FRAME_PACKING]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.AUDIO_CHANNEL_CONFIGURATION]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.CONTENT_PROTECTION]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.ESSENTIAL_PROPERTY]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.SUPPLEMENTAL_PROPERTY]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.INBAND_EVENT_STREAM]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.ACCESSIBILITY]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.ROLE]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.RATING]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.VIEWPOINT]: [ DashConstants.VALUE, DashConstants.ID ],\n [DashConstants.CONTENT_COMPONENT]: [ DashConstants.CONTENT_TYPE ],\n [DashConstants.REPRESENTATION]: [ DashConstants.ID, DashConstants.DEPENDENCY_ID, DashConstants.MEDIA_STREAM_STRUCTURE_ID ],\n [DashConstants.SUBSET]: [ DashConstants.ID ],\n [DashConstants.METRICS]: [ DashConstants.METRICS_MINUS ],\n [DashConstants.REPORTING]: [ DashConstants.VALUE, DashConstants.ID ]\n };\n if (stringAttrsInElements.hasOwnProperty(nodeName)) {\n let attrNames = stringAttrsInElements[nodeName];\n if (attrNames !== undefined) {\n return attrNames.indexOf(attr.name) >= 0;\n } else {\n return false;\n }\n }\n return false;\n },\n str => String(str)\n );\n }\n}\n\nexport default StringMatcher;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\n\nfunction ObjectIron(mappers) {\n\n function mergeValues(parentItem, childItem) {\n for (let name in parentItem) {\n if (!childItem.hasOwnProperty(name)) {\n childItem[name] = parentItem[name];\n }\n }\n }\n\n function mapProperties(properties, parent, child) {\n for (let i = 0, len = properties.length; i < len; ++i) {\n const property = properties[i];\n\n if (parent[property.name]) {\n if (child[property.name]) {\n // check to see if we should merge\n if (property.merge) {\n const parentValue = parent[property.name];\n const childValue = child[property.name];\n\n // complex objects; merge properties\n if (typeof parentValue === 'object' && typeof childValue === 'object') {\n mergeValues(parentValue, childValue);\n }\n // simple objects; merge them together\n else {\n child[property.name] = parentValue + childValue;\n }\n }\n } else {\n // just add the property\n child[property.name] = parent[property.name];\n }\n }\n }\n }\n\n function mapItem(item, node) {\n for (let i = 0, len = item.children.length; i < len; ++i) {\n const childItem = item.children[i];\n\n const array = node[childItem.name + '_asArray'];\n if (array) {\n for (let v = 0, len2 = array.length; v < len2; ++v) {\n const childNode = array[v];\n mapProperties(item.properties, node, childNode);\n mapItem(childItem, childNode);\n }\n }\n }\n }\n\n function run(source) {\n\n if (source === null || typeof source !== 'object') {\n return source;\n }\n\n if ('period' in mappers) {\n const periodMapper = mappers.period;\n const periods = source.Period_asArray;\n for (let i = 0, len = periods.length; i < len; ++i) {\n const period = periods[i];\n mapItem(periodMapper, period);\n\n if ('adaptationset' in mappers) {\n const adaptationSets = period.AdaptationSet_asArray;\n if (adaptationSets) {\n const adaptationSetMapper = mappers.adaptationset;\n for (let i = 0, len = adaptationSets.length; i < len; ++i) {\n mapItem(adaptationSetMapper, adaptationSets[i]);\n }\n }\n }\n }\n }\n\n return source;\n }\n\n return {\n run: run\n };\n}\n\n\nObjectIron.__dashjs_factory_name = 'ObjectIron';\nconst factory = FactoryMaker.getClassFactory(ObjectIron);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Constants from '../../streaming/constants/Constants';\n\nimport { getIndexBasedSegment } from './SegmentsUtils';\n\nfunction ListSegmentsGetter(config, isDynamic) {\n\n config = config || {};\n const timelineConverter = config.timelineConverter;\n\n let instance;\n\n function checkConfig() {\n if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function getSegmentByIndex(representation, index) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n const list = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].\n AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;\n const len = list.SegmentURL_asArray.length;\n\n const start = representation.startNumber;\n let segment = null;\n if (index < len) {\n const s = list.SegmentURL_asArray[index];\n\n segment = getIndexBasedSegment(timelineConverter, isDynamic, representation, index);\n if (segment) {\n segment.replacementTime = (start + index - 1) * representation.segmentDuration;\n segment.media = s.media ? s.media : '';\n segment.mediaRange = s.mediaRange;\n segment.index = index;\n segment.indexRange = s.indexRange;\n }\n }\n\n representation.availableSegmentsNumber = len;\n\n return segment;\n }\n\n function getSegmentByTime(representation, requestedTime) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n const duration = representation.segmentDuration;\n\n if (isNaN(duration)) {\n return null;\n }\n\n const periodTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, requestedTime);\n const index = Math.floor(periodTime / duration);\n\n return getSegmentByIndex(representation, index);\n }\n\n instance = {\n getSegmentByIndex: getSegmentByIndex,\n getSegmentByTime: getSegmentByTime\n };\n\n return instance;\n}\n\nListSegmentsGetter.__dashjs_factory_name = 'ListSegmentsGetter';\nconst factory = FactoryMaker.getClassFactory(ListSegmentsGetter);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Constants from '../../streaming/constants/Constants';\n\n\nfunction SegmentBaseGetter(config) {\n\n config = config || {};\n const timelineConverter = config.timelineConverter;\n\n let instance;\n\n function checkConfig() {\n if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function getSegmentByIndex(representation, index) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n const len = representation.segments ? representation.segments.length : -1;\n let seg;\n if (index < len) {\n seg = representation.segments[index];\n if (seg && seg.availabilityIdx === index) {\n return seg;\n }\n }\n\n for (let i = 0; i < len; i++) {\n seg = representation.segments[i];\n\n if (seg && seg.availabilityIdx === index) {\n return seg;\n }\n }\n\n return null;\n }\n\n function getSegmentByTime(representation, requestedTime) {\n checkConfig();\n\n const periodTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, requestedTime);\n const index = getIndexByTime(representation, periodTime);\n\n return getSegmentByIndex(representation, index);\n }\n\n function getIndexByTime(representation, time) {\n if (!representation) {\n return -1;\n }\n\n const segments = representation.segments;\n const ln = segments ? segments.length : null;\n\n let idx = -1;\n let epsilon,\n frag,\n ft,\n fd,\n i;\n\n if (segments && ln > 0) {\n for (i = 0; i < ln; i++) {\n frag = segments[i];\n ft = frag.presentationStartTime;\n fd = frag.duration;\n\n epsilon = fd / 2;\n if ((time + epsilon) >= ft &&\n (time - epsilon) < (ft + fd)) {\n idx = frag.availabilityIdx;\n break;\n }\n }\n }\n\n return idx;\n }\n\n instance = {\n getSegmentByIndex: getSegmentByIndex,\n getSegmentByTime: getSegmentByTime\n };\n\n return instance;\n}\n\nSegmentBaseGetter.__dashjs_factory_name = 'SegmentBaseGetter';\nconst factory = FactoryMaker.getClassFactory(SegmentBaseGetter);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport Segment from './../vo/Segment';\n\nfunction zeroPadToLength(numStr, minStrLength) {\n while (numStr.length < minStrLength) {\n numStr = '0' + numStr;\n }\n return numStr;\n}\n\nfunction getNumberForSegment(segment, segmentIndex) {\n return segment.representation.startNumber + segmentIndex;\n}\n\nexport function unescapeDollarsInTemplate(url) {\n return url ? url.split('$$').join('$') : url;\n}\n\nexport function replaceIDForTemplate(url, value) {\n if (!value || !url || url.indexOf('$RepresentationID$') === -1) { return url; }\n let v = value.toString();\n return url.split('$RepresentationID$').join(v);\n}\n\nexport function replaceTokenForTemplate(url, token, value) {\n const formatTag = '%0';\n\n let startPos,\n endPos,\n formatTagPos,\n specifier,\n width,\n paddedValue;\n\n const tokenLen = token.length;\n const formatTagLen = formatTag.length;\n\n if (!url) {\n return url;\n }\n\n // keep looping round until all instances of have been\n // replaced. once that has happened, startPos below will be -1\n // and the completed url will be returned.\n while (true) {\n\n // check if there is a valid $...$ identifier\n // if not, return the url as is.\n startPos = url.indexOf('$' + token);\n if (startPos < 0) {\n return url;\n }\n\n // the next '$' must be the end of the identifier\n // if there isn't one, return the url as is.\n endPos = url.indexOf('$', startPos + tokenLen);\n if (endPos < 0) {\n return url;\n }\n\n // now see if there is an additional format tag suffixed to\n // the identifier within the enclosing '$' characters\n formatTagPos = url.indexOf(formatTag, startPos + tokenLen);\n if (formatTagPos > startPos && formatTagPos < endPos) {\n\n specifier = url.charAt(endPos - 1);\n width = parseInt(url.substring(formatTagPos + formatTagLen, endPos - 1), 10);\n\n // support the minimum specifiers required by IEEE 1003.1\n // (d, i , o, u, x, and X) for completeness\n switch (specifier) {\n // treat all int types as uint,\n // hence deliberate fallthrough\n case 'd':\n case 'i':\n case 'u':\n paddedValue = zeroPadToLength(value.toString(), width);\n break;\n case 'x':\n paddedValue = zeroPadToLength(value.toString(16), width);\n break;\n case 'X':\n paddedValue = zeroPadToLength(value.toString(16), width).toUpperCase();\n break;\n case 'o':\n paddedValue = zeroPadToLength(value.toString(8), width);\n break;\n default:\n return url;\n }\n } else {\n paddedValue = value;\n }\n\n url = url.substring(0, startPos) + paddedValue + url.substring(endPos + 1);\n }\n}\n\nfunction getSegment(representation, duration, presentationStartTime, mediaStartTime, availabilityStartTime,\n timelineConverter, presentationEndTime, isDynamic, index) {\n let seg = new Segment();\n\n seg.representation = representation;\n seg.duration = duration;\n seg.presentationStartTime = presentationStartTime;\n seg.mediaStartTime = mediaStartTime;\n seg.availabilityStartTime = availabilityStartTime;\n seg.availabilityEndTime = timelineConverter.calcAvailabilityEndTimeFromPresentationTime(presentationEndTime, representation.adaptation.period.mpd, isDynamic);\n seg.wallStartTime = timelineConverter.calcWallTimeForSegment(seg, isDynamic);\n seg.replacementNumber = getNumberForSegment(seg, index);\n seg.availabilityIdx = index;\n\n return seg;\n}\n\nfunction isSegmentAvailable(timelineConverter, representation, segment, isDynamic) {\n const periodEnd = timelineConverter.getPeriodEnd(representation, isDynamic);\n const periodRelativeEnd = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, periodEnd);\n\n const segmentTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, segment.presentationStartTime);\n if (segmentTime >= periodRelativeEnd) {\n if (isDynamic) {\n // segment is not available in current period, but it may be segment available in another period that current one (in DVR window)\n // if not (time > segmentAvailabilityRange.end), then return false\n if ( representation.segmentAvailabilityRange && segment.presentationStartTime >= representation.segmentAvailabilityRange.end) {\n return false;\n }\n } else {\n return false;\n }\n }\n\n return true;\n}\n\nexport function getIndexBasedSegment(timelineConverter, isDynamic, representation, index) {\n let duration,\n presentationStartTime,\n presentationEndTime;\n\n duration = representation.segmentDuration;\n\n /*\n * From spec - If neither @duration attribute nor SegmentTimeline element is present, then the Representation\n * shall contain exactly one Media Segment. The MPD start time is 0 and the MPD duration is obtained\n * in the same way as for the last Media Segment in the Representation.\n */\n if (isNaN(duration)) {\n duration = representation.adaptation.period.duration;\n }\n\n presentationStartTime = parseFloat((representation.adaptation.period.start + (index * duration)).toFixed(5));\n presentationEndTime = parseFloat((presentationStartTime + duration).toFixed(5));\n\n const segment = getSegment(representation, duration, presentationStartTime,\n timelineConverter.calcMediaTimeFromPresentationTime(presentationStartTime, representation),\n timelineConverter.calcAvailabilityStartTimeFromPresentationTime(presentationStartTime, representation.adaptation.period.mpd, isDynamic),\n timelineConverter, presentationEndTime, isDynamic, index);\n\n if (!isSegmentAvailable(timelineConverter, representation, segment, isDynamic)) {\n return null;\n }\n\n return segment;\n}\n\nexport function getTimeBasedSegment(timelineConverter, isDynamic, representation, time, duration, fTimescale, url, range, index, tManifest) {\n const scaledTime = time / fTimescale;\n const scaledDuration = Math.min(duration / fTimescale, representation.adaptation.period.mpd.maxSegmentDuration);\n\n let presentationStartTime,\n presentationEndTime,\n seg;\n\n presentationStartTime = timelineConverter.calcPresentationTimeFromMediaTime(scaledTime, representation);\n presentationEndTime = presentationStartTime + scaledDuration;\n\n seg = getSegment(representation, scaledDuration, presentationStartTime,\n scaledTime,\n representation.adaptation.period.mpd.manifest.loadedTime,\n timelineConverter, presentationEndTime, isDynamic, index);\n\n if (!isSegmentAvailable(timelineConverter, representation, seg, isDynamic)) {\n return null;\n }\n\n seg.replacementTime = tManifest ? tManifest : time;\n\n url = replaceTokenForTemplate(url, 'Number', seg.replacementNumber);\n url = replaceTokenForTemplate(url, 'Time', seg.replacementTime);\n seg.media = url;\n seg.mediaRange = range;\n\n return seg;\n}\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Constants from '../../streaming/constants/Constants';\n\nimport { replaceTokenForTemplate, getIndexBasedSegment } from './SegmentsUtils';\n\nfunction TemplateSegmentsGetter(config, isDynamic) {\n config = config || {};\n const timelineConverter = config.timelineConverter;\n\n let instance;\n\n function checkConfig() {\n if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function getSegmentByIndex(representation, index) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n const template = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].\n AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentTemplate;\n\n index = Math.max(index, 0);\n\n const seg = getIndexBasedSegment(timelineConverter, isDynamic, representation, index);\n if (seg) {\n seg.replacementTime = (index - 1) * representation.segmentDuration;\n\n let url = template.media;\n url = replaceTokenForTemplate(url, 'Number', seg.replacementNumber);\n url = replaceTokenForTemplate(url, 'Time', seg.replacementTime);\n seg.media = url;\n }\n\n const duration = representation.segmentDuration;\n const availabilityWindow = representation.segmentAvailabilityRange;\n if (isNaN(duration)) {\n representation.availableSegmentsNumber = 1;\n }\n else {\n representation.availableSegmentsNumber = Math.ceil((availabilityWindow.end - availabilityWindow.start) / duration);\n }\n\n return seg;\n }\n\n function getSegmentByTime(representation, requestedTime) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n const duration = representation.segmentDuration;\n\n if (isNaN(duration)) {\n return null;\n }\n\n const periodTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, requestedTime);\n const index = Math.floor(periodTime / duration);\n\n return getSegmentByIndex(representation, index);\n }\n\n instance = {\n getSegmentByIndex: getSegmentByIndex,\n getSegmentByTime: getSegmentByTime\n };\n\n return instance;\n}\n\nTemplateSegmentsGetter.__dashjs_factory_name = 'TemplateSegmentsGetter';\nconst factory = FactoryMaker.getClassFactory(TemplateSegmentsGetter);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Constants from '../../streaming/constants/Constants';\n\nimport { getTimeBasedSegment } from './SegmentsUtils';\n\nfunction TimelineSegmentsGetter(config, isDynamic) {\n\n config = config || {};\n const timelineConverter = config.timelineConverter;\n\n let instance;\n\n function checkConfig() {\n if (!timelineConverter || !timelineConverter.hasOwnProperty('calcMediaTimeFromPresentationTime') ||\n !timelineConverter.hasOwnProperty('calcSegmentAvailabilityRange')) {\n throw new Error(Constants.MISSING_CONFIG_ERROR);\n }\n }\n\n function iterateSegments(representation, iterFunc) {\n const base = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].\n AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentTemplate ||\n representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].\n AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;\n const timeline = base.SegmentTimeline;\n const list = base.SegmentURL_asArray;\n\n let time = 0;\n let scaledTime = 0;\n let availabilityIdx = -1;\n\n let fragments,\n frag,\n i,\n len,\n j,\n repeat,\n repeatEndTime,\n nextFrag,\n fTimescale;\n\n fTimescale = representation.timescale;\n fragments = timeline.S_asArray;\n\n let breakIterator = false;\n\n for (i = 0, len = fragments.length; i < len && !breakIterator; i++) {\n frag = fragments[i];\n repeat = 0;\n if (frag.hasOwnProperty('r')) {\n repeat = frag.r;\n }\n\n // For a repeated S element, t belongs only to the first segment\n if (frag.hasOwnProperty('t')) {\n time = frag.t;\n scaledTime = time / fTimescale;\n }\n\n // This is a special case: \"A negative value of the @r attribute of the S element indicates that the duration indicated in @d attribute repeats until the start of the next S element, the end of the Period or until the\n // next MPD update.\"\n if (repeat < 0) {\n nextFrag = fragments[i + 1];\n\n if (nextFrag && nextFrag.hasOwnProperty('t')) {\n repeatEndTime = nextFrag.t / fTimescale;\n } else {\n const availabilityEnd = representation.segmentAvailabilityRange ? representation.segmentAvailabilityRange.end : (timelineConverter.calcSegmentAvailabilityRange(representation, isDynamic).end);\n repeatEndTime = timelineConverter.calcMediaTimeFromPresentationTime(availabilityEnd, representation);\n representation.segmentDuration = frag.d / fTimescale;\n }\n\n repeat = Math.ceil((repeatEndTime - scaledTime) / (frag.d / fTimescale)) - 1;\n }\n\n for (j = 0; j <= repeat && !breakIterator; j++) {\n availabilityIdx++;\n\n breakIterator = iterFunc(time, scaledTime, base, list, frag, fTimescale, availabilityIdx, i);\n\n if (breakIterator) {\n representation.segmentDuration = frag.d / fTimescale;\n\n // check if there is at least one more segment\n if (j < repeat - 1 || i < len - 1) {\n availabilityIdx++;\n }\n }\n\n time += frag.d;\n scaledTime = time / fTimescale;\n }\n }\n\n representation.availableSegmentsNumber = availabilityIdx;\n }\n\n function getSegmentByIndex(representation, index, lastSegmentTime) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n let segment = null;\n let found = false;\n\n iterateSegments(representation, function (time, scaledTime, base, list, frag, fTimescale, availabilityIdx, i) {\n if (found || lastSegmentTime < 0) {\n let media = base.media;\n let mediaRange = frag.mediaRange;\n\n if (list) {\n media = list[i].media || '';\n mediaRange = list[i].mediaRange;\n }\n\n segment = getTimeBasedSegment(\n timelineConverter,\n isDynamic,\n representation,\n time,\n frag.d,\n fTimescale,\n media,\n mediaRange,\n availabilityIdx,\n frag.tManifest);\n\n return true;\n } else if (scaledTime >= lastSegmentTime - frag.d * 0.5 / fTimescale) { // same logic, if deviation is\n // 50% of segment duration, segment is found if scaledTime is greater than or equal to (startTime of previous segment - half of the previous segment duration)\n found = true;\n }\n\n return false;\n });\n\n return segment;\n }\n\n function getSegmentByTime(representation, requestedTime) {\n checkConfig();\n\n if (!representation) {\n return null;\n }\n\n if (requestedTime === undefined) {\n requestedTime = null;\n }\n\n let segment = null;\n const requiredMediaTime = timelineConverter.calcMediaTimeFromPresentationTime(requestedTime, representation);\n\n iterateSegments(representation, function (time, scaledTime, base, list, frag, fTimescale, availabilityIdx, i) {\n // In some cases when requiredMediaTime = actual end time of the last segment\n // it is possible that this time a bit exceeds the declared end time of the last segment.\n // in this case we still need to include the last segment in the segment list.\n if (requiredMediaTime < (scaledTime + (frag.d / fTimescale))) {\n let media = base.media;\n let mediaRange = frag.mediaRange;\n\n if (list) {\n media = list[i].media || '';\n mediaRange = list[i].mediaRange;\n }\n\n segment = getTimeBasedSegment(\n timelineConverter,\n isDynamic,\n representation,\n time,\n frag.d,\n fTimescale,\n media,\n mediaRange,\n availabilityIdx,\n frag.tManifest);\n\n return true;\n }\n\n return false;\n });\n\n return segment;\n }\n\n\n instance = {\n getSegmentByIndex: getSegmentByIndex,\n getSegmentByTime: getSegmentByTime\n };\n\n return instance;\n}\n\nTimelineSegmentsGetter.__dashjs_factory_name = 'TimelineSegmentsGetter';\nconst factory = FactoryMaker.getClassFactory(TimelineSegmentsGetter);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass AdaptationSet {\n constructor() {\n this.period = null;\n this.index = -1;\n this.type = null;\n }\n}\n\nexport default AdaptationSet;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\n\nconst DEFAULT_DVB_PRIORITY = 1;\nconst DEFAULT_DVB_WEIGHT = 1;\n\nclass BaseURL {\n constructor(url, serviceLocation, priority, weight) {\n this.url = url || '';\n this.serviceLocation = serviceLocation || url || '';\n\n // DVB extensions\n this.dvb_priority = priority || DEFAULT_DVB_PRIORITY;\n this.dvb_weight = weight || DEFAULT_DVB_WEIGHT;\n\n this.availabilityTimeOffset = 0;\n this.availabilityTimeComplete = true;\n\n /* currently unused:\n * byteRange,\n */\n }\n}\n\nBaseURL.DEFAULT_DVB_PRIORITY = DEFAULT_DVB_PRIORITY;\nBaseURL.DEFAULT_DVB_WEIGHT = DEFAULT_DVB_WEIGHT;\n\nexport default BaseURL;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass Event {\n constructor() {\n this.duration = NaN;\n this.presentationTime = NaN;\n this.id = NaN;\n this.messageData = '';\n this.eventStream = null;\n this.presentationTimeDelta = NaN; // Specific EMSG Box parameter\n }\n}\n\nexport default Event;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass EventStream {\n constructor() {\n this.adaptionSet = null;\n this.representation = null;\n this.period = null;\n this.timescale = 1;\n this.value = '';\n this.schemeIdUri = '';\n }\n}\n\nexport default EventStream;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass Mpd {\n constructor() {\n this.manifest = null;\n this.suggestedPresentationDelay = 0;\n this.availabilityStartTime = null;\n this.availabilityEndTime = Number.POSITIVE_INFINITY;\n this.timeShiftBufferDepth = Number.POSITIVE_INFINITY;\n this.maxSegmentDuration = Number.POSITIVE_INFINITY;\n this.minimumUpdatePeriod = NaN;\n this.mediaPresentationDuration = NaN;\n }\n}\n\nexport default Mpd;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass Period {\n constructor() {\n this.id = null;\n this.index = -1;\n this.duration = NaN;\n this.start = NaN;\n this.mpd = null;\n }\n}\n\nPeriod.DEFAULT_ID = 'defaultId';\n\nexport default Period;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\n\nimport DashConstants from '../constants/DashConstants';\n\nclass Representation {\n constructor() {\n this.id = null;\n this.index = -1;\n this.adaptation = null;\n this.segmentInfoType = null;\n this.initialization = null;\n this.codecs = null;\n this.codecPrivateData = null;\n this.segmentDuration = NaN;\n this.timescale = 1;\n this.startNumber = 1;\n this.indexRange = null;\n this.range = null;\n this.presentationTimeOffset = 0;\n // Set the source buffer timeOffset to this\n this.MSETimeOffset = NaN;\n this.segmentAvailabilityRange = null;\n this.availableSegmentsNumber = 0;\n this.bandwidth = NaN;\n this.width = NaN;\n this.height = NaN;\n this.scanType = null;\n this.maxPlayoutRate = NaN;\n this.availabilityTimeOffset = 0;\n this.availabilityTimeComplete = true;\n }\n\n hasInitialization() {\n return (this.initialization !== null || this.range !== null);\n }\n\n hasSegments() {\n return this.segmentInfoType !== DashConstants.BASE_URL &&\n this.segmentInfoType !== DashConstants.SEGMENT_BASE &&\n !this.indexRange;\n }\n}\n\nexport default Representation;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass Segment {\n constructor() {\n this.indexRange = null;\n this.index = null;\n this.mediaRange = null;\n this.media = null;\n this.duration = NaN;\n // this is the time that should be inserted into the media url\n this.replacementTime = null;\n // this is the number that should be inserted into the media url\n this.replacementNumber = NaN;\n // This is supposed to match the time encoded in the media Segment\n this.mediaStartTime = NaN;\n // When the source buffer timeOffset is set to MSETimeOffset this is the\n // time that will match the seekTarget and video.currentTime\n this.presentationStartTime = NaN;\n // Do not schedule this segment until\n this.availabilityStartTime = NaN;\n // Ignore and discard this segment after\n this.availabilityEndTime = NaN;\n // The index of the segment inside the availability window\n this.availabilityIdx = NaN;\n // For dynamic mpd's, this is the wall clock time that the video\n // element currentTime should be presentationStartTime\n this.wallStartTime = NaN;\n this.representation = null;\n }\n}\n\nexport default Segment;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass UTCTiming {\n constructor() {\n // UTCTiming is a DescriptorType and doesn't have any additional fields\n this.schemeIdUri = '';\n this.value = '';\n }\n}\n\nexport default UTCTiming;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport OfflineConstants from './constants/OfflineConstants';\nimport OfflineStream from './OfflineStream';\nimport OfflineIndexDBManifestParser from './utils/OfflineIndexDBManifestParser';\nimport OfflineErrors from './errors/OfflineErrors';\nimport DashParser from '../dash/parser/DashParser';\n\nfunction OfflineDownload(config) {\n config = config || {};\n\n const context = this.context;\n const manifestLoader = config.manifestLoader;\n const mediaPlayerModel = config.mediaPlayerModel;\n const abrController = config.abrController;\n const playbackController = config.playbackController;\n const adapter = config.adapter;\n const dashMetrics = config.dashMetrics;\n const timelineConverter = config.timelineConverter;\n const offlineStoreController = config.offlineStoreController;\n const manifestId = config.id;\n const eventBus = config.eventBus;\n const errHandler = config.errHandler;\n const events = config.events;\n const errors = config.errors;\n const settings = config.settings;\n const debug = config.debug;\n const manifestUpdater = config.manifestUpdater;\n const baseURLController = config.baseURLController;\n const constants = config.constants;\n const dashConstants = config.dashConstants;\n const urlUtils = config.urlUtils;\n\n let instance,\n logger,\n _manifestURL,\n _offlineURL,\n _xmlManifest,\n _streams,\n _manifest,\n _isDownloadingStatus,\n _isComposed,\n _representationsToUpdate,\n _indexDBManifestParser,\n _progressionById,\n _progression,\n _status;\n\n\n function setup() {\n logger = debug.getLogger(instance);\n manifestUpdater.initialize();\n _streams = [];\n _isDownloadingStatus = false;\n _isComposed = false;\n _progressionById = {};\n _progression = 0;\n _status = undefined;\n }\n\n function getId() {\n return manifestId;\n }\n\n function getOfflineUrl () {\n return _offlineURL;\n }\n\n function getManifestUrl () {\n return _manifestURL;\n }\n\n function getStatus () {\n return _status;\n }\n\n function setInitialState(state) {\n _offlineURL = state.url;\n _progression = state.progress;\n _manifestURL = state.originalUrl;\n _status = state.status;\n }\n\n /**\n * Download a stream, from url of manifest\n * @param {string} url\n * @instance\n */\n function downloadFromUrl(url) {\n _manifestURL = url;\n _offlineURL = `${OfflineConstants.OFFLINE_SCHEME}://${manifestId}`;\n _status = OfflineConstants.OFFLINE_STATUS_CREATED;\n setupOfflineEvents();\n let offlineManifest = {\n 'fragmentStore': manifestId,\n 'status': _status,\n 'manifestId': manifestId,\n 'url': _offlineURL,\n 'originalURL': url\n };\n return createOfflineManifest(offlineManifest);\n }\n\n function initDownload() {\n manifestLoader.load(_manifestURL);\n _isDownloadingStatus = true;\n }\n\n function setupOfflineEvents() {\n eventBus.on(events.MANIFEST_UPDATED, onManifestUpdated, instance);\n eventBus.on(events.ORIGINAL_MANIFEST_LOADED, onOriginalManifestLoaded, instance);\n setupIndexedDBEvents();\n }\n\n function setupIndexedDBEvents() {\n eventBus.on(events.ERROR, onError, instance);\n }\n\n function isDownloading() {\n return _isDownloadingStatus;\n }\n\n function onManifestUpdated(e) {\n if (_isComposed) {\n return;\n }\n if (!e.error) {\n try {\n _manifest = e.manifest;\n } catch (err) {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: err.message,\n data: {\n id: manifestId,\n status: _status\n }\n });\n }\n }\n }\n\n function onDownloadingStarted(e) {\n if (e.id !== manifestId) {\n return;\n }\n if (!e.error && manifestId !== null) {\n _status = OfflineConstants.OFFLINE_STATUS_STARTED;\n offlineStoreController.setDownloadingStatus(manifestId, _status).then(function () {\n eventBus.trigger(events.OFFLINE_RECORD_STARTED, {id: manifestId, message: 'Downloading started for this stream !'});\n });\n } else {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: 'Cannot start download ',\n data: {\n id: manifestId,\n status: _status,\n error: e.error\n }\n });\n }\n }\n\n function OnStreamProgression(stream, downloaded, available) {\n\n _progressionById[stream.getStreamInfo().id] = {\n downloaded,\n available\n };\n\n let segments = 0;\n let allSegments = 0;\n let waitForAllProgress;\n for (var property in _progressionById) {\n if (_progressionById.hasOwnProperty(property)) {\n if (_progressionById[property] === null) {\n waitForAllProgress = true;\n } else {\n segments += _progressionById[property].downloaded;\n allSegments += _progressionById[property].available;\n }\n }\n }\n\n if (!waitForAllProgress) {\n // all progression have been started, we can compute global progression\n _progression = segments / allSegments;\n\n // store progression\n offlineStoreController.getManifestById(manifestId)\n .then((item) => {\n item.progress = _progression;\n return updateOfflineManifest(item);\n });\n }\n }\n\n function onDownloadingFinished(e) {\n if (e.id !== manifestId) {\n return;\n }\n if (!e.error && manifestId !== null) {\n _status = OfflineConstants.OFFLINE_STATUS_FINISHED;\n offlineStoreController.setDownloadingStatus(manifestId, _status)\n .then(function () {\n eventBus.trigger(events.OFFLINE_RECORD_FINISHED, {id: manifestId, message: 'Downloading has been successfully completed for this stream !'});\n resetDownload();\n });\n } else {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: 'Error finishing download ',\n data: {\n id: manifestId,\n status: _status,\n error: e.error\n }\n });\n }\n }\n\n function onManifestUpdateNeeded(e) {\n if (e.id !== manifestId) {\n return;\n }\n\n _representationsToUpdate = e.representations;\n\n if (_representationsToUpdate.length > 0) {\n _indexDBManifestParser.parse(_xmlManifest, _representationsToUpdate).then(function (parsedManifest) {\n if (parsedManifest !== null && manifestId !== null) {\n offlineStoreController.getManifestById(manifestId)\n .then((item) => {\n item.manifest = parsedManifest;\n return updateOfflineManifest(item);\n })\n .then( function () {\n for (let i = 0, ln = _streams.length; i < ln; i++) {\n _streams[i].startOfflineStreamProcessors();\n }\n });\n } else {\n throw 'falling parsing offline manifest';\n }\n }).catch(function (err) {\n throw err;\n });\n }\n }\n\n function composeStreams() {\n try {\n adapter.updatePeriods(_manifest);\n baseURLController.initialize(_manifest);\n const streamsInfo = adapter.getStreamsInfo();\n if (streamsInfo.length === 0) {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: 'Cannot download - no streams',\n data: {\n id: manifestId,\n status: _status\n }\n });\n }\n for (let i = 0, ln = streamsInfo.length; i < ln; i++) {\n const streamInfo = streamsInfo[i];\n let stream = OfflineStream(context).create({\n id: manifestId,\n callbacks: {\n started: onDownloadingStarted,\n progression: OnStreamProgression,\n finished: onDownloadingFinished,\n updateManifestNeeded: onManifestUpdateNeeded\n },\n constants: constants,\n dashConstants: dashConstants,\n eventBus: eventBus,\n events: events,\n errors: errors,\n settings: settings,\n debug: debug,\n errHandler: errHandler,\n mediaPlayerModel: mediaPlayerModel,\n abrController: abrController,\n playbackController: playbackController,\n dashMetrics: dashMetrics,\n baseURLController: baseURLController,\n timelineConverter: timelineConverter,\n adapter: adapter,\n offlineStoreController: offlineStoreController\n });\n _streams.push(stream);\n\n // initialise stream and get downloadable representations\n stream.initialize(streamInfo);\n _progressionById[streamInfo.id] = null;\n }\n _isComposed = true;\n } catch (e) {\n logger.info(e);\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: e.message,\n data: {\n id: manifestId,\n status: _status,\n error: e.error\n }\n });\n }\n }\n\n function getMediaInfos() {\n _streams.forEach(stream => {\n stream.getMediaInfos();\n });\n }\n\n /**\n * Init databsse to store fragments\n * @param {number} manifestId\n * @instance\n */\n function createFragmentStore(manifestId) {\n return offlineStoreController.createFragmentStore(manifestId);\n }\n\n /**\n * Store in database the string representation of offline manifest (with only downloaded representations)\n * @param {object} offlineManifest\n * @instance\n */\n function createOfflineManifest(offlineManifest) {\n return offlineStoreController.createOfflineManifest(offlineManifest);\n }\n\n /**\n * Store in database the string representation of offline manifest (with only downloaded representations)\n * @param {object} offlineManifest\n * @instance\n */\n function updateOfflineManifest(offlineManifest) {\n return offlineStoreController.updateOfflineManifest(offlineManifest);\n }\n\n /**\n * Triggered when manifest is loaded from internet.\n * @param {Object[]} e\n */\n function onOriginalManifestLoaded(e) {\n // unregister form event\n eventBus.off(events.ORIGINAL_MANIFEST_LOADED, onOriginalManifestLoaded, instance);\n\n _xmlManifest = e.originalManifest;\n\n if (_manifest.type === dashConstants.DYNAMIC) {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: 'Cannot handle DYNAMIC manifest',\n data: {\n id: manifestId,\n status: _status\n }\n });\n logger.error('Cannot handle DYNAMIC manifest');\n\n return;\n }\n\n if (_manifest.Period_asArray.length > 1) {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: 'MultiPeriod manifest are not yet supported',\n data: {\n id: manifestId,\n status: _status\n }\n });\n logger.error('MultiPeriod manifest are not yet supported');\n\n return;\n }\n\n // save original manifest (for resume)\n\n // initialise offline streams\n composeStreams(_manifest);\n\n // get MediaInfos\n getMediaInfos();\n\n eventBus.trigger(events.STREAMS_COMPOSED);\n }\n\n function initializeAllMediasInfoList(selectedRepresentations) {\n for (let i = 0; i < _streams.length; i++) {\n _streams[i].initializeAllMediasInfoList(selectedRepresentations);\n }\n }\n\n function getSelectedRepresentations(mediaInfos) {\n let rep = {};\n rep[constants.VIDEO] = [];\n rep[constants.AUDIO] = [];\n rep[constants.TEXT] = [];\n rep[constants.FRAGMENTED_TEXT] = [];\n\n // selectedRepresentations.video.forEach(item => {\n // ret[constants.VIDEO].push(item.id);\n // });\n // selectedRepresentations.audio.forEach(item => {\n // ret[constants.AUDIO].push(item.id);\n // });\n // selectedRepresentations.text.forEach(item => {\n // ret[item.type].push(item.id);\n // });\n\n mediaInfos.forEach(mediaInfo => {\n mediaInfo.bitrateList.forEach(bitrate => {\n rep[mediaInfo.type].push(bitrate.id);\n });\n });\n return rep;\n }\n\n function startDownload(mediaInfos) {\n try {\n let rep = getSelectedRepresentations(mediaInfos);\n\n offlineStoreController.saveSelectedRepresentations(manifestId, rep)\n .then(() => {\n return createFragmentStore(manifestId);\n })\n .then(() => {\n return generateOfflineManifest(rep);\n })\n .then(function () {\n initializeAllMediasInfoList(rep);\n });\n } catch (err) {\n _status = OfflineConstants.OFFLINE_STATUS_ERROR;\n errHandler.error({\n code: OfflineErrors.OFFLINE_ERROR,\n message: err.message,\n data: {\n id: manifestId,\n status: _status\n }\n });\n }\n }\n\n /**\n * Create the parser used to convert original manifest in offline manifest\n * Creates a JSON object that will be stored in database\n * @param {Object[]} selectedRepresentations\n * @instance\n */\n function generateOfflineManifest(selectedRepresentations) {\n _indexDBManifestParser = OfflineIndexDBManifestParser(context).create({\n manifestId: manifestId,\n allMediaInfos: selectedRepresentations,\n debug: debug,\n dashConstants: dashConstants,\n constants: constants,\n urlUtils: urlUtils\n });\n\n return _indexDBManifestParser.parse(_xmlManifest).then(function (parsedManifest) {\n if (parsedManifest !== null) {\n return offlineStoreController.getManifestById(manifestId)\n .then((item) => {\n item.originalURL = _manifest.url;\n item.originalManifest = _xmlManifest;\n item.manifest = parsedManifest;\n return updateOfflineManifest(item);\n });\n } else {\n return Promise.reject('falling parsing offline manifest');\n }\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Stops downloading of fragments\n * @instance\n */\n function stopDownload() {\n if (manifestId !== null && isDownloading()) {\n for (let i = 0, ln = _streams.length; i < ln; i++) {\n _streams[i].stopOfflineStreamProcessors();\n }\n\n // remove streams\n _streams = [];\n\n _isComposed = false;\n\n _status = OfflineConstants.OFFLINE_STATUS_STOPPED;\n // update status\n offlineStoreController.setDownloadingStatus(manifestId, _status).then(function () {\n eventBus.trigger(events.OFFLINE_RECORD_STOPPED, {\n sender: this,\n id: manifestId,\n status: _status,\n message: 'Downloading has been stopped for this stream !'\n });\n _isDownloadingStatus = false;\n });\n }\n }\n\n /**\n * Delete an offline manifest (and all of its data)\n * @instance\n */\n function deleteDownload() {\n stopDownload();\n }\n\n /**\n * Resume download of a stream\n * @instance\n */\n function resumeDownload() {\n if (isDownloading()) {\n return;\n }\n\n _isDownloadingStatus = true;\n\n let selectedRepresentations;\n\n offlineStoreController.getManifestById(manifestId)\n .then((item) => {\n let parser = DashParser(context).create({debug: debug});\n _manifest = parser.parse(item.originalManifest);\n\n composeStreams(_manifest);\n\n selectedRepresentations = item.selected;\n\n eventBus.trigger(events.STREAMS_COMPOSED);\n\n return createFragmentStore(manifestId);\n }). then(() => {\n initializeAllMediasInfoList(selectedRepresentations);\n });\n }\n\n /**\n * Compute the progression of download\n * @instance\n */\n function getDownloadProgression() {\n return Math.round(_progression * 100);\n }\n\n /**\n * Reset events listeners\n * @instance\n */\n function resetDownload() {\n for (let i = 0, ln = _streams.length; i < ln; i++) {\n _streams[i].reset();\n }\n _indexDBManifestParser = null;\n _isDownloadingStatus = false;\n _streams = [];\n eventBus.off(events.MANIFEST_UPDATED, onManifestUpdated, instance);\n eventBus.off(events.ORIGINAL_MANIFEST_LOADED, onOriginalManifestLoaded, instance);\n resetIndexedDBEvents();\n }\n\n function onError(e) {\n if ( e.error.code === OfflineErrors.INDEXEDDB_QUOTA_EXCEED_ERROR ||\n e.error.code === OfflineErrors.INDEXEDDB_INVALID_STATE_ERROR ) {\n stopDownload();\n }\n }\n\n function resetIndexedDBEvents() {\n eventBus.on(events.ERROR, onError, instance);\n }\n\n /**\n * Reset\n * @instance\n */\n function reset() {\n if (isDownloading()) {\n resetDownload();\n }\n baseURLController.reset();\n manifestUpdater.reset();\n }\n\n instance = {\n reset: reset,\n getId: getId,\n getOfflineUrl: getOfflineUrl,\n getManifestUrl: getManifestUrl,\n getStatus: getStatus,\n setInitialState: setInitialState,\n initDownload: initDownload,\n downloadFromUrl: downloadFromUrl,\n startDownload: startDownload,\n stopDownload: stopDownload,\n resumeDownload: resumeDownload,\n deleteDownload: deleteDownload,\n getDownloadProgression: getDownloadProgression,\n isDownloading: isDownloading,\n resetDownload: resetDownload\n };\n\n setup();\n\n return instance;\n}\n\nOfflineDownload.__dashjs_factory_name = 'OfflineDownload';\nexport default dashjs.FactoryMaker.getClassFactory(OfflineDownload); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport OfflineStreamProcessor from './OfflineStreamProcessor';\n\n/**\n * Initialize and Manage Offline Stream for each type\n */\n/**\n * @class OfflineStream\n * @description Initialize and Manage Offline Stream for each type\n * @param {Object} config - dependences\n * @ignore\n */\nfunction OfflineStream(config) {\n\n config = config || {};\n const context = this.context;\n const eventBus = config.eventBus;\n const events = config.events;\n const errors = config.errors;\n const constants = config.constants;\n const dashConstants = config.dashConstants;\n const settings = config.settings;\n const debug = config.debug;\n const errHandler = config.errHandler;\n const mediaPlayerModel = config.mediaPlayerModel;\n const abrController = config.abrController;\n const playbackController = config.playbackController;\n const adapter = config.adapter;\n const dashMetrics = config.dashMetrics;\n const baseURLController = config.baseURLController;\n const timelineConverter = config.timelineConverter;\n const offlineStoreController = config.offlineStoreController;\n const manifestId = config.id;\n const startedCb = config.callbacks && config.callbacks.started;\n const progressionCb = config.callbacks && config.callbacks.progression;\n const finishedCb = config.callbacks && config.callbacks.finished;\n const updateManifest = config.callbacks && config.callbacks.updateManifestNeeded;\n\n let instance,\n offlineStreamProcessors,\n startedOfflineStreamProcessors,\n finishedOfflineStreamProcessors,\n streamInfo,\n representationsToUpdate,\n allMediasInfosList,\n progressionById;\n\n function setup() {\n resetInitialSettings();\n }\n\n /**\n * Reset\n */\n function resetInitialSettings() {\n streamInfo = null;\n offlineStreamProcessors = [];\n startedOfflineStreamProcessors = 0;\n finishedOfflineStreamProcessors = 0;\n allMediasInfosList = [];\n representationsToUpdate = [];\n progressionById = {};\n }\n\n /**\n * Initialize offlinestream\n * @param {Object} initStreamInfo\n */\n function initialize(initStreamInfo) {\n streamInfo = initStreamInfo;\n eventBus.on(events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, this);\n }\n\n /**\n * Creates media infos list, so that user will be able to choose the representation he wants to download\n */\n function getMediaInfos() {\n let mediaInfos = adapter.getAllMediaInfoForType(streamInfo, constants.VIDEO);\n mediaInfos = mediaInfos.concat(adapter.getAllMediaInfoForType(streamInfo, constants.AUDIO));\n mediaInfos = mediaInfos.concat(adapter.getAllMediaInfoForType(streamInfo, constants.FRAGMENTED_TEXT));\n mediaInfos = mediaInfos.concat(adapter.getAllMediaInfoForType(streamInfo, constants.TEXT));\n\n // mediaInfos = mediaInfos.concat(adapter.getAllMediaInfoForType(streamInfo, constants.MUXED));\n // mediaInfos = mediaInfos.concat(adapter.getAllMediaInfoForType(streamInfo, constants.IMAGE));\n\n eventBus.trigger(events.OFFLINE_RECORD_LOADEDMETADATA, {\n id: manifestId,\n mediaInfos: mediaInfos\n });\n }\n\n /**\n * Initialize with choosen representations by user\n * @param {Object} mediasInfoList\n */\n function initializeAllMediasInfoList(mediasInfoList) {\n allMediasInfosList = mediasInfoList;\n initializeMedia(streamInfo);\n }\n\n /**\n * Initialize media for each type\n * @param {Object} streamInfo\n */\n function initializeMedia(streamInfo) {\n createOfflineStreamProcessorFor(constants.VIDEO,streamInfo);\n createOfflineStreamProcessorFor(constants.AUDIO,streamInfo);\n createOfflineStreamProcessorFor(constants.FRAGMENTED_TEXT,streamInfo);\n createOfflineStreamProcessorFor(constants.TEXT,streamInfo);\n\n createOfflineStreamProcessorFor(constants.MUXED,streamInfo);\n createOfflineStreamProcessorFor(constants.IMAGE,streamInfo);\n }\n\n function createOfflineStreamProcessorFor(type, streamInfo) {\n // filter mediaInfo according to choosen representation id\n let allMediaInfoForType = adapter.getAllMediaInfoForType(streamInfo, type);\n allMediaInfoForType.forEach((media) => {\n media.bitrateList = media.bitrateList.filter((bitrate) => {\n if (allMediasInfosList[type] && allMediasInfosList[type].indexOf(bitrate.id) !== -1) {\n return true;\n }\n return false;\n });\n });\n\n allMediaInfoForType = allMediaInfoForType.filter((media) => {\n return (media.bitrateList && media.bitrateList.length > 0);\n });\n\n // cration of an offline stream processor for each choosen representation\n allMediaInfoForType.forEach((mediaInfo) => {\n if (mediaInfo.bitrateList) {\n mediaInfo.bitrateList.forEach((bitrate) => {\n createStreamProcessor(mediaInfo, bitrate);\n });\n }\n });\n return allMediaInfoForType;\n }\n\n function createStreamProcessor (mediaInfo, bitrate) {\n\n let streamProcessor = OfflineStreamProcessor(context).create({\n id: manifestId,\n streamInfo: streamInfo,\n debug: debug,\n events: events,\n errors: errors,\n eventBus: eventBus,\n constants: constants,\n dashConstants: dashConstants,\n settings: settings,\n type: mediaInfo.type,\n mimeType: mediaInfo.mimeType,\n bitrate: bitrate,\n errHandler: errHandler,\n mediaPlayerModel: mediaPlayerModel,\n abrController: abrController,\n playbackController: playbackController,\n adapter: adapter,\n dashMetrics: dashMetrics,\n baseURLController: baseURLController,\n timelineConverter: timelineConverter,\n offlineStoreController: offlineStoreController,\n callbacks: {\n completed: onStreamCompleted,\n progression: onStreamProgression\n }\n });\n offlineStreamProcessors.push(streamProcessor);\n streamProcessor.initialize(mediaInfo);\n\n progressionById[bitrate.id] = null;\n }\n\n function onStreamCompleted() {\n finishedOfflineStreamProcessors++;\n if (finishedOfflineStreamProcessors === offlineStreamProcessors.length) {\n finishedCb({sender: this, id: manifestId, message: 'Downloading has been successfully completed for this stream !'});\n }\n }\n\n function onStreamProgression(streamProcessor, downloadedSegments, availableSegments ) {\n progressionById[streamProcessor.getRepresentationId()] = {\n downloadedSegments,\n availableSegments\n };\n\n let segments = 0;\n let allSegments = 0;\n let waitForAllProgress;\n for (var property in progressionById) {\n if (progressionById.hasOwnProperty(property)) {\n if (progressionById[property] === null) {\n waitForAllProgress = true;\n } else {\n segments += progressionById[property].downloadedSegments;\n allSegments += progressionById[property].availableSegments;\n }\n }\n }\n\n if (!waitForAllProgress && progressionCb) {\n // all progression have been started, we can compute global progression\n if (allSegments > 0) {\n progressionCb(instance, segments, allSegments);\n }\n }\n }\n\n function onDataUpdateCompleted(e) {\n let repCtrl = e.sender;\n if (!streamInfo || repCtrl.getStreamId() !== streamInfo.id) return;\n\n if (e.currentRepresentation.segments && e.currentRepresentation.segments.length > 0) {\n representationsToUpdate.push(e.currentRepresentation);\n }\n\n let sp;\n // data are ready fr stream processor, let's start download\n for (let i = 0; i < offlineStreamProcessors.length; i++ ) {\n if (offlineStreamProcessors[i].getRepresentationController().getType() === repCtrl.getType()) {\n sp = offlineStreamProcessors[i];\n break;\n }\n }\n\n if (sp) {\n checkIfAllOfflineStreamProcessorsStarted();\n }\n }\n\n function checkIfAllOfflineStreamProcessorsStarted() {\n startedOfflineStreamProcessors++;\n if (startedOfflineStreamProcessors === offlineStreamProcessors.length) {\n startedCb({sender: this, id: manifestId, message: 'Downloading started for this stream !'});\n\n if (representationsToUpdate.length > 0) {\n updateManifest({sender: this, id: manifestId, representations: representationsToUpdate });\n } else {\n startOfflineStreamProcessors();\n }\n }\n }\n\n function getStreamInfo() {\n return streamInfo;\n }\n\n function getStartTime() {\n return streamInfo ? streamInfo.start : NaN;\n }\n\n function getDuration() {\n return streamInfo ? streamInfo.duration : NaN;\n }\n\n /**\n * Stop offline stream processors\n */\n function stopOfflineStreamProcessors() {\n for (let i = 0; i < offlineStreamProcessors.length; i++) {\n offlineStreamProcessors[i].stop();\n }\n }\n\n /**\n * Start offline stream processors\n */\n function startOfflineStreamProcessors() {\n for (let i = 0; i < offlineStreamProcessors.length; i++) {\n offlineStreamProcessors[i].start();\n }\n }\n\n function deactivate() {\n let ln = offlineStreamProcessors ? offlineStreamProcessors.length : 0;\n for (let i = 0; i < ln; i++) {\n offlineStreamProcessors[i].removeExecutedRequestsBeforeTime(getStartTime() + getDuration());\n offlineStreamProcessors[i].reset();\n }\n }\n\n /**\n * Reset\n */\n function reset() {\n stopOfflineStreamProcessors();\n deactivate();\n resetInitialSettings();\n\n eventBus.off(events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, this);\n }\n\n instance = {\n initialize: initialize,\n getMediaInfos: getMediaInfos,\n initializeAllMediasInfoList: initializeAllMediasInfoList,\n getStreamInfo: getStreamInfo,\n stopOfflineStreamProcessors: stopOfflineStreamProcessors,\n startOfflineStreamProcessors: startOfflineStreamProcessors,\n reset: reset\n };\n\n setup();\n return instance;\n}\n\nOfflineStream.__dashjs_factory_name = 'OfflineStream';\nexport default dashjs.FactoryMaker.getClassFactory(OfflineStream); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport DashHandler from '../dash/DashHandler';\nimport RepresentationController from '../dash/controllers/RepresentationController';\nimport FragmentModel from '../streaming/models/FragmentModel';\nimport FragmentLoader from '../streaming/FragmentLoader';\nimport URLUtils from '../streaming/utils/URLUtils';\nimport RequestModifier from '../streaming/utils/RequestModifier';\n\n\nfunction OfflineStreamProcessor(config) {\n\n config = config || {};\n const context = this.context;\n const eventBus = config.eventBus;\n const events = config.events;\n const errors = config.errors;\n const debug = config.debug;\n const constants = config.constants;\n const settings = config.settings;\n const dashConstants = config.dashConstants;\n const manifestId = config.id;\n const type = config.type;\n const streamInfo = config.streamInfo;\n const errHandler = config.errHandler;\n const mediaPlayerModel = config.mediaPlayerModel;\n const abrController = config.abrController;\n const playbackController = config.playbackController;\n const adapter = config.adapter;\n const dashMetrics = config.dashMetrics;\n const baseURLController = config.baseURLController;\n const timelineConverter = config.timelineConverter;\n const bitrate = config.bitrate;\n const offlineStoreController = config.offlineStoreController;\n const completedCb = config.callbacks && config.callbacks.completed;\n const progressCb = config.callbacks && config.callbacks.progression;\n\n let instance,\n logger,\n mediaInfo,\n indexHandler,\n representationController,\n fragmentModel,\n updating,\n downloadedSegments,\n isInitialized,\n isStopped;\n\n function setup() {\n resetInitialSettings();\n logger = debug.getLogger(instance);\n\n indexHandler = DashHandler(context).create({\n streamInfo: streamInfo,\n type: type,\n timelineConverter: timelineConverter,\n dashMetrics: dashMetrics,\n mediaPlayerModel: mediaPlayerModel,\n baseURLController: baseURLController,\n errHandler: errHandler,\n settings: settings,\n // boxParser: boxParser,\n eventBus: eventBus,\n events: events,\n debug: debug,\n requestModifier: RequestModifier(context).getInstance(),\n dashConstants: dashConstants,\n constants: constants,\n urlUtils: URLUtils(context).getInstance()\n });\n\n representationController = RepresentationController(context).create({\n streamId: streamInfo.id,\n type: type,\n abrController: abrController,\n dashMetrics: dashMetrics,\n playbackController: playbackController,\n timelineConverter: timelineConverter,\n dashConstants: dashConstants,\n events: events,\n eventBus: eventBus,\n errors: errors\n });\n\n fragmentModel = FragmentModel(context).create({\n streamId: streamInfo.id,\n dashMetrics: dashMetrics,\n fragmentLoader: FragmentLoader(context).create({\n dashMetrics: dashMetrics,\n mediaPlayerModel: mediaPlayerModel,\n errHandler: errHandler,\n requestModifier: RequestModifier(context).getInstance(),\n settings: settings,\n eventBus: eventBus,\n events: events,\n errors: errors,\n constants: constants,\n dashConstants: dashConstants,\n urlUtils: URLUtils(context).getInstance()\n }),\n debug: debug,\n eventBus: eventBus,\n events: events\n });\n\n eventBus.on(events.STREAM_COMPLETED, onStreamCompleted, instance);\n eventBus.on(events.FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, instance);\n }\n\n function initialize(_mediaInfo) {\n mediaInfo = _mediaInfo;\n indexHandler.initialize(false);\n updateRepresentation(mediaInfo);\n }\n\n function isInitRequest(request) {\n return request.type === 'InitializationSegment';\n }\n\n function onFragmentLoadingCompleted(e) {\n if (e.sender !== fragmentModel) {\n return;\n }\n\n if (e.request !== null) {\n let isInit = isInitRequest(e.request);\n let suffix = isInit ? 'init' : e.request.index;\n let fragmentName = e.request.representationId + '_' + suffix;\n offlineStoreController.storeFragment(manifestId, fragmentName, e.response)\n .then(() => {\n if (!isInit) {\n // store current index and downloadedSegments number\n offlineStoreController.setRepresentationCurrentState(manifestId, e.request.representationId, {\n index: e.request.index,\n downloaded: downloadedSegments\n } );\n }\n });\n }\n\n if (e.error && e.request.serviceLocation && !isStopped) {\n fragmentModel.executeRequest(e.request);\n } else {\n downloadedSegments++;\n download();\n }\n }\n\n function onStreamCompleted(e) {\n if (e.fragmentModel !== fragmentModel) {\n return;\n }\n logger.info(`[${manifestId}] Stream is complete`);\n stop();\n completedCb();\n }\n\n function getRepresentationController () {\n return representationController;\n }\n\n function getRepresentationId() {\n return representationController.getCurrentRepresentation().id;\n }\n\n /**\n * Stops download of fragments\n * @memberof OfflineStreamProcessor#\n */\n function stop() {\n if (isStopped) {\n return;\n }\n isStopped = true;\n }\n\n\n function removeExecutedRequestsBeforeTime(time) {\n if (fragmentModel) {\n fragmentModel.removeExecutedRequestsBeforeTime(time);\n }\n }\n\n /**\n * Execute init request for the represenation\n * @memberof OfflineStreamProcessor#\n */\n function getInitRequest() {\n if (!representationController.getCurrentRepresentation()) {\n return null;\n }\n\n return indexHandler.getInitRequest(getMediaInfo(), representationController.getCurrentRepresentation());\n }\n\n /**\n * Get next request\n * @memberof OfflineStreamProcessor#\n */\n function getNextRequest() {\n return indexHandler.getNextSegmentRequest(getMediaInfo(), representationController.getCurrentRepresentation());\n }\n\n /**\n * Start download\n * @memberof OfflineStreamProcessor#\n */\n function start() {\n if (representationController) {\n if (!representationController.getCurrentRepresentation()) {\n throw new Error('Start denied to OfflineStreamProcessor');\n }\n isStopped = false;\n\n offlineStoreController.getRepresentationCurrentState(manifestId, representationController.getCurrentRepresentation().id)\n .then((state) => {\n if (state) {\n indexHandler.setCurrentIndex(state.index);\n downloadedSegments = state.downloaded;\n }\n download();\n }).catch(() => {\n // start from beginining\n download();\n });\n }\n }\n\n /**\n * Performs download of fragment according to type\n * @memberof OfflineStreamProcessor#\n */\n function download() {\n if (isStopped) {\n return;\n }\n\n if (isNaN(representationController.getCurrentRepresentation())) {\n let request = null;\n if (!isInitialized) {\n request = getInitRequest();\n isInitialized = true;\n } else {\n request = getNextRequest();\n\n // update progression : done here because availableSegmentsNumber is done in getNextRequest from dash handler\n updateProgression();\n }\n\n if (request) {\n logger.info(`[${manifestId}] download request : ${request.url}`);\n fragmentModel.executeRequest(request);\n } else {\n logger.info(`[${manifestId}] no request to be downloaded`);\n }\n }\n }\n\n /**\n * Update representation\n * @param {Object} mediaInfo - mediaInfo\n * @memberof OfflineStreamProcessor#\n */\n function updateRepresentation(mediaInfo) {\n updating = true;\n\n let voRepresentations = adapter.getVoRepresentations(mediaInfo);\n\n // get representation VO according to id.\n let quality = voRepresentations.findIndex((representation) => {\n return representation.id === bitrate.id;\n });\n\n if (type !== constants.VIDEO && type !== constants.AUDIO && type !== constants.TEXT && type !== constants.FRAGMENTED_TEXT) {\n updating = false;\n return;\n }\n\n representationController.updateData(null, voRepresentations, type, quality);\n }\n\n function isUpdating() {\n return updating;\n }\n\n function getType() {\n return type;\n }\n\n function getMediaInfo() {\n return mediaInfo;\n }\n\n function getAvailableSegmentsNumber() {\n return representationController.getCurrentRepresentation().availableSegmentsNumber + 1; // do not forget init segment\n }\n\n function updateProgression () {\n if (progressCb) {\n progressCb(instance, downloadedSegments, getAvailableSegmentsNumber());\n }\n }\n\n function resetInitialSettings() {\n isInitialized = false;\n downloadedSegments = 0;\n updating = false;\n }\n\n /**\n * Reset\n * @memberof OfflineStreamProcessor#\n */\n function reset() {\n resetInitialSettings();\n indexHandler.reset();\n\n eventBus.off(events.STREAM_COMPLETED, onStreamCompleted, instance);\n eventBus.off(events.FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, instance);\n }\n\n instance = {\n initialize: initialize,\n getMediaInfo: getMediaInfo,\n getRepresentationController: getRepresentationController,\n removeExecutedRequestsBeforeTime: removeExecutedRequestsBeforeTime,\n getType: getType,\n getRepresentationId: getRepresentationId,\n isUpdating: isUpdating,\n start: start,\n stop: stop,\n getAvailableSegmentsNumber: getAvailableSegmentsNumber,\n reset: reset\n };\n\n setup();\n\n return instance;\n}\nOfflineStreamProcessor.__dashjs_factory_name = 'OfflineStreamProcessor';\nconst factory = dashjs.FactoryMaker.getClassFactory(OfflineStreamProcessor); /* jshint ignore:line */\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * Offline constants declaration\n * @class\n * @ignore\n */\nclass OfflineConstants {\n\n init() {\n this.OFFLINE_SCHEME = 'offline_indexeddb';\n this.OFFLINE_URL_REGEX = /^offline_indexeddb:\\/\\//i;\n this.OFFLINE_STATUS_CREATED = 'created';\n this.OFFLINE_STATUS_STARTED = 'started';\n this.OFFLINE_STATUS_STOPPED = 'stopped';\n this.OFFLINE_STATUS_FINISHED = 'finished';\n this.OFFLINE_STATUS_ERROR = 'error';\n }\n\n constructor () {\n this.init();\n }\n}\n\nlet constants = new OfflineConstants();\nexport default constants;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport OfflineConstants from '../constants/OfflineConstants';\nimport OfflineStoreController from './OfflineStoreController';\nimport OfflineDownload from '../OfflineDownload';\nimport IndexDBOfflineLoader from '../net/IndexDBOfflineLoader';\nimport OfflineUrlUtils from '../utils/OfflineUrlUtils';\nimport OfflineEvents from '../events/OfflineEvents';\nimport OfflineErrors from '../errors/OfflineErrors';\nimport OfflineRecord from '../vo/OfflineDownloadVo';\n\n/**\n * @module OfflineController\n * @param {Object} config - dependencies\n * @description Provides access to offline stream recording and playback functionality.\n */\nfunction OfflineController(config) {\n\n const context = this.context;\n const errHandler = config.errHandler;\n const events = config.events;\n const errors = config.errors;\n const settings = config.settings;\n const eventBus = config.eventBus;\n const debug = config.debug;\n const manifestLoader = config.manifestLoader;\n const manifestModel = config.manifestModel;\n const mediaPlayerModel = config.mediaPlayerModel;\n const abrController = config.abrController;\n const playbackController = config.playbackController;\n const dashMetrics = config.dashMetrics;\n const timelineConverter = config.timelineConverter;\n const adapter = config.adapter;\n const manifestUpdater = config.manifestUpdater;\n const baseURLController = config.baseURLController;\n const schemeLoaderFactory = config.schemeLoaderFactory;\n const constants = config.constants;\n const dashConstants = config.dashConstants;\n const urlUtils = config.urlUtils;\n\n let instance,\n downloads,\n logger,\n offlineStoreController,\n offlineUrlUtils;\n\n function setup() {\n logger = debug.getLogger(instance);\n offlineStoreController = OfflineStoreController(context).create({\n eventBus: config.eventBus,\n errHandler: errHandler\n });\n offlineUrlUtils = OfflineUrlUtils(context).getInstance();\n urlUtils.registerUrlRegex(offlineUrlUtils.getRegex(), offlineUrlUtils);\n schemeLoaderFactory.registerLoader(OfflineConstants.OFFLINE_SCHEME, IndexDBOfflineLoader);\n\n downloads = [];\n }\n\n /*\n ---------------------------------------------------------------------------\n DOWNLOAD LIST FUNCTIONS\n ---------------------------------------------------------------------------\n */\n function getDownloadFromId(id) {\n let download = downloads.find((item) => {\n return item.getId() === id;\n });\n return download;\n }\n\n function createDownloadFromId(id) {\n let download;\n download = getDownloadFromId(id);\n\n if (!download) {\n // create download controller\n download = OfflineDownload(context).create({\n id: id,\n eventBus: eventBus,\n events: events,\n errors: errors,\n settings: settings,\n manifestLoader: manifestLoader,\n manifestModel: manifestModel,\n mediaPlayerModel: mediaPlayerModel,\n manifestUpdater: manifestUpdater,\n baseURLController: baseURLController,\n abrController: abrController,\n playbackController: playbackController,\n adapter: adapter,\n dashMetrics: dashMetrics,\n timelineConverter: timelineConverter,\n errHandler: errHandler,\n offlineStoreController: offlineStoreController,\n debug: debug,\n constants: constants,\n dashConstants: dashConstants,\n urlUtils: urlUtils\n });\n\n downloads.push(download);\n }\n\n return download;\n }\n\n function createDownloadFromStorage(offline) {\n let download = getDownloadFromId(offline.manifestId);\n\n if (!download) {\n download = createDownloadFromId(offline.manifestId);\n let status = offline.status;\n if (status === OfflineConstants.OFFLINE_STATUS_STARTED) {\n status = OfflineConstants.OFFLINE_STATUS_STOPPED;\n }\n\n download.setInitialState({\n url: offline.url,\n progress: offline.progress,\n originalUrl: offline.originalURL,\n status: status\n });\n }\n\n return download;\n }\n\n function removeDownloadFromId(id) {\n return new Promise(function (resolve, reject) {\n let download = getDownloadFromId(id);\n let waitForStatusChanged = false;\n if (download) {\n //is download running?\n if (download.isDownloading()) {\n //register status changed event\n waitForStatusChanged = true;\n const downloadStopped = function () {\n eventBus.off(events.OFFLINE_RECORD_STOPPED, downloadStopped, instance);\n return offlineStoreController.deleteDownloadById(id).then(function () {\n resolve();\n }).catch(function (err) {\n reject(err);\n });\n };\n eventBus.on(events.OFFLINE_RECORD_STOPPED, downloadStopped, instance);\n }\n download.deleteDownload();\n let index = downloads.indexOf(download);\n downloads.splice(index, 1);\n }\n\n if (!waitForStatusChanged) {\n resolve();\n }\n });\n }\n\n function generateManifestId() {\n let timestamp = new Date().getTime();\n return timestamp;\n }\n\n /*\n ---------------------------------------------------------------------------\n\n OFFLINE CONTROLLER API\n\n ---------------------------------------------------------------------------\n */\n\n /**\n * Loads records from storage\n * This methods has to be called first, to be sure that all downloads have been loaded\n *\n * @return {Promise} asynchronously resolved\n * @memberof module:OfflineController\n */\n function loadRecordsFromStorage() {\n return new Promise(function (resolve, reject) {\n offlineStoreController.getAllManifests().then((items) => {\n items.manifests.forEach((offline) => {\n createDownloadFromStorage(offline);\n });\n\n resolve();\n }).catch((e) => {\n logger.error('Failed to load downloads ' + e);\n reject(e);\n });\n });\n }\n\n /**\n * Get all records from storage\n *\n * @return {Promise} asynchronously resolved with records\n * @memberof module:OfflineController\n * @instance\n */\n function getAllRecords() {\n let records = [];\n downloads.forEach((download) => {\n const record = new OfflineRecord();\n record.id = download.getId();\n record.progress = download.getDownloadProgression();\n record.url = download.getOfflineUrl();\n record.originalUrl = download.getManifestUrl();\n record.status = download.getStatus();\n records.push(record);\n });\n return records;\n }\n\n /**\n * Create a new content record in storage and download manifest from url\n *\n * @param {string} manifestURL - the content manifest url\n * @return {Promise} asynchronously resolved with record identifier\n * @memberof module:OfflineController\n * @instance\n */\n function createRecord(manifestURL) {\n return new Promise(function (resolve, reject) {\n let id = generateManifestId();\n\n // create download controller\n let download = createDownloadFromId(id);\n\n download.downloadFromUrl(manifestURL).then(() => {\n download.initDownload();\n resolve(id);\n })\n .catch((e) => {\n logger.error('Failed to download ' + e);\n removeDownloadFromId(id).then(function () {\n reject(e);\n });\n });\n });\n }\n\n /**\n * Start downloading the record with selected tracks representations\n *\n * @param {string} id - record identifier\n * @param {MediaInfo[]} mediaInfos - the selected tracks representations\n * @memberof module:OfflineController\n * @instance\n */\n function startRecord(id, mediaInfos) {\n let download = getDownloadFromId(id);\n if (download) {\n download.startDownload(mediaInfos);\n }\n }\n\n /**\n * Stop downloading of the record\n *\n * @param {string} id - record identifier\n * @memberof module:OfflineController\n * @instance\n */\n function stopRecord(id) {\n let download = getDownloadFromId(id);\n if (download) {\n download.stopDownload();\n }\n }\n\n /**\n * Resume downloading of the record\n *\n * @param {string} id - record identifier\n * @memberof module:OfflineController\n * @instance\n */\n function resumeRecord(id) {\n let download = getDownloadFromId(id);\n if (download) {\n download.resumeDownload();\n }\n }\n\n /**\n * Deletes a record from storage\n *\n * @param {string} id - record identifier\n * @memberof module:OfflineController\n * @instance\n */\n function deleteRecord(id) {\n return removeDownloadFromId(id).then(function () {\n return offlineStoreController.deleteDownloadById(id);\n });\n }\n\n\n /**\n * Get download progression of a record\n *\n * @param {string} id - record identifier\n * @return {number} percentage progression\n * @memberof module:OfflineController\n * @instance\n */\n function getRecordProgression(id) {\n let download = getDownloadFromId(id);\n if (download) {\n return download.getDownloadProgression();\n }\n return 0;\n }\n\n /**\n * Reset all records\n * @memberof module:OfflineController\n * @instance\n */\n function resetRecords() {\n downloads.forEach((download) => {\n download.resetDownload();\n });\n }\n\n /**\n * Reset\n * @instance\n */\n function reset() {\n resetRecords();\n schemeLoaderFactory.unregisterLoader(OfflineConstants.OFFLINE_SCHEME);\n }\n\n instance = {\n loadRecordsFromStorage: loadRecordsFromStorage,\n createRecord: createRecord,\n startRecord: startRecord,\n stopRecord: stopRecord,\n resumeRecord: resumeRecord,\n deleteRecord: deleteRecord,\n getRecordProgression: getRecordProgression,\n getAllRecords: getAllRecords,\n resetRecords: resetRecords,\n reset: reset\n };\n\n setup();\n\n return instance;\n}\n\nOfflineController.__dashjs_factory_name = 'OfflineController';\nconst factory = dashjs.FactoryMaker.getClassFactory(OfflineController); /* jshint ignore:line */\nfactory.events = OfflineEvents;\nfactory.errors = OfflineErrors;\ndashjs.FactoryMaker.updateClassFactory(OfflineController.__dashjs_factory_name, factory); /* jshint ignore:line */\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport IndexDBStore from '../storage/IndexDBStore';\nimport OfflineErrors from '../errors/OfflineErrors';\n\n/**\n * @class OfflineStoreController\n * @description This class manages database store\n * @param {object} config\n * @ignore\n */\nfunction OfflineStoreController(config) {\n\n config = config || {};\n const context = this.context;\n const errHandler = config.errHandler;\n\n let instance,\n indexDBStore;\n\n function setup() {\n indexDBStore = IndexDBStore(context).getInstance();\n }\n\n function createFragmentStore(manifestId, storeName) {\n try {\n indexDBStore.createFragmentStore(manifestId, storeName);\n } catch (err) {\n manageDOMError(err);\n }\n }\n\n function storeFragment(manifestId, fragmentId, fragmentData) {\n return indexDBStore.storeFragment(manifestId, fragmentId, fragmentData).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function createOfflineManifest(manifest) {\n return indexDBStore.storeManifest(manifest).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function updateOfflineManifest(manifest) {\n return indexDBStore.updateManifest(manifest).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function getManifestById(manifestId) {\n return indexDBStore.getManifestById(manifestId).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function saveSelectedRepresentations (manifestId, selected) {\n return indexDBStore.saveSelectedRepresentations(manifestId, selected).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function getCurrentHigherManifestId() {\n return indexDBStore.getCurrentHigherManifestId().catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function getAllManifests() {\n return indexDBStore.getAllManifests().catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function deleteDownloadById(manifestId) {\n return indexDBStore.deleteDownloadById(manifestId).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function setDownloadingStatus(manifestId, status) {\n return indexDBStore.setDownloadingStatus(manifestId, status).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function setRepresentationCurrentState(manifestId, representationId, state) {\n return indexDBStore.setRepresentationCurrentState(manifestId, representationId, state).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function getRepresentationCurrentState(manifestId, representationId) {\n return indexDBStore.getRepresentationCurrentState(manifestId, representationId).catch(function (err) {\n manageDOMError(err);\n });\n }\n\n function manageDOMError(err) {\n let error;\n if (err) {\n switch (err.name) {\n case 'QuotaExceededError':\n error = OfflineErrors.INDEXEDDB_QUOTA_EXCEED_ERROR;\n break;\n case 'InvalidStateError':\n error = OfflineErrors.INDEXEDDB_INVALID_STATE_ERROR;\n break;\n case 'NotFoundError':\n error = OfflineErrors.INDEXEDDB_NOT_FOUND_ERROR;\n break;\n case 'VersionError':\n error = OfflineErrors.INDEXEDDB_VERSION_ERROR;\n break;\n // TODO : Manage all DOM cases\n }\n\n // avoid importing DashJSError object from streaming\n errHandler.error({code: error, message: err.name, data: err});\n }\n }\n\n instance = {\n storeFragment: storeFragment,\n createOfflineManifest: createOfflineManifest,\n updateOfflineManifest: updateOfflineManifest,\n getManifestById: getManifestById,\n saveSelectedRepresentations: saveSelectedRepresentations,\n createFragmentStore: createFragmentStore,\n getCurrentHigherManifestId: getCurrentHigherManifestId,\n getAllManifests: getAllManifests,\n deleteDownloadById: deleteDownloadById,\n setDownloadingStatus: setDownloadingStatus,\n setRepresentationCurrentState: setRepresentationCurrentState,\n getRepresentationCurrentState: getRepresentationCurrentState\n };\n\n setup();\n\n return instance;\n}\n\nOfflineStoreController.__dashjs_factory_name = 'OfflineStoreController';\nexport default dashjs.FactoryMaker.getClassFactory(OfflineStoreController); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport ErrorsBase from '../../core/errors/ErrorsBase';\n/**\n * Offline Errors declaration\n * @class\n */\nclass OfflineErrors extends ErrorsBase {\n constructor () {\n\n super();\n\n /**\n * Error code returned when an error occurs in offline module\n */\n this.OFFLINE_ERROR = 11000;\n\n // Based upon https://developer.mozilla.org/fr/docs/Web/API/DOMException\n this.INDEXEDDB_QUOTA_EXCEED_ERROR = 11001;\n this.INDEXEDDB_INVALID_STATE_ERROR = 11002;\n this.INDEXEDDB_NOT_READABLE_ERROR = 11003;\n this.INDEXEDDB_NOT_FOUND_ERROR = 11004;\n this.INDEXEDDB_NETWORK_ERROR = 11005;\n this.INDEXEDDB_DATA_ERROR = 11006;\n this.INDEXEDDB_TRANSACTION_INACTIVE_ERROR = 11007;\n this.INDEXEDDB_NOT_ALLOWED_ERROR = 11008;\n this.INDEXEDDB_NOT_SUPPORTED_ERROR = 11009;\n this.INDEXEDDB_VERSION_ERROR = 11010;\n this.INDEXEDDB_TIMEOUT_ERROR = 11011;\n this.INDEXEDDB_ABORT_ERROR = 11012;\n this.INDEXEDDB_UNKNOWN_ERROR = 11013;\n }\n}\n\nlet offlineErrors = new OfflineErrors();\nexport default offlineErrors;\n",
"import EventsBase from './../../core/events/EventsBase';\n/**\n * These are offline events that should be sent to the player level.\n * @class\n */\nclass OfflineEvents extends EventsBase {\n constructor () {\n super();\n\n /**\n * Triggered when all mediaInfo has been loaded\n * @event OfflineEvents#OFFLINE_RECORD_LOADEDMETADATA\n */\n this.OFFLINE_RECORD_LOADEDMETADATA = 'public_offlineRecordLoadedmetadata';\n\n /**\n * Triggered when a record is initialized and download is started\n * @event OfflineEvents#OFFLINE_RECORD_STARTED\n */\n this.OFFLINE_RECORD_STARTED = 'public_offlineRecordStarted';\n\n /**\n * Triggered when the user stop downloading a record\n * @event OfflineEvents#OFFLINE_RECORD_STOPPED\n */\n this.OFFLINE_RECORD_STOPPED = 'public_offlineRecordStopped';\n\n /**\n * Triggered when all record has been downloaded\n * @event OfflineEvents#OFFLINE_RECORD_FINISHED\n */\n this.OFFLINE_RECORD_FINISHED = 'public_offlineRecordFinished';\n }\n}\n\nlet offlineEvents = new OfflineEvents();\nexport default offlineEvents;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport OfflineController from './controllers/OfflineController';\n\n// Shove both of these into the global scope\nvar context = (typeof window !== 'undefined' && window) || global;\n\nvar dashjs = context.dashjs;\nif (!dashjs) {\n dashjs = context.dashjs = {};\n}\n\ndashjs.OfflineController = OfflineController;\n\nexport default dashjs;\nexport { OfflineController };\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport IndexDBStore from '../storage/IndexDBStore';\n\nfunction IndexDBOfflineLoader(config) {\n config = config || {};\n const context = this.context;\n const urlUtils = config.urlUtils;\n const constants = config.constants;\n const dashConstants = config.dashConstants;\n\n let instance,\n indexDBStore;\n\n function setup() {\n indexDBStore = IndexDBStore(context).getInstance();\n }\n\n function getManifestId (url) {\n let myURL = urlUtils.removeHostname(url);\n var parts = myURL.split('/');\n return parts[0];\n }\n /**\n * Load manifest or fragment from indexeddb database\n * @param {object} config configuration of request\n */\n function load(config) {\n if (config.request) {\n let manifestId = getManifestId(config.request.url);\n if (manifestId % 1 === 0) {\n if (\n config.request.mediaType === constants.AUDIO ||\n config.request.mediaType === constants.VIDEO ||\n config.request.mediaType === constants.TEXT ||\n config.request.mediaType === constants.MUXED ||\n config.request.mediaType === constants.IMAGE ||\n config.request.mediaType === constants.FRAGMENTED_TEXT ||\n config.request.mediaType === constants.EMBEDDED_TEXT\n ) {\n let suffix = config.request.type === 'InitializationSegment' ? 'init' : config.request.index;\n let key = config.request.representationId + '_' + suffix;\n indexDBStore.getFragmentByKey(manifestId, key).then(function (fragment) {\n config.success(fragment, null, config.request.url, constants.ARRAY_BUFFER);\n }).catch(function (err) {\n config.error(err);\n });\n } else if (config.request.type === dashConstants.MPD) {\n indexDBStore.getManifestById(manifestId).then(function (item) {\n indexDBStore.createFragmentStore(item.fragmentStore);\n config.success(item.manifest, null, config.request.url, constants.XML);\n }).catch(function (err) {\n config.error(config.request, 404, err);\n });\n }\n } else {\n config.error(config.request, null, 'MediaType can not be found');\n }\n }\n }\n\n function abort() {\n // nothing to do\n }\n\n setup();\n\n instance = {\n load: load,\n abort: abort\n };\n\n return instance;\n}\n\nIndexDBOfflineLoader.__dashjs_factory_name = 'IndexDBOfflineLoader';\nconst factory = dashjs.FactoryMaker.getClassFactory(IndexDBOfflineLoader); /* jshint ignore:line */\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nconst localforage = require('localforage');\nconst entities = require('html-entities').XmlEntities;\n\n/**\n * @ignore\n */\nfunction IndexDBStore() {\n\n let instance,\n manifestStore,\n fragmentStores;\n\n function setup() {\n fragmentStores = {};\n\n if (typeof window === 'undefined') {\n return;\n }\n\n localforage.config({\n driver: localforage.INDEXEDDB,\n name: 'dash_offline_db'\n });\n\n manifestStore = localforage.createInstance({\n driver: localforage.INDEXEDDB,\n name: 'dash_offline_db',\n version: 1.0,\n storeName: 'manifest'\n });\n }\n\n /////////////////////////////////////////\n //\n // GET/SET Methods\n //\n ////////////////////////////////////////\n\n /**\n * Creates an instance of localforage to store fragments in indexed db\n * @param {string} storeName\n * @instance\n */\n function createFragmentStore(storeName) {\n\n if (!fragmentStores[storeName]) {\n console.log('setStore ' + storeName);\n let fragmentStore = localforage.createInstance({\n driver: localforage.INDEXEDDB,\n name: 'dash_offline_db',\n version: 1.0,\n storeName: storeName\n });\n fragmentStores[storeName] = fragmentStore;\n }\n }\n\n /**\n * Update download status\n * @param {number} manifestId\n * @param {string} newStatus\n * @returns {Promise} promise\n * @instance\n */\n function setDownloadingStatus(manifestId, newStatus) {\n return getManifestById(manifestId).then(function (item) {\n item.status = newStatus;\n return updateManifest(item).catch(function () {\n return Promise.reject('Cannot set status ' + newStatus + ' for this stream !');\n });\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Updat last downloaded fragment index for representationId\n * @param {number} manifestId - manifest id\n * @param {string} representationId - representation\n * @param {number} state - representation state\n * @returns {Promise} promise\n * @instance\n */\n function setRepresentationCurrentState(manifestId, representationId, state) {\n return getManifestById(manifestId).then(function (item) {\n if (!item.state) {\n item.state = {};\n }\n\n if (!item.state[representationId]) {\n item.state[representationId] = {\n index: -1,\n downloaded: 0\n };\n }\n\n item.state[representationId] = state;\n return updateManifest(item).catch(function () {\n return Promise.reject('Cannot set current index for represenation id ' + representationId);\n });\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Returns current downloaded segment index for representation\n * @param {number} manifestId - manifest id\n * @param {string} representationId - representation\n * @returns {Promise} promise\n * @instance\n */\n function getRepresentationCurrentState(manifestId, representationId) {\n return getManifestById(manifestId).then(function (item) {\n let state = {\n index: -1,\n downloaded: 0\n };\n if (item.state && item.state[representationId]) {\n state = item.state[representationId];\n }\n return Promise.resolve(state);\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Returns a fragment from its key\n * @param {number} manifestId\n * @param {number} key\n * @returns {Promise} fragment\n * @instance\n */\n function getFragmentByKey(manifestId, key) {\n let fragmentStore = fragmentStores[manifestId];\n\n if (!fragmentStore) {\n return Promise.reject(new Error (`No fragment store found for manifest ${manifestId}`));\n }\n\n return fragmentStore.getItem(key).then(function (value) {\n return Promise.resolve(value);\n }).catch(function (err) {\n return Promise.reject(err);\n });\n\n }\n\n /**\n * Returns a manifest from its identifier\n * @param {number} id\n * @returns {Promise} {Object[]} manifests\n * @instance\n */\n function getManifestById(id) {\n return getAllManifests().then(function (array) {\n if (array) {\n let item = null;\n for (let i = 0; i < array.manifests.length; i++) {\n if (array.manifests[i].manifestId === parseInt(id)) {\n item = array.manifests[i];\n }\n }\n if (item !== null) {\n item.manifest = entities.decode(item.manifest);\n return Promise.resolve(item);\n } else {\n return Promise.reject('Cannot found manifest with this manifestId : ' + id);\n }\n } else {\n return Promise.reject('Any manifests stored in DB !');\n }\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Returns all offline manifests\n * @returns {Promise} {Object[]} manifests\n * @instance\n */\n function getAllManifests() {\n return manifestStore.getItem('manifest').then(function (array) {\n return Promise.resolve(array ? array : {\n 'manifests': []\n });\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Return higher manifest id\n * @returns {Promise} number\n * @instance\n */\n function getCurrentHigherManifestId() {\n return getAllManifests().then(function (array) {\n let higherManifestId = 0;\n if (array) {\n for (let i = 0; i < array.manifests.length; i++) {\n if (array.manifests[i].manifestId > higherManifestId) {\n higherManifestId = array.manifests[i].manifestId;\n }\n }\n return Promise.resolve(higherManifestId);\n } else {\n return Promise.resolve(higherManifestId);\n }\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Update manifest\n * @param {Object} manifest updated manifest\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function updateManifest(manifest) {\n return getAllManifests().then(function (array) {\n try {\n for (let i = 0; i < array.manifests.length; i++) {\n if (array.manifests[i].manifestId === manifest.manifestId) {\n array.manifests[i] = manifest;\n }\n }\n return manifestStore.setItem('manifest', array);\n } catch (err) {\n throw new Error('Any results found !');\n }\n });\n }\n\n /**\n * save selected representation by user\n * @param {Object} manifest updated manifest\n * @param {Object} selected selected representations\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function saveSelectedRepresentations(manifest, selected) {\n return getManifestById(manifest).then(function (item) {\n if (!item.selected) {\n item.selected = {};\n }\n\n item.selected = selected;\n return updateManifest(item).catch(function () {\n return Promise.reject('Cannot save selected representations');\n });\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Store a manifest in manifest array\n * @param {Object} manifest\n * @instance\n */\n function storeManifest(manifest) {\n return manifestStore.getItem('manifest').then(function (results) {\n let array = results ? results : {\n 'manifests': []\n };\n array.manifests.push(manifest);\n return manifestStore.setItem('manifest', array);\n });\n }\n\n /**\n * Store a fragment in fragment store\n * @param {number} manifestId\n * @param {number} fragmentId\n * @param {Object} fragmentData\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function storeFragment(manifestId, fragmentId, fragmentData) {\n let fragmentStore = fragmentStores[manifestId];\n\n if (!fragmentStore) {\n return Promise.reject(new Error (`No fragment store found for manifest ${manifestId}`));\n }\n\n return fragmentStore.setItem(fragmentId, fragmentData, function () {\n return Promise.resolve();\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /////////////////////////////////////////\n //\n // DROP Methods\n //\n ////////////////////////////////////////\n\n /**\n * Remove all manifest and fragment store\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function dropAll() {\n return localforage.clear().then(function () {\n return Promise.resolve();\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Remove framgent store given its name\n * @param {string} storeName\n * @instance\n */\n function dropFragmentStore(storeName) {\n localforage.dropInstance({\n driver: localforage.INDEXEDDB,\n name: 'dash_offline_db',\n version: 1.0,\n storeName: storeName\n }).then(function () {\n delete fragmentStores[storeName];\n }).catch(function (err) {\n console.log('dropFragmentStore failed ' + err);\n });\n return;\n }\n\n /**\n * Remove download given its id (fragmentStore + manifest entry in manifest array)\n * @param {number} manifestId\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function deleteDownloadById(manifestId) {\n return manifestStore.getItem('manifest').then(function (array) {\n if (array) {\n return deleteFragmentStore(manifestId).then(function () {\n for (let i = 0; i < array.manifests.length; i++) {\n if (array.manifests[i].manifestId === parseInt(manifestId)) {\n array.manifests.splice(i, 1);\n }\n }\n return manifestStore.setItem('manifest', array).then(function () {\n return Promise.resolve('This stream has been successfull removed !');\n }).catch(function () {\n return Promise.reject('An error occured when trying to delete this manifest');\n });\n });\n } else {\n return Promise.resolve('Nothing to delete !');\n }\n }).catch(function (err) {\n return Promise.reject(err);\n });\n }\n\n /**\n * Remove fragment store\n * @param {string} storeName\n * @returns {Promise} promise asynchronously resolved\n * @instance\n */\n function deleteFragmentStore(storeName) {\n localforage.createInstance({\n name: 'dash_offline_db',\n storeName: storeName\n });\n return localforage.dropInstance({\n name: 'dash_offline_db',\n storeName: storeName\n }).then(function () {\n delete fragmentStores[storeName];\n return Promise.resolve();\n }).catch(function (err) {\n console.log(err);\n return Promise.reject(err);\n });\n\n }\n\n\n setup();\n\n instance = {\n dropAll: dropAll,\n getFragmentByKey: getFragmentByKey,\n getManifestById: getManifestById,\n storeFragment: storeFragment,\n storeManifest: storeManifest,\n updateManifest: updateManifest,\n saveSelectedRepresentations: saveSelectedRepresentations,\n createFragmentStore: createFragmentStore,\n setDownloadingStatus: setDownloadingStatus,\n setRepresentationCurrentState: setRepresentationCurrentState,\n getRepresentationCurrentState: getRepresentationCurrentState,\n getCurrentHigherManifestId: getCurrentHigherManifestId,\n getAllManifests: getAllManifests,\n dropFragmentStore: dropFragmentStore,\n deleteDownloadById: deleteDownloadById\n };\n\n return instance;\n}\n\nIndexDBStore.__dashjs_factory_name = 'IndexDBStore';\nexport default dashjs.FactoryMaker.getSingletonFactory(IndexDBStore); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst Entities = require('html-entities').XmlEntities;\nconst OFFLINE_BASE_URL = 'offline_indexeddb://';\n\nfunction OfflineIndexDBManifestParser(config) {\n\n const manifestId = config.manifestId;\n const allMediaInfos = config.allMediaInfos;\n const urlUtils = config.urlUtils;\n const debug = config.debug;\n const dashConstants = config.dashConstants;\n const constants = config.constants;\n\n let instance,\n DOM,\n logger;\n\n\n function setup() {\n logger = debug.getLogger(instance);\n }\n\n /**\n * Parse XML manifest\n * @param {string} XMLDoc - xml manifest\n * @param {object} representation\n * @returns {Promise} a promise that will be resolved or rejected at the end of encoding process\n * @instance\n */\n function parse(XMLDoc, representation) {\n return new Promise(function (resolve, reject) {\n\n DOM = new DOMParser().parseFromString(XMLDoc, 'application/xml');\n let mpd = DOM.getElementsByTagName(dashConstants.MPD) ? DOM.getElementsByTagName(dashConstants.MPD) : null;\n\n for (let i = 0; i < mpd.length; i++) {\n if (mpd[i] !== null) {\n editBaseURLAttribute(mpd[i]);\n browsePeriods(mpd[i], representation);\n }\n }\n\n let manifestEncoded = encodeManifest(DOM);\n if (manifestEncoded !== '') {\n resolve(manifestEncoded);\n } else {\n reject('Encoded error');\n }\n });\n }\n\n /**\n * URL encode parsed manifest\n * @param {string} DOM\n * @returns {string} Url encoded XML\n * @instance\n */\n function encodeManifest(DOM) {\n logger.info('encodedManifest ' + new XMLSerializer().serializeToString(DOM));\n return new Entities().encode(new XMLSerializer().serializeToString(DOM));\n }\n\n /**\n * Update baseURL to point to local stored data P\n * @param {XML} currentMPD\n * @instance\n */\n function editBaseURLAttribute(currentMPD) {\n let basesURL,\n fragmentId,\n representationId;\n\n let url = `${OFFLINE_BASE_URL}${manifestId}/`;\n\n basesURL = currentMPD.getElementsByTagName(dashConstants.BASE_URL);\n\n if (basesURL.length === 0) {\n // add baseURL\n let element = DOM.createElement(dashConstants.BASE_URL);\n element.innerHTML = url;\n currentMPD.appendChild(element);\n }\n basesURL = currentMPD.getElementsByTagName(dashConstants.BASE_URL);\n for (let i = 0; i < basesURL.length; i++) {\n let parent = basesURL[i].parentNode;\n\n if (parent.nodeName === dashConstants.MPD) {\n basesURL[i].innerHTML = url;\n } else if (parent.nodeName === dashConstants.REPRESENTATION) {\n let adaptationsSet = parent.parentNode;\n if (adaptationsSet.nodeName == dashConstants.ADAPTATION_SET) {\n\n if (urlUtils.isHTTPS(basesURL[i].innerHTML) || urlUtils.isHTTPURL(basesURL[i].innerHTML)) {\n fragmentId = getFragmentId(basesURL[i].innerHTML);\n representationId = getBestRepresentationId(adaptationsSet);\n basesURL[i].innerHTML = url + representationId + '_' + fragmentId;\n } else if (basesURL[i].innerHTML === './') {\n basesURL[i].innerHTML = url;\n } else {\n fragmentId = getFragmentId(basesURL[i].innerHTML);\n representationId = getBestRepresentationId(adaptationsSet);\n basesURL[i].innerHTML = representationId + '_' + fragmentId;\n }\n }\n } else {\n basesURL[i].innerHTML = url;\n }\n }\n }\n\n /**\n * Browse periods\n * @param {XML} currentMPD\n * @param {Object} representation\n * @instance\n */\n function browsePeriods(currentMPD, representation) {\n let periods = currentMPD.getElementsByTagName(dashConstants.PERIOD);\n for (let j = 0; j < periods.length; j++) {\n browseAdaptationsSet(periods[j], representation);\n }\n }\n\n /**\n * Browse adapatation set to update data (delete those taht are not choosen by user ...)\n * @param {XML} currentPeriod\n * @param {Array} representationsToUpdate\n * @instance\n */\n function browseAdaptationsSet(currentPeriod, representationsToUpdate) {\n let adaptationsSet,\n currentAdaptationSet,\n currentAdaptationType,\n representations;\n\n adaptationsSet = currentPeriod.getElementsByTagName(dashConstants.ADAPTATION_SET);\n\n for (let i = adaptationsSet.length - 1; i >= 0; i--) {\n currentAdaptationSet = adaptationsSet[i];\n if (currentAdaptationSet) {\n currentAdaptationType = findAdaptationType(currentAdaptationSet);\n representations = findRepresentations(currentAdaptationSet);\n\n findAndKeepOnlySelectedRepresentations(currentAdaptationSet, representations, currentAdaptationType);\n\n representations = findRepresentations(currentAdaptationSet);\n\n deleteSegmentBase(currentAdaptationSet);\n\n if (representations.length === 0) {\n currentPeriod.removeChild(currentAdaptationSet);\n } else {\n //detect Segment list use case\n for (let i = 0; i < representations.length; i++) {\n let rep = representations[i];\n let segmentList = getSegmentList(rep);\n if (segmentList.length >= 1) {\n editSegmentListAttributes(segmentList, rep);\n }\n }\n\n let segmentTemplate = getSegmentTemplate(currentAdaptationSet);\n // segmentTemplate is defined, update attributes in order to be correctly played offline\n if (segmentTemplate.length >= 1) {\n editSegmentTemplateAttributes(segmentTemplate);\n }\n\n // detect SegmentBase use case => transfrom manifest to SegmentList in SegmentTemplate\n if (representationsToUpdate && representationsToUpdate.length > 0 ) {\n let selectedRep;\n for (let i = 0; i < representations.length; i++) {\n let rep = representations[i];\n for (let j = 0; representationsToUpdate && j < representationsToUpdate.length; j++) {\n if (representationsToUpdate[j].id === rep.id) {\n selectedRep = representationsToUpdate[j];\n break;\n }\n }\n }\n addSegmentTemplateAttributes(currentAdaptationSet, selectedRep);\n }\n }\n }\n }\n }\n\n /**\n * Returns type of adapation set\n * @param {XML} currentAdaptationSet\n * @returns {string|null} type\n * @instance\n */\n function findAdaptationType(currentAdaptationSet) {\n if (getIsMuxed(currentAdaptationSet)) {\n return constants.MUXED;\n } else if (getIsAudio(currentAdaptationSet)) {\n return constants.AUDIO;\n } else if (getIsVideo(currentAdaptationSet)) {\n return constants.VIDEO;\n } else if (getIsFragmentedText(currentAdaptationSet)) {\n return constants.FRAGMENTED_TEXT;\n } else if (getIsImage(currentAdaptationSet)) {\n return constants.IMAGE;\n }\n\n return constants.TEXT;\n }\n\n function getIsAudio(adaptation) {\n return getIsTypeOf(adaptation, constants.AUDIO);\n }\n\n function getIsVideo(adaptation) {\n return getIsTypeOf(adaptation, constants.VIDEO);\n }\n\n function getIsFragmentedText(adaptation) {\n return getIsTypeOf(adaptation, constants.FRAGMENTED_TEXT);\n }\n\n function getIsMuxed(adaptation) {\n return getIsTypeOf(adaptation, constants.MUXED);\n }\n\n function getIsImage(adaptation) {\n return getIsTypeOf(adaptation, constants.IMAGE);\n }\n\n // based upon DashManifestModel, but using DomParser\n function getIsTypeOf(adaptation, type) {\n\n if (!adaptation) {\n throw new Error('adaptation is not defined');\n }\n\n if (!type) {\n throw new Error('type is not defined');\n }\n\n // 1. check codecs for fragmented text\n if (isFragmentedTextCodecFound(adaptation)) {\n // fragmented text codec has been found for adaptation, let's check if tested type is fragmented text\n return type === constants.FRAGMENTED_TEXT;\n }\n\n // 2. test mime type\n return testMimeType(adaptation, type);\n }\n\n function testMimeType(adaptation, type) {\n let mimeTypeRegEx = (type !== constants.TEXT) ? new RegExp(type) : new RegExp('(vtt|ttml)');\n\n let mimeType = findMimeType(adaptation);\n if (mimeType) {\n return mimeTypeRegEx.test(mimeType);\n }\n\n // no mime type in adaptation, search in representation\n let representations = findRepresentations(adaptation);\n if (representations) {\n for (let i = 0; i < representations.length; i++) {\n let representation = representations[i];\n mimeType = findMimeType(representation);\n if (mimeType) {\n return mimeTypeRegEx.test(mimeType);\n }\n }\n }\n return false;\n }\n\n /**\n * Search for fragmented text codec in adaptation (STPP or WVTT)\n * @param {Object} adaptation\n */\n function isFragmentedTextCodecFound (adaptation) {\n let isFragmentedTextCodecFoundInTag = function (tag) {\n let codecs = tag.getAttribute(dashConstants.CODECS);\n if (codecs) {\n if (codecs.search(constants.STPP) === 0 ||\n codecs.search(constants.WVTT) === 0 ) {\n return true;\n }\n }\n return false;\n };\n\n if (isFragmentedTextCodecFoundInTag(adaptation)) {\n return true;\n }\n\n // check in representations\n let representations = findRepresentations(adaptation);\n if (representations && representations.length > 0) {\n\n if (isFragmentedTextCodecFoundInTag(representations[0])) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Returns mime-type of xml tag\n * @param {Object} tag\n * @returns {string|null} mimeType\n * @instance\n */\n function findMimeType(tag) {\n return tag.getAttribute(dashConstants.MIME_TYPE);\n }\n\n /**\n * Returns representations of adaptation set\n * @param {XML} adaptation\n * @returns {XML} representations\n * @instance\n */\n function findRepresentations(adaptation) {\n return adaptation.getElementsByTagName(dashConstants.REPRESENTATION);\n }\n\n /**\n * Return segment template list of adaptations set\n * @param {XML} currentAdaptationSet\n * @returns {XML} representations\n * @instance\n */\n function getSegmentTemplate(currentAdaptationSet) {\n return currentAdaptationSet.getElementsByTagName(dashConstants.SEGMENT_TEMPLATE);\n }\n\n /**\n * Return segment list tags of adaptations set\n * @param {XML} tag\n * @returns {XML} representations\n * @instance\n */\n function getSegmentList(tag) {\n return tag.getElementsByTagName(dashConstants.SEGMENT_LIST);\n }\n\n function deleteSegmentBase(tag) {\n let elements = tag.getElementsByTagName(dashConstants.SEGMENT_BASE);\n for (let i = 0; i < elements.length; i++) {\n let segmentBase = elements[i];\n segmentBase.parentNode.removeChild(segmentBase);\n }\n }\n\n /**\n * @param {XML} segmentTemplate\n * @param {object} rep\n * @instance\n */\n function addSegmentTimelineElements(segmentTemplate, rep) {\n let S = DOM.createElement('S');\n if (rep && rep.segments) {\n let segmentTimelineElement = DOM.createElement(dashConstants.SEGMENT_TIMELINE);\n let changedDuration = getDurationChangeArray(rep);\n for (let i = 0; i < changedDuration.length; i++) {\n let repeatValue = i + 1 < changedDuration.length ? (changedDuration[i + 1] - changedDuration[i]) - 1 : 0;\n if (repeatValue > 1) {\n S.setAttribute('r', repeatValue);\n }\n S.setAttribute('d', rep.segments[changedDuration[i]].duration);\n segmentTimelineElement.appendChild(S);\n S = DOM.createElement('S');\n }\n segmentTemplate.appendChild(segmentTimelineElement);\n }\n }\n\n function getDurationChangeArray(rep) {\n let array = [];\n array.push(0);\n for (let i = 1; i < rep.segments.length; i++) {\n if (rep.segments[i - 1].duration !== rep.segments[i].duration) {\n array.push(i);\n }\n }\n return array;\n }\n\n /**\n * Update attributes of segment templates to match offline urls\n * @param {Array} segmentsTemplates\n * @instance\n */\n function editSegmentTemplateAttributes(segmentsTemplates) {\n for (let i = 0; i < segmentsTemplates.length; i++) {\n let media = segmentsTemplates[i].getAttribute(dashConstants.MEDIA);\n media = '$RepresentationID$_$Number$' + media.substring(media.indexOf('.'), media.length); //id + extension\n segmentsTemplates[i].setAttribute(dashConstants.START_NUMBER, '0');\n segmentsTemplates[i].setAttribute(dashConstants.MEDIA, media);\n segmentsTemplates[i].setAttribute(dashConstants.INITIALIZATION_MINUS,'$RepresentationID$_init');\n }\n }\n\n /**\n * Update attributes of segment list to match offline urls\n * @param {Array} segmentLists\n * @param {Object} representation\n * @instance\n */\n function editSegmentListAttributes(segmentLists, representation) {\n let repId = representation.getAttribute(dashConstants.ID);\n for (let i = 0; i < segmentLists.length; i++) {\n\n let segmentList = segmentLists[i];\n let initialisation = segmentList.getElementsByTagName(dashConstants.INITIALIZATION);\n if (initialisation) {\n let sourceURL = initialisation[0].getAttribute(dashConstants.SOURCE_URL);\n sourceURL = `${repId}_init`;\n initialisation[0].setAttribute(dashConstants.SOURCE_URL, sourceURL);\n }\n let segmentURLs = segmentList.getElementsByTagName(dashConstants.SEGMENT_URL);\n\n if (segmentURLs) {\n for (let j = 0; j < segmentURLs.length; j++) {\n let segmentUrl = segmentURLs[j];\n let media = segmentUrl.getAttribute(dashConstants.MEDIA);\n media = `${repId}_${j}`;\n segmentUrl.setAttribute(dashConstants.MEDIA, media);\n }\n }\n }\n }\n\n /**\n * @param {XML} adaptationSet\n * @param {object} rep\n * @instance\n */\n function addSegmentTemplateAttributes(adaptationSet, rep) {\n let segmentTemplateElement = DOM.createElement(dashConstants.SEGMENT_TEMPLATE);\n segmentTemplateElement.setAttribute(dashConstants.START_NUMBER, '0');\n segmentTemplateElement.setAttribute(dashConstants.MEDIA, '$RepresentationID$-$Time$');\n segmentTemplateElement.setAttribute(dashConstants.INITIALIZATION_MINUS,'$RepresentationID$_init');\n addSegmentTimelineElements(segmentTemplateElement, rep);\n adaptationSet.appendChild(segmentTemplateElement);\n }\n\n /**\n * Delete all representations except the one choosed by user\n * @param {XML} currentAdaptationSet\n * @param {XML} representations\n * @param {string} adaptationType\n * @instance\n */\n function findAndKeepOnlySelectedRepresentations(currentAdaptationSet, representations, adaptationType) {\n for ( var i = representations.length - 1; i >= 0; i--) {\n let representation = representations[i];\n let repId = representation.getAttribute(dashConstants.ID);\n if (allMediaInfos[adaptationType] && allMediaInfos[adaptationType].indexOf(repId) === -1) {\n // representation is not selected, remove it\n currentAdaptationSet.removeChild(representation);\n }\n }\n }\n\n // UTILS\n /**\n * Get id of first representation of adaptation set\n * @param {XMl} currentAdaptationSet\n * @returns {string} id\n * @instance\n */\n function getBestRepresentationId(currentAdaptationSet) {\n let bestRepresentation = currentAdaptationSet.getElementsByTagName(dashConstants.REPRESENTATION)[0];\n console.log(bestRepresentation.getAttribute(dashConstants.ID));\n return bestRepresentation.getAttribute(dashConstants.ID);\n }\n\n /**\n * Parse and returns fragments of offline url => xxxx://xxxx/fragmentId/\n * @param {string} url\n * @returns {string} fragmentId\n * @instance\n */\n function getFragmentId(url) {\n let idxFragId = url.lastIndexOf('/');\n //logger.warn('fragId : ' + url.substring(idxFragId + 1, url.length));\n return url.substring(idxFragId,url.length);\n }\n\n setup();\n\n instance = {\n parse: parse\n };\n\n return instance;\n}\nOfflineIndexDBManifestParser.__dashjs_factory_name = 'OfflineIndexDBManifestParser';\nexport default dashjs.FactoryMaker.getClassFactory(OfflineIndexDBManifestParser); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport OfflineConstants from '../constants/OfflineConstants';\n\nfunction OfflineUrlUtils() {\n\n function setup() {\n }\n\n function getRegex() {\n return OfflineConstants.OFFLINE_URL_REGEX;\n }\n\n /*\n * -------------------\n * SPECIFIC BEHAVIOUR\n * -------------------\n */\n function removeHostname(url) {\n return url.replace(/(^\\w+:|^)\\/\\//, '');\n }\n\n function isRelative() {\n return false;\n }\n\n function resolve(url, baseUrl) {\n if (baseUrl.charAt(baseUrl.length - 1 ) !== '/') {\n baseUrl = baseUrl.concat('/');\n }\n return baseUrl + url;\n }\n\n setup();\n const instance = {\n getRegex: getRegex,\n isRelative: isRelative,\n removeHostname: removeHostname,\n resolve: resolve\n };\n return instance;\n}\n\nOfflineUrlUtils.__dashjs_factory_name = 'OfflineUrlUtils';\nexport default dashjs.FactoryMaker.getSingletonFactory(OfflineUrlUtils); /* jshint ignore:line */\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass OfflineDownload {\n constructor() {\n this.id = null;\n this.url = null;\n this.originalUrl = null;\n this.status = null;\n this.progress = null;\n }\n}\n\nexport default OfflineDownload;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport Constants from './constants/Constants';\nimport URLLoader from './net/URLLoader';\nimport HeadRequest from './vo/HeadRequest';\nimport DashJSError from './vo/DashJSError';\nimport FactoryMaker from '../core/FactoryMaker';\n\nfunction FragmentLoader(config) {\n\n config = config || {};\n const context = this.context;\n const eventBus = config.eventBus;\n const events = config.events;\n const urlUtils = config.urlUtils;\n const errors = config.errors;\n\n let instance,\n urlLoader;\n\n function setup() {\n urlLoader = URLLoader(context).create({\n errHandler: config.errHandler,\n errors: errors,\n dashMetrics: config.dashMetrics,\n mediaPlayerModel: config.mediaPlayerModel,\n requestModifier: config.requestModifier,\n useFetch: config.settings.get().streaming.lowLatencyEnabled,\n urlUtils: urlUtils,\n constants: Constants,\n boxParser: config.boxParser,\n dashConstants: config.dashConstants\n });\n }\n\n function checkForExistence(request) {\n const report = function (success) {\n eventBus.trigger(\n events.CHECK_FOR_EXISTENCE_COMPLETED, {\n request: request,\n exists: success\n }\n );\n };\n\n if (request) {\n let headRequest = new HeadRequest(request.url);\n urlLoader.load({\n request: headRequest,\n success: function () {\n report(true);\n },\n error: function () {\n report(false);\n }\n });\n } else {\n report(false);\n }\n }\n\n function load(request) {\n const report = function (data, error) {\n eventBus.trigger(events.LOADING_COMPLETED, {\n request: request,\n response: data || null,\n error: error || null,\n sender: instance\n });\n };\n\n if (request) {\n urlLoader.load({\n request: request,\n progress: function (event) {\n eventBus.trigger(events.LOADING_PROGRESS, {\n request: request,\n stream: event.stream\n });\n if (event.data) {\n eventBus.trigger(events.LOADING_DATA_PROGRESS, {\n request: request,\n response: event.data || null,\n error: null,\n sender: instance\n });\n }\n },\n success: function (data) {\n report(data);\n },\n error: function (request, statusText, errorText) {\n report(\n undefined,\n new DashJSError(\n errors.FRAGMENT_LOADER_LOADING_FAILURE_ERROR_CODE,\n errorText,\n statusText\n )\n );\n },\n abort: function (request) {\n if (request) {\n eventBus.trigger(events.LOADING_ABANDONED, {request: request, mediaType: request.mediaType, sender: instance});\n }\n }\n });\n } else {\n report(\n undefined,\n new DashJSError(\n errors.FRAGMENT_LOADER_NULL_REQUEST_ERROR_CODE,\n errors.FRAGMENT_LOADER_NULL_REQUEST_ERROR_MESSAGE\n )\n );\n }\n }\n\n function abort() {\n if (urlLoader) {\n urlLoader.abort();\n }\n }\n\n function reset() {\n if (urlLoader) {\n urlLoader.abort();\n urlLoader = null;\n }\n }\n\n instance = {\n checkForExistence: checkForExistence,\n load: load,\n abort: abort,\n reset: reset\n };\n\n setup();\n\n return instance;\n}\n\nFragmentLoader.__dashjs_factory_name = 'FragmentLoader';\nexport default FactoryMaker.getClassFactory(FragmentLoader);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport EventsBase from '../core/events/EventsBase';\n/**\n * @class\n * @implements EventsBase\n */\nclass MediaPlayerEvents extends EventsBase {\n\n /**\n * @description Public facing external events to be used when developing a player that implements dash.js.\n */\n constructor() {\n super();\n /**\n * Triggered when playback will not start yet\n * as the MPD's availabilityStartTime is in the future.\n * Check delay property in payload to determine time before playback will start.\n * @event MediaPlayerEvents#AST_IN_FUTURE\n */\n this.AST_IN_FUTURE = 'astInFuture';\n\n /**\n * Triggered when the video element's buffer state changes to stalled.\n * Check mediaType in payload to determine type (Video, Audio, FragmentedText).\n * @event MediaPlayerEvents#BUFFER_EMPTY\n */\n this.BUFFER_EMPTY = 'bufferStalled';\n\n /**\n * Triggered when the video element's buffer state changes to loaded.\n * Check mediaType in payload to determine type (Video, Audio, FragmentedText).\n * @event MediaPlayerEvents#BUFFER_LOADED\n */\n this.BUFFER_LOADED = 'bufferLoaded';\n\n /**\n * Triggered when the video element's buffer state changes, either stalled or loaded. Check payload for state.\n * @event MediaPlayerEvents#BUFFER_LEVEL_STATE_CHANGED\n */\n this.BUFFER_LEVEL_STATE_CHANGED = 'bufferStateChanged';\n\n /**\n * Triggered when there is an error from the element or MSE source buffer.\n * @event MediaPlayerEvents#ERROR\n */\n this.ERROR = 'error';\n /**\n * Triggered when a fragment download has completed.\n * @event MediaPlayerEvents#FRAGMENT_LOADING_COMPLETED\n */\n this.FRAGMENT_LOADING_COMPLETED = 'fragmentLoadingCompleted';\n\n /**\n * Triggered when a partial fragment download has completed.\n * @event MediaPlayerEvents#FRAGMENT_LOADING_PROGRESS\n */\n this.FRAGMENT_LOADING_PROGRESS = 'fragmentLoadingProgress';\n /**\n * Triggered when a fragment download has started.\n * @event MediaPlayerEvents#FRAGMENT_LOADING_STARTED\n */\n this.FRAGMENT_LOADING_STARTED = 'fragmentLoadingStarted';\n\n /**\n * Triggered when a fragment download is abandoned due to detection of slow download base on the ABR abandon rule..\n * @event MediaPlayerEvents#FRAGMENT_LOADING_ABANDONED\n */\n this.FRAGMENT_LOADING_ABANDONED = 'fragmentLoadingAbandoned';\n\n /**\n * Triggered when {@link module:Debug} logger methods are called.\n * @event MediaPlayerEvents#LOG\n */\n this.LOG = 'log';\n\n //TODO refactor with internal event\n /**\n * Triggered when the manifest load is complete\n * @event MediaPlayerEvents#MANIFEST_LOADED\n */\n this.MANIFEST_LOADED = 'manifestLoaded';\n\n /**\n * Triggered anytime there is a change to the overall metrics.\n * @event MediaPlayerEvents#METRICS_CHANGED\n */\n this.METRICS_CHANGED = 'metricsChanged';\n\n /**\n * Triggered when an individual metric is added, updated or cleared.\n * @event MediaPlayerEvents#METRIC_CHANGED\n */\n this.METRIC_CHANGED = 'metricChanged';\n\n /**\n * Triggered every time a new metric is added.\n * @event MediaPlayerEvents#METRIC_ADDED\n */\n this.METRIC_ADDED = 'metricAdded';\n\n /**\n * Triggered every time a metric is updated.\n * @event MediaPlayerEvents#METRIC_UPDATED\n */\n this.METRIC_UPDATED = 'metricUpdated';\n\n /**\n * Triggered at the stream end of a period.\n * @event MediaPlayerEvents#PERIOD_SWITCH_COMPLETED\n */\n this.PERIOD_SWITCH_COMPLETED = 'periodSwitchCompleted';\n\n /**\n * Triggered when a new period starts.\n * @event MediaPlayerEvents#PERIOD_SWITCH_STARTED\n */\n this.PERIOD_SWITCH_STARTED = 'periodSwitchStarted';\n\n /**\n * Triggered when an ABR up /down switch is initiated; either by user in manual mode or auto mode via ABR rules.\n * @event MediaPlayerEvents#QUALITY_CHANGE_REQUESTED\n */\n this.QUALITY_CHANGE_REQUESTED = 'qualityChangeRequested';\n\n /**\n * Triggered when the new ABR quality is being rendered on-screen.\n * @event MediaPlayerEvents#QUALITY_CHANGE_RENDERED\n */\n this.QUALITY_CHANGE_RENDERED = 'qualityChangeRendered';\n\n /**\n * Triggered when the new track is being rendered.\n * @event MediaPlayerEvents#TRACK_CHANGE_RENDERED\n */\n this.TRACK_CHANGE_RENDERED = 'trackChangeRendered';\n\n /**\n * Triggered when the source is setup and ready.\n * @event MediaPlayerEvents#SOURCE_INITIALIZED\n */\n this.SOURCE_INITIALIZED = 'sourceInitialized';\n\n /**\n * Triggered when a stream (period) is being loaded\n * @event MediaPlayerEvents#STREAM_INITIALIZING\n */\n this.STREAM_INITIALIZING = 'streamInitializing';\n\n /**\n * Triggered when a stream (period) is loaded\n * @event MediaPlayerEvents#STREAM_INITIALIZED\n */\n this.STREAM_INITIALIZED = 'streamInitialized';\n\n /**\n * Triggered when the player has been reset.\n * @event MediaPlayerEvents#STREAM_TEARDOWN_COMPLETE\n */\n this.STREAM_TEARDOWN_COMPLETE = 'streamTeardownComplete';\n\n /**\n * Triggered once all text tracks detected in the MPD are added to the video element.\n * @event MediaPlayerEvents#TEXT_TRACKS_ADDED\n */\n this.TEXT_TRACKS_ADDED = 'allTextTracksAdded';\n\n /**\n * Triggered when a text track is added to the video element's TextTrackList\n * @event MediaPlayerEvents#TEXT_TRACK_ADDED\n */\n this.TEXT_TRACK_ADDED = 'textTrackAdded';\n\n /**\n * Triggered when a ttml chunk is parsed.\n * @event MediaPlayerEvents#TTML_PARSED\n */\n this.TTML_PARSED = 'ttmlParsed';\n\n /**\n * Triggered when a ttml chunk has to be parsed.\n * @event MediaPlayerEvents#TTML_TO_PARSE\n */\n this.TTML_TO_PARSE = 'ttmlToParse';\n\n /**\n * Triggered when a caption is rendered.\n * @event MediaPlayerEvents#CAPTION_RENDERED\n */\n this.CAPTION_RENDERED = 'captionRendered';\n\n /**\n * Triggered when the caption container is resized.\n * @event MediaPlayerEvents#CAPTION_CONTAINER_RESIZE\n */\n this.CAPTION_CONTAINER_RESIZE = 'captionContainerResize';\n\n /**\n * Sent when enough data is available that the media can be played,\n * at least for a couple of frames. This corresponds to the\n * HAVE_ENOUGH_DATA readyState.\n * @event MediaPlayerEvents#CAN_PLAY\n */\n this.CAN_PLAY = 'canPlay';\n\n /**\n * Sent when playback completes.\n * @event MediaPlayerEvents#PLAYBACK_ENDED\n */\n this.PLAYBACK_ENDED = 'playbackEnded';\n\n /**\n * Sent when an error occurs. The element's error\n * attribute contains more information.\n * @event MediaPlayerEvents#PLAYBACK_ERROR\n */\n this.PLAYBACK_ERROR = 'playbackError';\n\n /**\n * Sent when playback is not allowed (for example if user gesture is needed).\n * @event MediaPlayerEvents#PLAYBACK_NOT_ALLOWED\n */\n this.PLAYBACK_NOT_ALLOWED = 'playbackNotAllowed';\n\n /**\n * The media's metadata has finished loading; all attributes now\n * contain as much useful information as they're going to.\n * @event MediaPlayerEvents#PLAYBACK_METADATA_LOADED\n */\n this.PLAYBACK_METADATA_LOADED = 'playbackMetaDataLoaded';\n\n /**\n * Sent when playback is paused.\n * @event MediaPlayerEvents#PLAYBACK_PAUSED\n */\n this.PLAYBACK_PAUSED = 'playbackPaused';\n\n /**\n * Sent when the media begins to play (either for the first time, after having been paused,\n * or after ending and then restarting).\n *\n * @event MediaPlayerEvents#PLAYBACK_PLAYING\n */\n this.PLAYBACK_PLAYING = 'playbackPlaying';\n\n /**\n * Sent periodically to inform interested parties of progress downloading\n * the media. Information about the current amount of the media that has\n * been downloaded is available in the media element's buffered attribute.\n * @event MediaPlayerEvents#PLAYBACK_PROGRESS\n */\n this.PLAYBACK_PROGRESS = 'playbackProgress';\n\n /**\n * Sent when the playback speed changes.\n * @event MediaPlayerEvents#PLAYBACK_RATE_CHANGED\n */\n this.PLAYBACK_RATE_CHANGED = 'playbackRateChanged';\n\n /**\n * Sent when a seek operation completes.\n * @event MediaPlayerEvents#PLAYBACK_SEEKED\n */\n this.PLAYBACK_SEEKED = 'playbackSeeked';\n\n /**\n * Sent when a seek operation begins.\n * @event MediaPlayerEvents#PLAYBACK_SEEKING\n */\n this.PLAYBACK_SEEKING = 'playbackSeeking';\n\n /**\n * Sent when a seek operation has been asked.\n * @event MediaPlayerEvents#PLAYBACK_SEEK_ASKED\n */\n this.PLAYBACK_SEEK_ASKED = 'playbackSeekAsked';\n\n /**\n * Sent when the video element reports stalled\n * @event MediaPlayerEvents#PLAYBACK_STALLED\n */\n this.PLAYBACK_STALLED = 'playbackStalled';\n\n /**\n * Sent when playback of the media starts after having been paused;\n * that is, when playback is resumed after a prior pause event.\n *\n * @event MediaPlayerEvents#PLAYBACK_STARTED\n */\n this.PLAYBACK_STARTED = 'playbackStarted';\n\n /**\n * The time indicated by the element's currentTime attribute has changed.\n * @event MediaPlayerEvents#PLAYBACK_TIME_UPDATED\n */\n this.PLAYBACK_TIME_UPDATED = 'playbackTimeUpdated';\n\n /**\n * Sent when the media playback has stopped because of a temporary lack of data.\n *\n * @event MediaPlayerEvents#PLAYBACK_WAITING\n */\n this.PLAYBACK_WAITING = 'playbackWaiting';\n\n /**\n * Manifest validity changed - As a result of an MPD validity expiration event.\n * @event MediaPlayerEvents#MANIFEST_VALIDITY_CHANGED\n */\n this.MANIFEST_VALIDITY_CHANGED = 'manifestValidityChanged';\n }\n}\n\nlet mediaPlayerEvents = new MediaPlayerEvents();\nexport default mediaPlayerEvents;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * Constants declaration\n * @class\n * @ignore\n * @hideconstructor\n */\nclass Constants {\n\n init () {\n /**\n * @constant {string} STREAM Stream media type. Mainly used to report metrics relative to the full stream\n * @memberof Constants#\n * @static\n */\n this.STREAM = 'stream';\n\n /**\n * @constant {string} VIDEO Video media type\n * @memberof Constants#\n * @static\n */\n this.VIDEO = 'video';\n\n /**\n * @constant {string} AUDIO Audio media type\n * @memberof Constants#\n * @static\n */\n this.AUDIO = 'audio';\n\n /**\n * @constant {string} TEXT Text media type\n * @memberof Constants#\n * @static\n */\n this.TEXT = 'text';\n\n /**\n * @constant {string} FRAGMENTED_TEXT Fragmented text media type\n * @memberof Constants#\n * @static\n */\n this.FRAGMENTED_TEXT = 'fragmentedText';\n\n /**\n * @constant {string} EMBEDDED_TEXT Embedded text media type\n * @memberof Constants#\n * @static\n */\n this.EMBEDDED_TEXT = 'embeddedText';\n\n /**\n * @constant {string} MUXED Muxed (video/audio in the same chunk) media type\n * @memberof Constants#\n * @static\n */\n this.MUXED = 'muxed';\n\n /**\n * @constant {string} IMAGE Image media type\n * @memberof Constants#\n * @static\n */\n this.IMAGE = 'image';\n\n /**\n * @constant {string} STPP STTP Subtitles format\n * @memberof Constants#\n * @static\n */\n this.STPP = 'stpp';\n\n /**\n * @constant {string} TTML STTP Subtitles format\n * @memberof Constants#\n * @static\n */\n this.TTML = 'ttml';\n\n /**\n * @constant {string} VTT STTP Subtitles format\n * @memberof Constants#\n * @static\n */\n this.VTT = 'vtt';\n\n /**\n * @constant {string} WVTT STTP Subtitles format\n * @memberof Constants#\n * @static\n */\n this.WVTT = 'wvtt';\n\n /**\n * @constant {string} ABR_STRATEGY_DYNAMIC Dynamic Adaptive bitrate algorithm\n * @memberof Constants#\n * @static\n */\n this.ABR_STRATEGY_DYNAMIC = 'abrDynamic';\n\n /**\n * @constant {string} ABR_STRATEGY_BOLA Adaptive bitrate algorithm based on Bola (buffer level)\n * @memberof Constants#\n * @static\n */\n this.ABR_STRATEGY_BOLA = 'abrBola';\n\n /**\n * @constant {string} ABR_STRATEGY_THROUGHPUT Adaptive bitrate algorithm based on throughput\n * @memberof Constants#\n * @static\n */\n this.ABR_STRATEGY_THROUGHPUT = 'abrThroughput';\n\n /**\n * @constant {string} MOVING_AVERAGE_SLIDING_WINDOW Moving average sliding window\n * @memberof Constants#\n * @static\n */\n this.MOVING_AVERAGE_SLIDING_WINDOW = 'slidingWindow';\n\n /**\n * @constant {string} EWMA Exponential moving average\n * @memberof Constants#\n * @static\n */\n this.MOVING_AVERAGE_EWMA = 'ewma';\n\n /**\n * @constant {string} BAD_ARGUMENT_ERROR Invalid Arguments type of error\n * @memberof Constants#\n * @static\n */\n this.BAD_ARGUMENT_ERROR = 'Invalid Arguments';\n\n /**\n * @constant {string} MISSING_CONFIG_ERROR Missing ocnfiguration parameters type of error\n * @memberof Constants#\n * @static\n */\n this.MISSING_CONFIG_ERROR = 'Missing config parameter(s)';\n this.LOCATION = 'Location';\n this.INITIALIZE = 'initialize';\n this.TEXT_SHOWING = 'showing';\n this.TEXT_HIDDEN = 'hidden';\n this.CC1 = 'CC1';\n this.CC3 = 'CC3';\n this.UTF8 = 'utf-8';\n this.SCHEME_ID_URI = 'schemeIdUri';\n this.START_TIME = 'starttime';\n this.SERVICE_DESCRIPTION_LL_SCHEME = 'urn:dvb:dash:lowlatency:scope:2019';\n this.SUPPLEMENTAL_PROPERTY_LL_SCHEME = 'urn:dvb:dash:lowlatency:critical:2019';\n this.XML = 'XML';\n this.ARRAY_BUFFER = 'ArrayBuffer';\n }\n\n constructor () {\n this.init();\n }\n}\n\nconst constants = new Constants();\nexport default constants;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport EventBus from '../../core/EventBus';\nimport MediaPlayerEvents from '../MediaPlayerEvents';\nimport FactoryMaker from '../../core/FactoryMaker';\nimport Debug from '../../core/Debug';\nimport Settings from '../../core/Settings';\nimport {HTTPRequest} from '../vo/metrics/HTTPRequest';\nimport DashManifestModel from '../../dash/models/DashManifestModel';\nimport Utils from '../../core/Utils';\nimport {getVersionString} from '../../core/Version';\n\nconst CMCD_REQUEST_FIELD_NAME = 'Common-Media-Client-Data';\nconst CMCD_VERSION = 1;\nconst DEFAULT_DEVICE_ID = `dash.js-v${getVersionString()}`;\nconst BUFFER_STATES = {\n DEFAULT: null,\n INITIALIZING: 1,\n SEEKING: 2,\n RISK: 3,\n EMPTY: 4\n};\nconst OBJECT_TYPES = {\n MANIFEST: 'm',\n AUDIO: 'a',\n VIDEO: 'v',\n INIT: 'i',\n CAPTION: 'c'\n};\nconst STREAMING_FORMATS = {\n DASH: 'd',\n MSS: 's'\n};\nconst STREAM_TYPES = {\n VOD: 'v',\n LIVE: 'l'\n};\n\nfunction CmcdModel() {\n\n let logger,\n dashManifestModel,\n instance,\n internalData,\n abrController,\n dashMetrics,\n playbackController;\n\n let context = this.context;\n let eventBus = EventBus(context).getInstance();\n let settings = Settings(context).getInstance();\n\n function setup() {\n logger = Debug(context).getInstance().getLogger(instance);\n dashManifestModel = DashManifestModel(context).getInstance();\n\n _resetInitialSettings();\n }\n\n function initialize() {\n eventBus.on(MediaPlayerEvents.PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);\n eventBus.on(MediaPlayerEvents.MANIFEST_LOADED, _onManifestLoaded, instance);\n eventBus.on(MediaPlayerEvents.BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);\n }\n\n function setConfig(config) {\n if (!config) return;\n\n if (config.abrController) {\n abrController = config.abrController;\n }\n\n if (config.dashMetrics) {\n dashMetrics = config.dashMetrics;\n }\n\n if (config.playbackController) {\n playbackController = config.playbackController;\n }\n }\n\n function _resetInitialSettings() {\n internalData = {\n pr: 1,\n nor: null,\n st: null,\n sf: null,\n sid: `${Utils.generateUuid()}`,\n bs: {\n audio: BUFFER_STATES.INITIALIZING,\n video: BUFFER_STATES.INITIALIZING\n },\n cid: null,\n did: `${DEFAULT_DEVICE_ID}`\n\n };\n }\n\n function getQueryParameter(request) {\n try {\n if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {\n const cmcdData = _getCmcdData(request);\n const finalPayloadString = _buildFinalString(cmcdData);\n\n return {\n key: CMCD_REQUEST_FIELD_NAME,\n value: finalPayloadString\n };\n }\n\n return null;\n } catch (e) {\n return null;\n }\n }\n\n function _getCmcdData(request) {\n try {\n let cmcdData = null;\n\n if (request.type === HTTPRequest.MPD_TYPE) {\n _setDefaultContentId(request);\n return _getCmcdDataForMpd(request);\n } else if (request.type === HTTPRequest.MEDIA_SEGMENT_TYPE) {\n return _getCmcdDataForMediaSegment(request);\n } else if (request.type === HTTPRequest.INIT_SEGMENT_TYPE) {\n return _getCmcdDataForInitSegment(request);\n }\n\n return cmcdData;\n } catch (e) {\n return null;\n }\n }\n\n function _setDefaultContentId(request) {\n try {\n internalData.cid = `${Utils.generateHashCode(request.url)}`;\n } catch (e) {\n\n }\n }\n\n function _getCmcdDataForMpd() {\n const data = _getGenericCmcdData();\n\n data.ot = `${OBJECT_TYPES.MANIFEST}`;\n\n return data;\n }\n\n function _getCmcdDataForMediaSegment(request) {\n const data = _getGenericCmcdData();\n const encodedBitrate = _getBitrateByRequest(request);\n const d = _getObjectDurationByRequest(request);\n const ot = request.mediaType === 'video' ? `${OBJECT_TYPES.VIDEO}` : request.mediaType === 'audio' ? `${OBJECT_TYPES.AUDIO}` : request.mediaType === 'fragmentedText' ? `${OBJECT_TYPES.CAPTION}` : null;\n const mtp = _getMeasuredThroughputByType(request.mediaType);\n const dl = _getDeadlineByType(request.mediaType);\n const bs = _getBufferStateByRequest(request);\n\n if (encodedBitrate) {\n data.br = encodedBitrate;\n }\n\n if (ot) {\n data.ot = ot;\n }\n\n if (!isNaN(d)) {\n data.d = d;\n }\n\n if (!isNaN(mtp)) {\n data.mtp = mtp;\n }\n\n if (!isNaN(dl)) {\n data.dl = dl;\n }\n\n if (!isNaN(bs) && bs !== null) {\n data.bs = bs;\n }\n\n return data;\n }\n\n function _getCmcdDataForInitSegment() {\n const data = _getGenericCmcdData();\n\n data.ot = `${OBJECT_TYPES.INIT}`;\n\n return data;\n }\n\n function _getGenericCmcdData() {\n const data = {};\n\n data.v = CMCD_VERSION;\n data.sid = settings.get().streaming.cmcd.sid ? settings.get().streaming.cmcd.sid : internalData.sid;\n data.cid = settings.get().streaming.cmcd.cid ? settings.get().streaming.cmcd.cid : internalData.cid;\n data.did = settings.get().streaming.cmcd.did ? settings.get().streaming.cmcd.did : internalData.did;\n\n data.sid = `\"${data.sid}\"`;\n data.cid = `\"${data.cid}\"`;\n data.did = `\"${data.did}\"`;\n\n if (!isNaN(internalData.pr) && internalData.pr !== 1 && internalData.pr !== null) {\n data.pr = internalData.pr;\n }\n\n if (internalData.st) {\n data.st = internalData.st;\n }\n\n if (internalData.sf) {\n data.sf = internalData.sf;\n }\n\n return data;\n }\n\n function _getBitrateByRequest(request) {\n try {\n const quality = request.quality;\n const bitrateList = request.mediaInfo.bitrateList;\n\n return parseInt(bitrateList[quality].bandwidth / 1000);\n } catch (e) {\n return null;\n }\n }\n\n function _getObjectDurationByRequest(request) {\n try {\n return !isNaN(request.duration) ? Math.round(request.duration * 1000) : null;\n } catch (e) {\n return null;\n }\n }\n\n function _getMeasuredThroughputByType(mediaType) {\n try {\n return Math.round(abrController.getThroughputHistory().getSafeAverageThroughput(mediaType));\n } catch (e) {\n return null;\n }\n }\n\n function _getDeadlineByType(mediaType) {\n try {\n const playbackRate = internalData.pr;\n const bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);\n\n if (!isNaN(playbackRate) && !isNaN(bufferLevel)) {\n return parseInt((bufferLevel / playbackRate) * 1000);\n }\n\n return null;\n } catch (e) {\n return null;\n }\n }\n\n function _getBufferStateByRequest(request) {\n try {\n const mediaType = request.mediaType;\n if (internalData.bs[mediaType] !== null) {\n return internalData.bs[mediaType];\n }\n\n const bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);\n const duration = request.duration;\n if (bufferLevel < duration) {\n return BUFFER_STATES.RISK;\n }\n\n return BUFFER_STATES.DEFAULT;\n } catch (e) {\n\n }\n }\n\n function _onPlaybackRateChanged(data) {\n try {\n internalData.pr = data.playbackRate;\n } catch (e) {\n\n }\n }\n\n function _onManifestLoaded(data) {\n try {\n const isDynamic = dashManifestModel.getIsDynamic(data.data);\n const st = isDynamic ? `${STREAM_TYPES.LIVE}` : `${STREAM_TYPES.VOD}`;\n const sf = data.protocol && data.protocol === 'MSS' ? `${STREAMING_FORMATS.MSS}` : `${STREAMING_FORMATS.DASH}`;\n\n internalData.st = `${st}`;\n internalData.sf = `${sf}`;\n } catch (e) {\n }\n }\n\n function _onBufferLevelStateChanged(data) {\n try {\n if (data.state && data.mediaType) {\n let state = null;\n switch (data.state) {\n case MediaPlayerEvents.BUFFER_LOADED:\n state = BUFFER_STATES.DEFAULT;\n break;\n case MediaPlayerEvents.BUFFER_EMPTY:\n if (playbackController.isSeeking()) {\n state = BUFFER_STATES.SEEKING;\n }\n state = BUFFER_STATES.EMPTY;\n break;\n default:\n }\n internalData.bs[data.mediaType] = state;\n\n }\n } catch (e) {\n\n }\n }\n\n function _buildFinalString(cmcdData) {\n try {\n if (!cmcdData) {\n return null;\n }\n const keys = Object.keys(cmcdData);\n const length = keys.length;\n\n return keys.reduce((acc, key, index) => {\n acc += `${key}=${cmcdData[key]}`;\n if (index < length - 1) {\n acc += ',';\n }\n\n return acc;\n }, '');\n\n } catch (e) {\n return null;\n }\n }\n\n function reset() {\n eventBus.off(MediaPlayerEvents.PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, this);\n eventBus.off(MediaPlayerEvents.MANIFEST_LOADED, _onManifestLoaded, this);\n eventBus.off(MediaPlayerEvents.BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);\n\n _resetInitialSettings();\n }\n\n instance = {\n getQueryParameter,\n setConfig,\n reset,\n initialize\n };\n\n setup();\n\n return instance;\n}\n\nCmcdModel.__dashjs_factory_name = 'CmcdModel';\nexport default FactoryMaker.getSingletonFactory(CmcdModel);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport FragmentRequest from '../vo/FragmentRequest';\n\nconst FRAGMENT_MODEL_LOADING = 'loading';\nconst FRAGMENT_MODEL_EXECUTED = 'executed';\nconst FRAGMENT_MODEL_CANCELED = 'canceled';\nconst FRAGMENT_MODEL_FAILED = 'failed';\n\nfunction FragmentModel(config) {\n\n config = config || {};\n const eventBus = config.eventBus;\n const events = config.events;\n const dashMetrics = config.dashMetrics;\n const fragmentLoader = config.fragmentLoader;\n const debug = config.debug;\n const streamId = config.streamId;\n\n let instance,\n logger,\n executedRequests,\n loadingRequests;\n\n function setup() {\n logger = debug.getLogger(instance);\n resetInitialSettings();\n eventBus.on(events.LOADING_COMPLETED, onLoadingCompleted, instance);\n eventBus.on(events.LOADING_DATA_PROGRESS, onLoadingInProgress, instance);\n eventBus.on(events.LOADING_ABANDONED, onLoadingAborted, instance);\n }\n\n function isFragmentLoaded(request) {\n const isEqualComplete = function (req1, req2) {\n return ((req1.action === FragmentRequest.ACTION_COMPLETE) && (req1.action === req2.action));\n };\n\n const isEqualMedia = function (req1, req2) {\n return !isNaN(req1.index) && (req1.startTime === req2.startTime) && (req1.adaptationIndex === req2.adaptationIndex) && (req1.type === req2.type);\n };\n\n const isEqualInit = function (req1, req2) {\n return isNaN(req1.index) && isNaN(req2.index) && (req1.quality === req2.quality);\n };\n\n const check = function (requests) {\n let isLoaded = false;\n\n requests.some(req => {\n if (isEqualMedia(request, req) || isEqualInit(request, req) || isEqualComplete(request, req)) {\n isLoaded = true;\n return isLoaded;\n }\n });\n return isLoaded;\n };\n\n if (!request) {\n return false;\n }\n\n return check(executedRequests);\n }\n\n function isFragmentLoadedOrPending(request) {\n let isLoaded = false;\n let i = 0;\n let req;\n\n // First, check if the fragment has already been loaded\n isLoaded = isFragmentLoaded(request);\n\n // Then, check if the fragment is about to be loeaded\n if (!isLoaded) {\n for (i = 0; i < loadingRequests.length; i++) {\n req = loadingRequests[i];\n if ((request.url === req.url) && (request.startTime === req.startTime)) {\n isLoaded = true;\n }\n }\n }\n\n return isLoaded;\n }\n\n /**\n *\n * Gets an array of {@link FragmentRequest} objects\n *\n * @param {Object} filter The object with properties by which the method filters the requests to be returned.\n * the only mandatory property is state, which must be a value from\n * other properties should match the properties of {@link FragmentRequest}. E.g.:\n * getRequests({state: FragmentModel.FRAGMENT_MODEL_EXECUTED, quality: 0}) - returns\n * all the requests from executedRequests array where requests.quality = filter.quality\n *\n * @returns {Array}\n * @memberof FragmentModel#\n */\n function getRequests(filter) {\n const states = filter ? filter.state instanceof Array ? filter.state : [filter.state] : [];\n\n let filteredRequests = [];\n states.forEach(state => {\n const requests = getRequestsForState(state);\n filteredRequests = filteredRequests.concat(filterRequests(requests, filter));\n });\n\n return filteredRequests;\n }\n\n function getRequestThreshold(req) {\n return isNaN(req.duration) ? 0.25 : Math.min(req.duration / 8, 0.5);\n }\n\n function removeExecutedRequestsBeforeTime(time) {\n executedRequests = executedRequests.filter(req => {\n const threshold = getRequestThreshold(req);\n return isNaN(req.startTime) || (time !== undefined ? req.startTime >= time - threshold : false);\n });\n }\n\n function removeExecutedRequestsAfterTime(time) {\n executedRequests = executedRequests.filter(req => {\n return isNaN(req.startTime) || (time !== undefined ? req.startTime < time : false);\n });\n }\n\n function removeExecutedRequestsInTimeRange(start, end) {\n if (end <= start + 0.5) {\n return;\n }\n\n executedRequests = executedRequests.filter(req => {\n const threshold = getRequestThreshold(req);\n return (isNaN(req.startTime) || req.startTime >= (end - threshold)) ||\n (isNaN(req.duration) || (req.startTime + req.duration) <= (start + threshold));\n });\n }\n\n // Remove requests that are not \"represented\" by any of buffered ranges\n function syncExecutedRequestsWithBufferedRange(bufferedRanges, streamDuration) {\n if (!bufferedRanges || bufferedRanges.length === 0) {\n removeExecutedRequestsBeforeTime();\n return;\n }\n\n let start = 0;\n for (let i = 0, ln = bufferedRanges.length; i < ln; i++) {\n removeExecutedRequestsInTimeRange(start, bufferedRanges.start(i));\n start = bufferedRanges.end(i);\n }\n if (streamDuration > 0) {\n removeExecutedRequestsInTimeRange(start, streamDuration);\n }\n }\n\n function abortRequests() {\n fragmentLoader.abort();\n loadingRequests = [];\n }\n\n function executeRequest(request) {\n switch (request.action) {\n case FragmentRequest.ACTION_COMPLETE:\n executedRequests.push(request);\n addSchedulingInfoMetrics(request, FRAGMENT_MODEL_EXECUTED);\n logger.debug('STREAM_COMPLETED');\n eventBus.trigger(events.STREAM_COMPLETED, {\n request: request\n });\n break;\n case FragmentRequest.ACTION_DOWNLOAD:\n addSchedulingInfoMetrics(request, FRAGMENT_MODEL_LOADING);\n loadingRequests.push(request);\n loadCurrentFragment(request);\n break;\n default:\n logger.warn('Unknown request action.');\n }\n }\n\n function loadCurrentFragment(request) {\n eventBus.trigger(events.FRAGMENT_LOADING_STARTED, {\n streamId: streamId,\n request: request\n });\n fragmentLoader.load(request);\n }\n\n function getRequestForTime(arr, time, threshold) {\n // loop through the executed requests and pick the one for which the playback interval matches the given time\n const lastIdx = arr.length - 1;\n for (let i = lastIdx; i >= 0; i--) {\n const req = arr[i];\n const start = req.startTime;\n const end = start + req.duration;\n threshold = !isNaN(threshold) ? threshold : getRequestThreshold(req);\n if ((!isNaN(start) && !isNaN(end) && ((time + threshold) >= start) && ((time - threshold) < end)) || (isNaN(start) && isNaN(time))) {\n return req;\n }\n }\n return null;\n }\n\n function filterRequests(arr, filter) {\n // for time use a specific filtration function\n if (filter.hasOwnProperty('time')) {\n return [getRequestForTime(arr, filter.time, filter.threshold)];\n }\n\n return arr.filter(request => {\n for (const prop in filter) {\n if (prop === 'state') continue;\n if (filter.hasOwnProperty(prop) && request[prop] != filter[prop]) return false;\n }\n\n return true;\n });\n }\n\n function getRequestsForState(state) {\n let requests;\n switch (state) {\n case FRAGMENT_MODEL_LOADING:\n requests = loadingRequests;\n break;\n case FRAGMENT_MODEL_EXECUTED:\n requests = executedRequests;\n break;\n default:\n requests = [];\n }\n return requests;\n }\n\n function addSchedulingInfoMetrics(request, state) {\n dashMetrics.addSchedulingInfo(request, state);\n dashMetrics.addRequestsQueue(request.mediaType, loadingRequests, executedRequests);\n }\n\n function onLoadingCompleted(e) {\n if (e.sender !== fragmentLoader) return;\n\n loadingRequests.splice(loadingRequests.indexOf(e.request), 1);\n\n if (e.response && !e.error) {\n executedRequests.push(e.request);\n }\n\n addSchedulingInfoMetrics(e.request, e.error ? FRAGMENT_MODEL_FAILED : FRAGMENT_MODEL_EXECUTED);\n\n eventBus.trigger(events.FRAGMENT_LOADING_COMPLETED, {\n request: e.request,\n response: e.response,\n error: e.error,\n sender: this\n });\n }\n\n function onLoadingInProgress(e) {\n if (e.sender !== fragmentLoader) return;\n\n eventBus.trigger(events.FRAGMENT_LOADING_PROGRESS, {\n request: e.request,\n response: e.response,\n error: e.error,\n sender: this\n });\n }\n\n function onLoadingAborted(e) {\n if (e.sender !== fragmentLoader) return;\n\n eventBus.trigger(events.FRAGMENT_LOADING_ABANDONED, { streamId: streamId, request: e.request, mediaType: e.mediaType });\n }\n\n function resetInitialSettings() {\n executedRequests = [];\n loadingRequests = [];\n }\n\n function reset() {\n eventBus.off(events.LOADING_COMPLETED, onLoadingCompleted, this);\n eventBus.off(events.LOADING_DATA_PROGRESS, onLoadingInProgress, this);\n eventBus.off(events.LOADING_ABANDONED, onLoadingAborted, this);\n\n if (fragmentLoader) {\n fragmentLoader.reset();\n }\n resetInitialSettings();\n }\n\n function addExecutedRequest(request) {\n executedRequests.push(request);\n }\n\n instance = {\n getRequests: getRequests,\n isFragmentLoaded: isFragmentLoaded,\n isFragmentLoadedOrPending: isFragmentLoadedOrPending,\n removeExecutedRequestsBeforeTime: removeExecutedRequestsBeforeTime,\n removeExecutedRequestsAfterTime: removeExecutedRequestsAfterTime,\n syncExecutedRequestsWithBufferedRange: syncExecutedRequestsWithBufferedRange,\n abortRequests: abortRequests,\n executeRequest: executeRequest,\n reset: reset,\n addExecutedRequest: addExecutedRequest\n };\n\n setup();\n return instance;\n}\n\nFragmentModel.__dashjs_factory_name = 'FragmentModel';\nconst factory = FactoryMaker.getClassFactory(FragmentModel);\nfactory.FRAGMENT_MODEL_LOADING = FRAGMENT_MODEL_LOADING;\nfactory.FRAGMENT_MODEL_EXECUTED = FRAGMENT_MODEL_EXECUTED;\nfactory.FRAGMENT_MODEL_CANCELED = FRAGMENT_MODEL_CANCELED;\nfactory.FRAGMENT_MODEL_FAILED = FRAGMENT_MODEL_FAILED;\nFactoryMaker.updateClassFactory(FragmentModel.__dashjs_factory_name, factory);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\n\n/**\n * @module FetchLoader\n * @ignore\n * @description Manages download of resources via HTTP using fetch.\n * @param {Object} cfg - dependencies from parent\n */\nfunction FetchLoader(cfg) {\n\n cfg = cfg || {};\n const requestModifier = cfg.requestModifier;\n const boxParser = cfg.boxParser;\n\n let instance;\n\n function load(httpRequest) {\n\n // Variables will be used in the callback functions\n const requestStartTime = new Date();\n const request = httpRequest.request;\n\n const headers = new Headers(); /*jshint ignore:line*/\n if (request.range) {\n headers.append('Range', 'bytes=' + request.range);\n }\n\n if (!request.requestStartDate) {\n request.requestStartDate = requestStartTime;\n }\n\n if (requestModifier) {\n // modifyRequestHeader expects a XMLHttpRequest object so,\n // to keep backward compatibility, we should expose a setRequestHeader method\n // TODO: Remove RequestModifier dependency on XMLHttpRequest object and define\n // a more generic way to intercept/modify requests\n requestModifier.modifyRequestHeader({\n setRequestHeader: function (header, value) {\n headers.append(header, value);\n }\n });\n }\n\n let abortController;\n if (typeof window.AbortController === 'function') {\n abortController = new AbortController(); /*jshint ignore:line*/\n httpRequest.abortController = abortController;\n abortController.signal.onabort = httpRequest.onabort;\n }\n\n const reqOptions = {\n method: httpRequest.method,\n headers: headers,\n credentials: httpRequest.withCredentials ? 'include' : undefined,\n signal: abortController ? abortController.signal : undefined\n };\n\n fetch(httpRequest.url, reqOptions).then(function (response) {\n if (!httpRequest.response) {\n httpRequest.response = {};\n }\n httpRequest.response.status = response.status;\n httpRequest.response.statusText = response.statusText;\n httpRequest.response.responseURL = response.url;\n\n if (!response.ok) {\n httpRequest.onerror();\n }\n\n let responseHeaders = '';\n for (const key of response.headers.keys()) {\n responseHeaders += key + ': ' + response.headers.get(key) + '\\r\\n';\n }\n httpRequest.response.responseHeaders = responseHeaders;\n\n if (!response.body) {\n // Fetch returning a ReadableStream response body is not currently supported by all browsers.\n // Browser compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\n // If it is not supported, returning the whole segment when it's ready (as xhr)\n return response.arrayBuffer().then(function (buffer) {\n httpRequest.response.response = buffer;\n const event = {\n loaded: buffer.byteLength,\n total: buffer.byteLength,\n stream: false\n };\n httpRequest.progress(event);\n httpRequest.onload();\n httpRequest.onend();\n return;\n });\n }\n\n const totalBytes = parseInt(response.headers.get('Content-Length'), 10);\n let bytesReceived = 0;\n let signaledFirstByte = false;\n let remaining = new Uint8Array();\n let offset = 0;\n\n httpRequest.reader = response.body.getReader();\n let downLoadedData = [];\n\n const processResult = function ({value, done}) {\n if (done) {\n if (remaining) {\n // If there is pending data, call progress so network metrics\n // are correctly generated\n // Same structure as https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/onprogress\n httpRequest.progress({\n loaded: bytesReceived,\n total: isNaN(totalBytes) ? bytesReceived : totalBytes,\n lengthComputable: true,\n time: calculateDownloadedTime(downLoadedData, bytesReceived),\n stream: true\n });\n\n httpRequest.response.response = remaining.buffer;\n }\n httpRequest.onload();\n httpRequest.onend();\n return;\n }\n\n if (value && value.length > 0) {\n remaining = concatTypedArray(remaining, value);\n bytesReceived += value.length;\n downLoadedData.push({\n ts: Date.now(),\n bytes: value.length\n });\n\n const boxesInfo = boxParser.findLastTopIsoBoxCompleted(['moov', 'mdat'], remaining, offset);\n if (boxesInfo.found) {\n const end = boxesInfo.lastCompletedOffset + boxesInfo.size;\n\n // If we are going to pass full buffer, avoid copying it and pass\n // complete buffer. Otherwise clone the part of the buffer that is completed\n // and adjust remaining buffer. A clone is needed because ArrayBuffer of a typed-array\n // keeps a reference to the original data\n let data;\n if (end === remaining.length) {\n data = remaining;\n remaining = new Uint8Array();\n } else {\n data = new Uint8Array(remaining.subarray(0, end));\n remaining = remaining.subarray(end);\n }\n\n // Announce progress but don't track traces. Throughput measures are quite unstable\n // when they are based in small amount of data\n httpRequest.progress({\n data: data.buffer,\n lengthComputable: false,\n noTrace: true\n });\n\n offset = 0;\n } else {\n offset = boxesInfo.lastCompletedOffset;\n\n // Call progress so it generates traces that will be later used to know when the first byte\n // were received\n if (!signaledFirstByte) {\n httpRequest.progress({\n lengthComputable: false,\n noTrace: true\n });\n signaledFirstByte = true;\n }\n }\n }\n read(httpRequest, processResult);\n };\n\n read(httpRequest, processResult);\n })\n .catch(function (e) {\n if (httpRequest.onerror) {\n httpRequest.onerror(e);\n }\n });\n }\n\n function read(httpRequest, processResult) {\n httpRequest.reader.read()\n .then(processResult)\n .catch(function (e) {\n if (httpRequest.onerror && httpRequest.response.status === 200) {\n // Error, but response code is 200, trigger error\n httpRequest.onerror(e);\n }\n });\n }\n\n function concatTypedArray(remaining, data) {\n if (remaining.length === 0) {\n return data;\n }\n const result = new Uint8Array(remaining.length + data.length);\n result.set(remaining);\n result.set(data, remaining.length);\n return result;\n }\n\n function abort(request) {\n if (request.abortController) {\n // For firefox and edge\n request.abortController.abort();\n } else if (request.reader) {\n // For Chrome\n try {\n request.reader.cancel();\n request.onabort();\n } catch (e) {\n // throw exceptions (TypeError) when reader was previously closed,\n // for example, because a network issue\n }\n }\n }\n\n function calculateDownloadedTime(datum, bytesReceived) {\n datum = datum.filter(data => data.bytes > ((bytesReceived / 4) / datum.length));\n if (datum.length > 1) {\n let time = 0;\n const avgTimeDistance = (datum[datum.length - 1].ts - datum[0].ts) / datum.length;\n datum.forEach((data, index) => {\n // To be counted the data has to be over a threshold\n const next = datum[index + 1];\n if (next) {\n const distance = next.ts - data.ts;\n time += distance < avgTimeDistance ? distance : 0;\n }\n });\n return time;\n }\n return null;\n }\n\n instance = {\n load: load,\n abort: abort,\n calculateDownloadedTime: calculateDownloadedTime\n };\n\n return instance;\n}\n\nFetchLoader.__dashjs_factory_name = 'FetchLoader';\n\nconst factory = FactoryMaker.getClassFactory(FetchLoader);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport XHRLoader from './XHRLoader';\nimport FetchLoader from './FetchLoader';\nimport {HTTPRequest} from '../vo/metrics/HTTPRequest';\nimport FactoryMaker from '../../core/FactoryMaker';\nimport DashJSError from '../vo/DashJSError';\nimport CmcdModel from '../models/CmcdModel';\nimport Utils from '../../core/Utils';\n\n/**\n * @module HTTPLoader\n * @ignore\n * @description Manages download of resources via HTTP.\n * @param {Object} cfg - dependancies from parent\n */\nfunction HTTPLoader(cfg) {\n\n cfg = cfg || {};\n\n const context = this.context;\n const errHandler = cfg.errHandler;\n const dashMetrics = cfg.dashMetrics;\n const mediaPlayerModel = cfg.mediaPlayerModel;\n const requestModifier = cfg.requestModifier;\n const boxParser = cfg.boxParser;\n const useFetch = cfg.useFetch || false;\n const errors = cfg.errors;\n\n let instance,\n requests,\n delayedRequests,\n retryRequests,\n downloadErrorToRequestTypeMap,\n cmcdModel;\n\n function setup() {\n requests = [];\n delayedRequests = [];\n retryRequests = [];\n cmcdModel = CmcdModel(context).getInstance();\n\n downloadErrorToRequestTypeMap = {\n [HTTPRequest.MPD_TYPE]: errors.DOWNLOAD_ERROR_ID_MANIFEST_CODE,\n [HTTPRequest.XLINK_EXPANSION_TYPE]: errors.DOWNLOAD_ERROR_ID_XLINK_CODE,\n [HTTPRequest.INIT_SEGMENT_TYPE]: errors.DOWNLOAD_ERROR_ID_INITIALIZATION_CODE,\n [HTTPRequest.MEDIA_SEGMENT_TYPE]: errors.DOWNLOAD_ERROR_ID_CONTENT_CODE,\n [HTTPRequest.INDEX_SEGMENT_TYPE]: errors.DOWNLOAD_ERROR_ID_CONTENT_CODE,\n [HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE]: errors.DOWNLOAD_ERROR_ID_CONTENT_CODE,\n [HTTPRequest.OTHER_TYPE]: errors.DOWNLOAD_ERROR_ID_CONTENT_CODE\n };\n }\n\n function internalLoad(config, remainingAttempts) {\n const request = config.request;\n const traces = [];\n let firstProgress = true;\n let needFailureReport = true;\n let requestStartTime = new Date();\n let lastTraceTime = requestStartTime;\n let lastTraceReceivedCount = 0;\n let httpRequest;\n\n if (!requestModifier || !dashMetrics || !errHandler) {\n throw new Error('config object is not correct or missing');\n }\n\n const handleLoaded = function (success) {\n needFailureReport = false;\n\n request.requestStartDate = requestStartTime;\n request.requestEndDate = new Date();\n request.firstByteDate = request.firstByteDate || requestStartTime;\n\n if (!request.checkExistenceOnly) {\n dashMetrics.addHttpRequest(request, httpRequest.response ? httpRequest.response.responseURL : null,\n httpRequest.response ? httpRequest.response.status : null,\n httpRequest.response && httpRequest.response.getAllResponseHeaders ? httpRequest.response.getAllResponseHeaders() :\n httpRequest.response ? httpRequest.response.responseHeaders : [],\n success ? traces : null);\n\n if (request.type === HTTPRequest.MPD_TYPE) {\n dashMetrics.addManifestUpdate(request.type, request.requestStartDate, request.requestEndDate);\n }\n }\n };\n\n const onloadend = function () {\n if (requests.indexOf(httpRequest) === -1) {\n return;\n } else {\n requests.splice(requests.indexOf(httpRequest), 1);\n }\n\n if (needFailureReport) {\n handleLoaded(false);\n\n if (remainingAttempts > 0) {\n remainingAttempts--;\n let retryRequest = {config: config};\n retryRequests.push(retryRequest);\n retryRequest.timeout = setTimeout(function () {\n if (retryRequests.indexOf(retryRequest) === -1) {\n return;\n } else {\n retryRequests.splice(retryRequests.indexOf(retryRequest), 1);\n }\n internalLoad(config, remainingAttempts);\n }, mediaPlayerModel.getRetryIntervalsForType(request.type));\n } else {\n errHandler.error(new DashJSError(downloadErrorToRequestTypeMap[request.type], request.url + ' is not available', {\n request: request,\n response: httpRequest.response\n }));\n\n if (config.error) {\n config.error(request, 'error', httpRequest.response.statusText);\n }\n\n if (config.complete) {\n config.complete(request, httpRequest.response.statusText);\n }\n }\n }\n };\n\n const progress = function (event) {\n const currentTime = new Date();\n\n if (firstProgress) {\n firstProgress = false;\n if (!event.lengthComputable ||\n (event.lengthComputable && event.total !== event.loaded)) {\n request.firstByteDate = currentTime;\n }\n }\n\n if (event.lengthComputable) {\n request.bytesLoaded = event.loaded;\n request.bytesTotal = event.total;\n }\n\n if (!event.noTrace) {\n traces.push({\n s: lastTraceTime,\n d: event.time ? event.time : currentTime.getTime() - lastTraceTime.getTime(),\n b: [event.loaded ? event.loaded - lastTraceReceivedCount : 0]\n });\n\n lastTraceTime = currentTime;\n lastTraceReceivedCount = event.loaded;\n }\n\n if (config.progress && event) {\n config.progress(event);\n }\n };\n\n const onload = function () {\n if (httpRequest.response.status >= 200 && httpRequest.response.status <= 299) {\n handleLoaded(true);\n\n if (config.success) {\n config.success(httpRequest.response.response, httpRequest.response.statusText, httpRequest.response.responseURL);\n }\n\n if (config.complete) {\n config.complete(request, httpRequest.response.statusText);\n }\n }\n };\n\n const onabort = function () {\n if (config.abort) {\n config.abort(request);\n }\n };\n\n let loader;\n if (useFetch && window.fetch && request.responseType === 'arraybuffer' && request.type === HTTPRequest.MEDIA_SEGMENT_TYPE) {\n loader = FetchLoader(context).create({\n requestModifier: requestModifier,\n boxParser: boxParser\n });\n } else {\n loader = XHRLoader(context).create({\n requestModifier: requestModifier\n });\n }\n\n let modifiedUrl = requestModifier.modifyRequestURL(request.url);\n const additionalQueryParameter = _getAdditionalQueryParameter(request);\n modifiedUrl = Utils.addAditionalQueryParameterToUrl(modifiedUrl, additionalQueryParameter);\n const verb = request.checkExistenceOnly ? HTTPRequest.HEAD : HTTPRequest.GET;\n const withCredentials = mediaPlayerModel.getXHRWithCredentialsForType(request.type);\n\n\n httpRequest = {\n url: modifiedUrl,\n method: verb,\n withCredentials: withCredentials,\n request: request,\n onload: onload,\n onend: onloadend,\n onerror: onloadend,\n progress: progress,\n onabort: onabort,\n loader: loader\n };\n\n // Adds the ability to delay single fragment loading time to control buffer.\n let now = new Date().getTime();\n if (isNaN(request.delayLoadingTime) || now >= request.delayLoadingTime) {\n // no delay - just send\n requests.push(httpRequest);\n loader.load(httpRequest);\n } else {\n // delay\n let delayedRequest = {httpRequest: httpRequest};\n delayedRequests.push(delayedRequest);\n delayedRequest.delayTimeout = setTimeout(function () {\n if (delayedRequests.indexOf(delayedRequest) === -1) {\n return;\n } else {\n delayedRequests.splice(delayedRequests.indexOf(delayedRequest), 1);\n }\n try {\n requestStartTime = new Date();\n lastTraceTime = requestStartTime;\n requests.push(delayedRequest.httpRequest);\n loader.load(delayedRequest.httpRequest);\n } catch (e) {\n delayedRequest.httpRequest.onerror();\n }\n }, (request.delayLoadingTime - now));\n }\n }\n\n function _getAdditionalQueryParameter(request) {\n try {\n const additionalQueryParameter = [];\n const cmcdQueryParameter = cmcdModel.getQueryParameter(request);\n\n if (cmcdQueryParameter) {\n additionalQueryParameter.push(cmcdQueryParameter);\n }\n\n return additionalQueryParameter;\n } catch (e) {\n return [];\n }\n }\n\n /**\n * Initiates a download of the resource described by config.request\n * @param {Object} config - contains request (FragmentRequest or derived type), and callbacks\n * @memberof module:HTTPLoader\n * @instance\n */\n function load(config) {\n if (config.request) {\n internalLoad(\n config,\n mediaPlayerModel.getRetryAttemptsForType(\n config.request.type\n )\n );\n } else {\n if (config.error) {\n config.error(config.request, 'error');\n }\n }\n }\n\n /**\n * Aborts any inflight downloads\n * @memberof module:HTTPLoader\n * @instance\n */\n function abort() {\n retryRequests.forEach(t => {\n clearTimeout(t.timeout);\n // abort request in order to trigger LOADING_ABANDONED event\n if (t.config.request && t.config.abort) {\n t.config.abort(t.config.request);\n }\n });\n retryRequests = [];\n\n delayedRequests.forEach(x => clearTimeout(x.delayTimeout));\n delayedRequests = [];\n\n requests.forEach(x => {\n // abort will trigger onloadend which we don't want\n // when deliberately aborting inflight requests -\n // set them to undefined so they are not called\n x.onloadend = x.onerror = x.onprogress = undefined;\n x.loader.abort(x);\n });\n requests = [];\n }\n\n instance = {\n load: load,\n abort: abort\n };\n\n setup();\n\n return instance;\n}\n\nHTTPLoader.__dashjs_factory_name = 'HTTPLoader';\n\nconst factory = FactoryMaker.getClassFactory(HTTPLoader);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\nimport HTTPLoader from '../../streaming/net/HTTPLoader';\n\n/**\n * @module\n * @description Choose right url loader for scheme\n * @ignore\n */\nfunction SchemeLoaderFactory() {\n\n let instance;\n\n let schemeLoaderMap;\n\n function registerLoader(scheme, loader) {\n schemeLoaderMap[scheme] = loader;\n }\n\n function unregisterLoader(scheme) {\n if (schemeLoaderMap[scheme]) {\n delete schemeLoaderMap[scheme];\n }\n }\n\n function unregisterAllLoader() {\n schemeLoaderMap = {};\n }\n\n function getLoader(url) {\n\n // iterates through schemeLoaderMap to find a loader for the scheme\n for (var scheme in schemeLoaderMap) {\n if (schemeLoaderMap.hasOwnProperty(scheme) && url.startsWith(scheme)) {\n return schemeLoaderMap[scheme];\n }\n }\n\n return HTTPLoader;\n }\n\n function reset() {\n unregisterAllLoader();\n }\n\n function setup() {\n reset();\n }\n\n setup();\n\n instance = {\n getLoader: getLoader,\n registerLoader: registerLoader,\n unregisterLoader: unregisterLoader,\n unregisterAllLoader: unregisterAllLoader,\n reset: reset\n };\n\n return instance;\n}\n\nSchemeLoaderFactory.__dashjs_factory_name = 'SchemeLoaderFactory';\nconst factory = FactoryMaker.getSingletonFactory(SchemeLoaderFactory);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\nimport SchemeLoaderFactory from '../../streaming/net/SchemeLoaderFactory';\n\n/**\n * @class URLLoader\n * @description Call Offline Loader or Online Loader dependaing on URL\n * @param {Object} cfg - dependances\n * @ignore\n*/\nfunction URLLoader(cfg) {\n\n cfg = cfg || {};\n const context = this.context;\n\n let instance,\n schemeLoaderFactory,\n loader;\n\n schemeLoaderFactory = SchemeLoaderFactory(context).getInstance();\n\n function load(config) {\n\n let loaderFactory = schemeLoaderFactory.getLoader(config && config.request ? config.request.url : null);\n loader = loaderFactory(context).create({\n errHandler: cfg.errHandler,\n mediaPlayerModel: cfg.mediaPlayerModel,\n requestModifier: cfg.requestModifier,\n useFetch: cfg.useFetch || null,\n dashMetrics: cfg.dashMetrics,\n boxParser: cfg.boxParser ? cfg.boxParser : null,\n constants: cfg.constants ? cfg.constants : null,\n dashConstants: cfg.dashConstants ? cfg.dashConstants : null,\n urlUtils: cfg.urlUtils ? cfg.urlUtils : null,\n errors: cfg.errors\n });\n\n loader.load(config);\n }\n\n function abort() {\n if (loader) {\n loader.abort();\n }\n }\n instance = {\n load: load,\n abort: abort\n };\n\n return instance;\n\n}\nURLLoader.__dashjs_factory_name = 'URLLoader';\n\nconst factory = FactoryMaker.getClassFactory(URLLoader);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport FactoryMaker from '../../core/FactoryMaker';\n\n/**\n * @module XHRLoader\n * @ignore\n * @description Manages download of resources via HTTP.\n * @param {Object} cfg - dependencies from parent\n */\nfunction XHRLoader(cfg) {\n\n cfg = cfg || {};\n const requestModifier = cfg.requestModifier;\n\n let instance;\n\n function load(httpRequest) {\n\n // Variables will be used in the callback functions\n const requestStartTime = new Date();\n const request = httpRequest.request;\n\n let xhr = new XMLHttpRequest();\n xhr.open(httpRequest.method, httpRequest.url, true);\n\n if (request.responseType) {\n xhr.responseType = request.responseType;\n }\n\n if (request.range) {\n xhr.setRequestHeader('Range', 'bytes=' + request.range);\n }\n\n if (!request.requestStartDate) {\n request.requestStartDate = requestStartTime;\n }\n\n if (requestModifier) {\n xhr = requestModifier.modifyRequestHeader(xhr);\n }\n\n xhr.withCredentials = httpRequest.withCredentials;\n\n xhr.onload = httpRequest.onload;\n xhr.onloadend = httpRequest.onend;\n xhr.onerror = httpRequest.onerror;\n xhr.onprogress = httpRequest.progress;\n xhr.onabort = httpRequest.onabort;\n\n xhr.send();\n\n httpRequest.response = xhr;\n }\n\n function abort(request) {\n const x = request.response;\n x.onloadend = x.onerror = x.onprogress = undefined; //Ignore events from aborted requests.\n x.abort();\n }\n\n instance = {\n load: load,\n abort: abort\n };\n\n return instance;\n}\n\nXHRLoader.__dashjs_factory_name = 'XHRLoader';\n\nconst factory = FactoryMaker.getClassFactory(XHRLoader);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\nimport Constants from '../constants/Constants';\nimport DashConstants from '../../dash/constants/DashConstants';\nimport FactoryMaker from '../../core/FactoryMaker';\nimport ThumbnailTrackInfo from '../vo/ThumbnailTrackInfo';\nimport URLUtils from '../../streaming/utils/URLUtils';\nimport { replaceIDForTemplate, getTimeBasedSegment } from '../../dash/utils/SegmentsUtils';\nimport Events from '../../core/events/Events';\nimport BoxParser from '../../streaming/utils/BoxParser';\nimport XHRLoader from '../../streaming/net/XHRLoader';\nimport DashHandler from '../../dash/DashHandler';\n\nexport const THUMBNAILS_SCHEME_ID_URIS = ['http://dashif.org/thumbnail_tile',\n 'http://dashif.org/guidelines/thumbnail_tile'];\n\nfunction ThumbnailTracks(config) {\n const context = this.context;\n const adapter = config.adapter;\n const baseURLController = config.baseURLController;\n const streamInfo = config.streamInfo;\n const timelineConverter = config.timelineConverter;\n const debug = config.debug;\n const eventBus = config.eventBus;\n const events = config.events;\n const dashConstants = config.dashConstants;\n\n const urlUtils = URLUtils(context).getInstance();\n\n let instance,\n tracks,\n indexHandler,\n currentTrackIndex,\n mediaInfo,\n loader,\n boxParser;\n\n function initialize() {\n reset();\n loader = XHRLoader(context).create({});\n boxParser = BoxParser(context).getInstance();\n\n indexHandler = DashHandler(context).create({\n timelineConverter: timelineConverter,\n baseURLController: baseURLController,\n debug: debug,\n eventBus: eventBus,\n events: events,\n dashConstants: dashConstants,\n urlUtils: urlUtils\n });\n\n // initialize controllers\n indexHandler.initialize(adapter ? adapter.getIsDynamic() : false);\n\n // parse representation and create tracks\n addTracks();\n }\n\n function normalizeSegments(fragments, representation) {\n const segments = [];\n let count = 0;\n\n let i,\n len,\n s,\n seg;\n\n for (i = 0, len = fragments.length; i < len; i++) {\n s = fragments[i];\n\n seg = getTimeBasedSegment(\n timelineConverter,\n adapter.getIsDynamic(),\n representation,\n s.startTime,\n s.duration,\n s.timescale,\n s.media,\n s.mediaRange,\n count);\n\n if (seg) {\n segments.push(seg);\n seg = null;\n count++;\n }\n }\n return segments;\n }\n\n function addTracks() {\n if (!streamInfo || !adapter) {\n return;\n }\n\n // Extract thumbnail tracks\n mediaInfo = adapter.getMediaInfoForType(streamInfo, Constants.IMAGE);\n if (!mediaInfo) {\n return;\n }\n\n const voReps = adapter.getVoRepresentations(mediaInfo);\n\n if (voReps && voReps.length > 0) {\n voReps.forEach((rep) => {\n if ((rep.segmentInfoType === DashConstants.SEGMENT_TEMPLATE && rep.segmentDuration > 0 && rep.media) ||\n rep.segmentInfoType === DashConstants.SEGMENT_TIMELINE) {\n createTrack(rep);\n }\n if (rep.segmentInfoType === DashConstants.SEGMENT_BASE) {\n createTrack(rep, true);\n }\n });\n }\n\n if (tracks.length > 0) {\n // Sort bitrates and select the lowest bitrate rendition\n tracks.sort((a, b) => a.bitrate - b.bitrate);\n currentTrackIndex = tracks.length - 1;\n }\n }\n\n function createTrack(representation, useSegmentBase) {\n const track = new ThumbnailTrackInfo();\n track.id = representation.id;\n track.bitrate = representation.bandwidth;\n track.width = representation.width;\n track.height = representation.height;\n track.tilesHor = 1;\n track.tilesVert = 1;\n\n if (representation.essentialProperties) {\n representation.essentialProperties.forEach((p) => {\n if (THUMBNAILS_SCHEME_ID_URIS.indexOf(p.schemeIdUri) >= 0 && p.value) {\n const vars = p.value.split('x');\n if (vars.length === 2 && !isNaN(vars[0]) && !isNaN(vars[1])) {\n track.tilesHor = parseInt(vars[0], 10);\n track.tilesVert = parseInt(vars[1], 10);\n }\n }\n });\n }\n\n if (useSegmentBase) {\n eventBus.trigger(Events.SEGMENTBASE_SEGMENTSLIST_REQUEST_NEEDED, {\n mimeType: mediaInfo.mimeType,\n mediaType: Constants.IMAGE,\n representation: representation,\n callback: function (segments, representation) {\n let cache = [];\n segments = normalizeSegments(segments, representation);\n track.segmentDuration = segments[0].duration; //assume all segments have the same duration\n track.readThumbnail = function (time, callback) {\n\n let cached = null;\n cache.some(el => {\n if (el.start <= time && el.end > time) {\n cached = el.url;\n return true;\n }\n });\n if (cached) {\n callback(cached);\n } else {\n segments.some((ss) => {\n if (ss.mediaStartTime <= time && ss.mediaStartTime + ss.duration > time) {\n const baseURL = baseURLController.resolve(representation.path);\n loader.load({\n method: 'get',\n url: baseURL.url,\n request: {\n range: ss.mediaRange,\n responseType: 'arraybuffer'\n },\n onload: function (e) {\n let info = boxParser.getSamplesInfo(e.target.response);\n let blob = new Blob( [ e.target.response.slice(info.sampleList[0].offset, info.sampleList[0].offset + info.sampleList[0].size) ], { type: 'image/jpeg' } );\n let imageUrl = window.URL.createObjectURL( blob );\n cache.push({\n start: ss.mediaStartTime,\n end: ss.mediaStartTime + ss.duration,\n url: imageUrl\n });\n if (callback)\n callback(imageUrl);\n }\n });\n return true;\n }\n });\n }\n };\n }\n });\n } else {\n track.startNumber = representation.startNumber;\n track.segmentDuration = representation.segmentDuration;\n track.timescale = representation.timescale;\n track.templateUrl = buildTemplateUrl(representation);\n }\n\n if (track.tilesHor > 0 && track.tilesVert > 0) {\n // Precalculate width and heigth per tile for perf reasons\n track.widthPerTile = track.width / track.tilesHor;\n track.heightPerTile = track.height / track.tilesVert;\n tracks.push(track);\n }\n }\n\n function buildTemplateUrl(representation) {\n const templateUrl = urlUtils.isRelative(representation.media) ?\n urlUtils.resolve(representation.media, baseURLController.resolve(representation.path).url) : representation.media;\n\n if (!templateUrl) {\n return '';\n }\n\n return replaceIDForTemplate(templateUrl, representation.id);\n }\n\n function getTracks() {\n return tracks;\n }\n\n function getCurrentTrackIndex() {\n return currentTrackIndex;\n }\n\n function getCurrentTrack() {\n if (currentTrackIndex < 0) {\n return null;\n }\n return tracks[currentTrackIndex];\n }\n\n function setTrackByIndex(index) {\n if (!tracks || tracks.length === 0) {\n return;\n }\n // select highest bitrate in case selected index is higher than bitrate list length\n if (index >= tracks.length) {\n index = tracks.length - 1;\n }\n currentTrackIndex = index;\n }\n\n function getThumbnailRequestForTime(time) {\n let currentVoRep;\n const voReps = adapter.getVoRepresentations(mediaInfo);\n for (let i = 0; i < voReps.length; i++) {\n if (tracks[currentTrackIndex].id === voReps[i].id) {\n currentVoRep = voReps[i];\n break;\n }\n }\n\n return indexHandler.getSegmentRequestForTime(mediaInfo, currentVoRep, time);\n }\n\n function reset() {\n tracks = [];\n currentTrackIndex = -1;\n mediaInfo = null;\n }\n\n instance = {\n initialize: initialize,\n getTracks: getTracks,\n reset: reset,\n setTrackByIndex: setTrackByIndex,\n getCurrentTrack: getCurrentTrack,\n getCurrentTrackIndex: getCurrentTrackIndex,\n getThumbnailRequestForTime: getThumbnailRequestForTime\n };\n\n initialize();\n\n return instance;\n}\n\nThumbnailTracks.__dashjs_factory_name = 'ThumbnailTracks';\nexport default FactoryMaker.getClassFactory(ThumbnailTracks);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport Debug from '../../core/Debug';\nimport IsoFile from './IsoFile';\nimport FactoryMaker from '../../core/FactoryMaker';\nimport ISOBoxer from 'codem-isoboxer';\n\nimport IsoBoxSearchInfo from '../vo/IsoBoxSearchInfo';\n\nfunction BoxParser(/*config*/) {\n\n let logger,\n instance;\n let context = this.context;\n\n function setup() {\n logger = Debug(context).getInstance().getLogger(instance);\n }\n\n /**\n * @param {ArrayBuffer} data\n * @returns {IsoFile|null}\n * @memberof BoxParser#\n */\n function parse(data) {\n if (!data) return null;\n\n if (data.fileStart === undefined) {\n data.fileStart = 0;\n }\n\n let parsedFile = ISOBoxer.parseBuffer(data);\n let dashIsoFile = IsoFile(context).create();\n\n dashIsoFile.setData(parsedFile);\n\n return dashIsoFile;\n }\n\n /**\n * From the list of type boxes to look for, returns the latest one that is fully completed (header + payload). This\n * method only looks into the list of top boxes and doesn't analyze nested boxes.\n * @param {string[]} types\n * @param {ArrayBuffer|uint8Array} buffer\n * @param {number} offset\n * @returns {IsoBoxSearchInfo}\n * @memberof BoxParser#\n */\n function findLastTopIsoBoxCompleted(types, buffer, offset) {\n if (offset === undefined) {\n offset = 0;\n }\n\n // 8 = size (uint32) + type (4 characters)\n if (!buffer || offset + 8 >= buffer.byteLength) {\n return new IsoBoxSearchInfo(0, false);\n }\n\n const data = (buffer instanceof ArrayBuffer) ? new Uint8Array(buffer) : buffer;\n let boxInfo;\n let lastCompletedOffset = 0;\n while (offset < data.byteLength) {\n const boxSize = parseUint32(data, offset);\n const boxType = parseIsoBoxType(data, offset + 4);\n\n if (boxSize === 0) {\n break;\n }\n\n if (offset + boxSize <= data.byteLength) {\n if (types.indexOf(boxType) >= 0) {\n boxInfo = new IsoBoxSearchInfo(offset, true, boxSize);\n } else {\n lastCompletedOffset = offset + boxSize;\n }\n }\n\n offset += boxSize;\n }\n\n if (!boxInfo) {\n return new IsoBoxSearchInfo(lastCompletedOffset, false);\n }\n\n return boxInfo;\n }\n\n function getSamplesInfo(ab) {\n if (!ab || ab.byteLength === 0) {\n return {sampleList: [], lastSequenceNumber: NaN, totalDuration: NaN, numSequences: NaN};\n }\n let isoFile = parse(ab);\n // zero or more moofs\n let moofBoxes = isoFile.getBoxes('moof');\n // exactly one mfhd per moof\n let mfhdBoxes = isoFile.getBoxes('mfhd');\n\n let sampleDuration,\n sampleCompositionTimeOffset,\n sampleCount,\n sampleSize,\n sampleDts,\n sampleList,\n sample,\n i, j, k, l, m, n,\n dataOffset,\n lastSequenceNumber,\n numSequences,\n totalDuration;\n\n numSequences = isoFile.getBoxes('moof').length;\n lastSequenceNumber = mfhdBoxes[mfhdBoxes.length - 1].sequence_number;\n sampleCount = 0;\n\n sampleList = [];\n let subsIndex = -1;\n let nextSubsSample = -1;\n for (l = 0; l < moofBoxes.length; l++) {\n let moofBox = moofBoxes[l];\n // zero or more trafs per moof\n let trafBoxes = moofBox.getChildBoxes('traf');\n for (j = 0; j < trafBoxes.length; j++) {\n let trafBox = trafBoxes[j];\n // exactly one tfhd per traf\n let tfhdBox = trafBox.getChildBox('tfhd');\n // zero or one tfdt per traf\n let tfdtBox = trafBox.getChildBox('tfdt');\n sampleDts = tfdtBox.baseMediaDecodeTime;\n // zero or more truns per traf\n let trunBoxes = trafBox.getChildBoxes('trun');\n // zero or more subs per traf\n let subsBoxes = trafBox.getChildBoxes('subs');\n for (k = 0; k < trunBoxes.length; k++) {\n let trunBox = trunBoxes[k];\n sampleCount = trunBox.sample_count;\n dataOffset = (tfhdBox.base_data_offset || 0) + (trunBox.data_offset || 0);\n\n for (i = 0; i < sampleCount; i++) {\n sample = trunBox.samples[i];\n sampleDuration = (sample.sample_duration !== undefined) ? sample.sample_duration : tfhdBox.default_sample_duration;\n sampleSize = (sample.sample_size !== undefined) ? sample.sample_size : tfhdBox.default_sample_size;\n sampleCompositionTimeOffset = (sample.sample_composition_time_offset !== undefined) ? sample.sample_composition_time_offset : 0;\n let sampleData = {\n 'dts': sampleDts,\n 'cts': (sampleDts + sampleCompositionTimeOffset),\n 'duration': sampleDuration,\n 'offset': moofBox.offset + dataOffset,\n 'size': sampleSize,\n 'subSizes': [sampleSize]\n };\n if (subsBoxes) {\n for (m = 0; m < subsBoxes.length; m++) {\n let subsBox = subsBoxes[m];\n if (subsIndex < (subsBox.entry_count - 1) && i > nextSubsSample) {\n subsIndex++;\n nextSubsSample += subsBox.entries[subsIndex].sample_delta;\n }\n if (i == nextSubsSample) {\n sampleData.subSizes = [];\n let entry = subsBox.entries[subsIndex];\n for (n = 0; n < entry.subsample_count; n++) {\n sampleData.subSizes.push(entry.subsamples[n].subsample_size);\n }\n }\n }\n }\n sampleList.push(sampleData);\n dataOffset += sampleSize;\n sampleDts += sampleDuration;\n }\n }\n totalDuration = sampleDts - tfdtBox.baseMediaDecodeTime;\n }\n }\n return {sampleList: sampleList, lastSequenceNumber: lastSequenceNumber, totalDuration: totalDuration, numSequences: numSequences};\n }\n\n function getMediaTimescaleFromMoov(ab) {\n let isoFile = parse(ab);\n let mdhdBox = isoFile ? isoFile.getBox('mdhd') : undefined;\n\n return mdhdBox ? mdhdBox.timescale : NaN;\n }\n\n function parseUint32(data, offset) {\n return data[offset + 3] >>> 0 |\n (data[offset + 2] << 8) >>> 0 |\n (data[offset + 1] << 16) >>> 0 |\n (data[offset] << 24) >>> 0;\n }\n\n function parseIsoBoxType(data, offset) {\n return String.fromCharCode(data[offset++]) +\n String.fromCharCode(data[offset++]) +\n String.fromCharCode(data[offset++]) +\n String.fromCharCode(data[offset]);\n }\n\n function findInitRange(data) {\n let initRange = null;\n let start,\n end;\n\n const isoFile = parse(data);\n\n if (!isoFile) {\n return initRange;\n }\n\n const ftyp = isoFile.getBox('ftyp');\n const moov = isoFile.getBox('moov');\n\n logger.debug('Searching for initialization.');\n\n if (moov && moov.isComplete) {\n start = ftyp ? ftyp.offset : moov.offset;\n end = moov.offset + moov.size - 1;\n initRange = start + '-' + end;\n\n logger.debug('Found the initialization. Range: ' + initRange);\n }\n\n return initRange;\n }\n\n instance = {\n parse: parse,\n findLastTopIsoBoxCompleted: findLastTopIsoBoxCompleted,\n getMediaTimescaleFromMoov: getMediaTimescaleFromMoov,\n getSamplesInfo: getSamplesInfo,\n findInitRange: findInitRange\n };\n\n setup();\n\n return instance;\n}\nBoxParser.__dashjs_factory_name = 'BoxParser';\nexport default FactoryMaker.getSingletonFactory(BoxParser);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\n\n/**\n * @module DefaultURLUtils\n * @description Provides utility functions for operating on URLs.\n * Initially this is simply a method to determine the Base URL of a URL, but\n * should probably include other things provided all over the place such as\n * determining whether a URL is relative/absolute, resolving two paths etc.\n * @ignore\n */\nfunction DefaultURLUtils() {\n\n let resolveFunction;\n\n const schemeRegex = /^[a-z][a-z0-9+\\-_.]*:/i;\n const httpUrlRegex = /^https?:\\/\\//i;\n const httpsUrlRegex = /^https:\\/\\//i;\n const originRegex = /^([a-z][a-z0-9+\\-_.]*:\\/\\/[^\\/]+)\\/?/i;\n\n /**\n * Resolves a url given an optional base url\n * Uses window.URL to do the resolution.\n *\n * @param {string} url\n * @param {string} [baseUrl]\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n * @private\n */\n const nativeURLResolver = (url, baseUrl) => {\n try {\n return new window.URL(url, baseUrl).toString();\n } catch (e) {\n return url;\n }\n };\n\n /**\n * Resolves a url given an optional base url\n * Does not resolve ./, ../ etc but will do enough to construct something\n * which will satisfy XHR etc when window.URL is not available ie\n * IE11/node etc.\n *\n * @param {string} url\n * @param {string} [baseUrl]\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n * @private\n */\n const dumbURLResolver = (url, baseUrl) => {\n let baseUrlParseFunc = parseBaseUrl;\n\n if (!baseUrl) {\n return url;\n }\n\n if (!isRelative(url)) {\n return url;\n }\n\n if (isPathAbsolute(url)) {\n baseUrlParseFunc = parseOrigin;\n }\n\n if (isSchemeRelative(url)) {\n baseUrlParseFunc = parseScheme;\n }\n\n const base = baseUrlParseFunc(baseUrl);\n const joinChar =\n base.charAt(base.length - 1) !== '/' &&\n url.charAt(0) !== '/' ?\n '/' : '';\n\n return [base, url].join(joinChar);\n };\n\n function setup() {\n try {\n const u = new window.URL('x', 'http://y'); //jshint ignore:line\n resolveFunction = nativeURLResolver;\n } catch (e) {\n // must be IE11/Node etc\n } finally {\n resolveFunction = resolveFunction || dumbURLResolver;\n }\n }\n\n /**\n * Returns a string that contains the Base URL of a URL, if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function parseBaseUrl(url) {\n const slashIndex = url.indexOf('/');\n const lastSlashIndex = url.lastIndexOf('/');\n\n if (slashIndex !== -1) {\n // if there is only '//'\n if (lastSlashIndex === slashIndex + 1) {\n return url;\n }\n\n if (url.indexOf('?') !== -1) {\n url = url.substring(0, url.indexOf('?'));\n }\n\n return url.substring(0, lastSlashIndex + 1);\n }\n\n return '';\n }\n\n /**\n * Returns a string that contains the scheme and origin of a URL,\n * if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function parseOrigin(url) {\n const matches = url.match(originRegex);\n\n if (matches) {\n return matches[1];\n }\n\n return '';\n }\n\n /**\n * Returns a string that contains the fragment of a URL without scheme,\n * if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function removeHostname(url) {\n let urlParts = /^(?:\\w+\\:\\/\\/)?([^\\/]+)(.*)$/.exec(url); //[1] = host / [2] = path\n return urlParts[2].substring(1);\n }\n\n /**\n * Returns a string that contains the scheme of a URL, if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function parseScheme(url) {\n const matches = url.match(schemeRegex);\n\n if (matches) {\n return matches[0];\n }\n\n return '';\n }\n\n /**\n * Determines whether the url is relative.\n * @return {boolean}\n * @param {string} url\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function isRelative(url) {\n return !schemeRegex.test(url);\n }\n\n /**\n * Determines whether the url is path-absolute.\n * @return {bool}\n * @param {string} url\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function isPathAbsolute(url) {\n return isRelative(url) && url.charAt(0) === '/';\n }\n\n /**\n * Determines whether the url is scheme-relative.\n * @return {bool}\n * @param {string} url\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function isSchemeRelative(url) {\n return url.indexOf('//') === 0;\n }\n\n /**\n * Determines whether the url is an HTTP-URL as defined in ISO/IEC\n * 23009-1:2014 3.1.15. ie URL with a fixed scheme of http or https\n * @return {bool}\n * @param {string} url\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function isHTTPURL(url) {\n return httpUrlRegex.test(url);\n }\n\n /**\n * Determines whether the supplied url has https scheme\n * @return {bool}\n * @param {string} url\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function isHTTPS(url) {\n return httpsUrlRegex.test(url);\n }\n\n /**\n * Resolves a url given an optional base url\n * @return {string}\n * @param {string} url\n * @param {string} [baseUrl]\n * @memberof module:DefaultURLUtils\n * @instance\n */\n function resolve(url, baseUrl) {\n return resolveFunction(url, baseUrl);\n }\n\n setup();\n\n const instance = {\n parseBaseUrl: parseBaseUrl,\n parseOrigin: parseOrigin,\n parseScheme: parseScheme,\n isRelative: isRelative,\n isPathAbsolute: isPathAbsolute,\n isSchemeRelative: isSchemeRelative,\n isHTTPURL: isHTTPURL,\n isHTTPS: isHTTPS,\n removeHostname: removeHostname,\n resolve: resolve\n };\n\n return instance;\n}\n\nDefaultURLUtils.__dashjs_factory_name = 'DefaultURLUtils';\nexport default FactoryMaker.getSingletonFactory(DefaultURLUtils);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport IsoBox from '../vo/IsoBox';\nimport FactoryMaker from '../../core/FactoryMaker';\n\nfunction IsoFile() {\n\n let instance,\n parsedIsoFile;\n\n /**\n * @param {string} type\n * @returns {IsoBox|null}\n * @memberof IsoFile#\n */\n function getBox(type) {\n if (!type || !parsedIsoFile || !parsedIsoFile.boxes || (parsedIsoFile.boxes.length === 0) || typeof parsedIsoFile.fetch !== 'function') return null;\n\n return convertToDashIsoBox(parsedIsoFile.fetch(type));\n }\n\n /**\n * @param {string} type\n * @returns {Array|null} array of {@link IsoBox}\n * @memberof IsoFile#\n */\n function getBoxes(type) {\n let boxes = [];\n\n if (!type || !parsedIsoFile || typeof parsedIsoFile.fetchAll !== 'function') {\n return boxes;\n }\n\n let boxData = parsedIsoFile.fetchAll(type);\n let box;\n\n for (let i = 0, ln = boxData.length; i < ln; i++) {\n box = convertToDashIsoBox(boxData[i]);\n\n if (box) {\n boxes.push(box);\n }\n }\n\n return boxes;\n }\n\n /**\n * @param {string} value\n * @memberof IsoFile#\n */\n function setData(value) {\n parsedIsoFile = value;\n }\n\n /**\n * @returns {IsoBox|null}\n * @memberof IsoFile#\n */\n function getLastBox() {\n if (!parsedIsoFile || !parsedIsoFile.boxes || !parsedIsoFile.boxes.length) return null;\n\n let type = parsedIsoFile.boxes[parsedIsoFile.boxes.length - 1].type;\n let boxes = getBoxes(type);\n\n return boxes.length > 0 ? boxes[boxes.length - 1] : null;\n }\n\n function convertToDashIsoBox(boxData) {\n if (!boxData) return null;\n\n let box = new IsoBox(boxData);\n\n if (boxData.hasOwnProperty('_incomplete')) {\n box.isComplete = !boxData._incomplete;\n }\n\n return box;\n }\n\n instance = {\n getBox: getBox,\n getBoxes: getBoxes,\n setData: setData,\n getLastBox: getLastBox\n };\n\n return instance;\n}\nIsoFile.__dashjs_factory_name = 'IsoFile';\nexport default FactoryMaker.getClassFactory(IsoFile);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport deepEqual from 'fast-deep-equal';\n\n/**\n * @module ObjectUtils\n * @ignore\n * @description Provides utility functions for objects\n */\nfunction ObjectUtils() {\n\n let instance;\n\n /**\n * Returns true if objects are equal\n * @return {boolean}\n * @param {object} obj1\n * @param {object} obj2\n * @memberof module:ObjectUtils\n * @instance\n */\n function areEqual(obj1, obj2) {\n return deepEqual(obj1, obj2);\n }\n\n instance = {\n areEqual: areEqual\n };\n\n return instance;\n}\n\nObjectUtils.__dashjs_factory_name = 'ObjectUtils';\nexport default FactoryMaker.getSingletonFactory(ObjectUtils);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\n\nfunction RequestModifier() {\n\n let instance;\n\n function modifyRequestURL(url) {\n return url;\n }\n\n function modifyRequestHeader(request) {\n return request;\n }\n\n instance = {\n modifyRequestURL: modifyRequestURL,\n modifyRequestHeader: modifyRequestHeader\n };\n\n return instance;\n}\n\nRequestModifier.__dashjs_factory_name = 'RequestModifier';\nexport default FactoryMaker.getSingletonFactory(RequestModifier);\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport FactoryMaker from '../../core/FactoryMaker';\nimport DefaultURLUtils from './DefaultURLUtils';\n\n/**\n * @module URLUtils\n * @ignore\n * @description Provides utility functions for operating on URLs.\n * Initially this is simply a method to determine the Base URL of a URL, but\n * should probably include other things provided all over the place such as\n * determining whether a URL is relative/absolute, resolving two paths etc.\n */\nfunction URLUtils() {\n\n let instance;\n let defaultURLUtils;\n let regexUtils = [];\n const context = this.context;\n\n function getUtils(url) {\n let i;\n for (i = 0; i < regexUtils.length; i++) {\n let regex = regexUtils[i].regex;\n if (regex.test(url)) {\n return regexUtils[i].utils;\n }\n }\n return defaultURLUtils;\n }\n\n function setup() {\n defaultURLUtils = DefaultURLUtils(context).getInstance();\n }\n\n /**\n * Register a module to handle specific url.\n * @param {regex} regex - url regex\n * @param {object} utils - object that handles the regex\n * @memberof module:URLUtils\n * @instance\n */\n function registerUrlRegex(regex, utils) {\n regexUtils.push({regex: regex, utils: utils});\n }\n\n function internalCall(functionName, url, baseUrl) {\n let utils = getUtils(baseUrl || url);\n return utils && typeof (utils[functionName]) === 'function' ? utils[functionName](url, baseUrl) : defaultURLUtils[functionName](url, baseUrl);\n }\n\n /**\n * Returns a string that contains the Base URL of a URL, if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:URLUtils\n * @instance\n */\n function parseBaseUrl(url) {\n return internalCall('parseBaseUrl', url);\n }\n\n /**\n * Returns a string that contains the scheme and origin of a URL,\n * if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:URLUtils\n * @instance\n */\n function parseOrigin(url) {\n return internalCall('parseOrigin', url);\n }\n\n /**\n * Returns a string that contains the fragment of a URL without scheme,\n * if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:URLUtils\n * @instance\n */\n function removeHostname(url) {\n return internalCall('removeHostname', url);\n }\n\n /**\n * Returns a string that contains the scheme of a URL, if determinable.\n * @param {string} url - full url\n * @return {string}\n * @memberof module:URLUtils\n * @instance\n */\n function parseScheme(url) {\n return internalCall('parseScheme', url);\n }\n\n /**\n * Determines whether the url is relative.\n * @return {boolean}\n * @param {string} url\n * @memberof module:URLUtils\n * @instance\n */\n function isRelative(url) {\n return internalCall('isRelative', url);\n }\n\n /**\n * Determines whether the url is path-absolute.\n * @return {bool}\n * @param {string} url\n * @memberof module:URLUtils\n * @instance\n */\n function isPathAbsolute(url) {\n return internalCall('isPathAbsolute', url);\n }\n\n /**\n * Determines whether the url is scheme-relative.\n * @return {bool}\n * @param {string} url\n * @memberof module:URLUtils\n * @instance\n */\n function isSchemeRelative(url) {\n return internalCall('isSchemeRelative', url);\n }\n\n /**\n * Determines whether the url is an HTTP-URL as defined in ISO/IEC\n * 23009-1:2014 3.1.15. ie URL with a fixed scheme of http or https\n * @return {bool}\n * @param {string} url\n * @memberof module:URLUtils\n * @instance\n */\n function isHTTPURL(url) {\n return internalCall('isHTTPURL', url);\n }\n\n /**\n * Determines whether the supplied url has https scheme\n * @return {bool}\n * @param {string} url\n * @memberof module:URLUtils\n * @instance\n */\n function isHTTPS(url) {\n return internalCall('isHTTPS', url);\n }\n\n /**\n * Resolves a url given an optional base url\n * @return {string}\n * @param {string} url\n * @param {string} [baseUrl]\n * @memberof module:URLUtils\n * @instance\n */\n function resolve(url, baseUrl) {\n return internalCall('resolve', url, baseUrl);\n }\n\n setup();\n instance = {\n registerUrlRegex: registerUrlRegex,\n parseBaseUrl: parseBaseUrl,\n parseOrigin: parseOrigin,\n parseScheme: parseScheme,\n isRelative: isRelative,\n isPathAbsolute: isPathAbsolute,\n isSchemeRelative: isSchemeRelative,\n isHTTPURL: isHTTPURL,\n isHTTPS: isHTTPS,\n removeHostname: removeHostname,\n resolve: resolve\n };\n\n return instance;\n}\n\nURLUtils.__dashjs_factory_name = 'URLUtils';\nconst factory = FactoryMaker.getSingletonFactory(URLUtils);\nexport default factory;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass DashJSError {\n constructor(code, message, data) {\n this.code = code || null;\n this.message = message || null;\n this.data = data || null;\n }\n}\n\nexport default DashJSError;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { HTTPRequest } from '../vo/metrics/HTTPRequest';\n\n/**\n * @class\n * @ignore\n */\nclass FragmentRequest {\n constructor(url) {\n this.action = FragmentRequest.ACTION_DOWNLOAD;\n this.startTime = NaN;\n this.mediaType = null;\n this.mediaInfo = null;\n this.type = null;\n this.duration = NaN;\n this.timescale = NaN;\n this.range = null;\n this.url = url || null;\n this.serviceLocation = null;\n this.requestStartDate = null;\n this.firstByteDate = null;\n this.requestEndDate = null;\n this.quality = NaN;\n this.index = NaN;\n this.availabilityStartTime = null;\n this.availabilityEndTime = null;\n this.wallStartTime = null;\n this.bytesLoaded = NaN;\n this.bytesTotal = NaN;\n this.delayLoadingTime = NaN;\n this.responseType = 'arraybuffer';\n this.representationId = null;\n }\n\n isInitializationRequest() {\n return (this.type && this.type === HTTPRequest.INIT_SEGMENT_TYPE);\n }\n\n setInfo(info) {\n this.type = info && info.init ? HTTPRequest.INIT_SEGMENT_TYPE : HTTPRequest.MEDIA_SEGMENT_TYPE;\n this.url = info && info.url ? info.url : null;\n this.range = info && info.range ? info.range.start + '-' + info.range.end : null;\n this.mediaType = info && info.mediaType ? info.mediaType : null;\n }\n}\n\nFragmentRequest.ACTION_DOWNLOAD = 'download';\nFragmentRequest.ACTION_COMPLETE = 'complete';\n\nexport default FragmentRequest;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nimport FragmentRequest from './FragmentRequest';\n\nclass HeadRequest extends FragmentRequest {\n constructor(url) {\n super(url);\n this.checkForExistenceOnly = true;\n }\n}\n\nexport default HeadRequest;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass IsoBox {\n constructor(boxData) {\n this.offset = boxData._offset;\n this.type = boxData.type;\n this.size = boxData.size;\n this.boxes = [];\n if (boxData.boxes) {\n for (let i = 0; i < boxData.boxes.length; i++) {\n this.boxes.push(new IsoBox(boxData.boxes[i]));\n }\n }\n this.isComplete = true;\n\n switch (boxData.type) {\n case 'sidx':\n this.timescale = boxData.timescale;\n this.earliest_presentation_time = boxData.earliest_presentation_time;\n this.first_offset = boxData.first_offset;\n this.references = boxData.references;\n if (boxData.references) {\n this.references = [];\n for (let i = 0; i < boxData.references.length; i++) {\n let reference = {\n reference_type: boxData.references[i].reference_type,\n referenced_size: boxData.references[i].referenced_size,\n subsegment_duration: boxData.references[i].subsegment_duration\n };\n this.references.push(reference);\n }\n }\n break;\n case 'emsg':\n this.id = boxData.id;\n this.value = boxData.value;\n this.timescale = boxData.timescale;\n this.scheme_id_uri = boxData.scheme_id_uri;\n this.presentation_time_delta = boxData.version === 1 ? boxData.presentation_time : boxData.presentation_time_delta;\n this.event_duration = boxData.event_duration;\n this.message_data = boxData.message_data;\n break;\n case 'mdhd':\n this.timescale = boxData.timescale;\n break;\n case 'mfhd':\n this.sequence_number = boxData.sequence_number;\n break;\n case 'subs':\n this.entry_count = boxData.entry_count;\n this.entries = boxData.entries;\n break;\n case 'tfhd':\n this.base_data_offset = boxData.base_data_offset;\n this.sample_description_index = boxData.sample_description_index;\n this.default_sample_duration = boxData.default_sample_duration;\n this.default_sample_size = boxData.default_sample_size;\n this.default_sample_flags = boxData.default_sample_flags;\n this.flags = boxData.flags;\n break;\n case 'tfdt':\n this.version = boxData.version;\n this.baseMediaDecodeTime = boxData.baseMediaDecodeTime;\n this.flags = boxData.flags;\n break;\n case 'trun':\n this.sample_count = boxData.sample_count;\n this.first_sample_flags = boxData.first_sample_flags;\n this.data_offset = boxData.data_offset;\n this.flags = boxData.flags;\n this.samples = boxData.samples;\n if (boxData.samples) {\n this.samples = [];\n for (let i = 0, ln = boxData.samples.length; i < ln; i++) {\n let sample = {\n sample_size: boxData.samples[i].sample_size,\n sample_duration: boxData.samples[i].sample_duration,\n sample_composition_time_offset: boxData.samples[i].sample_composition_time_offset\n };\n this.samples.push(sample);\n }\n }\n break;\n }\n\n }\n\n getChildBox(type) {\n for (let i = 0; i < this.boxes.length; i++) {\n if (this.boxes[i].type === type) {\n return this.boxes[i];\n }\n }\n }\n\n getChildBoxes(type) {\n let boxes = [];\n for (let i = 0; i < this.boxes.length; i++) {\n if (this.boxes[i].type === type) {\n boxes.push(this.boxes[i]);\n }\n }\n return boxes;\n }\n\n}\n\nexport default IsoBox;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass IsoBoxSearchInfo {\n constructor(lastCompletedOffset, found, size) {\n this.lastCompletedOffset = lastCompletedOffset;\n this.found = found;\n this.size = size;\n }\n}\n\nexport default IsoBoxSearchInfo;\n",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @class\n * @ignore\n */\nclass ThumbnailTrackInfo {\n constructor() {\n this.bitrate = 0;\n this.width = 0;\n this.height = 0;\n this.tilesHor = 0;\n this.tilesVert = 0;\n this.widthPerTile = 0;\n this.heightPerTile = 0;\n this.startNumber = 0;\n this.segmentDuration = 0;\n this.timescale = 0;\n this.templateUrl = '';\n this.id = '';\n }\n}\n\nexport default ThumbnailTrackInfo;",
"/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2013, Dash Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * * Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * @classdesc This Object holds reference to the HTTPRequest for manifest, fragment and xlink loading.\n * Members which are not defined in ISO23009-1 Annex D should be prefixed by a _ so that they are ignored\n * by Metrics Reporting code.\n * @ignore\n */\nclass HTTPRequest {\n /**\n * @class\n */\n constructor() {\n /**\n * Identifier of the TCP connection on which the HTTP request was sent.\n * @public\n */\n this.tcpid = null;\n /**\n * This is an optional parameter and should not be included in HTTP request/response transactions for progressive download.\n * The type of the request:\n * - MPD\n * - XLink expansion\n * - Initialization Fragment\n * - Index Fragment\n * - Media Fragment\n * - Bitstream Switching Fragment\n * - other\n * @public\n */\n this.type = null;\n /**\n * The original URL (before any redirects or failures)\n * @public\n */\n this.url = null;\n /**\n * The actual URL requested, if different from above\n * @public\n */\n this.actualurl = null;\n /**\n * The contents of the byte-range-spec part of the HTTP Range header.\n * @public\n */\n this.range = null;\n /**\n * Real-Time | The real time at which the request was sent.\n * @public\n */\n this.trequest = null;\n /**\n * Real-Time | The real time at which the first byte of the response was received.\n * @public\n */\n this.tresponse = null;\n /**\n * The HTTP response code.\n * @public\n */\n this.responsecode = null;\n /**\n * The duration of the throughput trace intervals (ms), for successful requests only.\n * @public\n */\n this.interval = null;\n /**\n * Throughput traces, for successful requests only.\n * @public\n */\n this.trace = [];\n\n /**\n * Type of stream (\"audio\" | \"video\" etc..)\n * @public\n */\n this._stream = null;\n /**\n * Real-Time | The real time at which the request finished.\n * @public\n */\n this._tfinish = null;\n /**\n * The duration of the media requests, if available, in milliseconds.\n * @public\n */\n this._mediaduration = null;\n /**\n * The media segment quality\n * @public\n */\n this._quality = null;\n /**\n * all the response headers from request.\n * @public\n */\n this._responseHeaders = null;\n /**\n * The selected service location for the request. string.\n * @public\n */\n this._serviceLocation = null;\n }\n}\n\n/**\n * @classdesc This Object holds reference to the progress of the HTTPRequest.\n * @ignore\n */\nclass HTTPRequestTrace {\n /**\n * @class\n */\n constructor() {\n /**\n * Real-Time | Measurement stream start.\n * @public\n */\n this.s = null;\n /**\n * Measurement stream duration (ms).\n * @public\n */\n this.d = null;\n /**\n * List of integers counting the bytes received in each trace interval within the measurement stream.\n * @public\n */\n this.b = [];\n }\n}\n\nHTTPRequest.GET = 'GET';\nHTTPRequest.HEAD = 'HEAD';\nHTTPRequest.MPD_TYPE = 'MPD';\nHTTPRequest.XLINK_EXPANSION_TYPE = 'XLinkExpansion';\nHTTPRequest.INIT_SEGMENT_TYPE = 'InitializationSegment';\nHTTPRequest.INDEX_SEGMENT_TYPE = 'IndexSegment';\nHTTPRequest.MEDIA_SEGMENT_TYPE = 'MediaSegment';\nHTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE = 'BitstreamSwitchingSegment';\nHTTPRequest.OTHER_TYPE = 'other';\n\nexport { HTTPRequest, HTTPRequestTrace };\n"
]
}