UNPKG

@l5i/dashjs

Version:

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

1,239 lines (1,008 loc) 117 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.dashjs || (g.dashjs = {})).MetricsReporting = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @module FactoryMaker */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var FactoryMaker = (function () { var instance = undefined; var singletonContexts = []; var singletonFactories = {}; var classFactories = {}; function extend(name, childInstance, override, context) { if (!context[name] && childInstance) { context[name] = { instance: childInstance, override: override }; } } /** * Use this method from your extended object. this.factory is injected into your object. * this.factory.getSingletonInstance(this.context, 'VideoModel') * will return the video model for use in the extended object. * * @param {Object} context - injected into extended object as this.context * @param {string} className - string name found in all dash.js objects * with name __dashjs_factory_name Will be at the bottom. Will be the same as the object's name. * @returns {*} Context aware instance of specified singleton name. * @memberof module:FactoryMaker * @instance */ function getSingletonInstance(context, className) { for (var i in singletonContexts) { var obj = singletonContexts[i]; if (obj.context === context && obj.name === className) { return obj.instance; } } return null; } /** * Use this method to add an singleton instance to the system. Useful for unit testing to mock objects etc. * * @param {Object} context * @param {string} className * @param {Object} instance * @memberof module:FactoryMaker * @instance */ function setSingletonInstance(context, className, instance) { for (var i in singletonContexts) { var obj = singletonContexts[i]; if (obj.context === context && obj.name === className) { singletonContexts[i].instance = instance; return; } } singletonContexts.push({ name: className, context: context, instance: instance }); } /*------------------------------------------------------------------------------------------*/ // Factories storage Management /*------------------------------------------------------------------------------------------*/ function getFactoryByName(name, factoriesArray) { return factoriesArray[name]; } function updateFactory(name, factory, factoriesArray) { if (name in factoriesArray) { factoriesArray[name] = factory; } } /*------------------------------------------------------------------------------------------*/ // Class Factories Management /*------------------------------------------------------------------------------------------*/ function updateClassFactory(name, factory) { updateFactory(name, factory, classFactories); } function getClassFactoryByName(name) { return getFactoryByName(name, classFactories); } function getClassFactory(classConstructor) { var factory = getFactoryByName(classConstructor.__dashjs_factory_name, classFactories); if (!factory) { factory = function (context) { if (context === undefined) { context = {}; } return { create: function create() { return merge(classConstructor, context, arguments); } }; }; classFactories[classConstructor.__dashjs_factory_name] = factory; // store factory } return factory; } /*------------------------------------------------------------------------------------------*/ // Singleton Factory MAangement /*------------------------------------------------------------------------------------------*/ function updateSingletonFactory(name, factory) { updateFactory(name, factory, singletonFactories); } function getSingletonFactoryByName(name) { return getFactoryByName(name, singletonFactories); } function getSingletonFactory(classConstructor) { var factory = getFactoryByName(classConstructor.__dashjs_factory_name, singletonFactories); if (!factory) { factory = function (context) { var instance = undefined; if (context === undefined) { context = {}; } return { getInstance: function getInstance() { // If we don't have an instance yet check for one on the context if (!instance) { instance = getSingletonInstance(context, classConstructor.__dashjs_factory_name); } // If there's no instance on the context then create one if (!instance) { instance = merge(classConstructor, context, arguments); singletonContexts.push({ name: classConstructor.__dashjs_factory_name, context: context, instance: instance }); } return instance; } }; }; singletonFactories[classConstructor.__dashjs_factory_name] = factory; // store factory } return factory; } function merge(classConstructor, context, args) { var classInstance = undefined; var className = classConstructor.__dashjs_factory_name; var extensionObject = context[className]; if (extensionObject) { var extension = extensionObject.instance; if (extensionObject.override) { //Override public methods in parent but keep parent. classInstance = classConstructor.apply({ context: context }, args); extension = extension.apply({ context: context, factory: instance, parent: classInstance }, args); for (var prop in extension) { if (classInstance.hasOwnProperty(prop)) { classInstance[prop] = extension[prop]; } } } else { //replace parent object completely with new object. Same as dijon. return extension.apply({ context: context, factory: instance }, args); } } else { // Create new instance of the class classInstance = classConstructor.apply({ context: context }, args); } // Add getClassName function to class instance prototype (used by Debug) classInstance.getClassName = function () { return className; }; return classInstance; } instance = { extend: extend, getSingletonInstance: getSingletonInstance, setSingletonInstance: setSingletonInstance, getSingletonFactory: getSingletonFactory, getSingletonFactoryByName: getSingletonFactoryByName, updateSingletonFactory: updateSingletonFactory, getClassFactory: getClassFactory, getClassFactoryByName: getClassFactoryByName, updateClassFactory: updateClassFactory }; return instance; })(); exports["default"] = FactoryMaker; module.exports = exports["default"]; },{}],2:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * @class * @ignore */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var EventsBase = (function () { function EventsBase() { _classCallCheck(this, EventsBase); } _createClass(EventsBase, [{ key: 'extend', value: function extend(events, config) { if (!events) return; var override = config ? config.override : false; var publicOnly = config ? config.publicOnly : false; for (var evt in events) { if (!events.hasOwnProperty(evt) || this[evt] && !override) continue; if (publicOnly && events[evt].indexOf('public_') === -1) continue; this[evt] = events[evt]; } } }]); return EventsBase; })(); exports['default'] = EventsBase; module.exports = exports['default']; },{}],3:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _utilsDVBErrorsTranslator = _dereq_(17); var _utilsDVBErrorsTranslator2 = _interopRequireDefault(_utilsDVBErrorsTranslator); var _MetricsReportingEvents = _dereq_(4); var _MetricsReportingEvents2 = _interopRequireDefault(_MetricsReportingEvents); var _controllersMetricsCollectionController = _dereq_(5); var _controllersMetricsCollectionController2 = _interopRequireDefault(_controllersMetricsCollectionController); var _metricsMetricsHandlerFactory = _dereq_(10); var _metricsMetricsHandlerFactory2 = _interopRequireDefault(_metricsMetricsHandlerFactory); var _reportingReportingFactory = _dereq_(15); var _reportingReportingFactory2 = _interopRequireDefault(_reportingReportingFactory); function MetricsReporting() { var context = this.context; var instance = undefined; var dvbErrorsTranslator = undefined; /** * Create a MetricsCollectionController, and a DVBErrorsTranslator * @param {Object} config - dependancies from owner * @return {MetricsCollectionController} Metrics Collection Controller */ function createMetricsReporting(config) { dvbErrorsTranslator = (0, _utilsDVBErrorsTranslator2['default'])(context).getInstance({ eventBus: config.eventBus, metricsModel: config.metricsModel, metricsConstants: config.metricsConstants, events: config.events }); return (0, _controllersMetricsCollectionController2['default'])(context).create(config); } /** * Get the ReportingFactory to allow new reporters to be registered * @return {ReportingFactory} Reporting Factory */ function getReportingFactory() { return (0, _reportingReportingFactory2['default'])(context).getInstance(); } /** * Get the MetricsHandlerFactory to allow new handlers to be registered * @return {MetricsHandlerFactory} Metrics Handler Factory */ function getMetricsHandlerFactory() { return (0, _metricsMetricsHandlerFactory2['default'])(context).getInstance(); } instance = { createMetricsReporting: createMetricsReporting, getReportingFactory: getReportingFactory, getMetricsHandlerFactory: getMetricsHandlerFactory }; return instance; } MetricsReporting.__dashjs_factory_name = 'MetricsReporting'; var factory = dashjs.FactoryMaker.getClassFactory(MetricsReporting); /* jshint ignore:line */ factory.events = _MetricsReportingEvents2['default']; dashjs.FactoryMaker.updateClassFactory(MetricsReporting.__dashjs_factory_name, factory); /* jshint ignore:line */ exports['default'] = factory; module.exports = exports['default']; },{"10":10,"15":15,"17":17,"4":4,"5":5}],4:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var _coreEventsEventsBase = _dereq_(2); var _coreEventsEventsBase2 = _interopRequireDefault(_coreEventsEventsBase); var MetricsReportingEvents = (function (_EventsBase) { _inherits(MetricsReportingEvents, _EventsBase); function MetricsReportingEvents() { _classCallCheck(this, MetricsReportingEvents); _get(Object.getPrototypeOf(MetricsReportingEvents.prototype), 'constructor', this).call(this); this.METRICS_INITIALISATION_COMPLETE = 'internal_metricsReportingInitialized'; this.BECAME_REPORTING_PLAYER = 'internal_becameReportingPlayer'; } return MetricsReportingEvents; })(_coreEventsEventsBase2['default']); var metricsReportingEvents = new MetricsReportingEvents(); exports['default'] = metricsReportingEvents; module.exports = exports['default']; },{"2":2}],5:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _MetricsController = _dereq_(6); var _MetricsController2 = _interopRequireDefault(_MetricsController); var _utilsManifestParsing = _dereq_(19); var _utilsManifestParsing2 = _interopRequireDefault(_utilsManifestParsing); var _MetricsReportingEvents = _dereq_(4); var _MetricsReportingEvents2 = _interopRequireDefault(_MetricsReportingEvents); function MetricsCollectionController(config) { config = config || {}; var metricsControllers = {}; var context = this.context; var eventBus = config.eventBus; var events = config.events; function update(e) { if (e.error) { return; } // start by assuming all existing controllers need removing var controllersToRemove = Object.keys(metricsControllers); var metrics = (0, _utilsManifestParsing2['default'])(context).getInstance({ dashManifestModel: config.dashManifestModel, constants: config.constants }).getMetrics(e.manifest); metrics.forEach(function (m) { var key = JSON.stringify(m); if (!metricsControllers.hasOwnProperty(key)) { try { var controller = (0, _MetricsController2['default'])(context).create(config); controller.initialize(m); metricsControllers[key] = controller; } catch (e) { // fail quietly } } else { // we still need this controller - delete from removal list controllersToRemove.splice(key, 1); } }); // now remove the unwanted controllers controllersToRemove.forEach(function (c) { metricsControllers[c].reset(); delete metricsControllers[c]; }); eventBus.trigger(_MetricsReportingEvents2['default'].METRICS_INITIALISATION_COMPLETE); } function resetMetricsControllers() { Object.keys(metricsControllers).forEach(function (key) { metricsControllers[key].reset(); }); metricsControllers = {}; } function setup() { eventBus.on(events.MANIFEST_UPDATED, update); eventBus.on(events.STREAM_TEARDOWN_COMPLETE, resetMetricsControllers); } function reset() { eventBus.off(events.MANIFEST_UPDATED, update); eventBus.off(events.STREAM_TEARDOWN_COMPLETE, resetMetricsControllers); } setup(); return { reset: reset }; } MetricsCollectionController.__dashjs_factory_name = 'MetricsCollectionController'; exports['default'] = dashjs.FactoryMaker.getClassFactory(MetricsCollectionController); /* jshint ignore:line */ module.exports = exports['default']; },{"19":19,"4":4,"6":6}],6:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _RangeController = _dereq_(8); var _RangeController2 = _interopRequireDefault(_RangeController); var _ReportingController = _dereq_(9); var _ReportingController2 = _interopRequireDefault(_ReportingController); var _MetricsHandlersController = _dereq_(7); var _MetricsHandlersController2 = _interopRequireDefault(_MetricsHandlersController); function MetricsController(config) { config = config || {}; var metricsHandlersController = undefined, reportingController = undefined, rangeController = undefined, instance = undefined; var context = this.context; function initialize(metricsEntry) { try { rangeController = (0, _RangeController2['default'])(context).create({ mediaElement: config.mediaElement }); rangeController.initialize(metricsEntry.Range); reportingController = (0, _ReportingController2['default'])(context).create({ debug: config.debug, metricsConstants: config.metricsConstants }); reportingController.initialize(metricsEntry.Reporting, rangeController); metricsHandlersController = (0, _MetricsHandlersController2['default'])(context).create({ debug: config.debug, eventBus: config.eventBus, metricsConstants: config.metricsConstants, events: config.events }); metricsHandlersController.initialize(metricsEntry.metrics, reportingController); } catch (e) { reset(); throw e; } } function reset() { if (metricsHandlersController) { metricsHandlersController.reset(); } if (reportingController) { reportingController.reset(); } if (rangeController) { rangeController.reset(); } } instance = { initialize: initialize, reset: reset }; return instance; } MetricsController.__dashjs_factory_name = 'MetricsController'; exports['default'] = dashjs.FactoryMaker.getClassFactory(MetricsController); /* jshint ignore:line */ module.exports = exports['default']; },{"7":7,"8":8,"9":9}],7:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _metricsMetricsHandlerFactory = _dereq_(10); var _metricsMetricsHandlerFactory2 = _interopRequireDefault(_metricsMetricsHandlerFactory); function MetricsHandlersController(config) { config = config || {}; var handlers = []; var instance = undefined; var context = this.context; var eventBus = config.eventBus; var Events = config.events; var metricsHandlerFactory = (0, _metricsMetricsHandlerFactory2['default'])(context).getInstance({ debug: config.debug, eventBus: config.eventBus, metricsConstants: config.metricsConstants }); function handle(e) { handlers.forEach(function (handler) { handler.handleNewMetric(e.metric, e.value, e.mediaType); }); } function initialize(metrics, reportingController) { metrics.split(',').forEach(function (m, midx, ms) { var handler = undefined; // there is a bug in ISO23009-1 where the metrics attribute // is a comma-separated list but HttpList key can contain a // comma enclosed by (). if (m.indexOf('(') !== -1 && m.indexOf(')') === -1) { var nextm = ms[midx + 1]; if (nextm && nextm.indexOf('(') === -1 && nextm.indexOf(')') !== -1) { m += ',' + nextm; // delete the next metric so forEach does not visit. delete ms[midx + 1]; } } handler = metricsHandlerFactory.create(m, reportingController); if (handler) { handlers.push(handler); } }); eventBus.on(Events.METRIC_ADDED, handle, instance); eventBus.on(Events.METRIC_UPDATED, handle, instance); } function reset() { eventBus.off(Events.METRIC_ADDED, handle, instance); eventBus.off(Events.METRIC_UPDATED, handle, instance); handlers.forEach(function (handler) { return handler.reset(); }); handlers = []; } instance = { initialize: initialize, reset: reset }; return instance; } MetricsHandlersController.__dashjs_factory_name = 'MetricsHandlersController'; exports['default'] = dashjs.FactoryMaker.getClassFactory(MetricsHandlersController); /* jshint ignore:line */ module.exports = exports['default']; },{"10":10}],8:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _utilsCustomTimeRanges = _dereq_(26); var _utilsCustomTimeRanges2 = _interopRequireDefault(_utilsCustomTimeRanges); function RangeController(config) { config = config || {}; var useWallClockTime = false; var context = this.context; var instance = undefined, ranges = undefined; var mediaElement = config.mediaElement; function initialize(rs) { if (rs && rs.length) { rs.forEach(function (r) { var start = r.starttime; var end = start + r.duration; ranges.add(start, end); }); useWallClockTime = !!rs[0]._useWallClockTime; } } function reset() { ranges.clear(); } function setup() { ranges = (0, _utilsCustomTimeRanges2['default'])(context).create(); } function isEnabled() { var numRanges = ranges.length; var time = undefined; if (!numRanges) { return true; } // When not present, DASH Metrics reporting is requested // for the whole duration of the content. time = useWallClockTime ? new Date().getTime() / 1000 : mediaElement.currentTime; for (var i = 0; i < numRanges; i += 1) { var start = ranges.start(i); var end = ranges.end(i); if (start <= time && time < end) { return true; } } return false; } instance = { initialize: initialize, reset: reset, isEnabled: isEnabled }; setup(); return instance; } RangeController.__dashjs_factory_name = 'RangeController'; exports['default'] = dashjs.FactoryMaker.getClassFactory(RangeController); /* jshint ignore:line */ module.exports = exports['default']; },{"26":26}],9:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _reportingReportingFactory = _dereq_(15); var _reportingReportingFactory2 = _interopRequireDefault(_reportingReportingFactory); function ReportingController(config) { var reporters = []; var instance = undefined; var reportingFactory = (0, _reportingReportingFactory2['default'])(this.context).getInstance(config); function initialize(reporting, rangeController) { // "if multiple Reporting elements are present, it is expected that // the client processes one of the recognized reporting schemes." // to ignore this, and support multiple Reporting per Metric, // simply change the 'some' below to 'forEach' reporting.some(function (r) { var reporter = reportingFactory.create(r, rangeController); if (reporter) { reporters.push(reporter); return true; } }); } function reset() { reporters.forEach(function (r) { return r.reset(); }); reporters = []; } function report(type, vos) { reporters.forEach(function (r) { return r.report(type, vos); }); } instance = { initialize: initialize, reset: reset, report: report }; return instance; } ReportingController.__dashjs_factory_name = 'ReportingController'; exports['default'] = dashjs.FactoryMaker.getClassFactory(ReportingController); /* jshint ignore:line */ module.exports = exports['default']; },{"15":15}],10:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _handlersBufferLevelHandler = _dereq_(11); var _handlersBufferLevelHandler2 = _interopRequireDefault(_handlersBufferLevelHandler); var _handlersDVBErrorsHandler = _dereq_(12); var _handlersDVBErrorsHandler2 = _interopRequireDefault(_handlersDVBErrorsHandler); var _handlersHttpListHandler = _dereq_(14); var _handlersHttpListHandler2 = _interopRequireDefault(_handlersHttpListHandler); var _handlersGenericMetricHandler = _dereq_(13); var _handlersGenericMetricHandler2 = _interopRequireDefault(_handlersGenericMetricHandler); function MetricsHandlerFactory(config) { config = config || {}; var instance = undefined; var debug = config.debug; // group 1: key, [group 3: n [, group 5: type]] var keyRegex = /([a-zA-Z]*)(\(([0-9]*)(\,\s*([a-zA-Z]*))?\))?/; var context = this.context; var knownFactoryProducts = { BufferLevel: _handlersBufferLevelHandler2['default'], DVBErrors: _handlersDVBErrorsHandler2['default'], HttpList: _handlersHttpListHandler2['default'], PlayList: _handlersGenericMetricHandler2['default'], RepSwitchList: _handlersGenericMetricHandler2['default'], TcpList: _handlersGenericMetricHandler2['default'] }; function create(listType, reportingController) { var matches = listType.match(keyRegex); var handler; if (!matches) { return; } try { handler = knownFactoryProducts[matches[1]](context).create({ eventBus: config.eventBus, metricsConstants: config.metricsConstants }); handler.initialize(matches[1], reportingController, matches[3], matches[5]); } catch (e) { handler = null; debug.error('MetricsHandlerFactory: Could not create handler for type ' + matches[1] + ' with args ' + matches[3] + ', ' + matches[5] + ' (' + e.message + ')'); } return handler; } function register(key, handler) { knownFactoryProducts[key] = handler; } function unregister(key) { delete knownFactoryProducts[key]; } instance = { create: create, register: register, unregister: unregister }; return instance; } MetricsHandlerFactory.__dashjs_factory_name = 'MetricsHandlerFactory'; exports['default'] = dashjs.FactoryMaker.getSingletonFactory(MetricsHandlerFactory); /* jshint ignore:line */ module.exports = exports['default']; },{"11":11,"12":12,"13":13,"14":14}],11:[function(_dereq_,module,exports){ /** * The copyright in this software is being made available under the BSD License, * included below. This software may be subject to other third party and contributor * rights, including patent rights, and no such rights are granted under this license. * * Copyright (c) 2013, Dash Industry Forum. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * Neither the name of Dash Industry Forum nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSE