1(function(global,factory){typeof exports==='object'&&typeof module!=='undefined'?factory(require('video.js')):typeof define==='function'&&define.amd?define(['video.js'],factory):(factory(global.videojs))}(this,(function(videojs){'use strict';videojs=videojs&&videojs.hasOwnProperty('default')?videojs['default']:videojs;var PlayerWrapper=function PlayerWrapper(player,adsPluginSettings,controller){this.vjsPlayer=player;this.controller=controller;this.contentTrackingTimer=null;this.contentComplete=!1;this.updateTimeIntervalHandle=null;this.updateTimeInterval=1000;this.seekCheckIntervalHandle=null;this.seekCheckInterval=1000;this.resizeCheckIntervalHandle=null;this.resizeCheckInterval=250;this.seekThreshold=100;this.contentEndedListeners=[];this.contentSource='';this.contentPlayheadTracker={currentTime:0,previousTime:0,seeking:!1,duration:0};this.vjsPlayerDimensions={width:this.getPlayerWidth(),height:this.getPlayerHeight()};this.vjsControls=this.vjsPlayer.getChild('controlBar');this.h5Player=null;this.vjsPlayer.one('play',this.setUpPlayerIntervals.bind(this));this.boundContentEndedListener=this.localContentEndedListener.bind(this);this.vjsPlayer.on('contentended',this.boundContentEndedListener);this.vjsPlayer.on('dispose',this.playerDisposedListener.bind(this));this.vjsPlayer.on('readyforpreroll',this.onReadyForPreroll.bind(this));this.vjsPlayer.ready(this.onPlayerReady.bind(this));this.vjsPlayer.ads(adsPluginSettings)};PlayerWrapper.prototype.setUpPlayerIntervals=function(){this.updateTimeIntervalHandle=setInterval(this.updateCurrentTime.bind(this),this.updateTimeInterval);this.seekCheckIntervalHandle=setInterval(this.checkForSeeking.bind(this),this.seekCheckInterval);this.resizeCheckIntervalHandle=setInterval(this.checkForResize.bind(this),this.resizeCheckInterval)};PlayerWrapper.prototype.updateCurrentTime=function(){if(!this.contentPlayheadTracker.seeking){this.contentPlayheadTracker.currentTime=this.vjsPlayer.currentTime()}};PlayerWrapper.prototype.checkForSeeking=function(){var tempCurrentTime=this.vjsPlayer.currentTime();var diff=(tempCurrentTime-this.contentPlayheadTracker.previousTime)*1000;if(Math.abs(diff)>this.seekCheckInterval+this.seekThreshold){this.contentPlayheadTracker.seeking=!0}else{this.contentPlayheadTracker.seeking=!1} 2this.contentPlayheadTracker.previousTime=this.vjsPlayer.currentTime()};PlayerWrapper.prototype.checkForResize=function(){var currentWidth=this.getPlayerWidth();var currentHeight=this.getPlayerHeight();if(currentWidth!=this.vjsPlayerDimensions.width||currentHeight!=this.vjsPlayerDimensions.height){this.vjsPlayerDimensions.width=currentWidth;this.vjsPlayerDimensions.height=currentHeight;this.controller.onPlayerResize(currentWidth,currentHeight)}};PlayerWrapper.prototype.localContentEndedListener=function(){if(!this.contentComplete){this.contentComplete=!0;this.controller.onContentComplete()} 3for(var index in this.contentEndedListeners){if(typeof this.contentEndedListeners[index]==='function'){this.contentEndedListeners[index]()}} 4clearInterval(this.updateTimeIntervalHandle);clearInterval(this.seekCheckIntervalHandle);clearInterval(this.resizeCheckIntervalHandle);if(this.vjsPlayer.el()){this.vjsPlayer.one('play',this.setUpPlayerIntervals.bind(this))}};PlayerWrapper.prototype.onNoPostroll=function(){this.vjsPlayer.trigger('nopostroll')};PlayerWrapper.prototype.playerDisposedListener=function(){this.contentEndedListeners=[];this.controller.onPlayerDisposed();this.contentComplete=!0;this.vjsPlayer.off('contentended',this.boundContentEndedListener);if(this.vjsPlayer.ads.adTimeoutTimeout){clearTimeout(this.vjsPlayer.ads.adTimeoutTimeout)} 5var intervalsToClear=[this.updateTimeIntervalHandle,this.seekCheckIntervalHandle,this.resizeCheckIntervalHandle];for(var index in intervalsToClear){if(intervalsToClear[index]){clearInterval(intervalsToClear[index])}}};PlayerWrapper.prototype.onReadyForPreroll=function(){this.controller.onPlayerReadyForPreroll()};PlayerWrapper.prototype.onPlayerReady=function(){this.h5Player=document.getElementById(this.controller.getSettings().id).getElementsByClassName('vjs-tech')[0];if(this.h5Player.hasAttribute('autoplay')){this.controller.setSetting('adWillAutoPlay',!0)} 6this.onVolumeChange();this.vjsPlayer.on('fullscreenchange',this.onFullscreenChange.bind(this));this.vjsPlayer.on('volumechange',this.onVolumeChange.bind(this))};PlayerWrapper.prototype.onFullscreenChange=function(){if(this.vjsPlayer.isFullscreen()){this.controller.onPlayerEnterFullscreen()}else{this.controller.onPlayerExitFullscreen()}};PlayerWrapper.prototype.onVolumeChange=function(){var newVolume=this.vjsPlayer.muted()?0:this.vjsPlayer.volume();this.controller.onPlayerVolumeChanged(newVolume)};PlayerWrapper.prototype.injectAdContainerDiv=function(adContainerDiv){this.vjsControls.el().parentNode.appendChild(adContainerDiv)};PlayerWrapper.prototype.getContentPlayer=function(){return this.h5Player};PlayerWrapper.prototype.getVolume=function(){return this.vjsPlayer.muted()?0:this.vjsPlayer.volume()};PlayerWrapper.prototype.setVolume=function(volume){this.vjsPlayer.volume(volume);if(volume==0){this.vjsPlayer.muted(!0)}else{this.vjsPlayer.muted(!1)}};PlayerWrapper.prototype.unmute=function(){this.vjsPlayer.muted(!1)};PlayerWrapper.prototype.mute=function(){this.vjsPlayer.muted(!0)};PlayerWrapper.prototype.play=function(){this.vjsPlayer.play()};PlayerWrapper.prototype.getPlayerWidth=function(){var width=(getComputedStyle(this.vjsPlayer.el(
6))||{}).width;if(!width||parseInt(width,10)===0){width=(this.vjsPlayer.el().getBoundingClientRect()||{}).width} 7return parseInt(width,10)||this.vjsPlayer.width()};PlayerWrapper.prototype.getPlayerHeight=function(){var height=(getComputedStyle(this.vjsPlayer.el())||{}).height;if(!height||parseInt(height,10)===0){height=(this.vjsPlayer.el().getBoundingClientRect()||{}).height} 8return parseInt(height,10)||this.vjsPlayer.height()};PlayerWrapper.prototype.getPlayerOptions=function(){return this.vjsPlayer.options_};PlayerWrapper.prototype.toggleFullscreen=function(){if(this.vjsPlayer.isFullscreen()){this.vjsPlayer.exitFullscreen()}else{this.vjsPlayer.requestFullscreen()}};PlayerWrapper.prototype.getContentPlayheadTracker=function(){return this.contentPlayheadTracker};PlayerWrapper.prototype.onAdError=function(adErrorEvent){this.vjsControls.show();var errorMessage=adErrorEvent.getError!==undefined?adErrorEvent.getError():adErrorEvent.stack;this.vjsPlayer.trigger({type:'adserror',data:{AdError:errorMessage,AdErrorEvent:adErrorEvent}})};PlayerWrapper.prototype.onAdBreakStart=function(adEvent){this.contentSource=this.vjsPlayer.currentSrc();this.vjsPlayer.off('contentended',this.boundContentEndedListener);if(adEvent.getAd().getAdPodInfo().getPodIndex()!=-1){this.vjsPlayer.ads.startLinearAdMode()} 9this.vjsControls.hide();this.vjsPlayer.pause()};PlayerWrapper.prototype.onAdBreakEnd=function(){this.vjsPlayer.on('contentended',this.boundContentEndedListener);if(this.vjsPlayer.ads.inAdBreak()){this.vjsPlayer.ads.endLinearAdMode()} 10this.vjsControls.show()};PlayerWrapper.prototype.onAdStart=function(){this.vjsPlayer.trigger('ads-ad-started')};PlayerWrapper.prototype.onAllAdsCompleted=function(){if(this.contentComplete==!0){if(this.h5Player.src!=this.contentSource){this.vjsPlayer.src(this.contentSource)} 11this.controller.onContentAndAdsCompleted()}};PlayerWrapper.prototype.onAdsReady=function(){this.vjsPlayer.trigger('adsready')};PlayerWrapper.prototype.changeSource=function(contentSrc,playOnLoad){if(this.vjsPlayer.currentSrc()){this.vjsPlayer.currentTime(0);this.vjsPlayer.pause()} 12if(contentSrc){this.vjsPlayer.src(contentSrc)} 13if(playOnLoad){this.vjsPlayer.one('loadedmetadata',this.playContentFromZero.bind(this))}else{this.vjsPlayer.one('loadedmetadata',this.seekContentToZero.bind(this))}};PlayerWrapper.prototype.seekContentToZero=function(){this.vjsPlayer.currentTime(0)};PlayerWrapper.prototype.playContentFromZero=function(){this.vjsPlayer.currentTime(0);this.vjsPlayer.play()};PlayerWrapper.prototype.addContentEndedListener=function(listener){this.contentEndedListeners.push(listener)};PlayerWrapper.prototype.reset=function(){this.vjsPlayer.on('contentended',this.boundContentEndedListener);this.vjsControls.show();if(this.vjsPlayer.ads.inAdBreak()){this.vjsPlayer.ads.endLinearAdMode()} 14this.contentPlayheadTracker.currentTime=0};var AdUi=function AdUi(controller){this.controller=controller;this.adContainerDiv=document.createElement('div');this.controlsDiv=document.createElement('div');this.countdownDiv=document.createElement('div');this.seekBarDiv=document.createElement('div');this.progressDiv=document.createElement('div');this.playPauseDiv=document.createElement('div');this.muteDiv=document.createElement('div');this.sliderDiv=document.createElement('div');this.sliderLevelDiv=document.createElement('div');this.fullscreenDiv=document.createElement('div');this.boundOnMouseUp=this.onMouseUp.bind(this);this.boundOnMouseMove=this.onMouseMove.bind(this);this.adPlayheadTracker={'currentTime':0,'duration':0,'isPod':!1,'adPosition':0,'totalAds':0};this.controlPrefix=this.controller.getSettings().id?this.controller.getSettings().id+'_':'';this.showCountdown=!0;if(this.controller.getSettings().showCountdown===!1){this.showCountdown=!1} 15this.createAdContainer()};AdUi.prototype.createAdContainer=function(){this.assignControlAttributes(this.adContainerDiv,'ima-ad-container');this.adContainerDiv.style.position='absolute';this.adContainerDiv.style.zIndex=1111;this.adContainerDiv.addEventListener('mouseenter',this.showAdControls.bind(this),!1);this.adContainerDiv.addEventListener('mouseleave',this.hideAdControls.bind(this),!1);this.createControls();this.controller.injectAdContainerDiv(this.adContainerDiv)};AdUi.prototype.createControls=function(){this.assignControlAttributes(this.controlsDiv,'ima-controls-div');this.controlsDiv.style.width='100%';this.assignControlAttributes(this.countdownDiv,'ima-countdown-div');this.countdownDiv.innerHTML=this.controller.getSettings().adLabel;this.countdownDiv.style.display=this.showCountdown?'block':'none';this.assignControlAttributes(this.seekBarDiv,'ima-seek-bar-div');this.seekBarDiv.style.width='100%';this.assignControlAttributes(this.progressDiv,'ima-progress-div');this.assignControlAttributes(this.playPauseDiv,'ima-play-pause-div');this.addClass(this.playPauseDiv,'ima-playing');this.playPauseDiv.addEventListener('click',this.onAdPlayPauseClick.bind(this),!1);this.assignControlAttributes(this.muteDiv,'ima-mute-div');this.addClass(this.muteDiv,'ima-non-muted');this.muteDiv.addEventListener('click',this.onAdMuteClick.bind(this),!1);this.assignControlAttributes(this.sliderDiv,'ima-slider-div');this.sliderDiv.addEventListener('mousedown',this.onAdVolumeSliderMouseDown.bind(this),!1);if(this.controller.getIsIos()){this.sliderDiv.style.display='none'} 16this.assignControlAttributes(this.sliderLevelDiv,'ima-slider-level-div');this.assignControlAttributes(this.fullscreenDiv,'ima-fullscreen-div');this.addClass(this.fullscreenDiv,'ima-non-fullscreen');this.fullscreenDiv.addEventListener('click',this.onAdFullscreenClick.bind(this),!1);this.adContainerDiv.appendChild(this.controlsDiv);this.controlsDiv.appendChild(this.countdownDiv);this.controlsDiv.appendChild(this.seekBarDiv);this.controlsDiv.appendChild(this.playPauseDiv);this.controlsDiv.appendChild(this.muteDiv);this.controlsDiv.appendChild(this.sliderDiv);this.controlsDiv.appendChild(this.fullscreenDiv);this.seekBarDiv.appendChild(this.progressDiv);this.sliderDiv.appendChild(this.sliderLevelDiv)};AdUi.prototype.onAdPlayPauseClick=function(){this.controller.onAdPlayPauseClick()};AdUi.prototype.onAdMuteClick=function(){this.controller.onAdMuteClick()};AdUi.prototype.onAdFullscreenClick=function(){this.controller.toggleFullscreen()};AdUi.prototype.onAdsPaused=function(){this.addClass(this.playPauseDiv,'ima-paused');this.removeClass(this.playPauseDiv,'ima-playing');this.showAdControls()};AdUi.prototype.onAdsResumed=function(){this.onAdsPlaying();this.showAdControls()};AdUi.prototype.onAdsPlaying=function(){this.addClass(this.playPauseDiv,'ima-playing');this.removeClass(this.playPauseDiv,'ima-paused')};AdUi.prototype.updateAdUi=function(currentTime,remainingTime,duration,adPosition,totalAds){var remainingMinutes=Math.floor(remainingTime/60);var remainingSeconds=Math.floor(remainingTime%60);if(remainingSeconds.toString().length<2){remainingSeconds='0'+remainingSeconds} 17var podCount=': ';if(totalAds>1){podCount=' ('+adPosition+' '+this.controller.getSettings().adLabelNofN+' '+totalAds+'): '} 18this.countdownDiv.innerHTML=this.controller.getSettings().adLabel+podCount+remainingMinutes+':'+remainingSeconds;var playProgressRatio=currentTime/duration;var playProgressPercent=playProgressRatio*100;this.progressDiv.style.width=playProgressPercent+'%'};AdUi.prototype.unmute=function(){this.addClass(this.muteDiv,'ima-non-muted');this.removeClass(this.muteDiv,'ima-muted');this.sliderLevelDiv.style.width=this.controller.getPlayerVolume()*100+'%'};AdUi.prototype.mute=function(){this.addClass(this.muteDiv,'ima-muted');this.removeClass(this.muteDiv,'ima-non-muted');this.sliderLevelDiv.style.width='0%'};AdUi.prototype.onAdVolumeSliderMouseDown=function(){document.addEventListener('mouseup',this.boundOnMouseUp,!1);document.addEventListener('mousemove',this.boundOnMouseMove,!1)};AdUi.prototype.onMouseMove=function(event){this.changeVolume(event)};AdUi.prototype.onMouseUp=function(event){this.changeVolume(event);document.removeEventListener('mouseup',this.boundOnMouseUp);document.removeEventListener('mousemove',this.boundOnMouseMove)};AdUi.prototype.changeVolume=function(event){var percent=(event.clientX-this.sliderDiv.getBoundingClientRect().left)/this.sliderDiv.offsetWidth;percent*=100;percent=Math.min(Math.max(percent,0),100);this.sliderLevelDiv.style.width=percent+'%';if(this.percent==0){this.addClass(this.muteDiv,'ima-muted');this.removeClass(this.muteDiv,'ima-non-muted')}else{this.addClass(this.muteDiv,'ima-non-muted');this.removeClass(this.muteDiv,'ima-muted')} 19this.controller.setVolume(percent/100)};AdUi.prototype.showAdContainer=function(){this.adContainerDiv.style.display='block'};AdUi.prototype.onAdError=function(){this.adContainerDiv.style.display='none'};AdUi.prototype.onAdBreakStart=function(adEvent){this.adContainerDiv.style.display='block';var contentType=adEvent.getAd().getContentType();if(contentType==='application/javascript'&&!this.controller.getSettings().showControlsForJSAds){this.controlsDiv.style.display='none'}else{this.controlsDiv.style.display='block'} 20this.onAdsPlaying();this.hideAdControls()};AdUi.prototype.onAdBreakEnd=function(){var currentAd=this.controller.getCurrentAd();if(currentAd==null||currentAd.isLinear()){this.adContainerDiv.style.display='none'} 21this.controlsDiv.style.display='none';this.countdownDiv.innerHTML=''};AdUi.prototype.onAllAdsCompleted=function(){this.adContainerDiv.style.display='none'};AdUi.prototype.onLinearAdStart=function(){this.removeClass(this.adContainerDiv,'bumpable-ima-ad-container')};AdUi.prototype.onNonLinearAdLoad=function(){this.adContainerDiv.style.display='block';this.addClass(this.adContainerDiv,'bumpable-ima-ad-container')};AdUi.prototype.onPlayerEnterFullscreen=function(){this.addClass(this.fullscreenDiv,'ima-fullscreen');this.removeClass(this.fullscreenDiv,'ima-non-fullscreen')};AdUi.prototype.onPlayerExitFullscreen=function(){this.addClass(this.fullscreenDiv,'ima-non-fullscreen');this.removeClass(this.fullscreenDiv,'ima-fullscreen')};AdUi.prototype.onPlayerVolumeChanged=function(volume){if(volume==0){this.addClass(this.muteDiv,'ima-muted');this.removeClass(this.muteDiv,'ima-non-muted');this.sliderLevelDiv.style.width='0%'}else{this.addClass(this.muteDiv,'ima-non-muted');this.removeClass(this.muteDiv,'ima-muted');this.sliderLevelDiv.style.width=volume*100+'%'}};AdUi.prototype.showAdControls=function(){this.addClass(this.controlsDiv,'ima-controls-div-showing');this.playPauseDiv.style.display='block';this.muteDiv.style.display='block';this.fullscreenDiv.style.display='block';if(!this.controller.getIsIos()){this.sliderDiv.style.display='block'}};AdUi.prototype.hideAdControls=function(){this.removeClass(this.controlsDiv,'ima-controls-div-showing');this.playPauseDiv.style.display='none';this.muteDiv.style.display='none';this.sliderDiv.style.display='none';this.fullscreenDiv.style.display='none'};AdUi.prototype.assignControlAttributes=function(element,controlName){element.i
21d=this.controlPrefix+controlName;element.className=this.controlPrefix+controlName+' '+controlName};AdUi.prototype.getClassRegexp=function(className){return new RegExp('(^|[^A-Za-z-])'+className+'((?![A-Za-z-])|$)','gi')};AdUi.prototype.elementHasClass=function(element,className){var classRegexp=this.getClassRegexp(className);return classRegexp.test(element.className)};AdUi.prototype.addClass=function(element,classToAdd){element.className=element.className.trim()+' '+classToAdd};AdUi.prototype.removeClass=function(element,classToRemove){var classRegexp=this.getClassRegexp(classToRemove);element.className=element.className.trim().replace(classRegexp,'')};AdUi.prototype.getAdContainerDiv=function(){return this.adContainerDiv};AdUi.prototype.setShowCountdown=function(showCountdownIn){this.showCountdown=showCountdownIn;this.countdownDiv.style.display=this.showCountdown?'block':'none'};var name="videojs-ima";var version="1.4.0";var license="Apache-2.0";var main="./dist/videojs.ima.js";var author={"name":"Google Inc."};var engines={"node":">=0.8.0"};var scripts={"contBuild":"watch 'npm run rollup:max' src","predevServer":"echo \"Starting up server on localhost:8000.\"","devServer":"forever start ./node_modules/http-server/bin/http-server -p 8000 && npm run contBuild","postdevServer":"forever stop ./node_modules/http-server/bin/http-server","lint":"eslint \"src/*.js\"","rollup":"npm-run-all rollup:*","rollup:max":"rollup -c configs/rollup.config.js","rollup:min":"rollup -c configs/rollup.config.min.js","pretest":"npm run rollup","start":"npm run devServer","test":"npm-run-all test:*","test:vjs5":"npm install [email protected] --no-save && npm-run-all -p -r testServer webdriver","test:vjs6":"npm install video.js@6 --no-save && npm-run-all -p -r testServer webdriver","testServer":"http-server --cors -p 8000 --silent","preversion":"node scripts/preversion.js && npm run lint && npm test","version":"node scripts/version.js","postversion":"node scripts/postversion.js","webdriver":"mocha test/webdriver/*.js --no-timeouts"};var repository={"type":"git","url":"https://github.com/googleads/videojs-ima"};var files=["CHANGELOG.md","LICENSE","README.md","dist/","src/"];var dependencies={"can-autoplay":"^3.0.0","video.js":"^5.19.2 || ^6","videojs-contrib-ads":"^6"};var devDependencies={"babel-core":"^6.26.0","babel-preset-env":"^1.6.1","child_process":"^1.0.2","chromedriver":"^2.35.0","conventional-changelog-cli":"^1.3.5","conventional-changelog-videojs":"^3.0.0","eslint":"^4.11.0","eslint-config-google":"^0.9.1","eslint-plugin-jsdoc":"^3.2.0","forever":"^0.15.3","geckodriver":"^1.10.0","http-server":"^0.10.0","mocha":"^4.0.1","npm-run-all":"^4.1.2","path":"^0.12.7","rimraf":"^2.6.2","rollup":"^0.51.8","rollup-plugin-babel":"^3.0.3","rollup-plugin-copy":"^0.2.3","rollup-plugin-json":"^2.3.0","rollup-plugin-uglify":"^2.0.1","selenium-webdriver":"^3.6.0","uglify-es":"^3.1.10","watch":"^1.0.2"};var keywords=["videojs","videojs-plugin"];var pkg={name:name,version:version,license:license,main:main,author:author,engines:engines,scripts:scripts,repository:repository,files:files,dependencies:dependencies,devDependencies:devDependencies,keywords:keywords};var SdkImpl=function SdkImpl(controller){this.controller=controller;this.adDisplayContainer=null;this.adDisplayContainerInitialized=!1;this.adsLoader=null;this.adsManager=null;this.adsRenderingSettings=null;this.adTagUrl=null;this.adsResponse=null;this.currentAd=null;this.adTrackingTimer=null;this.allAdsCompleted=!1;this.adsActive=!1;this.adPlaying=!1;this.adMuted=!1;this.adBreakReadyListener=undefined;this.contentCompleteCalled=!1;this.adsManagerDimensions={width:0,height:0};this.autoPlayAdBreaks=!0;if(this.controller.getSettings().autoPlayAdBreaks===!1){this.autoPlayAdBreaks=!1} 22if(this.controller.getSettings().locale){google.ima.settings.setLocale(this.controller.getSettings().locale)} 23if(this.controller.getSettings().disableFlashAds){google.ima.settings.setDisableFlashAds(this.controller.getSettings().disableFlashAds)} 24if(this.controller.getSettings().disableCustomPlaybackForIOS10Plus){google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.controller.getSettings().disableCustomPlaybackForIOS10Plus)} 25this.initAdObjects();if(this.controller.getSettings().adTagUrl||this.controller.getSettings().adsResponse){this.requestAds()}};SdkImpl.prototype.initAdObjects=function(){this.adDisplayContainer=new google.ima.AdDisplayContainer(this.controller.getAdContainerDiv(),this.controller.getContentPlayer());this.adsLoader=new google.ima.AdsLoader(this.adDisplayContainer);this.adsLoader.getSettings().setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.ENABLED);if(this.controller.getSettings().vpaidAllowed==!1){this.adsLoader.getSettings().setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.DISABLED)} 26if(this.controller.getSettings().vpaidMode){this.adsLoader.getSettings().setVpaidMode(this.controller.getSettings().vpaidMode)} 27if(this.controller.getSettings().locale){this.adsLoader.getSettings().setLocale(this.controller.getSettings().locale)} 28if(this.controller.getSettings().numRedirects){this.adsLoader.getSettings().setNumRedirects(this.controller.getSettings().numRedirects)} 29this.adsLoader.getSettings().setPlayerType('videojs-ima');this.adsLoader.getSettings().setPlayerVersion(pkg.version);this.adsLoader.getSettings().setAutoPlayAdBreaks(this.autoPlayAdBreaks);this.adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.onAdsManagerLoaded.bind(this),!1);this.adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,this.onAdsLoaderError.bind(this),!1)};SdkImpl.prototype.requestAds=function(){var adsRequest=new google.ima.AdsRequest();if(this.controller.getSettings().adTagUrl){adsRequest.adTagUrl=this.controller.getSettings().adTagUrl}else{adsRequest.adsResponse=this.controller.getSettings().adsResponse} 30if(this.controller.getSettings().forceNonLinearFullSlot){adsRequest.forceNonLinearFullSlot=!0} 31adsRequest.linearAdSlotWidth=this.controller.getPlayerWidth();adsRequest.linearAdSlotHeight=this.controller.getPlayerHeight();adsRequest.nonLinearAdSlotWidth=this.controller.getSettings().nonLinearWidth||this.controller.getPlayerWidth();adsRequest.nonLinearAdSlotHeight=this.controller.getSettings().nonLinearHeight||this.controller.getPlayerHeight();adsRequest.setAdWillAutoPlay(this.controller.adsWillAutoplay());adsRequest.setAdWillPlayMuted(this.controller.adsWillPlayMuted());this.adsLoader.requestAds(adsRequest)};SdkImpl.prototype.onAdsManagerLoaded=function(adsManagerLoadedEvent){this.createAdsRenderingSettings();this.adsManager=adsManagerLoadedEvent.getAdsManager(this.controller.getContentPlayheadTracker(),this.adsRenderingSettings);this.adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,this.onAdError.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.AD_BREAK_READY,this.onAdBreakReady.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,this.onContentPauseRequested.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,this.onContentResumeRequested.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED,this.onAllAdsCompleted.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.LOADED,this.onAdLoaded.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.STARTED,this.onAdStarted.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.CLICK,this.onAdPaused.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE,this.onAdComplete.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.SKIPPED,this.onAdComplete.bind(this));if(this.controller.getIsMobile()){this.adsManager.addEventListener(google.ima.AdEvent.Type.PAUSED,this.onAdPaused.bind(this));this.adsManager.addEventListener(google.ima.AdEvent.Type.RESUMED,this.onAdResumed.bind(this))} 32if(!this.autoPlayAdBreaks){this.initAdsManager()} 33this.controller.onAdsReady();if(this.controller.getSettings().adsManagerLoadedCallback){this.controller.getSettings().adsManagerLoadedCallback()}};SdkImpl.prototype.onAdsLoaderError=function(event){window.console.warn('AdsLoader error: '+event.getError());this.controller.onErrorLoadingAds(event);if(this.adsManager){this.adsManager.destroy()}};SdkImpl.prototype.initAdsManager=function(){try{var initWidth=this.controller.getPlayerWidth();var initHeight=this.controller.getPlayerHeight();this.adsManagerDimensions.width=initWidth;this.adsManagerDimensions.height=initHeight;this.adsManager.init(initWidth,initHeight,google.ima.ViewMode.NORMAL);this.adsManager.setVolume(this.controller.getPlayerVolume());if(!this.adDisplayContainerInitialized){this.adDisplayContainer.initialize();this.adDisplayContainer.initialized=!0}}catch(adError){this.onAdError(adError)}};SdkImpl.prototype.createAdsRenderingSettings=function(){this.adsRenderingSettings=new google.ima.AdsRenderingSettings();this.adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete=!0;if(this.controller.getSettings().adsRenderingSettings){for(var setting in this.controller.getSettings().adsRenderingSettings){if(setting!==''){this.adsRenderingSettings[setting]=this.controller.getSettings().adsRenderingSettings[setting]}}}};SdkImpl.prototype.onAdError=function(adErrorEvent){var errorMessage=adErrorEvent.getError!==undefined?adErrorEvent.getError():adErrorEvent.stack;window.console.warn('Ad error: '+errorMessage);this.adsManager.destroy();this.controller.onAdError(adErrorEvent)};SdkImpl.prototype.onAdBreakReady=function(adEvent){this.adBreakReadyListener(adEvent)};SdkImpl.prototype.onContentPauseRequested=function(adEvent){this.adsActive=!0;this.adPlaying=!0;this.controller.onAdBreakStart(adEvent)};SdkImpl.prototype.onContentResumeRequested=function(adEvent){this.adsActive=!1;this.adPlaying=!1;this.controller.onAdBreakEnd()};SdkImpl.prototype.onAllAdsCompleted=function(adEvent){this.allAdsCompleted=!0;this.controller.onAllAdsCompleted()};SdkImpl.prototype.onAdLoaded=function(adEvent){if(!adEvent.getAd().isLinear()){this.controller.onNonLinearAdLoad();this.controller.playContent()}};SdkImpl.prototype.onAdStarted=function(adEvent){this.currentAd=adEvent.getAd();if(this.currentAd.isLinear()){this.adTrackingTimer=setInterval(this.onAdPlayheadTrackerInterval.bind(this),250);this.controller.onLinearAdStart()}else{this.controller.onNonLinearAdStart()}};SdkImpl.prototype.onAdPaused=function(){this.controller.onAdsPaused()};SdkImpl.prototype.onAdResumed=function(adEvent){this.controller.onAdsResumed()};SdkImpl.prototype.onAdComplete=function(){if(this.currentAd.isLinear()){clearInterval(this.adTrackingTimer)}};SdkImpl.prototype.onAdPlayheadTrackerInterval=function(){var remainingTime=this.adsManager.getRemainingTime();var duration=this.currentAd.getDuration();var currentTime=duration-remainingTime;currentTime=currentTime>0?currentTime:0;var totalAds=0;var adPosition=void 0;if(this.currentAd.getAdPodInfo()){adPosition=this.currentAd.getAdPodInfo().getAdPosition();totalAds=this.currentAd.getAdPodInfo().getTotalAds()} 34this.controller.onAdPlayheadUpdated(currentTime,remainingTime,duration,adPosition,totalAds)};SdkImpl.prototype.onContentComplete=function(){if(this.adsLoader){this.adsLoader.contentComplete();this.contentCompleteCalled=!0} 35if(this.adsManager&&this.adsManager.getCuePoints()&&!this.adsManager.getCuePoints().includes(-1)){this.controller.onNoPostroll()} 36if(this.allAdsCompleted){this.controller.onContentAndAdsCompleted()}};SdkImpl.prototype.onPlayerDisposed=function(){if(this.adTrackingTimer){clearInterval(this.adTrackingTimer)} 37if(this.adsManager){this.adsManager.destroy();this.adsManager=null}};SdkImpl.prototype.onPlayerReadyForPreroll=function(){if(this.autoPlayAdBreaks){this.initAdsManager();try{this.controller.showAdContainer();this.adsManager.setVolume(this.controller.getPlayerVolume());this.adsManager.start()}catch(adError){this.onAdError(adError)}}};SdkImpl.prototype.onPlayerEnterFullscreen=function(){if(this.adsManager){this.adsManager.resize(window.screen.width,window.screen.height,google.ima.ViewMode.FULLSCREEN)}};SdkImpl.prototype.onPlayerExitFullscreen=function(){if(this.adsManager){this.adsManager.resize(this.controller.getPlayerWidth(),this.controller.getPlayerHeight(),google.ima.ViewMode.NORMAL)}};SdkImpl.prototype.onPlayerVolumeChanged=function(volume){if(this.adsManager){this.adsManager.setVolume(volume)} 38if(volume==0){this.adMuted=!0}else{this.adMuted=!1}};SdkImpl.prototype.onPlayerResize=function(width,height){if(this.adsManager){this.adsManagerDimensions.width=width;this.adsManagerDimensions.height=height;this.adsManager.resize(width,height,google.ima.ViewMode.NORMAL)}};SdkImpl.prototype.getCurrentAd=function(){return this.currentAd};SdkImpl.prototype.setAdBreakReadyListener=function(listener){this.adBreakReadyListener=listener};SdkImpl.prototype.isAdPlaying=function(){return this.adPlaying};SdkImpl.prototype.isAdMuted=function(){return this.adMuted};SdkImpl.prototype.pauseAds=function(){this.adsManager.pause();this.adPlaying=!1};SdkImpl.prototype.resumeAds=function(){this.adsManager.resume();this.adPlaying=!0};SdkImpl.prototype.unmute=function(){this.adsManager.setVolume(1);this.adMuted=!1};SdkImpl.prototype.mute=function(){this.adsManager.setVolume(0);this.adMuted=!0};SdkImpl.prototype.setVolume=function(volume){this.adsManager.setVolume(volume);if(volume==0){this.adMuted=!0}else{this.adMuted=!1}};SdkImpl.prototype.initializeAdDisplayContainer=function(){this.adDisplayContainerInitialized=!0;this.adDisplayContainer.initialize()};SdkImpl.prototype.playAdBreak=function(){if(!this.autoPlayAdBreaks){this.controller.showAdContainer();this.adsManager.setVolume(this.controller.getPlayerVolume());this.adsManager.start()}};SdkImpl.prototype.addEventListener=function(event,callback){if(this.adsManager){this.adsManager.addEventListener(event,callback)}};SdkImpl.prototype.getAdsManager=function(){return this.adsManager};SdkImpl.prototype.reset=function(){this.adsActive=!1;this.adPlaying=!1;if(this.adTrackingTimer){clearInterval(this.adTrackingTimer)} 39if(this.adsManager){this.adsManager.destroy();this.adsManager=null} 40if(this.adsLoader&&!this.contentCompleteCalled){this.adsLoader.contentComplete()} 41this.contentCompleteCalled=!1;this.allAdsCompleted=!1};var Controller=function Controller(player,options){this.settings={};this.contentAndAdsEndedListeners=[];this.isMobile=navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/Android/i);this.isIos=navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i);this.initWithSettings(options);var contribAdsDefaults={debug:this.settings.debug,timeout:this.settings.timeout,prerollTimeout:this.settings.prerollTimeout};var adsPluginSettings=this.extend({},contribAdsDefaults,options.contribAdsSettings||{});this.playerWrapper=new PlayerWrapper(player,adsPluginSettings,this);this.adUi=new AdUi(this);this.sdkImpl=new SdkImpl(this)};Controller.IMA_DEFAULTS={debug:!1,timeout:5000,prerollTimeout:1000,adLabel:'Advertisement',adLabelNofN:'of',showControlsForJSAds:!0};Controller.prototype.initWithSettings=function(options){this.settings=this.extend({},Controller.IMA_DEFAULTS,options||{});if(!this.settings.id){window.console.error('Error: must provide id of video.js div');return} 42this.warnAboutDeprecatedSettings();this.showCountdown=!0;if(this.settings.showCountdown===!1){this.showCountdown=!1}};Controller.prototype.warnAboutDeprecatedSettings=function(){var _this=this;var deprecatedSettings=['adWillAutoplay','adsWillAutoplay','adWillPlayMuted','adsWillPlayMuted'];
42deprecatedSettings.forEach(function(setting){if(_this.settings[setting]!==undefined){console.warn('WARNING: videojs.ima setting '+setting+' is deprecated')}})};Controller.prototype.getSettings=function(){return this.settings};Controller.prototype.getIsMobile=function(){return this.isMobile};Controller.prototype.getIsIos=function(){return this.isIos};Controller.prototype.injectAdContainerDiv=function(adContainerDiv){this.playerWrapper.injectAdContainerDiv(adContainerDiv)};Controller.prototype.getAdContainerDiv=function(){return this.adUi.getAdContainerDiv()};Controller.prototype.getContentPlayer=function(){return this.playerWrapper.getContentPlayer()};Controller.prototype.getContentPlayheadTracker=function(){return this.playerWrapper.getContentPlayheadTracker()};Controller.prototype.requestAds=function(){this.sdkImpl.requestAds()};Controller.prototype.setSetting=function(key,value){this.settings[key]=value};Controller.prototype.onErrorLoadingAds=function(adErrorEvent){this.adUi.onAdError();this.playerWrapper.onAdError(adErrorEvent)};Controller.prototype.onAdPlayPauseClick=function(){if(this.sdkImpl.isAdPlaying()){this.adUi.onAdsPaused();this.sdkImpl.pauseAds()}else{this.adUi.onAdsPlaying();this.sdkImpl.resumeAds()}};Controller.prototype.onAdMuteClick=function(){if(this.sdkImpl.isAdMuted()){this.playerWrapper.unmute();this.adUi.unmute();this.sdkImpl.unmute()}else{this.playerWrapper.mute();this.adUi.mute();this.sdkImpl.mute()}};Controller.prototype.setVolume=function(volume){this.playerWrapper.setVolume(volume);this.sdkImpl.setVolume(volume)};Controller.prototype.getPlayerVolume=function(){return this.playerWrapper.getVolume()};Controller.prototype.toggleFullscreen=function(){this.playerWrapper.toggleFullscreen()};Controller.prototype.onAdError=function(adErrorEvent){this.adUi.onAdError();this.playerWrapper.onAdError(adErrorEvent)};Controller.prototype.onAdBreakStart=function(adEvent){this.playerWrapper.onAdBreakStart(adEvent);this.adUi.onAdBreakStart(adEvent)};Controller.prototype.showAdContainer=function(){this.adUi.showAdContainer()};Controller.prototype.onAdBreakEnd=function(){this.playerWrapper.onAdBreakEnd();this.adUi.onAdBreakEnd()};Controller.prototype.onAllAdsCompleted=function(){this.adUi.onAllAdsCompleted();this.playerWrapper.onAllAdsCompleted()};Controller.prototype.onAdsPaused=function(){this.adUi.onAdsPaused()};Controller.prototype.onAdsResumed=function(){this.adUi.onAdsResumed()};Controller.prototype.onAdPlayheadUpdated=function(currentTime,remainingTime,duration,adPosition,totalAds){this.adUi.updateAdUi(currentTime,remainingTime,duration,adPosition,totalAds)};Controller.prototype.getCurrentAd=function(){return this.sdkImpl.getCurrentAd()};Controller.prototype.playContent=function(){this.playerWrapper.play()};Controller.prototype.onLinearAdStart=function(){this.adUi.onLinearAdStart();this.playerWrapper.onAdStart()};Controller.prototype.onNonLinearAdLoad=function(){this.adUi.onNonLinearAdLoad()};Controller.prototype.onNonLinearAdStart=function(){this.adUi.onNonLinearAdLoad();this.playerWrapper.onAdStart()};Controller.prototype.getPlayerWidth=function(){return this.playerWrapper.getPlayerWidth()};Controller.prototype.getPlayerHeight=function(){return this.playerWrapper.getPlayerHeight()};Controller.prototype.onAdsReady=function(){this.playerWrapper.onAdsReady()};Controller.prototype.onPlayerResize=function(width,height){this.sdkImpl.onPlayerResize(width,height)};Controller.prototype.onContentComplete=function(){this.sdkImpl.onContentComplete()};Controller.prototype.onNoPostroll=function(){this.playerWrapper.onNoPostroll()};Controller.prototype.onContentAndAdsCompleted=function(){for(var index in this.contentAndAdsEndedListeners){if(typeof this.contentAndAdsEndedListeners[index]==='function'){this.contentAndAdsEndedListeners[index]()}}};Controller.prototype.onPlayerDisposed=function(){this.contentAndAdsEndedListeners=[];this.sdkImpl.onPlayerDisposed()};Controller.prototype.onPlayerReadyForPreroll=function(){this.sdkImpl.onPlayerReadyForPreroll()};Controller.prototype.onPlayerEnterFullscreen=function(){this.adUi.onPlayerEnterFullscreen();this.sdkImpl.onPlayerEnterFullscreen()};Controller.prototype.onPlayerExitFullscreen=function(){this.adUi.onPlayerExitFullscreen();this.sdkImpl.onPlayerExitFullscreen()};Controller.prototype.onPlayerVolumeChanged=function(volume){this.adUi.onPlayerVolumeChanged(volume);this.sdkImpl.onPlayerVolumeChanged(volume)};Controller.prototype.setContentWithAdTag=function(contentSrc,adTag,playOnLoad){this.reset();this.settings.adTagUrl=adTag?adTag:this.settings.adTagUrl;this.playerWrapper.changeSource(contentSrc,playOnLoad)};Controller.prototype.setContentWithAdsResponse=function(contentSrc,adsResponse,playOnLoad){this.reset();this.settings.adsResponse=adsResponse?adsResponse:this.settings.adsResponse;this.playerWrapper.changeSource(contentSrc,playOnLoad)};Controller.prototype.reset=function(){this.sdkImpl.reset();this.playerWrapper.reset()};Controller.prototype.addContentEndedListener=function(listener){this.playerWrapper.addContentEndedListener(listener)};Controller.prototype.addContentAndAdsEndedListener=function(listener){this.contentAndAdsEndedListeners.push(listener)};Controller.prototype.setAdBreakReadyListener=function(listener){this.sdkImpl.setAdBreakReadyListener(listener)};Controller.prototype.setShowCountdown=function(showCountdownIn){this.adUi.setShowCountdown(showCountdownIn);this.showCountdown=showCountdownIn;this.countdownDiv.style.display=this.showCountdown?'block':'none'};Controller.prototype.initializeAdDisplayContainer=function(){this.sdkImpl.initializeAdDisplayContainer()};Controller.prototype.playAdBreak=function(){this.sdkImpl.playAdBreak()};Controller.prototype.addEventListener=function(event,callback){this.sdkImpl.addEventListener(event,callback)};Controller.prototype.getAdsManager=function(){return this.sdkImpl.getAdsManager()};Controller.prototype.changeAdTag=function(adTag){this.reset();this.settings.adTagUrl=adTag};Controller.prototype.pauseAd=function(){this.adUi.onAdsPaused();this.sdkImpl.pauseAds()};Controller.prototype.resumeAd=function(){this.adUi.onAdsPlaying();this.sdkImpl.resumeAds()};Controller.prototype.adsWillAutoplay=function(){if(this.settings.adsWillAutoplay!==undefined){return this.settings.adsWillAutoplay}else if(this.settings.adWillAutoplay!==undefined){return this.settings.adWillAutoplay}else{return!!this.playerWrapper.getPlayerOptions().autoplay}};Controller.prototype.adsWillPlayMuted=function(){if(this.settings.adsWillPlayMuted!==un
42defined){return this.settings.adsWillPlayMuted}else if(this.settings.adWillPlayMuted!==undefined){return this.settings.adWillPlayMuted}else if(this.playerWrapper.getPlayerOptions().muted!==undefined){return this.playerWrapper.getPlayerOptions().muted}else{return this.playerWrapper.getVolume()==0}};Controller.prototype.extend=function(obj){var arg=void 0;var index=void 0;var key=void 0;for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]} 43for(index=0;index<args.length;index++){arg=args[index];for(key in arg){if(arg.hasOwnProperty(key)){obj[key]=arg[key]}}} 44return obj};var ImaPlugin=function ImaPlugin(player,options){this.controller=new Controller(player,options);this.addContentAndAdsEndedListener=function(listener){this.controller.addContentAndAdsEndedListener(listener)}.bind(this);this.addContentEndedListener=function(listener){this.controller.addContentEndedListener(listener)}.bind(this);this.addEventListener=function(event,callback){this.controller.addEventListener(event,callback)}.bind(this);this.changeAdTag=function(adTag){this.controller.changeAdTag(adTag)}.bind(this);this.getAdsManager=function(){return this.controller.getAdsManager()}.bind(this);this.initializeAdDisplayContainer=function(){this.controller.initializeAdDisplayContainer()}.bind(this);this.pauseAd=function(){this.controller.pauseAd()}.bind(this);this.playAdBreak=function(){this.controller.playAdBreak()}.bind(this);this.requestAds=function(){this.controller.requestAds()}.bind(this);this.resumeAd=function(){this.controller.resumeAd()}.bind(this);this.setAdBreakReadyListener=function(listener){this.controller.setAdBreakReadyListener(listener)}.bind(this);this.setContentWithAdTag=function(contentSrc,adTag,playOnLoad){this.controller.setContentWithAdTag(contentSrc,adTag,playOnLoad)}.bind(this);this.setContentWithAdsResponse=function(contentSrc,adsResponse,playOnLoad){this.controller.setContentWithAdsResponse(contentSrc,adsResponse,playOnLoad)}.bind(this);this.setShowCountdown=function(showCountdownIn){this.controller.setShowCountdown(showCountdownIn)}.bind(this)};var init=function init(options){this.ima=new ImaPlugin(this,options)};var registerPlugin=videojs.registerPlugin||videojs.plugin;registerPlugin('ima',init)})))
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.