Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move setupIMA after _adsLoader declaration #8

Merged
merged 1 commit into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ima-wrapper.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ima-wrapper.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Video Ad Manager IMA Wrapper</title>
<title>IMA Wrapper</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/global.css">
Expand Down Expand Up @@ -34,7 +34,7 @@
</style>
</head>
<body>
<h1>Video Ad Manager IMA Wrapper</h1>
<h1>IMA Wrapper</h1>
<p>...</p>

<div class="container">
Expand All @@ -51,7 +51,7 @@ <h1>Video Ad Manager IMA Wrapper</h1>
<br/>
<br/>
<h3>VAST Tag URL/XML Inspector (VAST, VPAID):</h3>
<textarea id="vast-url-input">https://v.adserve.tv/pg/vast-vpaid.xml</textarea>
<textarea id="vast-url-input">https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=</textarea>
<button id="test-ad-button" class="primary-button">Test Ad</button>
<button id="pause-ad-button" class="ad-button">Pause Ad</button>
<!--<button id="resume-ad-button" class="ad-button">Resume Ad</button>-->
Expand Down
4 changes: 2 additions & 2 deletions public/js/ima-wrapper.js

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
var testAdButton = document.getElementById('test-ad-button');

var pauseAdButton = document.getElementById('pause-ad-button');
// var resumeAdButton = document.getElementById('resume-ad-button');
var stopAdButton = document.getElementById('stop-ad-button');
var skipAdButton = document.getElementById('skip-ad-button');
var resizeAdButton = document.getElementById('resize-ad-button');
Expand Down Expand Up @@ -235,15 +234,6 @@
*/


/*
vastUrl = 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=';
videoElement.muted = true;
setTimeout(function() {
adsManager.requestAds(vastUrl, { muted: true });
}, 1000);

*/



/*
Expand Down Expand Up @@ -296,12 +286,12 @@
videoElement.play();
}

adsManager.requestAds(giveVastUrl, { muted: false });
adsManager.requestAds(giveVastUrl, { muted: true });
}

testAdButton.addEventListener('click', function() {
console.log('test button click');
//videoElement.muted = true;
videoElement.muted = true;
requestAd();
}, false);

Expand Down
55 changes: 26 additions & 29 deletions src/ima-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ const IMAWrapper = function(adContainer, videoElement) {
// These events are all callbacks.
this._eventCallbacks = {};

// IMA global variables
this._adsLoader = null;
this._adDisplayContainer = null;
this._adDisplayContainerInitialized = false;
this._adsManager = null;
this._currentAd = null;
this._adPodInfo = null;

// Attributes
this._attributes = {
version: '!!#Version#!!'
};

// Options
this._options = {
autoplay: true,
muted: true,
secure: false, // default false, google.ima.ImaSdkSettings.VpaidMode.INSECURE
vastLoadTimeout: 23000,
loadVideoTimeout: 8000, // default value is 8000 ms = 8 sec, timeout to load video of the ad
};

// IMA SDK ima3.js
this.IMA_SDK_SRC = '//imasdk.googleapis.com/js/sdkloader/ima3.js';
// Check that Client Side IMA SDK has been included
Expand All @@ -64,28 +86,6 @@ const IMAWrapper = function(adContainer, videoElement) {
this.setupIMA();
}

// IMA global variables
this._adsLoader = null;
this._adDisplayContainer = null;
this._adDisplayContainerInitialized = false;
this._adsManager = null;
this._currentAd = null;
this._adPodInfo = null;

// Attributes
this._attributes = {
volume: 0
};

// Options
this._options = {
autoplay: true,
muted: true,
secure: false, // default false, google.ima.ImaSdkSettings.VpaidMode.INSECURE
vastLoadTimeout: 23000,
loadVideoTimeout: 8000, // default value is 8000 ms = 8 sec, timeout to load video of the ad
};

};
IMAWrapper.prototype.setupIMA = function() {
console.log('setup IMA');
Expand All @@ -94,13 +94,6 @@ IMAWrapper.prototype.setupIMA = function() {
this._adDisplayContainer = new google.ima.AdDisplayContainer(this._adContainer, this._videoElement);
this._adsLoader = new google.ima.AdsLoader(this._adDisplayContainer);

console.log('ia adsLoader', this._adsLoader)
/*
this._adsLoader.getSettings().setVpaidMode(this._options.useSecureIframe ?
google.ima.ImaSdkSettings.VpaidMode.ENABLED :
google.ima.ImaSdkSettings.VpaidMode.INSECURE
);*/

// Listen and respond to ads loaded and error events.
this._adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, this.onIMAAdsManagerLoaded.bind(this), false);
this._adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, this.onIMAAdsManagerAdError.bind(this), false);
Expand Down Expand Up @@ -370,4 +363,8 @@ IMAWrapper.prototype.removeEventListener = function(eventName) {
this._eventCallbacks[eventName] = null;
};

IMAWrapper.prototype.getVersion = function() {
return this._attributes.version;
};

export default IMAWrapper;