Skip to content

Commit

Permalink
fix: 🐜 do not subscribe to AdLoaded evt twice
Browse files Browse the repository at this point in the history
some creatives only allow one handler per event
  • Loading branch information
carpasse committed Jan 15, 2019
1 parent b2ee8ce commit 0e4346e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/adUnit/VpaidAdUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const {
closeLinear
} = linearEvents;

// NOTE some ads only allow one handler per event and we need to subscribe to the adLoaded to know the creative is loaded.
const VPAID_EVENTS = EVENTS.filter((event) => event !== adLoaded);

// eslint-disable-next-line id-match
const _private = Symbol('_private');

Expand Down Expand Up @@ -309,7 +312,7 @@ class VpaidAdUnit extends VideoAdUnit {
this.creativeAd = await this[_private].loadCreativePromise;
const adLoadedPromise = waitFor(this.creativeAd, adLoaded);

for (const creativeEvt of EVENTS) {
for (const creativeEvt of VPAID_EVENTS) {
this.creativeAd.subscribe(this[_private].handleVpaidEvt.bind(this, creativeEvt), creativeEvt);
}

Expand Down
2 changes: 1 addition & 1 deletion src/adUnit/__tests__/VpaidAdUnit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ describe('VpaidAdUnit', () => {
adUnit = new VpaidAdUnit(vpaidChain, videoAdContainer);
});

for (const vpaidEvt of EVENTS) {
for (const vpaidEvt of EVENTS.filter((evt) => evt !== adLoaded)) {
test(`${vpaidEvt} must be emitted by the ad unit`, async () => {
const callback = jest.fn();

Expand Down

0 comments on commit 0e4346e

Please sign in to comment.