Skip to content

Commit

Permalink
Merge pull request #14 from basil79/ima3-included
Browse files Browse the repository at this point in the history
fixed onAdSkipped, abort and call onAllAdsCompleted
  • Loading branch information
basil79 authored Jan 25, 2023
2 parents 8ee7ec7 + 0a7bc3a commit c67527e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
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.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"url": "https://github.com/basil79/ima-wrapper/issues"
},
"homepage": "https://github.com/basil79/ima-wrapper#readme",
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/preset-env": "^7.16.5",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h3>Ad Events:</h3>
<br/>

<!-- IMA SDK -->
<!--<script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>-->
<!-- <script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script> -->

<script src="js/ima-wrapper.js?v=2"></script>
<script src="js/index.js?v=2"></script>
Expand Down
4 changes: 2 additions & 2 deletions public/js/ima-wrapper.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
// Example
var videoElement = document.getElementById('video-element');
var adContainer = document.getElementById('ad-container');
var adsManager = new adserve.tv.IMAWrapper(adContainer, videoElement);
var adsManager = new adserve.tv.IMAWrapper(adContainer, videoElement, function(error) {
if(error) {
console.log(error);
return;
}
console.log('IMAWrapper is ready');
});

console.log('IMAWrapper version is', adsManager.getVersion());

Expand Down
19 changes: 15 additions & 4 deletions src/ima-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ IMAWrapper.prototype.skip = function() {
this._adsManager.skip();
}
// Force skip
this.onIMAAdSkipped();
//this.onIMAAdSkipped();
this.onAdSkipped();
}
};
IMAWrapper.prototype.resize = function(width, height, viewMode) {
Expand Down Expand Up @@ -212,6 +213,11 @@ IMAWrapper.prototype.abort = function() {
this._adsManager && (this._adsManager.destroy(), this._adsManager = null);
this.doContentComplete();
};
IMAWrapper.prototype._abort = function() {
this.abort();
// Dispatch AllAdsCompleted
this.onAllAdsCompleted();
}

// IMA Events
IMAWrapper.prototype.onIMAAdsManagerLoaded = function(adsManagerLoadedEvent) {
Expand Down Expand Up @@ -243,7 +249,7 @@ IMAWrapper.prototype.onIMAAdsManagerLoaded = function(adsManagerLoadedEvent) {
this._adsManager.addEventListener(google.ima.AdEvent.Type.PAUSED, this.onAdPaused.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.RESUMED, this.onAdPlaying.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED, this.onAdSkippableStateChange.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.SKIPPED, this.onIMAAdSkipped.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.SKIPPED, this.onAdSkipped.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.STARTED, this.onAdVideoStart.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.THIRD_QUARTILE, this.onAdVideoThirdQuartile.bind(this));
this._adsManager.addEventListener(google.ima.AdEvent.Type.USER_CLOSE, this.onAdUserClose.bind(this));
Expand All @@ -253,7 +259,6 @@ IMAWrapper.prototype.onIMAAdsManagerLoaded = function(adsManagerLoadedEvent) {
this.onAdsManagerLoaded();
};
IMAWrapper.prototype.onIMAAdsManagerAdError = function(adsManagerAdErrorEvent) {
this.abort();
this.onAdError(adsManagerAdErrorEvent.getError()); //.getError().getErrorCode() + ' ' + adsManagerAdErrorEvent.getError().getMessage());
};
IMAWrapper.prototype.onIMAAdClickThru = function(adEvent) {
Expand All @@ -266,14 +271,15 @@ IMAWrapper.prototype.onIMAAdLoaded = function(adEvent) {
this._currentAd = adEvent.getAd();
this.onAdLoaded(this._currentAd);
};
/*
IMAWrapper.prototype.onIMAAdSkipped = function() {
// Destroy ad
this.abort();
this.onAdSkipped();
this.onAdStopped();
};
*/
IMAWrapper.prototype.onIMAAdError = function(adErrorEvent) {
this.abort();
console.log('ima error', adErrorEvent);
this.onAdError(adErrorEvent.getError()); //.getError().getErrorCode() + ' ' + adErrorEvent.getError().getMessage() + ' ' + adErrorEvent.getError().getInnerError())
};
Expand Down Expand Up @@ -334,9 +340,13 @@ IMAWrapper.prototype.onAdPlaying = function() {
};
IMAWrapper.prototype.onAdSkipped = function() {
this._callEvent(this.EVENTS.AdSkipped);
// abort the ad, unsubscribe and reset to a default state
this._abort();
};
IMAWrapper.prototype.onAdStopped = function() {
this._callEvent(this.EVENTS.AdStopped);
// abort the ad, unsubscribe and reset to a default state
this._abort();
};
IMAWrapper.prototype.onAdClickThru = function(url, id, playerHandles) {
if (this.EVENTS.AdClickThru in this._eventCallbacks) {
Expand All @@ -354,6 +364,7 @@ IMAWrapper.prototype.onAllAdsCompleted = function() {
this._callEvent(this.EVENTS.AllAdsCompleted);
};
IMAWrapper.prototype.onAdError = function(message) {
this.abort();
if (this.EVENTS.AdError in this._eventCallbacks) {
this._eventCallbacks[this.EVENTS.AdError](message);
}
Expand Down

0 comments on commit c67527e

Please sign in to comment.