clappr-stats
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,1 +0,1 @@ | ||
!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),l=r(u),f="clappr:stats:report",h=function(t){function e(t){i(this,e),a(Object.getPrototypeOf(e.prototype),"constructor",this).call(this,t),this._runEach=(0,l["default"])(t,"options.clapprStats.runEach",5e3),this._onReport=(0,l["default"])(t,"options.clapprStats.onReport",this._defaultReport),this._uriToMeasureLatency=(0,l["default"])(t,"options.clapprStats.uriToMeasureLatency"),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}},this.on(f,this._onReport)}return o(e,t),s(e,[{key:"_now",value:function(){var t=performance&&"function"==typeof performance.now;return t?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.listenTo(this.container,c.Events.CONTAINER_TIMEUPDATE,function(e){return e.current>0&&t.onContainerUpdateWhilePlaying()}),this.listenToOnce(this.container,c.Events.CONTAINER_STATE_BUFFERING,this.onBuffering),this.listenTo(this.container,c.Events.CONTAINER_SEEK,function(){return t._inc("seek")}),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)}},{key:"onBitrate",value:function(t){var e=parseInt((0,l["default"])(t,"height",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(),height:e}),this._inc("changeLevel")}},{key:"stopReporting",value:function(){this._buildReport(),clearInterval(this._intervalId)}},{key:"startTimers",value:function(){this._intervalId=setInterval(this._buildReport.bind(this),this._runEach),this._start("session"),this._start("startup")}},{key:"onFirstPlaying",value:function(){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._start("pause"),this._inc("pause"),this.listenToOnce(this.container,c.Events.CONTAINER_PLAY,this.playAfterPause)}},{key:"onContainerUpdateWhilePlaying",value:function(){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:"_buildReport",value:function(){this._stop("session"),this._start("session"),this._metrics.extra.playbackName=this._playbackName,this._metrics.extra.playbackType=this._playbackType,this._calculateBitrates(),this._fetchFPS(),this._measureLatency(),this.trigger(f,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.height});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:"_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"]=h,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},l=u[typeof e]&&e&&!e.nodeType?e:void 0,f=u[typeof t]&&t&&!t.nodeType?t:void 0,h=r(l&&f&&"object"==typeof n&&n),p=r(u[typeof self]&&self),_=r(u[typeof window]&&window),y=r(u.undefined&&void 0),v=h||_!==(y&&y.window)&&_||p||y||Function("return this")(),d=Object.prototype,b=d.toString,m=v.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===B?void 0:n}return et.call(e,t)?e[t]:void 0}function l(t){var e=this.__data__;return st?void 0!==e[t]:et.call(e,t)}function f(t,e){var n=this.__data__;return n[t]=st&&void 0===e?B:e,this}function h(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=O(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=O(e,t);return n<0?void 0:e[n][1]}function v(t){return O(this.__data__,t)>-1}function d(t,e){var n=this.__data__,r=O(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||h),string:new s}}function g(t){return w(this,t)["delete"](t)}function T(t){return w(this,t).get(t)}function E(t){return w(this,t).has(t)}function k(t,e){return w(this,t).set(t,e),this}function O(t,e){for(var n=t.length;n--;)if(C(t[n][0],e))return n;return-1}function w(t,e){var n=t.__data__;return P(e)?n["string"==typeof e?"string":"hash"]:n.map}function N(t,e){var n=t[e];return x(n)?n:void 0}function P(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}function A(t){if(null!=t){try{return tt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function R(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(R.Cache||b),n}function C(t,e){return t===e||t!==t&&e!==e}function F(t){var e=S(t)?nt.call(t):"";return e==M||e==D}function S(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function x(t){if(!S(t))return!1;var e=F(t)||o(t)?rt:$;return e.test(A(t))}function j(t){return null==t?"":I(t)}var I=n(2),L="Expected a function",B="__lodash_hash_undefined__",M="[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=N(Q,"Map"),st=N(Object,"create");s.prototype.clear=a,s.prototype["delete"]=c,s.prototype.get=u,s.prototype.has=l,s.prototype.set=f,h.prototype.clear=p,h.prototype["delete"]=_,h.prototype.get=y,h.prototype.has=v,h.prototype.set=d,b.prototype.clear=m,b.prototype["delete"]=g,b.prototype.get=T,b.prototype.has=E,b.prototype.set=k;var at=R(function(t){var e=[];return j(t).replace(U,function(t,n,r,i){e.push(r?i.replace(Y,"$1"):n||t)}),e});R.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 d(t)?t:l(t)}function o(t,e){if(d(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==-f?"-0":e}function a(t){return!!t&&"object"==typeof t}function c(t){return"symbol"==typeof t||a(t)&&v.call(t)==h}function u(t,e,n){var i=null==t?void 0:r(t,e);return void 0===i?n:i}var l=n(3),f=1/0,h="[object Symbol]",p=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_=/^\w*$/,y=Object.prototype,v=y.toString,d=Array.isArray;t.exports=u},function(e,n){e.exports=t}])}); | ||
!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),l=r(u),f="clappr:stats:report",h=function(t){function e(t){i(this,e),a(Object.getPrototypeOf(e.prototype),"constructor",this).call(this,t),this._runEach=(0,l["default"])(t,"options.clapprStats.runEach",5e3),this._onReport=(0,l["default"])(t,"options.clapprStats.onReport",this._defaultReport),this._uriToMeasureLatency=(0,l["default"])(t,"options.clapprStats.uriToMeasureLatency"),this._newMetrics(),this.on(f,this._onReport)}return o(e,t),s(e,[{key:"_now",value:function(){var t=performance&&"function"==typeof performance.now;return t?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,function(){return t._inc("seek")}),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)}},{key:"onBitrate",value:function(t){var e=parseInt((0,l["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:"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}}}},{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._fetchFPS(),this._measureLatency(),this.trigger(f,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:"_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"]=h,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},l=u[typeof e]&&e&&!e.nodeType?e:void 0,f=u[typeof t]&&t&&!t.nodeType?t:void 0,h=r(l&&f&&"object"==typeof n&&n),p=r(u[typeof self]&&self),_=r(u[typeof window]&&window),y=r(u.undefined&&void 0),v=h||_!==(y&&y.window)&&_||p||y||Function("return this")(),d=Object.prototype,b=d.toString,m=v.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 l(t){var e=this.__data__;return st?void 0!==e[t]:et.call(e,t)}function f(t,e){var n=this.__data__;return n[t]=st&&void 0===e?M:e,this}function h(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 v(t){return k(this.__data__,t)>-1}function d(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||h),string:new s}}function g(t){return O(this,t)["delete"](t)}function T(t){return O(this,t).get(t)}function E(t){return O(this,t).has(t)}function w(t,e){return O(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 O(t,e){var n=t.__data__;return P(e)?n["string"==typeof e?"string":"hash"]:n.map}function N(t,e){var n=t[e];return x(n)?n:void 0}function P(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}function A(t){if(null!=t){try{return tt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function R(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(R.Cache||b),n}function C(t,e){return t===e||t!==t&&e!==e}function F(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 x(t){if(!S(t))return!1;var e=F(t)||o(t)?rt:$;return e.test(A(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=N(Q,"Map"),st=N(Object,"create");s.prototype.clear=a,s.prototype["delete"]=c,s.prototype.get=u,s.prototype.has=l,s.prototype.set=f,h.prototype.clear=p,h.prototype["delete"]=_,h.prototype.get=y,h.prototype.has=v,h.prototype.set=d,b.prototype.clear=m,b.prototype["delete"]=g,b.prototype.get=T,b.prototype.has=E,b.prototype.set=w;var at=R(function(t){var e=[];return j(t).replace(U,function(t,n,r,i){e.push(r?i.replace(Y,"$1"):n||t)}),e});R.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 d(t)?t:l(t)}function o(t,e){if(d(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==-f?"-0":e}function a(t){return!!t&&"object"==typeof t}function c(t){return"symbol"==typeof t||a(t)&&v.call(t)==h}function u(t,e,n){var i=null==t?void 0:r(t,e);return void 0===i?n:i}var l=n(3),f=1/0,h="[object Symbol]",p=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_=/^\w*$/,y=Object.prototype,v=y.toString,d=Array.isArray;t.exports=u},function(e,n){e.exports=t}])}); |
56
index.js
@@ -27,17 +27,3 @@ import {ContainerPlugin, Events} from 'clappr' | ||
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 | ||
} | ||
} | ||
this._newMetrics() | ||
this.on(REPORT_EVENT, this._onReport) | ||
@@ -54,3 +40,2 @@ } | ||
this.listenTo(this.container, Events.CONTAINER_PAUSE, this.onPause) | ||
this.listenTo(this.container, Events.CONTAINER_TIMEUPDATE, (e) => e.current > 0 && this.onContainerUpdateWhilePlaying()) | ||
this.listenToOnce(this.container, Events.CONTAINER_STATE_BUFFERING, this.onBuffering) | ||
@@ -64,4 +49,4 @@ this.listenTo(this.container, Events.CONTAINER_SEEK, () => this._inc('seek')) | ||
onBitrate(bitrate) { | ||
var height = parseInt(get(bitrate, 'height', 0), 10) | ||
onBitrate(newBitrate) { | ||
var bitrate = parseInt(get(newBitrate, 'bitrate', 0), 10) | ||
var now = this._now() | ||
@@ -75,3 +60,3 @@ | ||
this._metrics.extra.bitratesHistory.push({start: this._now(), height: height}) | ||
this._metrics.extra.bitratesHistory.push({start: this._now(), bitrate: bitrate}) | ||
@@ -83,3 +68,8 @@ this._inc('changeLevel') | ||
this._buildReport() | ||
clearInterval(this._intervalId) | ||
this._newMetrics() | ||
this.stopListening() | ||
this.bindEvents() | ||
} | ||
@@ -94,2 +84,4 @@ | ||
onFirstPlaying() { | ||
this.listenTo(this.container, Events.CONTAINER_TIMEUPDATE, this.onContainerUpdateWhilePlaying) | ||
this._start('watch') | ||
@@ -109,2 +101,3 @@ this._stop('startup') | ||
onPause() { | ||
this._stop('watch') | ||
this._start('pause') | ||
@@ -116,4 +109,6 @@ this._inc('pause') | ||
onContainerUpdateWhilePlaying() { | ||
this._stop('watch') | ||
this._start('watch') | ||
if (this.container.playback.isPlaying()) { | ||
this._stop('watch') | ||
this._start('watch') | ||
} | ||
} | ||
@@ -136,2 +131,19 @@ | ||
_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: [], bitrateMean: 0, | ||
bitrateVariance: 0, bitrateStandardDeviation: 0, bitrateMostUsed: 0, | ||
buffersize: 0 | ||
} | ||
} | ||
} | ||
_buildReport() { | ||
@@ -164,3 +176,3 @@ this._stop('session') | ||
_calculateBitrates() { | ||
var bitrates = this._metrics.extra.bitratesHistory.map((x) => x.height) | ||
var bitrates = this._metrics.extra.bitratesHistory.map((x) => x.bitrate) | ||
@@ -167,0 +179,0 @@ this._metrics.extra.bitrateMean = bitrates.reduce((a,b) => a + b, 0) / bitrates.length |
{ | ||
"name": "clappr-stats", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "clappr playback stats report plugin", | ||
@@ -11,2 +11,3 @@ "main": "index.js", | ||
"scripts": { | ||
"watch": "node_modules/.bin/webpack -d --watch", | ||
"build": "node_modules/.bin/webpack", | ||
@@ -13,0 +14,0 @@ "start": "node_modules/.bin/webpack-dev-server --host 0.0.0.0 --content-base public/ --hot", |
@@ -56,8 +56,8 @@ [![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) (we're considering height as "bitrate") | ||
bitrateVariance: 0, // bitrate variance (kbps) (we're considering height as "bitrate") | ||
bitrateStandardDeviation: 0, // bitrate standard deviation (kbps) (we're considering height as "bitrate") | ||
bitrateMostUsed: 0, // most used (based on time) bitrate (kbps) (we're considering height as "bitrate") | ||
bitrateMean: 0, // bitrate mean (kbps) | ||
bitrateVariance: 0, // bitrate variance (kbps) | ||
bitrateStandardDeviation: 0, // bitrate standard deviation (kbps) | ||
bitrateMostUsed: 0, // most used (based on time) bitrate (kbps) | ||
} | ||
} | ||
``` |
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
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
27392
232