@flowplayer/player 3.17.1 → 3.18.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core.js +1 -1
- package/default.js +1 -1
- package/embed.js +2 -2
- package/package.json +1 -3
- package/plugins/ads.js +1 -1
- package/plugins/analytics.js +1 -1
- package/plugins/fas.d.ts +50 -6
- package/plugins/message.d.ts +60 -1
- package/plugins/message.js +1 -1
- package/plugins/ssai.js +1 -1
- package/plugins/health.d.ts +0 -1681
- package/plugins/health.js +0 -1
package/plugins/health.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).flowplayer=t.flowplayer||{},t.flowplayer.health=e())}(this,(function(){"use strict";const t="rebuffer",e="rebuffer:ended",i="insights:ttff",n="insights:time_to_first_frag_loaded",s="insights:watched_interval";var a=Object.freeze({__proto__:null,RECORD:"health:record",REBUFFER:t,REBUFFER_ENDED:e,DISPLAY:"display",TIME_TO_FIRST_FRAME:i,TIME_TO_FIRST_FRAGMENT_LOADED:n,WATCHED_INTERVAL:s});const r="fullscreenenter",o="fullscreenexit",d="loadedmetadata",c="loadeddata",l="progress",h="loadstart",u="pause",_="playing",m="waiting",p="canplay",f="ended",y="seeked",g="seeking",v="content:loadstart",E=[v,"error","src"];function T(t){try{return!!new URL(t)}catch(t){return!1}}function S(t,e){const i=function(){try{return localStorage.getItem("flowplayer/debug")}catch(t){return""}}(),n=(n,...s)=>{try{const a=(null==e?void 0:e.debug)||i;a&&t.match(a)&&console.log(`flowplayer/${t} -- ${n}`,...s)}catch(t){console.warn(t)}};return n.log=n,n}const w=navigator;function R(t){var e,i;const n=null===(e=t.hls)||void 0===e?void 0:e.bandwidthEstimate;return n?1e-6*n:(null===(i=w.connection)||void 0===i?void 0:i.downlink)||-1}function A(t,e){return async function(t,e){try{await fetch(t,{body:e,method:"POST",mode:"no-cors"})}catch(t){}}(t,JSON.stringify({events:e}))}var I;!function(t){t[t.OFF=0]="OFF",t[t.ON=1]="ON",t[t.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(I||(I={}));const W=t=>{switch(t){case!0:return I.ON;case!1:return I.OFF;default:return t}};function O(){try{const t=window.location!==window.parent.location?document.referrer:document.location.href;return"string"==typeof t&&t.slice(0,200)}catch(t){return!1}}const D=[],N="https://ihi.flowplayer.com/v1/health/events";function M(t){if(t.suspended)return;const e=D.slice(0);D.length=0,0!=e.length&&(t.logger.log(`:dispatch events={${e.length}}`),A(function(){try{return"undefined"==typeof window?N:window.__FLOWPLAYER_INSIGHTS_URL?window.__FLOWPLAYER_INSIGHTS_URL:N}catch(t){return N}}(),e))}async function b(t,e,i){const n=await C();D.push(Object.assign(e,n)),t.logger.log(":enqueue",e.event,e),D.length<10&&!i||M(t)}const U=()=>{var t,e;try{const i=window;return null===(e=null===(t=null==i?void 0:i.google)||void 0===t?void 0:t.ima)||void 0===e?void 0:e.VERSION}catch(t){return}},C=async()=>({client_time:Date.now()}),F=(t,e)=>Object.assign(t,{detail:e}),L=(t,{event:e,media_session_id:i,session_id:n,play_range_id:s})=>({event:e,media_session_id:i,session_id:n,play_range_id:s,device_id:t.deviceId(),version:"3.17.1",commit:"a470c80308623312bd4a81d3ff6897ca77b160a0",ima_sdk_version:U(),preload:t.opt("preload"),autoplay:W(t.opt("autoplay")),live:t.opt("live"),dvr:!!t.live_state.dvr,source:t.original_src,downlink_mbs:R(t),page_url:O(),player_id:t.opt("metadata.player_id"),media_id:t.opt("metadata.media_id"),site_id:t.opt("metadata.site_id"),category_id:t.opt("metadata.category_id"),sitegroup_id:t.opt("metadata.sitegroup_id"),token:t.token,plugins:t.plugins.map(t=>t.constructor.name).sort((t,e)=>t.localeCompare(e)),current_time:t.currentTime,external_media_id:t.opt("external_media_id")}),k=t=>({bitrate:null==t?void 0:t.bitrate,resolution:null==t?void 0:t.attrs.RESOLUTION,frame_rate:null==t?void 0:t.attrs["FRAME-RATE"]});function P(t,e,i,n){const s=L(e,t.eventInfo(i)),{before:a,after:r}=n;b(t,((t,e,i)=>Object.assign(t,{state:{before:e,after:i}}))(s,k(a),k(r)))}const x=[1e7]+""+-1e3+-4e3+-8e3+-1e11,B=()=>"undefined"==typeof crypto?"":x.replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16));var H;function G(t){switch(t){case H.MEDIA_PLAYBACK_ABORTED:return"media playback was aborted";case H.MEDIA_ERR_NETWORK:return"a network error occurred";case H.MEDIA_ERR_DECODE:return"unable to decode media content";case H.MEDIA_ERR_SRC_NOT_SUPPORTED:return"unsupported media type";case H.NO_INTERNET:return"no internet connection detected";case H.MIXED_CONTENT:return"cannot load insecure content in a secure context";default:return"an unknown error occurred"}}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.MEDIA_PLAYBACK_ABORTED=1]="MEDIA_PLAYBACK_ABORTED",t[t.MEDIA_ERR_NETWORK=2]="MEDIA_ERR_NETWORK",t[t.MEDIA_ERR_DECODE=3]="MEDIA_ERR_DECODE",t[t.MEDIA_ERR_SRC_NOT_SUPPORTED=4]="MEDIA_ERR_SRC_NOT_SUPPORTED",t[t.MIXED_CONTENT=1001]="MIXED_CONTENT",t[t.NO_INTERNET=1002]="NO_INTERNET"}(H||(H={}));const j=(t,e)=>{let i=null;return(...n)=>{null!==i&&(clearTimeout(i),i=null),i=setTimeout(()=>e(...n),t)}};var K;!function(t){t[t.Starting=0]="Starting",t[t.ConfigFinalized=1]="ConfigFinalized",t[t.TimerStartedWithAdsAutoplay=2]="TimerStartedWithAdsAutoplay",t[t.TimerStartedWithContentAutoplay=3]="TimerStartedWithContentAutoplay",t[t.TimerStartedWithUserGesture=4]="TimerStartedWithUserGesture",t[t.MetricReported=5]="MetricReported"}(K||(K={}));class TimeToFirstFrame{constructor(t=K.Starting,e=!1,i=!1){this.state=t,this.loadedAd=e,this.requiresUserGesture=i}reset(){this.state=K.Starting,this.loadedAd=!1,this.elapsed=void 0}toJSON(){var t;return{ad_was_requested:this.loadedAd,ms_to_first_frame:Math.round((null===(t=this.elapsed)||void 0===t?void 0:t.duration)||-1)}}startTimer(t){this.state==K.ConfigFinalized&&(this.state=t,performance.mark("ttff:start"))}hasStarted(){return[K.TimerStartedWithAdsAutoplay,K.TimerStartedWithContentAutoplay,K.TimerStartedWithUserGesture].includes(this.state)}stopTimer(t){if(this.hasStarted()){performance.mark("ttff:end");const e=this.elapsed=performance.measure("ttff","ttff:start","ttff:end");this.state=K.MetricReported,t(e)}}}function z(t){return Math.round(1e3*t)/1e3}class EWMA{constructor(t){this.tickInterval=t,this.ewma=0,this.startTime=Date.now()}decay(){const t=Date.now()-this.startTime;return Math.pow(2,-t/(4*this.tickInterval))}update(t){const e=this.decay();return this.ewma=e*this.ewma+(1-e)*t,this.ewma}toJSON(){return this.ewma}}class WatchedState{constructor(t){this.player=t,this.marchingInterval=void 0,this.lastWatchedPoint=void 0,this.watchedSum=0,this.lastReportedSum=0,this.ewmaTickWatched=new EWMA(WatchedState.AccuracyMilliseconds)}reset(){this.onNotWatching(),this.watchedSum=0,this.lastReportedSum=0,this.lastWatchedPoint=void 0}onNotWatching(){this.marchingInterval&&(this.updateWatched(),this.marchingInterval=clearInterval(this.marchingInterval))}onWatching(){this.marchingInterval||(this.lastWatchedPoint=this.createWatchedPoint(),this.marchingInterval=setInterval(()=>{this.updateWatched()},WatchedState.AccuracyMilliseconds))}createWatchedPoint(){return{currentTime:this.player.currentTime,paused:this.player.paused}}updateWatched(){const t=this.createWatchedPoint();this.lastWatchedPoint&&this.calculateTimeWatched(this.lastWatchedPoint,t),this.lastWatchedPoint=t}calculateTimeWatched(t,e){const i=e.currentTime-t.currentTime,n=this.ewmaTickWatched.update(i);if(!(i<0)&&!(1e3*i>1.3*WatchedState.AccuracyMilliseconds)&&(this.watchedSum+=i,this.watchedSum!=this.lastReportedSum&&(this.watchedSum>this.lastReportedSum+WatchedState.ReportingIntervalSeconds||this.player.ended))){const t=z(n),e={total_watched_seconds:z(this.watchedSum),tick_watched_seconds:t,batch_watched_seconds:z(this.watchedSum-this.lastReportedSum)};this.lastReportedSum=this.watchedSum,this.player.emit(s,e)}}}WatchedState.ReportingIntervalSeconds=5,WatchedState.AccuracyMilliseconds=160;const q=B();class Health{constructor(t,e){let i;this.session_id=q,this.suspended=!1,this.logger=S("health",e.opts),this.media_session_id=B(),this.play_range_id=B(),this.analyticsLoop=setInterval(()=>M(this),2e3),e.on("reap",()=>clearInterval(this.analyticsLoop)),e.on(_,()=>{i!==this.media_session_id&&(i=this.media_session_id,this.first_playing_event_timestamp=Date.now()),this.play_range_id=B()});let n=Date.now()-1e3;e.on("timeupdate",t=>{if(i!==this.media_session_id)return;const s=Date.now();if(s<n)return;n=Date.now()+5e3;const a=L(e,this.eventInfo(t.type)),r=F(a,{duration:(o=e.duration,Number.isFinite(o)?o:o===1/0?-1:void 0)});var o;this.first_playing_event_timestamp&&(Object.assign(r,{ms_since_first_playing:s-this.first_playing_event_timestamp}),this.first_playing_event_timestamp=void 0),b(this,r)});const s=this;if(e.health={get media_session_id(){return s.media_session_id},set media_session_id(t){s.media_session_id=t},get session_id(){return s.session_id},set session_id(t){s.session_id=t},toggle(t){t?s.resume():s.suspend()}},!Health._UNLOAD_SUBSCRIBED){Health._UNLOAD_SUBSCRIBED=!0;const e=e=>t.instances.forEach(t=>t.emit(e.type));document.addEventListener("visibilitychange",t=>{"hidden"==document.visibilityState&&e(t)}),window.addEventListener("pagehide",e)}}eventInfo(t){return{event:t,media_session_id:this.media_session_id,session_id:this.session_id,play_range_id:this.play_range_id}}suspend(){this.suspended=!0,clearInterval(this.analyticsLoop)}resume(){this.suspended=!1,this.analyticsLoop=setInterval(()=>M(this),2e3)}init(a,S,w){if(O().toString().startsWith("data:"))return this.suspend();!function(i){let n=null;const s=()=>{n=null};i.on(m,(function(e){i.seeking||i.networkState===i.NETWORK_LOADING&&(i.readyState<HTMLMediaElement.HAVE_CURRENT_DATA||i.emit(t))})),i.on(t,t=>{n=t}),i.on(p,t=>{if(n){const a=t.timeStamp-n.timeStamp;if(s(),a<31)return;if(a>3e5)return;i.emit(e,{rebuffer_duration:a/1e3})}}),E.forEach(t=>i.on(t,s))}(w),function(t){let e;[p,v].forEach(i=>{t.on(i,i=>{const s=Date.now();switch(i.type){case v:return e=s;case p:if(e)return t.emit(n,{ms_since_loading_started:s-e}),e=null}})})}(w),function(t){if(void 0===window.performance)return;const e=new TimeToFirstFrame;t.on("ovp:config:finalized",t=>{e.reset(),e.state=K.ConfigFinalized,e.requiresUserGesture=!t.detail.autoplay}),t.on(v,()=>{t.root.classList.contains("ad-hide-first-frame")&&e.startTimer(K.TimerStartedWithAdsAutoplay),t.opt("autoplay")&&e.startTimer(K.TimerStartedWithContentAutoplay)}),t.on("click",()=>{t.opt("autoplay")||e.startTimer(K.TimerStartedWithUserGesture)}),t.on("ad-requested",()=>{e.loadedAd=!0}),t.on("timeupdate",()=>{if(!(t.readyState<HTMLMediaElement.HAVE_CURRENT_DATA))switch(e.state){case K.TimerStartedWithContentAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}}),t.on("ad-started",()=>{switch(e.state){case K.TimerStartedWithAdsAutoplay:case K.TimerStartedWithUserGesture:return e.stopTimer(()=>t.emit(i,e.toJSON()))}})}(w),function(t){const e=new WatchedState(t);t.on(v,()=>e.reset()),t.on(_,()=>e.onWatching()),t.on(u,()=>e.onNotWatching()),t.on(g,()=>e.onNotWatching()),t.on(f,()=>e.updateWatched()),t.on("visibilitychange",()=>e.updateWatched())}(w),w.on("display",t=>{b(this,L(w,this.eventInfo(t.type)),!0)}),w.on("health:record",({detail:t})=>{const e=L(w,this.eventInfo(t.event));Object.assign(e,t.detail||{}),b(this,e)}),[h,d,c,l,m,t].forEach(t=>{w.on(t,t=>{b(this,L(w,this.eventInfo(t.type)))})}),[e,i,n,s].forEach(t=>{w.on(t,t=>{const e=L(w,this.eventInfo(t.type));b(this,Object.assign(e,t.detail))})}),[_,u,g,y,f,r,o,p,v].forEach(t=>{w.on(t,t=>{b(this,L(w,this.eventInfo(t.type)))})}),w.on("volumechange",j(800,t=>{const e=L(w,this.eventInfo(t.type));b(this,F(e,{volume:parseFloat(w.volume.toFixed(2)),muted:w.muted}))})),w.on("resize",j(800,t=>{const e=L(w,this.eventInfo(t.type));b(this,F(e,{height:S.clientHeight,width:S.clientWidth}))})),w.on("hls/failover",t=>{const e=L(w,this.eventInfo(t.type)),i=t.detail,{reason:n,from:s}=i;b(this,F(e,{reason:n,from:s}))}),w.on("qualitychange",({type:t,detail:e})=>{switch(e.kind){case"hls":return P(this,w,t,e)}}),w.addEventListener("error",t=>{const e=L(w,this.eventInfo(t.type)),i=t.error||w.error;if(!i)return b(this,e,!0);const n=i.code,s={error_message:i.message||G(n),error_code:n,error_stack:i.stack||""};return b(this,F(e,s),!0)}),w.on("src",t=>{var e;const i=null===(e=t.detail)||void 0===e?void 0:e.src;if("string"!=typeof i)return;if(!T(w.original_src))return;if(!T(i))return;if(i==w.original_src)return;this.media_session_id=B();b(this,L(w,this.eventInfo(t.type))),M(this)}),w.on("visibilitychange",t=>{b(this,L(w,this.eventInfo(t.type))),M(this)})}}return Health.events=a,Health._UNLOAD_SUBSCRIBED=!1,function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)return e;if(null===document.currentScript)return e;"flowplayer"in t||(t.flowplayer={extensions:[]});const i=t.flowplayer;return"function"==typeof i?(i(e),e):(Array.isArray(i.extensions)||(i.extensions=[]),~i.extensions.indexOf(e)||i.extensions.push(e),e)}(window,Health)}));
|