@newrelic/video-core 4.1.0 → 4.1.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/README.md +3 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.LICENSE.txt +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.LICENSE.txt +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/umd/nrvideo.min.js +1 -1
- package/dist/umd/nrvideo.min.js.LICENSE.txt +1 -1
- package/dist/umd/nrvideo.min.js.map +1 -1
- package/package.json +1 -1
- package/src/harvestScheduler.js +18 -3
- package/src/videoConfiguration.js +13 -0
- package/src/videotracker.js +18 -0
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ const options = {
|
|
|
20
20
|
},
|
|
21
21
|
config: {
|
|
22
22
|
qoeAggregate: false, // Optional: Enable/disable QoE (Quality of Experience) event aggregation (default: false)
|
|
23
|
+
qoeIntervalFactor: 2, // Optional: Include QoE aggregate events once every N harvest cycles; must be a whole number (e.g. 2, not 2.1) (default: 1)
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
|
|
@@ -31,6 +32,8 @@ const tracker = new VideoSpecificTracker(player, options);
|
|
|
31
32
|
|
|
32
33
|
- **qoeAggregate** (boolean, optional, default: `false`): Controls whether Quality of Experience (QoE) events are aggregated and sent to New Relic. Set to `true` if you want to enable QoE event collection.
|
|
33
34
|
|
|
35
|
+
- **qoeIntervalFactor** (number, optional, default: `1`): Controls how frequently QoE aggregate events are included in harvest cycles. A value of `1` includes them on every cycle; a value of `N` includes them once every N cycles. Must be a positive integer — invalid values default to `1`. QoE events are always included on the first and final harvest cycles regardless of this setting.
|
|
36
|
+
|
|
34
37
|
|
|
35
38
|
## APIs
|
|
36
39
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
(()=>{"use strict";var t={28(t,e,i){i.d(e,{X:()=>a});var s=i(347),r=i(144);class a{async send(t,e){const{url:i,payload:s,options:a={}}=t;try{if(!i||!s)throw new Error("URL and payload are required");const t={url:i,payload:s,options:a,callback:e};await this.executeRequest(t)}catch(t){r.A.error("Failed to send request:",t.message),e({retry:!1,status:0,error:t.message})}}async executeRequest(t){const{url:e,payload:i,options:s,callback:r}=t,a=Date.now();try{const r=JSON.stringify(i.body);if(s.isFinalHarvest&&navigator.sendBeacon){const i=await this.sendWithBeacon(e,r),s={success:i,status:i?204:0};return void this.handleRequestComplete(t,s,a)}const n=await this.fetchWithTimeout(e,{method:"POST",body:r,headers:{"Content-Type":"application/json"},keepalive:s.isFinalHarvest},1e4),o={success:n.ok,status:n.status,statusText:n.statusText};this.handleRequestComplete(t,o,a)}catch(e){const i={success:!1,status:0,error:e.message};this.handleRequestComplete(t,i,a)}}handleRequestComplete(t,e){const{callback:i}=t;i({retry:!e.success&&(0===e.status||(0,s.Sc)(e.status)),status:e.status,error:e.error})}async sendWithBeacon(t,e){try{return navigator.sendBeacon(t,e)}catch(t){return r.A.warn("sendBeacon failed, falling back to fetch:",t.message),!1}}async fetchWithTimeout(t,e,i){const s=new AbortController,r=setTimeout(()=>s.abort(),i);try{const i=await fetch(t,{...e,signal:s.signal});return clearTimeout(r),i}catch(t){if(clearTimeout(r),"AbortError"===t.name)throw new Error(`Request timeout after ${i}ms`);throw t}}}},51(t,e,i){i.d(e,{A:()=>r});class s{}s.AdPositions={PRE:"pre",MID:"mid",POST:"post"},s.COLLECTOR={US:["bam.nr-data.net","bam-cell.nr-data.net"],EU:"bam.eu01.nr-data.net",Staging:"staging-bam-cell.nr-data.net",GOV:"gov-bam.nr-data.net"},s.VALID_EVENT_TYPES=["VideoAction","VideoAdAction","VideoErrorAction","VideoCustomAction"],s.MAX_PAYLOAD_SIZE=1048576,s.MAX_BEACON_SIZE=61440,s.MAX_EVENTS_PER_BATCH=1e3,s.INTERVAL=1e4,s.QOE_AGGREGATE_KEYS=["coreVersion","instrumentation.name","instrumentation.provider","instrumentation.version","isBackgroundEvent","playerName","playerVersion","src","viewId","viewSession","contentIsAutoplayed","contentIsMuted","contentRenditionHeight","contentRenditionWidth","contentSrc","numberOfVideos","pageUrl","trackerName","trackerVersion","contentDuration","contentPlayrate","contentPlayhead","contentPreload","elapsedTime","contentTitle","contentId","contentIsLive","deviceType","deviceGroup","deviceManufacturer","deviceModel","deviceName","deviceSize","deviceUuid","contentRenditionName","contentIsFullscreen","contentCdn","contentFps","asnOrganization","asnLongitude","asnLatitude","asn","timeSinceRequested","timeSinceStarted"];const r=s},144(t,e,i){i.d(e,{A:()=>o});class s{static error(...t){r(t,s.Levels.ERROR,"darkred")}static warn(...t){r(t,s.Levels.WARNING,"darkorange")}static notice(...t){r([].slice.call(arguments),s.Levels.NOTICE,"darkcyan")}static debug(...t){r(t,s.Levels.DEBUG,"indigo")}static debugCommonVideoEvents(t,e,i){try{if(s.level<=s.Levels.DEBUG){i=i||function(t){s.debug("Event: "+t.type)};var r=["canplay","buffering","waiting","ended","play","playing","pause","resume","error","abort","seek","seeking","seeked","stalled","dispose","loadeddata","loadstart","loadedmetadata"];e&&(null===e[0]?(e.shift(),r=e):r=r.concat(e));for(var a=0;a<r.length;a++)"function"==typeof t?t.call(window,r[a],i):t.on?t.on(r[a],i):t.addEventListener?t.addEventListener(r[a],i):t.addEventHandler?t.addEventHandler(r[a],i):s.warn("debugCommonVideoEvents: No common listener function found for ",t)}}catch(t){s.warn(t)}}}function r(t,e,i){e=e||s.Levels.NOTICE,i=i||"darkcyan";var r,o,h=s.prefix;s.includeTime&&(h+="["+("0"+(r=new Date).getDate()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2)+"."+("00"+r.getMilliseconds()).slice(-3)+"] "),h+=function(t){return n[t]}(e)+":",s.level<=e&&e!==s.Levels.SILENT&&(!s.colorful||"undefined"!=typeof document&&document.documentMode?a(t,h):(o=e===s.Levels.ERROR&&console.error?console.error:e===s.Levels.WARNING&&console.warn?console.warn:e===s.Levels.DEBUG&&console.debug&&null==window.cast?console.debug:console.log,h="%c"+h,t.splice(0,0,h,"color: "+i),o.apply(console,t)))}function a(t,e){if(t instanceof Array)for(var i in t)a(t[i],e);else"string"==typeof t?console.log(e+" "+t):(console.log(e+"↵"),console.log(t))}s.Levels={SILENT:5,ERROR:4,WARNING:3,NOTICE:2,DEBUG:1,ALL:0},s.level=s.Levels.ERROR,s.colorful=!0,s.includeTime=!0,s.prefix="[nrvideo]";const n={4:"e",3:"w",2:"n",1:"d"};!function(){if("undefined"!=typeof window&&window.location&&window.location.search){var t=/\?.*&*nrvideo-debug=(.+)/i.exec(window.location.search);null!==t&&("true"===t[1]?s.level=s.Levels.ALL:s.level=t[1]),null!==/\?.*&*nrvideo-colors=false/i.exec(window.location.search)&&(s.colorful=!1)}}();const o=s},302(t,e,i){i.d(e,{A:()=>l});var s=i(330),r=i(568),a=i(455),n=i(51),o=i(487),h=i(144);class d extends r.A{constructor(t){super(),this.customData={},this.heartbeat=null,this.parentTracker=null,this._trackerReadyChrono=new a.A,this._trackerReadyChrono.start(),this._actionTable=n.A.ACTION_TABLE,this._actionAdTable=n.A.ACTION_AD_TABLE,t=t||{},this.setOptions(t)}setOptions(t){t&&(t.parentTracker&&(this.parentTracker=t.parentTracker),t.customData&&(this.customData=t.customData),t.heartbeat&&(this.heartbeat=t.heartbeat))}dispose(){this.unregisterListeners()}registerListeners(){}unregisterListeners(){}getHeartbeat(){return this.state._isAd?2e3:this.heartbeat?this.heartbeat:this.parentTracker&&this.parentTracker.heartbeat?this.parentTracker.heartbeat:3e4}startHeartbeat(){this._heartbeatInterval=setInterval(this.sendHeartbeat.bind(this),Math.max(this.getHeartbeat(),2e3))}stopHeartbeat(){this._heartbeatInterval&&clearInterval(this._heartbeatInterval)}sendHeartbeat(t){this.sendVideoAction(d.Events.HEARTBEAT,t)}getAttributes(t,e){(t=t||{}).trackerName=this.getTrackerName(),t.trackerVersion=this.getTrackerVersion(),t.coreVersion=s.rE,t.timeSinceTrackerReady=this._trackerReadyChrono.getDeltaTime();for(let e in this.customData)t[e]=this.customData[e];return null!=document.hidden&&(t.isBackgroundEvent=document.hidden),t}getTrackerVersion(){return s.rE}getTrackerName(){return"base-tracker"}sendVideoAction(t,e){this.emit("VideoAction",t,this.getAttributes(e))}sendVideoAdAction(t,e){this.emit("VideoAdAction",t,this.getAttributes(e))}sendVideoErrorAction(t,e){let i=this.isAd()?"adError":"videoError";this.emit("VideoErrorAction",t,this.getAttributes(e,i))}sendVideoCustomAction(t,e){this.emit("VideoCustomAction",t,this.getAttributes(e,"customAction"))}setHarvestInterval(t){if(o.videoAnalyticsHarvester)try{o.videoAnalyticsHarvester.setHarvestInterval(t)}catch(t){return void h.A.error("Failed to set harvest interval:",t.message)}else h.A.error("VideoAnalyticsHarvester is not available")}}d.Events={HEARTBEAT:"HEARTBEAT",QOE_AGGREGATE:"QOE_AGGREGATE"};const l=d},330(t){t.exports={rE:"4.1.0"}},347(t,e,i){i.d(e,{Q3:()=>n,Sc:()=>o,c$:()=>a,z8:()=>h});var s=i(330),r=i(144);function a(t){try{if(!window.NRVIDEO||!window.NRVIDEO.info)throw new Error("NRVIDEO info is not available.");let{beacon:e,licenseKey:i,applicationID:r}=window.NRVIDEO.info;if(!e||!i)throw new Error("Options object provided by New Relic is not correctly initialized");return r?`https://${t||e}/ins/1/${i}?a=${r}&v=${s.rE}&ref=${window.location.href}&ca=VA`:`https://${t||e}/ins/1/${i}?&v=${s.rE}&ref=${window.location.href}&ca=VA`}catch(t){return console.error(t.message),null}}function n(t){if("string"==typeof t&&t.length)return t.length;if("object"==typeof t){if("undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer&&t.byteLength)return t.byteLength;if("undefined"!=typeof Blob&&t instanceof Blob&&t.size)return t.size;if(!("undefined"!=typeof FormData&&t instanceof FormData))try{return function(t){try{return JSON.stringify(t,(()=>{const t=new WeakSet;return(e,i)=>{if("object"==typeof i&&null!==i){if(t.has(i))return;t.add(i)}return i}})())??""}catch(t){return r.A.error("Error stringifying value:",t.message),""}}(t).length}catch(t){return}}}function o(t){switch(t){case 408:case 429:case 500:return!0;case 401:case 403:case 404:return!1}return t>=502&&t<=504||t>=512&&t<=530}function h(t,e){return t&&Array.isArray(t)&&0!==t.length?e&&"object"==typeof e?t.reduce((t,i)=>(i in e&&(t[i]=e[i]),t),{}):{}:e}},374(t,e,i){i.d(e,{n:()=>d});var s=i(431),r=i(413),a=i(28),n=i(347),o=i(51),h=i(144);class d{constructor(t){this.eventBuffer=t,this.retryQueueHandler=new r.u,this.httpClient=new a.X,this.fallBackUrl="",this.retryCount=0,this.eventBuffer instanceof s.t&&this.eventBuffer.setSmartHarvestCallback((t,e)=>this.triggerSmartHarvest(t,e)),this.isStarted=!1,this.currentTimerId=null,this.harvestCycle=o.A.INTERVAL,this.isHarvesting=!1,this.setupPageLifecycleHandlers()}startScheduler(){this.isStarted?h.A.warn("Harvest scheduler is already started"):(this.isStarted=!0,h.A.notice("Starting harvest scheduler",{harvestCycle:this.harvestCycle,eventBufferSize:this.eventBuffer?this.eventBuffer.size():0}),this.scheduleNextHarvest())}stopScheduler(){this.isStarted&&(this.isStarted=!1,this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null),h.A.notice("Harvest scheduler stopped"))}async triggerSmartHarvest(t,e){if(h.A.notice(`${t} harvest triggered at ${e}% threshold`,{type:t,threshold:e}),this.eventBuffer&&!this.eventBuffer.isEmpty()){this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null);try{await this.triggerHarvest({})}catch(e){h.A.error(`${t} harvest failed:`,e.message)}finally{this.isStarted&&this.scheduleNextHarvest()}}}scheduleNextHarvest(){if(!this.isStarted)return;const t=this.harvestCycle;this.currentTimerId=setTimeout(()=>this.onHarvestInterval(),t)}async onHarvestInterval(){try{const t=this.eventBuffer&&!this.eventBuffer.isEmpty(),e=this.retryQueueHandler&&this.retryQueueHandler.getQueueSize()>0;if(!t&&!e)return;await this.triggerHarvest({})}catch(t){h.A.error("Error during scheduled harvest:",t.message)}finally{this.scheduleNextHarvest()}}async triggerHarvest(t={}){if(this.isHarvesting)return{success:!1,reason:"harvest_in_progress"};this.isHarvesting=!0;try{let e=this.drainEvents(t);if(t.isFinalHarvest){const t=o.A.MAX_BEACON_SIZE;(0,n.Q3)(e)>t&&(e=this.trimEventsToFit(e,t))}const i=await this.sendChunk(e,t,!0);return{success:i.success,totalChunks:1,results:[i]}}catch(t){return h.A.error("Harvest cycle failed:",t.message),this.handleHarvestFailure(t),{success:!1,error:t.message,consecutiveFailures:this.consecutiveFailures}}finally{this.isHarvesting=!1}}trimEventsToFit(t,e){if(0===t.length)return t;const i=[];let s=0;for(let r=t.length-1;r>=0;r--){const a=t[r],o=(0,n.Q3)({ins:[a,...i]});o>e||(i.unshift(a),s=o)}const r=t.length-i.length;if(r>0){const a=t.slice(0,r);h.A.warn(`Discarded ${r} events to fit beacon size limit`,{originalCount:t.length,trimmedCount:i.length,finalSize:s,maxSize:e}),this.retryQueueHandler&&this.retryQueueHandler.addFailedEvents(a)}return i}drainEvents(){const t=this.eventBuffer.drain();let e=[...t],i=(0,n.Q3)(t);if(this.retryQueueHandler&&this.retryQueueHandler.getQueueSize()>0){const t=o.A.MAX_PAYLOAD_SIZE-i,s=o.A.MAX_EVENTS_PER_BATCH-e.length;if(t>0&&s>0){const i=this.retryQueueHandler.getRetryEventsToFit(t,s);i.length>0&&(e=[...i,...e])}}return e}async sendChunk(t,e,i){const s={url:(0,n.c$)(this.fallBackUrl),payload:{body:{ins:t}},options:{...e,isLastChunk:i}};return new Promise(e=>{this.httpClient.send(s,i=>{i.retry?this.handleRequestFailure(t):(this.retryCount=0,this.fallBackUrl=""),e({success:!i.retry,status:i.status,error:i.error,chunk:t,eventCount:t.length})})})}handleRequestFailure(t){this.retryQueueHandler.addFailedEvents(t),"US"===window.NRVIDEO?.info?.region&&(this.retryCount++,this.retryCount>5?(this.retryCount=0,this.fallBackUrl=""):this.retryCount>=2&&(this.fallBackUrl=o.A.COLLECTOR.US[1]))}handleHarvestFailure(t){this.consecutiveFailures++,h.A.warn("Harvest failure handled",{error:t.message,consecutiveFailures:this.consecutiveFailures})}updateHarvestInterval(t){"number"!=typeof t&&isNaN(t)?h.A.warn("Invalid newInterval provided to updateHarvestInterval"):t<1e3||t>3e5?h.A.warn("newInterval out of bounds (1000-300000), ignoring"):this.harvestCycle!==t&&(this.harvestCycle=t,h.A.notice("Updated harvestCycle:",this.harvestCycle),this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null),this.isStarted&&this.scheduleNextHarvest())}setupPageLifecycleHandlers(){let t=!1;const e=()=>{t||(t=!0,this.triggerHarvest({isFinalHarvest:!0,force:!0}))};document.addEventListener("visibilitychange",()=>{document.hidden&&e()}),window.addEventListener("pagehide",()=>{e()}),window.addEventListener("beforeunload",()=>{e()})}}},413(t,e,i){i.d(e,{u:()=>h});var s=i(144),r=i(347),a=i(51);const{MAX_PAYLOAD_SIZE:n,MAX_EVENTS_PER_BATCH:o}=a.A;class h{constructor(){this.retryQueue=[],this.maxQueueSize=o,this.maxQueueSizeBytes=n}addFailedEvents(t){try{const e=Array.isArray(t)?t:[t];s.A.notice(`Adding ${e.length} failed events to retry queue`,{queueSizeBefore:this.retryQueue.length});for(const t of e){this.retryQueue.length>=this.maxQueueSize&&this.evictOldestEvent();const e=(0,r.Q3)(t);for(;(0,r.Q3)(this.retryQueue)+e>this.maxQueueSizeBytes;)this.evictOldestEvent();this.retryQueue.push({...t})}}catch(t){s.A.error("Failed to add events to retry queue:",t.message)}}discardEvent(t,e){s.A.warn("Discarded event",{reason:e,eventType:t.eventType})}evictOldestEvent(){if(this.retryQueue.length>0){const t=this.retryQueue.shift();this.discardEvent(t,"Queue full - evicted oldest")}}getRetryEventsToFit(t,e){const i=[];let s=0,a=0;for(let n=this.retryQueue.length-1;n>=0;n--){const o=this.retryQueue[n];if(a>=e)break;const h=(0,r.Q3)(o);if(s+h>t)break;i.unshift(o),s+=h,a++,this.retryQueue.splice(n,1)}return i}getQueueSize(){return this.retryQueue.length}clear(){this.retryQueue=[]}}},431(t,e,i){i.d(e,{t:()=>h});var s=i(144),r=i(51),a=i(347);const{MAX_PAYLOAD_SIZE:n,MAX_EVENTS_PER_BATCH:o}=r.A;class h{constructor(){this.buffer=[],this.maxPayloadSize=n,this.maxEventsPerBatch=o,this.currentPayloadSize=0,this.totalEvents=0,this.smartHarvestPayloadThreshold=Math.floor(.6*this.maxPayloadSize),this.overflowPayloadThreshold=Math.floor(.9*this.maxPayloadSize),this.smartHarvestEventThreshold=Math.floor(.6*this.maxEventsPerBatch),this.overflowEventThreshold=Math.floor(.9*this.maxEventsPerBatch),this.onSmartHarvestTrigger=null}addOrReplaceByActionName(t,e){const i=this.buffer.findIndex(e=>e.actionName===t);try{return-1===i?this.add(e):this.add(e,i),!0}catch(t){return s.A.error("Failed to set or replace the event to buffer:",t.message),!1}}add(t,e){try{const i=(0,a.Q3)(t),s=this.currentPayloadSize+i>=this.maxPayloadSize,r=this.totalEvents+1>=this.maxEventsPerBatch;if((s||r)&&this.makeRoom(i),null!=e&&e>-1){const s=(0,a.Q3)(this.buffer[e]);this.buffer[e]=t,this.currentPayloadSize+=i-s}else this.buffer.push(t),this.totalEvents++,this.currentPayloadSize+=i;return this.checkSmartHarvestTrigger(),!0}catch(t){return s.A.error("Failed to add event to buffer:",t.message),!1}}checkSmartHarvestTrigger(){const t=this.currentPayloadSize/this.maxPayloadSize,e=this.totalEvents/this.maxEventsPerBatch,i=this.currentPayloadSize>=this.overflowPayloadThreshold,r=this.totalEvents>=this.overflowEventThreshold;if(i||r){const r=i?`payload ${this.currentPayloadSize}/${this.maxPayloadSize} bytes (${Math.round(100*t)}%)`:`events ${this.totalEvents}/${this.maxEventsPerBatch} (${Math.round(100*e)}%)`;s.A.warn(`OVERFLOW PREVENTION: ${r} - Emergency harvest triggered`),this.onSmartHarvestTrigger&&"function"==typeof this.onSmartHarvestTrigger&&this.onSmartHarvestTrigger("overflow",90)}else{const t=this.currentPayloadSize>=this.smartHarvestPayloadThreshold,e=this.totalEvents>=this.smartHarvestEventThreshold;(t||e)&&this.onSmartHarvestTrigger&&"function"==typeof this.onSmartHarvestTrigger&&this.onSmartHarvestTrigger("smart",60)}}setSmartHarvestCallback(t){this.onSmartHarvestTrigger=t}drain(){try{const t=this.buffer.splice(0);return this.totalEvents=0,this.currentPayloadSize=0,t}catch(t){return s.A.error("Failed to drain events from buffer:",t.message),[]}}isEmpty(){return 0===this.totalEvents}size(){return this.totalEvents}clear(){this.buffer=[],this.totalEvents=0}makeRoom(t){if(t>this.maxPayloadSize)s.A.error("Event dropped: Event size exceeds maximum payload size.");else for(;(this.totalEvents>=this.maxEventsPerBatch||this.currentPayloadSize+t>=this.maxPayloadSize)&&this.buffer.length>0;){const t=this.buffer.shift(),e=(0,a.Q3)(t);this.totalEvents--,this.currentPayloadSize-=e,s.A.warn("Event buffer full, oldest event removed.")}}}},455(t,e,i){i.d(e,{A:()=>r});class s{constructor(){this.reset()}reset(){this.startTime=0,this.stopTime=0,this.accumulator=0,this.offset=0}getDeltaTime(){return this.startTime?this.offset+((new Date).getTime()-this.startTime):null}start(){this.startTime=(new Date).getTime(),this.stopTime=0}stop(){return this.stopTime=(new Date).getTime(),this.startTime<this.stopTime&&(this.accumulator+=this.stopTime-this.startTime),this.getDeltaTime()}getDuration(){return this.stopTime?this.accumulator+this.offset:this.accumulator+(this.getDeltaTime()??0)}clone(){var t=new s;return t.startTime=this.startTime,t.stopTime=this.stopTime,t.offset=this.offset,t.accumulator=this.accumulator,t}}const r=s},487(t,e,i){i.r(e),i.d(e,{videoAnalyticsHarvester:()=>o});var s=i(374),r=i(431),a=i(144),n=i(302);const o=new class{constructor(){this.isInitialized=!1,this.harvestScheduler=null,this.eventBuffer=null}initialize(){if(this.isInitialized)a.A.warn("Video analytics agent already initialized");else try{this.eventBuffer=new r.t,this.harvestScheduler=new s.n(this.eventBuffer),this.harvestScheduler.startScheduler(),this.isInitialized=!0,a.A.notice("Video analytics agent initialized successfully")}catch(t){a.A.error("Failed to initialize video analytics agent:",t.message)}}addEvent(t){this.isInitialized||(a.A.warn("Video analytics agent not initialized, initializing now"),this.initialize());try{return t.actionName&&t.actionName===n.A.Events.QOE_AGGREGATE?this.eventBuffer.addOrReplaceByActionName(n.A.Events.QOE_AGGREGATE,t):this.eventBuffer.add(t)}catch(t){return a.A.error("Failed to add event to harvesting system:",t.message),!1}}setHarvestInterval(t){this.isInitialized||this.initialize(),this.harvestScheduler.updateHarvestInterval(t)}}},568(t,e,i){i.d(e,{A:()=>s});const s=class{on(t,e){if(this._listeners=this._listeners||{},"function"==typeof e)return this._listeners[t]=this._listeners[t]||[],this._listeners[t].push(e),this}off(t,e){if(this._listeners=this._listeners||{},this._listeners[t]){var i=this._listeners[t].indexOf(e);-1!==i&&this._listeners[t].splice(i,1)}return this}emit(t,e,i){return this._listeners=this._listeners||{},i=i||{},Array.isArray(this._listeners[e])&&this._listeners[e].forEach(s=>{s.call(this,{eventType:t,type:e,data:i,target:this})}),Array.isArray(this._listeners["*"])&&this._listeners["*"].forEach(s=>{s.call(this,{eventType:t,type:e,data:i,target:this})}),this}}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var a=e[s]={exports:{}};return t[s](a,a.exports,i),a.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{default:()=>D});var r=i(144),a=i(487),n=i(51),o=i(302),h=i(347);function d(t,e={}){try{if(!n.A.VALID_EVENT_TYPES.includes(t))return r.A.warn("Invalid event type provided to recordEvent",{eventType:t}),!1;if(!window?.NRVIDEO?.info)return;const{appName:i,applicationID:s}=window.NRVIDEO.info,{qoe:d,...l}=e,c=d?{...d}:{},u={...s?{}:{appName:i},timestamp:Date.now(),timeSinceLoad:window.performance?window.performance.now()/1e3:null},A={...l,eventType:t,...u},g=(0,h.z8)(n.A.QOE_AGGREGATE_KEYS,e);let m=null;"VideoAction"===t&&(m={eventType:"VideoAction",actionName:o.A.Events.QOE_AGGREGATE,qoeAggregateVersion:"1.0.0",...c,...g,...u});const f=a.videoAnalyticsHarvester.addEvent(A);if(m&&window?.NRVIDEO?.config?.qoeAggregate){const t=a.videoAnalyticsHarvester.addEvent(m);return f&&t}return f}catch(t){return r.A.error("Failed to record event:",t.message),!1}}const{COLLECTOR:l}=n.A;const c=new class{setConfiguration(t,e){return!!this.validateRequiredFields(t)&&!!this.validateConfigFields(e)&&(this.initializeGlobalConfig(t,e),r.A.notice("Video analytics configuration initialized successfully"),!0)}validateRequiredFields(t){if(!t||"object"!=typeof t)return r.A.error("Configuration must be an object"),!1;const{licenseKey:e,appName:i,region:s,applicationID:a,beacon:n}=t;if(!e)return r.A.error("licenseKey is required"),!1;if(a){if(!n)return r.A.error("beacon is required when applicationID is provided"),!1;if(!Object.values(l).flatMap(t=>t).includes(n))return r.A.error(`Invalid beacon: ${n}`),!1}else{if(!i||!s)return r.A.error("appName and region are required when applicationID is not provided"),!1;if(!l[s])return r.A.error(`Invalid region: ${s}. Valid regions are: ${Object.keys(l).join(", ")}`),!1}return!0}validateConfigFields(t){if(null==t)return!0;if("object"!=typeof t||Array.isArray(t))return r.A.error("config must be an object"),!1;const{qoeAggregate:e}=t;return void 0===e||"boolean"==typeof e||(r.A.error("qoeAggregate must be a boolean"),!1)}initializeGlobalConfig(t,e){let{licenseKey:i,appName:s,region:r,beacon:a,applicationID:o}=t;a="US"===r?n.A.COLLECTOR.US[0]:a||l[r],window.NRVIDEO={info:{...r?{region:r}:{},beacon:a,licenseKey:i,applicationID:o,...o?{}:{appName:s}},config:{qoeAggregate:e?.qoeAggregate??!1}}}};class u{static addTracker(t,e){var i,s;e?.info&&(i=e.info,s=e?.config,c.setConfiguration(i,s)),t.on&&t.emit?(A.push(t),t.on("*",g),"function"==typeof t.trackerInit&&t.trackerInit()):r.A.error("Tried to load a non-tracker.",t)}static removeTracker(t){t.off("*",g),t.dispose();let e=A.indexOf(t);-1!==e&&A.splice(e,1)}static getTrackers(){return A}static send(t,e,i){return d(t,{actionName:e,...i})}static sendError(t){return d("VideoErrorAction",{actionName:"ERROR",...t})}static async forceHarvest(){try{const{videoAnalyticsHarvester:t}=i(487);return await t.forceHarvest()}catch(t){return r.A.error("Failed to force harvest:",t.message),{success:!1,error:t.message}}}}let A=[];function g(t){try{let e=function(t){let e={};for(let i in t)null!==t[i]&&void 0!==t[i]&&(e[i]=t[i]);return e}(t.data);r.A.level<=r.A.Levels.DEBUG?r.A.notice("Sent",t.type,e):r.A.notice("Sent",t.type),u.send(t.eventType,t.type,e)}catch(t){r.A.error("Error in event handler:",t.message)}}const m=u;var f=i(455),T=i(568);const E=class{constructor(){this.reset(),this._createdAt=Date.now(),this._hb=!0,this._acc=0,this._bufferAcc=0}reset(){this._viewSession=null,this._viewCount=0,this._isAd=!1,this.numberOfErrors=0,this.numberOfAds=0,this.numberOfVideos=0,this.totalPlaytime=0,this.weightedAverageBitrate=0,this.totalAdPlaytime=0,this.isAdBreak=!1,this.initialBufferingHappened=!1,this.startupTime=null,this.peakBitrate=0,this._lastBitrate=null,this._lastBitrateChangeTimestamp=null,this.partialAverageBitrate=0,this.hadStartupFailure=!1,this.hadPlaybackFailure=!1,this.totalRebufferingTime=0,this.resetFlags(),this.resetChronos()}resetFlags(){this.isPlayerReady=!1,this.isRequested=!1,this.isStarted=!1,this.isPaused=!1,this.isSeeking=!1,this.isBuffering=!1,this.isPlaying=!1}resetChronos(){this.timeSinceRequested=new f.A,this.timeSinceStarted=new f.A,this.timeSincePaused=new f.A,this.timeSinceSeekBegin=new f.A,this.timeSinceBufferBegin=new f.A,this.timeSinceAdBreakStart=new f.A,this.timeSinceLastDownload=new f.A,this.timeSinceLastHeartbeat=new f.A,this.timeSinceLastRenditionChange=new f.A,this.timeSinceLastAdQuartile=new f.A,this.timeSinceLastAd=new f.A,this.timeSinceLastError=new f.A,this.timeSinceLastAdError=new f.A,this.timeSinceResumed=new f.A,this.timeSinceSeekEnd=new f.A,this.playtimeSinceLastEvent=new f.A,this.customTimeSinceAttributes={},this.elapsedTime=new f.A,this.bufferElapsedTime=new f.A,this._totalAdPlaytime=new f.A}isAd(){return this._isAd}setIsAd(t){this._isAd=t}setTimeSinceAttribute(t){this.customTimeSinceAttributes[t]=new f.A,this.customTimeSinceAttributes[t].start()}removeTimeSinceAttribute(t){delete this.customTimeSinceAttributes[t]}getViewSession(){if(!this._viewSession){let t=(new Date).getTime(),e=Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2);this._viewSession=t+"-"+e}return this._viewSession}getViewId(){return this.getViewSession()+"-"+this._viewCount}getStateAttributes(t){t=t||{},this.isAd()?(this.isRequested&&(t.timeSinceAdRequested=this.timeSinceRequested.getDeltaTime(),t.timeSinceLastAdHeartbeat=this.timeSinceLastHeartbeat.getDeltaTime()),this.isStarted&&(t.timeSinceAdStarted=this.timeSinceStarted.getDeltaTime()),this.isPaused&&(t.timeSinceAdPaused=this.timeSincePaused.getDeltaTime()),this.isBuffering&&(t.timeSinceAdBufferBegin=this.timeSinceBufferBegin.getDeltaTime()),this.isSeeking&&(t.timeSinceAdSeekBegin=this.timeSinceSeekBegin.getDeltaTime()),this.isAdBreak&&(t.timeSinceAdBreakBegin=this.timeSinceAdBreakStart.getDeltaTime()),this.numberOfErrors>0&&this.timeSinceLastAdError.startTime>0&&(t.timeSinceLastAdError=this.timeSinceLastAdError.getDeltaTime()),t.numberOfAds=this.numberOfAds):(this.isRequested&&(t.timeSinceRequested=this.timeSinceRequested.getDeltaTime(),t.timeSinceLastHeartbeat=this.timeSinceLastHeartbeat.getDeltaTime()),this.isStarted&&(t.timeSinceStarted=this.timeSinceStarted.getDeltaTime()),this.isPaused&&(t.timeSincePaused=this.timeSincePaused.getDeltaTime()),this.isBuffering&&(t.timeSinceBufferBegin=this.timeSinceBufferBegin.getDeltaTime()),this.isSeeking&&(t.timeSinceSeekBegin=this.timeSinceSeekBegin.getDeltaTime()),t.timeSinceLastAd=this.timeSinceLastAd.getDeltaTime(),this.numberOfErrors>0&&this.timeSinceLastError.startTime>0&&(t.timeSinceLastError=this.timeSinceLastError.getDeltaTime()),t.numberOfVideos=this.numberOfVideos),t.numberOfErrors=this.numberOfErrors,this.isAd()||(this.playtimeSinceLastEvent.startTime>0?t.playtimeSinceLastEvent=this.playtimeSinceLastEvent.getDeltaTime():t.playtimeSinceLastEvent=0,this.isPlaying?this.playtimeSinceLastEvent.start():this.playtimeSinceLastEvent.reset(),this.totalPlaytime+=t.playtimeSinceLastEvent,t.totalPlaytime=this.totalPlaytime);for(const[e,i]of Object.entries(this.customTimeSinceAttributes))t[e]=i.getDeltaTime();return t}getQoeAttributes(t){t=t||{};const e={};try{null!==this.startupTime&&(e.startupTime=this.startupTime),this.peakBitrate>0&&(e.peakBitrate=this.peakBitrate),e.hadStartupFailure=this.hadStartupFailure,e.hadPlaybackFailure=this.hadPlaybackFailure,e.totalRebufferingTime=this.totalRebufferingTime,e.rebufferingRatio=this.totalPlaytime>0?this.totalRebufferingTime/this.totalPlaytime*100:0,e.totalPlaytime=this.totalPlaytime,e.averageBitrate=this.weightedBitrate,e.numberOfErrors=this.numberOfErrors}catch(t){r.A.error("Failed to add attributes for QOE KPIs",t.message)}return t.qoe=e,t}calculateBufferType(t){let e="";return e=t?"initial":this.isSeeking?"seek":this.isPaused?"pause":"connection",r.A.debug("Buffer Type = "+e),e}goViewCountUp(){this._viewCount++}goPlayerReady(){return!this.isPlayerReady&&(this.isPlayerReady=!0,!0)}goRequest(){return!this.isRequested&&(this.isRequested=!0,this.timeSinceLastAd.reset(),this.timeSinceRequested.start(),!0)}goStart(){return!(!this.isRequested||this.isStarted||(this.isAd()?this.numberOfAds++:this.numberOfVideos++,this.isStarted=!0,this.isPlaying=!0,this.timeSinceStarted.start(),this.playtimeSinceLastEvent.start(),0))}goEnd(){return!!this.isRequested&&(this.numberOfErrors=0,this.resetFlags(),this.timeSinceRequested.stop(),this.timeSinceStarted.stop(),this.playtimeSinceLastEvent.stop(),this.isPlaying=!1,!0)}goPause(){return!(!this.isStarted||this.isPaused||(this.isPaused=!0,this.isPlaying=!1,this.timeSincePaused.start(),this.playtimeSinceLastEvent.stop(),this.timeSinceResumed.reset(),this.isBuffering&&(this._bufferAcc+=this.bufferElapsedTime.getDeltaTime()),this.elapsedTime.start(),0))}goResume(){return!(!this.isStarted||!this.isPaused||(this.isPaused=!1,this.isPlaying=!0,this.timeSincePaused.stop(),this.timeSinceResumed.start(),this._hb?(this._acc=this.elapsedTime.getDeltaTime(),this._hb=!1):(this.isBuffering&&this.bufferElapsedTime.start(),this._acc+=this.elapsedTime.getDeltaTime()),0))}goBufferStart(){return!(!this.isRequested||this.isBuffering||(this.isBuffering=!0,this.isPlaying=!1,this.timeSinceBufferBegin.start(),this.bufferElapsedTime.start(),0))}goBufferEnd(){return!(!this.isRequested||!this.isBuffering||(this.isBuffering=!1,this.isPlaying=!0,this.timeSinceBufferBegin.stop(),this._hb?(this._bufferAcc=this.bufferElapsedTime.getDeltaTime(),this._hb=!1):this._bufferAcc+=this.bufferElapsedTime.getDeltaTime(),!this.isAd()&&this.initialBufferingHappened&&(this.totalRebufferingTime+=this.timeSinceBufferBegin.getDeltaTime()),0))}goSeekStart(){return!(!this.isStarted||this.isSeeking||(this.isSeeking=!0,this.isPlaying=!1,this.timeSinceSeekBegin.start(),this.timeSinceSeekEnd.reset(),0))}goSeekEnd(){return!(!this.isStarted||!this.isSeeking||(this.isSeeking=!1,this.isPlaying=!0,this.timeSinceSeekBegin.stop(),this.timeSinceSeekEnd.start(),0))}goAdBreakStart(){return!this.isAdBreak&&(this.isAdBreak=!0,this.timeSinceAdBreakStart.start(),!0)}goAdBreakEnd(){return!!this.isAdBreak&&(this.isRequested=!1,this.isAdBreak=!1,this.totalAdPlaytime=this.timeSinceAdBreakStart.getDeltaTime(),this.timeSinceAdBreakStart.stop(),!0)}goDownload(){this.timeSinceLastDownload.start()}goHeartbeat(){this.timeSinceLastHeartbeat.start()}goRenditionChange(){this.timeSinceLastRenditionChange.start()}goAdQuartile(){this.timeSinceLastAdQuartile.start()}goError(){this.isError=!0,this.numberOfErrors++,this.isAd()?this.timeSinceLastAdError.start():(this.timeSinceLastError.start(),this.isStarted?this.hadPlaybackFailure=!0:this.hadStartupFailure=!0)}goLastAd(){this.timeSinceLastAd.start()}trackContentBitrateState(t){if(t&&"number"==typeof t&&(this.peakBitrate=Math.max(this.peakBitrate,t),null===this._lastBitrate||this._lastBitrate!==t)){const e=null===this._lastBitrateChangeTimestamp?this.totalPlaytime:Date.now()-this._lastBitrateChangeTimestamp,i=t*e;this.partialAverageBitrate+=i,this.weightedBitrate=i/e,this._lastBitrate=t,this._lastBitrateChangeTimestamp=Date.now()}}resetViewIdTrackedState(){this.peakBitrate=0,this.partialAverageBitrate=0,this.startupTime=null,this._lastBitrate=null,this._lastBitrateChangeTimestamp=null}clearTotalAdsTime(){console.log("clear total ads time",this.totalAdTime),this._totalAdPlaytime.reset()}totalAdTime(){return this._totalAdPlaytime.getDuration()}startAdsTime(){return console.log("startAdsTime"),this._totalAdPlaytime.start()}stopAdsTime(){return console.log("stopAdsTime"),this._totalAdPlaytime.stop()}setStartupTime(t){null===this.startupTime&&(this.startupTime=Math.max(this.timeSinceRequested.getDeltaTime()-t,0))}};var S=i(330);class v extends o.A{constructor(t,e){super(),this.state=new E,this.adsTracker=null,this._lastBufferType=null,this._userId=null,e=e||{},this.setOptions(e),t&&this.setPlayer(t,e.tag),r.A.notice("Tracker "+this.getTrackerName()+" v"+this.getTrackerVersion()+" is ready.")}setUserId(t){this._userId=t}setOptions(t){t&&(t.adsTracker&&this.setAdsTracker(t.adsTracker),"boolean"==typeof t.isAd&&this.setIsAd(t.isAd),o.A.prototype.setOptions.apply(this,arguments))}setPlayer(t,e){(this.player||this.tag)&&this.dispose(),"undefined"!=typeof document&&document.getElementById&&("string"==typeof t&&(t=document.getElementById(t)),"string"==typeof e&&(e=document.getElementById(e))),e=e||t,this.player=t,this.tag=e,this.registerListeners()}isAd(){return this.state.isAd()}setIsAd(t){this.state.setIsAd(t)}setAdsTracker(t){this.disposeAdsTracker(),t&&(this.adsTracker=t,this.adsTracker.setIsAd(!0),this.adsTracker.parentTracker=this,this.adsTracker.on("*",y.bind(this)))}disposeAdsTracker(){this.adsTracker&&(this.adsTracker.off("*",y),this.adsTracker.dispose())}dispose(){this.stopHeartbeat(),this.disposeAdsTracker(),this.unregisterListeners(),this.player=null,this.tag=null}registerListeners(){}unregisterListeners(){}getViewId(){return this.parentTracker?this.parentTracker.getViewId():this.state.getViewId()}getViewSession(){return this.parentTracker?this.parentTracker.getViewSession():this.state.getViewSession()}getVideoId(){return null}getTitle(){return null}isLive(){return null}getBitrate(){return null}getWebkitBitrate(){if(this.tag&&this.tag.webkitVideoDecodedByteCount){let t;if(this._lastWebkitBitrate){t=this.tag.webkitVideoDecodedByteCount;let e=t-this._lastWebkitBitrate,i=this.getHeartbeat()/1e3;t=Math.round(e/i*8)}return this._lastWebkitBitrate=this.tag.webkitVideoDecodedByteCount,t||null}}getRenditionName(){return null}getRenditionBitrate(){return null}getRenditionShift(t){let e,i=this.getRenditionBitrate();return this.isAd()?(e=this._lastAdRendition,t&&(this._lastAdRendition=i)):(e=this._lastRendition,t&&(this._lastRendition=i)),i&&e?i>e?"up":i<e?"down":null:null}getRenditionHeight(){return this.tag?this.tag.videoHeight:null}getRenditionWidth(){return this.tag?this.tag.videoWidth:null}getDuration(){return this.tag?this.tag.duration:null}getPlayhead(){return this.tag?this.tag.currentTime:null}getLanguage(){return null}getSrc(){return this.tag?this.tag.currentSrc:null}getPlayrate(){return this.tag?this.tag.playbackRate:null}isMuted(){return this.tag?this.tag.muted:null}isFullscreen(){return null}getCdn(){return null}getPlayerName(){return this.getTrackerName()}getPlayerVersion(){return S.rE}getFps(){return null}isAutoplayed(){return this.tag?this.tag.autoplay:null}getPreload(){return this.tag?this.tag.preload:null}getAdQuartile(){return null}getAdPosition(){return this.parentTracker?this.parentTracker.state.isStarted?"mid":"pre":null}getAdPartner(){return null}getAdCreativeId(){return null}getInstrumentationProvider(){return null}getInstrumentationName(){return null}getInstrumentationVersion(){return null}getAttributes(t,e){if(void 0===(t=o.A.prototype.getAttributes.apply(this,arguments)).isAd&&(t.isAd=this.isAd()),t.viewSession=this.getViewSession(),t.viewId=this.getViewId(),t.playerName=this.getPlayerName(),t.playerVersion=this.getPlayerVersion(),t["instrumentation.provider"]=this.getInstrumentationProvider(),t["instrumentation.name"]=this.getInstrumentationName(),t["instrumentation.version"]=this.getInstrumentationVersion(),t["enduser.id"]=this._userId,t.src="Browser","customAction"===e)return t;try{t.pageUrl=window.location.href}catch(t){}this.isAd()?(t.adId=this.getVideoId(),t.adTitle=this.getTitle(),t.adSrc=this.getSrc(),t.adCdn=this.getCdn(),this.state.isStarted&&(t.adBitrate=this.getBitrate()||this.getWebkitBitrate()||this.getRenditionBitrate(),t.adRenditionBitrate=this.getRenditionBitrate()),t.adRenditionName=this.getRenditionName(),t.adRenditionHeight=this.getRenditionHeight(),t.adRenditionWidth=this.getRenditionWidth(),t.adDuration=this.getDuration(),t.adPlayhead=this.getPlayhead(),t.adLanguage=this.getLanguage(),t.adIsMuted=this.isMuted(),t.adFps=this.getFps(),t.adPosition=this.getAdPosition(),t.adCreativeId=this.getAdCreativeId(),t.adPartner=this.getAdPartner()):(t.contentId=this.getVideoId(),t.contentTitle=this.getTitle(),t.contentSrc=this.getSrc(),t.contentCdn=this.getCdn(),t.contentPlayhead=this.getPlayhead(),t.contentIsLive=this.isLive(),this.state.isStarted&&(t.contentBitrate=this.getBitrate()||this.getWebkitBitrate()||this.getRenditionBitrate(),t.contentRenditionBitrate=this.getRenditionBitrate()),t.contentRenditionName=this.getRenditionName(),t.contentRenditionHeight=this.getRenditionHeight(),t.contentRenditionWidth=this.getRenditionWidth(),t.contentDuration=this.getDuration(),t.contentLanguage=this.getLanguage(),t.contentPlayrate=this.getPlayrate(),t.contentIsFullscreen=this.isFullscreen(),t.contentIsMuted=this.isMuted(),t.contentIsAutoplayed=this.isAutoplayed(),t.contentPreload=this.getPreload(),t.contentFps=this.getFps(),null!=this.adsTracker&&this.adsTracker.state.totalAdPlaytime>0&&(t.totalAdPlaytime=this.adsTracker.state.totalAdPlaytime)),this.state.getStateAttributes(t),this.state.isStarted&&!this.isAd()&&this.state.trackContentBitrateState(t.contentBitrate);for(let e in this.customData)t[e]=this.customData[e];return this.addQoeAttributes(t),t}addQoeAttributes(t){const e=(t=this.state.getQoeAttributes(t)).qoe;for(let t in this.customData)e[t]=this.customData[t]}sendCustom(t,e,i){i=i||{},this.sendVideoCustomAction(t,i),this.state.setTimeSinceAttribute(e)}sendPlayerReady(t){this.state.goPlayerReady()&&(t=t||{},this.sendVideoAction(v.Events.PLAYER_READY,t))}sendRequest(t){if(this.state.goRequest()){let e;this.isAd()?(e=v.Events.AD_REQUEST,this.sendVideoAdAction(e,t)):(e=v.Events.CONTENT_REQUEST,this.sendVideoAction(e,t))}}sendStart(t){if(this.state.goStart()){let e;if(this.isAd())e=v.Events.AD_START,this.parentTracker&&(this.parentTracker.state.isPlaying=!1),this.sendVideoAdAction(e,t),this.state.startAdsTime();else{e=v.Events.CONTENT_START;let i=0;this.adsTracker&&(this.adsTracker.state.isPlaying||this.adsTracker.state.isBuffering?(i=this.adsTracker.state.stopAdsTime(),this.adsTracker.state.isPlaying=!1,this.adsTracker.state.isBuffering=!1):i=this.adsTracker.state.totalAdTime()??0),this.state.setStartupTime(i),this.sendVideoAction(e,t)}this.startHeartbeat(),this.state.goHeartbeat()}}sendEnd(t){if(this.state.goEnd()){let e;t=t||{},this.isAd()?(e=v.Events.AD_END,t.timeSinceAdRequested=this.state.timeSinceRequested.getDeltaTime(),t.timeSinceAdStarted=this.state.timeSinceStarted.getDeltaTime(),this.parentTracker&&(this.parentTracker.state.isPlaying=!0),this.state.stopAdsTime()):(e=v.Events.CONTENT_END,t.timeSinceRequested=this.state.timeSinceRequested.getDeltaTime(),t.timeSinceStarted=this.state.timeSinceStarted.getDeltaTime()),this.stopHeartbeat(),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.parentTracker&&this.isAd()&&this.parentTracker.state.goLastAd(),this.state.goViewCountUp(),this.state.totalPlaytime=0,this.isAd()||(this.adsTracker&&this.adsTracker.state.clearTotalAdsTime(),this.state.resetViewIdTrackedState())}}sendPause(t){if(this.state.goPause()){let e=this.isAd()?v.Events.AD_PAUSE:v.Events.CONTENT_PAUSE;this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendResume(t){if(this.state.goResume()){let e;t=t||{},this.isAd()?(e=v.Events.AD_RESUME,t.timeSinceAdPaused=this.state.timeSincePaused.getDeltaTime()):(e=v.Events.CONTENT_RESUME,t.timeSincePaused=this.state.timeSincePaused.getDeltaTime()),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendBufferStart(t){if(this.state.goBufferStart()){let e;t=t||{},e=this.isAd()?v.Events.AD_BUFFER_START:v.Events.CONTENT_BUFFER_START,t=this.buildBufferAttributes(t),this._lastBufferType=t.bufferType,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendBufferEnd(t){if(this.state.goBufferEnd()){let e;t=t||{},this.isAd()?(e=v.Events.AD_BUFFER_END,t.timeSinceAdBufferBegin=this.state.timeSinceBufferBegin.getDeltaTime()):(e=v.Events.CONTENT_BUFFER_END,t.timeSinceBufferBegin=this.state.timeSinceBufferBegin.getDeltaTime()),t=this.buildBufferAttributes(t),null!=this._lastBufferType&&(t.bufferType=this._lastBufferType),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.state.initialBufferingHappened=!0}}buildBufferAttributes(t){return null==t.timeSinceStarted||t.timeSinceStarted<100?t.isInitialBuffering=!this.state.initialBufferingHappened:t.isInitialBuffering=!1,t.bufferType=this.state.calculateBufferType(t.isInitialBuffering),t.timeSinceResumed=this.state.timeSinceResumed.getDeltaTime(),t.timeSinceSeekEnd=this.state.timeSinceSeekEnd.getDeltaTime(),t}sendSeekStart(t){if(this.state.goSeekStart()){let e;e=this.isAd()?v.Events.AD_SEEK_START:v.Events.CONTENT_SEEK_START,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendSeekEnd(t){if(this.state.goSeekEnd()){let e;t=t||{},this.isAd()?(e=v.Events.AD_SEEK_END,t.timeSinceAdSeekBegin=this.state.timeSinceSeekBegin.getDeltaTime()):(e=v.Events.CONTENT_SEEK_END,t.timeSinceSeekBegin=this.state.timeSinceSeekBegin.getDeltaTime()),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendDownload(t){(t=t||{}).state||r.A.warn("Called sendDownload without { state: xxxxx }."),this.sendVideoAction(v.Events.DOWNLOAD,t),this.state.goDownload()}sendError(t){(t=t||{}).isAd=this.isAd(),this.state.goError();let e=this.isAd()?v.Events.AD_ERROR:v.Events.CONTENT_ERROR;this.sendVideoErrorAction(e,t)}sendRenditionChanged(t){let e;(t=t||{}).timeSinceLastRenditionChange=this.state.timeSinceLastRenditionChange.getDeltaTime(),t.shift=this.getRenditionShift(!0),e=this.isAd()?v.Events.AD_RENDITION_CHANGE:v.Events.CONTENT_RENDITION_CHANGE,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.state.goRenditionChange()}sendHeartbeat(t){if(this.state.isRequested){let e,i=this.getHeartbeat();this.state._hb=!0,i=this.adjustElapsedTimeForPause(i),this.isAd()?(e=v.Events.AD_HEARTBEAT,"bitmovin-ads"===this.getPlayerName()?this.sendVideoAdAction(e,t):this.sendVideoAdAction(e,{elapsedTime:i,...t})):(e=v.Events.CONTENT_HEARTBEAT,this.sendVideoAction(e,{elapsedTime:i,...t})),this.state.goHeartbeat()}}adjustElapsedTimeForPause(t){return this.state._acc&&(t-=this.state._acc,this.state._acc=0),this.state.isPaused&&((t-=this.state.elapsedTime.getDeltaTime())<10&&(t=0),this.state.elapsedTime.start()),this.state._bufferAcc?(t-=this.state._bufferAcc,this.state._bufferAcc=0):this.state.isBuffering&&((t-=this.state.bufferElapsedTime.getDeltaTime())<5&&(t=0),this.state.bufferElapsedTime.start()),Math.max(0,t)}sendAdBreakStart(t){this.isAd()&&this.state.goAdBreakStart()&&(this.state.totalAdPlaytime=0,this.parentTracker&&(this.parentTracker.state.isPlaying=!1),this.sendVideoAdAction(v.Events.AD_BREAK_START,t))}sendAdBreakEnd(t){this.isAd()&&this.state.goAdBreakEnd()&&((t=t||{}).timeSinceAdBreakBegin=this.state.timeSinceAdBreakStart.getDeltaTime(),this.sendVideoAdAction(v.Events.AD_BREAK_END,t),this.parentTracker&&(this.parentTracker.state.isPlaying=!0),this.stopHeartbeat(),this.parentTracker&&this.isAd()&&this.parentTracker.state.goLastAd())}sendAdQuartile(t){this.isAd()&&((t=t||{}).quartile||r.A.warn("Called sendAdQuartile without { quartile: xxxxx }."),t.timeSinceLastAdQuartile=this.state.timeSinceLastAdQuartile.getDeltaTime(),this.sendVideoAdAction(v.Events.AD_QUARTILE,t),this.state.goAdQuartile())}sendAdClick(t){this.isAd()&&((t=t||{}).url||r.A.warn("Called sendAdClick without { url: xxxxx }."),this.sendVideoAdAction(v.Events.AD_CLICK,t))}}function y(t){t.type!==v.Events.AD_ERROR?this.sendVideoAdAction(t.type,t.data):this.sendVideoErrorAction(t.type,t.data)}v.Events={PLAYER_READY:"PLAYER_READY",DOWNLOAD:"DOWNLOAD",ERROR:"ERROR",CONTENT_REQUEST:"CONTENT_REQUEST",CONTENT_START:"CONTENT_START",CONTENT_END:"CONTENT_END",CONTENT_PAUSE:"CONTENT_PAUSE",CONTENT_RESUME:"CONTENT_RESUME",CONTENT_SEEK_START:"CONTENT_SEEK_START",CONTENT_SEEK_END:"CONTENT_SEEK_END",CONTENT_BUFFER_START:"CONTENT_BUFFER_START",CONTENT_BUFFER_END:"CONTENT_BUFFER_END",CONTENT_HEARTBEAT:"CONTENT_HEARTBEAT",CONTENT_RENDITION_CHANGE:"CONTENT_RENDITION_CHANGE",CONTENT_ERROR:"CONTENT_ERROR",AD_REQUEST:"AD_REQUEST",AD_START:"AD_START",AD_END:"AD_END",AD_PAUSE:"AD_PAUSE",AD_RESUME:"AD_RESUME",AD_SEEK_START:"AD_SEEK_START",AD_SEEK_END:"AD_SEEK_END",AD_BUFFER_START:"AD_BUFFER_START",AD_BUFFER_END:"AD_BUFFER_END",AD_HEARTBEAT:"AD_HEARTBEAT",AD_RENDITION_CHANGE:"AD_RENDITION_CHANGE",AD_ERROR:"AD_ERROR",AD_BREAK_START:"AD_BREAK_START",AD_BREAK_END:"AD_BREAK_END",AD_QUARTILE:"AD_QUARTILE",AD_CLICK:"AD_CLICK"};const p=v;var R=i(431),_=i(413),B=i(28),b=i(374);const D={Constants:n.A,Chrono:f.A,Log:r.A,Emitter:T.A,Tracker:o.A,VideoTracker:p,VideoTrackerState:E,Core:m,version:S.rE,NrVideoEventAggregator:R.t,RetryQueueHandler:_.u,OptimizedHttpClient:B.X,HarvestScheduler:b.n,recordEvent:d};module.exports.nrvideo=s})();
|
|
2
|
+
(()=>{"use strict";var t={28(t,e,i){i.d(e,{X:()=>a});var s=i(347),r=i(144);class a{async send(t,e){const{url:i,payload:s,options:a={}}=t;try{if(!i||!s)throw new Error("URL and payload are required");const t={url:i,payload:s,options:a,callback:e};await this.executeRequest(t)}catch(t){r.A.error("Failed to send request:",t.message),e({retry:!1,status:0,error:t.message})}}async executeRequest(t){const{url:e,payload:i,options:s,callback:r}=t,a=Date.now();try{const r=JSON.stringify(i.body);if(s.isFinalHarvest&&navigator.sendBeacon){const i=await this.sendWithBeacon(e,r),s={success:i,status:i?204:0};return void this.handleRequestComplete(t,s,a)}const n=await this.fetchWithTimeout(e,{method:"POST",body:r,headers:{"Content-Type":"application/json"},keepalive:s.isFinalHarvest},1e4),o={success:n.ok,status:n.status,statusText:n.statusText};this.handleRequestComplete(t,o,a)}catch(e){const i={success:!1,status:0,error:e.message};this.handleRequestComplete(t,i,a)}}handleRequestComplete(t,e){const{callback:i}=t;i({retry:!e.success&&(0===e.status||(0,s.Sc)(e.status)),status:e.status,error:e.error})}async sendWithBeacon(t,e){try{return navigator.sendBeacon(t,e)}catch(t){return r.A.warn("sendBeacon failed, falling back to fetch:",t.message),!1}}async fetchWithTimeout(t,e,i){const s=new AbortController,r=setTimeout(()=>s.abort(),i);try{const i=await fetch(t,{...e,signal:s.signal});return clearTimeout(r),i}catch(t){if(clearTimeout(r),"AbortError"===t.name)throw new Error(`Request timeout after ${i}ms`);throw t}}}},51(t,e,i){i.d(e,{A:()=>r});class s{}s.AdPositions={PRE:"pre",MID:"mid",POST:"post"},s.COLLECTOR={US:["bam.nr-data.net","bam-cell.nr-data.net"],EU:"bam.eu01.nr-data.net",Staging:"staging-bam-cell.nr-data.net",GOV:"gov-bam.nr-data.net"},s.VALID_EVENT_TYPES=["VideoAction","VideoAdAction","VideoErrorAction","VideoCustomAction"],s.MAX_PAYLOAD_SIZE=1048576,s.MAX_BEACON_SIZE=61440,s.MAX_EVENTS_PER_BATCH=1e3,s.INTERVAL=1e4,s.QOE_AGGREGATE_KEYS=["coreVersion","instrumentation.name","instrumentation.provider","instrumentation.version","isBackgroundEvent","playerName","playerVersion","src","viewId","viewSession","contentIsAutoplayed","contentIsMuted","contentRenditionHeight","contentRenditionWidth","contentSrc","numberOfVideos","pageUrl","trackerName","trackerVersion","contentDuration","contentPlayrate","contentPlayhead","contentPreload","elapsedTime","contentTitle","contentId","contentIsLive","deviceType","deviceGroup","deviceManufacturer","deviceModel","deviceName","deviceSize","deviceUuid","contentRenditionName","contentIsFullscreen","contentCdn","contentFps","asnOrganization","asnLongitude","asnLatitude","asn","timeSinceRequested","timeSinceStarted"];const r=s},144(t,e,i){i.d(e,{A:()=>o});class s{static error(...t){r(t,s.Levels.ERROR,"darkred")}static warn(...t){r(t,s.Levels.WARNING,"darkorange")}static notice(...t){r([].slice.call(arguments),s.Levels.NOTICE,"darkcyan")}static debug(...t){r(t,s.Levels.DEBUG,"indigo")}static debugCommonVideoEvents(t,e,i){try{if(s.level<=s.Levels.DEBUG){i=i||function(t){s.debug("Event: "+t.type)};var r=["canplay","buffering","waiting","ended","play","playing","pause","resume","error","abort","seek","seeking","seeked","stalled","dispose","loadeddata","loadstart","loadedmetadata"];e&&(null===e[0]?(e.shift(),r=e):r=r.concat(e));for(var a=0;a<r.length;a++)"function"==typeof t?t.call(window,r[a],i):t.on?t.on(r[a],i):t.addEventListener?t.addEventListener(r[a],i):t.addEventHandler?t.addEventHandler(r[a],i):s.warn("debugCommonVideoEvents: No common listener function found for ",t)}}catch(t){s.warn(t)}}}function r(t,e,i){e=e||s.Levels.NOTICE,i=i||"darkcyan";var r,o,h=s.prefix;s.includeTime&&(h+="["+("0"+(r=new Date).getDate()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2)+"."+("00"+r.getMilliseconds()).slice(-3)+"] "),h+=function(t){return n[t]}(e)+":",s.level<=e&&e!==s.Levels.SILENT&&(!s.colorful||"undefined"!=typeof document&&document.documentMode?a(t,h):(o=e===s.Levels.ERROR&&console.error?console.error:e===s.Levels.WARNING&&console.warn?console.warn:e===s.Levels.DEBUG&&console.debug&&null==window.cast?console.debug:console.log,h="%c"+h,t.splice(0,0,h,"color: "+i),o.apply(console,t)))}function a(t,e){if(t instanceof Array)for(var i in t)a(t[i],e);else"string"==typeof t?console.log(e+" "+t):(console.log(e+"↵"),console.log(t))}s.Levels={SILENT:5,ERROR:4,WARNING:3,NOTICE:2,DEBUG:1,ALL:0},s.level=s.Levels.ERROR,s.colorful=!0,s.includeTime=!0,s.prefix="[nrvideo]";const n={4:"e",3:"w",2:"n",1:"d"};!function(){if("undefined"!=typeof window&&window.location&&window.location.search){var t=/\?.*&*nrvideo-debug=(.+)/i.exec(window.location.search);null!==t&&("true"===t[1]?s.level=s.Levels.ALL:s.level=t[1]),null!==/\?.*&*nrvideo-colors=false/i.exec(window.location.search)&&(s.colorful=!1)}}();const o=s},302(t,e,i){i.d(e,{A:()=>l});var s=i(330),r=i(568),a=i(455),n=i(51),o=i(487),h=i(144);class d extends r.A{constructor(t){super(),this.customData={},this.heartbeat=null,this.parentTracker=null,this._trackerReadyChrono=new a.A,this._trackerReadyChrono.start(),this._actionTable=n.A.ACTION_TABLE,this._actionAdTable=n.A.ACTION_AD_TABLE,t=t||{},this.setOptions(t)}setOptions(t){t&&(t.parentTracker&&(this.parentTracker=t.parentTracker),t.customData&&(this.customData=t.customData),t.heartbeat&&(this.heartbeat=t.heartbeat))}dispose(){this.unregisterListeners()}registerListeners(){}unregisterListeners(){}getHeartbeat(){return this.state._isAd?2e3:this.heartbeat?this.heartbeat:this.parentTracker&&this.parentTracker.heartbeat?this.parentTracker.heartbeat:3e4}startHeartbeat(){this._heartbeatInterval=setInterval(this.sendHeartbeat.bind(this),Math.max(this.getHeartbeat(),2e3))}stopHeartbeat(){this._heartbeatInterval&&clearInterval(this._heartbeatInterval)}sendHeartbeat(t){this.sendVideoAction(d.Events.HEARTBEAT,t)}getAttributes(t,e){(t=t||{}).trackerName=this.getTrackerName(),t.trackerVersion=this.getTrackerVersion(),t.coreVersion=s.rE,t.timeSinceTrackerReady=this._trackerReadyChrono.getDeltaTime();for(let e in this.customData)t[e]=this.customData[e];return null!=document.hidden&&(t.isBackgroundEvent=document.hidden),t}getTrackerVersion(){return s.rE}getTrackerName(){return"base-tracker"}sendVideoAction(t,e){this.emit("VideoAction",t,this.getAttributes(e))}sendVideoAdAction(t,e){this.emit("VideoAdAction",t,this.getAttributes(e))}sendVideoErrorAction(t,e){let i=this.isAd()?"adError":"videoError";this.emit("VideoErrorAction",t,this.getAttributes(e,i))}sendVideoCustomAction(t,e){this.emit("VideoCustomAction",t,this.getAttributes(e,"customAction"))}setHarvestInterval(t){if(o.videoAnalyticsHarvester)try{o.videoAnalyticsHarvester.setHarvestInterval(t)}catch(t){return void h.A.error("Failed to set harvest interval:",t.message)}else h.A.error("VideoAnalyticsHarvester is not available")}}d.Events={HEARTBEAT:"HEARTBEAT",QOE_AGGREGATE:"QOE_AGGREGATE"};const l=d},330(t){t.exports={rE:"4.1.1"}},347(t,e,i){i.d(e,{Q3:()=>n,Sc:()=>o,c$:()=>a,z8:()=>h});var s=i(330),r=i(144);function a(t){try{if(!window.NRVIDEO||!window.NRVIDEO.info)throw new Error("NRVIDEO info is not available.");let{beacon:e,licenseKey:i,applicationID:r}=window.NRVIDEO.info;if(!e||!i)throw new Error("Options object provided by New Relic is not correctly initialized");return r?`https://${t||e}/ins/1/${i}?a=${r}&v=${s.rE}&ref=${window.location.href}&ca=VA`:`https://${t||e}/ins/1/${i}?&v=${s.rE}&ref=${window.location.href}&ca=VA`}catch(t){return console.error(t.message),null}}function n(t){if("string"==typeof t&&t.length)return t.length;if("object"==typeof t){if("undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer&&t.byteLength)return t.byteLength;if("undefined"!=typeof Blob&&t instanceof Blob&&t.size)return t.size;if(!("undefined"!=typeof FormData&&t instanceof FormData))try{return function(t){try{return JSON.stringify(t,(()=>{const t=new WeakSet;return(e,i)=>{if("object"==typeof i&&null!==i){if(t.has(i))return;t.add(i)}return i}})())??""}catch(t){return r.A.error("Error stringifying value:",t.message),""}}(t).length}catch(t){return}}}function o(t){switch(t){case 408:case 429:case 500:return!0;case 401:case 403:case 404:return!1}return t>=502&&t<=504||t>=512&&t<=530}function h(t,e){return t&&Array.isArray(t)&&0!==t.length?e&&"object"==typeof e?t.reduce((t,i)=>(i in e&&(t[i]=e[i]),t),{}):{}:e}},374(t,e,i){i.d(e,{n:()=>d});var s=i(431),r=i(413),a=i(28),n=i(347),o=i(51),h=i(144);class d{constructor(t){this.eventBuffer=t,this.retryQueueHandler=new r.u,this.httpClient=new a.X,this.fallBackUrl="",this.retryCount=0,this.eventBuffer instanceof s.t&&this.eventBuffer.setSmartHarvestCallback((t,e)=>this.triggerSmartHarvest(t,e)),this.isStarted=!1,this.currentTimerId=null,this.harvestCycle=o.A.INTERVAL,this.isHarvesting=!1,this.qoeCycleCount=1,this.setupPageLifecycleHandlers()}startScheduler(){this.isStarted?h.A.warn("Harvest scheduler is already started"):(this.isStarted=!0,h.A.notice("Starting harvest scheduler",{harvestCycle:this.harvestCycle,eventBufferSize:this.eventBuffer?this.eventBuffer.size():0}),this.scheduleNextHarvest())}stopScheduler(){this.isStarted&&(this.isStarted=!1,this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null),h.A.notice("Harvest scheduler stopped"))}async triggerSmartHarvest(t,e){if(h.A.notice(`${t} harvest triggered at ${e}% threshold`,{type:t,threshold:e}),this.eventBuffer&&!this.eventBuffer.isEmpty()){this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null);try{await this.triggerHarvest({})}catch(e){h.A.error(`${t} harvest failed:`,e.message)}finally{this.isStarted&&this.scheduleNextHarvest()}}}scheduleNextHarvest(){if(!this.isStarted)return;const t=this.harvestCycle;this.currentTimerId=setTimeout(()=>this.onHarvestInterval(),t)}async onHarvestInterval(){try{const t=this.eventBuffer&&!this.eventBuffer.isEmpty(),e=this.retryQueueHandler&&this.retryQueueHandler.getQueueSize()>0;if(!t&&!e)return;await this.triggerHarvest({})}catch(t){h.A.error("Error during scheduled harvest:",t.message)}finally{this.scheduleNextHarvest()}}async triggerHarvest(t={}){if(this.isHarvesting)return{success:!1,reason:"harvest_in_progress"};this.isHarvesting=!0;try{let e=this.drainEvents(t);if(t.isFinalHarvest){const t=o.A.MAX_BEACON_SIZE;(0,n.Q3)(e)>t&&(e=this.trimEventsToFit(e,t))}const i=await this.sendChunk(e,t,!0);return{success:i.success,totalChunks:1,results:[i]}}catch(t){return h.A.error("Harvest cycle failed:",t.message),this.handleHarvestFailure(t),{success:!1,error:t.message,consecutiveFailures:this.consecutiveFailures}}finally{this.isHarvesting=!1}}trimEventsToFit(t,e){if(0===t.length)return t;const i=[];let s=0;for(let r=t.length-1;r>=0;r--){const a=t[r],o=(0,n.Q3)({ins:[a,...i]});o>e||(i.unshift(a),s=o)}const r=t.length-i.length;if(r>0){const a=t.slice(0,r);h.A.warn(`Discarded ${r} events to fit beacon size limit`,{originalCount:t.length,trimmedCount:i.length,finalSize:s,maxSize:e}),this.retryQueueHandler&&this.retryQueueHandler.addFailedEvents(a)}return i}drainEvents(t={}){const e=window.NRVIDEO?.config?.qoeIntervalFactor??1,i=(this.qoeCycleCount-1)%e==0||!!t.isFinalHarvest,s=this.eventBuffer.drain(),r=i?s:s.filter(t=>"QOE_AGGREGATE"!==t.actionName);this.qoeCycleCount++;let a=[...r],h=(0,n.Q3)(r);if(this.retryQueueHandler&&this.retryQueueHandler.getQueueSize()>0){const t=o.A.MAX_PAYLOAD_SIZE-h,e=o.A.MAX_EVENTS_PER_BATCH-a.length;if(t>0&&e>0){const i=this.retryQueueHandler.getRetryEventsToFit(t,e);i.length>0&&(a=[...i,...a])}}return a}async sendChunk(t,e,i){const s={url:(0,n.c$)(this.fallBackUrl),payload:{body:{ins:t}},options:{...e,isLastChunk:i}};return new Promise(e=>{this.httpClient.send(s,i=>{i.retry?this.handleRequestFailure(t):(this.retryCount=0,this.fallBackUrl=""),e({success:!i.retry,status:i.status,error:i.error,chunk:t,eventCount:t.length})})})}handleRequestFailure(t){this.retryQueueHandler.addFailedEvents(t),"US"===window.NRVIDEO?.info?.region&&(this.retryCount++,this.retryCount>5?(this.retryCount=0,this.fallBackUrl=""):this.retryCount>=2&&(this.fallBackUrl=o.A.COLLECTOR.US[1]))}handleHarvestFailure(t){this.consecutiveFailures++,h.A.warn("Harvest failure handled",{error:t.message,consecutiveFailures:this.consecutiveFailures})}updateHarvestInterval(t){"number"!=typeof t&&isNaN(t)?h.A.warn("Invalid newInterval provided to updateHarvestInterval"):t<1e3||t>3e5?h.A.warn("newInterval out of bounds (1000-300000), ignoring"):this.harvestCycle!==t&&(this.harvestCycle=t,h.A.notice("Updated harvestCycle:",this.harvestCycle),this.currentTimerId&&(clearTimeout(this.currentTimerId),this.currentTimerId=null),this.isStarted&&this.scheduleNextHarvest())}setupPageLifecycleHandlers(){let t=!1;const e=()=>{t||(t=!0,this.triggerHarvest({isFinalHarvest:!0,force:!0}))};document.addEventListener("visibilitychange",()=>{document.hidden&&e()}),window.addEventListener("pagehide",()=>{e()}),window.addEventListener("beforeunload",()=>{e()})}}},413(t,e,i){i.d(e,{u:()=>h});var s=i(144),r=i(347),a=i(51);const{MAX_PAYLOAD_SIZE:n,MAX_EVENTS_PER_BATCH:o}=a.A;class h{constructor(){this.retryQueue=[],this.maxQueueSize=o,this.maxQueueSizeBytes=n}addFailedEvents(t){try{const e=Array.isArray(t)?t:[t];s.A.notice(`Adding ${e.length} failed events to retry queue`,{queueSizeBefore:this.retryQueue.length});for(const t of e){this.retryQueue.length>=this.maxQueueSize&&this.evictOldestEvent();const e=(0,r.Q3)(t);for(;(0,r.Q3)(this.retryQueue)+e>this.maxQueueSizeBytes;)this.evictOldestEvent();this.retryQueue.push({...t})}}catch(t){s.A.error("Failed to add events to retry queue:",t.message)}}discardEvent(t,e){s.A.warn("Discarded event",{reason:e,eventType:t.eventType})}evictOldestEvent(){if(this.retryQueue.length>0){const t=this.retryQueue.shift();this.discardEvent(t,"Queue full - evicted oldest")}}getRetryEventsToFit(t,e){const i=[];let s=0,a=0;for(let n=this.retryQueue.length-1;n>=0;n--){const o=this.retryQueue[n];if(a>=e)break;const h=(0,r.Q3)(o);if(s+h>t)break;i.unshift(o),s+=h,a++,this.retryQueue.splice(n,1)}return i}getQueueSize(){return this.retryQueue.length}clear(){this.retryQueue=[]}}},431(t,e,i){i.d(e,{t:()=>h});var s=i(144),r=i(51),a=i(347);const{MAX_PAYLOAD_SIZE:n,MAX_EVENTS_PER_BATCH:o}=r.A;class h{constructor(){this.buffer=[],this.maxPayloadSize=n,this.maxEventsPerBatch=o,this.currentPayloadSize=0,this.totalEvents=0,this.smartHarvestPayloadThreshold=Math.floor(.6*this.maxPayloadSize),this.overflowPayloadThreshold=Math.floor(.9*this.maxPayloadSize),this.smartHarvestEventThreshold=Math.floor(.6*this.maxEventsPerBatch),this.overflowEventThreshold=Math.floor(.9*this.maxEventsPerBatch),this.onSmartHarvestTrigger=null}addOrReplaceByActionName(t,e){const i=this.buffer.findIndex(e=>e.actionName===t);try{return-1===i?this.add(e):this.add(e,i),!0}catch(t){return s.A.error("Failed to set or replace the event to buffer:",t.message),!1}}add(t,e){try{const i=(0,a.Q3)(t),s=this.currentPayloadSize+i>=this.maxPayloadSize,r=this.totalEvents+1>=this.maxEventsPerBatch;if((s||r)&&this.makeRoom(i),null!=e&&e>-1){const s=(0,a.Q3)(this.buffer[e]);this.buffer[e]=t,this.currentPayloadSize+=i-s}else this.buffer.push(t),this.totalEvents++,this.currentPayloadSize+=i;return this.checkSmartHarvestTrigger(),!0}catch(t){return s.A.error("Failed to add event to buffer:",t.message),!1}}checkSmartHarvestTrigger(){const t=this.currentPayloadSize/this.maxPayloadSize,e=this.totalEvents/this.maxEventsPerBatch,i=this.currentPayloadSize>=this.overflowPayloadThreshold,r=this.totalEvents>=this.overflowEventThreshold;if(i||r){const r=i?`payload ${this.currentPayloadSize}/${this.maxPayloadSize} bytes (${Math.round(100*t)}%)`:`events ${this.totalEvents}/${this.maxEventsPerBatch} (${Math.round(100*e)}%)`;s.A.warn(`OVERFLOW PREVENTION: ${r} - Emergency harvest triggered`),this.onSmartHarvestTrigger&&"function"==typeof this.onSmartHarvestTrigger&&this.onSmartHarvestTrigger("overflow",90)}else{const t=this.currentPayloadSize>=this.smartHarvestPayloadThreshold,e=this.totalEvents>=this.smartHarvestEventThreshold;(t||e)&&this.onSmartHarvestTrigger&&"function"==typeof this.onSmartHarvestTrigger&&this.onSmartHarvestTrigger("smart",60)}}setSmartHarvestCallback(t){this.onSmartHarvestTrigger=t}drain(){try{const t=this.buffer.splice(0);return this.totalEvents=0,this.currentPayloadSize=0,t}catch(t){return s.A.error("Failed to drain events from buffer:",t.message),[]}}isEmpty(){return 0===this.totalEvents}size(){return this.totalEvents}clear(){this.buffer=[],this.totalEvents=0}makeRoom(t){if(t>this.maxPayloadSize)s.A.error("Event dropped: Event size exceeds maximum payload size.");else for(;(this.totalEvents>=this.maxEventsPerBatch||this.currentPayloadSize+t>=this.maxPayloadSize)&&this.buffer.length>0;){const t=this.buffer.shift(),e=(0,a.Q3)(t);this.totalEvents--,this.currentPayloadSize-=e,s.A.warn("Event buffer full, oldest event removed.")}}}},455(t,e,i){i.d(e,{A:()=>r});class s{constructor(){this.reset()}reset(){this.startTime=0,this.stopTime=0,this.accumulator=0,this.offset=0}getDeltaTime(){return this.startTime?this.offset+((new Date).getTime()-this.startTime):null}start(){this.startTime=(new Date).getTime(),this.stopTime=0}stop(){return this.stopTime=(new Date).getTime(),this.startTime<this.stopTime&&(this.accumulator+=this.stopTime-this.startTime),this.getDeltaTime()}getDuration(){return this.stopTime?this.accumulator+this.offset:this.accumulator+(this.getDeltaTime()??0)}clone(){var t=new s;return t.startTime=this.startTime,t.stopTime=this.stopTime,t.offset=this.offset,t.accumulator=this.accumulator,t}}const r=s},487(t,e,i){i.r(e),i.d(e,{videoAnalyticsHarvester:()=>o});var s=i(374),r=i(431),a=i(144),n=i(302);const o=new class{constructor(){this.isInitialized=!1,this.harvestScheduler=null,this.eventBuffer=null}initialize(){if(this.isInitialized)a.A.warn("Video analytics agent already initialized");else try{this.eventBuffer=new r.t,this.harvestScheduler=new s.n(this.eventBuffer),this.harvestScheduler.startScheduler(),this.isInitialized=!0,a.A.notice("Video analytics agent initialized successfully")}catch(t){a.A.error("Failed to initialize video analytics agent:",t.message)}}addEvent(t){this.isInitialized||(a.A.warn("Video analytics agent not initialized, initializing now"),this.initialize());try{return t.actionName&&t.actionName===n.A.Events.QOE_AGGREGATE?this.eventBuffer.addOrReplaceByActionName(n.A.Events.QOE_AGGREGATE,t):this.eventBuffer.add(t)}catch(t){return a.A.error("Failed to add event to harvesting system:",t.message),!1}}setHarvestInterval(t){this.isInitialized||this.initialize(),this.harvestScheduler.updateHarvestInterval(t)}}},568(t,e,i){i.d(e,{A:()=>s});const s=class{on(t,e){if(this._listeners=this._listeners||{},"function"==typeof e)return this._listeners[t]=this._listeners[t]||[],this._listeners[t].push(e),this}off(t,e){if(this._listeners=this._listeners||{},this._listeners[t]){var i=this._listeners[t].indexOf(e);-1!==i&&this._listeners[t].splice(i,1)}return this}emit(t,e,i){return this._listeners=this._listeners||{},i=i||{},Array.isArray(this._listeners[e])&&this._listeners[e].forEach(s=>{s.call(this,{eventType:t,type:e,data:i,target:this})}),Array.isArray(this._listeners["*"])&&this._listeners["*"].forEach(s=>{s.call(this,{eventType:t,type:e,data:i,target:this})}),this}}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var a=e[s]={exports:{}};return t[s](a,a.exports,i),a.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{default:()=>D});var r=i(144),a=i(487),n=i(51),o=i(302),h=i(347);function d(t,e={}){try{if(!n.A.VALID_EVENT_TYPES.includes(t))return r.A.warn("Invalid event type provided to recordEvent",{eventType:t}),!1;if(!window?.NRVIDEO?.info)return;const{appName:i,applicationID:s}=window.NRVIDEO.info,{qoe:d,...l}=e,c=d?{...d}:{},u={...s?{}:{appName:i},timestamp:Date.now(),timeSinceLoad:window.performance?window.performance.now()/1e3:null},A={...l,eventType:t,...u},g=(0,h.z8)(n.A.QOE_AGGREGATE_KEYS,e);let m=null;"VideoAction"===t&&(m={eventType:"VideoAction",actionName:o.A.Events.QOE_AGGREGATE,qoeAggregateVersion:"1.0.0",...c,...g,...u});const f=a.videoAnalyticsHarvester.addEvent(A);if(m&&window?.NRVIDEO?.config?.qoeAggregate){const t=a.videoAnalyticsHarvester.addEvent(m);return f&&t}return f}catch(t){return r.A.error("Failed to record event:",t.message),!1}}const{COLLECTOR:l}=n.A;const c=new class{setConfiguration(t,e){return!!this.validateRequiredFields(t)&&!!this.validateConfigFields(e)&&(this.initializeGlobalConfig(t,e),r.A.notice("Video analytics configuration initialized successfully"),!0)}validateRequiredFields(t){if(!t||"object"!=typeof t)return r.A.error("Configuration must be an object"),!1;const{licenseKey:e,appName:i,region:s,applicationID:a,beacon:n}=t;if(!e)return r.A.error("licenseKey is required"),!1;if(a){if(!n)return r.A.error("beacon is required when applicationID is provided"),!1;if(!Object.values(l).flatMap(t=>t).includes(n))return r.A.error(`Invalid beacon: ${n}`),!1}else{if(!i||!s)return r.A.error("appName and region are required when applicationID is not provided"),!1;if(!l[s])return r.A.error(`Invalid region: ${s}. Valid regions are: ${Object.keys(l).join(", ")}`),!1}return!0}validateConfigFields(t){if(null==t)return!0;if("object"!=typeof t||Array.isArray(t))return r.A.error("config must be an object"),!1;const{qoeAggregate:e}=t;return void 0===e||"boolean"==typeof e||(r.A.error("qoeAggregate must be a boolean"),!1)}sanitizeQoeIntervalFactor(t){return null==t?1:"number"==typeof t&&Number.isInteger(t)&&t>=1?t:(console.warn(`[nrvideo] Invalid qoeIntervalFactor "${t}" — must be a positive integer. Defaulting to 1.`),1)}initializeGlobalConfig(t,e){let{licenseKey:i,appName:s,region:r,beacon:a,applicationID:o}=t;a="US"===r?n.A.COLLECTOR.US[0]:a||l[r],window.NRVIDEO={info:{...r?{region:r}:{},beacon:a,licenseKey:i,applicationID:o,...o?{}:{appName:s}},config:{qoeAggregate:e?.qoeAggregate??!1,qoeIntervalFactor:this.sanitizeQoeIntervalFactor(e?.qoeIntervalFactor)}}}};class u{static addTracker(t,e){var i,s;e?.info&&(i=e.info,s=e?.config,c.setConfiguration(i,s)),t.on&&t.emit?(A.push(t),t.on("*",g),"function"==typeof t.trackerInit&&t.trackerInit()):r.A.error("Tried to load a non-tracker.",t)}static removeTracker(t){t.off("*",g),t.dispose();let e=A.indexOf(t);-1!==e&&A.splice(e,1)}static getTrackers(){return A}static send(t,e,i){return d(t,{actionName:e,...i})}static sendError(t){return d("VideoErrorAction",{actionName:"ERROR",...t})}static async forceHarvest(){try{const{videoAnalyticsHarvester:t}=i(487);return await t.forceHarvest()}catch(t){return r.A.error("Failed to force harvest:",t.message),{success:!1,error:t.message}}}}let A=[];function g(t){try{let e=function(t){let e={};for(let i in t)null!==t[i]&&void 0!==t[i]&&(e[i]=t[i]);return e}(t.data);r.A.level<=r.A.Levels.DEBUG?r.A.notice("Sent",t.type,e):r.A.notice("Sent",t.type),u.send(t.eventType,t.type,e)}catch(t){r.A.error("Error in event handler:",t.message)}}const m=u;var f=i(455),T=i(568);const E=class{constructor(){this.reset(),this._createdAt=Date.now(),this._hb=!0,this._acc=0,this._bufferAcc=0}reset(){this._viewSession=null,this._viewCount=0,this._isAd=!1,this.numberOfErrors=0,this.numberOfAds=0,this.numberOfVideos=0,this.totalPlaytime=0,this.weightedAverageBitrate=0,this.totalAdPlaytime=0,this.isAdBreak=!1,this.initialBufferingHappened=!1,this.startupTime=null,this.peakBitrate=0,this._lastBitrate=null,this._lastBitrateChangeTimestamp=null,this.partialAverageBitrate=0,this.hadStartupFailure=!1,this.hadPlaybackFailure=!1,this.totalRebufferingTime=0,this.resetFlags(),this.resetChronos()}resetFlags(){this.isPlayerReady=!1,this.isRequested=!1,this.isStarted=!1,this.isPaused=!1,this.isSeeking=!1,this.isBuffering=!1,this.isPlaying=!1}resetChronos(){this.timeSinceRequested=new f.A,this.timeSinceStarted=new f.A,this.timeSincePaused=new f.A,this.timeSinceSeekBegin=new f.A,this.timeSinceBufferBegin=new f.A,this.timeSinceAdBreakStart=new f.A,this.timeSinceLastDownload=new f.A,this.timeSinceLastHeartbeat=new f.A,this.timeSinceLastRenditionChange=new f.A,this.timeSinceLastAdQuartile=new f.A,this.timeSinceLastAd=new f.A,this.timeSinceLastError=new f.A,this.timeSinceLastAdError=new f.A,this.timeSinceResumed=new f.A,this.timeSinceSeekEnd=new f.A,this.playtimeSinceLastEvent=new f.A,this.customTimeSinceAttributes={},this.elapsedTime=new f.A,this.bufferElapsedTime=new f.A,this._totalAdPlaytime=new f.A}isAd(){return this._isAd}setIsAd(t){this._isAd=t}setTimeSinceAttribute(t){this.customTimeSinceAttributes[t]=new f.A,this.customTimeSinceAttributes[t].start()}removeTimeSinceAttribute(t){delete this.customTimeSinceAttributes[t]}getViewSession(){if(!this._viewSession){let t=(new Date).getTime(),e=Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2);this._viewSession=t+"-"+e}return this._viewSession}getViewId(){return this.getViewSession()+"-"+this._viewCount}getStateAttributes(t){t=t||{},this.isAd()?(this.isRequested&&(t.timeSinceAdRequested=this.timeSinceRequested.getDeltaTime(),t.timeSinceLastAdHeartbeat=this.timeSinceLastHeartbeat.getDeltaTime()),this.isStarted&&(t.timeSinceAdStarted=this.timeSinceStarted.getDeltaTime()),this.isPaused&&(t.timeSinceAdPaused=this.timeSincePaused.getDeltaTime()),this.isBuffering&&(t.timeSinceAdBufferBegin=this.timeSinceBufferBegin.getDeltaTime()),this.isSeeking&&(t.timeSinceAdSeekBegin=this.timeSinceSeekBegin.getDeltaTime()),this.isAdBreak&&(t.timeSinceAdBreakBegin=this.timeSinceAdBreakStart.getDeltaTime()),this.numberOfErrors>0&&this.timeSinceLastAdError.startTime>0&&(t.timeSinceLastAdError=this.timeSinceLastAdError.getDeltaTime()),t.numberOfAds=this.numberOfAds):(this.isRequested&&(t.timeSinceRequested=this.timeSinceRequested.getDeltaTime(),t.timeSinceLastHeartbeat=this.timeSinceLastHeartbeat.getDeltaTime()),this.isStarted&&(t.timeSinceStarted=this.timeSinceStarted.getDeltaTime()),this.isPaused&&(t.timeSincePaused=this.timeSincePaused.getDeltaTime()),this.isBuffering&&(t.timeSinceBufferBegin=this.timeSinceBufferBegin.getDeltaTime()),this.isSeeking&&(t.timeSinceSeekBegin=this.timeSinceSeekBegin.getDeltaTime()),t.timeSinceLastAd=this.timeSinceLastAd.getDeltaTime(),this.numberOfErrors>0&&this.timeSinceLastError.startTime>0&&(t.timeSinceLastError=this.timeSinceLastError.getDeltaTime()),t.numberOfVideos=this.numberOfVideos),t.numberOfErrors=this.numberOfErrors,this.isAd()||(this.playtimeSinceLastEvent.startTime>0?t.playtimeSinceLastEvent=this.playtimeSinceLastEvent.getDeltaTime():t.playtimeSinceLastEvent=0,this.isPlaying?this.playtimeSinceLastEvent.start():this.playtimeSinceLastEvent.reset(),this.totalPlaytime+=t.playtimeSinceLastEvent,t.totalPlaytime=this.totalPlaytime);for(const[e,i]of Object.entries(this.customTimeSinceAttributes))t[e]=i.getDeltaTime();return t}getQoeAttributes(t){t=t||{};const e={};try{null!==this.startupTime&&(e.startupTime=this.startupTime),this.peakBitrate>0&&(e.peakBitrate=this.peakBitrate),e.hadStartupFailure=this.hadStartupFailure,e.hadPlaybackFailure=this.hadPlaybackFailure,e.totalRebufferingTime=this.totalRebufferingTime,e.rebufferingRatio=this.totalPlaytime>0?this.totalRebufferingTime/this.totalPlaytime*100:0,e.totalPlaytime=this.totalPlaytime,e.averageBitrate=this.weightedBitrate,e.numberOfErrors=this.numberOfErrors}catch(t){r.A.error("Failed to add attributes for QOE KPIs",t.message)}return t.qoe=e,t}calculateBufferType(t){let e="";return e=t?"initial":this.isSeeking?"seek":this.isPaused?"pause":"connection",r.A.debug("Buffer Type = "+e),e}goViewCountUp(){this._viewCount++}goPlayerReady(){return!this.isPlayerReady&&(this.isPlayerReady=!0,!0)}goRequest(){return!this.isRequested&&(this.isRequested=!0,this.timeSinceLastAd.reset(),this.timeSinceRequested.start(),!0)}goStart(){return!(!this.isRequested||this.isStarted||(this.isAd()?this.numberOfAds++:this.numberOfVideos++,this.isStarted=!0,this.isPlaying=!0,this.timeSinceStarted.start(),this.playtimeSinceLastEvent.start(),0))}goEnd(){return!!this.isRequested&&(this.numberOfErrors=0,this.resetFlags(),this.timeSinceRequested.stop(),this.timeSinceStarted.stop(),this.playtimeSinceLastEvent.stop(),this.isPlaying=!1,!0)}goPause(){return!(!this.isStarted||this.isPaused||(this.isPaused=!0,this.isPlaying=!1,this.timeSincePaused.start(),this.playtimeSinceLastEvent.stop(),this.timeSinceResumed.reset(),this.isBuffering&&(this._bufferAcc+=this.bufferElapsedTime.getDeltaTime()),this.elapsedTime.start(),0))}goResume(){return!(!this.isStarted||!this.isPaused||(this.isPaused=!1,this.isPlaying=!0,this.timeSincePaused.stop(),this.timeSinceResumed.start(),this._hb?(this._acc=this.elapsedTime.getDeltaTime(),this._hb=!1):(this.isBuffering&&this.bufferElapsedTime.start(),this._acc+=this.elapsedTime.getDeltaTime()),0))}goBufferStart(){return!(!this.isRequested||this.isBuffering||(this.isBuffering=!0,this.isPlaying=!1,this.timeSinceBufferBegin.start(),this.bufferElapsedTime.start(),0))}goBufferEnd(){return!(!this.isRequested||!this.isBuffering||(this.isBuffering=!1,this.isPlaying=!0,this.timeSinceBufferBegin.stop(),this._hb?(this._bufferAcc=this.bufferElapsedTime.getDeltaTime(),this._hb=!1):this._bufferAcc+=this.bufferElapsedTime.getDeltaTime(),!this.isAd()&&this.initialBufferingHappened&&(this.totalRebufferingTime+=this.timeSinceBufferBegin.getDeltaTime()),0))}goSeekStart(){return!(!this.isStarted||this.isSeeking||(this.isSeeking=!0,this.isPlaying=!1,this.timeSinceSeekBegin.start(),this.timeSinceSeekEnd.reset(),0))}goSeekEnd(){return!(!this.isStarted||!this.isSeeking||(this.isSeeking=!1,this.isPlaying=!0,this.timeSinceSeekBegin.stop(),this.timeSinceSeekEnd.start(),0))}goAdBreakStart(){return!this.isAdBreak&&(this.isAdBreak=!0,this.timeSinceAdBreakStart.start(),!0)}goAdBreakEnd(){return!!this.isAdBreak&&(this.isRequested=!1,this.isAdBreak=!1,this.totalAdPlaytime=this.timeSinceAdBreakStart.getDeltaTime(),this.timeSinceAdBreakStart.stop(),!0)}goDownload(){this.timeSinceLastDownload.start()}goHeartbeat(){this.timeSinceLastHeartbeat.start()}goRenditionChange(){this.timeSinceLastRenditionChange.start()}goAdQuartile(){this.timeSinceLastAdQuartile.start()}goError(){this.isError=!0,this.numberOfErrors++,this.isAd()?this.timeSinceLastAdError.start():(this.timeSinceLastError.start(),this.isStarted?this.hadPlaybackFailure=!0:this.hadStartupFailure=!0)}goLastAd(){this.timeSinceLastAd.start()}trackContentBitrateState(t){if(t&&"number"==typeof t&&(this.peakBitrate=Math.max(this.peakBitrate,t),null===this._lastBitrate||this._lastBitrate!==t)){const e=null===this._lastBitrateChangeTimestamp?this.totalPlaytime:Date.now()-this._lastBitrateChangeTimestamp,i=t*e;this.partialAverageBitrate+=i,this.weightedBitrate=i/e,this._lastBitrate=t,this._lastBitrateChangeTimestamp=Date.now()}}resetViewIdTrackedState(){this.peakBitrate=0,this.partialAverageBitrate=0,this.startupTime=null,this._lastBitrate=null,this._lastBitrateChangeTimestamp=null}clearTotalAdsTime(){console.log("clear total ads time",this.totalAdTime),this._totalAdPlaytime.reset()}totalAdTime(){return this._totalAdPlaytime.getDuration()}startAdsTime(){return console.log("startAdsTime"),this._totalAdPlaytime.start()}stopAdsTime(){return console.log("stopAdsTime"),this._totalAdPlaytime.stop()}setStartupTime(t){null===this.startupTime&&(this.startupTime=Math.max(this.timeSinceRequested.getDeltaTime()-t,0))}};var v=i(330);class S extends o.A{constructor(t,e){super(),this.state=new E,this.adsTracker=null,this._lastBufferType=null,this._userId=null,e=e||{},this.setOptions(e),t&&this.setPlayer(t,e.tag),r.A.notice("Tracker "+this.getTrackerName()+" v"+this.getTrackerVersion()+" is ready.")}setUserId(t){this._userId=t}setOptions(t){t&&(t.adsTracker&&this.setAdsTracker(t.adsTracker),"boolean"==typeof t.isAd&&this.setIsAd(t.isAd),o.A.prototype.setOptions.apply(this,arguments))}setPlayer(t,e){(this.player||this.tag)&&this.dispose(),"undefined"!=typeof document&&document.getElementById&&("string"==typeof t&&(t=document.getElementById(t)),"string"==typeof e&&(e=document.getElementById(e))),e=e||t,this.player=t,this.tag=e,this.registerListeners()}isAd(){return this.state.isAd()}setIsAd(t){this.state.setIsAd(t)}setAdsTracker(t){this.disposeAdsTracker(),t&&(this.adsTracker=t,this.adsTracker.setIsAd(!0),this.adsTracker.parentTracker=this,this.adsTracker.on("*",y.bind(this)))}disposeAdsTracker(){this.adsTracker&&(this.adsTracker.off("*",y),this.adsTracker.dispose())}dispose(){this.stopHeartbeat(),this.disposeAdsTracker(),this.unregisterListeners(),this.player=null,this.tag=null}registerListeners(){}unregisterListeners(){}getViewId(){return this.parentTracker?this.parentTracker.getViewId():this.state.getViewId()}getViewSession(){return this.parentTracker?this.parentTracker.getViewSession():this.state.getViewSession()}getVideoId(){return null}getTitle(){return null}isLive(){return null}getBitrate(){return null}getManifestBitrate(){return null}getMeasuredBitrate(){return null}getDownloadBitrate(){return null}getWebkitBitrate(){if(this.tag&&this.tag.webkitVideoDecodedByteCount){let t;if(this._lastWebkitBitrate){t=this.tag.webkitVideoDecodedByteCount;let e=t-this._lastWebkitBitrate,i=this.getHeartbeat()/1e3;t=Math.round(e/i*8)}return this._lastWebkitBitrate=this.tag.webkitVideoDecodedByteCount,t||null}}getRenditionName(){return null}getRenditionBitrate(){return null}getRenditionShift(t){let e,i=this.getRenditionBitrate();return this.isAd()?(e=this._lastAdRendition,t&&(this._lastAdRendition=i)):(e=this._lastRendition,t&&(this._lastRendition=i)),i&&e?i>e?"up":i<e?"down":null:null}getRenditionHeight(){return this.tag?this.tag.videoHeight:null}getRenditionWidth(){return this.tag?this.tag.videoWidth:null}getDuration(){return this.tag?this.tag.duration:null}getPlayhead(){return this.tag?this.tag.currentTime:null}getLanguage(){return null}getSrc(){return this.tag?this.tag.currentSrc:null}getPlayrate(){return this.tag?this.tag.playbackRate:null}isMuted(){return this.tag?this.tag.muted:null}isFullscreen(){return null}getCdn(){return null}getPlayerName(){return this.getTrackerName()}getPlayerVersion(){return v.rE}getFps(){return null}isAutoplayed(){return this.tag?this.tag.autoplay:null}getPreload(){return this.tag?this.tag.preload:null}getAdQuartile(){return null}getAdPosition(){return this.parentTracker?this.parentTracker.state.isStarted?"mid":"pre":null}getAdPartner(){return null}getAdCreativeId(){return null}getInstrumentationProvider(){return null}getInstrumentationName(){return null}getInstrumentationVersion(){return null}getAttributes(t,e){if(void 0===(t=o.A.prototype.getAttributes.apply(this,arguments)).isAd&&(t.isAd=this.isAd()),t.viewSession=this.getViewSession(),t.viewId=this.getViewId(),t.playerName=this.getPlayerName(),t.playerVersion=this.getPlayerVersion(),t["instrumentation.provider"]=this.getInstrumentationProvider(),t["instrumentation.name"]=this.getInstrumentationName(),t["instrumentation.version"]=this.getInstrumentationVersion(),t["enduser.id"]=this._userId,t.src="Browser","customAction"===e)return t;try{t.pageUrl=window.location.href}catch(t){}this.isAd()?(t.adId=this.getVideoId(),t.adTitle=this.getTitle(),t.adSrc=this.getSrc(),t.adCdn=this.getCdn(),this.state.isStarted&&(t.adBitrate=this.getBitrate()||this.getWebkitBitrate()||this.getRenditionBitrate(),t.adRenditionBitrate=this.getRenditionBitrate()),t.adRenditionName=this.getRenditionName(),t.adRenditionHeight=this.getRenditionHeight(),t.adRenditionWidth=this.getRenditionWidth(),t.adDuration=this.getDuration(),t.adPlayhead=this.getPlayhead(),t.adLanguage=this.getLanguage(),t.adIsMuted=this.isMuted(),t.adFps=this.getFps(),t.adPosition=this.getAdPosition(),t.adCreativeId=this.getAdCreativeId(),t.adPartner=this.getAdPartner()):(t.contentId=this.getVideoId(),t.contentTitle=this.getTitle(),t.contentSrc=this.getSrc(),t.contentCdn=this.getCdn(),t.contentPlayhead=this.getPlayhead(),t.contentIsLive=this.isLive(),this.state.isStarted&&(t.contentBitrate=this.getBitrate()||this.getWebkitBitrate()||this.getRenditionBitrate(),t.contentRenditionBitrate=this.getRenditionBitrate(),t.contentManifestBitrate=this.getManifestBitrate(),t.contentMeasuredBitrate=this.getMeasuredBitrate(),t.contentDownloadBitrate=this.getDownloadBitrate()),t.contentRenditionName=this.getRenditionName(),t.contentRenditionHeight=this.getRenditionHeight(),t.contentRenditionWidth=this.getRenditionWidth(),t.contentDuration=this.getDuration(),t.contentLanguage=this.getLanguage(),t.contentPlayrate=this.getPlayrate(),t.contentIsFullscreen=this.isFullscreen(),t.contentIsMuted=this.isMuted(),t.contentIsAutoplayed=this.isAutoplayed(),t.contentPreload=this.getPreload(),t.contentFps=this.getFps(),null!=this.adsTracker&&this.adsTracker.state.totalAdPlaytime>0&&(t.totalAdPlaytime=this.adsTracker.state.totalAdPlaytime)),this.state.getStateAttributes(t),this.state.isStarted&&!this.isAd()&&this.state.trackContentBitrateState(t.contentBitrate);for(let e in this.customData)t[e]=this.customData[e];return this.addQoeAttributes(t),t}addQoeAttributes(t){const e=(t=this.state.getQoeAttributes(t)).qoe;for(let t in this.customData)e[t]=this.customData[t]}sendCustom(t,e,i){i=i||{},this.sendVideoCustomAction(t,i),this.state.setTimeSinceAttribute(e)}sendPlayerReady(t){this.state.goPlayerReady()&&(t=t||{},this.sendVideoAction(S.Events.PLAYER_READY,t))}sendRequest(t){if(this.state.goRequest()){let e;this.isAd()?(e=S.Events.AD_REQUEST,this.sendVideoAdAction(e,t)):(e=S.Events.CONTENT_REQUEST,this.sendVideoAction(e,t))}}sendStart(t){if(this.state.goStart()){let e;if(this.isAd())e=S.Events.AD_START,this.parentTracker&&(this.parentTracker.state.isPlaying=!1),this.sendVideoAdAction(e,t),this.state.startAdsTime();else{e=S.Events.CONTENT_START;let i=0;this.adsTracker&&(this.adsTracker.state.isPlaying||this.adsTracker.state.isBuffering?(i=this.adsTracker.state.stopAdsTime(),this.adsTracker.state.isPlaying=!1,this.adsTracker.state.isBuffering=!1):i=this.adsTracker.state.totalAdTime()??0),this.state.setStartupTime(i),this.sendVideoAction(e,t)}this.startHeartbeat(),this.state.goHeartbeat()}}sendEnd(t){if(this.state.goEnd()){let e;t=t||{},this.isAd()?(e=S.Events.AD_END,t.timeSinceAdRequested=this.state.timeSinceRequested.getDeltaTime(),t.timeSinceAdStarted=this.state.timeSinceStarted.getDeltaTime(),this.parentTracker&&(this.parentTracker.state.isPlaying=!0),this.state.stopAdsTime()):(e=S.Events.CONTENT_END,t.timeSinceRequested=this.state.timeSinceRequested.getDeltaTime(),t.timeSinceStarted=this.state.timeSinceStarted.getDeltaTime()),this.stopHeartbeat(),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.parentTracker&&this.isAd()&&this.parentTracker.state.goLastAd(),this.state.goViewCountUp(),this.state.totalPlaytime=0,this.isAd()||(this.adsTracker&&this.adsTracker.state.clearTotalAdsTime(),this.state.resetViewIdTrackedState())}}sendPause(t){if(this.state.goPause()){let e=this.isAd()?S.Events.AD_PAUSE:S.Events.CONTENT_PAUSE;this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendResume(t){if(this.state.goResume()){let e;t=t||{},this.isAd()?(e=S.Events.AD_RESUME,t.timeSinceAdPaused=this.state.timeSincePaused.getDeltaTime()):(e=S.Events.CONTENT_RESUME,t.timeSincePaused=this.state.timeSincePaused.getDeltaTime()),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendBufferStart(t){if(this.state.goBufferStart()){let e;t=t||{},e=this.isAd()?S.Events.AD_BUFFER_START:S.Events.CONTENT_BUFFER_START,t=this.buildBufferAttributes(t),this._lastBufferType=t.bufferType,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendBufferEnd(t){if(this.state.goBufferEnd()){let e;t=t||{},this.isAd()?(e=S.Events.AD_BUFFER_END,t.timeSinceAdBufferBegin=this.state.timeSinceBufferBegin.getDeltaTime()):(e=S.Events.CONTENT_BUFFER_END,t.timeSinceBufferBegin=this.state.timeSinceBufferBegin.getDeltaTime()),t=this.buildBufferAttributes(t),null!=this._lastBufferType&&(t.bufferType=this._lastBufferType),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.state.initialBufferingHappened=!0}}buildBufferAttributes(t){return null==t.timeSinceStarted||t.timeSinceStarted<100?t.isInitialBuffering=!this.state.initialBufferingHappened:t.isInitialBuffering=!1,t.bufferType=this.state.calculateBufferType(t.isInitialBuffering),t.timeSinceResumed=this.state.timeSinceResumed.getDeltaTime(),t.timeSinceSeekEnd=this.state.timeSinceSeekEnd.getDeltaTime(),t}sendSeekStart(t){if(this.state.goSeekStart()){let e;e=this.isAd()?S.Events.AD_SEEK_START:S.Events.CONTENT_SEEK_START,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendSeekEnd(t){if(this.state.goSeekEnd()){let e;t=t||{},this.isAd()?(e=S.Events.AD_SEEK_END,t.timeSinceAdSeekBegin=this.state.timeSinceSeekBegin.getDeltaTime()):(e=S.Events.CONTENT_SEEK_END,t.timeSinceSeekBegin=this.state.timeSinceSeekBegin.getDeltaTime()),this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t)}}sendDownload(t){(t=t||{}).state||r.A.warn("Called sendDownload without { state: xxxxx }."),this.sendVideoAction(S.Events.DOWNLOAD,t),this.state.goDownload()}sendError(t){(t=t||{}).isAd=this.isAd(),this.state.goError();let e=this.isAd()?S.Events.AD_ERROR:S.Events.CONTENT_ERROR;this.sendVideoErrorAction(e,t)}sendRenditionChanged(t){let e;(t=t||{}).timeSinceLastRenditionChange=this.state.timeSinceLastRenditionChange.getDeltaTime(),t.shift=this.getRenditionShift(!0),e=this.isAd()?S.Events.AD_RENDITION_CHANGE:S.Events.CONTENT_RENDITION_CHANGE,this.isAd()?this.sendVideoAdAction(e,t):this.sendVideoAction(e,t),this.state.goRenditionChange()}sendHeartbeat(t){if(this.state.isRequested){let e,i=this.getHeartbeat();this.state._hb=!0,i=this.adjustElapsedTimeForPause(i),this.isAd()?(e=S.Events.AD_HEARTBEAT,"bitmovin-ads"===this.getPlayerName()?this.sendVideoAdAction(e,t):this.sendVideoAdAction(e,{elapsedTime:i,...t})):(e=S.Events.CONTENT_HEARTBEAT,this.sendVideoAction(e,{elapsedTime:i,...t})),this.state.goHeartbeat()}}adjustElapsedTimeForPause(t){return this.state._acc&&(t-=this.state._acc,this.state._acc=0),this.state.isPaused&&((t-=this.state.elapsedTime.getDeltaTime())<10&&(t=0),this.state.elapsedTime.start()),this.state._bufferAcc?(t-=this.state._bufferAcc,this.state._bufferAcc=0):this.state.isBuffering&&((t-=this.state.bufferElapsedTime.getDeltaTime())<5&&(t=0),this.state.bufferElapsedTime.start()),Math.max(0,t)}sendAdBreakStart(t){this.isAd()&&this.state.goAdBreakStart()&&(this.state.totalAdPlaytime=0,this.parentTracker&&(this.parentTracker.state.isPlaying=!1),this.sendVideoAdAction(S.Events.AD_BREAK_START,t))}sendAdBreakEnd(t){this.isAd()&&this.state.goAdBreakEnd()&&((t=t||{}).timeSinceAdBreakBegin=this.state.timeSinceAdBreakStart.getDeltaTime(),this.sendVideoAdAction(S.Events.AD_BREAK_END,t),this.parentTracker&&(this.parentTracker.state.isPlaying=!0),this.stopHeartbeat(),this.parentTracker&&this.isAd()&&this.parentTracker.state.goLastAd())}sendAdQuartile(t){this.isAd()&&((t=t||{}).quartile||r.A.warn("Called sendAdQuartile without { quartile: xxxxx }."),t.timeSinceLastAdQuartile=this.state.timeSinceLastAdQuartile.getDeltaTime(),this.sendVideoAdAction(S.Events.AD_QUARTILE,t),this.state.goAdQuartile())}sendAdClick(t){this.isAd()&&((t=t||{}).url||r.A.warn("Called sendAdClick without { url: xxxxx }."),this.sendVideoAdAction(S.Events.AD_CLICK,t))}}function y(t){t.type!==S.Events.AD_ERROR?this.sendVideoAdAction(t.type,t.data):this.sendVideoErrorAction(t.type,t.data)}S.Events={PLAYER_READY:"PLAYER_READY",DOWNLOAD:"DOWNLOAD",ERROR:"ERROR",CONTENT_REQUEST:"CONTENT_REQUEST",CONTENT_START:"CONTENT_START",CONTENT_END:"CONTENT_END",CONTENT_PAUSE:"CONTENT_PAUSE",CONTENT_RESUME:"CONTENT_RESUME",CONTENT_SEEK_START:"CONTENT_SEEK_START",CONTENT_SEEK_END:"CONTENT_SEEK_END",CONTENT_BUFFER_START:"CONTENT_BUFFER_START",CONTENT_BUFFER_END:"CONTENT_BUFFER_END",CONTENT_HEARTBEAT:"CONTENT_HEARTBEAT",CONTENT_RENDITION_CHANGE:"CONTENT_RENDITION_CHANGE",CONTENT_ERROR:"CONTENT_ERROR",AD_REQUEST:"AD_REQUEST",AD_START:"AD_START",AD_END:"AD_END",AD_PAUSE:"AD_PAUSE",AD_RESUME:"AD_RESUME",AD_SEEK_START:"AD_SEEK_START",AD_SEEK_END:"AD_SEEK_END",AD_BUFFER_START:"AD_BUFFER_START",AD_BUFFER_END:"AD_BUFFER_END",AD_HEARTBEAT:"AD_HEARTBEAT",AD_RENDITION_CHANGE:"AD_RENDITION_CHANGE",AD_ERROR:"AD_ERROR",AD_BREAK_START:"AD_BREAK_START",AD_BREAK_END:"AD_BREAK_END",AD_QUARTILE:"AD_QUARTILE",AD_CLICK:"AD_CLICK"};const p=S;var R=i(431),_=i(413),B=i(28),b=i(374);const D={Constants:n.A,Chrono:f.A,Log:r.A,Emitter:T.A,Tracker:o.A,VideoTracker:p,VideoTrackerState:E,Core:m,version:v.rE,NrVideoEventAggregator:R.t,RetryQueueHandler:_.u,OptimizedHttpClient:B.X,HarvestScheduler:b.n,recordEvent:d};module.exports.nrvideo=s})();
|
|
3
3
|
//# sourceMappingURL=index.js.map
|