Skip to content

Commit cb9f3fd

Browse files
authored
fix: remove async IIFE and register listeners before VAST fetch (VAST-84) (#84)
- Remove const self = this pattern that was a workaround for Turbopack (VAST-72) - Replace async IIFE with .then() to preserve lexical this - Call addEventsListeners() before handleVAST() to prevent race condition where readyforpreroll could fire before listeners were attached
1 parent fd39d6b commit cb9f3fd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/index.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,18 @@ class Vast extends Plugin {
7171
console.error(e);
7272
}
7373

74-
const self = this;
7574
if (options.vmapUrl) {
76-
self.handleVMAP(options.vmapUrl);
75+
this.handleVMAP(options.vmapUrl);
7776
} else {
78-
self.disablePostroll();
79-
(async () => {
80-
await self.handleVAST(options.vastUrl, () => {
81-
self.disablePreroll();
82-
});
83-
if (self.adsArray.length > 0) {
84-
self.addEventsListeners();
85-
// has to be done outside of handleVAST because not done at the same moment for VMAP case
86-
self.player.trigger('adsready');
77+
this.disablePostroll();
78+
this.addEventsListeners();
79+
this.handleVAST(options.vastUrl, () => {
80+
this.disablePreroll();
81+
}).then(() => {
82+
if (this.adsArray.length > 0) {
83+
this.player.trigger('adsready');
8784
}
88-
})();
85+
});
8986
}
9087
}
9188

0 commit comments

Comments
 (0)