Skip to content

Commit

Permalink
fix(ads): Added missing call to initialize() method after an error oc…
Browse files Browse the repository at this point in the history
…curred and having multiple Ads to play; added new event listener to resize Ads when media has been loaded
  • Loading branch information
rafa8626 committed Nov 28, 2018
1 parent ac781f0 commit cdef255
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/js/media/ads.ts
Expand Up @@ -4,7 +4,6 @@ import Media from '../media';
import { IS_ANDROID, IS_IOS, IS_IPHONE } from '../utils/constants';
import { addEvent } from '../utils/events';
import { isVideo, loadScript } from '../utils/general';
// import { isAutoplaySupported } from '../utils/media';

declare const google: any;

Expand Down Expand Up @@ -330,6 +329,7 @@ class Ads {
);
// Create responsive ad
window.addEventListener('resize', this.resizeAds.bind(this));
this.element.addEventListener('loadedmetadata', this.resizeAds.bind(this));

// Request Ads automatically if `autoplay` was set
if (this.autoStart === true || this.autoStartMuted === true || force === true) {
Expand Down Expand Up @@ -410,6 +410,9 @@ class Ads {
this.adsManager.destroy();
}

if (IS_IOS || IS_ANDROID) {
this.element.removeEventListener('loadedmetadata', this._contentLoadedAction.bind(this));
}
this.element.removeEventListener('ended', this._contentEndedListener.bind(this));
window.removeEventListener('resize', this.resizeAds.bind(this));
this.adsContainer.remove();
Expand Down Expand Up @@ -657,6 +660,7 @@ class Ads {
this.currentAdsIndex++;
this.playTriggered = true;
this.adsStarted = true;
this.adsDone = false;
this.destroy();
this.load(true);
} else {
Expand Down Expand Up @@ -727,6 +731,18 @@ class Ads {

if (this.autoStart === true || this.playTriggered === true) {
this.playTriggered = false;
if (!this.adsDone) {
this.adsDone = true;
this.adDisplayContainer.initialize();

if (IS_IOS || IS_ANDROID) {
this.preloadContent = this._contentLoadedAction;
this.element.addEventListener('loadedmetadata', this._contentLoadedAction.bind(this));
} else {
this._contentLoadedAction();
}
return;
}
manager.init(
this.element.offsetWidth,
this.element.offsetHeight,
Expand Down

0 comments on commit cdef255

Please sign in to comment.