From 8a07c507ff6870def2d50ad96cc23e21113c896a Mon Sep 17 00:00:00 2001 From: Interactive Media Ads Developer Relations Date: Tue, 29 Oct 2024 10:40:33 -0700 Subject: [PATCH] No public description PiperOrigin-RevId: 691076942 --- advanced/ads.js | 15 ++++++++------- advanced/video_player.js | 2 +- playlist/ads.js | 15 ++++++++------- playlist/video_player.js | 2 +- vpaid/linear/VpaidVideoAd.js | 21 +++++++++++---------- vpaid/nonlinear/VpaidNonLinear.js | 2 +- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/advanced/ads.js b/advanced/ads.js index 5a3b577..995e4d7 100644 --- a/advanced/ads.js +++ b/advanced/ads.js @@ -6,7 +6,7 @@ /** * Shows how to use the IMA SDK to request and display ads. */ -var Ads = function(application, videoPlayer) { +const Ads = function(application, videoPlayer) { this.application_ = application; this.videoPlayer_ = videoPlayer; this.customClickDiv_ = document.getElementById('customClick'); @@ -37,7 +37,7 @@ Ads.prototype.initialUserAction = function() { }; Ads.prototype.requestAds = function(adTagUrl) { - var adsRequest = new google.ima.AdsRequest(); + const adsRequest = new google.ima.AdsRequest(); adsRequest.adTagUrl = adTagUrl; adsRequest.linearAdSlotWidth = this.videoPlayer_.width; adsRequest.linearAdSlotHeight = this.videoPlayer_.height; @@ -71,7 +71,7 @@ Ads.prototype.contentEnded = function() { Ads.prototype.onAdsManagerLoaded_ = function(adsManagerLoadedEvent) { this.application_.log('Ads loaded.'); - var adsRenderingSettings = new google.ima.AdsRenderingSettings(); + const adsRenderingSettings = new google.ima.AdsRenderingSettings(); adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; this.adsManager_ = adsManagerLoadedEvent.getAdsManager( this.videoPlayer_.contentPlayer, adsRenderingSettings); @@ -92,18 +92,19 @@ Ads.prototype.startAdsManager_ = function(adsManager) { // Handle errors. adsManager.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, this.onAdError_, false, this); - var events = [ + const events = [ google.ima.AdEvent.Type.ALL_ADS_COMPLETED, google.ima.AdEvent.Type.CLICK, google.ima.AdEvent.Type.COMPLETE, google.ima.AdEvent.Type.FIRST_QUARTILE, google.ima.AdEvent.Type.LOADED, google.ima.AdEvent.Type.MIDPOINT, google.ima.AdEvent.Type.PAUSED, google.ima.AdEvent.Type.STARTED, google.ima.AdEvent.Type.THIRD_QUARTILE ]; - for (var index in events) { + for (const index in events) { adsManager.addEventListener(events[index], this.onAdEvent_, false, this); } - var initWidth, initHeight; + let initWidth; + let initHeight; if (this.application_.fullscreen) { initWidth = this.application_.fullscreenWidth; initHeight = this.application_.fullscreenHeight; @@ -136,7 +137,7 @@ Ads.prototype.onAdEvent_ = function(adEvent) { if (adEvent.type == google.ima.AdEvent.Type.CLICK) { this.application_.adClicked(); } else if (adEvent.type == google.ima.AdEvent.Type.LOADED) { - var ad = adEvent.getAd(); + const ad = adEvent.getAd(); if (!ad.isLinear()) { this.onContentResumeRequested_(); } diff --git a/advanced/video_player.js b/advanced/video_player.js index 5a897d5..b2f03fa 100644 --- a/advanced/video_player.js +++ b/advanced/video_player.js @@ -6,7 +6,7 @@ /** * Handles video player functionality. */ -var VideoPlayer = function() { +const VideoPlayer = function() { this.contentPlayer = document.getElementById('content'); this.adContainer = document.getElementById('adcontainer'); this.videoPlayerContainer_ = document.getElementById('videoplayer'); diff --git a/playlist/ads.js b/playlist/ads.js index 3908452..c5ad491 100644 --- a/playlist/ads.js +++ b/playlist/ads.js @@ -6,7 +6,7 @@ /** * Shows how to use the IMA SDK to request and display ads. */ -var Ads = function(application, videoPlayer) { +const Ads = function(application, videoPlayer) { this.application_ = application; this.videoPlayer_ = videoPlayer; this.customClickDiv_ = document.getElementById('customClick'); @@ -37,7 +37,7 @@ Ads.prototype.initialUserAction = function() { Ads.prototype.requestAds = function(adTagUrl) { this.contentCompleteCalled = false; this.allAdsCompleted = false; - var adsRequest = new google.ima.AdsRequest(); + const adsRequest = new google.ima.AdsRequest(); adsRequest.adTagUrl = adTagUrl; adsRequest.linearAdSlotWidth = this.videoPlayer_.width; adsRequest.linearAdSlotHeight = this.videoPlayer_.height; @@ -90,7 +90,7 @@ Ads.prototype.destroyAdsManager = function() { Ads.prototype.onAdsManagerLoaded_ = function(adsManagerLoadedEvent) { this.application_.log('Ads loaded.'); - var adsRenderingSettings = new google.ima.AdsRenderingSettings(); + const adsRenderingSettings = new google.ima.AdsRenderingSettings(); adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; this.adsManager_ = adsManagerLoadedEvent.getAdsManager( this.videoPlayer_.contentPlayer, adsRenderingSettings); @@ -114,18 +114,19 @@ Ads.prototype.startAdsManager_ = function(adsManager) { adsManager.addEventListener( google.ima.AdEvent.Type.ALL_ADS_COMPLETED, this.onAllAdsCompleted_, false, this); - var events = [ + const events = [ google.ima.AdEvent.Type.ALL_ADS_COMPLETED, google.ima.AdEvent.Type.CLICK, google.ima.AdEvent.Type.COMPLETE, google.ima.AdEvent.Type.FIRST_QUARTILE, google.ima.AdEvent.Type.LOADED, google.ima.AdEvent.Type.MIDPOINT, google.ima.AdEvent.Type.PAUSED, google.ima.AdEvent.Type.STARTED, google.ima.AdEvent.Type.THIRD_QUARTILE ]; - for (var index in events) { + for (const index in events) { adsManager.addEventListener(events[index], this.onAdEvent_, false, this); } - var initWidth, initHeight; + let initWidth; + let initHeight; if (this.application_.fullscreen) { initWidth = this.application_.fullscreenWidth; initHeight = this.application_.fullscreenHeight; @@ -160,7 +161,7 @@ Ads.prototype.onAdEvent_ = function(adEvent) { if (adEvent.type == google.ima.AdEvent.Type.CLICK) { this.application_.adClicked(); } else if (adEvent.type == google.ima.AdEvent.Type.LOADED) { - var ad = adEvent.getAd(); + const ad = adEvent.getAd(); if (!ad.isLinear()) { this.onContentResumeRequested_(); } diff --git a/playlist/video_player.js b/playlist/video_player.js index b61ff10..c68744a 100644 --- a/playlist/video_player.js +++ b/playlist/video_player.js @@ -6,7 +6,7 @@ /** * Handles video player functionality. */ -var VideoPlayer = function() { +const VideoPlayer = function() { this.contentPlayer = document.getElementById('content'); this.adContainer = document.getElementById('adcontainer'); this.videoPlayerContainer_ = document.getElementById('videoplayer'); diff --git a/vpaid/linear/VpaidVideoAd.js b/vpaid/linear/VpaidVideoAd.js index 6ea9561..de6987c 100644 --- a/vpaid/linear/VpaidVideoAd.js +++ b/vpaid/linear/VpaidVideoAd.js @@ -6,7 +6,7 @@ /** * @constructor */ -var VpaidVideoPlayer = function() { +const VpaidVideoPlayer = function() { /** * The slot is the div element on the main page that the ad is supposed to * occupy. @@ -154,10 +154,11 @@ VpaidVideoPlayer.prototype.timeUpdateHandler_ = function() { if (this.nextQuartileIndex_ >= this.quartileEvents_.length) { return; } - var percentPlayed = + const percentPlayed = this.videoSlot_.currentTime * 100.0 / this.videoSlot_.duration; if (percentPlayed >= this.quartileEvents_[this.nextQuartileIndex_].value) { - var lastQuartileEvent = this.quartileEvents_[this.nextQuartileIndex_].event; + const lastQuartileEvent = + this.quartileEvents_[this.nextQuartileIndex_].event; this.eventsCallbacks_[lastQuartileEvent](); this.nextQuartileIndex_ += 1; } @@ -178,9 +179,9 @@ VpaidVideoPlayer.prototype.updateVideoSlot_ = function() { this.slot_.appendChild(this.videoSlot_); } this.updateVideoPlayerSize_(); - var foundSource = false; - var videos = this.parameters_.videos || []; - for (var i = 0; i < videos.length; i++) { + let foundSource = false; + const videos = this.parameters_.videos || []; + for (let i = 0; i < videos.length; i++) { // Choose the first video with a supported mimetype. if (this.videoSlot_.canPlayType(videos[i].mimetype) != '') { this.videoSlot_.setAttribute('src', videos[i].url); @@ -220,7 +221,7 @@ VpaidVideoPlayer.prototype.stopAd = function() { this.log('Stopping ad'); // Calling AdStopped immediately terminates the ad. Setting a timeout allows // events to go through. - var callback = this.callEvent_.bind(this); + const callback = this.callEvent_.bind(this); setTimeout(callback, 75, ['AdStopped']); }; @@ -279,7 +280,7 @@ VpaidVideoPlayer.prototype.collapseAd = function() { */ VpaidVideoPlayer.prototype.skipAd = function() { this.log('skipAd'); - var skippableState = this.attributes_['skippableState']; + const skippableState = this.attributes_['skippableState']; if (skippableState) { this.callEvent_('AdSkipped'); } @@ -294,7 +295,7 @@ VpaidVideoPlayer.prototype.skipAd = function() { VpaidVideoPlayer.prototype.subscribe = function( aCallback, eventName, aContext) { this.log('Subscribe ' + eventName); - var callBack = aCallback.bind(aContext); + const callBack = aCallback.bind(aContext); this.eventsCallbacks_[eventName] = callBack; }; @@ -423,6 +424,6 @@ VpaidVideoPlayer.prototype.callEvent_ = function(eventType) { * Main function called by wrapper to get the VPAID ad. * @return {Object} The VPAID compliant ad. */ -var getVPAIDAd = function() { +const getVPAIDAd = function() { return new VpaidVideoPlayer(); }; diff --git a/vpaid/nonlinear/VpaidNonLinear.js b/vpaid/nonlinear/VpaidNonLinear.js index 19576ca..eb44825 100644 --- a/vpaid/nonlinear/VpaidNonLinear.js +++ b/vpaid/nonlinear/VpaidNonLinear.js @@ -467,6 +467,6 @@ const VpaidNonLinear = class { * Main function called by wrapper to get the VPAID ad. * @return {Object} The VPAID compliant ad. */ -var getVPAIDAd = function() { +const getVPAIDAd = function() { return new VpaidNonLinear(); };