Skip to content

Commit

Permalink
Pull yospace ad data when the source was loaded, and delay SourceLoad…
Browse files Browse the repository at this point in the history
…ed event until this was successfully done
  • Loading branch information
dweinber committed Dec 4, 2024
1 parent c3918a6 commit b2cf81f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/ts/InternalBitmovinYospacePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -386,6 +390,29 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI {
return this.player.play(issuer);
}

private pullYospaceAdDataForLive(): Promise<void> {
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<void>((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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/ts/YospaceListenerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -95,7 +96,9 @@ export class YospaceAdListenerAdapter {
}

onAnalyticUpdate() {
// No op
this.emitEvent({
type: BYSListenerEvent.ANALYTIC_UPDATED,
} as BYSListenerEventBase);
}

onTrackingEvent(type: BYSTrackingEventType) {
Expand Down

0 comments on commit b2cf81f

Please sign in to comment.