dashjs
Version:
A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.
1,269 lines (1,043 loc) • 127 kB
JavaScript
(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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({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
* @ignore
*/
"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.
*/
/**
* Constants declaration
* @class
* @ignore
* @hideconstructor
*/
'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 Constants = (function () {
_createClass(Constants, [{
key: 'init',
value: function init() {
/**
* @constant {string} STREAM Stream media type. Mainly used to report metrics relative to the full stream
* @memberof Constants#
* @static
*/
this.STREAM = 'stream';
/**
* @constant {string} VIDEO Video media type
* @memberof Constants#
* @static
*/
this.VIDEO = 'video';
/**
* @constant {string} AUDIO Audio media type
* @memberof Constants#
* @static
*/
this.AUDIO = 'audio';
/**
* @constant {string} TEXT Text media type
* @memberof Constants#
* @static
*/
this.TEXT = 'text';
/**
* @constant {string} FRAGMENTED_TEXT Fragmented text media type
* @memberof Constants#
* @static
*/
this.FRAGMENTED_TEXT = 'fragmentedText';
/**
* @constant {string} EMBEDDED_TEXT Embedded text media type
* @memberof Constants#
* @static
*/
this.EMBEDDED_TEXT = 'embeddedText';
/**
* @constant {string} MUXED Muxed (video/audio in the same chunk) media type
* @memberof Constants#
* @static
*/
this.MUXED = 'muxed';
/**
* @constant {string} IMAGE Image media type
* @memberof Constants#
* @static
*/
this.IMAGE = 'image';
/**
* @constant {string} STPP STTP Subtitles format
* @memberof Constants#
* @static
*/
this.STPP = 'stpp';
/**
* @constant {string} TTML STTP Subtitles format
* @memberof Constants#
* @static
*/
this.TTML = 'ttml';
/**
* @constant {string} VTT STTP Subtitles format
* @memberof Constants#
* @static
*/
this.VTT = 'vtt';
/**
* @constant {string} WVTT STTP Subtitles format
* @memberof Constants#
* @static
*/
this.WVTT = 'wvtt';
/**
* @constant {string} ABR_STRATEGY_DYNAMIC Dynamic Adaptive bitrate algorithm
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_DYNAMIC = 'abrDynamic';
/**
* @constant {string} ABR_STRATEGY_BOLA Adaptive bitrate algorithm based on Bola (buffer level)
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_BOLA = 'abrBola';
/**
* @constant {string} ABR_STRATEGY_THROUGHPUT Adaptive bitrate algorithm based on throughput
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_THROUGHPUT = 'abrThroughput';
/**
* @constant {string} MOVING_AVERAGE_SLIDING_WINDOW Moving average sliding window
* @memberof Constants#
* @static
*/
this.MOVING_AVERAGE_SLIDING_WINDOW = 'slidingWindow';
/**
* @constant {string} EWMA Exponential moving average
* @memberof Constants#
* @static
*/
this.MOVING_AVERAGE_EWMA = 'ewma';
/**
* @constant {string} BAD_ARGUMENT_ERROR Invalid Arguments type of error
* @memberof Constants#
* @static
*/
this.BAD_ARGUMENT_ERROR = 'Invalid Arguments';
/**
* @constant {string} MISSING_CONFIG_ERROR Missing ocnfiguration parameters type of error
* @memberof Constants#
* @static
*/
this.MISSING_CONFIG_ERROR = 'Missing config parameter(s)';
this.LOCATION = 'Location';
this.INITIALIZE = 'initialize';
this.TEXT_SHOWING = 'showing';
this.TEXT_HIDDEN = 'hidden';
this.CC1 = 'CC1';
this.CC3 = 'CC3';
this.UTF8 = 'utf-8';
this.SCHEME_ID_URI = 'schemeIdUri';
this.START_TIME = 'starttime';
}
}]);
function Constants() {
_classCallCheck(this, Constants);
this.init();
}
return Constants;
})();
var constants = new Constants();
exports['default'] = constants;
module.exports = exports['default'];
},{}],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
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _utilsDVBErrorsTranslator = _dereq_(18);
var _utilsDVBErrorsTranslator2 = _interopRequireDefault(_utilsDVBErrorsTranslator);
var _MetricsReportingEvents = _dereq_(5);
var _MetricsReportingEvents2 = _interopRequireDefault(_MetricsReportingEvents);
var _controllersMetricsCollectionController = _dereq_(6);
var _controllersMetricsCollectionController2 = _interopRequireDefault(_controllersMetricsCollectionController);
var _metricsMetricsHandlerFactory = _dereq_(11);
var _metricsMetricsHandlerFactory2 = _interopRequireDefault(_metricsMetricsHandlerFactory);
var _reportingReportingFactory = _dereq_(16);
var _reportingReportingFactory2 = _interopRequireDefault(_reportingReportingFactory);
function MetricsReporting() {
var context = this.context;
var instance = undefined,
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,
dashMetrics: config.dashMetrics,
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'];
},{"11":11,"16":16,"18":18,"5":5,"6":6}],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
});
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}],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 _MetricsController = _dereq_(7);
var _MetricsController2 = _interopRequireDefault(_MetricsController);
var _utilsManifestParsing = _dereq_(20);
var _utilsManifestParsing2 = _interopRequireDefault(_utilsManifestParsing);
var _MetricsReportingEvents = _dereq_(5);
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({
adapter: config.adapter,
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'];
},{"20":20,"5":5,"7":7}],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 _RangeController = _dereq_(9);
var _RangeController2 = _interopRequireDefault(_RangeController);
var _ReportingController = _dereq_(10);
var _ReportingController2 = _interopRequireDefault(_ReportingController);
var _MetricsHandlersController = _dereq_(8);
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'];
},{"10":10,"8":8,"9":9}],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 _metricsMetricsHandlerFactory = _dereq_(11);
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'];
},{"11":11}],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 _utilsCustomTimeRanges = _dereq_(27);
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'];
},{"27":27}],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 _reportingReportingFactory = _dereq_(16);
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 = re