diff --git a/src/ts/InternalBitmovinYospacePlayer.ts b/src/ts/InternalBitmovinYospacePlayer.ts index 371e87d..7bd2b62 100644 --- a/src/ts/InternalBitmovinYospacePlayer.ts +++ b/src/ts/InternalBitmovinYospacePlayer.ts @@ -286,7 +286,11 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI { } Logger.log('Loading Source: ' + stringify(clonedSource)); - this.player.load(clonedSource, forceTechnology, disableSeeking).then(resolve).catch(reject); + this.player + .load(clonedSource, forceTechnology, disableSeeking) + .then(() => this.pullYospaceAdDataForLive()) + .then(() => resolve()) + .catch(reject); } else { session.shutdown(); this.session = null; @@ -386,6 +390,29 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI { return this.player.play(issuer); } + private pullYospaceAdDataForLive(): Promise { + if ( + (this.yospaceSourceConfig.assetType !== YospaceAssetType.DVRLIVE && this.yospaceSourceConfig.assetType !== YospaceAssetType.LINEAR) || + this.startSent + ) { + // Manually triggering the Yospace ad data update is only needed for Live and DVRLive sessions, and only the first time the stream is started. + return Promise.resolve(); + } + + const adBreakUpdatePromise = new Promise((resolve, reject) => { + const onAnalyticUpdate = () => { + this.yospaceListenerAdapter.removeListener(BYSListenerEvent.ANALYTIC_UPDATED, onAnalyticUpdate); + resolve(); + }; + + this.yospaceListenerAdapter.addListener(BYSListenerEvent.ANALYTIC_UPDATED, onAnalyticUpdate); + }); + + this.session.onPlayerEvent(YsPlayerEvent.PLAYBACK_READY, 0); + + return adBreakUpdatePromise; + } + pause(issuer?: string): void { this.playerPolicy.canPause() ? this.player.pause(issuer) : this.handleYospacePolicyEvent(YospacePolicyErrorCode.PAUSE_NOT_ALLOWED); } diff --git a/src/ts/YospaceListenerAdapter.ts b/src/ts/YospaceListenerAdapter.ts index f00c4a0..9986fb2 100644 --- a/src/ts/YospaceListenerAdapter.ts +++ b/src/ts/YospaceListenerAdapter.ts @@ -10,6 +10,7 @@ export enum BYSListenerEvent { ADVERT_END = 'advert_end', AD_BREAK_END = 'ad_break_end', ANALYTICS_FIRED = 'analytics_fired', + ANALYTIC_UPDATED = 'analytics_updated', } export type BYSTrackingEventType = @@ -95,7 +96,9 @@ export class YospaceAdListenerAdapter { } onAnalyticUpdate() { - // No op + this.emitEvent({ + type: BYSListenerEvent.ANALYTIC_UPDATED, + } as BYSListenerEventBase); } onTrackingEvent(type: BYSTrackingEventType) {