restreamer-ui-v2/public/_player/clappr/dist/clappr-stats.min.js
2022-05-13 19:38:30 +02:00

1 line
16 KiB
JavaScript

!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)}(window,function(n){return o={},i.m=r=[function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t};function i(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)}}var o,s=n(1),a=n(2),u=(o=a)&&o.__esModule?o:{default:o};var c=(function(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)}(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(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:"supportedVersion",get:function(){return{min:"0.4.2"}}},{key:"_playbackName",get:function(){return this.container.playback.name}},{key:"_playbackType",get:function(){return this.container.getPlaybackType()}}]),r(l,[{key:"bindEvents",value:function(){var e=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 e._inc("error")}),this.listenTo(this.container,s.Events.CONTAINER_FULLSCREEN,function(){return e._inc("fullscreen")}),this.listenTo(this.container,s.Events.CONTAINER_PLAYBACKDVRSTATECHANGED,function(t){t&&e._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 t(e,n,r){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,n);if(void 0===i){var o=Object.getPrototypeOf(e);return null===o?void 0:t(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(t){var e=parseInt((0,u.default)(t,"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: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,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(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;if(this._metrics.extra.duration=n,this._metrics.extra.currentTime=e,this._metrics.extra.watchedPercentage=e/n*100,0===r?this._metrics.extra.watchHistory.push([e,e]):this._metrics.extra.watchHistory[r-1][1]=e,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(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:[],bitrateWeightedMean:0,bitrateMostUsed:0,buffersize:0,watchHistory:[],watchedPercentage:0,bufferingPercentage:0,bandwidth:0,duration:0,currentTime:0}}}},{key:"_onCompletion",value:function(){var t=this._metrics.extra.watchedPercentage,e=this._completion.watch,n=-1!=this._completion.calls.indexOf(t);-1==e.indexOf(t)||n||(s.Log.info(this.name+" PERCENTAGE_EVENT: "+t),this._completion.calls.push(t),this.trigger(l.PERCENTAGE_EVENT,t))}},{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 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._metrics.extra.bitratesHistory.map(function(t){return t.time}).reduce(function(t,e){return t+e},0);this._metrics.extra.bitrateWeightedMean=this._metrics.extra.bitratesHistory.map(function(t){return t.bitrate*t.time}).reduce(function(t,e){return t+e},0)/t,0<this._metrics.extra.bitratesHistory.length&&(this._metrics.extra.bitrateMostUsed=this._metrics.extra.bitratesHistory.slice().sort(function(t,e){return t.time<e.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 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 n=this;if(this._uriToMeasureLatency){var t,r=[],i=function(){t=r[2]-r[1],n._metrics.timers.latency=t};!function t(){if(r.push(n._now()),2<r.length)i();else{var e=new Image;e.onload=t,e.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(t){var e=(r._urisToMeasureBandwidth[i-1].end-r._urisToMeasureBandwidth[i-1].start)/1e3,n=8*t.loaded/e;r._metrics.extra.bandwidth=n,r._urisToMeasureBandwidth.forEach(function(t){t.start=0,t.end=0,t.expired=!1,clearTimeout(t.timer)})};!function t(e){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(e);else{var n=new XMLHttpRequest;n.open("GET",r._urisToMeasureBandwidth[i].url,!0),n.responseType="arraybuffer",n.onload=n.onabort=t,r._urisToMeasureBandwidth[i].start=r._now(),r._urisToMeasureBandwidth[i].timer=setTimeout(function(t){r._urisToMeasureBandwidth[t].expired=!0,n.abort()},r._urisToMeasureBandwidth[i].timeout,i),n.send()}i++}()}this._bwMeasureCount++}}]),l);function l(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,l);var e=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(l.__proto__||Object.getPrototypeOf(l)).call(this,t));return e._runEach=(0,u.default)(t,"options.clapprStats.runEach",5e3),e._onReport=(0,u.default)(t,"options.clapprStats.onReport",e._defaultReport),e._uriToMeasureLatency=(0,u.default)(t,"options.clapprStats.uriToMeasureLatency"),e._urisToMeasureBandwidth=(0,u.default)(t,"options.clapprStats.urisToMeasureBandwidth"),e._runBandwidthTestEvery=(0,u.default)(t,"options.clapprStats.runBandwidthTestEvery",10),e._bwMeasureCount=0,e._completion={watch:(0,u.default)(t,"options.clapprStats.onCompletion",[]),calls:[]},e._newMetrics(),e.on(l.REPORT_EVENT,e._onReport),e}(e.default=c).REPORT_EVENT="clappr:stats:report",c.PERCENTAGE_EVENT="clappr:stats:percentage",t.exports=e.default},function(t,e){t.exports=n},function(z,t,e){"use strict";(function(t){var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e="Expected a function",r="__lodash_hash_undefined__",n=1/0,o="[object Function]",s="[object GeneratorFunction]",a="[object Symbol]",u=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,c=/^\w*$/,l=/^\./,h=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,f=/\\(\\)?/g,p=/^\[object .+?Constructor\]$/,_="object"==(void 0===t?"undefined":i(t))&&t&&t.Object===Object&&t,d="object"==("undefined"==typeof self?"undefined":i(self))&&self&&self.Object===Object&&self,y=_||d||Function("return this")();var v,m=Array.prototype,b=Function.prototype,T=Object.prototype,E=y["__core-js_shared__"],g=(v=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+v:"",w=b.toString,P=T.hasOwnProperty,O=T.toString,k=RegExp("^"+w.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),N=y.Symbol,R=m.splice,S=U(y,"Map"),x=U(Object,"create"),C=N?N.prototype:void 0,A=C?C.toString:void 0;function M(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 j(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 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 F(t,e){for(var n,r,i=t.length;i--;)if((n=t[i][0])===(r=e)||n!=n&&r!=r)return i;return-1}function I(t,e){for(var n=0,r=(e=function(t,e){if(V(t))return!1;var n=void 0===t?"undefined":i(t);if("number"==n||"symbol"==n||"boolean"==n||null==t||W(t))return!0;return c.test(t)||!u.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:function(t){return V(t)?t:D(t)}(e)).length;null!=t&&n<r;)t=t[G(e[n++])];return n&&n==r?t:void 0}function L(t){return!(!Y(t)||function(t){return!!g&&g in t}(t))&&(function(t){var e=Y(t)?O.call(t):"";return e==o||e==s}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?k:p).test(function(t){if(null!=t){try{return w.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function H(t,e){var n=t.__data__;return function(t){var e=void 0===t?"undefined":i(t);return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}(e)?n["string"==typeof e?"string":"hash"]:n.map}function U(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return L(n)?n:void 0}M.prototype.clear=function(){this.__data__=x?x(null):{}},M.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},M.prototype.get=function(t){var e=this.__data__;if(x){var n=e[t];return n===r?void 0:n}return P.call(e,t)?e[t]:void 0},M.prototype.has=function(t){var e=this.__data__;return x?void 0!==e[t]:P.call(e,t)},M.prototype.set=function(t,e){return this.__data__[t]=x&&void 0===e?r:e,this},j.prototype.clear=function(){this.__data__=[]},j.prototype.delete=function(t){var e=this.__data__,n=F(e,t);return!(n<0)&&(n==e.length-1?e.pop():R.call(e,n,1),!0)},j.prototype.get=function(t){var e=this.__data__,n=F(e,t);return n<0?void 0:e[n][1]},j.prototype.has=function(t){return-1<F(this.__data__,t)},j.prototype.set=function(t,e){var n=this.__data__,r=F(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},B.prototype.clear=function(){this.__data__={hash:new M,map:new(S||j),string:new M}},B.prototype.delete=function(t){return H(this,t).delete(t)},B.prototype.get=function(t){return H(this,t).get(t)},B.prototype.has=function(t){return H(this,t).has(t)},B.prototype.set=function(t,e){return H(this,t).set(t,e),this};var D=$(function(t){t=function(t){return null==t?"":function(t){if("string"==typeof t)return t;if(W(t))return A?A.call(t):"";var e=t+"";return"0"==e&&1/t==-n?"-0":e}(t)}(t);var i=[];return l.test(t)&&i.push(""),t.replace(h,function(t,e,n,r){i.push(n?r.replace(f,"$1"):e||t)}),i});function G(t){if("string"==typeof t||W(t))return t;var e=t+"";return"0"==e&&1/t==-n?"-0":e}function $(i,o){if("function"!=typeof i||o&&"function"!=typeof o)throw new TypeError(e);function s(){var t=arguments,e=o?o.apply(this,t):t[0],n=s.cache;if(n.has(e))return n.get(e);var r=i.apply(this,t);return s.cache=n.set(e,r),r}return s.cache=new($.Cache||B),s}$.Cache=B;var V=Array.isArray;function Y(t){var e=void 0===t?"undefined":i(t);return!!t&&("object"==e||"function"==e)}function W(t){return"symbol"==(void 0===t?"undefined":i(t))||function(t){return!!t&&"object"==(void 0===t?"undefined":i(t))}(t)&&O.call(t)==a}z.exports=function(t,e,n){var r=null==t?void 0:I(t,e);return void 0===r?n:r}}).call(this,e(3))},function(t,e,n){"use strict";var r,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"===("undefined"==typeof window?"undefined":i(window))&&(r=window)}t.exports=r}],i.c=o,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="latest/",i(i.s=0);function i(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return r[t].call(e.exports,e,e.exports,i),e.l=!0,e.exports}var r,o});