Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691076942
  • Loading branch information
Interactive Media Ads Developer Relations authored and IMA Developer Relations committed Oct 29, 2024
1 parent 45830a7 commit 8a07c50
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
15 changes: 8 additions & 7 deletions advanced/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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_();
}
Expand Down
2 changes: 1 addition & 1 deletion advanced/video_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
15 changes: 8 additions & 7 deletions playlist/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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_();
}
Expand Down
2 changes: 1 addition & 1 deletion playlist/video_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
21 changes: 11 additions & 10 deletions vpaid/linear/VpaidVideoAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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']);
};

Expand Down Expand Up @@ -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');
}
Expand All @@ -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;
};

Expand Down Expand Up @@ -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();
};
2 changes: 1 addition & 1 deletion vpaid/nonlinear/VpaidNonLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit 8a07c50

Please sign in to comment.