@dolby-optiview/ads-sdk-core 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OptiViewAds.d.ts +5 -4
- package/dist/OptiViewAds.js +1 -1
- package/dist/external-playback/index.d.ts +4 -0
- package/dist/external-playback/index.js +1 -0
- package/dist/external-playback/observeExternalPlayback.d.ts +19 -0
- package/dist/external-playback/observeExternalPlayback.js +1 -0
- package/dist/external-playback/reconnectHold.d.ts +19 -0
- package/dist/external-playback/reconnectHold.js +1 -0
- package/dist/generated/diagnosticCodes.d.ts +45 -5
- package/dist/generated/diagnosticCodes.js +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/interfaces/AdSourceQueue.d.ts +19 -0
- package/dist/interfaces/AdSourceQueue.js +1 -0
- package/dist/interfaces/PlayerAdapter.d.ts +31 -1
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +1 -1
- package/dist/services/AdBreakSequencer.d.ts +33 -4
- package/dist/services/AdBreakSequencer.js +1 -1
- package/dist/services/AdPlayerController.d.ts +8 -61
- package/dist/services/AdPlayerController.js +1 -1
- package/dist/services/BreakChain.d.ts +43 -0
- package/dist/services/BreakChain.js +1 -0
- package/dist/services/BreakChainRecorder.d.ts +63 -0
- package/dist/services/BreakChainRecorder.js +1 -0
- package/dist/services/BreakPreloadLedger.d.ts +13 -0
- package/dist/services/BreakPreloadLedger.js +1 -0
- package/dist/services/BreakScheduler.d.ts +20 -6
- package/dist/services/BreakScheduler.js +1 -1
- package/dist/services/BreakTransitionTimer.d.ts +27 -2
- package/dist/services/BreakTransitionTimer.js +1 -1
- package/dist/services/CmcdAdReporter.d.ts +1 -0
- package/dist/services/CmcdAdReporter.js +1 -1
- package/dist/services/ExternalPlaybackGate.d.ts +40 -0
- package/dist/services/ExternalPlaybackGate.js +1 -0
- package/dist/services/LiveStartPushbackController.d.ts +5 -10
- package/dist/services/LiveStartPushbackController.js +1 -1
- package/dist/services/ManifestService.d.ts +2 -1
- package/dist/services/ManifestService.js +1 -1
- package/dist/services/ReloadGuard.d.ts +11 -0
- package/dist/services/ReloadGuard.js +1 -0
- package/dist/services/RewindRearm.d.ts +3 -1
- package/dist/services/RewindRearm.js +1 -1
- package/dist/services/SsaiController.js +1 -1
- package/dist/services/adPlayer/AdPlayerCallbacks.d.ts +63 -0
- package/dist/services/adPlayer/AdPlayerCallbacks.js +1 -0
- package/dist/services/adPlayer/AdPlayerEvents.d.ts +2 -0
- package/dist/services/adPlayer/AdPlayerEvents.js +1 -1
- package/dist/services/adPlayer/AdPreloader.d.ts +2 -2
- package/dist/services/adPlayer/AdPreloader.js +1 -1
- package/dist/services/adPlayer/AdStage.d.ts +7 -4
- package/dist/services/adPlayer/AdStage.js +1 -1
- package/dist/services/adPlayer/AssetParameterResolver.d.ts +10 -2
- package/dist/services/adPlayer/AssetParameterResolver.js +1 -1
- package/dist/services/adPlayer/AssetPlayback.d.ts +6 -2
- package/dist/services/adPlayer/AssetPlayback.js +1 -1
- package/dist/services/adPlayer/BreakSequenceDriver.d.ts +9 -3
- package/dist/services/adPlayer/BreakSequenceDriver.js +1 -1
- package/dist/services/adPlayer/GamPodBridge.d.ts +11 -1
- package/dist/services/adPlayer/GamPodBridge.js +1 -1
- package/dist/services/adPlayer/PauseAdPresenter.d.ts +3 -1
- package/dist/services/adPlayer/PauseAdPresenter.js +1 -1
- package/dist/services/adPlayer/PreparedPresentation.js +1 -1
- package/dist/services/adPlayer/PresentationModeTracker.d.ts +1 -1
- package/dist/services/adPlayer/PresentationModeTracker.js +1 -1
- package/dist/services/adPlayer/SuccessorQueue.d.ts +36 -0
- package/dist/services/adPlayer/SuccessorQueue.js +1 -0
- package/dist/services/adPlayer/presentation/DomPresentationHost.d.ts +22 -0
- package/dist/services/adPlayer/presentation/DomPresentationHost.js +1 -0
- package/dist/services/adPlayer/presentation/LayoutTransform.d.ts +28 -0
- package/dist/services/adPlayer/presentation/LayoutTransform.js +1 -0
- package/dist/services/adPlayer/presentation/PresentationLayout.d.ts +19 -0
- package/dist/services/adPlayer/presentation/PresentationLayout.js +1 -0
- package/dist/services/assetParameterMacroTable.js +1 -1
- package/dist/services/assetParameterMacros.d.ts +9 -9
- package/dist/services/assetParameterMacros.js +1 -1
- package/dist/services/channelSwitch.d.ts +2 -2
- package/dist/services/externalPlaybackDiagnostic.d.ts +3 -0
- package/dist/services/externalPlaybackDiagnostic.js +1 -0
- package/dist/services/externalPlaybackGuard.d.ts +24 -0
- package/dist/services/externalPlaybackGuard.js +1 -0
- package/dist/services/parseBreakManifest.d.ts +2 -1
- package/dist/services/parseBreakManifest.js +1 -1
- package/dist/services/resolveChannelEvents.d.ts +17 -0
- package/dist/services/resolveChannelEvents.js +1 -0
- package/dist/services/resolveExternalVendorConfigurations.js +1 -1
- package/dist/services/resolveGamVendorConfiguration.d.ts +6 -1
- package/dist/services/resolveGamVendorConfiguration.js +1 -1
- package/dist/services/ssbStream.d.ts +39 -0
- package/dist/services/ssbStream.js +1 -0
- package/dist/services/ssbSwitchSignals.d.ts +15 -0
- package/dist/services/ssbSwitchSignals.js +1 -0
- package/dist/services/staticAssetUrl.d.ts +28 -0
- package/dist/services/staticAssetUrl.js +1 -0
- package/dist/session/AdBreakStatusTracker.d.ts +18 -0
- package/dist/session/AdBreakStatusTracker.js +1 -1
- package/dist/session/BreakLifecycle.d.ts +6 -0
- package/dist/session/BreakLifecycle.js +1 -1
- package/dist/session/SessionStarter.d.ts +6 -43
- package/dist/session/SessionStarter.js +1 -1
- package/dist/session/SessionStarterDeps.d.ts +39 -0
- package/dist/session/SessionStarterDeps.js +1 -0
- package/dist/session/SessionStarterHelpers.d.ts +36 -0
- package/dist/session/SessionStarterHelpers.js +1 -0
- package/dist/session/SessionState.d.ts +22 -2
- package/dist/session/SessionState.js +1 -1
- package/dist/session/SsbSwitch.d.ts +55 -0
- package/dist/session/SsbSwitch.js +1 -0
- package/dist/session/breakMeasurement.d.ts +16 -0
- package/dist/session/breakMeasurement.js +1 -0
- package/dist/session/contentSnapback.d.ts +13 -0
- package/dist/session/contentSnapback.js +1 -0
- package/dist/session/createExternalPlaybackGate.d.ts +19 -0
- package/dist/session/createExternalPlaybackGate.js +1 -0
- package/dist/session/sessionTick.d.ts +7 -0
- package/dist/session/sessionTick.js +1 -0
- package/dist/types/BreakManifest.d.ts +34 -2
- package/dist/types/Events.d.ts +20 -10
- package/dist/types/OptiViewAdsConfig.d.ts +24 -8
- package/package.json +5 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Asset, Break } from '../../types/BreakManifest';
|
|
2
|
+
/** Creative identity IMA reports for an ad of a GAM pod; absent for other asset kinds. */
|
|
3
|
+
export interface AdCreativeIdentity {
|
|
4
|
+
adId?: string | undefined;
|
|
5
|
+
creativeId?: string | undefined;
|
|
6
|
+
/** 1-based position within the pod (IMA `getAdPodInfo().getAdPosition()` / VAST `sequence`); absent when unreported. */
|
|
7
|
+
podPosition?: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface AdPlayerCallbacks {
|
|
10
|
+
onAdStart: (breakInfo: Break, asset: Asset, index: number, total: number, identity?: AdCreativeIdentity) => void;
|
|
11
|
+
onAdEnd: (breakInfo: Break, asset: Asset, index: number, total: number, identity?: AdCreativeIdentity) => void;
|
|
12
|
+
/** `asset` is undefined for a break-level error (no playable variant, the break never began). */
|
|
13
|
+
onAdError: (breakInfo: Break, asset: Asset | undefined, error: Error) => void;
|
|
14
|
+
onAdTimeUpdate: (breakInfo: Break, asset: Asset, currentTime: number, duration: number) => void;
|
|
15
|
+
onAdWaiting: (breakInfo: Break, asset: Asset) => void;
|
|
16
|
+
onAdPlaying: (breakInfo: Break, asset: Asset) => void;
|
|
17
|
+
onBreakEnd: (breakInfo: Break) => void;
|
|
18
|
+
/** The break-cut timer expired with an ad still in flight; fired before that ad's `adend`. */
|
|
19
|
+
onBreakCut?: (breakInfo: Break) => void;
|
|
20
|
+
/**
|
|
21
|
+
* A content-covering break ended before its content pause landed, so no player transition
|
|
22
|
+
* announces the resume. Only the deferred-pause renderers (Kotlin/Swift) fire this.
|
|
23
|
+
*/
|
|
24
|
+
onBreakEndedWithoutContentPause?: (breakInfo: Break) => void;
|
|
25
|
+
/** Ad overlay became visible; gates `adbreakbegin` so the AD badge never precedes the first ad frame. */
|
|
26
|
+
onBreakVisible?: (breakInfo: Break) => void;
|
|
27
|
+
/** The current break soft-ended into a chained successor (overlay held, no content resume). */
|
|
28
|
+
onChainedBreakBegin?: (next: Break) => void;
|
|
29
|
+
/** A chained successor resolved but has nothing to play; the SDK must retire it (completeBreak). */
|
|
30
|
+
onChainedBreakSkipped?: (next: Break) => void;
|
|
31
|
+
/**
|
|
32
|
+
* The ad player buffered the next ad of `breakId` behind the playing ad: the playing break's next
|
|
33
|
+
* ad, or a chained break's first ad (`late` after a change during the last ad).
|
|
34
|
+
*/
|
|
35
|
+
onSuccessorBuffered?: (breakId: string, late: boolean) => void;
|
|
36
|
+
/** The ad player discarded the buffered ad of `breakId`. */
|
|
37
|
+
onSuccessorDropped?: (breakId: string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Fired just before the runtime's own post-break resume-seek, so the scheduler does not read
|
|
40
|
+
* the backward step as a DVR seek-back and re-arm the break.
|
|
41
|
+
*/
|
|
42
|
+
onContentResumeSeek?: (targetSeconds: number, breakEndSeconds: number) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Brackets a content RELOAD (shared-element break end), so the playhead passing through the
|
|
45
|
+
* start of the freshly loaded stream is not read as a seek back before the break.
|
|
46
|
+
*/
|
|
47
|
+
onContentReloading?: (active: boolean) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface PlayBreakOptions {
|
|
50
|
+
/** Seconds to present the break for (tune-in breaks: the remaining time); defaults to `break.duration`. */
|
|
51
|
+
effectiveDurationSec?: number;
|
|
52
|
+
/** Defer the overlay and `onBreakVisible` until the first ad frame renders (held delay:0 fullscreen pre-rolls). */
|
|
53
|
+
firstFrameGate?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* IMA quartile callbacks. `adIndex`/`totalAds` attribute the milestone to one ad of a
|
|
57
|
+
* multi-ad GAM pod; omitted when there is no per-ad breakdown.
|
|
58
|
+
*/
|
|
59
|
+
export interface GamEventCallbacks {
|
|
60
|
+
onAdFirstQuartile?: (breakInfo: Break, asset: Asset, adIndex?: number, totalAds?: number) => void;
|
|
61
|
+
onAdMidpoint?: (breakInfo: Break, asset: Asset, adIndex?: number, totalAds?: number) => void;
|
|
62
|
+
onAdThirdQuartile?: (breakInfo: Break, asset: Asset, adIndex?: number, totalAds?: number) => void;
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -21,6 +21,8 @@ export interface AdPlayerEventsDeps {
|
|
|
21
21
|
clearFirstFrameResolver: () => void;
|
|
22
22
|
drive: (transition: AdBreakTransition) => Promise<void>;
|
|
23
23
|
setPendingAdError: (value: Error | null) => void;
|
|
24
|
+
/** Drop the ad queued behind the failed one: it loads as today instead. */
|
|
25
|
+
dropQueuedAd: () => void;
|
|
24
26
|
log: (...args: unknown[]) => void;
|
|
25
27
|
maybePrepositionContentForResume: () => void;
|
|
26
28
|
maybeCatchUpContentForResume: (breakInfo: Break) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AssetType as t}from"../../types/BreakManifest";export class AdPlayerEvents{constructor(t,e){this.state=t,this.deps=e}recordAdProgress(t){!Number.isFinite(t)||t<=0||(this.deps.onGamPodAdProgress(t),t>this.state.currentAssetElapsedSec&&(this.state.currentAssetElapsedSec=t))}settleAssetProgress(){let t=this.state.currentAssetElapsedSec;if(t<=0){const e=this.state.currentAsset?.duration;"number"==typeof e&&Number.isFinite(e)&&e>0&&(t=e)}this.state.adSecondsPlayedThisBreak+=t,this.state.currentAssetElapsedSec=0}reportAdProgress(e){if(this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&(this.recordAdProgress(e.currentTime),this.deps.maybePrepositionContentForResume(),this.state.currentBreak&&this.deps.maybeCatchUpContentForResume(this.state.currentBreak),this.state.callbacks?.onAdTimeUpdate(this.state.currentBreak,this.state.currentAsset,e.currentTime,e.duration),this.state.currentAsset.type===t.STATIC&&e.duration>0)){const t=e.currentTime/e.duration,s=this.deps.getStaticQuartilesFired(),r=this.deps.getGamEventCallbacks();t>=.25&&!s.has("first")&&(s.add("first"),r.onAdFirstQuartile?.(this.state.currentBreak,this.state.currentAsset)),t>=.5&&!s.has("mid")&&(s.add("mid"),r.onAdMidpoint?.(this.state.currentBreak,this.state.currentAsset)),t>=.75&&!s.has("third")&&(s.add("third"),r.onAdThirdQuartile?.(this.state.currentBreak,this.state.currentAsset))}}setupEventListeners(){const t=this.deps.getAdPlayer();if(!t)return;t.on("ended",()=>{this.deps.onAdEnded()}),t.on("timedmetadata",t=>{t&&this.deps.processTimedMetadata(t)}),t.on("error",t=>{this.onAdError(this.deps.toAdError(t))}),t.on("timeupdate",()=>this.reportAdProgress(t)),t.on("waiting",()=>{this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&this.state.callbacks?.onAdWaiting(this.state.currentBreak,this.state.currentAsset)}),t.on("playing",()=>{if(this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&!t.paused){if(this.state.startPlaybackCutoff?.(),this.state.firstFrameResolver)return this.deps.revealFirstFrame(),this.state.firstFrameResolver(),void this.state.callbacks?.onAdPlaying(this.state.currentBreak,this.state.currentAsset);this.state.callbacks?.onAdPlaying(this.state.currentBreak,this.state.currentAsset)}});const e=()=>{const t=this.deps.getAdPlayer();if(this.deps.getSyncing()||!t)return;const e=this.deps.getAudioFocus();e?"ad"===e?this.deps.notifyVolumeChange():(this.deps.setSyncing(!0),t.muted=!0,t.volume=0,this.deps.setSyncing(!1)):this.state.isPlaying&&(this.deps.setSyncing(!0),this.deps.getContentPlayer().muted=t.muted,this.deps.getContentPlayer().volume=t.volume,this.deps.setSyncing(!1),this.deps.notifyVolumeChange())};this.deps.setAdVolumeChangeHandler(e),t.on("volumechange",e);const s=()=>{const t=this.deps.getAdPlayer();if(this.deps.getSyncing()||!t)return;const e=this.deps.getAudioFocus();e?"content"===e?this.deps.notifyVolumeChange():(this.deps.setSyncing(!0),this.deps.getContentPlayer().muted=!0,this.deps.setSyncing(!1)):(this.deps.setSyncing(!0),t.muted=this.deps.getContentPlayer().muted,t.volume=this.deps.getContentPlayer().volume,this.deps.setSyncing(!1),this.deps.notifyVolumeChange())};this.deps.setContentVolumeHandler(s),this.deps.getContentPlayer().on("volumechange",s)}onAdError(t){const e=this.deps.getSequencer(),s=this.state.currentBreak;if(!s||!e)return;const r=this.state.preloadGeneration,i=this.state.erroredAsset;if(i?.breakInfo!==s||i.generation!==r){if(this.state.erroredAsset={breakInfo:s,generation:r},this.state.firstFrameRejector){const e=this.state.firstFrameRejector;this.deps.clearFirstFrameResolver(),e(t)}this.deps.log("Ad error:",t.message),this.deps.setPendingAdError(t),this.deps.drive(e.onOutcome({kind:"asset-errored"}))}else this.deps.log("Ignoring further ad error for the same asset:",t.message)}}
|
|
1
|
+
import{AssetType as t}from"../../types/BreakManifest";export class AdPlayerEvents{constructor(t,e){this.state=t,this.deps=e}recordAdProgress(t){!Number.isFinite(t)||t<=0||(this.deps.onGamPodAdProgress(t),t>this.state.currentAssetElapsedSec&&(this.state.currentAssetElapsedSec=t))}settleAssetProgress(){let t=this.state.currentAssetElapsedSec;if(t<=0){const e=this.state.currentAsset?.duration;"number"==typeof e&&Number.isFinite(e)&&e>0&&(t=e)}this.state.adSecondsPlayedThisBreak+=t,this.state.currentAssetElapsedSec=0}reportAdProgress(e){if(this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&(this.recordAdProgress(e.currentTime),this.deps.maybePrepositionContentForResume(),this.state.currentBreak&&this.deps.maybeCatchUpContentForResume(this.state.currentBreak),this.state.callbacks?.onAdTimeUpdate(this.state.currentBreak,this.state.currentAsset,e.currentTime,e.duration),this.state.currentAsset.type===t.STATIC&&e.duration>0)){const t=e.currentTime/e.duration,s=this.deps.getStaticQuartilesFired(),r=this.deps.getGamEventCallbacks();t>=.25&&!s.has("first")&&(s.add("first"),r.onAdFirstQuartile?.(this.state.currentBreak,this.state.currentAsset)),t>=.5&&!s.has("mid")&&(s.add("mid"),r.onAdMidpoint?.(this.state.currentBreak,this.state.currentAsset)),t>=.75&&!s.has("third")&&(s.add("third"),r.onAdThirdQuartile?.(this.state.currentBreak,this.state.currentAsset))}}setupEventListeners(){const t=this.deps.getAdPlayer();if(!t)return;t.on("ended",()=>{this.deps.onAdEnded()}),t.on("timedmetadata",t=>{t&&this.deps.processTimedMetadata(t)}),t.on("error",t=>{this.onAdError(this.deps.toAdError(t))}),t.on("timeupdate",()=>this.reportAdProgress(t)),t.on("waiting",()=>{this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&this.state.callbacks?.onAdWaiting(this.state.currentBreak,this.state.currentAsset)}),t.on("playing",()=>{if(this.state.isPlaying&&this.state.currentBreak&&this.state.currentAsset&&!t.paused){if(this.state.startPlaybackCutoff?.(),this.state.firstFrameResolver)return this.deps.revealFirstFrame(),this.state.firstFrameResolver(),void this.state.callbacks?.onAdPlaying(this.state.currentBreak,this.state.currentAsset);this.state.callbacks?.onAdPlaying(this.state.currentBreak,this.state.currentAsset)}});const e=()=>{const t=this.deps.getAdPlayer();if(this.deps.getSyncing()||!t)return;const e=this.deps.getAudioFocus();e?"ad"===e?this.deps.notifyVolumeChange():(this.deps.setSyncing(!0),t.muted=!0,t.volume=0,this.deps.setSyncing(!1)):this.state.isPlaying&&(this.deps.setSyncing(!0),this.deps.getContentPlayer().muted=t.muted,this.deps.getContentPlayer().volume=t.volume,this.deps.setSyncing(!1),this.deps.notifyVolumeChange())};this.deps.setAdVolumeChangeHandler(e),t.on("volumechange",e);const s=()=>{const t=this.deps.getAdPlayer();if(this.deps.getSyncing()||!t)return;const e=this.deps.getAudioFocus();e?"content"===e?this.deps.notifyVolumeChange():(this.deps.setSyncing(!0),this.deps.getContentPlayer().muted=!0,this.deps.setSyncing(!1)):(this.deps.setSyncing(!0),t.muted=this.deps.getContentPlayer().muted,t.volume=this.deps.getContentPlayer().volume,this.deps.setSyncing(!1),this.deps.notifyVolumeChange())};this.deps.setContentVolumeHandler(s),this.deps.getContentPlayer().on("volumechange",s)}onAdError(t){const e=this.deps.getSequencer(),s=this.state.currentBreak;if(!s||!e)return;const r=this.state.preloadGeneration,i=this.state.erroredAsset;if(i?.breakInfo!==s||i.generation!==r){if(this.state.erroredAsset={breakInfo:s,generation:r},this.state.firstFrameRejector){const e=this.state.firstFrameRejector;this.deps.clearFirstFrameResolver(),e(t)}this.deps.log("Ad error:",t.message),this.deps.dropQueuedAd(),this.deps.setPendingAdError(t),this.deps.drive(e.onOutcome({kind:"asset-errored"}))}else this.deps.log("Ignoring further ad error for the same asset:",t.message)}}
|
|
@@ -19,8 +19,8 @@ export interface AdPreloaderDeps {
|
|
|
19
19
|
effectiveInsertionMode: () => string;
|
|
20
20
|
getVariant: (breakInfo: Break) => BreakVariant | null;
|
|
21
21
|
getAssets: (breakInfo: Break) => Asset[];
|
|
22
|
-
|
|
23
|
-
resolveAssetUri: (asset: Asset, duration: number) => Promise<string | null>;
|
|
22
|
+
buildStaticAssetUrl: (asset: StaticAsset, breakInfo: Break) => string | null;
|
|
23
|
+
resolveAssetUri: (asset: Asset, duration: number, breakInfo: Break) => Promise<string | null>;
|
|
24
24
|
getCompanionVariant: (breakInfo: Break) => BreakVariant | null;
|
|
25
25
|
getAdPlayer: () => PlayerAdapter | null;
|
|
26
26
|
getAdContainer: () => HTMLDivElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AssetType as e,BreakFormat as t,MediaType as s,Vendor as a,isVastAsset as r,isVendorAsset as i}from"../../types/BreakManifest";import{AUX_FETCH_TIMEOUT_MS as d,fetchWithTimeout as o}from"../fetchWithTimeout";import{resolveVastAdmission as n}from"../resolveVastAdmission";import{isImaCsaiSdkAvailable as l,VastAdManager as p}from"../VastAdManager";import{invalidateMediaPreload as h}from"./AdPlayerState";import{AdError as m}from"../../types/AdError";export const AD_LOAD_RETRY_AFTER_MS=2e3;export function adLoadShowsNoProgress(e){return!e||0===e.readyState&&0===e.buffered.length}export class AdPreloader{constructor(e){this.deps=e,this.warmedBreakIds=new Set}classifyCreative(e){const t=(e.split(/[?#]/)[0]??"").toLowerCase();return t.endsWith(".m3u8")||t.endsWith(".mpd")?"stream":/\.(mp4|m4v|m4a|webm|mov|ogg|ogv|mp3)$/.test(t)?"progressive":"unknown"}diagnosePreloadPath(e,t,s){const a=this.classifyCreative(t);this.deps.diagnose("DA-PRELOAD-PATH",`Ad preload path: ${s} (${a} creative)`,{breakId:e,adPreload:this.deps.preloadMode,path:s,creative:a})}async preload(a){if(this.deps.isPlaying())return void this.deps.log("Preload skipped: ad already playing");const i=h(this.deps.state),d=this.deps.getAdPlayer();if("none"===this.deps.preloadMode){const t=this.deps.getAssets(a)[0],s=t&&t.type===e.STATIC?this.deps.
|
|
1
|
+
import{AssetType as e,BreakFormat as t,MediaType as s,Vendor as a,isVastAsset as r,isVendorAsset as i}from"../../types/BreakManifest";import{AUX_FETCH_TIMEOUT_MS as d,fetchWithTimeout as o}from"../fetchWithTimeout";import{resolveVastAdmission as n}from"../resolveVastAdmission";import{isImaCsaiSdkAvailable as l,VastAdManager as p}from"../VastAdManager";import{invalidateMediaPreload as h}from"./AdPlayerState";import{AdError as m}from"../../types/AdError";export const AD_LOAD_RETRY_AFTER_MS=2e3;export function adLoadShowsNoProgress(e){return!e||0===e.readyState&&0===e.buffered.length}export class AdPreloader{constructor(e){this.deps=e,this.warmedBreakIds=new Set}classifyCreative(e){const t=(e.split(/[?#]/)[0]??"").toLowerCase();return t.endsWith(".m3u8")||t.endsWith(".mpd")?"stream":/\.(mp4|m4v|m4a|webm|mov|ogg|ogv|mp3)$/.test(t)?"progressive":"unknown"}diagnosePreloadPath(e,t,s){const a=this.classifyCreative(t);this.deps.diagnose("DA-PRELOAD-PATH",`Ad preload path: ${s} (${a} creative)`,{breakId:e,adPreload:this.deps.preloadMode,path:s,creative:a})}async preload(a){if(this.deps.isPlaying())return void this.deps.log("Preload skipped: ad already playing");const i=h(this.deps.state),d=this.deps.getAdPlayer();if("none"===this.deps.preloadMode){const t=this.deps.getAssets(a)[0],s=t&&t.type===e.STATIC?this.deps.buildStaticAssetUrl(t,a)??"":"";return this.diagnosePreloadPath(a.id,s,"none"),void this.deps.log('Preload skipped: adPreload "none"')}if("shared-element"===this.deps.effectiveInsertionMode()){const s=this.deps.getVariant(a);if(s&&s.format!==t.LSHAPE_CONTENT){const t=this.deps.getAssets(a)[0];if(t&&t.type===e.STATIC){const e=this.deps.buildStaticAssetUrl(t,a);e&&await this.warmCache([e])}}return}const o=this.deps.getAssets(a);if(0===o.length)return void this.deps.log("No assets to preload");this.preloadCompanion(a);const n=this.deps.getVariant(a);if(n?.format===t.LSHAPE_CONTENT)return;if(o[0].mediaType===s.IMAGE){const e=await this.deps.resolveAssetUri(o[0],a.duration,a);if(e){(new Image).src=e,this.deps.log("Preloading overlay image:",e)}return}if(r(o[0]))return void await this.preloadVastAsset(o[0],a);const l=await this.deps.resolveAssetUri(o[0],a.duration,a);if(l){if(d&&this.ownsPreload(i,d))if("single-decoder"!==this.deps.preloadMode){this.deps.log("Preloading ad (parallel):",l),this.diagnosePreloadPath(a.id,l,"parallel");try{if(await d.load(l),!this.ownsPreload(i,d))return;this.deps.state.preparedMedia={breakId:a.id,assetId:o[0].id,uri:l,player:d},this.deps.log("Preload complete for break:",a.id)}catch(e){this.deps.log("Preload failed (will load on demand):",e)}}else{if(this.deps.log("Preloading ad (single-decoder, detached):",l),this.diagnosePreloadPath(a.id,l,"single-decoder"),await this.warmCache([l]),!this.ownsPreload(i,d))return;try{await(d.preload?.(l))}catch(e){this.deps.log("Detached prefetch failed (will load on demand):",e)}}}else this.deps.log("No valid URI for preload")}ownsPreload(e,t){return e===this.deps.state.preloadGeneration&&!this.deps.isPlaying()&&t===this.deps.getAdPlayer()}async preloadVastAsset(e,s){const a=this.deps.getVariant(s),r=a?.format??t.SINGLE;if(!n({format:r,ssai:!1}).admitted)return void this.deps.log("VAST preload skipped: format not supported",r);if(!l())return void this.deps.log("VAST preload skipped: IMA client-side SDK unavailable");const i=this.deps.getAdPlayer(),d=this.deps.getAdContainer();if(!i||!d)return void this.deps.log("VAST preload skipped: ad player not initialized");const o=i.videoElement;if(!o)return void this.deps.log("VAST preload skipped: no ad video element");const h=this.deps.buildVastTagUrl(e,s);if(h){this.deps.state.vastAdManager||(this.deps.state.vastAdManager=new p(d,o,this.deps.debug)),this.deps.log("Preloading VAST asset via IMA CSAI:",h);try{await this.deps.state.vastAdManager.preloadVast(h,{muted:i.muted}),this.deps.log("VAST preload complete for break:",s.id)}catch(t){const a=t instanceof Error?t:new Error(String(t));this.deps.log("VAST preload failed (will load on demand):",a.message),this.deps.diagnose("DA-PRELOAD-FAILED",a.message,{breakId:s.id,assetId:e.id})}}else this.deps.log("No valid VAST tag URL for preload")}preloadChainedSuccessor(e){const t=this.deps.resolveChainedSuccessor(e);t&&this.preloadNext(t)}clearWarmedBreaks(){this.warmedBreakIds.clear()}async preloadNext(s){if(this.warmedBreakIds.has(s.id))return;this.preloadCompanion(s);const a=this.deps.getVariant(s);if(!a||a.format===t.LSHAPE_CONTENT)return;const r=this.deps.getAssets(s)[0];if(!r||r.type!==e.STATIC)return void this.deps.log("Chained successor first asset not static; skipping media warm:",s.id);const i=this.deps.buildStaticAssetUrl(r,s);if(i){this.warmedBreakIds.add(s.id),this.deps.log("Warming chained successor media:",s.id,i),await this.warmCache([i]);try{await(this.deps.getAdPlayer()?.preload?.(i))}catch(e){this.deps.log("Chained prefetch failed (will load on demand):",e)}}}revealFirstFrame(){if(!this.deps.state.firstFrameGateActive||this.deps.state.firstFrameGateShown)return;const e=this.deps.getCurrentBreak();if(!e)return;this.deps.state.firstFrameGateShown=!0,this.deps.show();const t=this.deps.getVariant(e);t&&this.deps.reapplyAdContainerLayout(t),this.deps.onBreakVisible(e)}armAdStartBudget(e){const t=1e3*((this.deps.state.effectiveBreakDurationSec??this.deps.state.currentBreak?.duration??0)+this.deps.state.adBreakCutSafetyMarginSec),s=i(e)&&e.vendor===a.GAM?this.deps.gamPodAdStartBudgetMs:this.deps.adStartBudgetMs,r=Math.max(Math.min(t-100,s),this.deps.minAdStartBudgetMs);this.deps.state.adStartBudgetMs=r,this.deps.state.adStartDeadlineMs=this.deps.clock.now()+r}remainingAdStartBudgetMs(){return Math.max(0,(this.deps.state.adStartDeadlineMs??this.deps.clock.now())-this.deps.clock.now())}loadWithinBudget(e,t){const s=this.deps.state.preloadGeneration,a=this.remainingAdStartBudgetMs(),r=this.deps.clock.now();return new Promise((i,d)=>{let o=!1,n=!1;const l=e=>{o||(o=!0,clearTimeout(p),null!==h&&clearTimeout(h),e.ok?i(!0):d(e.error))},p=setTimeout(()=>{s===this.deps.state.preloadGeneration&&this.deps.onAdError(new m("Ad load timeout","DA-AD-START-TIMEOUT")),o||(o=!0,null!==h&&clearTimeout(h),i(!1))},a);let h=null;a>2e3&&(h=setTimeout(()=>{if(o||s!==this.deps.state.preloadGeneration)return;const a=this.deps.clock.now()-r,i=this.deps.getAdPlayer()?.videoElement;adLoadShowsNoProgress(i)?(n=!0,this.deps.log(`Ad load for ${t.assetId} stalled after ${a}ms; retrying once`),this.deps.diagnose("DA-AD-LOAD-RETRIED",`Ad load for ${t.assetId} in break ${t.breakId} had not settled after ${a}ms; issued a second load()`,{breakId:t.breakId,assetId:t.assetId,uri:t.uri,elapsedMs:a,remainingBudgetMs:this.remainingAdStartBudgetMs()}),e().then(()=>l({ok:!0}),e=>l({ok:!1,error:e}))):this.deps.log(`Ad load for ${t.assetId} still pending after ${a}ms but the element is progressing (readyState=${i?.readyState}, buffered=${i?.buffered.length}); no retry`)},2e3)),e().then(()=>l({ok:!0}),e=>{n||l({ok:!1,error:e})})})}async waitForFirstFrame(){return new Promise((e,t)=>{this.deps.state.firstFrameResolver=()=>{this.clearFirstFrameResolver(),e()},this.deps.state.firstFrameRejector=e=>{this.clearFirstFrameResolver(),t(e)},this.deps.state.firstFrameTimeout=setTimeout(()=>{this.deps.onAdError(new m("First frame timeout","DA-AD-START-TIMEOUT"))},this.remainingAdStartBudgetMs())})}clearFirstFrame(e="Break ended before first frame"){if(this.deps.state.adStartDeadlineMs=null,this.deps.state.adStartBudgetMs=0,this.deps.state.firstFrameTimeout&&(clearTimeout(this.deps.state.firstFrameTimeout),this.deps.state.firstFrameTimeout=null),this.deps.state.firstFrameRejector){const t=this.deps.state.firstFrameRejector;this.deps.state.firstFrameResolver=null,this.deps.state.firstFrameRejector=null,t(new Error(e))}}clearFirstFrameResolver(){this.deps.state.adStartDeadlineMs=null,this.deps.state.adStartBudgetMs=0,this.deps.state.firstFrameTimeout&&(clearTimeout(this.deps.state.firstFrameTimeout),this.deps.state.firstFrameTimeout=null),this.deps.state.firstFrameResolver=null,this.deps.state.firstFrameRejector=null}preloadCompanion(s){const a=this.deps.getCompanionVariant(s);if(!a)return;if(a.format===t.LSHAPE_CONTENT){const t=a.assets[0];if(!t||t.type!==e.STATIC)return;const r=this.deps.buildStaticAssetUrl(t,s);if(!r)return;return(new Image).src=r,void this.deps.log("Preloading lshape_content backdrop:",r)}if(a.format!==t.DOUBLE&&a.format!==t.LSHAPE_AD)return;const r=a.assets[0]?.companion;if(!r||r.type!==e.STATIC)return;const i=this.deps.buildStaticAssetUrl(r,s);if(!i)return;(new Image).src=i,this.deps.log("Preloading companion:",i)}async warmCache(e){"function"==typeof fetch&&await Promise.allSettled(e.map(e=>o(e,{mode:"no-cors"},d).catch(()=>{})))}}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PlayerAdapter } from '../../interfaces/PlayerAdapter';
|
|
2
|
-
import {
|
|
2
|
+
import { type PresentationHost } from './presentation/DomPresentationHost';
|
|
3
|
+
import { AssetWithCompanion, Break, BreakVariant, LshapeContentBreakVariant, StaticAsset } from '../../types/BreakManifest';
|
|
3
4
|
export interface AdStageDeps {
|
|
4
5
|
contentPlayer: PlayerAdapter;
|
|
5
6
|
container: HTMLElement;
|
|
@@ -21,7 +22,7 @@ export interface AdStageDeps {
|
|
|
21
22
|
resizeVast: () => void;
|
|
22
23
|
getVariant: (breakInfo: Break) => BreakVariant | null;
|
|
23
24
|
getCurrentBreak: () => Break | null;
|
|
24
|
-
|
|
25
|
+
buildStaticAssetUrl: (asset: StaticAsset, breakInfo: Break | null) => string | null;
|
|
25
26
|
getCompanion: () => HTMLImageElement | HTMLVideoElement | null;
|
|
26
27
|
setCompanion: (element: HTMLImageElement | HTMLVideoElement | null) => void;
|
|
27
28
|
getOverlayImage: () => HTMLImageElement | null;
|
|
@@ -30,6 +31,8 @@ export interface AdStageDeps {
|
|
|
30
31
|
setImageAssetTimer: (timer: ReturnType<typeof setTimeout> | null) => void;
|
|
31
32
|
isChaining: () => boolean;
|
|
32
33
|
log: (...args: unknown[]) => void;
|
|
34
|
+
/** Presentation host seam: places the stage surfaces with normalized transforms. */
|
|
35
|
+
presentationHost: PresentationHost;
|
|
33
36
|
}
|
|
34
37
|
/** Owns the overlay stage geometry, break layout and companions. The content/ad switch is a cut; only the layout reflow glides. */
|
|
35
38
|
export declare class AdStage {
|
|
@@ -52,9 +55,9 @@ export declare class AdStage {
|
|
|
52
55
|
renderLshapeContentBackdrop(variant: LshapeContentBreakVariant): void;
|
|
53
56
|
reapplyAdContainerLayout(variant: BreakVariant): void;
|
|
54
57
|
applyLayout(variant: BreakVariant): void;
|
|
55
|
-
restoreLayout(
|
|
58
|
+
restoreLayout(): void;
|
|
56
59
|
renderCompanion(assets: AssetWithCompanion[], cssText: string): void;
|
|
57
|
-
/** Shows `img` as the stage companion and
|
|
60
|
+
/** Shows `img` as the stage companion and removes the previous one. */
|
|
58
61
|
private installCompanion;
|
|
59
62
|
/** Removes that specific companion element at once (a cut, like the ad surface). */
|
|
60
63
|
private retireCompanion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getPreparedPresentation as e}from"./PreparedPresentation";import{AssetType as t,BreakFormat as s}from"../../types/BreakManifest";const i=16/9;export class AdStage{constructor(e){this.deps=e,this.contentVideoGeometryHandler=null,this.contentVideoMutationObserver=null,this.resizeObserver=null,this.resizePoll=null,this.contentLayout=null,this.preparedLease=null,this.unsubscribeGeometry=null}setupOverlay(){const t=e(this.deps.container);if(t){const e=this.deps.getPlayerContainer();if(e&&e!==t.playerContainer)throw new Error("The prepared content container cannot be replaced");this.preparedLease=t.acquire(),this.deps.setStage(this.preparedLease.stage),this.deps.setPlayerContainer(this.preparedLease.playerContainer),this.unsubscribeGeometry=this.preparedLease.subscribe(()=>this.deps.resizeVast());try{this.setupMediaLayer()}catch(e){const t=this.deps.getAdContainer();throw t?.parentNode?.removeChild(t),this.deps.setAdContainer(null),this.deps.setAdMediaContainer(null),this.unsubscribeGeometry?.(),this.preparedLease.release(),e}return}const s=window.getComputedStyle(this.deps.container);"static"!==s.position&&""!==s.position||(this.deps.container.style.position="relative"),this.deps.setStage(document.createElement("div"));const i=this.deps.getStage();if(!i)return;if(i.className="dolby-stage",i.style.cssText="position:absolute;overflow:hidden;",this.deps.container.appendChild(i),this.contentVideoGeometryHandler=()=>this.refreshStageGeometry(),"undefined"!=typeof MutationObserver&&(this.contentVideoMutationObserver=new MutationObserver(()=>{(this.deps.contentPlayer.videoElement??null)!==this.deps.getContentVideo()&&this.refreshStageGeometry()}),this.contentVideoMutationObserver.observe(this.deps.container,{childList:!0,subtree:!0})),"undefined"!=typeof ResizeObserver)this.resizeObserver=new ResizeObserver(()=>this.refreshStageGeometry()),this.resizeObserver.observe(this.deps.container);else{let e=this.deps.container.getBoundingClientRect();this.resizePoll=setInterval(()=>{const t=this.deps.container.getBoundingClientRect();t.width===e.width&&t.height===e.height||(e=t,this.refreshStageGeometry())},250)}if(this.refreshStageGeometry(),this.deps.getPlayerContainer()){const e=this.deps.getPlayerContainer();if(!e)return;i.appendChild(e)}else{const e=document.createElement("div"),t=Array.from(this.deps.container.childNodes).filter(e=>e!==i);for(const s of t)e.appendChild(s);i.appendChild(e),this.deps.setPlayerContainer(e),this.deps.onPlayerContainerCreated()}const n=this.deps.getPlayerContainer();n&&(this.deps.setPlayerContainerOriginalStyle(n.style.cssText),n.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;transition:top 0.3s ease-in-out,left 0.3s ease-in-out,right 0.3s ease-in-out,bottom 0.3s ease-in-out;",this.setupMediaLayer())}setupMediaLayer(){const e=this.deps.getStage();if(!e)throw new Error("An ads presentation stage is required");this.deps.setAdContainer(document.createElement("div"));const t=this.deps.getAdContainer();if(!t)return;t.className="dolby-ad-container",t.style.cssText="display:none;position:absolute;top:0;left:0;right:0;bottom:0;z-index:100;background:#000;",this.deps.setAdMediaContainer(document.createElement("div"));const s=this.deps.getAdMediaContainer();if(!s)return;s.style.cssText="display:block;width:100%;height:100%;",t.appendChild(s),e.appendChild(t);const i=this.deps.createAdAdapter(s);i!==this.deps.contentPlayer&&i.prepareForAdPlayback?.(),this.deps.setAdPlayer(i),this.deps.setupEventListeners(),this.deps.log("Ad player overlay initialized")}refreshStageGeometry(){this.rebindContentVideoGeometryListener(),this.updateStageGeometry(),this.deps.resizeVast()}rebindContentVideoGeometryListener(){const e=this.deps.contentPlayer.videoElement??null,t=e&&"function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener?e:null;t!==this.deps.getContentVideo()&&(this.deps.getContentVideo()&&this.contentVideoGeometryHandler&&(this.deps.getContentVideo()?.removeEventListener("loadedmetadata",this.contentVideoGeometryHandler),this.deps.getContentVideo()?.removeEventListener("resize",this.contentVideoGeometryHandler)),this.deps.setContentVideo(t),t&&this.contentVideoGeometryHandler&&(t.addEventListener("loadedmetadata",this.contentVideoGeometryHandler),t.addEventListener("resize",this.contentVideoGeometryHandler)))}updateStageGeometry(){const e=this.deps.getStage();if(!e)return;const{width:t,height:s}=this.deps.container.getBoundingClientRect();if(0===t||0===s)return;const i=this.getContentAspectRatio();let n,o;t/s>i?(o=s,n=s*i):(n=t,o=t/i);const r=(s-o)/2,a=(t-n)/2;e.style.width=`${n}px`,e.style.height=`${o}px`,e.style.top=`${r}px`,e.style.left=`${a}px`}getContentAspectRatio(){const e=this.deps.contentPlayer.videoElement;if(!e)return i;const{videoWidth:t,videoHeight:s}=e;return!Number.isFinite(t)||!Number.isFinite(s)||t<=0||s<=0?i:t/s}renderLshapeContentBackdrop(e){const s=e.assets[0];if(!s||s.type!==t.STATIC)return;const i=this.deps.resolveUri(s.uri);if(!i)return;const n=document.createElement("img");n.className="dolby-companion",n.src=i,n.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;object-fit:cover;width:100%;height:100%;opacity:0;";const o=this.deps.getStage();o&&(this.installCompanion(n,o),this.deps.log("Rendered lshape_content backdrop:",i))}reapplyAdContainerLayout(e){const t=this.deps.getAdContainer();if(t){switch(e.format){case s.LSHAPE_AD:t.style.position="absolute",t.style.top="5%",t.style.left="5%",t.style.right="30%",t.style.bottom="30%",t.style.width="",t.style.height="",t.style.zIndex="100";break;case s.DOUBLE:t.style.position="absolute",t.style.top="26.04%",t.style.left="51.04%",t.style.right="1.04%",t.style.bottom="26.04%",t.style.width="",t.style.height="",t.style.zIndex="100"}this.deps.log("reapplyAdContainerLayout: re-stamped adContainer CSS for format:",e.format)}}applyLayout(e){const t=this.deps.getAdContainer(),i=this.deps.getPlayerContainer();if(!t||!i)return;const n="transition:top 0.3s ease-in-out,left 0.3s ease-in-out,right 0.3s ease-in-out,bottom 0.3s ease-in-out;";switch(e.format){case s.SINGLE:this.contentLayout&&(i.style.opacity="0"),t.style.cssText="display:none;opacity:0;position:absolute;top:0;left:0;right:0;bottom:0;z-index:100;background:#000;";break;case s.DOUBLE:i.style.cssText=`position:absolute;top:26.04%;left:1.04%;right:51.04%;bottom:26.04%;z-index:101;${n}`,t.style.cssText="display:none;opacity:0;position:absolute;top:26.04%;left:51.04%;right:1.04%;bottom:26.04%;z-index:100;background:#000;",this.renderCompanion(e.assets,"position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;object-fit:cover;width:100%;height:100%;opacity:0;"),this.contentLayout=e.format;break;case s.LSHAPE_AD:i.style.cssText=`position:absolute;top:5%;left:5%;right:30%;bottom:30%;z-index:101;opacity:0;${n}`,t.style.cssText="display:none;opacity:0;position:absolute;top:5%;left:5%;right:30%;bottom:30%;z-index:100;background:#000;",this.renderCompanion(e.assets,"position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;object-fit:cover;width:100%;height:100%;opacity:0;"),this.contentLayout=e.format;break;case s.LSHAPE_CONTENT:i.style.top="5%",i.style.left="5%",i.style.right="30%",i.style.bottom="30%",i.style.zIndex="101",this.contentLayout=e.format;break;case s.OVERLAY:{const s=e,i=e=>void 0!==e?100*e+"%":"auto",n=i(s.position.top),o=i(s.position.bottom),r=i(s.position.left),a=i(s.position.right),d=100*s.size.width+"%",l=100*s.size.height+"%",p=s.opacity??1;t.style.cssText=`display:none;position:absolute;top:${n};bottom:${o};left:${r};right:${a};width:${d};height:${l};z-index:100;opacity:${p};`;break}default:t.style.cssText="display:none;position:absolute;top:0;left:0;right:0;bottom:0;z-index:100;background:#000;"}}restoreLayout(e){if(this.preparedLease&&!this.preparedLease.isActive())return;const t=this.deps.getPlayerContainer();if(!t)return;const i=function(e){return e===s.DOUBLE||e===s.LSHAPE_AD||e===s.LSHAPE_CONTENT}(e)||null!==this.contentLayout;this.contentLayout=null,t.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;"+(i?"z-index:101;":"")+"transition:top 0.3s ease-in-out,left 0.3s ease-in-out,right 0.3s ease-in-out,bottom 0.3s ease-in-out;";const n=this.deps.getCompanion();n&&(this.deps.setCompanion(null),this.retireCompanion(n)),i&&(t.style.zIndex="")}renderCompanion(e,s){const i=e[0]?.companion;if(!i)return;const n=i.type===t.STATIC?this.deps.resolveUri(i.uri):null;if(!n)return;const o=document.createElement("img");o.className="dolby-companion",o.src=n,o.style.cssText=s;const r=this.deps.getStage();r&&this.installCompanion(o,r)}installCompanion(e,t){const s=this.deps.getCompanion();t.appendChild(e),this.deps.setCompanion(e),e.style.opacity="1",s&&s!==e&&this.retireCompanion(s)}retireCompanion(e){e.parentElement?.removeChild(e)}clearOverlayImage(){const e=this.deps.getImageAssetTimer();e&&(clearTimeout(e),this.deps.setImageAssetTimer(null));const t=this.deps.getOverlayImage();t?.parentElement&&t.parentElement.removeChild(t),this.deps.setOverlayImage(null)}show(){const e=this.deps.getAdContainer();if(!e)return;const t=this.deps.getCurrentBreak(),i=t?this.deps.getVariant(t):null;e.style.display="block",i?.format!==s.OVERLAY&&(e.style.opacity="1")}hide(){const e=this.deps.getAdContainer();e&&(e.style.opacity="0",e.style.display="none")}restoreContent(e,t){if(this.releasePreparedPresentation())return!0;const s=this.deps.getPlayerContainer();if(!s)return!1;if(e)for(;s.firstChild;)this.deps.container.appendChild(s.firstChild);else this.deps.container.appendChild(s),s.style.cssText=t;return!1}releasePreparedPresentation(){return!!this.preparedLease&&(this.unsubscribeGeometry?.(),this.unsubscribeGeometry=null,this.preparedLease.release(),!0)}destroy(){this.unsubscribeGeometry?.(),this.unsubscribeGeometry=null;const e=this.deps.getContentVideo();e&&this.contentVideoGeometryHandler&&(e.removeEventListener("loadedmetadata",this.contentVideoGeometryHandler),e.removeEventListener("resize",this.contentVideoGeometryHandler)),this.contentVideoMutationObserver?.disconnect(),this.resizeObserver?.disconnect(),null!==this.resizePoll&&clearInterval(this.resizePoll),this.resizePoll=null,this.contentVideoMutationObserver=null,this.resizeObserver=null,this.contentVideoGeometryHandler=null,this.contentLayout=null}}
|
|
1
|
+
import{getPreparedPresentation as e}from"./PreparedPresentation";import{LAYOUT_TRANSITION as t}from"./presentation/LayoutTransform";import{presentationLayoutFor as s,RESTORED_CONTENT_PLACEMENT as i}from"./presentation/PresentationLayout";import{AssetType as n,BreakFormat as o}from"../../types/BreakManifest";const r=16/9;export class AdStage{constructor(e){this.deps=e,this.contentVideoGeometryHandler=null,this.contentVideoMutationObserver=null,this.resizeObserver=null,this.resizePoll=null,this.contentLayout=null,this.preparedLease=null,this.unsubscribeGeometry=null}setupOverlay(){const s=e(this.deps.container);if(s){const e=this.deps.getPlayerContainer();if(e&&e!==s.playerContainer)throw new Error("The prepared content container cannot be replaced");this.preparedLease=s.acquire(),this.deps.setStage(this.preparedLease.stage),this.deps.setPlayerContainer(this.preparedLease.playerContainer),this.unsubscribeGeometry=this.preparedLease.subscribe(()=>this.deps.resizeVast());try{this.setupMediaLayer()}catch(e){const t=this.deps.getAdContainer();throw t?.parentNode?.removeChild(t),this.deps.setAdContainer(null),this.deps.setAdMediaContainer(null),this.unsubscribeGeometry?.(),this.preparedLease.release(),e}return}const i=window.getComputedStyle(this.deps.container);"static"!==i.position&&""!==i.position||(this.deps.container.style.position="relative"),this.deps.setStage(document.createElement("div"));const n=this.deps.getStage();if(!n)return;if(n.className="dolby-stage",n.style.cssText="position:absolute;overflow:hidden;",this.deps.container.appendChild(n),this.contentVideoGeometryHandler=()=>this.refreshStageGeometry(),"undefined"!=typeof MutationObserver&&(this.contentVideoMutationObserver=new MutationObserver(()=>{(this.deps.contentPlayer.videoElement??null)!==this.deps.getContentVideo()&&this.refreshStageGeometry()}),this.contentVideoMutationObserver.observe(this.deps.container,{childList:!0,subtree:!0})),"undefined"!=typeof ResizeObserver)this.resizeObserver=new ResizeObserver(()=>this.refreshStageGeometry()),this.resizeObserver.observe(this.deps.container);else{let e=this.deps.container.getBoundingClientRect();this.resizePoll=setInterval(()=>{const t=this.deps.container.getBoundingClientRect();t.width===e.width&&t.height===e.height||(e=t,this.refreshStageGeometry())},250)}if(this.refreshStageGeometry(),this.deps.getPlayerContainer()){const e=this.deps.getPlayerContainer();if(!e)return;n.appendChild(e)}else{const e=document.createElement("div"),t=Array.from(this.deps.container.childNodes).filter(e=>e!==n);for(const s of t)e.appendChild(s);n.appendChild(e),this.deps.setPlayerContainer(e),this.deps.onPlayerContainerCreated()}const o=this.deps.getPlayerContainer();o&&(this.deps.setPlayerContainerOriginalStyle(o.style.cssText),o.style.cssText=`position:absolute;top:0;left:0;right:0;bottom:0;transition:${t};`,this.setupMediaLayer())}setupMediaLayer(){const e=this.deps.getStage();if(!e)throw new Error("An ads presentation stage is required");this.deps.setAdContainer(document.createElement("div"));const s=this.deps.getAdContainer();if(!s)return;s.className="dolby-ad-container",s.style.cssText=`display:none;position:absolute;top:0;left:0;right:0;bottom:0;z-index:100;background:#000;transition:${t};`,this.deps.setAdMediaContainer(document.createElement("div"));const i=this.deps.getAdMediaContainer();if(!i)return;i.style.cssText="display:block;width:100%;height:100%;",s.appendChild(i),e.appendChild(s);const n=this.deps.createAdAdapter(i);n!==this.deps.contentPlayer&&(n.prepareForAdPlayback?.(),n.setExternalPlaybackAllowed?.(!1)),this.deps.setAdPlayer(n),this.deps.setupEventListeners(),this.deps.log("Ad player overlay initialized")}refreshStageGeometry(){this.rebindContentVideoGeometryListener(),this.updateStageGeometry(),this.deps.resizeVast()}rebindContentVideoGeometryListener(){const e=this.deps.contentPlayer.videoElement??null,t=e&&"function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener?e:null;t!==this.deps.getContentVideo()&&(this.deps.getContentVideo()&&this.contentVideoGeometryHandler&&(this.deps.getContentVideo()?.removeEventListener("loadedmetadata",this.contentVideoGeometryHandler),this.deps.getContentVideo()?.removeEventListener("resize",this.contentVideoGeometryHandler)),this.deps.setContentVideo(t),t&&this.contentVideoGeometryHandler&&(t.addEventListener("loadedmetadata",this.contentVideoGeometryHandler),t.addEventListener("resize",this.contentVideoGeometryHandler)))}updateStageGeometry(){const e=this.deps.getStage();if(!e)return;const{width:t,height:s}=this.deps.container.getBoundingClientRect();if(0===t||0===s)return;const i=this.getContentAspectRatio();let n,o;t/s>i?(o=s,n=s*i):(n=t,o=t/i);const r=(s-o)/2,a=(t-n)/2;e.style.width=`${n}px`,e.style.height=`${o}px`,e.style.top=`${r}px`,e.style.left=`${a}px`}getContentAspectRatio(){const e=this.deps.contentPlayer.videoElement;if(!e)return r;const{videoWidth:t,videoHeight:s}=e;return!Number.isFinite(t)||!Number.isFinite(s)||t<=0||s<=0?r:t/s}renderLshapeContentBackdrop(e){const t=e.assets[0];if(!t||t.type!==n.STATIC)return;const s=this.deps.buildStaticAssetUrl(t,this.deps.getCurrentBreak());if(!s)return;const i=document.createElement("img");i.className="dolby-companion",i.src=s,i.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;object-fit:cover;width:100%;height:100%;opacity:0;";const o=this.deps.presentationHost.getSurfaces()?.backdrop;o&&(this.installCompanion(i,o),this.deps.log("Rendered lshape_content backdrop:",s))}reapplyAdContainerLayout(e){const t=this.deps.getAdContainer();if(!t)return;const i=s(e.format);i&&(e.format!==o.LSHAPE_AD&&e.format!==o.DOUBLE||(t.style.zIndex="100"),this.deps.presentationHost.placeAd(i.ad),this.deps.log("reapplyAdContainerLayout: re-stamped adContainer CSS for format:",e.format))}applyLayout(e){const i=this.deps.getAdContainer(),n=this.deps.getPlayerContainer();if(!i||!n)return;const r=s(e.format);if(r){if(e.format!==o.LSHAPE_CONTENT){const e=i.style;e.display="none",e.opacity="0",e.position="absolute",e.top="0",e.left="0",e.right="0",e.bottom="0",e.width="",e.height="",e.zIndex="100",e.background="#000",e.transition=t}return((a=e.format)===o.DOUBLE||a===o.LSHAPE_AD||a===o.LSHAPE_CONTENT)&&(n.style.zIndex="101",this.contentLayout=e.format),e.format===o.LSHAPE_AD?n.style.opacity="0":e.format===o.DOUBLE&&(n.style.opacity=""),e.format===o.SINGLE?this.contentLayout&&(n.style.opacity="0"):this.deps.presentationHost.placeContent(r.content),e.format!==o.LSHAPE_CONTENT&&this.deps.presentationHost.placeAd(r.ad),void((e.format===o.DOUBLE||e.format===o.LSHAPE_AD)&&this.renderCompanion(e.assets,"position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;object-fit:cover;width:100%;height:100%;opacity:0;"))}var a;switch(e.format){case o.OVERLAY:{const t=e,s=e=>void 0!==e?100*e+"%":"auto",n=s(t.position.top),o=s(t.position.bottom),r=s(t.position.left),a=s(t.position.right),d=100*t.size.width+"%",p=100*t.size.height+"%",l=t.opacity??1;i.style.cssText=`display:none;position:absolute;top:${n};bottom:${o};left:${r};right:${a};width:${d};height:${p};z-index:100;opacity:${l};`;break}default:i.style.cssText="display:none;position:absolute;top:0;left:0;right:0;bottom:0;z-index:100;background:#000;"}}restoreLayout(){if(this.preparedLease&&!this.preparedLease.isActive())return;const e=this.deps.getPlayerContainer();if(!e)return;this.contentLayout=null,e.style.zIndex="",e.style.opacity="",this.deps.presentationHost.placeContent(i);const t=this.deps.getCompanion();t&&(this.deps.setCompanion(null),this.retireCompanion(t))}renderCompanion(e,t){const s=e[0]?.companion;if(!s)return;const i=s.type===n.STATIC?this.deps.buildStaticAssetUrl(s,this.deps.getCurrentBreak()):null;if(!i)return;const o=document.createElement("img");o.className="dolby-companion",o.src=i,o.style.cssText=t;const r=this.deps.presentationHost.getSurfaces()?.backdrop;r&&this.installCompanion(o,r)}installCompanion(e,t){const s=this.deps.getCompanion();t.appendChild(e),this.deps.setCompanion(e),e.style.opacity="1",s&&s!==e&&this.retireCompanion(s)}retireCompanion(e){e.parentElement?.removeChild(e)}clearOverlayImage(){const e=this.deps.getImageAssetTimer();e&&(clearTimeout(e),this.deps.setImageAssetTimer(null));const t=this.deps.getOverlayImage();t?.parentElement&&t.parentElement.removeChild(t),this.deps.setOverlayImage(null)}show(){const e=this.deps.getAdContainer();if(!e)return;const t=this.deps.getCurrentBreak(),s=t?this.deps.getVariant(t):null;e.style.display="block",s?.format!==o.OVERLAY&&(e.style.opacity="1")}hide(){const e=this.deps.getAdContainer();e&&(e.style.opacity="0",e.style.display="none")}restoreContent(e,t){if(this.deps.presentationHost.cancelPendingTransitions(),this.releasePreparedPresentation())return!0;const s=this.deps.getPlayerContainer();if(!s)return!1;if(e)for(;s.firstChild;)this.deps.container.appendChild(s.firstChild);else this.deps.container.appendChild(s),s.style.cssText=t;return!1}releasePreparedPresentation(){return!!this.preparedLease&&(this.unsubscribeGeometry?.(),this.unsubscribeGeometry=null,this.preparedLease.release(),!0)}destroy(){this.deps.presentationHost.cancelPendingTransitions(),this.unsubscribeGeometry?.(),this.unsubscribeGeometry=null;const e=this.deps.getContentVideo();e&&this.contentVideoGeometryHandler&&(e.removeEventListener("loadedmetadata",this.contentVideoGeometryHandler),e.removeEventListener("resize",this.contentVideoGeometryHandler)),this.contentVideoMutationObserver?.disconnect(),this.resizeObserver?.disconnect(),null!==this.resizePoll&&clearInterval(this.resizePoll),this.resizePoll=null,this.contentVideoMutationObserver=null,this.resizeObserver=null,this.contentVideoGeometryHandler=null,this.contentLayout=null}}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PlayerAdapter } from '../../interfaces/PlayerAdapter';
|
|
2
2
|
import type { AssetUri, Break, VastAsset } from '../../types/BreakManifest';
|
|
3
|
+
import type { StaticAsset } from '../../types/BreakManifest';
|
|
3
4
|
import { AssetParameterMacros } from '../assetParameterMacros';
|
|
4
5
|
import type { GamStreamManager } from '../GamStreamManager';
|
|
5
6
|
import type { AdPlayerState } from './AdPlayerState';
|
|
@@ -29,18 +30,25 @@ export declare class AssetParameterResolver {
|
|
|
29
30
|
/**
|
|
30
31
|
* Substitute the `$` macros in an effective (already layered) parameter map.
|
|
31
32
|
* Precedence per macro name: session macros, then the built-ins; a customer
|
|
32
|
-
* macro returning
|
|
33
|
-
* marks the parameter empty.
|
|
33
|
+
* macro returning an empty value omits the parameter.
|
|
34
34
|
* Every unresolved macro is sent literally and reported as
|
|
35
35
|
* `DA-ASSET-MACRO-UNKNOWN`.
|
|
36
36
|
*/
|
|
37
37
|
private resolveAssetParameterMacros;
|
|
38
|
+
private diagnoseApplied;
|
|
38
39
|
resolveSessionAdTagParameters(): Record<string, string> | undefined;
|
|
40
|
+
resolveSessionAdTagParametersForManifest: (manifestAssetParameters: Record<string, string> | undefined) => Record<string, string> | undefined;
|
|
39
41
|
/**
|
|
40
42
|
* The VAST tag URL with the effective asset parameters appended. Preload and
|
|
41
43
|
* playback both go through here so the two URLs are byte-identical.
|
|
42
44
|
*/
|
|
43
45
|
buildVastTagUrl(asset: VastAsset, breakInfo: Break): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* The request URL of a static asset (media, image, companion, backdrop or pause ad):
|
|
48
|
+
* the application layers and the asset's own parameters, without the manifest
|
|
49
|
+
* session layer. Preload and playback both go through here so the URLs match.
|
|
50
|
+
*/
|
|
51
|
+
buildStaticAssetUrl(asset: StaticAsset, breakInfo: Break | null): string | null;
|
|
44
52
|
/**
|
|
45
53
|
* IMA's `replaceAdTagParameters` replaces the whole map, so every push carries the full
|
|
46
54
|
* effective map. `undefined` falls back to the session baseline (the restore at break end).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isVendorAsset as e}from"../../types/BreakManifest";import{appendQueryParameters as s,applyAssetParameterMacros as t}from"../assetParameterMacros";import{buildAssetParameterMacroTable as a}from"../assetParameterMacroTable";import{objectEntries as r}from"../runtimeObject";import{resolveAssetParameters as i}from"../resolveAssetParameters";import{detectDeviceProfile as o}from"../detectDeviceType";import{resolveTargetedUri as n}from"../resolveTargetedUri";import{
|
|
1
|
+
import{isVendorAsset as e}from"../../types/BreakManifest";import{appendQueryParameters as s,applyAssetParameterMacros as t}from"../assetParameterMacros";import{buildAssetParameterMacroTable as a}from"../assetParameterMacroTable";import{objectEntries as r}from"../runtimeObject";import{resolveAssetParameters as i}from"../resolveAssetParameters";import{detectDeviceProfile as o}from"../detectDeviceType";import{resolveTargetedUri as n}from"../resolveTargetedUri";import{buildStaticAssetUrl as d}from"../staticAssetUrl";import{resolveExternalVendorParameters as m}from"../resolveExternalVendorConfigurations";function c(e,s){if(e&&0===Object.keys(e).length&&(e=void 0),s&&0===Object.keys(s).length&&(s=void 0),e===s)return!0;if(!e||!s)return!1;const t=Object.keys(e);return t.length===Object.keys(s).length&&t.every(t=>e[t]===s[t])}export class AssetParameterResolver{constructor(e,s){this.state=e,this.deps=s,this.resolveSessionAdTagParametersForManifest=e=>{const s=i(this.state.sessionAssetParameters,this.state.updatedAssetParameters,e,void 0);return this.resolveAssetParameterMacros(s,void 0,"session",{breakId:void 0,assetId:void 0})}}setSessionAssetParameters(e){this.state.sessionAssetParameters=e}setManifestAssetParameters(s){if(c(this.state.manifestAssetParameters,s))return;if(this.state.manifestAssetParameters=s,!this.deps.getGamStreamManager()?.isInitialized())return void this.deps.log("Manifest asset parameters stored before GAM initialization");const t=this.state.gamPodAsset;this.pushAssetParameters(t&&e(t)?t.assetParameters:void 0,t?.id),this.deps.diagnose("DA-ASSET-PARAMETERS-UPDATED","Manifest asset parameters changed; IMA targeting updated.",{source:"manifest",keys:Object.keys(s??{}).sort()})}updateAssetParameters(e){this.state.updatedAssetParameters=e,this.deps.getGamStreamManager()?.isInitialized()?this.pushAssetParameters(void 0):this.deps.log("updateAssetParameters: GAM not initialized, stored for VAST only")}updateAssetParameterMacros(e){const s={...this.state.sessionAssetParameterMacros};for(const[t,a]of r(e))void 0===a?delete s[t]:s[t]=a;this.state.sessionAssetParameterMacros=s,this.deps.diagnose("DA-ASSET-PARAMETERS-UPDATED","Asset parameter macros updated.",{source:"macros",keys:Object.keys(e).sort()}),this.deps.getGamStreamManager()?.isInitialized()?this.pushAssetParameters(void 0):this.deps.log("updateAssetParameterMacros: GAM not initialized, stored for VAST only")}setSessionAssetParameterMacros(e){this.state.sessionAssetParameterMacros={...e}}getSessionAssetParameterMacros(){return{...this.state.sessionAssetParameterMacros}}resolveExternalVendorConfiguration(e){const s=m(e,i(this.state.sessionAssetParameters,this.state.updatedAssetParameters,void 0,void 0),a({customerMacros:this.state.sessionAssetParameterMacros,element:this.deps.container,breakDurationSec:void 0}));for(const{key:e,macro:t}of s.unresolved)this.deps.diagnose("DA-ASSET-MACRO-UNKNOWN",`Asset parameter '${e}' sent with literal macro '${t}': the macro has no value.`,{key:e,macro:t});for(const{key:e,macro:t}of s.omitted)this.deps.diagnose("DA-ASSET-PARAMETER-OMITTED",`Asset parameter '${e}' not sent: macro '${t}' is empty.`,{key:e,macro:t});return s.configuration}resolveAssetParameterMacros(e,s,r,i){const o=t(e,a({customerMacros:this.state.sessionAssetParameterMacros,element:this.deps.container,breakDurationSec:"session"===r?void 0:s}));return this.diagnoseApplied(o,i),o.params}diagnoseApplied(e,s){for(const{key:t,macro:a}of e.unresolved)this.deps.diagnose("DA-ASSET-MACRO-UNKNOWN",`Asset parameter '${t}' sent with literal macro '${a}': the macro has no value.`,{...s,key:t,macro:a});for(const{key:t,macro:a,pair:r}of e.omitted)this.deps.diagnose("DA-ASSET-PARAMETER-OMITTED",`Asset parameter '${t}' not sent: macro '${a}' is empty.`,{...s,key:t,macro:a,...void 0!==r?{pair:r}:{}})}resolveSessionAdTagParameters(){return this.resolveSessionAdTagParametersForManifest(this.state.manifestAssetParameters)}buildVastTagUrl(e,t){const a=this.resolveUri(e.uri);if(!a)return null;const r=i(this.state.sessionAssetParameters,this.state.updatedAssetParameters,this.state.manifestAssetParameters,e.assetParameters),o=e.duration??this.deps.getEffectiveBreakDuration()??t.duration,n=this.resolveAssetParameterMacros(r,o,"break",{breakId:t.id,assetId:e.id});return s(a,n)}buildStaticAssetUrl(e,s){const t=this.resolveUri(e.uri);if(!t)return null;const r=e.duration??this.deps.getEffectiveBreakDuration()??s?.duration,i=d(t,{sessionConfigParameters:this.state.sessionAssetParameters,updateParameters:this.state.updatedAssetParameters,assetParameters:e.assetParameters},a({customerMacros:this.state.sessionAssetParameterMacros,element:this.deps.container,breakDurationSec:r}));return this.diagnoseApplied(i.applied,{breakId:s?.id,assetId:e.id}),i.url}pushAssetParameters(e,s){const t=this.deps.getGamStreamManager();if(!t?.isInitialized())return;const a=this.deps.getCurrentBreak(),r=i(this.state.sessionAssetParameters,this.state.updatedAssetParameters,this.state.manifestAssetParameters,e),o=this.resolveAssetParameterMacros(r,this.deps.getEffectiveBreakDuration()??a?.duration,"break",{breakId:a?.id,assetId:s});null!==this.state.pushedAssetParameters&&c(this.state.pushedAssetParameters,o)||(this.state.pushedAssetParameters=o,t.replaceAdTagParameters(o??{}))}resolveUri(e){if(void 0===this.state.detectedDeviceProfile){const e=o();void 0!==this.state.detectedDeviceType?e.deviceType=this.state.detectedDeviceType:this.state.detectedDeviceType=e.deviceType,this.state.detectedDeviceProfile=e}return n(e,this.state.detectedDeviceProfile??this.state.detectedDeviceType,e=>this.deps.diagnose(e.code,`Targeting ${e.field} was rejected.`,{field:e.field,...void 0===e.value?{}:{value:e.value}}))}}
|
|
@@ -15,7 +15,7 @@ export interface AssetPlaybackDeps {
|
|
|
15
15
|
};
|
|
16
16
|
getSequencer: () => AdBreakSequencer | null;
|
|
17
17
|
debug: boolean;
|
|
18
|
-
|
|
18
|
+
buildStaticAssetUrl: (asset: StaticAsset, breakInfo: Break | null) => string | null;
|
|
19
19
|
buildGamUrl: (asset: VendorAsset, breakDuration: number) => Promise<string | null>;
|
|
20
20
|
buildVastTagUrl: (asset: VastAsset, breakInfo: Break) => string | null;
|
|
21
21
|
onAdError: (error: Error) => void;
|
|
@@ -31,6 +31,10 @@ export interface AssetPlaybackDeps {
|
|
|
31
31
|
recordAdProgress: (currentTime: number) => void;
|
|
32
32
|
reportPhase: (name: string) => void;
|
|
33
33
|
armAdStartBudget: (asset: Asset) => void;
|
|
34
|
+
/** The ad queued behind the previous ad: true when it became the current source. */
|
|
35
|
+
takeQueuedSuccessor: (breakId: string, assetId: string, uri: string) => boolean;
|
|
36
|
+
/** Queue the playing break's next ad behind the ad that just started. */
|
|
37
|
+
queueUpcomingAd: () => void;
|
|
34
38
|
remainingAdStartBudgetMs: () => number;
|
|
35
39
|
loadWithinBudget: (startLoad: () => Promise<void>, context: {
|
|
36
40
|
breakId: string;
|
|
@@ -71,7 +75,7 @@ export declare class AssetPlayback {
|
|
|
71
75
|
playVastAsset(asset: VastAsset, index: number, total: number): void;
|
|
72
76
|
playImageAsset(asset: Asset, index: number, total: number): Promise<void>;
|
|
73
77
|
onImageAssetEnded(): void;
|
|
74
|
-
resolveAssetUri(asset: Asset, breakDuration: number): Promise<string | null>;
|
|
78
|
+
resolveAssetUri(asset: Asset, breakDuration: number, breakInfo?: Break | null): Promise<string | null>;
|
|
75
79
|
/**
|
|
76
80
|
* `duration` is Infinity for live and NaN before metadata; both read as zero so the caller
|
|
77
81
|
* does not hold a break open on a guess.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AssetType as e,BreakFormat as t,Vendor as s,MediaType as r,isVastAsset as i}from"../../types/BreakManifest";import{AdError as a}from"../../types/AdError";import{resolveVastAdmission as d}from"../resolveVastAdmission";import{classifyMediaError as n,toClassifiedAdError as o}from"./classifyMediaError";import{VastAdManager as h,isImaCsaiSdkAvailable as p}from"../VastAdManager";import{invalidateMediaPreload as c}from"./AdPlayerState";export class AssetPlayback{constructor(e,t){this.state=e,this.deps=t}get currentBreak(){return this.state.currentBreak}async playAsset(e,t,s){const d=this.currentBreak,n=this.deps.getAdPlayer();if(!d||!n)return;const h=this.state.preparedMedia,p=c(this.state),l=()=>this.state.preloadGeneration===p&&this.currentBreak===d&&this.deps.getAdPlayer()===n;if(this.state.currentAsset=e,this.state.currentAssetElapsedSec=0,this.deps.clearStaticQuartiles(),this.deps.clearOverlayImage(),this.deps.log("Playing asset:",e.id,"type:",e.type,"index:",t),i(e))return void this.playVastAsset(e,t,s);if(e.mediaType===r.IMAGE)return void await this.playImageAsset(e,t,s);const u=await this.resolveAssetUri(e,this.state.effectiveBreakDurationSec??d.duration);if(!l())return;if(!u)return void this.deps.onAdError(this.missingUriError(e));this.deps.log("Resolved URI:",u),this.deps.reportPhase("uri-resolved");const A=d.id;try{this.deps.armAdStartBudget(e);
|
|
1
|
+
import{AssetType as e,BreakFormat as t,Vendor as s,MediaType as r,isVastAsset as i}from"../../types/BreakManifest";import{AdError as a}from"../../types/AdError";import{resolveVastAdmission as d}from"../resolveVastAdmission";import{classifyMediaError as n,toClassifiedAdError as o}from"./classifyMediaError";import{VastAdManager as h,isImaCsaiSdkAvailable as p}from"../VastAdManager";import{invalidateMediaPreload as c}from"./AdPlayerState";export class AssetPlayback{constructor(e,t){this.state=e,this.deps=t}get currentBreak(){return this.state.currentBreak}async playAsset(e,t,s){const d=this.currentBreak,n=this.deps.getAdPlayer();if(!d||!n)return;const h=this.state.preparedMedia,p=c(this.state),l=()=>this.state.preloadGeneration===p&&this.currentBreak===d&&this.deps.getAdPlayer()===n;if(this.state.currentAsset=e,this.state.currentAssetElapsedSec=0,this.deps.clearStaticQuartiles(),this.deps.clearOverlayImage(),this.deps.log("Playing asset:",e.id,"type:",e.type,"index:",t),i(e))return void this.playVastAsset(e,t,s);if(e.mediaType===r.IMAGE)return void await this.playImageAsset(e,t,s);const u=await this.resolveAssetUri(e,this.state.effectiveBreakDurationSec??d.duration);if(!l())return;if(!u)return void this.deps.onAdError(this.missingUriError(e));this.deps.log("Resolved URI:",u),this.deps.reportPhase("uri-resolved");const A=d.id;try{this.deps.armAdStartBudget(e);const r=0===t&&h?.breakId===A&&h.assetId===e.id&&h.uri===u&&h.player===n,i=!r&&this.deps.takeQueuedSuccessor(A,e.id,u);if(i)this.deps.reportPhase("load-skipped-queued");else if(r)this.deps.reportPhase("load-skipped-preloaded");else{if(this.deps.reportPhase("load-start"),!await this.deps.loadWithinBudget(()=>n.load(u),{breakId:A,assetId:e.id,uri:u})||!l())return;this.deps.reportPhase("load-resolved")}this.reportPreparedDuration(n,d,e,t,s);const o=n.videoElement;if(o&&(o.style.cssText="display:block;width:100%;height:100%;object-fit:contain;"),this.deps.reportPhase("play-called"),this.state.firstFrameGateActive&&!this.state.firstFrameGateShown){const e=this.deps.waitForFirstFrame();await this.playRetryingInterruption(n,A),await e}else{let e=null;const t=await Promise.race([this.playRetryingInterruption(n,A).then(()=>!0),new Promise(t=>{e=setTimeout(()=>t(!1),this.deps.remainingAdStartBudgetMs())})]);if(e&&clearTimeout(e),!l())return;if(!t)return void this.deps.onAdError(new a(`Ad did not start within ${this.state.adStartBudgetMs}ms ad-start budget`,"DA-AD-START-TIMEOUT"))}if(!l())return;this.state.adStartDeadlineMs=null,this.state.adStartBudgetMs=0,i&&this.state.startPlaybackCutoff?.(),this.deps.transferPictureInPictureToAd();const p=this.deps.getSequencer();if(p){const t=this.deps.isGamPodAsset(e);t&&this.deps.beginGamPodTracking(e),await this.deps.drive(p.onOutcome({kind:"asset-started"})),!t&&l()&&this.deps.queueUpcomingAd()}else this.state.callbacks?.onAdStart(this.currentBreak,e,t,s)}catch(e){if(!l())return;this.deps.onAdError(o(e))}}reportPreparedDuration(e,t,s,r,i){const a=e.duration;if(!Number.isFinite(a)||a<=0)return;const d=s.duration;this.deps.diagnose("DA-AD-DURATION-PREPARED",`Ad media for break ${t.id} prepared: ${a}s of playable ad`,{breakId:t.id,assetId:s.id,index:r,total:i,preparedDurationSec:a,..."number"==typeof d?{declaredDurationSec:d}:{},breakDurationSec:this.state.effectiveBreakDurationSec??t.duration})}async playRetryingInterruption(e,t){const s=this.state.preloadGeneration;try{await e.play()}catch(r){if(s!==this.state.preloadGeneration||!function(e){return"AbortError"===e?.name}(r)||!this.isStartingBreak(t))throw r;this.deps.diagnose("DA-AD-START-INTERRUPTED","Ad play() was interrupted by a browser-initiated pause before the ad started; play() re-issued once.",{breakId:t,error:r instanceof Error?r.message:String(r)}),this.deps.reportPhase("play-retried"),await e.play()}}isStartingBreak(e){return this.state.isPlaying&&this.state.currentBreak?.id===e}playVastAsset(e,s,r){if(!this.currentBreak||!this.deps.getAdPlayer())return;const i=this.deps.getVariant(this.currentBreak)?.format??t.SINGLE,n=d({format:i,ssai:!1});if(!n.admitted)return this.deps.diagnose(n.diagnostic??"DA-VAST-UNSUPPORTED-FORMAT",`VAST asset '${e.id}' is not supported in '${i}' breaks (single/double/lshape_ad only); skipping.`,{breakId:this.currentBreak.id,assetId:e.id,format:i}),void this.deps.onAdError(new a(`VAST not supported in ${i} format`,n.diagnostic??"DA-VAST-UNSUPPORTED-FORMAT"));if(!p())return this.deps.diagnose("DA-VAST-IMA-SDK-MISSING","Google IMA client-side SDK (ima3.js) is unavailable; cannot play VAST ad.",{breakId:this.currentBreak.id,assetId:e.id}),void this.deps.onAdError(new a("IMA client-side SDK (ima3.js) not available","DA-VAST-IMA-SDK-MISSING"));const o=this.deps.buildVastTagUrl(e,this.currentBreak);if(!o)return void this.deps.onAdError(new a("No valid VAST tag URL for asset","DA-AD-URI-MISSING"));const c=this.deps.getAdPlayer(),l=c?.videoElement,u=this.deps.getAdContainer();if(!u||!l||!c)return void this.deps.onAdError(new a("VAST playout requires an ad container and ad video element","DA-AD-URI-MISSING"));this.deps.revealFirstFrame(),l.style.cssText="display:block;width:100%;height:100%;object-fit:contain;",this.state.vastAdManager||(this.state.vastAdManager=new h(u,l,this.deps.debug)),this.state.vastAdManager.setCallbacks({onAdStarted:t=>{if(!this.currentBreak)return;this.state.startPlaybackCutoff?.(),this.deps.setVastPodPosition(t);const i=this.deps.getSequencer();i?this.deps.drive(i.onOutcome({kind:"asset-started"})):this.state.callbacks?.onAdStart(this.currentBreak,e,s,r,{podPosition:t})},onAdProgress:(t,s)=>{this.currentBreak&&(this.deps.recordAdProgress(t),this.state.callbacks?.onAdTimeUpdate(this.currentBreak,e,t,s))},onAdFirstQuartile:()=>{this.currentBreak&&this.deps.getGamEventCallbacks().onAdFirstQuartile?.(this.currentBreak,e)},onAdMidpoint:()=>{this.currentBreak&&this.deps.getGamEventCallbacks().onAdMidpoint?.(this.currentBreak,e)},onAdThirdQuartile:()=>{this.currentBreak&&this.deps.getGamEventCallbacks().onAdThirdQuartile?.(this.currentBreak,e)}}),this.deps.log("Playing VAST asset via IMA CSAI:",o);(this.state.vastAdManager.hasPreloadedManager()?(this.state.vastAdManager.setMuted(c.muted),this.state.vastAdManager.startPreloaded()):this.state.vastAdManager.playVast(o,{muted:c.muted})).then(()=>{this.deps.onAdEnded()},t=>{const s=t instanceof Error?t.message:String(t),r=/ima3\.js|client-side SDK/i.test(s)?"DA-VAST-IMA-SDK-MISSING":"DA-VAST-IMA-ERROR",i=t instanceof a?t:new a(s,r);this.deps.diagnose(r,s,{...this.currentBreak?{breakId:this.currentBreak.id}:{},assetId:e.id}),this.deps.onAdError(i)})}async playImageAsset(e,t,s){const r=this.currentBreak,i=this.deps.getAdMediaContainer();if(!r||!i)return;const d=this.state.effectiveBreakDurationSec??r.duration,n=await this.resolveAssetUri(e,d);if(!n)return void this.deps.onAdError(this.missingUriError(e));const o=document.createElement("img");o.className="dolby-overlay-image",o.style.cssText="display:block;width:100%;height:100%;object-fit:contain;",this.deps.setOverlayImage(o);const h=e.duration??d;o.onload=()=>{if(this.deps.getOverlayImage()!==o||!this.currentBreak)return;this.state.startPlaybackCutoff?.();const r=this.deps.getSequencer();r?this.deps.drive(r.onOutcome({kind:"asset-started"})):this.state.callbacks?.onAdStart(this.currentBreak,e,t,s),h>0?this.deps.setImageAssetTimer(setTimeout(()=>this.onImageAssetEnded(),1e3*h)):this.onImageAssetEnded()},o.onerror=()=>{this.deps.getOverlayImage()===o&&this.deps.onAdError(new a(`Overlay image failed to load: ${n}`,"DA-IMAGE-LOAD-FAILED"))},o.src=n,i.appendChild(o)}onImageAssetEnded(){const e=this.deps.getSequencer();if(!this.currentBreak||!this.state.isPlaying||!e)return;const t=this.deps.getImageAssetTimer();t&&(clearTimeout(t),this.deps.setImageAssetTimer(null)),this.deps.drive(e.onOutcome({kind:"asset-ended"}))}async resolveAssetUri(t,r,i=this.currentBreak){switch(t.type){case e.STATIC:return this.deps.buildStaticAssetUrl(t,i);case e.VENDOR:{const e=t;return e.vendor===s.GAM?await this.deps.buildGamUrl(e,r):(this.deps.log("Unsupported vendor:",e.vendor),null)}default:return this.deps.log("Unsupported asset type:",t.type),null}}adPlayerStreamRemainingSec(){const e=this.deps.getAdPlayer();if(!e)return 0;const{duration:t,currentTime:s}=e;if(!Number.isFinite(t)||t<=0)return 0;if(!Number.isFinite(s)||s<0)return 0;const r=t-s;return r>0?r:0}revealFirstFrame(){this.deps.revealFirstFrame()}toAdError(e){const t=e,s=n(e);if(t&&("number"==typeof t.code||t.message)){const e="number"==typeof t.code?` (code ${t.code})`:"",r=t.message?`: ${t.message}`:"";return new a(`Ad playback error${e}${r}`,s)}return new a("Ad playback error",s)}missingUriError(e){return this.deps.hasGamIdentityMismatch(e)?new a("GAM pod asset identity does not match the stream session","DA-GAM-POD-IDENTITY-MISMATCH"):new a("No valid URI for asset","DA-AD-URI-MISSING")}}
|
|
@@ -3,7 +3,10 @@ import type { AdPlayerCallbacks, PlayBreakOptions } from '../AdPlayerController'
|
|
|
3
3
|
import type { AdBreakAction, AdBreakStep, AdBreakTransition, EffectiveInsertionMode } from '../AdBreakSequencer';
|
|
4
4
|
import type { GamPodAdStep } from '../GamPodAdTracker';
|
|
5
5
|
import { type AdPlayerState } from './AdPlayerState';
|
|
6
|
+
import type { SuccessorQueue } from './SuccessorQueue';
|
|
6
7
|
export interface BreakSequenceDriverDeps {
|
|
8
|
+
successorQueue: SuccessorQueue;
|
|
9
|
+
getAssets: (breakInfo: Break) => Asset[];
|
|
7
10
|
getChainResolver: () => ((currentBreakId: string) => Break | null) | null;
|
|
8
11
|
getEffectiveInsertionMode: () => EffectiveInsertionMode;
|
|
9
12
|
getVastPodPosition: () => number | undefined;
|
|
@@ -26,8 +29,11 @@ export declare class BreakSequenceDriver {
|
|
|
26
29
|
private readonly state;
|
|
27
30
|
private readonly deps;
|
|
28
31
|
constructor(state: AdPlayerState, deps: BreakSequenceDriverDeps);
|
|
29
|
-
/**
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Emit the transition's ad events (break-level steps are owned elsewhere), then perform its side
|
|
34
|
+
* effect. `late`: the transition answers a successor change while the last ad plays.
|
|
35
|
+
*/
|
|
36
|
+
drive(transition: AdBreakTransition, late?: boolean): Promise<void>;
|
|
31
37
|
/** Map a sequencer step to the matching SDK callback. */
|
|
32
38
|
emitStep(step: AdBreakStep): void;
|
|
33
39
|
/**
|
|
@@ -37,7 +43,7 @@ export declare class BreakSequenceDriver {
|
|
|
37
43
|
*/
|
|
38
44
|
settlePodAdEnd(step: AdBreakStep): boolean;
|
|
39
45
|
/** Perform the side effect a transition asks for (overlay intra-break only). */
|
|
40
|
-
performAction(action: AdBreakAction): Promise<void>;
|
|
46
|
+
performAction(action: AdBreakAction, late?: boolean): Promise<void>;
|
|
41
47
|
emitGamPodSteps(steps: GamPodAdStep[]): void;
|
|
42
48
|
/** Null when no resolver is injected or in shared-element mode (those breaks always hard-end). */
|
|
43
49
|
resolveChainedSuccessor(currentBreakId: string): Break | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invalidateMediaPreload as e}from"./AdPlayerState";export class BreakSequenceDriver{constructor(e,
|
|
1
|
+
import{invalidateMediaPreload as e}from"./AdPlayerState";export class BreakSequenceDriver{constructor(e,s){this.state=e,this.deps=s}async drive(e,s=!1){for(const s of e.noPlayableAsset??[])this.deps.diagnose("DA-BREAK-NO-PLAYABLE-ASSET",`break ${s.breakId} had no playable ad (${s.reason}); it began and ended without an ad.`,{breakId:s.breakId,reason:s.reason,declaredAssetCount:s.declaredAssetCount,...void 0!==s.format?{format:s.format}:{}});const{action:t}=e;"play-asset"===t.kind&&t.index>0&&this.state.currentBreak&&this.deps.successorQueue.confirm(this.state.currentBreak,t.asset);for(const s of e.steps)this.emitStep(s);await this.performAction(t,s)}emitStep(e){if(this.state.currentBreak)switch(e.type){case"adbreakbegin":case"adbreakend":return;case"adbegin":return this.deps.isExpandingPodAsset(e.asset)?void("pending"===this.state.gamPodMode&&(this.state.withheldPodAdBegin=e)):void(void 0!==this.deps.getVastPodPosition()?(this.state.callbacks?.onAdStart(this.state.currentBreak,e.asset,e.adIndex,e.totalAds,{podPosition:this.deps.getVastPodPosition()}),this.deps.setVastPodPosition(void 0)):this.state.callbacks?.onAdStart(this.state.currentBreak,e.asset,e.adIndex,e.totalAds));case"adend":if(this.settlePodAdEnd(e))return;return this.state.callbacks?.onAdEnd(this.state.currentBreak,e.asset,e.adIndex,e.totalAds),void this.deps.resetGamPodTracking();case"aderror":{this.deps.isExpandingPodAsset(e.asset)&&(this.state.withheldPodAdBegin=null,this.state.gamPodTracker?.sawAnyAd&&this.emitGamPodSteps(this.state.gamPodTracker.finish()));const s=this.deps.getPendingAdError()??new Error("Ad playback error");return this.deps.setPendingAdError(null),void this.state.callbacks?.onAdError(this.state.currentBreak,e.asset,s)}}}settlePodAdEnd(e){return!!this.deps.isExpandingPodAsset(e.asset)&&(this.state.gamPodTracker?.sawAnyAd?(this.emitGamPodSteps(this.state.gamPodTracker.finish()),this.deps.resetGamPodTracking(),!0):(this.deps.fallBackToPodLevelReporting(),!1))}async performAction(e,s=!1){switch(e.kind){case"play-asset":return void await this.deps.playAsset(e.asset,e.index,e.total);case"end-break":return void this.deps.endBreak();case"prepare-successor":return void this.deps.successorQueue.prepare(e.break,e.asset,s);case"drop-successor":return void this.deps.successorQueue.drop(e.breakId);default:return}}emitGamPodSteps(e){this.deps.emitGamPodSteps(e)}resolveChainedSuccessor(e){const s=this.deps.getChainResolver();if(!s)return null;if("shared-element"===this.deps.getEffectiveInsertionMode())return null;try{return s(e)}catch(e){return this.deps.log("Chain resolver error:",e),null}}advanceToChainedBreak(s,t){this.deps.log(`Chaining: "${s.id}" -> "${t.id}" (overlay held, content stays paused)`),this.deps.successorQueue.confirm(t,this.deps.getAssets(t)[0]),this.state.currentBreak=null,this.state.effectiveBreakDurationSec=null,e(this.state);const a=this.state.callbacks;a?.onBreakEnd(s),a?.onChainedBreakBegin?.(t),a&&(this.deps.setChaining(!0),this.deps.playBreak(t,a).finally(()=>{this.deps.setChaining(!1)}))}}
|
|
@@ -5,6 +5,7 @@ import { type GamPodAdInfo, type GamPodAdStep } from '../GamPodAdTracker';
|
|
|
5
5
|
import { type GamSessionIdentity } from '../resolveGamVendorConfiguration';
|
|
6
6
|
import type { AdBreakStep } from '../AdBreakSequencer';
|
|
7
7
|
import type { AdPlayerState } from './AdPlayerState';
|
|
8
|
+
import type { AssetParameterResolver } from './AssetParameterResolver';
|
|
8
9
|
export interface GamEventCallbacks {
|
|
9
10
|
onAdFirstQuartile?: (breakInfo: Break, asset: Asset, adIndex?: number, totalAds?: number) => void;
|
|
10
11
|
onAdMidpoint?: (breakInfo: Break, asset: Asset, adIndex?: number, totalAds?: number) => void;
|
|
@@ -33,7 +34,7 @@ export interface GamPodBridgeDeps {
|
|
|
33
34
|
}) => void;
|
|
34
35
|
onAdEnded: () => void;
|
|
35
36
|
pushAssetParameters: (assetParameters: Record<string, string> | undefined, assetId?: string) => void;
|
|
36
|
-
|
|
37
|
+
assetParameterResolver: Pick<AssetParameterResolver, 'resolveSessionAdTagParameters' | 'resolveSessionAdTagParametersForManifest'>;
|
|
37
38
|
diagnose: (code: string, message: string, context?: Record<string, unknown>) => void;
|
|
38
39
|
log: (...args: unknown[]) => void;
|
|
39
40
|
}
|
|
@@ -41,13 +42,22 @@ export interface GamPodBridgeDeps {
|
|
|
41
42
|
export declare class GamPodBridge {
|
|
42
43
|
private readonly state;
|
|
43
44
|
private readonly deps;
|
|
45
|
+
private preparedGamSession;
|
|
46
|
+
private nextGamIdentity;
|
|
44
47
|
constructor(state: AdPlayerState, deps: GamPodBridgeDeps);
|
|
45
48
|
setConfig(config: GamConfig | undefined): void;
|
|
46
49
|
setEventCallbacks(callbacks: GamEventCallbacks): void;
|
|
47
50
|
get eventCallbacks(): GamEventCallbacks;
|
|
48
51
|
startGamSession(identity: GamSessionIdentity, assetParameters?: Record<string, string>): Promise<void>;
|
|
49
52
|
endGamSession(): void;
|
|
53
|
+
prepareNextGamSession(identity: GamSessionIdentity, manifestAssetParameters: Record<string, string> | undefined): Promise<boolean>;
|
|
54
|
+
adoptPreparedGamSession(identity: GamSessionIdentity, sessionAssetParameters: Record<string, string> | undefined, manifestAssetParameters: Record<string, string> | undefined): Promise<boolean>;
|
|
55
|
+
discardPreparedGamSession(): void;
|
|
56
|
+
shouldSkipGamPodPreload(breakInfo: Break): boolean;
|
|
50
57
|
initializeGam(): Promise<void>;
|
|
58
|
+
private createGamStreamManager;
|
|
59
|
+
private createGamStreamConfig;
|
|
60
|
+
private attachGamCallbacks;
|
|
51
61
|
isGamEnabled(): boolean;
|
|
52
62
|
isGamReady(): boolean;
|
|
53
63
|
isGamPodAsset(asset: Asset): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Vendor as t}from"../../types/BreakManifest";import{GamPodAdTracker as e}from"../GamPodAdTracker";import{GAM_DUPLICATE_METADATA_DIAGNOSTIC_MESSAGE as s,GamStreamManager as a}from"../GamStreamManager";import{isGamVendorParameters as i}from"../GamPodUrlBuilder";import{gamPodIdentityMismatches as
|
|
1
|
+
import{Vendor as t}from"../../types/BreakManifest";import{GamPodAdTracker as e}from"../GamPodAdTracker";import{GAM_DUPLICATE_METADATA_DIAGNOSTIC_MESSAGE as s,GamStreamManager as a}from"../GamStreamManager";import{isGamVendorParameters as i}from"../GamPodUrlBuilder";import{gamPodIdentityMismatches as r}from"../resolveGamVendorConfiguration";export class GamPodBridge{constructor(t,e){this.state=t,this.deps=e,this.preparedGamSession=null,this.nextGamIdentity=null,this.identityMismatchAssetId=null,this.midBreakEndPosition=null,this.callbacks={}}setConfig(t){this.state.gamConfig=t}setEventCallbacks(t){this.callbacks=t}get eventCallbacks(){return this.callbacks}async startGamSession(t,e){this.discardPreparedGamSession(),this.state.currentGamIdentity=t,this.state.sessionAssetParameters=e,this.state.pushedAssetParameters=null,await this.initializeGam()}endGamSession(){this.discardPreparedGamSession(),this.state.gamStreamManager?.reset(),this.state.gamInitPromise=null,this.state.currentGamIdentity=void 0,this.state.sessionAssetParameters=void 0,this.state.manifestAssetParameters=void 0,this.state.sessionAssetParameterMacros={},this.state.updatedAssetParameters=void 0,this.state.pushedAssetParameters=null,this.state.earlyGamPodAdStart=null}async prepareNextGamSession(t,e){if(this.preparedGamSession&&this.preparedGamSession.identity.networkCode===t.networkCode&&this.preparedGamSession.identity.customAssetKey===t.customAssetKey)return await this.preparedGamSession.initPromise,this.preparedGamSession?.identity.networkCode===t.networkCode&&this.preparedGamSession.identity.customAssetKey===t.customAssetKey;this.discardPreparedGamSession();const s=this.createGamStreamManager();if(!s)throw new Error("GAM requires an adapter that exposes videoElement.");this.nextGamIdentity=t;const a=s.initialize(this.createGamStreamConfig(t,this.deps.assetParameterResolver.resolveSessionAdTagParametersForManifest(e)));this.preparedGamSession={identity:t,manager:s,initPromise:a};try{return await a,this.preparedGamSession?.manager===s}catch(t){throw this.preparedGamSession?.manager===s&&(s.reset(),this.preparedGamSession=null),t}}async adoptPreparedGamSession(t,e,s){const a=this.preparedGamSession;if(!a||a.identity.networkCode!==t.networkCode||a.identity.customAssetKey!==t.customAssetKey)return this.discardPreparedGamSession(),!1;try{await a.initPromise}catch{return this.discardPreparedGamSession(),!1}if(this.preparedGamSession!==a)return!1;const i=this.state.gamStreamManager;return this.state.gamStreamManager=a.manager,this.state.gamInitPromise=a.initPromise,this.state.currentGamIdentity=t,this.state.sessionAssetParameters=e,this.state.manifestAssetParameters=s,this.state.pushedAssetParameters=null,this.attachGamCallbacks(a.manager),this.preparedGamSession=null,this.nextGamIdentity=null,i&&i!==a.manager&&i.reset(),!0}discardPreparedGamSession(){this.preparedGamSession?.manager.reset(),this.preparedGamSession=null,this.nextGamIdentity=null}shouldSkipGamPodPreload(e){const s=this.nextGamIdentity;if(!s)return!1;return(Array.isArray(e.variant)?e.variant:[e.variant]).some(e=>e.assets.some(e=>"vendor"===e.type&&e.vendor===t.GAM&&i(e.vendorParameters)&&0===r(s,e.vendorParameters).length))}async initializeGam(){if(!this.state.currentGamIdentity)return;if(this.deps.log("Initializing GAM stream manager..."),this.state.gamStreamManager)this.state.gamStreamManager.reset();else if(this.state.gamStreamManager=this.createGamStreamManager(),!this.state.gamStreamManager)return;this.attachGamCallbacks(this.state.gamStreamManager);const t=this.state.currentGamIdentity,e=this.deps.assetParameterResolver.resolveSessionAdTagParameters();this.state.gamInitPromise=this.state.gamStreamManager.initialize(this.createGamStreamConfig(t,e));try{await this.state.gamInitPromise,this.deps.log("GAM stream manager initialized, streamId:",this.state.gamStreamManager.getStreamId())}catch(t){throw this.state.gamInitPromise=null,t}}createGamStreamManager(){const t=this.deps.isSharedElement()?this.deps.contentPlayer.videoElement:this.deps.getAdPlayer()?.videoElement;if(!t)return console.warn("[OptiViewAds] GAM requires an adapter that exposes videoElement. GAM will be skipped."),null;const e=this.deps.isSharedElement()?void 0:this.deps.getAdContainer()||void 0;return new a(t,e,this.deps.debug)}createGamStreamConfig(t,e){return{networkCode:t.networkCode,customAssetKey:t.customAssetKey,...e&&{adTagParameters:e},...this.state.gamConfig?.streamActivityMonitorId&&{streamActivityMonitorId:this.state.gamConfig.streamActivityMonitorId}}}attachGamCallbacks(t){t.setCallbacks({onAdFirstQuartile:()=>this.emitGamQuartile(this.callbacks.onAdFirstQuartile),onAdMidpoint:()=>this.emitGamQuartile(this.callbacks.onAdMidpoint),onAdThirdQuartile:()=>this.emitGamQuartile(this.callbacks.onAdThirdQuartile),onAdStarted:t=>{this.deps.log("GAM ad started"),this.onGamPodAdStarted(t)},onAdComplete:()=>{this.deps.log("GAM ad complete"),"per-ad"===this.state.gamPodMode&&this.state.gamPodTracker&&this.emitGamPodSteps(this.state.gamPodTracker.onAdComplete())},onAdBreakEnded:()=>{this.deps.log("GAM ad break ended");const t=this.deps.getAdPlayerStreamRemainingSec();t>.25?this.onAdBreakEndedWithPodLeft(t):this.deps.onAdEnded()},onError:t=>this.deps.log("GAM error:",t),onDuplicateMetadata:t=>{this.deps.diagnose("DA-GAM-DUPLICATE-METADATA",s,{assetId:this.state.gamPodAsset?.id,startTime:t})}})}isGamEnabled(){return!1!==this.state.gamConfig?.enabled}isGamReady(){return!0===this.state.gamStreamManager?.isInitialized()}isGamPodAsset(e){return"vendor"===e.type&&e.vendor===t.GAM&&this.isGamReady()}isExpandingPodAsset(t){return("pending"===this.state.gamPodMode||"per-ad"===this.state.gamPodMode)&&(!!t&&t.id===this.state.gamPodAsset?.id)}beginGamPodTracking(t){this.resetGamPodTracking(),this.state.gamPodAsset=t,this.state.gamPodTracker=new e(t),this.state.gamPodMode="pending";const s=this.state.earlyGamPodAdStart;this.state.earlyGamPodAdStart=null,s&&this.onGamPodAdStarted(s)}fallBackToPodLevelReporting(){if("pending"!==this.state.gamPodMode)return;this.state.gamPodMode="legacy",this.state.gamPodTracker=null;const t=this.state.withheldPodAdBegin;this.state.withheldPodAdBegin=null,t&&this.deps.emitStep(t)}resetGamPodTracking(){this.state.gamPodMode="none",this.state.gamPodTracker=null,this.state.gamPodAsset=null,this.state.withheldPodAdBegin=null,this.midBreakEndPosition=null}onGamPodAdProgress(t){"pending"===this.state.gamPodMode&&(t<2||(this.deps.log("No IMA pod ad reported after the pod started playing; reporting the pod as a single ad"),this.fallBackToPodLevelReporting()))}onGamPodAdStarted(t){t&&("none"!==this.state.gamPodMode?this.state.gamPodTracker&&("pending"===this.state.gamPodMode&&(this.state.withheldPodAdBegin=null,this.state.gamPodMode="per-ad"),"per-ad"===this.state.gamPodMode&&(this.logRestartedPodPosition(t),this.emitGamPodSteps(this.state.gamPodTracker.onAdStarted(t)))):this.state.earlyGamPodAdStart=t)}logRestartedPodPosition(t){const e=this.midBreakEndPosition;null!==e&&(this.midBreakEndPosition=null,"number"==typeof t.adPosition&&t.adPosition<=e&&this.deps.log(`IMA restarted pod ad positions after a mid-pod ad break end (ad ${t.adPosition} after ad ${e})`))}onAdBreakEndedWithPodLeft(t){const e="per-ad"===this.state.gamPodMode?this.state.gamPodTracker:null;if(!e||e.reportedLastAd)return this.deps.log(`GAM pod has ${t.toFixed(3)}s of slate left; playing it out`),void(e&&this.emitGamPodSteps(e.finish()));const s=e.lastAdPosition,a=e.lastTotalAds,i=a>0?` of ${a}`:"";this.deps.log(`IMA ad break ended after ad ${s}${i}; ${t.toFixed(3)}s of pod left, waiting for the next ad`),this.deps.diagnose("DA-GAM-POD-MID-BREAK-END",`IMA reported the ad break ended after ad ${s}${i} with ${t.toFixed(3)}s of pod left; per-ad reporting continues until the pod ends.`,{assetId:this.state.gamPodAsset?.id,adPosition:s,totalAds:a,remainingSec:t}),this.midBreakEndPosition=s,this.emitGamPodSteps(e.onAdBreakEnded())}emitGamPodSteps(t){const e=this.deps.getCurrentBreak();if(e)for(const s of t){const t={adId:s.adId,creativeId:s.creativeId,podPosition:s.adPosition};"adbegin"===s.type?this.deps.emitAdStart(e,s.asset,s.adIndex,s.totalAds,t):this.deps.emitAdEnd(e,s.asset,s.adIndex,s.totalAds,t)}}emitGamQuartile(t){const e=this.deps.getCurrentBreak();if(!t||!e)return;const s="per-ad"===this.state.gamPodMode?this.state.gamPodTracker?.currentAd:null;if(s)return void t(e,s.asset,s.adIndex,s.totalAds);const a=this.deps.getCurrentAsset();a&&t(e,a)}async buildGamUrl(t,e){if(this.identityMismatchAssetId=null,!i(t.vendorParameters))return this.deps.log("Invalid GAM vendor parameters:",t.vendorParameters),null;if(this.state.gamInitPromise&&await this.state.gamInitPromise,!this.state.gamStreamManager?.isInitialized())throw this.deps.log("GAM stream manager not initialized"),new Error("GAM stream manager not initialized. The stream identity comes from the break manifest's vendorConfiguration — check for DA-GAM-CONFIG-MISSING.");const s=t.vendorParameters;if(this.state.currentGamIdentity){const e=r(this.state.currentGamIdentity,s);for(const s of e)this.deps.diagnose("DA-GAM-POD-IDENTITY-MISMATCH",`GAM asset ${t.id} skipped: vendorParameters.${s.field} "${s.assetValue}" does not match the stream session's "${s.sessionValue}".`,{assetId:t.id,field:s.field,assetValue:s.assetValue,sessionValue:s.sessionValue});if(e.length>0)return this.identityMismatchAssetId=t.id,null}this.state.earlyGamPodAdStart=null,this.deps.pushAssetParameters(t.assetParameters,t.id);const a=this.state.gamStreamManager.buildPodUrl(t.uri,e,s);return this.deps.log("Built GAM pod URL:",a),a}processTimedMetadata(t){this.state.gamStreamManager?.processTimedMetadata(t)}destroy(){this.resetGamPodTracking(),this.state.earlyGamPodAdStart=null,this.state.gamStreamManager?.destroy(),this.state.gamStreamManager=null,this.state.gamInitPromise=null}hasIdentityMismatch(t){return this.identityMismatchAssetId===t.id}}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { PlayerAdapter } from '../../interfaces/PlayerAdapter';
|
|
2
|
-
import
|
|
2
|
+
import { StaticAsset } from '../../types/BreakManifest';
|
|
3
|
+
import type { AssetUri, Break } from '../../types/BreakManifest';
|
|
3
4
|
import type { PauseAdResolution } from '../PauseAdController';
|
|
4
5
|
export interface PauseAdPresenterDeps {
|
|
5
6
|
contentPlayer: PlayerAdapter;
|
|
6
7
|
getStage: () => HTMLElement | null;
|
|
7
8
|
resolveUri: (uri: string | AssetUri[]) => string | null;
|
|
9
|
+
buildStaticAssetUrl: (asset: StaticAsset, breakInfo: Break) => string | null;
|
|
8
10
|
diagnose: (code: string, message: string, context?: Record<string, unknown>) => void;
|
|
9
11
|
log: (...args: unknown[]) => void;
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MediaType as e}from"../../types/BreakManifest";import{AUX_FETCH_TIMEOUT_MS as t,fetchWithTimeout as s}from"../fetchWithTimeout";import{parseVastCompanionImage as i}from"../parseVastCompanion";import{parseVastLinearMediaFile as a}from"../parseVastLinear";import{resolvePauseResumePoint as n}from"../resolvePauseResumePoint";export class PauseAdPresenter{constructor(e){this.deps=e,this.pauseAdContainer=null,this.pauseAdVideoEl=null,this.pauseAdFadeTimer=null,this.pauseAdPinnedPosition=0,this.pauseAdResumeControls=[],this.pauseAdCreativeEndedCallback=null}async showPauseImage(e){const t=this.deps.getStage();if(!t)return;const s=await this.resolvePauseAsset(e);if(!s)return void this.deps.diagnose("DA-PAUSE-AD-NO-ASSET",`Pause ad '${e.break.id}' asset could not be resolved; nothing shown.`,{breakId:e.break.id,source:e.source,mediaType:e.mediaType});this.removePauseAdNow(),this.pauseAdPinnedPosition=this.deps.contentPlayer.currentTime;const i=document.createElement("div");if(i.className="dolby-pause-ad",i.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;z-index:150;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.35);opacity:0;transition:opacity 300ms ease-in-out;"+(s.clickThrough?"cursor:pointer;":""),"video"===s.kind){const e=document.createElement("video");e.className="dolby-pause-ad-video",e.style.cssText="max-width:100%;max-height:100%;object-fit:contain;",e.muted=!0,e.loop=!1,e.autoplay=!0,e.playsInline=!0,e.setAttribute("playsinline",""),e.src=s.url,this.pauseAdVideoEl=e,i.appendChild(e)}else{const e=document.createElement("img");e.className="dolby-pause-ad-image",e.style.cssText="max-width:100%;max-height:100%;object-fit:contain;",e.src=s.url,i.appendChild(e)}if(s.clickThrough){const e=s.clickThrough;i.addEventListener("click",()=>{window.open(e,"_blank","noopener")})}const a=this.buildPauseResumeButton(),n=this.buildPauseCloseButton();if(a.style.display="none",n.style.display="none",this.pauseAdResumeControls=[a,n],i.appendChild(a),i.appendChild(n),this.pauseAdVideoEl){const t=this.pauseAdVideoEl,s=e.break.id,i=()=>{this.pauseAdVideoEl===t&&this.pauseAdCreativeEndedCallback?.(s)};t.addEventListener("ended",i,{once:!0}),t.addEventListener("error",i,{once:!0}),t.play().catch(i)}t.appendChild(i),this.pauseAdContainer=i,requestAnimationFrame(()=>{this.pauseAdContainer===i&&(i.style.opacity="1")}),this.firePauseImpressions(s.impressions),this.deps.log("Pause ad shown:",e.break.id,e.source,e.mediaType)}hidePauseImage(){const e=this.pauseAdContainer;e&&(this.stopPauseAdVideo(),this.pauseAdContainer=null,e.style.opacity="0",this.pauseAdFadeTimer&&clearTimeout(this.pauseAdFadeTimer),this.pauseAdFadeTimer=setTimeout(()=>{e.parentElement&&e.parentElement.removeChild(e),this.pauseAdFadeTimer=null},300))}revealPauseAdResume(){for(const e of this.pauseAdResumeControls)e.style.display=""}setPauseAdCreativeEndedCallback(e){this.pauseAdCreativeEndedCallback=e}destroy(){this.removePauseAdNow()}removePauseAdNow(){this.pauseAdFadeTimer&&(clearTimeout(this.pauseAdFadeTimer),this.pauseAdFadeTimer=null),this.stopPauseAdVideo(),this.pauseAdContainer?.parentElement&&this.pauseAdContainer.parentElement.removeChild(this.pauseAdContainer),this.pauseAdContainer=null}stopPauseAdVideo(){this.pauseAdResumeControls=[];const e=this.pauseAdVideoEl;if(e){try{e.pause(),e.removeAttribute("src")}catch{}this.pauseAdVideoEl=null}}resumeFromPauseAd(){const e=n(this.pauseAdPinnedPosition,this.seekableStart(),this.seekableEnd());null!==e&&(this.deps.diagnose("DA-PAUSE-AD-DVR-EXPIRED",`Pause outlived the DVR window; resuming at the live edge (${e.toFixed(2)}s).`,{pinnedPosition:this.pauseAdPinnedPosition,liveEdge:e}),this.deps.contentPlayer.seek(e)),this.deps.contentPlayer.play()}seekableStart(){const e=this.deps.contentPlayer.videoElement?.seekable;return e&&0!==e.length?e.start(0):Number.NaN}seekableEnd(){const e=this.deps.contentPlayer.videoElement?.seekable;return e&&0!==e.length?e.end(e.length-1):Number.NaN}buildPauseResumeButton(){const e=document.createElement("button");return e.className="dolby-pause-ad-resume",e.setAttribute("aria-label","Resume playback"),e.style.cssText="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:72px;height:72px;border:none;border-radius:50%;cursor:pointer;background:rgba(0,0,0,0.6);display:flex;align-items:center;justify-content:center;",e.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="#fff" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>',e.addEventListener("click",e=>{e.stopPropagation(),this.resumeFromPauseAd()}),e}buildPauseCloseButton(){const e=document.createElement("button");return e.className="dolby-pause-ad-close",e.setAttribute("aria-label","Close pause ad and resume"),e.style.cssText="position:absolute;top:8px;right:8px;width:32px;height:32px;border:none;border-radius:50%;cursor:pointer;background:rgba(0,0,0,0.6);color:#fff;font-size:18px;line-height:32px;text-align:center;padding:0;",e.textContent="✕",e.addEventListener("click",e=>{e.stopPropagation(),this.resumeFromPauseAd()}),e}async resolvePauseAsset(n){const o=n.asset,r=n.mediaType===e.VIDEO?"video":"image";if("static"===n.source){const e=this.deps.
|
|
1
|
+
import{MediaType as e}from"../../types/BreakManifest";import{AUX_FETCH_TIMEOUT_MS as t,fetchWithTimeout as s}from"../fetchWithTimeout";import{parseVastCompanionImage as i}from"../parseVastCompanion";import{parseVastLinearMediaFile as a}from"../parseVastLinear";import{resolvePauseResumePoint as n}from"../resolvePauseResumePoint";export class PauseAdPresenter{constructor(e){this.deps=e,this.pauseAdContainer=null,this.pauseAdVideoEl=null,this.pauseAdFadeTimer=null,this.pauseAdPinnedPosition=0,this.pauseAdResumeControls=[],this.pauseAdCreativeEndedCallback=null}async showPauseImage(e){const t=this.deps.getStage();if(!t)return;const s=await this.resolvePauseAsset(e);if(!s)return void this.deps.diagnose("DA-PAUSE-AD-NO-ASSET",`Pause ad '${e.break.id}' asset could not be resolved; nothing shown.`,{breakId:e.break.id,source:e.source,mediaType:e.mediaType});this.removePauseAdNow(),this.pauseAdPinnedPosition=this.deps.contentPlayer.currentTime;const i=document.createElement("div");if(i.className="dolby-pause-ad",i.style.cssText="position:absolute;top:0;left:0;right:0;bottom:0;z-index:150;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.35);opacity:0;transition:opacity 300ms ease-in-out;"+(s.clickThrough?"cursor:pointer;":""),"video"===s.kind){const e=document.createElement("video");e.className="dolby-pause-ad-video",e.style.cssText="max-width:100%;max-height:100%;object-fit:contain;",e.muted=!0,e.loop=!1,e.autoplay=!0,e.playsInline=!0,e.setAttribute("playsinline",""),e.src=s.url,this.pauseAdVideoEl=e,i.appendChild(e)}else{const e=document.createElement("img");e.className="dolby-pause-ad-image",e.style.cssText="max-width:100%;max-height:100%;object-fit:contain;",e.src=s.url,i.appendChild(e)}if(s.clickThrough){const e=s.clickThrough;i.addEventListener("click",()=>{window.open(e,"_blank","noopener")})}const a=this.buildPauseResumeButton(),n=this.buildPauseCloseButton();if(a.style.display="none",n.style.display="none",this.pauseAdResumeControls=[a,n],i.appendChild(a),i.appendChild(n),this.pauseAdVideoEl){const t=this.pauseAdVideoEl,s=e.break.id,i=()=>{this.pauseAdVideoEl===t&&this.pauseAdCreativeEndedCallback?.(s)};t.addEventListener("ended",i,{once:!0}),t.addEventListener("error",i,{once:!0}),t.play().catch(i)}t.appendChild(i),this.pauseAdContainer=i,requestAnimationFrame(()=>{this.pauseAdContainer===i&&(i.style.opacity="1")}),this.firePauseImpressions(s.impressions),this.deps.log("Pause ad shown:",e.break.id,e.source,e.mediaType)}hidePauseImage(){const e=this.pauseAdContainer;e&&(this.stopPauseAdVideo(),this.pauseAdContainer=null,e.style.opacity="0",this.pauseAdFadeTimer&&clearTimeout(this.pauseAdFadeTimer),this.pauseAdFadeTimer=setTimeout(()=>{e.parentElement&&e.parentElement.removeChild(e),this.pauseAdFadeTimer=null},300))}revealPauseAdResume(){for(const e of this.pauseAdResumeControls)e.style.display=""}setPauseAdCreativeEndedCallback(e){this.pauseAdCreativeEndedCallback=e}destroy(){this.removePauseAdNow()}removePauseAdNow(){this.pauseAdFadeTimer&&(clearTimeout(this.pauseAdFadeTimer),this.pauseAdFadeTimer=null),this.stopPauseAdVideo(),this.pauseAdContainer?.parentElement&&this.pauseAdContainer.parentElement.removeChild(this.pauseAdContainer),this.pauseAdContainer=null}stopPauseAdVideo(){this.pauseAdResumeControls=[];const e=this.pauseAdVideoEl;if(e){try{e.pause(),e.removeAttribute("src")}catch{}this.pauseAdVideoEl=null}}resumeFromPauseAd(){const e=n(this.pauseAdPinnedPosition,this.seekableStart(),this.seekableEnd());null!==e&&(this.deps.diagnose("DA-PAUSE-AD-DVR-EXPIRED",`Pause outlived the DVR window; resuming at the live edge (${e.toFixed(2)}s).`,{pinnedPosition:this.pauseAdPinnedPosition,liveEdge:e}),this.deps.contentPlayer.seek(e)),this.deps.contentPlayer.play()}seekableStart(){const e=this.deps.contentPlayer.videoElement?.seekable;return e&&0!==e.length?e.start(0):Number.NaN}seekableEnd(){const e=this.deps.contentPlayer.videoElement?.seekable;return e&&0!==e.length?e.end(e.length-1):Number.NaN}buildPauseResumeButton(){const e=document.createElement("button");return e.className="dolby-pause-ad-resume",e.setAttribute("aria-label","Resume playback"),e.style.cssText="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:72px;height:72px;border:none;border-radius:50%;cursor:pointer;background:rgba(0,0,0,0.6);display:flex;align-items:center;justify-content:center;",e.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="#fff" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>',e.addEventListener("click",e=>{e.stopPropagation(),this.resumeFromPauseAd()}),e}buildPauseCloseButton(){const e=document.createElement("button");return e.className="dolby-pause-ad-close",e.setAttribute("aria-label","Close pause ad and resume"),e.style.cssText="position:absolute;top:8px;right:8px;width:32px;height:32px;border:none;border-radius:50%;cursor:pointer;background:rgba(0,0,0,0.6);color:#fff;font-size:18px;line-height:32px;text-align:center;padding:0;",e.textContent="✕",e.addEventListener("click",e=>{e.stopPropagation(),this.resumeFromPauseAd()}),e}async resolvePauseAsset(n){const o=n.asset,r=n.mediaType===e.VIDEO?"video":"image";if("static"===n.source){const e=this.deps.buildStaticAssetUrl(o,n.break);if(!e)return null;const t=o.interaction?.clickThrough;return{kind:r,url:e,...t?{clickThrough:t}:{},impressions:[]}}const d=this.deps.resolveUri(o.uri);if(!d)return null;try{const e=await s(d,{},t),n=await e.text();if("video"===r){const e=a(n);if(!e)return null;const t=e.clickThrough??o.interaction?.clickThrough;return{kind:r,url:e.mediaFileUrl,...t?{clickThrough:t}:{},impressions:e.impressions}}const l=i(n);if(!l)return null;const u=l.clickThrough??o.interaction?.clickThrough;return{kind:r,url:l.imageUrl,...u?{clickThrough:u}:{},impressions:l.impressions}}catch(e){return this.deps.log("Pause VAST fetch/parse failed:",e),null}}firePauseImpressions(e){for(const t of e)try{(new Image).src=t}catch{}}}
|