videojs-contrib-ads
Version:
A framework that provides common functionality needed by video advertisement libraries working with video.js.
1 lines • 17.2 kB
JavaScript
!function e(t,n,a){function o(i,s){if(!n[i]){if(!t[i]){var r="function"==typeof require&&require;if(!s&&r)return r(i,!0);if(d)return d(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[i]={exports:{}};t[i][0].call(u.exports,function(e){var n=t[i][1][e];return o(n?n:e)},u,u.exports,e,t,n,a)}return n[i].exports}for(var d="function"==typeof require&&require,i=0;i<a.length;i++)o(a[i]);return o}({1:[function(e,t,n){(function(t){"use strict";function a(e){return e&&e.__esModule?e:{"default":e}}function o(e){e.ads.cancelPlayTimeout||(u["default"].browser.IS_IOS&&u["default"].browser.IS_IPHONE&&!e.el_.hasAttribute("playsinline")&&!function(){var t=e.currentWidth?e.currentWidth():e.width(),n=e.currentHeight?e.currentHeight():e.height(),a=r["default"].createElement("div");a.style.width=t+"px",a.style.height=n+"px",a.style.background="black",e.el_.parentNode.insertBefore(a,e.el_),e.el_.style.display="none",e.one(["adstart","adtimeout","adserror","adscanceled","adskip","playing"],function(){e.el_.style.display="block",a.remove()}),e.on("fullscreenchange",function(){a&&!e.isFullscreen()&&(e.el_.style.display="block",a.remove())})}(),e.ads.cancelPlayTimeout=i["default"].setTimeout(function(){e.ads.cancelPlayTimeout=null,e.paused()||e.pause(),e.ads.cancelledPlay=!0},1))}n.__esModule=!0,n["default"]=o;var d=e(9),i=a(d),s=e(8),r=a(s),l="undefined"!=typeof window?window.videojs:"undefined"!=typeof t?t.videojs:null,u=a(l)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){"use strict";function a(e){return e&&e.__esModule?e:{"default":e}}function o(e){e.ads.contentSrc=e.currentSrc();var t=function(){if("ad-playback"!==e.ads.state){var t=e.currentSrc();t!==e.ads.contentSrc&&(e.trigger({type:"contentupdate",oldValue:e.ads.contentSrc,newValue:t}),e.ads.contentSrc=t)}};e.on("loadstart",t),i["default"].setTimeout(t,1)}n.__esModule=!0,n["default"]=o;var d=e(9),i=a(d)},{}],3:[function(e,t,n){(function(e){"use strict";function t(e){return e&&e.__esModule?e:{"default":e}}function a(e,t){var n=e.textTracks(),a=function(n){"metadata"===n.kind&&(e.ads.cueTextTracks.setMetadataTrackMode(n),t(e,n))};if(n.length>0)for(var o=0;o<n.length;o++){var d=n[o];a(d)}else n.addEventListener("addtrack",function(e){var t=e.track;a(t)})}function o(e){}function d(e,t){return t}function i(e,t){return t.id}function s(e,t,n,a){e.ads.includedCues={};for(var o=0;o<t.length;o++){var d=t[o],i=this.getSupportedAdCue(e,d);if(i===-1)return void l["default"].log.warn("Skipping as this is not a supported ad cue.",d);var s=this.getCueId(e,d),r=d.startTime;if(u(e,s))return void l["default"].log("Skipping ad already seen with ID "+s);n(e,i,s,r),c(e,s),void 0!==a&&a(e,i)}}n.__esModule=!0,n.processMetadataTracks=a,n.setMetadataTrackMode=o,n.getSupportedAdCue=d,n.getCueId=i,n.processAdTrack=s;var r="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,l=t(r),u=function(e,t){return void 0!==t&&e.ads.includedCues[t]},c=function(e,t){void 0!==t&&""!==t&&(e.ads.includedCues[t]=!0)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){(function(t){"use strict";function a(e){return e&&e.__esModule?e:{"default":e}}function o(e,t,n){void 0===t&&(t=!1);var a={};void 0!==n&&(a=n),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}"]=l["default"].referrer,a["{window.location.href}"]=s["default"].location.href,a["{random}"]=Math.floor(1e12*Math.random()),p(this.mediainfo,a,"custom_fields"),p(this.mediainfo,a,"customFields");for(var o in a)e=e.split(o).join(f(a[o],t));return e=e.replace(/{pageVariable\.([^}]+)}/g,function(e,n){for(var a=void 0,o=s["default"],i=n.split("."),r=0;r<i.length;r++)r===i.length-1?a=o[i[r]]:o=o[i[r]];var l="undefined"==typeof a?"undefined":d(a);return null===a?"null":void 0===a?(c["default"].log.warn('Page variable "'+n+'" not found'),""):"string"!==l&&"number"!==l&&"boolean"!==l?(c["default"].log.warn('Page variable "'+n+'" is not a supported type'),""):f(String(a),t)})}n.__esModule=!0;var d="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};n["default"]=o;var i=e(9),s=a(i),r=e(8),l=a(r),u="undefined"!=typeof window?window.videojs:"undefined"!=typeof t?t.videojs:null,c=a(u),f=function(e,t){return t?encodeURIComponent(e):e},p=function(e,t,n){if(e&&e[n])for(var a=e[n],o=Object.keys(a),d=0;d<o.length;d++){var i="{mediainfo."+n+"."+o[d]+"}";t[i]=a[o[d]]}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){"use strict";function a(e){if("playing"===e.type&&"preroll?"===this.ads.state)d(this,"ad",e);else if("playing"!==e.type||"ad-playback"!==this.ads.state||this.ads.videoElementRecycled())if("playing"===e.type&&"ads-ready?"===this.ads.state)d(this,"ad",e);else{if("playing"===e.type&&"ad-playback"===this.ads.state&&this.ads.videoElementRecycled())return void o(this,e);if("ad-playback"===this.ads.state)(this.ads.videoElementRecycled()||this.ads.stitchedAds())&&d(this,"ad",e);else if("content-playback"===this.ads.state&&"ended"===e.type)d(this,"content",e);else if("content-resuming"===this.ads.state){if(this.ads.snapshot&&this.currentSrc()!==this.ads.snapshot.currentSrc){if("loadstart"===e.type)return;return d(this,"content",e)}if(this.ads.snapshot&&this.ads.snapshot.ended){if("pause"===e.type||"ended"===e.type)return;return d(this,"content",e)}"playing"!==e.type&&d(this,"content",e)}}else d(this,"ad",e)}n.__esModule=!0,n["default"]=a;var o=function(e,t){t.isImmediatePropagationStopped=function(){return!0},t.cancelBubble=!0,t.isPropagationStopped=function(){return!0}},d=function(e,t,n){o(e,n),e.trigger({type:t+n.type,state:e.ads.state,originalEvent:n})}},{}],6:[function(e,t,n){(function(t){"use strict";function a(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=void 0;t=l["default"].browser.IS_IOS&&e.ads.isLive(e)&&e.seekable().length>0?e.currentTime()-e.seekable().end(0):e.currentTime();var n=e.$(".vjs-tech"),a=e.remoteTextTracks?e.remoteTextTracks():[],o=e.textTracks?e.textTracks():[],d=[],i=[],s={ended:e.ended(),currentSrc:e.currentSrc(),src:e.tech_.src(),currentTime:t,type:e.currentType()};n&&(s.nativePoster=n.poster,s.style=n.getAttribute("style"));for(var r=0;r<a.length;r++){var u=a[r];d.push({track:u,mode:u.mode}),u.mode="disabled"}s.suppressedRemoteTracks=d;for(var c=0;c<o.length;c++){var f=o[c];i.push({track:f,mode:f.mode}),f.mode="disabled"}return s.suppressedTracks=i,s}function d(e,t){if(e.ads.disableNextSnapshotRestore===!0)return void(e.ads.disableNextSnapshotRestore=!1);var n=e.$(".vjs-tech"),a=20,o=t.suppressedRemoteTracks,d=t.suppressedTracks,i=void 0,r=function(){for(var e=0;e<o.length;e++)i=o[e],i.track.mode=i.mode;for(var t=0;t<d.length;t++)i=d[t],i.track.mode=i.mode},u=function(){var n=void 0;l["default"].browser.IS_IOS&&e.ads.isLive(e)?t.currentTime<0&&(n=e.seekable().length>0?e.seekable().end(0)+t.currentTime:e.currentTime(),e.currentTime(n)):t.ended?e.currentTime(e.duration()):e.currentTime(t.currentTime),t.ended||e.play()},c=function f(){if(e.off("contentcanplay",f),e.ads.tryToResumeTimeout_&&(e.clearTimeout(e.ads.tryToResumeTimeout_),e.ads.tryToResumeTimeout_=null),n=e.el().querySelector(".vjs-tech"),n.readyState>1)return u();if(void 0===n.seekable)return u();if(n.seekable.length>0)return u();if(a--)s["default"].setTimeout(f,50);else try{u()}catch(t){l["default"].log.warn("Failed to resume the content after an advertisement",t)}};t.nativePoster&&(n.poster=t.nativePoster),"style"in t&&n.setAttribute("style",t.style||""),e.ads.videoElementRecycled()?(e.one("contentloadedmetadata",r),e.src({src:t.currentSrc,type:t.type}),e.load(),e.one("contentcanplay",c),e.ads.tryToResumeTimeout_=e.setTimeout(c,2e3)):e.ended()&&t.ended||(r(),e.play())}n.__esModule=!0,n.getPlayerSnapshot=o,n.restorePlayerSnapshot=d;var i=e(9),s=a(i),r="undefined"!=typeof window?window.videojs:"undefined"!=typeof t?t.videojs:null,l=a(r)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(e,t,n){},{}],8:[function(e,t,n){(function(n){var a="undefined"!=typeof n?n:"undefined"!=typeof window?window:{},o=e(7);if("undefined"!=typeof document)t.exports=document;else{var d=a["__GLOBAL_DOCUMENT_CACHE@4"];d||(d=a["__GLOBAL_DOCUMENT_CACHE@4"]=o),t.exports=d}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],9:[function(e,t,n){(function(e){"undefined"!=typeof window?t.exports=window:"undefined"!=typeof e?t.exports=e:"undefined"!=typeof self?t.exports=self:t.exports={}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],10:[function(e,t,n){(function(t){"use strict";function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t["default"]=e,t}function a(e){return e&&e.__esModule?e:{"default":e}}var o=e(9),d=a(o),i="undefined"!=typeof window?window.videojs:"undefined"!=typeof t?t.videojs:null,s=a(i),r=e(5),l=a(r),u=e(6),c=n(u),f=e(2),p=a(f),y=e(1),h=a(y),m=e(4),v=a(m),g=e(3),T=n(g),b=s["default"].getTech("Html5").Events,w=function(e){var t=e.$(".vjs-tech");t&&t.removeAttribute("poster")},_={timeout:5e3,prerollTimeout:100,postrollTimeout:100,debug:!1,stitchedAds:!1},k=function(e){var t=this,n=s["default"].mergeOptions(_,e),a=b.concat(["firstplay","loadedalldata","playing"]);t.on(a,l["default"]),t.on("ended",function(){t.hasClass("vjs-has-started")||t.addClass("vjs-has-started")}),t.on(["addurationchange","adcanplay"],function(){t.currentSrc()!==t.ads.snapshot.currentSrc&&t.play()}),t.on("nopreroll",function(){t.ads.nopreroll_=!0}),t.on("nopostroll",function(){t.ads.nopostroll_=!0}),t.on(["ads-ad-started","playing"],function(){t.removeClass("vjs-ad-loading")}),t.ads={state:"content-set",disableNextSnapshotRestore:!1,_contentHasEnded:!1,adType:null,VERSION:"4.2.6",reset:function(){t.ads.disableNextSnapshotRestore=!1,t.ads._contentHasEnded=!1,t.ads.snapshot=null,t.ads.adType=null},startLinearAdMode:function(){"preroll?"!==t.ads.state&&"content-playback"!==t.ads.state&&"postroll?"!==t.ads.state||t.trigger("adstart")},endLinearAdMode:function(){"ad-playback"===t.ads.state&&(t.trigger("adend"),t.removeClass("vjs-ad-loading"))},skipLinearAdMode:function(){"ad-playback"!==t.ads.state&&t.trigger("adskip")},stitchedAds:function(e){return void 0!==e&&(this._stitchedAds=!!e),this._stitchedAds},videoElementRecycled:function(){if(!this.snapshot)throw new Error("You cannot use videoElementRecycled while there is no snapshot.");var e=t.tech_.src()!==this.snapshot.src,n=t.currentSrc()!==this.snapshot.currentSrc;return e||n},isLive:function(e){return e.duration()===1/0||"8"===s["default"].browser.IOS_VERSION&&0===e.duration()},shouldPlayContentBehindAd:function(e){return!s["default"].browser.IS_IOS&&!s["default"].browser.IS_ANDROID&&e.duration()===1/0}},t.ads.stitchedAds(n.stitchedAds),t.ads.cueTextTracks=T,t.ads.adMacroReplacement=v["default"].bind(t),(0,p["default"])(t),t.on("contentupdate",t.ads.reset);var o={"content-set":{events:{adscanceled:function(){this.state="content-playback"},adsready:function(){this.state="ads-ready"},play:function(){this.state="ads-ready?",(0,h["default"])(t),w(t)},adserror:function(){this.state="content-playback"},adskip:function(){this.state="content-playback"}}},"ads-ready":{events:{play:function(){this.state="preroll?",(0,h["default"])(t)},adskip:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"}}},"preroll?":{enter:function(){t.ads.nopreroll_?(t.trigger("readyforpreroll"),d["default"].setTimeout(function(){t.trigger("nopreroll")},1)):(t.addClass("vjs-ad-loading"),t.ads.adTimeoutTimeout=d["default"].setTimeout(function(){t.trigger("adtimeout")},n.prerollTimeout),t.trigger("readyforpreroll"))},leave:function(){d["default"].clearTimeout(t.ads.adTimeoutTimeout)},events:{play:function(){(0,h["default"])(t)},adstart:function(){this.state="ad-playback",t.ads.adType="preroll"},adskip:function(){this.state="content-playback"},adtimeout:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"},nopreroll:function(){this.state="content-playback"}}},"ads-ready?":{enter:function(){t.addClass("vjs-ad-loading"),t.ads.adTimeoutTimeout=d["default"].setTimeout(function(){t.trigger("adtimeout")},n.timeout)},leave:function(){d["default"].clearTimeout(t.ads.adTimeoutTimeout),t.removeClass("vjs-ad-loading")},events:{play:function(){(0,h["default"])(t)},adscanceled:function(){this.state="content-playback"},adsready:function(){this.state="preroll?"},adskip:function(){this.state="content-playback"},adtimeout:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"}}},"ad-playback":{enter:function(){t.ads.shouldPlayContentBehindAd(t)||(this.snapshot=c.getPlayerSnapshot(t)),t.ads.shouldPlayContentBehindAd(t)&&(this.preAdVolume_=t.volume(),t.volume(0)),t.addClass("vjs-ad-playing"),t.hasClass("vjs-live")&&t.removeClass("vjs-live"),w(t),t.ads.cancelPlayTimeout&&d["default"].setTimeout(function(){d["default"].clearTimeout(t.ads.cancelPlayTimeout),t.ads.cancelPlayTimeout=null},1)},leave:function(){t.removeClass("vjs-ad-playing"),t.ads.isLive(t)&&t.addClass("vjs-live"),t.ads.shouldPlayContentBehindAd(t)||c.restorePlayerSnapshot(t,this.snapshot),t.ads.shouldPlayContentBehindAd(t)&&t.volume(this.preAdVolume_)},events:{adend:function(){this.state="content-resuming",t.ads.adType=null},adserror:function(){this.state="content-resuming",t.trigger("adend")}}},"content-resuming":{enter:function(){this._contentHasEnded&&(d["default"].clearTimeout(t.ads._fireEndedTimeout),t.ads._fireEndedTimeout=d["default"].setTimeout(function(){t.trigger("ended")},1e3))},leave:function(){d["default"].clearTimeout(t.ads._fireEndedTimeout)},events:{contentupdate:function(){this.state="content-set"},contentresumed:function(){this.state="content-playback"},playing:function(){this.state="content-playback"},ended:function(){this.state="content-playback"}}},"postroll?":{enter:function(){this.snapshot=c.getPlayerSnapshot(t),t.ads.nopostroll_?d["default"].setTimeout(function(){t.ads.state="content-resuming",t.trigger("ended")},1):(t.addClass("vjs-ad-loading"),t.ads.adTimeoutTimeout=d["default"].setTimeout(function(){t.trigger("adtimeout")},n.postrollTimeout))},leave:function(){d["default"].clearTimeout(t.ads.adTimeoutTimeout),t.removeClass("vjs-ad-loading")},events:{adstart:function(){this.state="ad-playback",t.ads.adType="postroll"},adskip:function(){this.state="content-resuming",d["default"].setTimeout(function(){t.trigger("ended")},1)},adtimeout:function(){this.state="content-resuming",d["default"].setTimeout(function(){t.trigger("ended")},1)},adserror:function(){this.state="content-resuming",d["default"].setTimeout(function(){t.trigger("ended")},1)},contentupdate:function(){this.state="ads-ready?"}}},"content-playback":{enter:function(){t.ads.cancelPlayTimeout&&(d["default"].clearTimeout(t.ads.cancelPlayTimeout),t.ads.cancelPlayTimeout=null),t.trigger({type:"contentplayback",triggerevent:t.ads.triggerevent}),t.ads.cancelledPlay&&(t.ads.cancelledPlay=!1,t.paused()&&t.play())},events:{adsready:function(){t.trigger("readyforpreroll")},adstart:function(){this.state="ad-playback","preroll"!==t.ads.adType&&(t.ads.adType="midroll")},contentupdate:function(){t.ads.shouldPlayContentBehindAd(t)||(0,h["default"])(t),t.paused()?this.state="content-set":this.state="ads-ready?"},contentended:function(){return this._contentHasEnded?void(this.state="content-resuming"):(this._contentHasEnded=!0,void(this.state="postroll?"))}}}},i=function(e){var a=t.ads.state,d=o[a].events;if(d){var i=d[e.type];i&&i.apply(t.ads)}if(a!==t.ads.state){var r=a,l=t.ads.state;t.ads.triggerevent=e.type,o[r].leave&&o[r].leave.apply(t.ads),o[l].enter&&o[l].enter.apply(t.ads),n.debug&&s["default"].log("ads",t.ads.triggerevent+" triggered: "+r+" -> "+l)}};t.on(b.concat(["adtimeout","contentupdate","contentplaying","contentended","contentresumed","adstart","adend","adskip","adsready","adserror","adscanceled","nopreroll"]),i),t.paused()||i({type:"play"})},S=s["default"].registerPlugin||s["default"].plugin;S("ads",k)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[10]);