Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clappr-stats

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clappr-stats - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

662

clappr-stats.min.js

@@ -1,1 +0,661 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("Clappr")):"function"==typeof define&&define.amd?define(["Clappr"],e):"object"==typeof exports?exports.ClapprStats=e(require("Clappr")):t.ClapprStats=e(t.Clappr)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),a=function(t,e,n){for(var r=!0;r;){var i=t,o=e,s=n;r=!1,null===i&&(i=Function.prototype);var a=Object.getOwnPropertyDescriptor(i,o);if(void 0!==a){if("value"in a)return a.value;var c=a.get;if(void 0===c)return;return c.call(s)}var u=Object.getPrototypeOf(i);if(null===u)return;t=u,e=o,n=s,r=!0,a=u=void 0}},c=n(5),u=n(4),h=r(u),l="clappr:stats:report",f=function(t){function e(t){i(this,e),a(Object.getPrototypeOf(e.prototype),"constructor",this).call(this,t),this._runEach=(0,h["default"])(t,"options.clapprStats.runEach",5e3),this._onReport=(0,h["default"])(t,"options.clapprStats.onReport",this._defaultReport),this._uriToMeasureLatency=(0,h["default"])(t,"options.clapprStats.uriToMeasureLatency"),this._newMetrics(),this.on(l,this._onReport)}return o(e,t),s(e,[{key:"_now",value:function(){var t=window.performance&&"function"==typeof window.performance.now;return t?window.performance.now():new Date}},{key:"_inc",value:function(t){this._metrics.counters[t]+=1}},{key:"_timerHasStarted",value:function(t){return void 0!==this["_start"+t]}},{key:"_start",value:function(t){this["_start"+t]=this._now()}},{key:"_stop",value:function(t){this._metrics.timers[t]+=this._now()-this["_start"+t]}},{key:"_defaultReport",value:function(t){console.log(t)}},{key:"name",get:function(){return"clappr_stats"}},{key:"_playbackName",get:function(){return this.container.playback.name}},{key:"_playbackType",get:function(){return this.container.getPlaybackType()}}]),s(e,[{key:"bindEvents",value:function(){var t=this;this.listenTo(this.container,c.Events.CONTAINER_BITRATE,this.onBitrate),this.listenTo(this.container,c.Events.CONTAINER_STOP,this.stopReporting),this.listenTo(this.container,c.Events.CONTAINER_ENDED,this.stopReporting),this.listenToOnce(this.container.playback,c.Events.PLAYBACK_PLAY_INTENT,this.startTimers),this.listenToOnce(this.container,c.Events.CONTAINER_PLAY,this.onFirstPlaying),this.listenTo(this.container,c.Events.CONTAINER_PLAY,this.onPlay),this.listenTo(this.container,c.Events.CONTAINER_PAUSE,this.onPause),this.listenToOnce(this.container,c.Events.CONTAINER_STATE_BUFFERING,this.onBuffering),this.listenTo(this.container,c.Events.CONTAINER_SEEK,this.onSeek),this.listenTo(this.container,c.Events.CONTAINER_ERROR,function(){return t._inc("error")}),this.listenTo(this.container,c.Events.CONTAINER_FULLSCREEN,function(){return t._inc("fullscreen")}),this.listenTo(this.container,c.Events.CONTAINER_PLAYBACKDVRSTATECHANGED,function(e){e&&t._inc("dvrUsage")}),this.listenTo(this.container.playback,c.Events.PLAYBACK_PROGRESS,this.onProgress),this.listenTo(this.container.playback,c.Events.PLAYBACK_TIMEUPDATE,this.onTimeUpdate)}},{key:"onBitrate",value:function(t){var e=parseInt((0,h["default"])(t,"bitrate",0),10),n=this._now();if(this._metrics.extra.bitratesHistory.length>0){var r=this._metrics.extra.bitratesHistory[this._metrics.extra.bitratesHistory.length-1];r.end=n,r.time=n-r.start}this._metrics.extra.bitratesHistory.push({start:this._now(),bitrate:e}),this._inc("changeLevel")}},{key:"stopReporting",value:function(){this._buildReport(),clearInterval(this._intervalId),this._newMetrics(),this.stopListening(),this.bindEvents()}},{key:"startTimers",value:function(){this._intervalId=setInterval(this._buildReport.bind(this),this._runEach),this._start("session"),this._start("startup")}},{key:"onFirstPlaying",value:function(){this.listenTo(this.container,c.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying),this._start("watch"),this._stop("startup")}},{key:"playAfterPause",value:function(){this._stop("pause"),this._start("watch")}},{key:"onPlay",value:function(){this._inc("play")}},{key:"onPause",value:function(){this._stop("watch"),this._start("pause"),this._inc("pause"),this.listenToOnce(this.container,c.Events.CONTAINER_PLAY,this.playAfterPause)}},{key:"onSeek",value:function(t){this._inc("seek"),this._metrics.extra.watchHistory.push([1e3*t,1e3*t])}},{key:"onTimeUpdate",value:function(t){var e=1e3*t.current,n=1e3*t.total,r=this._metrics.extra.watchHistory.length;this._metrics.extra.duration=n,this._metrics.extra.currentTime=e,0===r?this._metrics.extra.watchHistory.push([e,e]):this._metrics.extra.watchHistory[r-1][1]=e}},{key:"onContainerUpdateWhilePlaying",value:function(){this.container.playback.isPlaying()&&(this._stop("watch"),this._start("watch"))}},{key:"onBuffering",value:function(){this._inc("buffering"),this._start("buffering"),this.listenToOnce(this.container,c.Events.CONTAINER_STATE_BUFFERFULL,this.onBufferfull)}},{key:"onBufferfull",value:function(){this._stop("buffering"),this.listenToOnce(this.container,c.Events.CONTAINER_STATE_BUFFERING,this.onBuffering)}},{key:"onProgress",value:function(t){this._metrics.extra.buffersize=1e3*t.current}},{key:"_newMetrics",value:function(){this._metrics={counters:{play:0,pause:0,error:0,buffering:0,decodedFrames:0,droppedFrames:0,fps:0,changeLevel:0,seek:0,fullscreen:0,dvrUsage:0},timers:{startup:0,watch:0,pause:0,buffering:0,session:0,latency:0},extra:{playbackName:"",playbackType:"",bitratesHistory:[],bitrateMean:0,bitrateVariance:0,bitrateStandardDeviation:0,bitrateMostUsed:0,buffersize:0,watchHistory:[],watchedPercentage:0,bufferingPercentage:0}}}},{key:"_buildReport",value:function(){this._stop("session"),this._start("session"),this._metrics.extra.playbackName=this._playbackName,this._metrics.extra.playbackType=this._playbackType,this._calculateBitrates(),this._calculatePercentages(),this._fetchFPS(),this._measureLatency(),this.trigger(l,JSON.parse(JSON.stringify(this._metrics)))}},{key:"_fetchFPS",value:function(){var t={html5_video:this._html5FetchFPS,hls:this._html5FetchFPS,dash_shaka_playback:this._html5FetchFPS};t[this._playbackName]&&t[this._playbackName].call(this)}},{key:"_calculateBitrates",value:function(){var t=this,e=this._metrics.extra.bitratesHistory.map(function(t){return t.bitrate});this._metrics.extra.bitrateMean=e.reduce(function(t,e){return t+e},0)/e.length,this._metrics.extra.bitrateVariance=e.map(function(e){return Math.pow(e-t._metrics.extra.bitrateMean,2)}).reduce(function(t,e){return t+e},0)/e.length,this._metrics.extra.bitrateStandardDeviation=Math.sqrt(this._metrics.extra.bitrateVariance),this._metrics.extra.bitrateMostUsed=this._metrics.extra.bitratesHistory.sort(function(t,e){return t.time<e.time})[0]}},{key:"_calculatePercentages",value:function(){this._metrics.extra.duration>0&&(this._metrics.extra.watchedPercentage=this._metrics.timers.watch/this._metrics.extra.duration*100,this._metrics.extra.bufferingPercentage=this._metrics.timers.buffering/this._metrics.extra.duration*100)}},{key:"_html5FetchFPS",value:function(){var t=this.container.playback.el,e=t.webkitDecodedFrameCount||t.mozDecodedFrames||0,n=t.webkitDroppedFrameCount||t.mozParsedFrames-t.mozDecodedFrames||0,r=e-(this._lastDecodedFramesCount||0);this._metrics.counters.decodedFrames=e,this._metrics.counters.droppedFrames=n,this._metrics.counters.fps=r/(this._runEach/1e3),this._lastDecodedFramesCount=e}},{key:"_measureLatency",value:function(){var t=this;if(this._uriToMeasureLatency){var e,n=[],r=2,i=function s(){if(n.push(t._now()),n.length>r)o();else{var e=new Image;e.onload=s,e.src=t._uriToMeasureLatency+"?"+Math.random()+"="+t._now()}},o=function(){e=n[2]-n[1],t._metrics.timers.latency=e};i()}}}]),e}(c.ContainerPlugin);e["default"]=f,t.exports=e["default"]},function(t,e){"use strict";t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e,n){(function(t,n){"use strict";function r(t){return t&&t.Object===Object?t:null}function i(t){if("string"==typeof t)return t;if(s(t))return T?T.call(t):"";var e=t+"";return"0"==e&&1/t==-a?"-0":e}function o(t){return!!t&&"object"==typeof t}function s(t){return"symbol"==typeof t||o(t)&&b.call(t)==c}var a=1/0,c="[object Symbol]",u={"function":!0,object:!0},h=u[typeof e]&&e&&!e.nodeType?e:void 0,l=u[typeof t]&&t&&!t.nodeType?t:void 0,f=r(h&&l&&"object"==typeof n&&n),p=r(u[typeof self]&&self),_=r(u[typeof window]&&window),y=r(u.undefined&&void 0),d=f||_!==(y&&y.window)&&_||p||y||Function("return this")(),v=Object.prototype,b=v.toString,m=d.Symbol,g=m?m.prototype:void 0,T=g?g.toString:void 0;t.exports=i}).call(e,n(1)(t),function(){return this}())},function(t,e,n){(function(t,r){"use strict";function i(t){return t&&t.Object===Object?t:null}function o(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(n){}return e}function s(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function a(){this.__data__=st?st(null):{}}function c(t){return this.has(t)&&delete this.__data__[t]}function u(t){var e=this.__data__;if(st){var n=e[t];return n===M?void 0:n}return et.call(e,t)?e[t]:void 0}function h(t){var e=this.__data__;return st?void 0!==e[t]:et.call(e,t)}function l(t,e){var n=this.__data__;return n[t]=st&&void 0===e?M:e,this}function f(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function p(){this.__data__=[]}function _(t){var e=this.__data__,n=k(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():it.call(e,n,1),!0}function y(t){var e=this.__data__,n=k(e,t);return n<0?void 0:e[n][1]}function d(t){return k(this.__data__,t)>-1}function v(t,e){var n=this.__data__,r=k(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}function b(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function m(){this.__data__={hash:new s,map:new(ot||f),string:new s}}function g(t){return P(this,t)["delete"](t)}function T(t){return P(this,t).get(t)}function w(t){return P(this,t).has(t)}function E(t,e){return P(this,t).set(t,e),this}function k(t,e){for(var n=t.length;n--;)if(C(t[n][0],e))return n;return-1}function P(t,e){var n=t.__data__;return x(e)?n["string"==typeof e?"string":"hash"]:n.map}function O(t,e){var n=t[e];return F(n)?n:void 0}function x(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}function N(t){if(null!=t){try{return tt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function A(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(L);var n=function r(){var n=arguments,i=e?e.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=t.apply(this,n);return r.cache=o.set(i,s),s};return n.cache=new(A.Cache||b),n}function C(t,e){return t===e||t!==t&&e!==e}function R(t){var e=S(t)?nt.call(t):"";return e==B||e==D}function S(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function F(t){if(!S(t))return!1;var e=R(t)||o(t)?rt:$;return e.test(N(t))}function j(t){return null==t?"":I(t)}var I=n(2),L="Expected a function",M="__lodash_hash_undefined__",B="[object Function]",D="[object GeneratorFunction]",U=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g,H=/[\\^$.*+?()[\]{}|]/g,Y=/\\(\\)?/g,$=/^\[object .+?Constructor\]$/,z={"function":!0,object:!0},G=z[typeof e]&&e&&!e.nodeType?e:void 0,K=z[typeof t]&&t&&!t.nodeType?t:void 0,V=i(G&&K&&"object"==typeof r&&r),q=i(z[typeof self]&&self),J=i(z[typeof window]&&window),W=i(z.undefined&&void 0),Q=V||J!==(W&&W.window)&&J||q||W||Function("return this")(),X=Array.prototype,Z=Object.prototype,tt=Function.prototype.toString,et=Z.hasOwnProperty,nt=Z.toString,rt=RegExp("^"+tt.call(et).replace(H,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),it=X.splice,ot=O(Q,"Map"),st=O(Object,"create");s.prototype.clear=a,s.prototype["delete"]=c,s.prototype.get=u,s.prototype.has=h,s.prototype.set=l,f.prototype.clear=p,f.prototype["delete"]=_,f.prototype.get=y,f.prototype.has=d,f.prototype.set=v,b.prototype.clear=m,b.prototype["delete"]=g,b.prototype.get=T,b.prototype.has=w,b.prototype.set=E;var at=A(function(t){var e=[];return j(t).replace(U,function(t,n,r,i){e.push(r?i.replace(Y,"$1"):n||t)}),e});A.Cache=b,t.exports=at}).call(e,n(1)(t),function(){return this}())},function(t,e,n){"use strict";function r(t,e){e=o(e,t)?[e]:i(e);for(var n=0,r=e.length;null!=t&&n<r;)t=t[s(e[n++])];return n&&n==r?t:void 0}function i(t){return v(t)?t:h(t)}function o(t,e){if(v(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!c(t))||(_.test(t)||!p.test(t)||null!=e&&t in Object(e))}function s(t){if("string"==typeof t||c(t))return t;var e=t+"";return"0"==e&&1/t==-l?"-0":e}function a(t){return!!t&&"object"==typeof t}function c(t){return"symbol"==typeof t||a(t)&&d.call(t)==f}function u(t,e,n){var i=null==t?void 0:r(t,e);return void 0===i?n:i}var h=n(3),l=1/0,f="[object Symbol]",p=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_=/^\w*$/,y=Object.prototype,d=y.toString,v=Array.isArray;t.exports=u},function(e,n){e.exports=t}])});
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("Clappr"));
else if(typeof define === 'function' && define.amd)
define(["Clappr"], factory);
else if(typeof exports === 'object')
exports["ClapprStats"] = factory(require("Clappr"));
else
root["ClapprStats"] = factory(root["Clappr"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'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;};})();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 _clappr=__webpack_require__(1);var _lodashGet=__webpack_require__(2);var _lodashGet2=_interopRequireDefault(_lodashGet);var REPORT_EVENT='clappr:stats:report';var ClapprStats=(function(_ContainerPlugin){_inherits(ClapprStats,_ContainerPlugin);_createClass(ClapprStats,[{key:'_now',value:function _now(){var hasPerformanceSupport=window.performance && typeof window.performance.now === 'function';return hasPerformanceSupport?window.performance.now():new Date();}},{key:'_inc',value:function _inc(counter){this._metrics.counters[counter] += 1;}},{key:'_timerHasStarted',value:function _timerHasStarted(timer){return this['_start' + timer] !== undefined;}},{key:'_start',value:function _start(timer){this['_start' + timer] = this._now();}},{key:'_stop',value:function _stop(timer){this._metrics.timers[timer] += this._now() - this['_start' + timer];}},{key:'_defaultReport',value:function _defaultReport(metrics){console.log(metrics);} //eslint-disable-line no-console
},{key:'name',get:function get(){return 'clappr_stats';}},{key:'_playbackName',get:function get(){return this.container.playback.name;}},{key:'_playbackType',get:function get(){return this.container.getPlaybackType();}}]);function ClapprStats(container){_classCallCheck(this,ClapprStats);_get(Object.getPrototypeOf(ClapprStats.prototype),'constructor',this).call(this,container);this._runEach = (0,_lodashGet2['default'])(container,'options.clapprStats.runEach',5000);this._onReport = (0,_lodashGet2['default'])(container,'options.clapprStats.onReport',this._defaultReport);this._uriToMeasureLatency = (0,_lodashGet2['default'])(container,'options.clapprStats.uriToMeasureLatency');this._newMetrics();this.on(REPORT_EVENT,this._onReport);}_createClass(ClapprStats,[{key:'bindEvents',value:function bindEvents(){var _this=this;this.listenTo(this.container,_clappr.Events.CONTAINER_BITRATE,this.onBitrate);this.listenTo(this.container,_clappr.Events.CONTAINER_STOP,this.stopReporting);this.listenTo(this.container,_clappr.Events.CONTAINER_ENDED,this.stopReporting);this.listenToOnce(this.container.playback,_clappr.Events.PLAYBACK_PLAY_INTENT,this.startTimers);this.listenToOnce(this.container,_clappr.Events.CONTAINER_PLAY,this.onFirstPlaying);this.listenTo(this.container,_clappr.Events.CONTAINER_PLAY,this.onPlay);this.listenTo(this.container,_clappr.Events.CONTAINER_PAUSE,this.onPause);this.listenToOnce(this.container,_clappr.Events.CONTAINER_STATE_BUFFERING,this.onBuffering);this.listenTo(this.container,_clappr.Events.CONTAINER_SEEK,this.onSeek);this.listenTo(this.container,_clappr.Events.CONTAINER_ERROR,function(){return _this._inc('error');});this.listenTo(this.container,_clappr.Events.CONTAINER_FULLSCREEN,function(){return _this._inc('fullscreen');});this.listenTo(this.container,_clappr.Events.CONTAINER_PLAYBACKDVRSTATECHANGED,function(dvrInUse){dvrInUse && _this._inc('dvrUsage');});this.listenTo(this.container.playback,_clappr.Events.PLAYBACK_PROGRESS,this.onProgress);this.listenTo(this.container.playback,_clappr.Events.PLAYBACK_TIMEUPDATE,this.onTimeUpdate);}},{key:'onBitrate',value:function onBitrate(newBitrate){var bitrate=parseInt((0,_lodashGet2['default'])(newBitrate,'bitrate',0),10);var now=this._now();if(this._metrics.extra.bitratesHistory.length > 0){var beforeLast=this._metrics.extra.bitratesHistory[this._metrics.extra.bitratesHistory.length - 1];beforeLast.end = now;beforeLast.time = now - beforeLast.start;}this._metrics.extra.bitratesHistory.push({start:this._now(),bitrate:bitrate});this._inc('changeLevel');}},{key:'stopReporting',value:function stopReporting(){this._buildReport();clearInterval(this._intervalId);this._newMetrics();this.stopListening();this.bindEvents();}},{key:'startTimers',value:function startTimers(){this._intervalId = setInterval(this._buildReport.bind(this),this._runEach);this._start('session');this._start('startup');}},{key:'onFirstPlaying',value:function onFirstPlaying(){this.listenTo(this.container,_clappr.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying);this._start('watch');this._stop('startup');}},{key:'playAfterPause',value:function playAfterPause(){this._stop('pause');this._start('watch');}},{key:'onPlay',value:function onPlay(){this._inc('play');}},{key:'onPause',value:function onPause(){this._stop('watch');this._start('pause');this._inc('pause');this.listenToOnce(this.container,_clappr.Events.CONTAINER_PLAY,this.playAfterPause);}},{key:'onSeek',value:function onSeek(e){this._inc('seek');this._metrics.extra.watchHistory.push([e * 1000,e * 1000]);}},{key:'onTimeUpdate',value:function onTimeUpdate(e){var current=e.current * 1000,total=e.total * 1000,l=this._metrics.extra.watchHistory.length;this._metrics.extra.duration = total;this._metrics.extra.currentTime = current;if(l === 0){this._metrics.extra.watchHistory.push([current,current]);}else {this._metrics.extra.watchHistory[l - 1][1] = current;}}},{key:'onContainerUpdateWhilePlaying',value:function onContainerUpdateWhilePlaying(){if(this.container.playback.isPlaying()){this._stop('watch');this._start('watch');}}},{key:'onBuffering',value:function onBuffering(){this._inc('buffering');this._start('buffering');this.listenToOnce(this.container,_clappr.Events.CONTAINER_STATE_BUFFERFULL,this.onBufferfull);}},{key:'onBufferfull',value:function onBufferfull(){this._stop('buffering');this.listenToOnce(this.container,_clappr.Events.CONTAINER_STATE_BUFFERING,this.onBuffering);}},{key:'onProgress',value:function onProgress(progress){this._metrics.extra.buffersize = progress.current * 1000;}},{key:'_newMetrics',value:function _newMetrics(){this._metrics = {counters:{play:0,pause:0,error:0,buffering:0,decodedFrames:0,droppedFrames:0,fps:0,changeLevel:0,seek:0,fullscreen:0,dvrUsage:0},timers:{startup:0,watch:0,pause:0,buffering:0,session:0,latency:0},extra:{playbackName:'',playbackType:'',bitratesHistory:[],bitrateWeightedMean:0,bitrateMostUsed:0,buffersize:0,watchHistory:[],watchedPercentage:0,bufferingPercentage:0}};}},{key:'_buildReport',value:function _buildReport(){this._stop('session');this._start('session');this._metrics.extra.playbackName = this._playbackName;this._metrics.extra.playbackType = this._playbackType;this._calculateBitrates();this._calculatePercentages();this._fetchFPS();this._measureLatency();this.trigger(REPORT_EVENT,JSON.parse(JSON.stringify(this._metrics)));}},{key:'_fetchFPS',value:function _fetchFPS(){ // flashls ??? - hls.droppedFramesl hls.stream.bufferLength (seconds)
// hls ??? (use the same?)
var fetchFPS={'html5_video':this._html5FetchFPS,'hls':this._html5FetchFPS,'dash_shaka_playback':this._html5FetchFPS};fetchFPS[this._playbackName] && fetchFPS[this._playbackName].call(this);}},{key:'_calculateBitrates',value:function _calculateBitrates(){var _this2=this;var bitratesWatchedTime=0;this._metrics.extra.bitrateWeightedMean = this._metrics.extra.bitratesHistory.map(function(x){bitratesWatchedTime += x.time || 0;var bitrateTime=x.time || _this2._metrics.timers.watch - bitratesWatchedTime;return x.bitrate * bitrateTime;}).reduce(function(a,b){return a + b;},0) / this._metrics.timers.watch;this._metrics.extra.bitrateMostUsed = this._metrics.extra.bitratesHistory.sort(function(a,b){return a.time < b.time;})[0];}},{key:'_calculatePercentages',value:function _calculatePercentages(){if(this._metrics.extra.duration > 0){this._metrics.extra.watchedPercentage = this._metrics.timers.watch / this._metrics.extra.duration * 100;this._metrics.extra.bufferingPercentage = this._metrics.timers.buffering / this._metrics.extra.duration * 100;}}},{key:'_html5FetchFPS',value:function _html5FetchFPS(){var videoTag=this.container.playback.el;var decodedFrames=videoTag.webkitDecodedFrameCount || videoTag.mozDecodedFrames || 0;var droppedFrames=videoTag.webkitDroppedFrameCount || videoTag.mozParsedFrames - videoTag.mozDecodedFrames || 0;var decodedFramesLastTime=decodedFrames - (this._lastDecodedFramesCount || 0);this._metrics.counters.decodedFrames = decodedFrames;this._metrics.counters.droppedFrames = droppedFrames;this._metrics.counters.fps = decodedFramesLastTime / (this._runEach / 1000);this._lastDecodedFramesCount = decodedFrames;} // originally from https://www.smashingmagazine.com/2011/11/analyzing-network-characteristics-using-javascript-and-the-dom-part-1/
},{key:'_measureLatency',value:function _measureLatency(){var _this3=this;if(this._uriToMeasureLatency){var t=[],n=2,rtt;var ld=function ld(){t.push(_this3._now());if(t.length > n)done();else {var img=new Image();img.onload = ld;img.src = _this3._uriToMeasureLatency + '?' + Math.random() + '=' + _this3._now();}};var done=function done(){rtt = t[2] - t[1];_this3._metrics.timers.latency = rtt;};ld();}}}]);return ClapprStats;})(_clappr.ContainerPlugin);exports['default'] = ClapprStats;module.exports = exports['default'];
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/'use strict';var stringToPath=__webpack_require__(3); /** Used as references for various `Number` constants. */var INFINITY=1 / 0; /** `Object#toString` result references. */var symbolTag='[object Symbol]'; /** Used to match property names within property paths. */var reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/; /** Used for built-in method references. */var objectProto=Object.prototype; /**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/var objectToString=objectProto.toString; /**
* The base implementation of `_.get` without support for default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @returns {*} Returns the resolved value.
*/function baseGet(object,path){path = isKey(path,object)?[path]:castPath(path);var index=0,length=path.length;while(object != null && index < length) {object = object[toKey(path[index++])];}return index && index == length?object:undefined;} /**
* Casts `value` to a path array if it's not one.
*
* @private
* @param {*} value The value to inspect.
* @returns {Array} Returns the cast property path array.
*/function castPath(value){return isArray(value)?value:stringToPath(value);} /**
* Checks if `value` is a property name and not a property path.
*
* @private
* @param {*} value The value to check.
* @param {Object} [object] The object to query keys on.
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
*/function isKey(value,object){if(isArray(value)){return false;}var type=typeof value;if(type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)){return true;}return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);} /**
* Converts `value` to a string key if it's not a string or symbol.
*
* @private
* @param {*} value The value to inspect.
* @returns {string|symbol} Returns the key.
*/function toKey(value){if(typeof value == 'string' || isSymbol(value)){return value;}var result=value + '';return result == '0' && 1 / value == -INFINITY?'-0':result;} /**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @type {Function}
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/var isArray=Array.isArray; /**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/function isObjectLike(value){return !!value && typeof value == 'object';} /**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/function isSymbol(value){return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;} /**
* Gets the value at `path` of `object`. If the resolved value is
* `undefined`, the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @since 3.7.0
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/function get(object,path,defaultValue){var result=object == null?undefined:baseGet(object,path);return result === undefined?defaultValue:result;}module.exports = get;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module, global) {/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/'use strict';var baseToString=__webpack_require__(5); /** Used as the `TypeError` message for "Functions" methods. */var FUNC_ERROR_TEXT='Expected a function'; /** Used to stand-in for `undefined` hash values. */var HASH_UNDEFINED='__lodash_hash_undefined__'; /** `Object#toString` result references. */var funcTag='[object Function]',genTag='[object GeneratorFunction]'; /** Used to match property names within property paths. */var rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; /**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
*/var reRegExpChar=/[\\^$.*+?()[\]{}|]/g; /** Used to match backslashes in property paths. */var reEscapeChar=/\\(\\)?/g; /** Used to detect host constructors (Safari). */var reIsHostCtor=/^\[object .+?Constructor\]$/; /** Used to determine if values are of the language type `Object`. */var objectTypes={'function':true,'object':true}; /** Detect free variable `exports`. */var freeExports=objectTypes[typeof exports] && exports && !exports.nodeType?exports:undefined; /** Detect free variable `module`. */var freeModule=objectTypes[typeof module] && module && !module.nodeType?module:undefined; /** Detect free variable `global` from Node.js. */var freeGlobal=checkGlobal(freeExports && freeModule && typeof global == 'object' && global); /** Detect free variable `self`. */var freeSelf=checkGlobal(objectTypes[typeof self] && self); /** Detect free variable `window`. */var freeWindow=checkGlobal(objectTypes[typeof window] && window); /** Detect `this` as the global object. */var thisGlobal=checkGlobal(objectTypes[typeof undefined] && undefined); /**
* Used as a reference to the global object.
*
* The `this` value is used if it's the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/var root=freeGlobal || freeWindow !== (thisGlobal && thisGlobal.window) && freeWindow || freeSelf || thisGlobal || Function('return this')(); /**
* Checks if `value` is a global object.
*
* @private
* @param {*} value The value to check.
* @returns {null|Object} Returns `value` if it's a global object, else `null`.
*/function checkGlobal(value){return value && value.Object === Object?value:null;} /**
* Checks if `value` is a host object in IE < 9.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
*/function isHostObject(value){ // Many host objects are `Object` objects that can coerce to strings
// despite having improperly defined `toString` methods.
var result=false;if(value != null && typeof value.toString != 'function'){try{result = !!(value + '');}catch(e) {}}return result;} /** Used for built-in method references. */var arrayProto=Array.prototype,objectProto=Object.prototype; /** Used to resolve the decompiled source of functions. */var funcToString=Function.prototype.toString; /** Used to check objects for own properties. */var hasOwnProperty=objectProto.hasOwnProperty; /**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/var objectToString=objectProto.toString; /** Used to detect if a method is native. */var reIsNative=RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar,'\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,'$1.*?') + '$'); /** Built-in value references. */var splice=arrayProto.splice; /* Built-in method references that are verified to be native. */var Map=getNative(root,'Map'),nativeCreate=getNative(Object,'create'); /**
* Creates a hash object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/function Hash(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index < length) {var entry=entries[index];this.set(entry[0],entry[1]);}} /**
* Removes all key-value entries from the hash.
*
* @private
* @name clear
* @memberOf Hash
*/function hashClear(){this.__data__ = nativeCreate?nativeCreate(null):{};} /**
* Removes `key` and its value from the hash.
*
* @private
* @name delete
* @memberOf Hash
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/function hashDelete(key){return this.has(key) && delete this.__data__[key];} /**
* Gets the hash value for `key`.
*
* @private
* @name get
* @memberOf Hash
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/function hashGet(key){var data=this.__data__;if(nativeCreate){var result=data[key];return result === HASH_UNDEFINED?undefined:result;}return hasOwnProperty.call(data,key)?data[key]:undefined;} /**
* Checks if a hash value for `key` exists.
*
* @private
* @name has
* @memberOf Hash
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/function hashHas(key){var data=this.__data__;return nativeCreate?data[key] !== undefined:hasOwnProperty.call(data,key);} /**
* Sets the hash `key` to `value`.
*
* @private
* @name set
* @memberOf Hash
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the hash instance.
*/function hashSet(key,value){var data=this.__data__;data[key] = nativeCreate && value === undefined?HASH_UNDEFINED:value;return this;} // Add methods to `Hash`.
Hash.prototype.clear = hashClear;Hash.prototype['delete'] = hashDelete;Hash.prototype.get = hashGet;Hash.prototype.has = hashHas;Hash.prototype.set = hashSet; /**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/function ListCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index < length) {var entry=entries[index];this.set(entry[0],entry[1]);}} /**
* Removes all key-value entries from the list cache.
*
* @private
* @name clear
* @memberOf ListCache
*/function listCacheClear(){this.__data__ = [];} /**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/function listCacheDelete(key){var data=this.__data__,index=assocIndexOf(data,key);if(index < 0){return false;}var lastIndex=data.length - 1;if(index == lastIndex){data.pop();}else {splice.call(data,index,1);}return true;} /**
* Gets the list cache value for `key`.
*
* @private
* @name get
* @memberOf ListCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/function listCacheGet(key){var data=this.__data__,index=assocIndexOf(data,key);return index < 0?undefined:data[index][1];} /**
* Checks if a list cache value for `key` exists.
*
* @private
* @name has
* @memberOf ListCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/function listCacheHas(key){return assocIndexOf(this.__data__,key) > -1;} /**
* Sets the list cache `key` to `value`.
*
* @private
* @name set
* @memberOf ListCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the list cache instance.
*/function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index < 0){data.push([key,value]);}else {data[index][1] = value;}return this;} // Add methods to `ListCache`.
ListCache.prototype.clear = listCacheClear;ListCache.prototype['delete'] = listCacheDelete;ListCache.prototype.get = listCacheGet;ListCache.prototype.has = listCacheHas;ListCache.prototype.set = listCacheSet; /**
* Creates a map cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/function MapCache(entries){var index=-1,length=entries?entries.length:0;this.clear();while(++index < length) {var entry=entries[index];this.set(entry[0],entry[1]);}} /**
* Removes all key-value entries from the map.
*
* @private
* @name clear
* @memberOf MapCache
*/function mapCacheClear(){this.__data__ = {'hash':new Hash(),'map':new (Map || ListCache)(),'string':new Hash()};} /**
* Removes `key` and its value from the map.
*
* @private
* @name delete
* @memberOf MapCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/function mapCacheDelete(key){return getMapData(this,key)['delete'](key);} /**
* Gets the map value for `key`.
*
* @private
* @name get
* @memberOf MapCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/function mapCacheGet(key){return getMapData(this,key).get(key);} /**
* Checks if a map value for `key` exists.
*
* @private
* @name has
* @memberOf MapCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/function mapCacheHas(key){return getMapData(this,key).has(key);} /**
* Sets the map `key` to `value`.
*
* @private
* @name set
* @memberOf MapCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the map cache instance.
*/function mapCacheSet(key,value){getMapData(this,key).set(key,value);return this;} // Add methods to `MapCache`.
MapCache.prototype.clear = mapCacheClear;MapCache.prototype['delete'] = mapCacheDelete;MapCache.prototype.get = mapCacheGet;MapCache.prototype.has = mapCacheHas;MapCache.prototype.set = mapCacheSet; /**
* Gets the index at which the `key` is found in `array` of key-value pairs.
*
* @private
* @param {Array} array The array to search.
* @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
*/function assocIndexOf(array,key){var length=array.length;while(length--) {if(eq(array[length][0],key)){return length;}}return -1;} /**
* Gets the data for `map`.
*
* @private
* @param {Object} map The map to query.
* @param {string} key The reference key.
* @returns {*} Returns the map data.
*/function getMapData(map,key){var data=map.__data__;return isKeyable(key)?data[typeof key == 'string'?'string':'hash']:data.map;} /**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/function getNative(object,key){var value=object[key];return isNative(value)?value:undefined;} /**
* Checks if `value` is suitable for use as unique object key.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
*/function isKeyable(value){var type=typeof value;return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean'?value !== '__proto__':value === null;} /**
* Converts `string` to a property path array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the property path array.
*/var stringToPath=memoize(function(string){var result=[];toString(string).replace(rePropName,function(match,number,quote,string){result.push(quote?string.replace(reEscapeChar,'$1'):number || match);});return result;}); /**
* Converts `func` to its source code.
*
* @private
* @param {Function} func The function to process.
* @returns {string} Returns the source code.
*/function toSource(func){if(func != null){try{return funcToString.call(func);}catch(e) {}try{return func + '';}catch(e) {}}return '';} /**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided, it determines the cache key for storing the result based on the
* arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is used as the map cache key. The `func`
* is invoked with the `this` binding of the memoized function.
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
* constructor with one whose instances implement the
* [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
* method interface of `delete`, `get`, `has`, and `set`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] The function to resolve the cache key.
* @returns {Function} Returns the new memoized function.
* @example
*
* var object = { 'a': 1, 'b': 2 };
* var other = { 'c': 3, 'd': 4 };
*
* var values = _.memoize(_.values);
* values(object);
* // => [1, 2]
*
* values(other);
* // => [3, 4]
*
* object.a = 2;
* values(object);
* // => [1, 2]
*
* // Modify the result cache.
* values.cache.set(object, ['a', 'b']);
* values(object);
* // => ['a', 'b']
*
* // Replace `_.memoize.Cache`.
* _.memoize.Cache = WeakMap;
*/function memoize(func,resolver){if(typeof func != 'function' || resolver && typeof resolver != 'function'){throw new TypeError(FUNC_ERROR_TEXT);}var memoized=function memoized(){var args=arguments,key=resolver?resolver.apply(this,args):args[0],cache=memoized.cache;if(cache.has(key)){return cache.get(key);}var result=func.apply(this,args);memoized.cache = cache.set(key,result);return result;};memoized.cache = new (memoize.Cache || MapCache)();return memoized;} // Assign cache to `_.memoize`.
memoize.Cache = MapCache; /**
* Performs a
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'user': 'fred' };
* var other = { 'user': 'fred' };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/function eq(value,other){return value === other || value !== value && other !== other;} /**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/function isFunction(value){ // The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array and weak map constructors,
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var tag=isObject(value)?objectToString.call(value):'';return tag == funcTag || tag == genTag;} /**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/function isObject(value){var type=typeof value;return !!value && (type == 'object' || type == 'function');} /**
* Checks if `value` is a native function.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function,
* else `false`.
* @example
*
* _.isNative(Array.prototype.push);
* // => true
*
* _.isNative(_);
* // => false
*/function isNative(value){if(!isObject(value)){return false;}var pattern=isFunction(value) || isHostObject(value)?reIsNative:reIsHostCtor;return pattern.test(toSource(value));} /**
* Converts `value` to a string. An empty string is returned for `null`
* and `undefined` values. The sign of `-0` is preserved.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {string} Returns the string.
* @example
*
* _.toString(null);
* // => ''
*
* _.toString(-0);
* // => '-0'
*
* _.toString([1, 2, 3]);
* // => '1,2,3'
*/function toString(value){return value == null?'':baseToString(value);}module.exports = stringToPath;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)(module), (function() { return this; }())))
/***/ },
/* 4 */
/***/ function(module, exports) {
"use strict";module.exports = function(module){if(!module.webpackPolyfill){module.deprecate = function(){};module.paths = []; // module.parent = undefined by default
module.children = [];module.webpackPolyfill = 1;}return module;};
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module, global) {/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/ /** Used as references for various `Number` constants. */'use strict';var INFINITY=1 / 0; /** `Object#toString` result references. */var symbolTag='[object Symbol]'; /** Used to determine if values are of the language type `Object`. */var objectTypes={'function':true,'object':true}; /** Detect free variable `exports`. */var freeExports=objectTypes[typeof exports] && exports && !exports.nodeType?exports:undefined; /** Detect free variable `module`. */var freeModule=objectTypes[typeof module] && module && !module.nodeType?module:undefined; /** Detect free variable `global` from Node.js. */var freeGlobal=checkGlobal(freeExports && freeModule && typeof global == 'object' && global); /** Detect free variable `self`. */var freeSelf=checkGlobal(objectTypes[typeof self] && self); /** Detect free variable `window`. */var freeWindow=checkGlobal(objectTypes[typeof window] && window); /** Detect `this` as the global object. */var thisGlobal=checkGlobal(objectTypes[typeof undefined] && undefined); /**
* Used as a reference to the global object.
*
* The `this` value is used if it's the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/var root=freeGlobal || freeWindow !== (thisGlobal && thisGlobal.window) && freeWindow || freeSelf || thisGlobal || Function('return this')(); /**
* Checks if `value` is a global object.
*
* @private
* @param {*} value The value to check.
* @returns {null|Object} Returns `value` if it's a global object, else `null`.
*/function checkGlobal(value){return value && value.Object === Object?value:null;} /** Used for built-in method references. */var objectProto=Object.prototype; /**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/var objectToString=objectProto.toString; /** Built-in value references. */var Symbol=root.Symbol; /** Used to convert symbols to primitives and strings. */var symbolProto=Symbol?Symbol.prototype:undefined,symbolToString=symbolProto?symbolProto.toString:undefined; /**
* The base implementation of `_.toString` which doesn't convert nullish
* values to empty strings.
*
* @private
* @param {*} value The value to process.
* @returns {string} Returns the string.
*/function baseToString(value){ // Exit early for strings to avoid a performance hit in some environments.
if(typeof value == 'string'){return value;}if(isSymbol(value)){return symbolToString?symbolToString.call(value):'';}var result=value + '';return result == '0' && 1 / value == -INFINITY?'-0':result;} /**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/function isObjectLike(value){return !!value && typeof value == 'object';} /**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/function isSymbol(value){return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;}module.exports = baseToString;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)(module), (function() { return this; }())))
/***/ }
/******/ ])
});
;

24

index.js

@@ -70,3 +70,3 @@ import {ContainerPlugin, Events} from 'clappr'

this.stopListening()
this.bindEvents()
this.bindEvents()
}

@@ -155,5 +155,5 @@

extra: {
playbackName: '', playbackType: '', bitratesHistory: [], bitrateMean: 0,
bitrateVariance: 0, bitrateStandardDeviation: 0, bitrateMostUsed: 0,
buffersize: 0, watchHistory: [], watchedPercentage: 0, bufferingPercentage: 0
playbackName: '', playbackType: '', bitratesHistory: [], bitrateWeightedMean: 0,
bitrateMostUsed: 0, buffersize: 0, watchHistory: [], watchedPercentage: 0,
bufferingPercentage: 0
}

@@ -169,3 +169,3 @@ }

this._metrics.extra.playbackType = this._playbackType
this._calculateBitrates()

@@ -192,11 +192,9 @@ this._calculatePercentages()

_calculateBitrates() {
var bitrates = this._metrics.extra.bitratesHistory.map((x) => x.bitrate)
var bitratesWatchedTime = 0
this._metrics.extra.bitrateWeightedMean = this._metrics.extra.bitratesHistory.map((x) => {
bitratesWatchedTime += x.time || 0
var bitrateTime = x.time || (this._metrics.timers.watch - bitratesWatchedTime)
return x.bitrate * bitrateTime
}).reduce((a,b) => a + b, 0) / this._metrics.timers.watch
this._metrics.extra.bitrateMean = bitrates.reduce((a,b) => a + b, 0) / bitrates.length
this._metrics.extra.bitrateVariance = bitrates.map((n) => {
return Math.pow(n - this._metrics.extra.bitrateMean, 2)
}).reduce((a,b) => a + b, 0) / bitrates.length
this._metrics.extra.bitrateStandardDeviation = Math.sqrt(this._metrics.extra.bitrateVariance)
this._metrics.extra.bitrateMostUsed = this._metrics.extra.bitratesHistory.sort((a,b) => a.time < b.time)[0]

@@ -203,0 +201,0 @@ }

{
"name": "clappr-stats",
"version": "0.0.8",
"version": "0.0.9",
"description": "clappr playback stats report plugin",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -58,5 +58,3 @@ [![npm version](https://badge.fury.io/js/clappr-stats.svg)](https://badge.fury.io/js/clappr-stats)

bitratesHistory: [], // the bitrates changes history
bitrateMean: 0, // bitrate mean (kbps)
bitrateVariance: 0, // bitrate variance (kbps)
bitrateStandardDeviation: 0, // bitrate standard deviation (kbps)
bitrateWeightedMean: 0, // bitrate weighted mean (kbps)
bitrateMostUsed: 0, // most used (based on time) bitrate (kbps)

@@ -63,0 +61,0 @@ watchHistory: [], // an array of an array of watched range time ex: [0, 2200]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc