1import{M as d,a as c,b as l,c as u}from"./fluent-player.js?ver=1.4.0";const o=3e4;class y{constructor(s,a,e={}){var t;this.player=s,this.mediaId=a,this.nonce=(e==null?void 0:e.nonce)||"";const i=e==null?void 0:e.watchTracker;this._ownsWatchTracker=!i,this.watchTracker=i||new d(s,{completionThreshold:100,mediaId:a,segmentUpdateInterVal:5}),this.dirty=!1,this.flushTimer=null,this.flushing=!1,this.lastSentPercentage=0,this.lastSentDuration=0,this._onPlay=this._handlePlay.bind(this),this._onPause=this._handlePause.bind(this),this._onEnded=this._handleEnded.bind(this),this._onVisibilityChange=this._handleVisibilityChange.bind(this),this._onBeforeUnload=this._handleBeforeUnload.bind(this),this._attachListeners(),((t=this.player)==null?void 0:t.paused)===!1&&this._handlePlay()}_attachListeners(){this.player.addEventListener("play",this._onPlay),this.player.addEventListener("pause",this._onPause),this.player.addEventListener("ended",this._onEnded),document.addEventListener("visibilitychange",this._onVisibilityChange),window.addEventListener("beforeunload",this._onBeforeUnload)}_handlePlay(){this.dirty=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}_handlePause(){this.scheduleFlush()}_handleEnded(){this.dirty=!0,Promise.resolve().then(()=>this.flush())}_handleVisibilityChange(){document.visibilityState==="hidden"&&this._finalizeAndFlush(!0)}_handleBeforeUnload(){this._finalizeAndFlush(!0)}_finalizeAndFlush(s){this.dirty&&(this.watchTracker&&(this.watchTracker.endTime=this.watchTracker.getPlayerCurrentTime(),this.watchTracker.addWatchedSegment()),this.flush(s))}scheduleFlush(){this.flushTimer&&clearTimeout(this.flushTimer),this.flushTimer=setTimeout(()=>{this.flush()},o)}flush(s=!1){var r;if(!this.dirty||this.flushing)return;if(!this.mediaId||!this.nonce){!this.nonce&&!this._warnedMissingNonce&&(this._warnedMissingNonce=!0,console.debug("FluentPlayer: analytics beacon skipped â no per-media nonce for media",this.mediaId));return}if(this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.flushing=!0,!((r=this.player)!=null&&r.duration)){this.flushing=!1;return}let a=Math.round(this.watchTracker.getWatchedPercentage()),e=Math.round(this.watchTracker.getTotalWatchedTime());if(a<=this.lastSentPercentage&&e<=this.lastSentDuration){this.flushing=!1,this.dirty=!1;return}const i={nonce:this.nonce,media_id:this.mediaId,duration:e,percentage:a},t=c();if(!t){this.flushing=!1;return}this.dirty=!1;const n=()=>{this.lastSentPercentage=a,this.lastSentDuration=e};if(s&&navigator.sendBeacon){const h=l("fluent_player_track_event",i);navigator.sendBeacon(t,h)?n():(this.dirty=!0,this._keepaliveFlush(t,i,n)),this.flushing=!1}else u("fluent_player_track_event",i).then(h=>{h&&h.success?n():this.dirty=!0}).catch(()=>{this.dirty=!0}).finally(()=>{this.flushing=!1})}_keepaliveFlush(s,a,e){try{const i=l("fluent_player_track_event",a);fetch(s,{method:"POST",body:i,keepalive:!0}).then(t=>t.json()).then(t=>{t&&t.success&&(e(),this.dirty=!1)}).catch(()=>{})}catch{}}destroy(){this.dirty&&this._finalizeAndFlush(!0),this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.player.removeEventListener("play",this._onPlay),this.player.removeEventListener("pause",this._onPause),this.player.removeEventListener("ended",this._onEnded),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("beforeunload",this._onBeforeUnload),this.watchTracker&&(this._ownsWatchTracker&&this.watchTracker.destroy(),this.watchTracker=null)}}export{y as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.