UNPKG

videojs-contrib-ads

Version:

A framework that provides common functionality needed by video advertisement libraries working with video.js.

1 lines 14.6 kB
!function e(t,n,a){function o(s,d){if(!n[s]){if(!t[s]){var r="function"==typeof require&&require;if(!d&&r)return r(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[s]={exports:{}};t[s][0].call(u.exports,function(e){var n=t[s][1][e];return o(n?n:e)},u,u.exports,e,t,n,a)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<a.length;s++)o(a[s]);return o}({1:[function(e,t,n){(function(e){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var a="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,o=n(a),i=function(e){e.ads.cancelPlayTimeout||(o.default.browser.IS_IOS&&o.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=document.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","adplaying","adtimeout","adserror","adscanceled","adskip","playing"],function(){e.el_.style.display="block",a.remove()}),e.on("fullscreenchange",function(){a&&e.hasClass("vjs-fullscreen")&&(e.el_.style.display="block",a.remove())})}(),e.ads.cancelPlayTimeout=window.setTimeout(function(){e.ads.cancelPlayTimeout=null,e.paused()||e.pause(),e.ads.cancelledPlay=!0},1))};t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){"use strict";var a=function(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),window.setTimeout(t,1)};t.exports=a},{}],3:[function(e,t,n){(function(e){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var a="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},o="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,i=n(o),s=function(e,t){return t?encodeURIComponent(e):e},d=function(e,t,n){if(e&&e[n])for(var a=e[n],o=Object.keys(a),i=0;i<o.length;i++){var s="{mediainfo."+n+"."+o[i]+"}";t[s]=a[o[i]]}},r=function(e,t,n){void 0===t&&(t=!1);var o={};void 0!==n&&(o=n),o["{player.id}"]=this.options_["data-player"],o["{mediainfo.id}"]=this.mediainfo?this.mediainfo.id:"",o["{mediainfo.name}"]=this.mediainfo?this.mediainfo.name:"",o["{mediainfo.description}"]=this.mediainfo?this.mediainfo.description:"",o["{mediainfo.tags}"]=this.mediainfo?this.mediainfo.tags:"",o["{mediainfo.reference_id}"]=this.mediainfo?this.mediainfo.reference_id:"",o["{mediainfo.duration}"]=this.mediainfo?this.mediainfo.duration:"",o["{mediainfo.ad_keys}"]=this.mediainfo?this.mediainfo.ad_keys:"",o["{player.duration}"]=this.duration(),o["{timestamp}"]=(new Date).getTime(),o["{document.referrer}"]=document.referrer,o["{window.location.href}"]=window.location.href,o["{random}"]=Math.floor(1e12*Math.random()),d(this.mediainfo,o,"custom_fields"),d(this.mediainfo,o,"customFields");for(var r in o)e=e.split(r).join(s(o[r],t));return e=e.replace(/{pageVariable\.([^}]+)}/g,function(e,n){for(var o=void 0,d=window,r=n.split("."),l=0;l<r.length;l++)l===r.length-1?o=d[r[l]]:d=d[r[l]];var u="undefined"==typeof o?"undefined":a(o);return null===o?"null":void 0===o?(i.default.log.warn('Page variable "'+n+'" not found'),""):"string"!==u&&"number"!==u&&"boolean"!==u?(i.default.log.warn('Page variable "'+n+'" is not a supported type'),""):s(String(o),t)})};t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){(function(e){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var a="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,o=(n(a),function(e,t){t.isImmediatePropagationStopped=function(){return!0},t.cancelBubble=!0,t.isPropagationStopped=function(){return!0}}),i=function(e,t,n){o(e,n),e.trigger({type:t+n.type,state:e.ads.state,originalEvent:n})},s=function(e){if("playing"===e.type&&"preroll?"===this.ads.state)i(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)i(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())&&i(this,"ad",e);else if("content-playback"===this.ads.state&&"ended"===e.type)i(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 i(this,"content",e)}if(this.ads.snapshot&&this.ads.snapshot.ended){if("pause"===e.type||"ended"===e.type)return;return i(this,"content",e)}"playing"!==e.type&&i(this,"content",e)}}else i(this,"ad",e)};t.exports=s}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){(function(e){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var a="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,o=n(a),i={};i.getPlayerSnapshot=function(e){var t=void 0;t=o.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():[],i=[],s={ended:e.ended(),currentSrc:e.currentSrc(),src:e.src(),currentTime:t,type:e.currentType()};n&&(s.nativePoster=n.poster,s.style=n.getAttribute("style"));for(var d=0;d<a.length;d++){var r=a[d];i.push({track:r,mode:r.mode}),r.mode="disabled"}return s.suppressedTracks=i,s},i.restorePlayerSnapshot=function(e,t){if(e.ads.disableNextSnapshotRestore===!0)return void(e.ads.disableNextSnapshotRestore=!1);var n=e.$(".vjs-tech"),a=20,i=t.suppressedTracks,s=void 0,d=function(){for(var e=0;e<i.length;e++)s=i[e],s.track.mode=s.mode},r=function(){var n=void 0;o.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)):e.currentTime(t.ended?e.duration():t.currentTime),t.ended||e.play()},l=function t(){if(e.off("contentcanplay",t),e.ads.tryToResumeTimeout_&&(e.clearTimeout(e.ads.tryToResumeTimeout_),e.ads.tryToResumeTimeout_=null),n=e.el().querySelector(".vjs-tech"),n.readyState>1)return r();if(void 0===n.seekable)return r();if(n.seekable.length>0)return r();if(a--)window.setTimeout(t,50);else try{r()}catch(e){o.default.log.warn("Failed to resume the content after an advertisement",e)}};t.nativePoster&&(n.poster=t.nativePoster),"style"in t&&n.setAttribute("style",t.style||""),e.ads.videoElementRecycled()?(e.one("contentloadedmetadata",d),e.src({src:t.currentSrc,type:t.type}),e.load(),e.one("contentcanplay",l),e.ads.tryToResumeTimeout_=e.setTimeout(l,2e3)):e.ended()&&t.ended||(d(),e.play())},t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(e,t,n){(function(t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var a="undefined"!=typeof window?window.videojs:"undefined"!=typeof t?t.videojs:null,o=n(a),i=e(4),s=n(i),d=e(5),r=n(d),l=e(2),u=n(l),c=e(1),f=n(c),p=e(3),y=n(p),h=o.default.getComponent("Html5").Events,m=function(e){var t=e.$(".vjs-tech");t&&t.removeAttribute("poster")},v={timeout:5e3,prerollTimeout:100,postrollTimeout:100,debug:!1,stitchedAds:!1},g=function(e){var t=this,n=o.default.mergeOptions(v,e),a=h.concat(["firstplay","loadedalldata","playing"]);t.on(a,s.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,VERSION:"4.1.6",reset:function(){t.ads.disableNextSnapshotRestore=!1,t.ads._contentHasEnded=!1,t.ads.snapshot=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(){var e=void 0,n=void 0;if(!this.snapshot)throw new Error("You cannot use videoElementRecycled while there is no snapshot.");return e=t.src()!==this.snapshot.src,n=t.currentSrc()!==this.snapshot.currentSrc,e||n},isLive:function(e){return e.duration()===1/0||"8"===o.default.browser.IOS_VERSION&&0===e.duration()},shouldPlayContentBehindAd:function(e){return!o.default.browser.IS_IOS&&!o.default.browser.IS_ANDROID&&e.duration()===1/0}},t.ads.stitchedAds(n.stitchedAds),t.ads.adMacroReplacement=y.default.bind(t),(0,u.default)(t),t.on("contentupdate",t.ads.reset);var i={"content-set":{events:{adscanceled:function(){this.state="content-playback"},adsready:function(){this.state="ads-ready"},play:function(){this.state="ads-ready?",(0,f.default)(t),m(t)},adserror:function(){this.state="content-playback"},adskip:function(){this.state="content-playback"}}},"ads-ready":{events:{play:function(){this.state="preroll?",(0,f.default)(t)},adskip:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"}}},"preroll?":{enter:function(){t.ads.nopreroll_?(t.trigger("readyforpreroll"),window.setTimeout(function(){t.trigger("nopreroll")},1)):(t.addClass("vjs-ad-loading"),t.ads.adTimeoutTimeout=window.setTimeout(function(){t.trigger("adtimeout")},n.prerollTimeout),t.trigger("readyforpreroll"))},leave:function(){window.clearTimeout(t.ads.adTimeoutTimeout)},events:{play:function(){(0,f.default)(t)},adstart:function(){this.state="ad-playback"},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=window.setTimeout(function(){t.trigger("adtimeout")},n.timeout)},leave:function(){window.clearTimeout(t.ads.adTimeoutTimeout),t.removeClass("vjs-ad-loading")},events:{play:function(){(0,f.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=r.default.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"),m(t),t.ads.cancelPlayTimeout&&window.setTimeout(function(){window.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)||r.default.restorePlayerSnapshot(t,this.snapshot),t.ads.shouldPlayContentBehindAd(t)&&t.volume(this.preAdVolume_)},events:{adend:function(){this.state="content-resuming"},adserror:function(){this.state="content-resuming",t.trigger("adend")}}},"content-resuming":{enter:function(){this._contentHasEnded&&(window.clearTimeout(t.ads._fireEndedTimeout),t.ads._fireEndedTimeout=window.setTimeout(function(){t.trigger("ended")},1e3))},leave:function(){window.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=r.default.getPlayerSnapshot(t),t.ads.nopostroll_?window.setTimeout(function(){t.ads.state="content-resuming",t.trigger("ended")},1):(t.addClass("vjs-ad-loading"),t.ads.adTimeoutTimeout=window.setTimeout(function(){t.trigger("adtimeout")},n.postrollTimeout))},leave:function(){window.clearTimeout(t.ads.adTimeoutTimeout),t.removeClass("vjs-ad-loading")},events:{adstart:function(){this.state="ad-playback"},adskip:function(){this.state="content-resuming",window.setTimeout(function(){t.trigger("ended")},1)},adtimeout:function(){this.state="content-resuming",window.setTimeout(function(){t.trigger("ended")},1)},adserror:function(){this.state="content-resuming",window.setTimeout(function(){t.trigger("ended")},1)},contentupdate:function(){this.state="ads-ready?"}}},"content-playback":{enter:function(){t.ads.cancelPlayTimeout&&(window.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"},contentupdate:function(){t.ads.shouldPlayContentBehindAd(t)||(0,f.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?"))}}}},d=function(e){var a=t.ads.state,s=i[a].events;if(s){var d=s[e.type];d&&d.apply(t.ads)}if(a!==t.ads.state){var r=a,l=t.ads.state;t.ads.triggerevent=e.type,i[r].leave&&i[r].leave.apply(t.ads),i[l].enter&&i[l].enter.apply(t.ads),n.debug&&o.default.log("ads",t.ads.triggerevent+" triggered: "+r+" -> "+l)}};t.on(h.concat(["adtimeout","contentupdate","contentplaying","contentended","contentresumed","adstart","adend","adskip","adsready","adserror","adscanceled","nopreroll"]),d),t.paused()||d({type:"play"})};o.default.plugin("ads",g)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[6]);