@dolby-optiview/ads-sdk 1.0.0 → 1.1.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/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @dolby-optiview/ads-sdk
2
+
3
+ Web entry package of the OptiView Ads SDK: server-guided and manifest-driven
4
+ dynamic ad insertion for HLS.js, Shaka Player and THEOplayer, with a bundled
5
+ default ad player (HLS.js, native `<video>` fallback for Safari and iOS).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @dolby-optiview/ads-sdk hls.js
11
+ ```
12
+
13
+ `hls.js` 1.x is a peer dependency. The package depends on
14
+ `@dolby-optiview/ads-sdk-core` and `@dolby-optiview/ads-sdk-adapter-hlsjs`
15
+ and pulls them in automatically.
16
+
17
+ ## Quick start
18
+
19
+ ```typescript
20
+ import Hls from 'hls.js';
21
+ import { OptiViewAds, HlsJsAdapter } from '@dolby-optiview/ads-sdk';
22
+
23
+ const video = document.getElementById('video') as HTMLVideoElement;
24
+ const hls = new Hls();
25
+ hls.attachMedia(video);
26
+
27
+ const sdk = new OptiViewAds({
28
+ player: new HlsJsAdapter(hls, video),
29
+ container: document.getElementById('container')!,
30
+ });
31
+
32
+ sdk.addEventListener('adbreakbegin', (e) => console.log('Ad break started', e.break.id));
33
+ sdk.addEventListener('adbreakend', (e) => console.log('Ad break ended', e.break.id));
34
+
35
+ await sdk.startSession({
36
+ manifestUrl: 'https://manifest.example.com/v1/your-org/channels/your-channel',
37
+ });
38
+ hls.loadSource('https://example.com/content.m3u8');
39
+ video.play();
40
+ ```
41
+
42
+ `container` is the element that anchors the ad overlay; your player UI sits
43
+ inside it. Start one session per channel or piece of content and call
44
+ `sdk.endSession()` on channel change or stop; call `sdk.destroy()` when the
45
+ player is torn down.
46
+
47
+ ## Other content players
48
+
49
+ `OptiViewAds` from this package uses the default ad player. Pass your own
50
+ `createAdAdapter` factory to drive the ads with Shaka Player or THEOplayer
51
+ instead, using `@dolby-optiview/ads-sdk-adapter-shaka` or
52
+ `@dolby-optiview/ads-sdk-adapter-theoplayer`.
53
+
54
+ ## AI assistance
55
+
56
+ The package ships knowledge files and skills for IDE assistants:
57
+
58
+ ```bash
59
+ npx dolby-ads-init-ai # writes ./.dolby-ads/ai
60
+ ```
61
+
62
+ ## Documentation
63
+
64
+ - [OptiView Ads SDK documentation](https://optiview.dolby.com/docs/ads/player-integration/optiview-ads-sdk/)
65
+ - Related packages: `@dolby-optiview/ads-sdk-core`,
66
+ `@dolby-optiview/ads-sdk-adapter-hlsjs`,
67
+ `@dolby-optiview/ads-sdk-adapter-shaka`,
68
+ `@dolby-optiview/ads-sdk-adapter-theoplayer`,
69
+ `@dolby-optiview/ads-sdk-react-native`
70
+
71
+ ## License
72
+
73
+ See <https://optiview.dolby.com/policies/terms-of-service/>.
@@ -23,6 +23,8 @@ of the public contract and are never renamed.
23
23
  | `DA-ANVATO-CUE-MATCHED` | break | info | ptsSource: 'anvatoCue' — a PTS break's start was matched to an observed Anvato cue and scheduled at the cue's media time. |
24
24
  | `DA-ANVATO-CUE-ENTERED` | break | info | ptsSource: 'anvatoCue' — a break was started by the cue reaching the playhead rather than by the scheduler's 250ms tick; context carries the breakId, the cue pts and the media time it fired at, so the two start paths are distinguishable in the field. |
25
25
  | `DA-ANVATO-CUE-OBSERVED` | break | info | ptsSource: 'anvatoCue' — an Anvato break-signaling (type=cue) frame was observed in the stream; context carries the cue's pts, the media time it landed at, whether the tracker recorded it, and the raw payload — so a manifest-PTS vs in-stream-PTS misalignment is observable in the field. |
26
+ | `DA-ANVATO-CUE-SEGMENT-ANCHORED` | break | warn | ptsSource: 'anvatoCue' — an Anvato emsg cue arrived without a ptsOffset from the adapter, so its break is scheduled at the cue's carrying segment start, which can be up to one segment early. Emitted once per session; context: pts, mediaTime. |
27
+ | `DA-ANVATO-CUE-OFFSET-REJECTED` | break | warn | ptsSource: 'anvatoCue' — the adapter's ptsOffset placed an Anvato cue outside its carrying segment's window (more than 0.1s before or 15s after the cue startTime), so the cue's startTime is used instead. Emitted once per cue pts; context: pts, startTime, ptsOffset, mappedTime. |
26
28
  | `DA-PRELOAD-FAILED` | preload | warn | Ad preload failed; the asset will be loaded on demand at break start. |
27
29
  | `DA-PRELOAD-MODE-RESOLVED` | preload | info | The configured ad preload mode was resolved for this session; context carries both the configured and the resolved mode. |
28
30
  | `DA-PRELOAD-PATH` | preload | info | The preload path actually taken for a break's ad (parallel buffer / detached prefetch / none) and the creative container (stream vs progressive). |
@@ -49,6 +51,7 @@ of the public contract and are never renamed.
49
51
  | `DA-GAM-CONFIG-RESOLVED` | gam | info | The GAM stream identity for this session was resolved from the manifest's vendorConfiguration. |
50
52
  | `DA-GAM-CONFIG-MISSING` | gam | error | The break manifest carries no usable "gam" vendorConfiguration entry; GAM assets are skipped. |
51
53
  | `DA-GAM-POD-IDENTITY-MISMATCH` | gam | error | A GAM pod asset's vendorParameters name a different network code or custom asset key than the stream session was created with; the asset is skipped because the pod request cannot serve. |
54
+ | `DA-GAM-POD-MID-BREAK-END` | gam | warn | IMA reported the ad break ended before the pod's last ad while pod stream remains; per-ad reporting continues until the pod ends. |
52
55
  | `DA-VENDOR-CONFIG-UNKNOWN-TYPE` | manifest | info | One or more vendorConfiguration entries declare a type this SDK version does not recognise and were ignored. |
53
56
  | `DA-CONTENT-PLAYBACK-ERROR` | playback | error | The content player reported a playback error. |
54
57
  | `DA-CONTENT-RESUME-STALLED` | playback | warn | Content did not resume within the watchdog window after a break that paused it ended; the SDK re-issued play() once. iOS only for now. |
@@ -56,7 +59,13 @@ of the public contract and are never renamed.
56
59
  | `DA-CONTENT-PIPELINE-RECREATED` | playback | info | The content player's media pipeline was rebuilt at break end before content resumed (recovery mode recreate); context carries breakId, startTime and durationMs. |
57
60
  | `DA-CONTENT-PIPELINE-RECREATE-FAILED` | playback | warn | Rebuilding the content media pipeline at break end failed or timed out — or the adapter does not implement recreateMediaPipeline() (reason 'unsupported-adapter', e.g. a wrapper adapter that does not forward it); the SDK fell back to resuming in place with seek + play; context carries breakId, startTime, reason. |
58
61
  | `DA-AD-PLAYBACK-ERROR` | playback | error | The ad player reported a playback error during a break. |
62
+ | `DA-AD-LOAD-RETRIED` | playback | warn | The ad player's load() had not settled within the retry window of the ad-start budget and the ad element showed no progress (readyState 0, nothing buffered), so a second load() was issued for the same URI; a slow-but-progressing load is not retried. Context carries breakId, assetId, uri, elapsedMs, remainingBudgetMs. A still-stalled retry ends as DA-AD-PLAYBACK-ERROR "Ad load timeout". |
63
+ | `DA-AD-URI-MISSING` | playback | error | The ad asset had no usable media URI, VAST tag URL or render surface; reported as CMCD adec. |
64
+ | `DA-AD-MEDIA-LOAD-FAILED` | playback | error | The ad player could not fetch the ad media (network or HTTP failure); reported as CMCD adec. |
65
+ | `DA-AD-MEDIA-UNSUPPORTED` | playback | error | The ad player could not decode the ad media or does not support its format; reported as CMCD adec. |
66
+ | `DA-AD-START-TIMEOUT` | playback | error | The ad did not load, render a first frame or start within its start budget; reported as CMCD adec. |
59
67
  | `DA-AD-START-INTERRUPTED` | playback | warn | The ad element's play() was interrupted by a browser-initiated pause before the ad started (Chromium AbortError, seen on Samsung Tizen); the SDK re-issued play() once. context: breakId, error. |
68
+ | `DA-AD-DURATION-PREPARED` | playback | info | The ad media for a break was prepared and its real playable duration is now known, BEFORE the first frame. context: breakId, assetId, index, total, preparedDurationSec (the loaded media's own duration — on a GAM pod, the stitched pod's length), declaredDurationSec (what the manifest said about this asset, when it said anything) and breakDurationSec (the slot the break declares). Emitted per asset, so a multi-asset break reports one per asset and the break total is their sum. The three together separate a short break caused by a short POD from one caused by a short request or a late join. |
60
69
  | `DA-DELIVERY-MODE-RESOLVED` | session | info | Delivery mode (sgai/ssai) resolved for the session at start and again on an ads-channel switch from the manifest's delivery rules (or the explicit client config). |
61
70
  | `DA-DELIVERY-MODE-UNKNOWN` | session | warn | The matching delivery rule carried an unrecognized mode value; sgai is used (forward compatibility). |
62
71
  | `DA-DELIVERY-MODE-OVERRIDDEN` | session | info | The manifest's delivery rules resolved a different mode, but the explicit client config takes precedence. |
@@ -72,6 +81,11 @@ of the public contract and are never renamed.
72
81
  | `DA-ASSET-PARAMETER-OMITTED` | break | info | An asset parameter value contained a customer macro that is empty (value `null`), so the parameter was not sent; for GAM `cust_params` only the `&`-separated pair containing the macro was dropped. Raised once per parameter key and macro (per dropped pair for GAM `cust_params`). context: key, macro, pair (GAM `cust_params` only), breakId, assetId. |
73
82
  | `DA-VAST-SSAI-UNSUPPORTED` | session | warn | VAST assets are not supported in SSAI mode (VAST is SGAI-only); the asset was skipped. |
74
83
  | `DA-VAST-IMA-ERROR` | gam | error | Google IMA reported an error while loading or playing a VAST (client-side / CSAI) ad. |
84
+ | `DA-VAST-NO-FILL` | gam | error | The VAST ad server returned no ad (empty response, no ads after wrappers or no assets); reported as CMCD adec. |
85
+ | `DA-VAST-TIMEOUT` | gam | error | The VAST response or its media file did not load in time; reported as CMCD adec. |
86
+ | `DA-VAST-MALFORMED` | gam | error | The VAST response could not be parsed or uses an unsupported VAST version; reported as CMCD adec. |
87
+ | `DA-VAST-REQUEST-FAILED` | gam | error | The VAST ad request failed (network error, invalid tag URL, wrapper error or too many redirects); reported as CMCD adec. |
88
+ | `DA-VAST-CREATIVE-FAILED` | gam | error | The VAST creative could not be played (no compatible media file, playback error or trafficking error); reported as CMCD adec. |
75
89
  | `DA-VAST-IMA-SDK-MISSING` | gam | error | The Google IMA client-side SDK (ima3.js) is unavailable; VAST (CSAI) ads cannot be played. |
76
90
  | `DA-PAUSE-AD-SHOWN` | break | info | A pause ad (full-screen image or video) was shown while content is paused. |
77
91
  | `DA-PAUSE-AD-DISMISSED` | break | info | A pause ad was dismissed (content resumed, or the duration cap elapsed). |
@@ -84,11 +98,16 @@ of the public contract and are never renamed.
84
98
  | `DA-AD-SKIPPED` | playback | info | The viewer skipped the active ad break (controls.skipOffset honored). |
85
99
  | `DA-AD-SKIP-SUPPRESSED` | playback | info | A skip request was suppressed (no skipOffset declared, or requested before the offset). |
86
100
  | `DA-AD-CLICKED` | playback | info | The viewer clicked the ad on screen (adclick emitted). |
101
+ | `DA-LIVE-START-PUSHBACK` | playback | info | Initial live playback requested a backward seek to the configured target-duration distance. Context includes enabledBy (config or ptsSource), targetDurationSec, targetDurationSource, initialOffsetSec, initialOffsetTargetDurations, requestedOffsetSec, requestedOffsetTargetDurations, targetOffsetSec, targetOffsetTargetDurations, rewindSec, rewindTargetDurations, target and windowClamped. This is a request, not proof of the landing. |
102
+ | `DA-LIVE-START-PUSHBACK-SKIPPED` | playback | info | Initial live playback was left unchanged. The reason identifies a disabled adjustment (enabledBy says whether ptsSource or an explicit enabled decided it), an already sufficient offset, missing target duration or seekable range, invalid configuration, or no safe backward target. Available target-duration and offset measurements are included. |
103
+ | `DA-LIVE-START-PUSHBACK-LANDED` | playback | info | Measured initial-live seek landing. Context includes the requested target and targetDurationSec, landed, errorSec, liveEdgeAtLanding, landedOffsetSec and landedOffsetTargetDurations. A timeout or failed seek reports landed=null, never an inferred success. |
87
104
  | `DA-RESUME-SEEK` | playback | info | Content was resume-seeked to the resolved post-break position (insertion type policy). |
105
+ | `DA-RESUME-UNADDRESSABLE` | playback | warn | A break played through the content player (picture-in-picture), so content came back on a reloaded source whose timeline has its own origin, and that source published neither a program-date-time nor a seekable range to re-address the resume point against. Content stays where the reload left it — near the live edge — rather than being seeked to a position that does not exist on the new timeline. Context carries breakId, target (the position on the pre-borrow timeline) and offset. |
88
106
  | `DA-RESUME-LANDED` | playback | info | Where the post-break resume-seek actually landed, measured on the seeked event rather than inferred: context carries breakId, target (the position requested), landed and errorSec (landed - target; negative means the player settled EARLIER than asked). landed is null with a reason when no seeked event arrived, which is normal for a seek to the position the playhead already holds. Report-only: the SDK does not correct the position. |
89
107
  | `DA-RESUME-PREPOSITIONED` | playback | info | The break resumed without a seek: content was moved onto its resume position DURING the break, so the transition needed no jump. Context carries breakId, target, prepositionedTo, landed, shortfallSec and exact. exact=true means it reached the policy target. exact=false means the live window never published those frames, so content was moved as close as exists — the viewer lands short, but arrives already in place rather than via a visible seek at the cut. |
90
108
  | `DA-RESUME-CATCHUP` | playback | info | Content began playing behind the ad to reach its resume point. Context carries breakId, startPos, target, remainingAdSec, publishedEnd and clampedStart — clampedStart true means the stream had not published the ideal start position, so playback began late and the alignment loop must make up the difference (the zero-live-headroom case). Its ABSENCE on a live break that resumed short means catch-up never ran at all, which is a different fault from it running and falling short. |
91
- | `DA-RESUME-TARGET-CLAMPED` | playback | warn | The computed resume position sat inside the engine's minimum live offset and was clamped to the closest position the engine will hold; context carries breakId, requested, clamped and shortfallSec. Distinct from DA-RESUME-OFFSET-CLAMPED, which shortens the OFFSET to the ad seconds actually played. |
109
+ | `DA-RESUME-TARGET-CLAMPED` | playback | warn | The computed resume position sat outside the held live window and was clamped to the nearest end of it; context carries breakId, requested, clamped, shortfallSec and bound — 'end' when the target is ahead of the published edge, 'start' when it is behind the live window start (already evicted) — applied only when the gap is at most half the held window, otherwise DA-RESUME-START-CLAMP-SKIPPED is emitted instead. Distinct from DA-RESUME-OFFSET-CLAMPED, which shortens the OFFSET to the ad seconds actually played. |
110
+ | `DA-RESUME-START-CLAMP-SKIPPED` | playback | info | The resume target sat behind the element's live seekable start by more than half the held window, which cannot be DVR eviction (the element's seekable range disagrees with the adapter timeline); the target was left unchanged and the engine resolved the seek itself. Context carries breakId, requested, seekableStart, behindSec, windowSec and maxBehindSec. |
92
111
  | `DA-RESUME-ALIGN-BLOCKED` | playback | warn | Resume alignment wanted to move content past the live edge and stood down, because no seek can reach media the stream has not published yet; content is left riding the edge and the break-end clamp places it. Context carries target, requested, safeEnd, shortfallSec and remainingSec. Emitted once per break. A persistent shortfall here means the resume target is further ahead than the feed's published edge — typically the player's view of the edge is stale, not that the seek is wrong. |
93
112
  | `DA-CONTINUE-PLAYOUT-BEGIN` | playback | info | continueContentDuringBreak engaged: content keeps PLAYING through the break, hidden and muted, so no resume seek is needed. Context carries breakId, anchor, breakDurationSec and edgeDistanceSec. |
94
113
  | `DA-CONTINUE-PLAYOUT-END` | playback | info | continueContentDuringBreak reached the cut. Context carries driftSec (content position minus where the break says it should be), maxDriftSec, the corrections applied, rateHonoured (false if the engine drove playbackRate itself) and driftUnrecoverable. |
@@ -191,6 +191,32 @@ near zero means the clamp is absorbing it correctly. `landed: null` with a
191
191
  already holds fires no `seeked` event on several engines. The SDK never
192
192
  corrects the landing position.
193
193
 
194
+ ## DA-LIVE-START-PUSHBACK
195
+
196
+ Initial live playback requests a backward seek to five declared target durations behind the
197
+ reported live edge (on by default with `ptsSource: 'anvatoCue'`; an explicit `enabled` wins).
198
+ `enabledBy` (`config` or `ptsSource`) identifies which setting decided it. `targetDurationSec` and `targetDurationSource` identify
199
+ its input. `initialOffsetSec` / `initialOffsetTargetDurations`, `requestedOffsetSec` /
200
+ `requestedOffsetTargetDurations`, and `rewindSec` / `rewindTargetDurations` explain the arithmetic.
201
+ At 3×TD it rewinds 2×TD; at 4×TD it rewinds 1×TD. `windowClamped` indicates insufficient DVR depth.
202
+ This request is not evidence of a successful landing and does not change later break-resume policy.
203
+
204
+ ## DA-LIVE-START-PUSHBACK-SKIPPED
205
+
206
+ `disabled` means the adjustment is off: `enabledBy: ptsSource` for a stream without Anvato cue
207
+ signaling, `config` for an explicit `enabled: false`. `already-behind` means the viewer starts at or
208
+ beyond the minimum distance. `no-target-duration`
209
+ requires a configured `liveStartPushback.targetDurationSeconds` when the adapter cannot provide
210
+ actual declared HLS metadata. `no-range` and `no-backward-target` mean there is no safe backward
211
+ seek. Do not infer TD from average segment length or default player holdback.
212
+
213
+ ## DA-LIVE-START-PUSHBACK-LANDED
214
+
215
+ `landed`, `errorSec`, `landedOffsetSec` and `landedOffsetTargetDurations` measure the seeked event
216
+ against the requested target and current reported live edge. Timeout or failed seeks have
217
+ `landed: null`, not a guessed success. The edge may advance during settlement. Automatic player
218
+ latency correction can later reduce the headroom; this adjustment only runs at initial playback.
219
+
194
220
  ## DA-RESUME-TARGET-CLAMPED
195
221
 
196
222
  **Cause:** The resume position computed for this break sat closer to the live
@@ -209,6 +235,41 @@ resume _offset_ was shortened to the ad seconds actually played. On VOD, and on
209
235
  any engine that does not report a minimum live offset, no clamp is applied at
210
236
  all.
211
237
 
238
+ ## DA-RESUME-UNADDRESSABLE
239
+
240
+ **Cause:** iOS/tvOS, picture-in-picture only. The window presents the content
241
+ player's own layer and nothing else, so the ad has to play **through** that
242
+ player, and content is reloaded onto its own source at the hand-back. A
243
+ reloaded live item starts a **new timeline with its own origin**, so the resume
244
+ position the policy computed — a position on the timeline the break began on —
245
+ addresses nothing on it, and seeking there would leave the window buffering on
246
+ a point the stream does not contain. The SDK therefore needs an address that
247
+ survives the reload: `EXT-X-PROGRAM-DATE-TIME` (exact), or failing that the
248
+ published `seekable.end` plus the lead the pause had over it (approximate to
249
+ about one segment). This code means the reloaded source offered **neither**
250
+ within two seconds, so content was left where the reload put it — near the live
251
+ edge — rather than seeked somewhere that does not exist (`context` carries
252
+ `breakId`, `target` and `offset`). **Fix:** Serve `EXT-X-PROGRAM-DATE-TIME` on
253
+ the content manifest; it removes this case and makes the picture-in-picture
254
+ resume exact instead of approximate. If the stream does carry PDT, the adapter
255
+ is not surfacing it: check that `PlayerAdapter.programDateTime` and
256
+ `PlayerAdapter.seekableEnd` are implemented and answer for the **restored**
257
+ source rather than the one the player was carrying during the break.
258
+
259
+ ## DA-RESUME-START-CLAMP-SKIPPED
260
+
261
+ **Cause:** The resume target sat behind the element's live `seekable.start` by
262
+ more than half the held window (`context` carries `requested`, `seekableStart`,
263
+ `behindSec`, `windowSec`, `maxBehindSec`). A gap that large cannot be DVR
264
+ eviction — it means the element's seekable range disagrees with the adapter's
265
+ timeline, which some engines report on a different epoch. **Fix:** None — the
266
+ SDK left the target unchanged and let the engine resolve the seek itself rather
267
+ than pinning it to a start that is not on the same timeline. If the resume then
268
+ lands wrong, inspect `seekable` versus the adapter's reported position for that
269
+ platform; the engine's timeline mapping is the suspect, not the resume
270
+ arithmetic. The start clamp in `DA-RESUME-TARGET-CLAMPED` only applies inside
271
+ this half-window bound.
272
+
212
273
  ## DA-RESUME-ALIGN-BLOCKED
213
274
 
214
275
  **Cause:** The alignment pass that places content before the cut wanted a
@@ -321,6 +382,26 @@ DA-AD-PLAYOUT-SYNC and probe its final segment's start times to confirm. A
321
382
  single event near the end of a pod is the accumulated total, not an isolated
322
383
  glitch.
323
384
 
385
+ ## DA-AD-DURATION-PREPARED
386
+
387
+ **Cause:** Informational. The ad media for a break is loaded and its real
388
+ playable duration is now known, BEFORE the first ad frame. `context` carries
389
+ `breakId`, `assetId`, `index`, `total`, `preparedDurationSec` (the loaded
390
+ media's own duration — on a GAM pod, the stitched pod's length),
391
+ `declaredDurationSec` (what the manifest said about this asset, when it said
392
+ anything) and `breakDurationSec` (the slot the break declares). Emitted per
393
+ asset, so a multi-asset break reports one per asset and the break total is
394
+ their sum.
395
+
396
+ **Fix:** None — it is the number to plan against. Compare the three: a
397
+ `preparedDurationSec` well under `breakDurationSec` on a GAM pod means the POD
398
+ came up short of the slot, which is an ad-ops question; a short break with a
399
+ full pod is the SDK's or a late join's. Absent on a live or still-loading ad
400
+ source, where the adapter reports no finite duration — deliberately, because a
401
+ guessed number would be read as a measurement. Everything else that names a
402
+ break's real length arrives too late to act on: `adtimeupdate`'s duration comes
403
+ with the first tick, the resume offset and DA-AD-PLAYOUT-SYNC at the end.
404
+
324
405
  ## DA-AD-PLAYOUT-SYNC
325
406
 
326
407
  **Cause:** Informational. Per-break summary of ad playout health, emitted at
@@ -406,6 +487,29 @@ break `start` when a PTS break stays `DA-ANVATO-CUE-PENDING`: a cue that was
406
487
  observed but never matched points at a manifest-PTS vs in-stream-PTS
407
488
  misalignment (must agree within 5 ms).
408
489
 
490
+ ## DA-ANVATO-CUE-SEGMENT-ANCHORED
491
+
492
+ **Cause:** Warning (`ptsSource: 'anvatoCue'`). An Anvato DASH emsg cue
493
+ (`urn:anvato:es1:052016`) arrived without a `ptsOffset` from the content
494
+ adapter. Anvato carries the cue in an emsg v0 with a zero
495
+ `presentation_time_delta`, so players report it at the start of the segment
496
+ that carries it, and the break is scheduled there: up to one segment (e.g. 6s)
497
+ early. Content then resumes the same amount early, showing the end of the slate.
498
+ Emitted once per session; `context` carries `pts` and the `mediaTime` used.
499
+ **Fix:** Use an adapter that supplies `ptsOffset` (THEOplayer web and Android,
500
+ Shaka). A custom adapter sets `ptsOffset` on emsg cues to
501
+ `Period@start - presentationTimeOffset / timescale` from the MPD.
502
+
503
+ ## DA-ANVATO-CUE-OFFSET-REJECTED
504
+
505
+ **Cause:** Warning (`ptsSource: 'anvatoCue'`). The adapter's `ptsOffset` placed
506
+ an Anvato cue more than 0.1s before or 15s after the cue's `startTime`, so the
507
+ SDK ignored it and used the segment-start `startTime`. `context` carries `pts`,
508
+ `startTime`, `ptsOffset` and `mappedTime`. Emitted once per cue `pts`.
509
+ **Fix:** Check that the adapter's offset uses the player's own timeline: the
510
+ player time for media time `t` must be `t + ptsOffset`. A multi-Period MPD or a
511
+ player that counts time from `availabilityStartTime` can produce a wrong offset.
512
+
409
513
  ## DA-PRELOAD-FAILED
410
514
 
411
515
  **Cause:** Preloading the next ad failed; the asset will load on demand at break
@@ -874,6 +978,20 @@ requesting it would only waste the break while the viewer sees nothing.
874
978
  `context.assetValue` with `context.sessionValue` for the named `context.field` and fix
875
979
  the provisioning that produced the disagreement.
876
980
 
981
+ ## DA-GAM-POD-MID-BREAK-END
982
+
983
+ **Cause:** IMA reported `AD_BREAK_ENDED` part-way through a GAM pod, before the pod's last
984
+ ad, while the pod stream still had time left. IMA typically follows it with a new
985
+ `AD_BREAK_STARTED` and keeps playing the remaining ads of the same pod.
986
+
987
+ **Effect:** None for the viewer. The SDK keeps the break open, closes the ad that was
988
+ playing, and keeps reporting every following ad with its own `adbegin`/`adend` until the pod
989
+ stream ends; `adbreakend` fires once, at the real end of the pod.
990
+
991
+ **What to check:** `context.adPosition` and `context.totalAds` name the last ad reported
992
+ before the early end, and `context.remainingSec` the pod left. A recurring hit on one asset
993
+ points at the pod's ad decisioning or IMA rather than the integration.
994
+
877
995
  ## DA-VENDOR-CONFIG-UNKNOWN-TYPE
878
996
 
879
997
  **Cause:** Informational. The manifest carried `vendorConfiguration` entries whose
@@ -1015,7 +1133,9 @@ idempotent and emits no duplicate diagnostic.
1015
1133
  ## DA-AD-PLAYBACK-ERROR
1016
1134
 
1017
1135
  **Cause:** The AD player reported a playback error during a break (`aderror` with
1018
- `source: 'ad'`). The ad asset failed to load/decode. **Fix:** Verify the ad asset
1136
+ `source: 'ad'`). The ad asset failed to load/decode. `context.adErrorCode` carries
1137
+ the specific code reported as CMCD `adec` (for example `DA-AD-MEDIA-LOAD-FAILED`);
1138
+ it stays `DA-AD-PLAYBACK-ERROR` only when the cause is unknown. **Fix:** Verify the ad asset
1019
1139
  URL, format (HLS vs progressive MP4), codecs, and CORS. Check the
1020
1140
  `context.breakId`/`assetId` against the manifest. The SDK recovers and resumes
1021
1141
  content; repeated failures indicate a bad creative or pod URL. Note: with the
@@ -1024,6 +1144,45 @@ creative (URL extension, then `Content-Type`) and routed to native `<video>` or
1024
1144
  HLS.js accordingly — a `manifestParsingError` on an MP4 means a custom
1025
1145
  `createAdAdapter` is force-routing it through HLS.js.
1026
1146
 
1147
+ ## DA-AD-LOAD-RETRIED
1148
+
1149
+ **Cause:** The ad player's `load()` had not settled within the retry window of
1150
+ the ad-start budget (`context.elapsedMs`) and the ad element showed no progress
1151
+ (readyState 0, nothing buffered), so the SDK issued a second `load()` for the
1152
+ same URI. The first attempt was stalling in the browser's media pipeline — the
1153
+ fetch stays open but delivers no data (seen on Safari). A slow-but-progressing
1154
+ load is not retried. **Fix:**
1155
+ Usually none: the retry transparently recovers. If the retried load also
1156
+ stalls, the break ends as `DA-AD-PLAYBACK-ERROR` with "Ad load timeout" —
1157
+ verify the asset URL (see `context.uri`) and CDN reachability from the device.
1158
+ `context.breakId`/`assetId` identify the asset, `remainingBudgetMs` how much
1159
+ ad-start budget was left when the retry fired.
1160
+
1161
+ ## DA-AD-URI-MISSING
1162
+
1163
+ **Cause:** An ad asset had no usable media URI, VAST tag URL, or ad container,
1164
+ so the SDK could not start it. Reported as CMCD `adec` on the `aderror` event.
1165
+ **Fix:** Check the asset in the break manifest (`context.breakId`/`assetId`);
1166
+ for GAM assets, check `vendorParameters`.
1167
+
1168
+ ## DA-AD-MEDIA-LOAD-FAILED
1169
+
1170
+ **Cause:** The ad player could not fetch the ad media (network or HTTP
1171
+ failure). Reported as CMCD `adec`. **Fix:** Check that the ad URL is reachable
1172
+ from the device, returns HTTP 200, and allows CORS. The SDK skips the ad.
1173
+
1174
+ ## DA-AD-MEDIA-UNSUPPORTED
1175
+
1176
+ **Cause:** The ad player could not decode the ad media or does not support its
1177
+ format. Reported as CMCD `adec`. **Fix:** Check the container (HLS vs
1178
+ progressive MP4) and codecs against the target device. The SDK skips the ad.
1179
+
1180
+ ## DA-AD-START-TIMEOUT
1181
+
1182
+ **Cause:** The ad did not load, render a first frame, or start within its start
1183
+ budget. Reported as CMCD `adec`. **Fix:** Check ad media size, CDN latency, and
1184
+ device load; slow first segments are the usual cause.
1185
+
1027
1186
  ## DA-AD-START-INTERRUPTED
1028
1187
 
1029
1188
  **Cause:** A browser-initiated pause interrupted the ad element's pending `play()`
@@ -1090,6 +1249,35 @@ Verify the VAST tag URL is reachable with correct CORS and returns a valid VAST
1090
1249
  document, and confirm the IMA client-side SDK (`ima3.js`) is loaded. Inspect
1091
1250
  `context.message` for the IMA error.
1092
1251
 
1252
+ ## DA-VAST-NO-FILL
1253
+
1254
+ **Cause:** The VAST ad server returned no ad (empty response, no ads after
1255
+ wrappers, or no assets). Reported as CMCD `adec`; `adevc` carries the raw IMA
1256
+ code. **Fix:** This is an ad-server decision: check campaign targeting,
1257
+ inventory, and the ad tag parameters.
1258
+
1259
+ ## DA-VAST-TIMEOUT
1260
+
1261
+ **Cause:** The VAST response or its media file did not load in time. **Fix:**
1262
+ Check ad-server and wrapper latency and the media file size.
1263
+
1264
+ ## DA-VAST-MALFORMED
1265
+
1266
+ **Cause:** The VAST response could not be parsed or uses an unsupported VAST
1267
+ version. **Fix:** Fetch the ad tag URL and validate the returned XML.
1268
+
1269
+ ## DA-VAST-REQUEST-FAILED
1270
+
1271
+ **Cause:** The VAST ad request failed: network error, invalid tag URL, wrapper
1272
+ error, or too many redirects. **Fix:** Check the ad tag URL, CORS, and the
1273
+ wrapper chain.
1274
+
1275
+ ## DA-VAST-CREATIVE-FAILED
1276
+
1277
+ **Cause:** The VAST creative could not be played: no media file matches the
1278
+ player, playback failed, or a trafficking error. **Fix:** Check the MediaFile
1279
+ types, codecs, and dimensions in the VAST response.
1280
+
1093
1281
  ## DA-VAST-IMA-SDK-MISSING
1094
1282
 
1095
1283
  **Cause:** The Google IMA client-side SDK (`ima3.js`) is not available on the
@@ -19,6 +19,8 @@ export declare class NativeVideoAdapter implements PlayerAdapter {
19
19
  private cueScanHandler?;
20
20
  /** Cues already emitted, so the cuechange and scan paths never double-emit. */
21
21
  private emittedCues;
22
+ /** Target duration supplied by the SDK for the live startup distance; null when unknown. */
23
+ private liveStartTargetDuration;
22
24
  constructor(videoElement: HTMLVideoElement);
23
25
  get currentTime(): number;
24
26
  get duration(): number;
@@ -28,6 +30,8 @@ export declare class NativeVideoAdapter implements PlayerAdapter {
28
30
  get volume(): number;
29
31
  set volume(value: number);
30
32
  get videoElement(): HTMLVideoElement;
33
+ /** Content is ready and its initial engine seek has settled. */
34
+ get playbackReady(): boolean;
31
35
  /**
32
36
  * Program Date Time for native HLS playback.
33
37
  *
@@ -43,6 +47,25 @@ export declare class NativeVideoAdapter implements PlayerAdapter {
43
47
  * treats one valid sample as proof the stream carries PDT.
44
48
  */
45
49
  get programDateTime(): Date | null;
50
+ /**
51
+ * The published live edge on WebKit native HLS. WebKit ends `seekable` one hold-back before the
52
+ * newest segment and starts live playback there (measured in Safari: seekable `[0,12]` for a
53
+ * 24s window at TD=4, with media buffered 12s past the seekable end), and exposes no hold-back
54
+ * value, so the HLS minimum of three target durations is added back. A larger `HOLD-BACK` starts
55
+ * further behind than reported; only a low-latency `PART-HOLD-BACK` below 3×TD would start closer.
56
+ *
57
+ * Null off WebKit (`getStartDate()` absent), on VOD, before a seekable range exists, or without
58
+ * a target duration from {@link requestLiveStartOffset}; the SDK then uses the seekable end.
59
+ */
60
+ get liveEdge(): number | null;
61
+ /**
62
+ * Keeps `fallbackTargetDuration` for {@link liveEdge} and returns false: the element can only
63
+ * be placed before its first frame by an absolute start position, which needs the playlist
64
+ * window, so the SDK seeks once playback starts. `null` withdraws the target duration.
65
+ */
66
+ requestLiveStartOffset(targetDurations: number | null, fallbackTargetDuration: number | null): boolean;
67
+ /** WebKit's non-standard `getStartDate()` (unbound); undefined on other engines. */
68
+ private webKitStartDate;
46
69
  /**
47
70
  * The native pipeline is a single decoder per element; buffering the ad
48
71
  * element does not contend with the (separate) content element decoder in the
@@ -1 +1 @@
1
- export class NativeVideoAdapter{constructor(e){this.boundHandlers=new Map,this.eventListeners=new Map,this.cueTracks=[],this.emittedCues=new WeakSet,this.video=e,this.setupVideoListeners(),this.setupMetadataListener()}get currentTime(){return this.video.currentTime}get duration(){return this.video.duration}get paused(){return this.video.paused}get muted(){return this.video.muted}set muted(e){this.video.muted=e}get volume(){return this.video.volume}set volume(e){this.video.volume=e}get videoElement(){return this.video}get programDateTime(){const e=this.video.getStartDate;if("function"!=typeof e)return null;if(this.video.readyState<HTMLMediaElement.HAVE_METADATA)return null;const t=e.call(this.video);return t instanceof Date&&t.getTime()>0?new Date(t.getTime()+1e3*this.video.currentTime):null}get supportsParallelBuffering(){return!0}pause(){this.video.pause()}async play(){await this.video.play()}seek(e){this.video.currentTime=e}get sourceUrl(){return this.video.currentSrc||this.video.src||null}async load(e){return new Promise((t,r)=>{const i=()=>{n(),t()},s=()=>{n(),r(new Error("Native video load error"))},n=()=>{this.video.removeEventListener("loadedmetadata",i),this.video.removeEventListener("error",s)};this.video.addEventListener("loadedmetadata",i),this.video.addEventListener("error",s),this.video.preload="auto",this.video.src=e,this.video.load()})}unload(){this.video.removeAttribute("src"),this.video.load()}recreateMediaPipeline(e){const t=this.sourceUrl;return t?new Promise((r,i)=>{const s=()=>{o(),this.video.currentTime=e.startTime,r()},n=()=>{o(),i(new Error("Native pipeline recreate error"))},o=()=>{this.video.removeEventListener("loadedmetadata",s),this.video.removeEventListener("error",n)};this.video.addEventListener("loadedmetadata",s),this.video.addEventListener("error",n),this.video.removeAttribute("src"),this.video.load(),this.video.src=t,this.video.load()}):Promise.reject(new Error("Native pipeline recreate: no source URL"))}async preload(e){if("undefined"!=typeof document)return new Promise(t=>{const r=document.createElement("video");r.preload="metadata",r.muted=!0;let i=!1;const s=()=>{i||(i=!0,clearTimeout(n),r.removeAttribute("src"),r.load(),t())},n=setTimeout(s,8e3);r.addEventListener("loadedmetadata",s,{once:!0}),r.addEventListener("error",s,{once:!0}),r.src=e})}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t)}off(e,t){this.eventListeners.get(e)?.delete(t)}destroy(){for(const[e,t]of this.boundHandlers)this.video.removeEventListener(e,t);this.boundHandlers.clear(),this.teardownMetadataListener(),this.eventListeners.clear()}setupMetadataListener(){const e=this.video.textTracks;if(!e||"function"!=typeof e.addEventListener)return;const t=e=>{this.emittedCues.has(e)||(this.emittedCues.add(e),this.emit("timedmetadata",this.toCue(e)))},r=e=>{const r=e.cues;if(r)for(let e=0;e<r.length;e++)t(r[e])},i=e=>{if("metadata"!==e.kind)return;e.mode="hidden";const i=()=>{const r=e.activeCues;if(r)for(let e=0;e<r.length;e++)t(r[e])};e.addEventListener("cuechange",i),this.cueTracks.push({track:e,handler:i}),r(e)},s=e=>{const t=e.track;t&&i(t)};this.addTrackHandler=s,e.addEventListener("addtrack",s);const n=()=>{for(const{track:e}of this.cueTracks)r(e)};this.cueScanHandler=n,this.video.addEventListener("timeupdate",n);for(let t=0;t<e.length;t++)i(e[t])}teardownMetadataListener(){const e=this.video.textTracks;this.addTrackHandler&&e?.removeEventListener&&(e.removeEventListener("addtrack",this.addTrackHandler),this.addTrackHandler=void 0),this.cueScanHandler&&(this.video.removeEventListener("timeupdate",this.cueScanHandler),this.cueScanHandler=void 0);for(const{track:e,handler:t}of this.cueTracks)e.removeEventListener("cuechange",t);this.cueTracks=[],this.emittedCues=new WeakSet}toCue(e){const t={type:"id3",startTime:e.startTime,endTime:e.endTime},r=e.value;if(r?.key){const e="string"==typeof(i=r.data)?i:null==i?"":"[object ArrayBuffer]"===Object.prototype.toString.call(i)?(new TextDecoder).decode(new Uint8Array(i)):ArrayBuffer.isView(i)?(new TextDecoder).decode(new Uint8Array(i.buffer,i.byteOffset,i.byteLength)):String(i);t.frames={[r.key]:e},"string"==typeof r.info&&r.info&&(t.description=r.info),e&&(t.messageData=e)}var i;return t}setupVideoListeners(){const e=["timeupdate","ended","error","seeked","volumechange","waiting","playing","pause"];for(const t of e){const e=()=>{this.emit(t,"error"===t?this.video.error:void 0)};this.video.addEventListener(t,e),this.boundHandlers.set(t,e)}}emit(e,t){const r=this.eventListeners.get(e);if(r)for(const e of r)try{e(t)}catch(e){console.error("[NativeVideoAdapter] Event handler error:",e)}}}
1
+ export class NativeVideoAdapter{constructor(e){this.boundHandlers=new Map,this.eventListeners=new Map,this.cueTracks=[],this.emittedCues=new WeakSet,this.liveStartTargetDuration=null,this.video=e,this.setupVideoListeners(),this.setupMetadataListener()}get currentTime(){return this.video.currentTime}get duration(){return this.video.duration}get paused(){return this.video.paused}get muted(){return this.video.muted}set muted(e){this.video.muted=e}get volume(){return this.video.volume}set volume(e){this.video.volume=e}get videoElement(){return this.video}get playbackReady(){return this.video.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&!this.video.seeking}get programDateTime(){const e=this.webKitStartDate();if(!e)return null;if(this.video.readyState<HTMLMediaElement.HAVE_METADATA)return null;const t=e.call(this.video);return t instanceof Date&&t.getTime()>0?new Date(t.getTime()+1e3*this.video.currentTime):null}get liveEdge(){const e=this.liveStartTargetDuration,t=this.video.seekable;if(null===e||!this.webKitStartDate()||this.video.duration!==1/0||!t?.length)return null;const i=t.end(t.length-1);return Number.isFinite(i)?i+3*e:null}requestLiveStartOffset(e,t){const i=t;return this.liveStartTargetDuration=null!==e&&null!==i&&Number.isFinite(i)&&i>0?i:null,!1}webKitStartDate(){const e=this.video.getStartDate;return"function"==typeof e?e:void 0}get supportsParallelBuffering(){return!0}pause(){this.video.pause()}async play(){await this.video.play()}seek(e){this.video.currentTime=e}get sourceUrl(){return this.video.currentSrc||this.video.src||null}async load(e){return new Promise((t,i)=>{const r=()=>{n(),t()},s=()=>{n(),i(new Error("Native video load error"))},n=()=>{this.video.removeEventListener("loadedmetadata",r),this.video.removeEventListener("error",s)};this.video.addEventListener("loadedmetadata",r),this.video.addEventListener("error",s),this.video.preload="auto",this.video.src=e,this.video.load()})}unload(){this.video.removeAttribute("src"),this.video.load()}recreateMediaPipeline(e){const t=this.sourceUrl;return t?new Promise((i,r)=>{const s=()=>{a(),this.video.currentTime=e.startTime,i()},n=()=>{a(),r(new Error("Native pipeline recreate error"))},a=()=>{this.video.removeEventListener("loadedmetadata",s),this.video.removeEventListener("error",n)};this.video.addEventListener("loadedmetadata",s),this.video.addEventListener("error",n),this.video.removeAttribute("src"),this.video.load(),this.video.src=t,this.video.load()}):Promise.reject(new Error("Native pipeline recreate: no source URL"))}async preload(e){if("undefined"!=typeof document)return new Promise(t=>{const i=document.createElement("video");i.preload="metadata",i.muted=!0;let r=!1;const s=()=>{r||(r=!0,clearTimeout(n),i.removeAttribute("src"),i.load(),t())},n=setTimeout(s,8e3);i.addEventListener("loadedmetadata",s,{once:!0}),i.addEventListener("error",s,{once:!0}),i.src=e})}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t)}off(e,t){this.eventListeners.get(e)?.delete(t)}destroy(){for(const[e,t]of this.boundHandlers)this.video.removeEventListener(e,t);this.boundHandlers.clear(),this.teardownMetadataListener(),this.eventListeners.clear()}setupMetadataListener(){const e=this.video.textTracks;if(!e||"function"!=typeof e.addEventListener)return;const t=e=>{this.emittedCues.has(e)||(this.emittedCues.add(e),this.emit("timedmetadata",this.toCue(e)))},i=e=>{const i=e.cues;if(i)for(let e=0;e<i.length;e++)t(i[e])},r=e=>{if("metadata"!==e.kind)return;e.mode="hidden";const r=()=>{const i=e.activeCues;if(i)for(let e=0;e<i.length;e++)t(i[e])};e.addEventListener("cuechange",r),this.cueTracks.push({track:e,handler:r}),i(e)},s=e=>{const t=e.track;t&&r(t)};this.addTrackHandler=s,e.addEventListener("addtrack",s);const n=()=>{for(const{track:e}of this.cueTracks)i(e)};this.cueScanHandler=n,this.video.addEventListener("timeupdate",n);for(let t=0;t<e.length;t++)r(e[t])}teardownMetadataListener(){const e=this.video.textTracks;this.addTrackHandler&&e?.removeEventListener&&(e.removeEventListener("addtrack",this.addTrackHandler),this.addTrackHandler=void 0),this.cueScanHandler&&(this.video.removeEventListener("timeupdate",this.cueScanHandler),this.cueScanHandler=void 0);for(const{track:e,handler:t}of this.cueTracks)e.removeEventListener("cuechange",t);this.cueTracks=[],this.emittedCues=new WeakSet}toCue(e){const t={type:"id3",startTime:e.startTime,endTime:e.endTime},i=e.value;if(i?.key){const e="string"==typeof(r=i.data)?r:null==r?"":"[object ArrayBuffer]"===Object.prototype.toString.call(r)?(new TextDecoder).decode(new Uint8Array(r)):ArrayBuffer.isView(r)?(new TextDecoder).decode(new Uint8Array(r.buffer,r.byteOffset,r.byteLength)):String(r);t.frames={[i.key]:e},"string"==typeof i.info&&i.info&&(t.description=i.info),e&&(t.messageData=e)}var r;return t}setupVideoListeners(){const e=["timeupdate","ended","error","seeked","volumechange","waiting","playing","pause"];for(const t of e){const e=()=>{this.emit(t,"error"===t?this.video.error:void 0)};this.video.addEventListener(t,e),this.boundHandlers.set(t,e)}}emit(e,t){const i=this.eventListeners.get(e);if(i)for(const e of i)try{e(t)}catch(e){console.error("[NativeVideoAdapter] Event handler error:",e)}}}
@@ -57,6 +57,13 @@ export declare class RoutingAdAdapter implements PlayerAdapter {
57
57
  * `PlayerAdapter.unload`).
58
58
  */
59
59
  unload(): void;
60
+ /**
61
+ * Hand a borrowed content element back (shared-element insertion) without emptying it: the
62
+ * content engine's own `load()` replaces the ad media in one step, so the element never sits
63
+ * without a resource — which is when Safari closes the picture-in-picture window. Registered
64
+ * event handlers are kept, as with `unload()`.
65
+ */
66
+ releaseMediaElement(): void;
60
67
  destroy(): void;
61
68
  /**
62
69
  * Return the inner adapter for `tech`, (re)building it if absent or if a
@@ -1 +1 @@
1
- import e from"hls.js";import{HlsJsAdapter as t}from"@dolby-optiview/ads-sdk-adapter-hlsjs";import{NativeVideoAdapter as i}from"./NativeVideoAdapter";import{selectAdTech as n}from"./selectAdTech";export class RoutingAdAdapter{constructor(t,i=e.isSupported()){this.inner=null,this.currentTech=null,this.ownedSrc=null,this.hls=null,this.eventListeners=new Map,this.video=t,this.hlsSupported=i}get currentTime(){return this.inner?this.inner.currentTime:this.video.currentTime}get duration(){return this.inner?this.inner.duration:this.video.duration}get paused(){return this.inner?this.inner.paused:this.video.paused}get muted(){return this.video.muted}set muted(e){this.video.muted=e}get volume(){return this.video.volume}set volume(e){this.video.volume=e}get programDateTime(){return this.inner?this.inner.programDateTime:null}get videoElement(){return this.video}get supportsParallelBuffering(){return this.inner?.supportsParallelBuffering??this.hlsSupported}pause(){this.inner?this.inner.pause():this.video.pause()}async play(){if(this.inner)return this.inner.play();await this.video.play()}seek(e){this.inner?this.inner.seek(e):this.video.currentTime=e}load(e){const t=n(e),i=t=>{const i=this.ensureInner(t).load(e);return this.ownedSrc=this.video.getAttribute("src"),i};return"string"==typeof t?i(t):t.then(i)}preload(e){const t=n(e),i=t=>{const i=this.ensureInner(t);return i.preload?i.preload(e):Promise.resolve()};return"string"==typeof t?i(t):t.then(i)}on(e,t){let i=this.eventListeners.get(e);i||(i=new Set,this.eventListeners.set(e,i)),i.add(t),this.inner?.on(e,t)}off(e,t){this.eventListeners.get(e)?.delete(t),this.inner?.off(e,t)}unload(){this.teardownInner()}destroy(){this.teardownInner(),this.eventListeners.clear()}ensureInner(e){const t=this.hlsSupported?e:"native";if(this.inner&&this.currentTech===t)return this.inner;this.teardownInner(),this.inner=this.buildInner(t),this.currentTech=t;for(const[e,t]of this.eventListeners)for(const i of t)this.inner.on(e,i);return this.inner}buildInner(n){return"native"===n?new i(this.video):(this.hls=new e,new t(this.hls,this.video))}teardownInner(){if(this.inner?.destroy(),this.hls){try{this.hls.destroy()}catch{}this.hls=null}const e=this.video.getAttribute("src");e&&e!==this.ownedSrc||(this.video.removeAttribute("src"),"native"!==this.currentTech||null===this.ownedSrc||this.video.srcObject||this.video.load()),this.ownedSrc=null,this.inner=null,this.currentTech=null}}
1
+ import e from"hls.js";import{HlsJsAdapter as t}from"@dolby-optiview/ads-sdk-adapter-hlsjs";import{NativeVideoAdapter as i}from"./NativeVideoAdapter";import{selectAdTech as r}from"./selectAdTech";export class RoutingAdAdapter{constructor(t,i=e.isSupported()){this.inner=null,this.currentTech=null,this.ownedSrc=null,this.hls=null,this.eventListeners=new Map,this.video=t,this.hlsSupported=i}get currentTime(){return this.inner?this.inner.currentTime:this.video.currentTime}get duration(){return this.inner?this.inner.duration:this.video.duration}get paused(){return this.inner?this.inner.paused:this.video.paused}get muted(){return this.video.muted}set muted(e){this.video.muted=e}get volume(){return this.video.volume}set volume(e){this.video.volume=e}get programDateTime(){return this.inner?this.inner.programDateTime:null}get videoElement(){return this.video}get supportsParallelBuffering(){return this.inner?.supportsParallelBuffering??this.hlsSupported}pause(){this.inner?this.inner.pause():this.video.pause()}async play(){if(this.inner)return this.inner.play();await this.video.play()}seek(e){this.inner?this.inner.seek(e):this.video.currentTime=e}load(e){const t=r(e),i=t=>{const i=this.ensureInner(t).load(e);return this.ownedSrc=this.video.getAttribute("src"),i};return"string"==typeof t?i(t):t.then(i)}preload(e){const t=r(e),i=t=>{const i=this.ensureInner(t);return i.preload?i.preload(e):Promise.resolve()};return"string"==typeof t?i(t):t.then(i)}on(e,t){let i=this.eventListeners.get(e);i||(i=new Set,this.eventListeners.set(e,i)),i.add(t),this.inner?.on(e,t)}off(e,t){this.eventListeners.get(e)?.delete(t),this.inner?.off(e,t)}unload(){this.teardownInner()}releaseMediaElement(){if(this.inner){if(this.inner.destroy(),this.hls){try{this.hls.stopLoad()}catch{}this.video.getAttribute("src")===this.ownedSrc&&this.video.removeAttribute("src");for(const e of Array.from(this.video.querySelectorAll("source")))e.remove();try{this.hls.destroy()}catch{}this.hls=null}this.ownedSrc=null,this.inner=null,this.currentTech=null}}destroy(){this.teardownInner(),this.eventListeners.clear()}ensureInner(e){const t=this.hlsSupported?e:"native";if(this.inner&&this.currentTech===t)return this.inner;this.teardownInner(),this.inner=this.buildInner(t),this.currentTech=t;for(const[e,t]of this.eventListeners)for(const i of t)this.inner.on(e,i);return this.inner}buildInner(r){return"native"===r?new i(this.video):(this.hls=new e,new t(this.hls,this.video))}teardownInner(){if(this.inner?.destroy(),this.hls){const e=this.video.getAttribute("src");if(e&&e!==this.ownedSrc)for(const e of Array.from(this.video.querySelectorAll("source")))e.remove();try{this.hls.destroy()}catch{}this.hls=null}const e=this.video.getAttribute("src");e&&e!==this.ownedSrc||(this.video.removeAttribute("src"),"native"!==this.currentTech||null===this.ownedSrc||this.video.srcObject||this.video.load()),this.ownedSrc=null,this.inner=null,this.currentTech=null}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolby-optiview/ads-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "OptiView Ads SDK entry package - OptiViewAds with a default HLS.js ad player (native fallback)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "sideEffects": false,
46
46
  "dependencies": {
47
- "@dolby-optiview/ads-sdk-adapter-hlsjs": "^1.0.0",
48
- "@dolby-optiview/ads-sdk-core": "^1.0.0"
47
+ "@dolby-optiview/ads-sdk-adapter-hlsjs": "^1.1.0",
48
+ "@dolby-optiview/ads-sdk-core": "^1.1.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "hls.js": "^1.0.0"