videojs-contrib-ads
Version:
A framework that provides common functionality needed by video advertisement libraries working with video.js.
7 lines • 23.2 kB
JavaScript
/*
* videojs-contrib-ads
* @version 6.0.0
* @copyright 2018 Brightcove, Inc.
* @license Apache-2.0
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):e.videojsContribAds=t(e.videojs)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e["default"]:e;var t=function(e,t){t.isImmediatePropagationStopped=function(){return!0},t.cancelBubble=!0,t.isPropagationStopped=function(){return!0}},n=function(e,n,o){t(0,o),e.trigger({type:n+o.type,originalEvent:o})},o=function(e,o){e.ads.isInAdMode()&&(e.ads.isContentResuming()?e.ads._contentEnding&&n(e,"content",o):e.ads._cancelledPlay?t(0,o):n(e,"ad",o))},a=function(e,t){if(e.ads.isInAdMode()){if(e.ads.isContentResuming())return;n(e,"ad",t)}else e.ads._contentHasEnded||n(e,"content",t)},i=function(e,t){if(!("loadstart"===t.type&&!e.ads._hasThereBeenALoadStartDuringPlayerLife||"loadeddata"===t.type&&!e.ads._hasThereBeenALoadedData||"loadedmetadata"===t.type&&!e.ads._hasThereBeenALoadedMetaData))if(e.ads.inAdBreak())n(e,"ad",t);else{if(e.currentSrc()!==e.ads.contentSrc)return;n(e,"content",t)}},r=function(e,t){var o=e.ads._cancelledPlay&&!e.ads.isInAdMode();e.ads.inAdBreak()?n(e,"ad",t):(e.ads.isContentResuming()||o)&&n(e,"content",t)};function d(e){"playing"===e.type?o(this,e):"ended"===e.type?a(this,e):"loadstart"===e.type||"loadeddata"===e.type||"loadedmetadata"===e.type?i(this,e):"play"===e.type?r(this,e):this.ads.isInAdMode()&&(this.ads.isContentResuming()?n(this,"content",e):n(this,"ad",e))}var s,u="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},l="undefined"!=typeof window?window:void 0!==u?u:"undefined"!=typeof self?self:{},c={},p=(Object.freeze||Object)({"default":c}),f=p&&c||p,h=void 0!==u?u:"undefined"!=typeof window?window:{};"undefined"!=typeof document?s=document:(s=h["__GLOBAL_DOCUMENT_CACHE@4"])||(s=h["__GLOBAL_DOCUMENT_CACHE@4"]=f);var y=s,g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m=(function(){function e(e){this.value=e}function t(t){var n,o;function a(n,o){try{var r=t[n](o),d=r.value;d instanceof e?Promise.resolve(d.value).then(function(e){a("next",e)},function(e){a("throw",e)}):i(r.done?"return":"normal",r.value)}catch(s){i("throw",s)}}function i(e,t){switch(e){case"return":n.resolve({value:t,done:!0});break;case"throw":n.reject(t);break;default:n.resolve({value:t,done:!1})}(n=n.next)?a(n.key,n.arg):o=null}this._invoke=function(e,t){return new Promise(function(i,r){var d={key:e,arg:t,resolve:i,reject:r,next:null};o?o=o.next=d:(n=o=d,a(e,t))})},"function"!=typeof t["return"]&&(this["return"]=undefined)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype["throw"]=function(e){return this._invoke("throw",e)},t.prototype["return"]=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),v=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},A=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},T=function(e,t){return t?encodeURIComponent(e):e},b=function(e,t,n){if(e&&e[n])for(var o=e[n],a=Object.keys(o),i=0;i<a.length;i++){t["{mediainfo."+n+"."+a[i]+"}"]=o[a[i]]}};var _={processMetadataTracks:function(e,t){for(var n=e.textTracks(),o=function(n){"metadata"===n.kind&&(e.ads.cueTextTracks.setMetadataTrackMode(n),t(e,n))},a=0;a<n.length;a++)o(n[a]);n.addEventListener("addtrack",function(e){o(e.track)})},setMetadataTrackMode:function(e){},getSupportedAdCue:function(e,t){return t},isSupportedAdCue:function(e,t){return!0},getCueId:function(e,t){return t.id}};_.processAdTrack=function(t,n,o,a){t.ads.includedCues={};for(var i=0;i<n.length;i++){var r=n[i],d=this.getSupportedAdCue(t,r);if(!this.isSupportedAdCue(t,r))return void e.log.warn("Skipping as this is not a supported ad cue.",r);var s=this.getCueId(t,r),u=r.startTime;if((c=s)!==undefined&&t.ads.includedCues[c])return void e.log("Skipping ad already seen with ID "+s);a&&a(t,d,s,u),o(t,d,s,u),(l=s)!==undefined&&""!==l&&(t.ads.includedCues[l]=!0)}var l,c};var k=function(){function t(e){m(this,t),this.player=e}return t.prototype.transitionTo=function(e){var t=this.player;this.cleanup();var n=new e(t);t.ads._state=n,t.ads.debug(this.constructor.name+" -> "+n.constructor.name);for(var o=arguments.length,a=Array(o>1?o-1:0),i=1;i<o;i++)a[i-1]=arguments[i];n.init.apply(n,[t].concat(a))},t.prototype.init=function(){},t.prototype.cleanup=function(){},t.prototype.onPlay=function(){},t.prototype.onPlaying=function(){},t.prototype.onEnded=function(){},t.prototype.onAdsReady=function(){e.log.warn("Unexpected adsready event")},t.prototype.onAdsError=function(){},t.prototype.onAdsCanceled=function(){},t.prototype.onAdTimeout=function(){},t.prototype.onAdStarted=function(){},t.prototype.onContentChanged=function(){},t.prototype.onContentResumed=function(){},t.prototype.onContentEnded=function(){e.log.warn("Unexpected contentended event")},t.prototype.onNoPreroll=function(){},t.prototype.onNoPostroll=function(){},t.prototype.startLinearAdMode=function(){e.log.warn("Unexpected startLinearAdMode invocation (State via "+this.constructor.name+")")},t.prototype.endLinearAdMode=function(){e.log.warn("Unexpected endLinearAdMode invocation (State via "+this.constructor.name+")")},t.prototype.skipLinearAdMode=function(){e.log.warn("Unexpected skipLinearAdMode invocation (State via "+this.constructor.name+")")},t.prototype.isAdState=function(){throw new Error("isAdState unimplemented for "+this.constructor.name)},t.prototype.isContentResuming=function(){return!1},t.prototype.inAdBreak=function(){return!1},t.prototype.handleEvent=function(e){var t=this.player;"play"===e?this.onPlay(t):"adsready"===e?this.onAdsReady(t):"adserror"===e?this.onAdsError(t):"adscanceled"===e?this.onAdsCanceled(t):"adtimeout"===e?this.onAdTimeout(t):"ads-ad-started"===e?this.onAdStarted(t):"contentchanged"===e?this.onContentChanged(t):"contentresumed"===e?this.onContentResumed(t):"contentended"===e?this.onContentEnded(t):"playing"===e?this.onPlaying(t):"ended"===e?this.onEnded(t):"nopreroll"===e?this.onNoPreroll(t):"nopostroll"===e&&this.onNoPostroll(t)},t}(),S=function(e){function t(n){m(this,t);var o=A(this,e.call(this,n));return o.contentResuming=!1,o}return v(t,e),t.prototype.isAdState=function(){return!0},t.prototype.onPlaying=function(){this.contentResuming&&this.transitionTo(E)},t.prototype.onContentResumed=function(){this.contentResuming&&this.transitionTo(E)},t.prototype.isContentResuming=function(){return this.contentResuming},t.prototype.inAdBreak=function(){return!0===this.player.ads._inLinearAdMode},t}(k),C=function(e){function t(){return m(this,t),A(this,e.apply(this,arguments))}return v(t,e),t.prototype.isAdState=function(){return!1},t.prototype.onContentChanged=function(e){e.ads.debug("Received contentchanged event (ContentState)"),e.paused()?this.transitionTo(B):(this.transitionTo(R,!1),e.pause(),e.ads._pausedOnContentupdate=!0)},t}(k);function P(e){e.ads.cancelPlayTimeout||(e.ads.cancelPlayTimeout=e.setTimeout(function(){e.ads.cancelPlayTimeout=null,e.ads.isInAdMode()&&(e.paused()||e.pause(),e.ads._cancelledPlay=!0)},1))}var L={start:function(t){t.ads.debug("Starting ad break"),t.ads._inLinearAdMode=!0,t.trigger("adstart"),t.ads.shouldPlayContentBehindAd(t)||(t.ads.snapshot=function(t){var n=void 0;n=e.browser.IS_IOS&&t.ads.isLive(t)&&t.seekable().length>0?t.currentTime()-t.seekable().end(0):t.currentTime();var o=t.$(".vjs-tech"),a=t.textTracks?t.textTracks():[],i=[],r={ended:t.ended(),currentSrc:t.currentSrc(),src:t.tech_.src(),currentTime:n,type:t.currentType()};o&&(r.nativePoster=o.poster,r.style=o.getAttribute("style"));for(var d=0;d<a.length;d++){var s=a[d];i.push({track:s,mode:s.mode}),s.mode="disabled"}return r.suppressedTracks=i,r}(t)),t.ads.shouldPlayContentBehindAd(t)&&(t.ads.preAdVolume_=t.volume(),t.volume(0)),t.addClass("vjs-ad-playing"),t.hasClass("vjs-live")&&t.removeClass("vjs-live"),t.ads.removeNativePoster()},end:function(t){t.ads.debug("Ending ad break"),t.ads.adType=null,t.ads._inLinearAdMode=!1,t.trigger("adend"),t.removeClass("vjs-ad-playing"),t.ads.isLive(t)&&t.addClass("vjs-live"),t.ads.shouldPlayContentBehindAd(t)||function(t,n){if(!0!==t.ads.disableNextSnapshotRestore){var o=t.$(".vjs-tech"),a=20,i=n.suppressedTracks,r=void 0,d=function(){for(var e=0;e<i.length;e++)(r=i[e]).track.mode=r.mode},s=function(){var o=void 0;e.browser.IS_IOS&&t.ads.isLive(t)?n.currentTime<0&&(o=t.seekable().length>0?t.seekable().end(0)+n.currentTime:t.currentTime(),t.currentTime(o)):n.ended?t.currentTime(t.duration()):t.currentTime(n.currentTime),n.ended||t.play(),t.ads.shouldRemoveAutoplay_&&(t.autoplay(!1),t.ads.shouldRemoveAutoplay_=!1)},u=function l(){if(t.off("contentcanplay",l),t.ads.tryToResumeTimeout_&&(t.clearTimeout(t.ads.tryToResumeTimeout_),t.ads.tryToResumeTimeout_=null),(o=t.el().querySelector(".vjs-tech")).readyState>1)return s();if(o.seekable===undefined)return s();if(o.seekable.length>0)return s();if(a--)t.setTimeout(l,50);else try{s()}catch(n){e.log.warn("Failed to resume the content after an advertisement",n)}};n.nativePoster&&(o.poster=n.nativePoster),"style"in n&&o.setAttribute("style",n.style||""),t.ads.videoElementRecycled()?(t.one("contentloadedmetadata",d),e.browser.IS_IOS&&!t.autoplay()&&(t.autoplay(!0),t.ads.shouldRemoveAutoplay_=!0),t.src({src:n.currentSrc,type:n.type}),t.one("contentcanplay",u),t.ads.tryToResumeTimeout_=t.setTimeout(u,2e3)):(d(),t.ended()||t.play())}else t.ads.disableNextSnapshotRestore=!1}(t,t.ads.snapshot),t.ads.shouldPlayContentBehindAd(t)&&t.volume(t.ads.preAdVolume_)}},R=function(t){function n(){return m(this,n),A(this,t.apply(this,arguments))}return v(n,t),n.prototype.init=function(e,t){e.addClass("vjs-ad-loading");var n=e.ads.settings.timeout;"number"==typeof e.ads.settings.prerollTimeout&&(n=e.ads.settings.prerollTimeout),this._timeout=e.setTimeout(function(){e.trigger("adtimeout")},n),t?this.handleAdsReady():this.adsReady=!1},n.prototype.onAdsReady=function(t){t.ads.inAdBreak()||t.ads.isContentResuming()?e.log.warn("Unexpected adsready event (Preroll)"):(t.ads.debug("Received adsready event (Preroll)"),this.handleAdsReady())},n.prototype.handleAdsReady=function(){this.adsReady=!0,this.player.ads.nopreroll_?this.noPreroll():this.readyForPreroll()},n.prototype.afterLoadStart=function(e){var t=this.player;t.ads._hasThereBeenALoadStartDuringPlayerLife?e():(t.ads.debug("Waiting for loadstart..."),t.one("loadstart",function(){t.ads.debug("Received loadstart event"),e()}))},n.prototype.noPreroll=function(){var e=this;this.afterLoadStart(function(){e.player.ads.debug("Skipping prerolls due to nopreroll event (Preroll)"),e.transitionTo(E)})},n.prototype.readyForPreroll=function(){var e=this.player;this.afterLoadStart(function(){e.ads.debug("Triggered readyforpreroll event (Preroll)"),e.trigger("readyforpreroll")})},n.prototype.onPlay=function(e){e.ads.debug("Received play event (Preroll)"),this.inAdBreak()||this.isContentResuming()||P(this.player)},n.prototype.onAdsCanceled=function(e){var t=this;e.ads.debug("adscanceled (Preroll)"),this.afterLoadStart(function(){t.transitionTo(E)})},n.prototype.onAdsError=function(t){var n=this;e.log("adserror (Preroll)"),this.inAdBreak()&&t.ads.endLinearAdMode(),this.afterLoadStart(function(){n.transitionTo(E)})},n.prototype.startLinearAdMode=function(){var t=this.player;!this.adsReady||t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected startLinearAdMode invocation (Preroll)"):(t.clearTimeout(this._timeout),t.ads.adType="preroll",L.start(t))},n.prototype.onAdStarted=function(e){e.removeClass("vjs-ad-loading")},n.prototype.endLinearAdMode=function(){var e=this.player;this.inAdBreak()&&(e.removeClass("vjs-ad-loading"),L.end(e),this.contentResuming=!0)},n.prototype.skipLinearAdMode=function(){var t=this,n=this.player;n.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected skipLinearAdMode invocation"):this.afterLoadStart(function(){n.trigger("adskip"),n.ads.debug("skipLinearAdMode (Preroll)"),t.transitionTo(E)})},n.prototype.onAdTimeout=function(e){var t=this;this.afterLoadStart(function(){e.ads.debug("adtimeout (Preroll)"),t.transitionTo(E)})},n.prototype.onNoPreroll=function(t){t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected nopreroll event (Preroll)"):this.noPreroll()},n.prototype.cleanup=function(){var t=this.player;t.ads._hasThereBeenALoadStartDuringPlayerLife||e.log.warn("Leaving Preroll state before loadstart event can cause issues."),t.removeClass("vjs-ad-loading"),t.clearTimeout(this._timeout)},n}(S),w=function(e){function t(){return m(this,t),A(this,e.apply(this,arguments))}return v(t,e),t.prototype.init=function(e){e.ads.adType="midroll",L.start(e)},t.prototype.endLinearAdMode=function(){var e=this.player;this.inAdBreak()&&(this.contentResuming=!0,L.end(e))},t.prototype.onAdsError=function(e){this.inAdBreak()&&e.ads.endLinearAdMode()},t}(S),M=function(t){function n(){return m(this,n),A(this,t.apply(this,arguments))}return v(n,t),n.prototype.init=function(e){var t=this;if(e.ads._contentEnding=!0,e.ads.nopostroll_)e.setTimeout(function(){e.ads.debug("Triggered ended event (no postroll)"),t.contentResuming=!0,e.trigger("ended")},1);else{e.addClass("vjs-ad-loading");var n=e.ads.settings.timeout;"number"==typeof e.ads.settings.postrollTimeout&&(n=e.ads.settings.postrollTimeout),this._postrollTimeout=e.setTimeout(function(){e.trigger("adtimeout")},n)}},n.prototype.startLinearAdMode=function(){var t=this.player;t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected startLinearAdMode invocation (Postroll)"):(t.ads.adType="postroll",t.clearTimeout(this._postrollTimeout),L.start(t))},n.prototype.onAdStarted=function(e){e.removeClass("vjs-ad-loading")},n.prototype.endLinearAdMode=function(){var e=this.player;this.inAdBreak()&&(e.removeClass("vjs-ad-loading"),L.end(e),this.contentResuming=!0,e.ads.debug("Triggered ended event (endLinearAdMode)"),e.trigger("ended"))},n.prototype.skipLinearAdMode=function(){var t=this.player;t.ads.inAdBreak()||this.isContentResuming()?e.log.warn("Unexpected skipLinearAdMode invocation"):(t.ads.debug("Postroll abort (skipLinearAdMode)"),t.trigger("adskip"),this.abort())},n.prototype.onAdTimeout=function(e){e.ads.debug("Postroll abort (adtimeout)"),this.abort()},n.prototype.onAdsError=function(e){e.ads.debug("Postroll abort (adserror)"),e.ads.inAdBreak()&&e.ads.endLinearAdMode(),this.abort()},n.prototype.onEnded=function(){this.isContentResuming()?this.transitionTo(j):e.log.warn("Unexpected ended event during postroll")},n.prototype.onContentChanged=function(e){this.isContentResuming()?this.transitionTo(B):this.inAdBreak()||this.transitionTo(R)},n.prototype.onNoPostroll=function(t){this.isContentResuming()||this.inAdBreak()?e.log.warn("Unexpected nopostroll event (Postroll)"):this.transitionTo(j)},n.prototype.abort=function(){var e=this.player;this.contentResuming=!0,e.removeClass("vjs-ad-loading"),e.ads.debug("Triggered ended event (postroll abort)"),e.trigger("ended")},n.prototype.cleanup=function(){var e=this.player;e.clearTimeout(this._postrollTimeout),e.ads._contentEnding=!1},n}(S),B=function(e){function t(){return m(this,t),A(this,e.apply(this,arguments))}return v(t,e),t.prototype.init=function(e){this.adsReady=!1},t.prototype.onAdsReady=function(e){e.ads.debug("Received adsready event (BeforePreroll)"),this.adsReady=!0},t.prototype.onPlay=function(e){e.ads.debug("Received play event (BeforePreroll)"),P(e),this.transitionTo(R,this.adsReady)},t.prototype.onAdsCanceled=function(e){e.ads.debug("adscanceled (BeforePreroll)"),this.transitionTo(E)},t.prototype.onAdsError=function(){this.transitionTo(E)},t.prototype.onNoPreroll=function(){this.player.ads.debug("Skipping prerolls due to nopreroll event (BeforePreroll)"),this.transitionTo(E)},t.prototype.skipLinearAdMode=function(){this.player.trigger("adskip"),this.transitionTo(E)},t.prototype.onContentChanged=function(){},t}(C),E=function(e){function t(){return m(this,t),A(this,e.apply(this,arguments))}return v(t,e),t.prototype.init=function(e){e.paused()&&(e.ads._cancelledPlay||e.ads._pausedOnContentupdate)&&e.play()},t.prototype.onAdsReady=function(e){e.ads.debug("Received adsready event (ContentPlayback)"),e.ads.nopreroll_||(e.ads.debug("Triggered readyforpreroll event (ContentPlayback)"),e.trigger("readyforpreroll"))},t.prototype.onContentEnded=function(e){e.ads.debug("Received contentended event"),this.transitionTo(M)},t.prototype.startLinearAdMode=function(){this.transitionTo(w)},t}(C),j=function(t){function n(){return m(this,n),A(this,t.apply(this,arguments))}return v(n,t),n.prototype.init=function(e){e.ads._contentHasEnded=!0},n.prototype.startLinearAdMode=function(){e.log.warn("Unexpected startLinearAdMode invocation (AdsDone)")},n}(C),x=e.getTech("Html5").Events,I={timeout:5e3,prerollTimeout:undefined,postrollTimeout:undefined,debug:!1,stitchedAds:!1},O=function(t){var n,o=this,a=e.mergeOptions(I,t),i=x.concat(["firstplay","loadedalldata","playing"]);o.on(i,d),o.setTimeout(function(){o.ads._hasThereBeenALoadStartDuringPlayerLife||""===o.src()||e.log.error("videojs-contrib-ads has not seen a loadstart event 5 seconds after being initialized, but a source is present. This indicates that videojs-contrib-ads was initialized too late. It must be initialized immediately after video.js in the same tick. As a result, some ads will not play and some media events will be incorrect. For more information, see https://github.com/videojs/videojs-contrib-ads#important-note-about-initialization")},5e3),o.on("ended",function(){o.hasClass("vjs-has-started")||o.addClass("vjs-has-started")}),o.on(["addurationchange","adcanplay"],function(){o.ads.snapshot&&o.currentSrc()===o.ads.snapshot.currentSrc||o.ads.inAdBreak()&&o.play()}),o.on("nopreroll",function(){o.ads.debug("Received nopreroll event"),o.ads.nopreroll_=!0}),o.on("nopostroll",function(){o.ads.debug("Received nopostroll event"),o.ads.nopostroll_=!0}),o.on("playing",function(){o.ads._cancelledPlay=!1,o.ads._pausedOnContentupdate=!1}),o.one("loadstart",function(){o.ads._hasThereBeenALoadStartDuringPlayerLife=!0}),o.on("loadeddata",function(){o.ads._hasThereBeenALoadedData=!0}),o.on("loadedmetadata",function(){o.ads._hasThereBeenALoadedMetaData=!0}),o.ads={settings:a,disableNextSnapshotRestore:!1,_contentEnding:!1,_contentHasEnded:!1,_hasThereBeenALoadStartDuringPlayerLife:!1,_hasThereBeenALoadedData:!1,_hasThereBeenALoadedMetaData:!1,_inLinearAdMode:!1,adType:null,VERSION:"__VERSION__",reset:function(){o.ads.disableNextSnapshotRestore=!1,o.ads._contentEnding=!1,o.ads._contentHasEnded=!1,o.ads.snapshot=null,o.ads.adType=null,o.ads._hasThereBeenALoadedData=!1,o.ads._hasThereBeenALoadedMetaData=!1,o.ads._cancelledPlay=!1,o.ads.nopreroll_=!1,o.ads.nopostroll_=!1},startLinearAdMode:function(){o.ads._state.startLinearAdMode()},endLinearAdMode:function(){o.ads._state.endLinearAdMode()},skipLinearAdMode:function(){o.ads._state.skipLinearAdMode()},stitchedAds:function(e){return e!==undefined&&(this._stitchedAds=!!e),this._stitchedAds},videoElementRecycled:function(){if(o.ads.shouldPlayContentBehindAd(o))return!1;if(!this.snapshot)throw new Error("You cannot use videoElementRecycled while there is no snapshot.");var e=o.tech_.src()!==this.snapshot.src,t=o.currentSrc()!==this.snapshot.currentSrc;return e||t},isLive:function(t){return t.duration()===Infinity||"8"===e.browser.IOS_VERSION&&0===t.duration()},shouldPlayContentBehindAd:function(t){return!e.browser.IS_IOS&&!e.browser.IS_ANDROID&&t.duration()===Infinity},isInAdMode:function(){return this._state.isAdState()},isContentResuming:function(){return this._state.isContentResuming()},isAdPlaying:function(){return this._state.inAdBreak()},inAdBreak:function(){return this._state.inAdBreak()},removeNativePoster:function(){var e=o.$(".vjs-tech");e&&e.removeAttribute("poster")},debug:function(){if(this.settings.debug){for(var t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];1===n.length&&"string"==typeof n[0]?e.log("ADS: "+n[0]):e.log.apply(e,["ADS:"].concat(n))}}},o.ads._state=new B(o),o.ads.stitchedAds(a.stitchedAds),o.ads.cueTextTracks=_,o.ads.adMacroReplacement=function(t,n,o){n===undefined&&(n=!1);var a={};for(var i in o!==undefined&&(a=o),a["{player.id}"]=this.options_["data-player"],a["{mediainfo.id}"]=this.mediainfo?this.mediainfo.id:"",a["{mediainfo.name}"]=this.mediainfo?this.mediainfo.name:"",a["{mediainfo.description}"]=this.mediainfo?this.mediainfo.description:"",a["{mediainfo.tags}"]=this.mediainfo?this.mediainfo.tags:"",a["{mediainfo.reference_id}"]=this.mediainfo?this.mediainfo.reference_id:"",a["{mediainfo.duration}"]=this.mediainfo?this.mediainfo.duration:"",a["{mediainfo.ad_keys}"]=this.mediainfo?this.mediainfo.ad_keys:"",a["{player.duration}"]=this.duration(),a["{timestamp}"]=(new Date).getTime(),a["{document.referrer}"]=y.referrer,a["{window.location.href}"]=l.location.href,a["{random}"]=Math.floor(1e12*Math.random()),b(this.mediainfo,a,"custom_fields"),b(this.mediainfo,a,"customFields"),a)t=t.split(i).join(T(a[i],n));return t=t.replace(/{pageVariable\.([^}]+)}/g,function(t,o){for(var a=void 0,i=l,r=o.split("."),d=0;d<r.length;d++)d===r.length-1?a=i[r[d]]:i=i[r[d]];var s=void 0===a?"undefined":g(a);return null===a?"null":a===undefined?(e.log.warn('Page variable "'+o+'" not found'),""):"string"!==s&&"number"!==s&&"boolean"!==s?(e.log.warn('Page variable "'+o+'" is not a supported type'),""):T(String(a),n)})}.bind(o),(n=o).ads.contentSrc=n.currentSrc(),n.ads._seenInitialLoadstart=!1,n.on("loadstart",function(){if(!n.ads.inAdBreak()){var e=n.currentSrc();e!==n.ads.contentSrc&&(n.ads._seenInitialLoadstart&&n.trigger({type:"contentchanged"}),n.trigger({type:"contentupdate",oldValue:n.ads.contentSrc,newValue:e}),n.ads.contentSrc=e),n.ads._seenInitialLoadstart=!0}}),o.on("contentchanged",o.ads.reset);var r=function(){var t=o.textTracks();if(!o.ads.shouldPlayContentBehindAd(o)&&o.ads.inAdBreak()&&o.tech_.featuresNativeTextTracks&&e.browser.IS_IOS&&!Array.isArray(o.textTracks()))for(var n=0;n<t.length;n++){var a=t[n];"showing"===a.mode&&(a.mode="disabled")}};o.ready(function(){o.textTracks().addEventListener("change",r)}),o.on(["play","playing","ended","adsready","adscanceled","adskip","adserror","adtimeout","ads-ad-started","contentchanged","contentresumed","contentended","nopreroll","nopostroll"],function(e){o.ads._state.handleEvent(e.type)}),o.on("dispose",function(){o.textTracks().removeEventListener("change",r)})};return(e.registerPlugin||e.plugin)("ads",O),O});