clappr-stats
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("Clappr")):"function"==typeof define&&define.amd?define(["Clappr"],t):"object"==typeof exports?exports.ClapprStats=t(require("Clappr")):e.ClapprStats=t(e.Clappr)}("undefined"!=typeof self?self:this,function(e){return function(e){function t(e){delete installedChunks[e]}function n(e){var t=document.getElementsByTagName("head")[0],n=document.createElement("script");n.type="text/javascript",n.charset="utf-8",n.src=f.p+""+e+"."+w+".hot-update.js",t.appendChild(n)}function r(e){return e=e||1e4,new Promise(function(t,n){if("undefined"==typeof XMLHttpRequest)return n(new Error("No browser support"));try{var r=new XMLHttpRequest,i=f.p+""+w+".hot-update.json";r.open("GET",i,!0),r.timeout=e,r.send(null)}catch(e){return n(e)}r.onreadystatechange=function(){if(4===r.readyState)if(0===r.status)n(new Error("Manifest request to "+i+" timed out."));else if(404===r.status)t();else if(200!==r.status&&304!==r.status)n(new Error("Manifest request to "+i+" failed."));else{try{var e=JSON.parse(r.responseText)}catch(e){return void n(e)}t(e)}}})}function i(e){var t=C[e];if(!t)return f;var n=function(n){return t.hot.active?(C[n]?C[n].parents.indexOf(e)<0&&C[n].parents.push(e):(T=[e],_=n),t.children.indexOf(n)<0&&t.children.push(n)):(console.warn("[HMR] unexpected require("+n+") from disposed module "+e),T=[]),f(n)};for(var r in f)Object.prototype.hasOwnProperty.call(f,r)&&"e"!==r&&Object.defineProperty(n,r,function(e){return{configurable:!0,enumerable:!0,get:function(){return f[e]},set:function(t){f[e]=t}}}(r));return n.e=function(e){function t(){N--,"prepare"===k&&(j[e]||l(e),0===N&&0===x&&d())}return"ready"===k&&s("prepare"),N++,f.e(e).then(t,function(e){throw t(),e})},n}function o(e){var t={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_disposeHandlers:[],_main:_!==e,active:!0,accept:function(e,n){if(void 0===e)t._selfAccepted=!0;else if("function"==typeof e)t._selfAccepted=e;else if("object"==typeof e)for(var r=0;r<e.length;r++)t._acceptedDependencies[e[r]]=n||function(){};else t._acceptedDependencies[e]=n||function(){}},decline:function(e){if(void 0===e)t._selfDeclined=!0;else if("object"==typeof e)for(var n=0;n<e.length;n++)t._declinedDependencies[e[n]]=!0;else t._declinedDependencies[e]=!0},dispose:function(e){t._disposeHandlers.push(e)},addDisposeHandler:function(e){t._disposeHandlers.push(e)},removeDisposeHandler:function(e){var n=t._disposeHandlers.indexOf(e);n>=0&&t._disposeHandlers.splice(n,1)},check:c,apply:p,status:function(e){if(!e)return k;P.push(e)},addStatusHandler:function(e){P.push(e)},removeStatusHandler:function(e){var t=P.indexOf(e);t>=0&&P.splice(t,1)},data:g[e]};return _=void 0,t}function s(e){k=e;for(var t=0;t<P.length;t++)P[t].call(null,e)}function a(e){return+e+""===e?+e:e}function c(e){if("idle"!==k)throw new Error("check() is only allowed in idle status");return b=e,s("check"),r(E).then(function(e){if(!e)return s("idle"),null;A={},j={},R=e.c,m=e.h,s("prepare");var t=new Promise(function(e,t){y={resolve:e,reject:t}});v={};return l(0),"prepare"===k&&0===N&&0===x&&d(),t})}function u(e,t){if(R[e]&&A[e]){A[e]=!1;for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(v[n]=t[n]);0==--x&&0===N&&d()}}function l(e){R[e]?(A[e]=!0,x++,n(e)):j[e]=!0}function d(){s("ready");var e=y;if(y=null,e)if(b)Promise.resolve().then(function(){return p(b)}).then(function(t){e.resolve(t)},function(t){e.reject(t)});else{var t=[];for(var n in v)Object.prototype.hasOwnProperty.call(v,n)&&t.push(a(n));e.resolve(t)}}function p(n){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];e.indexOf(r)<0&&e.push(r)}}if("ready"!==k)throw new Error("apply() is only allowed in ready status");n=n||{};var i,o,c,u,l,d={},p=[],h={},_=function(){console.warn("[HMR] unexpected require("+b.moduleId+") to disposed module")};for(var y in v)if(Object.prototype.hasOwnProperty.call(v,y)){l=a(y);var b;b=v[y]?function(e){for(var t=[e],n={},i=t.slice().map(function(e){return{chain:[e],id:e}});i.length>0;){var o=i.pop(),s=o.id,a=o.chain;if((u=C[s])&&!u.hot._selfAccepted){if(u.hot._selfDeclined)return{type:"self-declined",chain:a,moduleId:s};if(u.hot._main)return{type:"unaccepted",chain:a,moduleId:s};for(var c=0;c<u.parents.length;c++){var l=u.parents[c],d=C[l];if(d){if(d.hot._declinedDependencies[s])return{type:"declined",chain:a.concat([l]),moduleId:s,parentId:l};t.indexOf(l)>=0||(d.hot._acceptedDependencies[s]?(n[l]||(n[l]=[]),r(n[l],[s])):(delete n[l],t.push(l),i.push({chain:a.concat([l]),id:l})))}}}}return{type:"accepted",moduleId:e,outdatedModules:t,outdatedDependencies:n}}(l):{type:"disposed",moduleId:y};var E=!1,O=!1,P=!1,x="";switch(b.chain&&(x="\nUpdate propagation: "+b.chain.join(" -> ")),b.type){case"self-declined":n.onDeclined&&n.onDeclined(b),n.ignoreDeclined||(E=new Error("Aborted because of self decline: "+b.moduleId+x));break;case"declined":n.onDeclined&&n.onDeclined(b),n.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+b.moduleId+" in "+b.parentId+x));break;case"unaccepted":n.onUnaccepted&&n.onUnaccepted(b),n.ignoreUnaccepted||(E=new Error("Aborted because "+l+" is not accepted"+x));break;case"accepted":n.onAccepted&&n.onAccepted(b),O=!0;break;case"disposed":n.onDisposed&&n.onDisposed(b),P=!0;break;default:throw new Error("Unexception type "+b.type)}if(E)return s("abort"),Promise.reject(E);if(O){h[l]=v[l],r(p,b.outdatedModules);for(l in b.outdatedDependencies)Object.prototype.hasOwnProperty.call(b.outdatedDependencies,l)&&(d[l]||(d[l]=[]),r(d[l],b.outdatedDependencies[l]))}P&&(r(p,[b.moduleId]),h[l]=_)}var N=[];for(o=0;o<p.length;o++)l=p[o],C[l]&&C[l].hot._selfAccepted&&N.push({module:l,errorHandler:C[l].hot._selfAccepted});s("dispose"),Object.keys(R).forEach(function(e){!1===R[e]&&t(e)});for(var j,A=p.slice();A.length>0;)if(l=A.pop(),u=C[l]){var S={},I=u.hot._disposeHandlers;for(c=0;c<I.length;c++)(i=I[c])(S);for(g[l]=S,u.hot.active=!1,delete C[l],delete d[l],c=0;c<u.children.length;c++){var M=C[u.children[c]];M&&((j=M.parents.indexOf(l))>=0&&M.parents.splice(j,1))}}var D,H;for(l in d)if(Object.prototype.hasOwnProperty.call(d,l)&&(u=C[l]))for(H=d[l],c=0;c<H.length;c++)D=H[c],(j=u.children.indexOf(D))>=0&&u.children.splice(j,1);s("apply"),w=m;for(l in h)Object.prototype.hasOwnProperty.call(h,l)&&(e[l]=h[l]);var B=null;for(l in d)if(Object.prototype.hasOwnProperty.call(d,l)&&(u=C[l])){H=d[l];var F=[];for(o=0;o<H.length;o++)if(D=H[o],i=u.hot._acceptedDependencies[D]){if(F.indexOf(i)>=0)continue;F.push(i)}for(o=0;o<F.length;o++){i=F[o];try{i(H)}catch(e){n.onErrored&&n.onErrored({type:"accept-errored",moduleId:l,dependencyId:H[o],error:e}),n.ignoreErrored||B||(B=e)}}}for(o=0;o<N.length;o++){var U=N[o];l=U.module,T=[l];try{f(l)}catch(e){if("function"==typeof U.errorHandler)try{U.errorHandler(e)}catch(t){n.onErrored&&n.onErrored({type:"self-accept-error-handler-errored",moduleId:l,error:t,orginalError:e,originalError:e}),n.ignoreErrored||B||(B=t),B||(B=e)}else n.onErrored&&n.onErrored({type:"self-accept-errored",moduleId:l,error:e}),n.ignoreErrored||B||(B=e)}}return B?(s("fail"),Promise.reject(B)):(s("idle"),new Promise(function(e){e(p)}))}function f(t){if(C[t])return C[t].exports;var n=C[t]={i:t,l:!1,exports:{},hot:o(t),parents:(O=T,T=[],O),children:[]};return e[t].call(n.exports,n,n.exports,i(t)),n.l=!0,n.exports}var h=window.webpackHotUpdateClapprStats;window.webpackHotUpdateClapprStats=function(e,t){u(e,t),h&&h(e,t)};var _,y,v,m,b=!0,w="bf811df379b6e7cd5f8d",E=1e4,g={},T=[],O=[],P=[],k="idle",x=0,N=0,j={},A={},R={},C={};return f.m=e,f.c=C,f.d=function(e,t,n){f.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,"a",t),t},f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f.p="latest/",f.h=function(){return w},i("./src/clappr-stats.js")(f.s="./src/clappr-stats.js")}({"./node_modules/lodash.get/index.js":function(e,t,n){"use strict";(function(t){function n(e,t){return null==e?void 0:e[t]}function r(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}function i(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function o(){this.__data__=ve?ve(null):{}}function s(e){return this.has(e)&&delete this.__data__[e]}function a(e){var t=this.__data__;if(ve){var n=t[e];return n===$?void 0:n}return de.call(t,e)?t[e]:void 0}function c(e){var t=this.__data__;return ve?void 0!==t[e]:de.call(t,e)}function u(e,t){return this.__data__[e]=ve&&void 0===t?$:t,this}function l(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function d(){this.__data__=[]}function p(e){var t=this.__data__,n=g(t,e);return!(n<0)&&(n==t.length-1?t.pop():_e.call(t,n,1),!0)}function f(e){var t=this.__data__,n=g(t,e);return n<0?void 0:t[n][1]}function h(e){return g(this.__data__,e)>-1}function _(e,t){var n=this.__data__,r=g(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}function y(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function v(){this.__data__={hash:new i,map:new(ye||l),string:new i}}function m(e){return x(this,e).delete(e)}function b(e){return x(this,e).get(e)}function w(e){return x(this,e).has(e)}function E(e,t){return x(this,e).set(e,t),this}function g(e,t){for(var n=e.length;n--;)if(M(e[n][0],t))return n;return-1}function T(e,t){t=j(t,e)?[t]:k(t);for(var n=0,r=t.length;null!=e&&n<r;)e=e[C(t[n++])];return n&&n==r?e:void 0}function O(e){return!(!H(e)||R(e))&&(D(e)||r(e)?fe:te).test(S(e))}function P(e){if("string"==typeof e)return e;if(F(e))return be?be.call(e):"";var t=e+"";return"0"==t&&1/e==-Y?"-0":t}function k(e){return Ee(e)?e:we(e)}function x(e,t){var n=e.__data__;return A(t)?n["string"==typeof t?"string":"hash"]:n.map}function N(e,t){var r=n(e,t);return O(r)?r:void 0}function j(e,t){if(Ee(e))return!1;var n=void 0===e?"undefined":G(e);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!F(e))||(J.test(e)||!K.test(e)||null!=t&&e in Object(t))}function A(e){var t=void 0===e?"undefined":G(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}function R(e){return!!ue&&ue in e}function C(e){if("string"==typeof e||F(e))return e;var t=e+"";return"0"==t&&1/e==-Y?"-0":t}function S(e){if(null!=e){try{return le.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function I(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError(q);var n=function n(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;if(o.has(i))return o.get(i);var s=e.apply(this,r);return n.cache=o.set(i,s),s};return n.cache=new(I.Cache||y),n}function M(e,t){return e===t||e!==e&&t!==t}function D(e){var t=H(e)?pe.call(e):"";return t==V||t==W}function H(e){var t=void 0===e?"undefined":G(e);return!!e&&("object"==t||"function"==t)}function B(e){return!!e&&"object"==(void 0===e?"undefined":G(e))}function F(e){return"symbol"==(void 0===e?"undefined":G(e))||B(e)&&pe.call(e)==z}function U(e){return null==e?"":P(e)}function L(e,t,n){var r=null==e?void 0:T(e,t);return void 0===r?n:r}var G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},q="Expected a function",$="__lodash_hash_undefined__",Y=1/0,V="[object Function]",W="[object GeneratorFunction]",z="[object Symbol]",K=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,J=/^\w*$/,X=/^\./,Q=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/[\\^$.*+?()[\]{}|]/g,ee=/\\(\\)?/g,te=/^\[object .+?Constructor\]$/,ne="object"==(void 0===t?"undefined":G(t))&&t&&t.Object===Object&&t,re="object"==("undefined"==typeof self?"undefined":G(self))&&self&&self.Object===Object&&self,ie=ne||re||Function("return this")(),oe=Array.prototype,se=Function.prototype,ae=Object.prototype,ce=ie["__core-js_shared__"],ue=function(){var e=/[^.]+$/.exec(ce&&ce.keys&&ce.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),le=se.toString,de=ae.hasOwnProperty,pe=ae.toString,fe=RegExp("^"+le.call(de).replace(Z,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),he=ie.Symbol,_e=oe.splice,ye=N(ie,"Map"),ve=N(Object,"create"),me=he?he.prototype:void 0,be=me?me.toString:void 0;i.prototype.clear=o,i.prototype.delete=s,i.prototype.get=a,i.prototype.has=c,i.prototype.set=u,l.prototype.clear=d,l.prototype.delete=p,l.prototype.get=f,l.prototype.has=h,l.prototype.set=_,y.prototype.clear=v,y.prototype.delete=m,y.prototype.get=b,y.prototype.has=w,y.prototype.set=E;var we=I(function(e){e=U(e);var t=[];return X.test(e)&&t.push(""),e.replace(Q,function(e,n,r,i){t.push(r?i.replace(ee,"$1"):n||e)}),t});I.Cache=y;var Ee=Array.isArray;e.exports=L}).call(t,n("./node_modules/webpack/buildin/global.js"))},"./node_modules/webpack/buildin/global.js":function(e,t,n){"use strict";var r,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":i(window))&&(r=window)}e.exports=r},"./src/clappr-stats.js":function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var s=i.get;if(void 0!==s)return s.call(r)},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=n("clappr"),u=n("./node_modules/lodash.get/index.js"),l=function(e){return e&&e.__esModule?e:{default:e}}(u),d=function(e){function t(e){r(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n._runEach=(0,l.default)(e,"options.clapprStats.runEach",5e3),n._onReport=(0,l.default)(e,"options.clapprStats.onReport",n._defaultReport),n._uriToMeasureLatency=(0,l.default)(e,"options.clapprStats.uriToMeasureLatency"),n._urisToMeasureBandwidth=(0,l.default)(e,"options.clapprStats.urisToMeasureBandwidth"),n._runBandwidthTestEvery=(0,l.default)(e,"options.clapprStats.runBandwidthTestEvery",10),n._bwMeasureCount=0,n._completion={watch:(0,l.default)(e,"options.clapprStats.onCompletion",[]),calls:[]},n._newMetrics(),n.on(t.REPORT_EVENT,n._onReport),n}return o(t,e),a(t,[{key:"_now",value:function(){return window.performance&&"function"==typeof window.performance.now?window.performance.now():new Date}},{key:"_inc",value:function(e){this._metrics.counters[e]+=1}},{key:"_timerHasStarted",value:function(e){return void 0!==this["_start"+e]}},{key:"_start",value:function(e){this["_start"+e]=this._now()}},{key:"_stop",value:function(e){this._metrics.timers[e]+=this._now()-this["_start"+e]}},{key:"_defaultReport",value:function(e){console.log(e)}},{key:"name",get:function(){return"clappr_stats"}},{key:"_playbackName",get:function(){return this.container.playback.name}},{key:"_playbackType",get:function(){return this.container.getPlaybackType()}}]),a(t,[{key:"bindEvents",value:function(){var e=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 e._inc("error")}),this.listenTo(this.container,c.Events.CONTAINER_FULLSCREEN,function(){return e._inc("fullscreen")}),this.listenTo(this.container,c.Events.CONTAINER_PLAYBACKDVRSTATECHANGED,function(t){t&&e._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:"destroy",value:function(){this.stopReporting(),s(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"destroy",this).call(this)}},{key:"onBitrate",value:function(e){var t=parseInt((0,l.default)(e,"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:t}),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.listenTo(this.container,c.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying),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),this.stopListening(this.container,c.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying)}},{key:"onSeek",value:function(e){this._inc("seek"),this._metrics.extra.watchHistory.push([1e3*e,1e3*e])}},{key:"onTimeUpdate",value:function(e){var t=1e3*e.current,n=1e3*e.total,r=this._metrics.extra.watchHistory.length;if(this._metrics.extra.duration=n,this._metrics.extra.currentTime=t,this._metrics.extra.watchedPercentage=t/n*100,0===r?this._metrics.extra.watchHistory.push([t,t]):this._metrics.extra.watchHistory[r-1][1]=t,this._metrics.extra.bitratesHistory.length>0){var i=this._metrics.extra.bitratesHistory[this._metrics.extra.bitratesHistory.length-1];i.end||(i.time=this._now()-i.start)}this._onCompletion()}},{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(e){this._metrics.extra.buffersize=1e3*e.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:[],bitrateWeightedMean:0,bitrateMostUsed:0,buffersize:0,watchHistory:[],watchedPercentage:0,bufferingPercentage:0,bandwidth:0,duration:0,currentTime:0}}}},{key:"_onCompletion",value:function(){var e=this._metrics.extra.watchedPercentage,n=this._completion.watch,r=-1!=this._completion.calls.indexOf(e);-1==n.indexOf(e)||r||(c.Log.info(this.name+" PERCENTAGE_EVENT: "+e),this._completion.calls.push(e),this.trigger(t.PERCENTAGE_EVENT,e))}},{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._measureBandwidth(),this.trigger(t.REPORT_EVENT,JSON.parse(JSON.stringify(this._metrics)))}},{key:"_fetchFPS",value:function(){var e={html5_video:this._html5FetchFPS,hls:this._html5FetchFPS,dash_shaka_playback:this._html5FetchFPS};e[this._playbackName]&&e[this._playbackName].call(this)}},{key:"_calculateBitrates",value:function(){var e=this._metrics.extra.bitratesHistory.map(function(e){return e.time}).reduce(function(e,t){return e+t},0);this._metrics.extra.bitrateWeightedMean=this._metrics.extra.bitratesHistory.map(function(e){return e.bitrate*e.time}).reduce(function(e,t){return e+t},0)/e,this._metrics.extra.bitratesHistory.length>0&&(this._metrics.extra.bitrateMostUsed=this._metrics.extra.bitratesHistory.slice().sort(function(e,t){return e.time<t.time})[0].bitrate)}},{key:"_calculatePercentages",value:function(){this._metrics.extra.duration>0&&(this._metrics.extra.bufferingPercentage=this._metrics.timers.buffering/this._metrics.extra.duration*100)}},{key:"_html5FetchFPS",value:function(){var e=this.container.playback.el,t=e.webkitDecodedFrameCount||e.mozDecodedFrames||0,n=e.webkitDroppedFrameCount||e.mozParsedFrames-e.mozDecodedFrames||0,r=t-(this._lastDecodedFramesCount||0);this._metrics.counters.decodedFrames=t,this._metrics.counters.droppedFrames=n,this._metrics.counters.fps=r/(this._runEach/1e3),this._lastDecodedFramesCount=t}},{key:"_measureLatency",value:function(){var e=this;if(this._uriToMeasureLatency){var t,n=[],r=function(){t=n[2]-n[1],e._metrics.timers.latency=t};!function t(){if(n.push(e._now()),n.length>2)r();else{var i=new Image;i.onload=t,i.src=e._uriToMeasureLatency+"?"+Math.random()+"="+e._now()}}()}}},{key:"_measureBandwidth",value:function(){var e=this;if(this._urisToMeasureBandwidth&&this._bwMeasureCount%this._runBandwidthTestEvery==0){var t=0,n=function(n){var r=(e._urisToMeasureBandwidth[t-1].end-e._urisToMeasureBandwidth[t-1].start)/1e3,i=8*n.loaded/r;e._metrics.extra.bandwidth=i,e._urisToMeasureBandwidth.forEach(function(e){e.start=0,e.end=0,e.expired=!1,clearTimeout(e.timer)})};!function r(i){if(t>0&&(e._urisToMeasureBandwidth[t-1].end=e._now(),clearTimeout(e._urisToMeasureBandwidth[t-1].timer)),t>=e._urisToMeasureBandwidth.length||t>0&&e._urisToMeasureBandwidth[t-1].expired)n(i);else{var o=new XMLHttpRequest;o.open("GET",e._urisToMeasureBandwidth[t].url,!0),o.responseType="arraybuffer",o.onload=o.onabort=r,e._urisToMeasureBandwidth[t].start=e._now(),e._urisToMeasureBandwidth[t].timer=setTimeout(function(t){e._urisToMeasureBandwidth[t].expired=!0,o.abort()},e._urisToMeasureBandwidth[t].timeout,t),o.send()}t++}()}this._bwMeasureCount++}}]),t}(c.ContainerPlugin);t.default=d,d.REPORT_EVENT="clappr:stats:report",d.PERCENTAGE_EVENT="clappr:stats:percentage",e.exports=t.default},clappr:function(t,n){t.exports=e}})}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("Clappr")):"function"==typeof define&&define.amd?define(["Clappr"],t):"object"==typeof exports?exports.ClapprStats=t(require("Clappr")):e.ClapprStats=t(e.Clappr)}(window,function(n){return function(N){var n=window.webpackHotUpdateClapprStats;window.webpackHotUpdateClapprStats=function(e,t){!function(e,t){if(!H[e]||!p[e])return;for(var n in p[e]=!1,t)Object.prototype.hasOwnProperty.call(t,n)&&(I[n]=t[n]);0==--u&&0===l&&_()}(e,t),n&&n(e,t)};var o,r=!0,A="6f4de0da0fe2448c3667",t=1e4,S={},R=[],i=[];function s(t){var n=F[t];if(!n)return U;function r(e){return n.hot.active?(F[e]?-1===F[e].parents.indexOf(t)&&F[e].parents.push(t):(R=[t],o=e),-1===n.children.indexOf(e)&&n.children.push(e)):(console.warn("[HMR] unexpected require("+e+") from disposed module "+t),R=[]),U(e)}function e(t){return{configurable:!0,enumerable:!0,get:function(){return U[t]},set:function(e){U[t]=e}}}for(var i in U)Object.prototype.hasOwnProperty.call(U,i)&&"e"!==i&&"t"!==i&&Object.defineProperty(r,i,e(i));return r.e=function(e){return"ready"===C&&M("prepare"),l++,U.e(e).then(t,function(e){throw t(),e});function t(){l--,"prepare"===C&&(d[e]||h(e),0===l&&0===u&&_())}},r.t=function(e,t){return 1&t&&(e=r(e)),U.t(e,-2&t)},r}var a=[],C="idle";function M(e){C=e;for(var t=0;t<a.length;t++)a[t].call(null,e)}var c,I,D,u=0,l=0,d={},p={},H={};function B(e){return+e+""===e?+e:e}function f(e){if("idle"!==C)throw new Error("check() is only allowed in idle status");return r=e,M("check"),function(e){return e=e||1e4,new Promise(function(t,n){if("undefined"==typeof XMLHttpRequest)return n(new Error("No browser support"));try{var r=new XMLHttpRequest,i=U.p+""+A+".hot-update.json";r.open("GET",i,!0),r.timeout=e,r.send(null)}catch(e){return n(e)}r.onreadystatechange=function(){if(4===r.readyState)if(0===r.status)n(new Error("Manifest request to "+i+" timed out."));else if(404===r.status)t();else if(200!==r.status&&304!==r.status)n(new Error("Manifest request to "+i+" failed."));else{try{var e=JSON.parse(r.responseText)}catch(e){return void n(e)}t(e)}}})}(t).then(function(e){if(!e)return M("idle"),null;p={},d={},H=e.c,D=e.h,M("prepare");var t=new Promise(function(e,t){c={resolve:e,reject:t}});I={};return h(0),"prepare"===C&&0===l&&0===u&&_(),t})}function h(e){H[e]?(p[e]=!0,u++,function(e){var t=document.createElement("script");t.charset="utf-8",t.src=U.p+""+e+"."+A+".hot-update.js",document.head.appendChild(t)}(e)):d[e]=!0}function _(){M("ready");var t=c;if(c=null,t)if(r)Promise.resolve().then(function(){return y(r)}).then(function(e){t.resolve(e)},function(e){t.reject(e)});else{var e=[];for(var n in I)Object.prototype.hasOwnProperty.call(I,n)&&e.push(B(n));t.resolve(e)}}function y(n){if("ready"!==C)throw new Error("apply() is only allowed in ready status");var e,t,r,l,i;function o(e){for(var t=[e],n={},r=t.map(function(e){return{chain:[e],id:e}});0<r.length;){var i=r.pop(),o=i.id,s=i.chain;if((l=F[o])&&!l.hot._selfAccepted){if(l.hot._selfDeclined)return{type:"self-declined",chain:s,moduleId:o};if(l.hot._main)return{type:"unaccepted",chain:s,moduleId:o};for(var a=0;a<l.parents.length;a++){var c=l.parents[a],u=F[c];if(u){if(u.hot._declinedDependencies[o])return{type:"declined",chain:s.concat([c]),moduleId:o,parentId:c};-1===t.indexOf(c)&&(u.hot._acceptedDependencies[o]?(n[c]||(n[c]=[]),d(n[c],[o])):(delete n[c],t.push(c),r.push({chain:s.concat([c]),id:c})))}}}}return{type:"accepted",moduleId:e,outdatedModules:t,outdatedDependencies:n}}function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];-1===e.indexOf(r)&&e.push(r)}}n=n||{};function s(){console.warn("[HMR] unexpected require("+f.moduleId+") to disposed module")}var a={},c=[],u={};for(var p in I)if(Object.prototype.hasOwnProperty.call(I,p)){var f;i=B(p);var h=!1,_=!1,y=!1,v="";switch((f=I[p]?o(i):{type:"disposed",moduleId:p}).chain&&(v="\nUpdate propagation: "+f.chain.join(" -> ")),f.type){case"self-declined":n.onDeclined&&n.onDeclined(f),n.ignoreDeclined||(h=new Error("Aborted because of self decline: "+f.moduleId+v));break;case"declined":n.onDeclined&&n.onDeclined(f),n.ignoreDeclined||(h=new Error("Aborted because of declined dependency: "+f.moduleId+" in "+f.parentId+v));break;case"unaccepted":n.onUnaccepted&&n.onUnaccepted(f),n.ignoreUnaccepted||(h=new Error("Aborted because "+i+" is not accepted"+v));break;case"accepted":n.onAccepted&&n.onAccepted(f),_=!0;break;case"disposed":n.onDisposed&&n.onDisposed(f),y=!0;break;default:throw new Error("Unexception type "+f.type)}if(h)return M("abort"),Promise.reject(h);if(_)for(i in u[i]=I[i],d(c,f.outdatedModules),f.outdatedDependencies)Object.prototype.hasOwnProperty.call(f.outdatedDependencies,i)&&(a[i]||(a[i]=[]),d(a[i],f.outdatedDependencies[i]));y&&(d(c,[f.moduleId]),u[i]=s)}var m,b=[];for(t=0;t<c.length;t++)i=c[t],F[i]&&F[i].hot._selfAccepted&&u[i]!==s&&b.push({module:i,errorHandler:F[i].hot._selfAccepted});M("dispose"),Object.keys(H).forEach(function(e){!1===H[e]&&function(e){delete installedChunks[e]}(e)});for(var w,g,E=c.slice();0<E.length;)if(i=E.pop(),l=F[i]){var T={},O=l.hot._disposeHandlers;for(r=0;r<O.length;r++)(e=O[r])(T);for(S[i]=T,l.hot.active=!1,delete F[i],delete a[i],r=0;r<l.children.length;r++){var P=F[l.children[r]];P&&0<=(m=P.parents.indexOf(i))&&P.parents.splice(m,1)}}for(i in a)if(Object.prototype.hasOwnProperty.call(a,i)&&(l=F[i]))for(g=a[i],r=0;r<g.length;r++)w=g[r],0<=(m=l.children.indexOf(w))&&l.children.splice(m,1);for(i in M("apply"),A=D,u)Object.prototype.hasOwnProperty.call(u,i)&&(N[i]=u[i]);var k=null;for(i in a)if(Object.prototype.hasOwnProperty.call(a,i)&&(l=F[i])){g=a[i];var x=[];for(t=0;t<g.length;t++)if(w=g[t],e=l.hot._acceptedDependencies[w]){if(-1!==x.indexOf(e))continue;x.push(e)}for(t=0;t<x.length;t++){e=x[t];try{e(g)}catch(e){n.onErrored&&n.onErrored({type:"accept-errored",moduleId:i,dependencyId:g[t],error:e}),n.ignoreErrored||(k=k||e)}}}for(t=0;t<b.length;t++){var j=b[t];i=j.module,R=[i];try{U(i)}catch(t){if("function"==typeof j.errorHandler)try{j.errorHandler(t)}catch(e){n.onErrored&&n.onErrored({type:"self-accept-error-handler-errored",moduleId:i,error:e,originalError:t}),n.ignoreErrored||(k=k||e),k=k||t}else n.onErrored&&n.onErrored({type:"self-accept-errored",moduleId:i,error:t}),n.ignoreErrored||(k=k||t)}}return k?(M("fail"),Promise.reject(k)):(M("idle"),new Promise(function(e){e(c)}))}var F={};function U(e){if(F[e])return F[e].exports;var t=F[e]={i:e,l:!1,exports:{},hot:function(e){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_disposeHandlers:[],_main:o!==e,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var n=0;n<e.length;n++)r._acceptedDependencies[e[n]]=t||function(){};else r._acceptedDependencies[e]=t||function(){}},decline:function(e){if(void 0===e)r._selfDeclined=!0;else if("object"==typeof e)for(var t=0;t<e.length;t++)r._declinedDependencies[e[t]]=!0;else r._declinedDependencies[e]=!0},dispose:function(e){r._disposeHandlers.push(e)},addDisposeHandler:function(e){r._disposeHandlers.push(e)},removeDisposeHandler:function(e){var t=r._disposeHandlers.indexOf(e);0<=t&&r._disposeHandlers.splice(t,1)},check:f,apply:y,status:function(e){if(!e)return C;a.push(e)},addStatusHandler:function(e){a.push(e)},removeStatusHandler:function(e){var t=a.indexOf(e);0<=t&&a.splice(t,1)},data:S[e]};return o=void 0,r}(e),parents:(i=R,R=[],i),children:[]};return N[e].call(t.exports,t,t.exports,s(e)),t.l=!0,t.exports}return U.m=N,U.c=F,U.d=function(e,t,n){U.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},U.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},U.t=function(t,e){if(1&e&&(t=U(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(U.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)U.d(n,r,function(e){return t[e]}.bind(null,r));return n},U.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return U.d(t,"a",t),t},U.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},U.p="latest/",U.h=function(){return A},s("./src/clappr-stats.js")(U.s="./src/clappr-stats.js")}({"./node_modules/lodash.get/index.js":function(W,e,t){"use strict";(function(e){var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t="Expected a function",r="__lodash_hash_undefined__",n=1/0,o="[object Function]",s="[object GeneratorFunction]",a="[object Symbol]",c=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,u=/^\w*$/,l=/^\./,d=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,p=/\\(\\)?/g,f=/^\[object .+?Constructor\]$/,h="object"==(void 0===e?"undefined":i(e))&&e&&e.Object===Object&&e,_="object"==("undefined"==typeof self?"undefined":i(self))&&self&&self.Object===Object&&self,y=h||_||Function("return this")();var v,m=Array.prototype,b=Function.prototype,w=Object.prototype,g=y["__core-js_shared__"],E=(v=/[^.]+$/.exec(g&&g.keys&&g.keys.IE_PROTO||""))?"Symbol(src)_1."+v:"",T=b.toString,O=w.hasOwnProperty,P=w.toString,k=RegExp("^"+T.call(O).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),x=y.Symbol,j=m.splice,N=U(y,"Map"),A=U(Object,"create"),S=x?x.prototype:void 0,R=S?S.toString:void 0;function C(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function M(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function I(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function D(e,t){for(var n,r,i=e.length;i--;)if((n=e[i][0])===(r=t)||n!=n&&r!=r)return i;return-1}function H(e,t){for(var n=0,r=(t=function(e,t){if($(e))return!1;var n=void 0===e?"undefined":i(e);if("number"==n||"symbol"==n||"boolean"==n||null==e||V(e))return!0;return u.test(e)||!c.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:function(e){return $(e)?e:L(e)}(t)).length;null!=e&&n<r;)e=e[G(t[n++])];return n&&n==r?e:void 0}function B(e){return!(!Y(e)||function(e){return!!E&&E in e}(e))&&(function(e){var t=Y(e)?P.call(e):"";return t==o||t==s}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?k:f).test(function(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function F(e,t){var n=e.__data__;return function(e){var t=void 0===e?"undefined":i(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function U(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return B(n)?n:void 0}C.prototype.clear=function(){this.__data__=A?A(null):{}},C.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},C.prototype.get=function(e){var t=this.__data__;if(A){var n=t[e];return n===r?void 0:n}return O.call(t,e)?t[e]:void 0},C.prototype.has=function(e){var t=this.__data__;return A?void 0!==t[e]:O.call(t,e)},C.prototype.set=function(e,t){return this.__data__[e]=A&&void 0===t?r:t,this},M.prototype.clear=function(){this.__data__=[]},M.prototype.delete=function(e){var t=this.__data__,n=D(t,e);return!(n<0)&&(n==t.length-1?t.pop():j.call(t,n,1),!0)},M.prototype.get=function(e){var t=this.__data__,n=D(t,e);return n<0?void 0:t[n][1]},M.prototype.has=function(e){return-1<D(this.__data__,e)},M.prototype.set=function(e,t){var n=this.__data__,r=D(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},I.prototype.clear=function(){this.__data__={hash:new C,map:new(N||M),string:new C}},I.prototype.delete=function(e){return F(this,e).delete(e)},I.prototype.get=function(e){return F(this,e).get(e)},I.prototype.has=function(e){return F(this,e).has(e)},I.prototype.set=function(e,t){return F(this,e).set(e,t),this};var L=q(function(e){e=function(e){return null==e?"":function(e){if("string"==typeof e)return e;if(V(e))return R?R.call(e):"";var t=e+"";return"0"==t&&1/e==-n?"-0":t}(e)}(e);var i=[];return l.test(e)&&i.push(""),e.replace(d,function(e,t,n,r){i.push(n?r.replace(p,"$1"):t||e)}),i});function G(e){if("string"==typeof e||V(e))return e;var t=e+"";return"0"==t&&1/e==-n?"-0":t}function q(i,o){if("function"!=typeof i||o&&"function"!=typeof o)throw new TypeError(t);function s(){var e=arguments,t=o?o.apply(this,e):e[0],n=s.cache;if(n.has(t))return n.get(t);var r=i.apply(this,e);return s.cache=n.set(t,r),r}return s.cache=new(q.Cache||I),s}q.Cache=I;var $=Array.isArray;function Y(e){var t=void 0===e?"undefined":i(e);return!!e&&("object"==t||"function"==t)}function V(e){return"symbol"==(void 0===e?"undefined":i(e))||function(e){return!!e&&"object"==(void 0===e?"undefined":i(e))}(e)&&P.call(e)==a}W.exports=function(e,t,n){var r=null==e?void 0:H(e,t);return void 0===r?n:r}}).call(this,t("./node_modules/webpack/buildin/global.js"))},"./node_modules/webpack/buildin/global.js":function(e,t,n){"use strict";var r,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"===("undefined"==typeof window?"undefined":i(window))&&(r=window)}e.exports=r},"./src/clappr-stats.js":function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e};function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o,s=n("clappr"),a=n("./node_modules/lodash.get/index.js"),c=(o=a)&&o.__esModule?o:{default:o};var u=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(l,s.ContainerPlugin),r(l,[{key:"_now",value:function(){return window.performance&&"function"==typeof window.performance.now?window.performance.now():new Date}},{key:"_inc",value:function(e){this._metrics.counters[e]+=1}},{key:"_timerHasStarted",value:function(e){return void 0!==this["_start"+e]}},{key:"_start",value:function(e){this["_start"+e]=this._now()}},{key:"_stop",value:function(e){this._metrics.timers[e]+=this._now()-this["_start"+e]}},{key:"_defaultReport",value:function(e){console.log(e)}},{key:"name",get:function(){return"clappr_stats"}},{key:"_playbackName",get:function(){return this.container.playback.name}},{key:"_playbackType",get:function(){return this.container.getPlaybackType()}}]),r(l,[{key:"bindEvents",value:function(){var t=this;this.listenTo(this.container,s.Events.CONTAINER_BITRATE,this.onBitrate),this.listenTo(this.container,s.Events.CONTAINER_STOP,this.stopReporting),this.listenTo(this.container,s.Events.CONTAINER_ENDED,this.stopReporting),this.listenToOnce(this.container.playback,s.Events.PLAYBACK_PLAY_INTENT,this.startTimers),this.listenToOnce(this.container,s.Events.CONTAINER_PLAY,this.onFirstPlaying),this.listenTo(this.container,s.Events.CONTAINER_PLAY,this.onPlay),this.listenTo(this.container,s.Events.CONTAINER_PAUSE,this.onPause),this.listenToOnce(this.container,s.Events.CONTAINER_STATE_BUFFERING,this.onBuffering),this.listenTo(this.container,s.Events.CONTAINER_SEEK,this.onSeek),this.listenTo(this.container,s.Events.CONTAINER_ERROR,function(){return t._inc("error")}),this.listenTo(this.container,s.Events.CONTAINER_FULLSCREEN,function(){return t._inc("fullscreen")}),this.listenTo(this.container,s.Events.CONTAINER_PLAYBACKDVRSTATECHANGED,function(e){e&&t._inc("dvrUsage")}),this.listenTo(this.container.playback,s.Events.PLAYBACK_PROGRESS,this.onProgress),this.listenTo(this.container.playback,s.Events.PLAYBACK_TIMEUPDATE,this.onTimeUpdate)}},{key:"destroy",value:function(){this.stopReporting(),function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(r):void 0}(l.prototype.__proto__||Object.getPrototypeOf(l.prototype),"destroy",this).call(this)}},{key:"onBitrate",value:function(e){var t=parseInt((0,c.default)(e,"bitrate",0),10),n=this._now();if(0<this._metrics.extra.bitratesHistory.length){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:t}),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,s.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying),this._start("watch"),this._stop("startup")}},{key:"playAfterPause",value:function(){this.listenTo(this.container,s.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying),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,s.Events.CONTAINER_PLAY,this.playAfterPause),this.stopListening(this.container,s.Events.CONTAINER_TIMEUPDATE,this.onContainerUpdateWhilePlaying)}},{key:"onSeek",value:function(e){this._inc("seek"),this._metrics.extra.watchHistory.push([1e3*e,1e3*e])}},{key:"onTimeUpdate",value:function(e){var t=1e3*e.current,n=1e3*e.total,r=this._metrics.extra.watchHistory.length;if(this._metrics.extra.duration=n,this._metrics.extra.currentTime=t,this._metrics.extra.watchedPercentage=t/n*100,0===r?this._metrics.extra.watchHistory.push([t,t]):this._metrics.extra.watchHistory[r-1][1]=t,0<this._metrics.extra.bitratesHistory.length){var i=this._metrics.extra.bitratesHistory[this._metrics.extra.bitratesHistory.length-1];i.end||(i.time=this._now()-i.start)}this._onCompletion()}},{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,s.Events.CONTAINER_STATE_BUFFERFULL,this.onBufferfull)}},{key:"onBufferfull",value:function(){this._stop("buffering"),this.listenToOnce(this.container,s.Events.CONTAINER_STATE_BUFFERING,this.onBuffering)}},{key:"onProgress",value:function(e){this._metrics.extra.buffersize=1e3*e.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:[],bitrateWeightedMean:0,bitrateMostUsed:0,buffersize:0,watchHistory:[],watchedPercentage:0,bufferingPercentage:0,bandwidth:0,duration:0,currentTime:0}}}},{key:"_onCompletion",value:function(){var e=this._metrics.extra.watchedPercentage,t=this._completion.watch,n=-1!=this._completion.calls.indexOf(e);-1==t.indexOf(e)||n||(s.Log.info(this.name+" PERCENTAGE_EVENT: "+e),this._completion.calls.push(e),this.trigger(l.PERCENTAGE_EVENT,e))}},{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._measureBandwidth(),this.trigger(l.REPORT_EVENT,JSON.parse(JSON.stringify(this._metrics)))}},{key:"_fetchFPS",value:function(){var e={html5_video:this._html5FetchFPS,hls:this._html5FetchFPS,dash_shaka_playback:this._html5FetchFPS};e[this._playbackName]&&e[this._playbackName].call(this)}},{key:"_calculateBitrates",value:function(){var e=this._metrics.extra.bitratesHistory.map(function(e){return e.time}).reduce(function(e,t){return e+t},0);this._metrics.extra.bitrateWeightedMean=this._metrics.extra.bitratesHistory.map(function(e){return e.bitrate*e.time}).reduce(function(e,t){return e+t},0)/e,0<this._metrics.extra.bitratesHistory.length&&(this._metrics.extra.bitrateMostUsed=this._metrics.extra.bitratesHistory.slice().sort(function(e,t){return e.time<t.time})[0].bitrate)}},{key:"_calculatePercentages",value:function(){0<this._metrics.extra.duration&&(this._metrics.extra.bufferingPercentage=this._metrics.timers.buffering/this._metrics.extra.duration*100)}},{key:"_html5FetchFPS",value:function(){var e=this.container.playback.el,t=e.webkitDecodedFrameCount||e.mozDecodedFrames||0,n=e.webkitDroppedFrameCount||e.mozParsedFrames-e.mozDecodedFrames||0,r=t-(this._lastDecodedFramesCount||0);this._metrics.counters.decodedFrames=t,this._metrics.counters.droppedFrames=n,this._metrics.counters.fps=r/(this._runEach/1e3),this._lastDecodedFramesCount=t}},{key:"_measureLatency",value:function(){var n=this;if(this._uriToMeasureLatency){var e,r=[],i=function(){e=r[2]-r[1],n._metrics.timers.latency=e};!function e(){if(r.push(n._now()),2<r.length)i();else{var t=new Image;t.onload=e,t.src=n._uriToMeasureLatency+"?"+Math.random()+"="+n._now()}}()}}},{key:"_measureBandwidth",value:function(){var r=this;if(this._urisToMeasureBandwidth&&this._bwMeasureCount%this._runBandwidthTestEvery==0){var i=0,o=function(e){var t=(r._urisToMeasureBandwidth[i-1].end-r._urisToMeasureBandwidth[i-1].start)/1e3,n=8*e.loaded/t;r._metrics.extra.bandwidth=n,r._urisToMeasureBandwidth.forEach(function(e){e.start=0,e.end=0,e.expired=!1,clearTimeout(e.timer)})};!function e(t){if(0<i&&(r._urisToMeasureBandwidth[i-1].end=r._now(),clearTimeout(r._urisToMeasureBandwidth[i-1].timer)),i>=r._urisToMeasureBandwidth.length||0<i&&r._urisToMeasureBandwidth[i-1].expired)o(t);else{var n=new XMLHttpRequest;n.open("GET",r._urisToMeasureBandwidth[i].url,!0),n.responseType="arraybuffer",n.onload=n.onabort=e,r._urisToMeasureBandwidth[i].start=r._now(),r._urisToMeasureBandwidth[i].timer=setTimeout(function(e){r._urisToMeasureBandwidth[e].expired=!0,n.abort()},r._urisToMeasureBandwidth[i].timeout,i),n.send()}i++}()}this._bwMeasureCount++}}]),l);function l(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(l.__proto__||Object.getPrototypeOf(l)).call(this,e));return t._runEach=(0,c.default)(e,"options.clapprStats.runEach",5e3),t._onReport=(0,c.default)(e,"options.clapprStats.onReport",t._defaultReport),t._uriToMeasureLatency=(0,c.default)(e,"options.clapprStats.uriToMeasureLatency"),t._urisToMeasureBandwidth=(0,c.default)(e,"options.clapprStats.urisToMeasureBandwidth"),t._runBandwidthTestEvery=(0,c.default)(e,"options.clapprStats.runBandwidthTestEvery",10),t._bwMeasureCount=0,t._completion={watch:(0,c.default)(e,"options.clapprStats.onCompletion",[]),calls:[]},t._newMetrics(),t.on(l.REPORT_EVENT,t._onReport),t}(t.default=u).REPORT_EVENT="clappr:stats:report",u.PERCENTAGE_EVENT="clappr:stats:percentage",e.exports=t.default},clappr:function(e,t){e.exports=n}})}); |
@@ -69,5 +69,13 @@ // Karma configuration | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['Chrome'], | ||
browsers: [!process.env.TRAVIS ? 'Chrome' : 'Chrome_travis_ci'], | ||
customLaunchers: { | ||
Chrome_travis_ci: { | ||
base: 'Chrome', | ||
flags: ['--no-sandbox'] | ||
} | ||
}, | ||
// Continuous Integration mode | ||
@@ -74,0 +82,0 @@ // if true, Karma captures browsers, runs the tests and exits |
{ | ||
"name": "clappr-stats", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "clappr playback stats report plugin", | ||
@@ -15,4 +15,4 @@ "main": "dist/clappr-stats.js", | ||
"start": "webpack-dev-server", | ||
"build": "webpack", | ||
"release": "webpack --progress --optimize-minimize --output-filename clappr-stats.min.js" | ||
"build": "webpack --progress", | ||
"release": "MINIMIZE=true webpack --progress" | ||
}, | ||
@@ -45,5 +45,8 @@ "browser": { | ||
"sinon": "^4.4.10", | ||
"webpack": "^3.11.0", | ||
"webpack-dev-server": "^2.11.2" | ||
"uglify-js": "^3.3.12", | ||
"uglifyjs-webpack-plugin": "^2.1.2", | ||
"webpack": "^4.31.0", | ||
"webpack-cli": "^3.3.10", | ||
"webpack-dev-server": "^3.3.1" | ||
} | ||
} |
@@ -13,5 +13,5 @@ import { expect, assert } from 'chai' | ||
describe('Clappr Stats', () => { | ||
describe('Clappr Stats', function() { | ||
before(() => { | ||
before(function() { | ||
this.timeInterval = 100 | ||
@@ -21,7 +21,7 @@ this.clock = sinon.useFakeTimers(Date.now()) | ||
after(() => { | ||
after(function() { | ||
this.clock.restore() | ||
}) | ||
beforeEach(() => { | ||
beforeEach(function() { | ||
this.callback = sinon.spy() | ||
@@ -42,3 +42,3 @@ this.callbackOptions = sinon.spy() | ||
it('call callbackOption when REPORT_EVENT is fired', () => { | ||
it('call callbackOption when REPORT_EVENT is fired', function() { | ||
this.simulator.play() | ||
@@ -50,3 +50,3 @@ this.clock.tick(this.timeInterval) | ||
it('call REPORT_EVENT every time interval', () => { | ||
it('call REPORT_EVENT every time interval', function() { | ||
this.plugin.on(ClapprStats.REPORT_EVENT, this.callback) | ||
@@ -69,3 +69,3 @@ let attempts = randomNumber() | ||
it('call PERCENTAGE_EVENT when PLAYBACK_TIMEUPDATE event is fired', () => { | ||
it('call PERCENTAGE_EVENT when PLAYBACK_TIMEUPDATE event is fired', function() { | ||
this.plugin.on(ClapprStats.PERCENTAGE_EVENT, this.callback) | ||
@@ -80,3 +80,3 @@ | ||
it('call PERCENTAGE_EVENT if video start in middle time and make seek for past', () => { | ||
it('call PERCENTAGE_EVENT if video start in middle time and make seek for past', function() { | ||
this.plugin.on(ClapprStats.PERCENTAGE_EVENT, this.callback) | ||
@@ -91,5 +91,5 @@ | ||
it('call PERCENTAGE_EVENT once with the same state', () => { | ||
it('call PERCENTAGE_EVENT once with the same state', function() { | ||
this.plugin.on(ClapprStats.PERCENTAGE_EVENT, this.callback) | ||
this.simulator.play(4) | ||
@@ -102,28 +102,5 @@ assert.isOk(this.callback.calledOnce) | ||
it('does not update time watch in this events sequence [BUG]', () => { | ||
let counter = 0 | ||
let originalMethod = window.performance.now | ||
window.performance.now = () => { return counter++ } | ||
it('should update counters', function() { | ||
this.plugin.on(ClapprStats.REPORT_EVENT, this.callback) | ||
let container = this.simulator.container | ||
this.simulator.plugin.on(ClapprStats.REPORT_EVENT, this.callback) | ||
container.play() | ||
container.playing() | ||
container.timeUpdated({current: 50}) | ||
container.paused() | ||
container.timeUpdated({current: 80}) | ||
container.pause() | ||
this.clock.tick(this.timeInterval) | ||
let watch = this.callback.getCall(0).args[0].timers.watch | ||
expect(watch).to.be.equal(3) | ||
window.performance.now = originalMethod | ||
}) | ||
it('should update counters', () => { | ||
this.plugin.on(ClapprStats.REPORT_EVENT, this.callback) | ||
this.simulator.play() | ||
@@ -148,5 +125,5 @@ this.simulator.enableFullscreen() | ||
it('should update timer', () => { | ||
it('should update timer', function() { | ||
this.plugin.on(ClapprStats.REPORT_EVENT, this.callback) | ||
this.simulator.play() | ||
@@ -161,2 +138,2 @@ this.clock.tick(this.timeInterval) | ||
}) | ||
}) | ||
}) |
@@ -1,37 +0,85 @@ | ||
var webpack = require('webpack'); | ||
var path = require('path'); | ||
const webpack = require('webpack') | ||
const path = require('path') | ||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
module.exports = { | ||
entry: path.resolve(__dirname, 'src/clappr-stats.js'), | ||
externals: { | ||
clappr: 'Clappr' | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel-loader' | ||
} | ||
const minimize = !!process.env.MINIMIZE | ||
const packageName = 'clappr-stats' | ||
let configurations = [] | ||
const webpackConfig = (config) => { | ||
return { | ||
mode: config.mode || 'none', | ||
devtool: config.devtool || 'source-maps', | ||
entry: path.resolve(__dirname, 'src/clappr-stats.js'), | ||
externals: { | ||
clappr: 'Clappr' | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel-loader' | ||
} | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.js'] | ||
}, | ||
plugins: [ | ||
new webpack.NamedModulesPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
...(config.plugins || []) | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.js'] | ||
}, | ||
plugins: [ | ||
new webpack.NamedModulesPlugin(), | ||
new webpack.HotModuleReplacementPlugin() | ||
], | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
publicPath: 'latest/', | ||
filename: 'clappr-stats.js', | ||
library: 'ClapprStats', | ||
libraryTarget: 'umd', | ||
}, | ||
devServer: { | ||
contentBase: 'public/', | ||
host: '0.0.0.0', | ||
disableHostCheck: true, | ||
hot: true | ||
optimization: config.optimization, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
publicPath: 'latest/', | ||
filename: config.filename, | ||
library: 'ClapprStats', | ||
libraryTarget: 'umd', | ||
}, | ||
devServer: { | ||
contentBase: 'public/', | ||
host: '0.0.0.0', | ||
disableHostCheck: true, | ||
hot: true | ||
} | ||
} | ||
}; | ||
} | ||
configurations.push(webpackConfig({ | ||
filename: `${packageName}.js`, | ||
mode: 'development' | ||
})) | ||
if (minimize) { | ||
console.log('NOTE: Enabled minifying bundle (uglify)') | ||
const loaderOptions = new webpack.LoaderOptionsPlugin({ minimize, debug: !minimize }) | ||
const uglify = new UglifyJsPlugin({ | ||
uglifyOptions: { | ||
warnings: false, | ||
compress: {}, | ||
mangle: true, | ||
sourceMap: true, | ||
comments: false, | ||
output: { comments: false } | ||
}, | ||
}) | ||
configurations.push(webpackConfig({ | ||
filename: `${packageName}.min.js`, | ||
plugins: [ | ||
loaderOptions, | ||
], | ||
optimization: { | ||
minimizer: [ | ||
uglify, | ||
], | ||
}, | ||
mode: 'production' | ||
})) | ||
} | ||
module.exports = configurations |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
17
2667
3
5
220353
19
1