@streamlayer/feature-advertisement 1.1.1-rc.8.pd3aefe41 → 1.2.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/lib/advertisement.d.ts +6 -6
- package/lib/advertisement.js +9 -9
- package/lib/index.d.ts +14 -15
- package/lib/index.js +9 -9
- package/lib/units/external-ad.d.ts +2 -2
- package/lib/units/external-ad.js +3 -3
- package/lib/units/external-pause-ad.js +1 -1
- package/lib/units/gam.js +1 -1
- package/lib/units/pause-ad.d.ts +1 -1
- package/lib/units/pause-ad.js +1 -1
- package/lib/units/sponsor-logo.d.ts +4 -12
- package/lib/units/sponsor-logo.js +3 -4
- package/lib/units/ssai-ad-break.d.ts +1 -1
- package/lib/units/ssai-creative.d.ts +1 -1
- package/lib/units/ssai-creative.js +1 -1
- package/lib/units/ssai-detector.d.ts +1 -1
- package/lib/units/ssai-detector.js +1 -1
- package/lib/units/ssai-preload.d.ts +1 -1
- package/lib/units/ssai-providers.d.ts +1 -1
- package/lib/units/ssai-providers.js +1 -1
- package/lib/units/vast-tracker.d.ts +1 -1
- package/package.json +9 -42
- package/classic/package.json +0 -5
- package/lib/cjs/advertisement.d.ts +0 -64
- package/lib/cjs/advertisement.js +0 -322
- package/lib/cjs/index.d.ts +0 -21
- package/lib/cjs/index.js +0 -41
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/units/ad-macros.d.ts +0 -7
- package/lib/cjs/units/ad-macros.js +0 -91
- package/lib/cjs/units/external-ad.d.ts +0 -127
- package/lib/cjs/units/external-ad.js +0 -421
- package/lib/cjs/units/external-pause-ad.d.ts +0 -50
- package/lib/cjs/units/external-pause-ad.js +0 -259
- package/lib/cjs/units/gam.d.ts +0 -26
- package/lib/cjs/units/gam.js +0 -152
- package/lib/cjs/units/parse-vast-extensions.d.ts +0 -26
- package/lib/cjs/units/parse-vast-extensions.js +0 -56
- package/lib/cjs/units/pause-ad-card.d.ts +0 -49
- package/lib/cjs/units/pause-ad-card.js +0 -136
- package/lib/cjs/units/pause-ad.d.ts +0 -16
- package/lib/cjs/units/pause-ad.js +0 -52
- package/lib/cjs/units/sponsor-logo.d.ts +0 -78
- package/lib/cjs/units/sponsor-logo.js +0 -194
- package/lib/cjs/units/ssai-ad-break.d.ts +0 -21
- package/lib/cjs/units/ssai-ad-break.js +0 -11
- package/lib/cjs/units/ssai-creative.d.ts +0 -89
- package/lib/cjs/units/ssai-creative.js +0 -136
- package/lib/cjs/units/ssai-detector.d.ts +0 -180
- package/lib/cjs/units/ssai-detector.js +0 -1172
- package/lib/cjs/units/ssai-log.d.ts +0 -16
- package/lib/cjs/units/ssai-log.js +0 -23
- package/lib/cjs/units/ssai-preload.d.ts +0 -20
- package/lib/cjs/units/ssai-preload.js +0 -62
- package/lib/cjs/units/ssai-providers.d.ts +0 -117
- package/lib/cjs/units/ssai-providers.js +0 -300
- package/lib/cjs/units/vast-tracker.d.ts +0 -45
- package/lib/cjs/units/vast-tracker.js +0 -64
- package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +0 -71
- package/lib/classic/advertisement.js +0 -348
- package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -77
- package/lib/classic/cjs/advertisement.js +0 -350
- package/lib/classic/cjs/index.js +0 -49
- package/lib/classic/cjs/package.json +0 -1
- package/lib/classic/cjs/units/ad-macros.js +0 -115
- package/lib/classic/cjs/units/external-ad.js +0 -500
- package/lib/classic/cjs/units/external-pause-ad.js +0 -278
- package/lib/classic/cjs/units/gam.js +0 -173
- package/lib/classic/cjs/units/parse-vast-extensions.js +0 -60
- package/lib/classic/cjs/units/pause-ad-card.js +0 -134
- package/lib/classic/cjs/units/pause-ad.js +0 -72
- package/lib/classic/cjs/units/sponsor-logo.js +0 -201
- package/lib/classic/cjs/units/ssai-ad-break.js +0 -11
- package/lib/classic/cjs/units/ssai-creative.js +0 -142
- package/lib/classic/cjs/units/ssai-detector.js +0 -1195
- package/lib/classic/cjs/units/ssai-log.js +0 -23
- package/lib/classic/cjs/units/ssai-preload.js +0 -72
- package/lib/classic/cjs/units/ssai-providers.js +0 -361
- package/lib/classic/cjs/units/vast-tracker.js +0 -81
- package/lib/classic/index.js +0 -29
- package/lib/classic/units/ad-macros.js +0 -113
- package/lib/classic/units/external-ad.js +0 -491
- package/lib/classic/units/external-pause-ad.js +0 -275
- package/lib/classic/units/gam.js +0 -171
- package/lib/classic/units/parse-vast-extensions.js +0 -58
- package/lib/classic/units/pause-ad-card.js +0 -131
- package/lib/classic/units/pause-ad.js +0 -70
- package/lib/classic/units/sponsor-logo.js +0 -197
- package/lib/classic/units/ssai-ad-break.js +0 -9
- package/lib/classic/units/ssai-creative.js +0 -140
- package/lib/classic/units/ssai-detector.js +0 -1192
- package/lib/classic/units/ssai-log.js +0 -21
- package/lib/classic/units/ssai-preload.js +0 -68
- package/lib/classic/units/ssai-providers.js +0 -351
- package/lib/classic/units/vast-tracker.js +0 -77
- package/lib/vast-client.d.ts +0 -9
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var ssaiProviders = require('./ssai-providers.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Per-instance cache + impression-firing wrapper around a SsaiCreativeProvider.
|
|
7
|
-
* Caches resolved creatives by creativeId so repeated active-ad polls and pod
|
|
8
|
-
* repeats don't refetch. In-flight fetches are cancellable via AbortController.
|
|
9
|
-
*/
|
|
10
|
-
class SsaiCreativeCache {
|
|
11
|
-
provider;
|
|
12
|
-
cache = new Map();
|
|
13
|
-
inflight = new Map();
|
|
14
|
-
constructor(provider) {
|
|
15
|
-
this.provider = provider;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* The already-resolved creative, or undefined — synchronous on purpose: a
|
|
19
|
-
* prefetched creative lets the ad break flip straight to 'ready' with no
|
|
20
|
-
* async gap (which the UI would render as a blink between two ads of a pod).
|
|
21
|
-
*/
|
|
22
|
-
peek = (creativeId) => this.cache.get(creativeId);
|
|
23
|
-
resolve = (creativeId) => {
|
|
24
|
-
const cached = this.cache.get(creativeId);
|
|
25
|
-
if (cached) {
|
|
26
|
-
return Promise.resolve(cached);
|
|
27
|
-
}
|
|
28
|
-
const existing = this.inflight.get(creativeId);
|
|
29
|
-
if (existing) {
|
|
30
|
-
return existing.promise;
|
|
31
|
-
}
|
|
32
|
-
const controller = new AbortController();
|
|
33
|
-
const promise = this.provider
|
|
34
|
-
.resolve(creativeId, controller.signal)
|
|
35
|
-
.then((creative) => {
|
|
36
|
-
this.cache.set(creativeId, creative);
|
|
37
|
-
this.inflight.delete(creativeId);
|
|
38
|
-
return creative;
|
|
39
|
-
})
|
|
40
|
-
.catch((error) => {
|
|
41
|
-
this.inflight.delete(creativeId);
|
|
42
|
-
throw error;
|
|
43
|
-
});
|
|
44
|
-
this.inflight.set(creativeId, { promise, controller });
|
|
45
|
-
return promise;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Cancel an in-flight fetch (e.g. the break ended before it resolved).
|
|
49
|
-
*/
|
|
50
|
-
cancel = (creativeId) => {
|
|
51
|
-
const existing = this.inflight.get(creativeId);
|
|
52
|
-
if (existing) {
|
|
53
|
-
existing.controller.abort();
|
|
54
|
-
this.inflight.delete(creativeId);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Fire the impression for a creative. Delegates to the provider's
|
|
59
|
-
* `fireImpression` when present, otherwise the shared default (first
|
|
60
|
-
* trackingEvent named 'impression' via sendBeacon/fetch). Called once per
|
|
61
|
-
* visible appearance of the bar (the UI dedupes the ~250ms active-poll so a
|
|
62
|
-
* single continuous appearance fires exactly one impression). Each genuine pod
|
|
63
|
-
* insertion of the same creative is a distinct impression and re-fires.
|
|
64
|
-
*/
|
|
65
|
-
fireImpression = (creative) => {
|
|
66
|
-
if (this.provider.fireImpression) {
|
|
67
|
-
this.provider.fireImpression(creative);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
ssaiProviders.fireDefaultImpression(creative);
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Fire the impression for an already-resolved creativeId. No-op if the
|
|
74
|
-
* creative isn't cached yet (the bar only renders once resolved, so by the
|
|
75
|
-
* time the UI calls this the creative is present).
|
|
76
|
-
*/
|
|
77
|
-
fireImpressionById = (creativeId) => {
|
|
78
|
-
const creative = this.cache.get(creativeId);
|
|
79
|
-
if (creative) {
|
|
80
|
-
this.fireImpression(creative);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Fire a lifecycle / click beacon. Delegates to the provider's `fireTracking`
|
|
85
|
-
* when it defines one, otherwise fires every matching `trackingEvents` URL.
|
|
86
|
-
*/
|
|
87
|
-
fireTracking = (creative, event) => {
|
|
88
|
-
if (this.provider.fireTracking) {
|
|
89
|
-
this.provider.fireTracking(creative, event);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
ssaiProviders.fireTrackingEvents(creative, event);
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Fire a beacon for a creativeId that may still be resolving.
|
|
96
|
-
*
|
|
97
|
-
* `start` in particular lands the instant the break opens, which is usually
|
|
98
|
-
* BEFORE the metadata request has come back — dropping it would silently lose
|
|
99
|
-
* the first beacon of every ad. Resolution is already in flight by then and
|
|
100
|
-
* `resolve` returns that same promise, so this attaches to it rather than
|
|
101
|
-
* issuing a second request. A creative that never resolves fires nothing,
|
|
102
|
-
* which is the correct outcome: there are no URLs to fire.
|
|
103
|
-
*/
|
|
104
|
-
fireTrackingById = (creativeId, event) => {
|
|
105
|
-
const cached = this.cache.get(creativeId);
|
|
106
|
-
if (cached) {
|
|
107
|
-
this.fireTracking(cached, event);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.resolve(creativeId)
|
|
111
|
-
.then((creative) => this.fireTracking(creative, event))
|
|
112
|
-
.catch(() => undefined);
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Fire the companion's `clickTracking` beacons. Separate from
|
|
116
|
-
* {@link fireTracking} because these live on the companion, not in
|
|
117
|
-
* `trackingEvents` — a provider's `fireTracking` override has no say over them.
|
|
118
|
-
*/
|
|
119
|
-
fireCompanionClickById = (creativeId) => {
|
|
120
|
-
const companion = this.cache.get(creativeId)?.companion;
|
|
121
|
-
if (!companion) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
for (const url of companion.clickTracking) {
|
|
125
|
-
ssaiProviders.fireBeacon(url);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
destroy = () => {
|
|
129
|
-
this.inflight.forEach((entry) => entry.controller.abort());
|
|
130
|
-
this.inflight.clear();
|
|
131
|
-
this.cache.clear();
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
exports.DEFAULT_CREATIVE_API_BASE = ssaiProviders.DEFAULT_CREATIVE_API_BASE;
|
|
136
|
-
exports.SsaiCreativeCache = SsaiCreativeCache;
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import type { SsaiProgressEvent } from './ssai-creative.js';
|
|
2
|
-
export type SsaiDateRange = {
|
|
3
|
-
id: string;
|
|
4
|
-
creativeId: string;
|
|
5
|
-
startMs: number;
|
|
6
|
-
durationSec: number;
|
|
7
|
-
endMs: number;
|
|
8
|
-
/**
|
|
9
|
-
* Exact program times of lifecycle events, when the stream's tracking markers
|
|
10
|
-
* state them (Synamedia dialect). `updateProgress` prefers these over fractions
|
|
11
|
-
* of the window — the markers are the ad server's own quartile schedule, and
|
|
12
|
-
* they stay honest even while the window's end is still provisional.
|
|
13
|
-
*/
|
|
14
|
-
progressAtMs?: Partial<Record<SsaiProgressEvent, number>>;
|
|
15
|
-
};
|
|
16
|
-
/** hls.js `Level`, structurally: `uri` is a string, legacy `url` a string[]. */
|
|
17
|
-
type HlsLikeLevel = {
|
|
18
|
-
uri?: string;
|
|
19
|
-
url?: string | string[];
|
|
20
|
-
} & Record<string, unknown>;
|
|
21
|
-
export type HlsLike = {
|
|
22
|
-
on: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
23
|
-
off: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
24
|
-
media?: HTMLVideoElement | null;
|
|
25
|
-
/**
|
|
26
|
-
* hls.js' level list and level selection, used only to resolve the active
|
|
27
|
-
* media playlist's URL for the supplemental live-edge poll (see
|
|
28
|
-
* `LIVE_EDGE_POLL_MS`). All optional — a minimal host player simply gets no
|
|
29
|
-
* supplement.
|
|
30
|
-
*/
|
|
31
|
-
levels?: HlsLikeLevel[] | null;
|
|
32
|
-
currentLevel?: number;
|
|
33
|
-
loadLevel?: number;
|
|
34
|
-
/**
|
|
35
|
-
* hls.js' own PROGRAM-DATE-TIME of the frame on screen right now. When the host
|
|
36
|
-
* exposes it this is the best answer available — hls.js derives it from the
|
|
37
|
-
* playlist it is actually playing, so it needs no origin of ours and cannot
|
|
38
|
-
* drift as the live window slides.
|
|
39
|
-
*/
|
|
40
|
-
playingDate?: Date | null;
|
|
41
|
-
/**
|
|
42
|
-
* hls.js live-latency diagnostics. Never used for detection — only surfaced by
|
|
43
|
-
* `getDebugSnapshot` so the debug window can cross-check the program clock
|
|
44
|
-
* against the player's own view of how far behind live it is. All optional:
|
|
45
|
-
* a minimal host player (or the e2e stub) simply reports them as unavailable.
|
|
46
|
-
*/
|
|
47
|
-
latency?: number;
|
|
48
|
-
drift?: number;
|
|
49
|
-
liveSyncPosition?: number | null;
|
|
50
|
-
targetLatency?: number | null;
|
|
51
|
-
};
|
|
52
|
-
export type SsaiDetectorOptions = {
|
|
53
|
-
player?: HlsLike;
|
|
54
|
-
videoRef?: HTMLVideoElement;
|
|
55
|
-
manifestUrl?: string;
|
|
56
|
-
/**
|
|
57
|
-
* A creative id was seen in the manifest for the first time — typically
|
|
58
|
-
* seconds before its break starts, since the viewer's playhead trails the
|
|
59
|
-
* live edge. This is the prefetch hook: resolve the creative and warm its
|
|
60
|
-
* artwork here and the bar can show the instant the break begins.
|
|
61
|
-
*/
|
|
62
|
-
onAdDiscovered?: (creativeId: string) => void;
|
|
63
|
-
onBreakStart: (range: SsaiDateRange) => void;
|
|
64
|
-
onCreativeChange: (range: SsaiDateRange) => void;
|
|
65
|
-
/**
|
|
66
|
-
* The active ad's window ends within `AD_ENDING_LEAD_MS`. Fired once per
|
|
67
|
-
* airing while a break is active — the UI's cue to start its closing
|
|
68
|
-
* animation early enough to complete at the boundary. Purely presentational:
|
|
69
|
-
* beacons and break bookkeeping are unaffected.
|
|
70
|
-
*/
|
|
71
|
-
onAdEnding?: (range: SsaiDateRange) => void;
|
|
72
|
-
onBreakEnd: () => void;
|
|
73
|
-
/**
|
|
74
|
-
* Playback reached a lifecycle milestone of the given ad. Fires at most once
|
|
75
|
-
* per event per playthrough, in order, and is INDEPENDENT of whether the
|
|
76
|
-
* overlay is on screen — the ad is stitched into the stream, so it plays (and
|
|
77
|
-
* must be reported) whether or not the viewer dismissed the bar.
|
|
78
|
-
*/
|
|
79
|
-
onProgress?: (range: SsaiDateRange, event: SsaiProgressEvent) => void;
|
|
80
|
-
};
|
|
81
|
-
/** One `X-AD-EVENT-TYPE` marker: an instant in program time, not a window. */
|
|
82
|
-
export type SsaiTrackingMarker = {
|
|
83
|
-
id: string;
|
|
84
|
-
adId: string;
|
|
85
|
-
event: string;
|
|
86
|
-
timeMs: number;
|
|
87
|
-
/** Per-session beacon from `X-AD-URL`, kept for diagnostics. */
|
|
88
|
-
url?: string;
|
|
89
|
-
};
|
|
90
|
-
/** A `com.synamedia.dai.adbreak` range — the whole break, with no ad identity. */
|
|
91
|
-
type SsaiAdBreakWindow = {
|
|
92
|
-
id: string;
|
|
93
|
-
startMs: number;
|
|
94
|
-
endMs: number;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Reconstruct one ad window per AIRING of an `X-AD-ID` from its tracking
|
|
98
|
-
* markers: earliest marker (impression/start) to latest (complete).
|
|
99
|
-
*
|
|
100
|
-
* `breaks` separates re-airings of the same creative (see above) and is the
|
|
101
|
-
* fallback end: until the `complete` marker shows up, an airing whose markers
|
|
102
|
-
* all share one timestamp would fold to a zero-length window and never display;
|
|
103
|
-
* when an enclosing adbreak range covers it, its end is used instead, and the
|
|
104
|
-
* window tightens on the refresh that brings `complete` in.
|
|
105
|
-
*
|
|
106
|
-
* Exported for unit tests only — production code reaches it through the
|
|
107
|
-
* detector.
|
|
108
|
-
*/
|
|
109
|
-
export declare const foldTrackingMarkers: (markers: SsaiTrackingMarker[], breaks: SsaiAdBreakWindow[]) => SsaiDateRange[];
|
|
110
|
-
/** Which source `currentProgramTimeMs()` is answering from right now. */
|
|
111
|
-
export type SsaiClockSource = 'playingDate' | 'pdt-origin' | 'waiting-for-pdt' | 'wall-clock';
|
|
112
|
-
export type SsaiDebugEvent = {
|
|
113
|
-
wallMs: number;
|
|
114
|
-
/** Program time at the moment of the event (NaN while the clock is unmapped). */
|
|
115
|
-
programMs: number;
|
|
116
|
-
type: string;
|
|
117
|
-
detail?: string;
|
|
118
|
-
};
|
|
119
|
-
export type SsaiDebugRange = SsaiDateRange & {
|
|
120
|
-
/** 'daterange' = explicit creative DATERANGE; 'markers' = window folded from tracking markers. */
|
|
121
|
-
source: 'daterange' | 'markers';
|
|
122
|
-
};
|
|
123
|
-
export type SsaiDebugSnapshot = {
|
|
124
|
-
wallMs: number;
|
|
125
|
-
/** Program time of the on-screen frame per the detector's clock (NaN while unmapped). */
|
|
126
|
-
programMs: number;
|
|
127
|
-
clockSource: SsaiClockSource;
|
|
128
|
-
/** How the detector is attached: hls.js events, native manifest polling, or nothing. */
|
|
129
|
-
attachMode: 'hls' | 'manifest-poll' | 'none';
|
|
130
|
-
/** hls.js `playingDate`, NaN when the host doesn't expose it. */
|
|
131
|
-
playingDateMs: number;
|
|
132
|
-
/** The alternate mapping `programTimeOriginMs + video.currentTime` — cross-check against playingDate. */
|
|
133
|
-
pdtOriginProgramMs: number;
|
|
134
|
-
programTimeOriginMs: number;
|
|
135
|
-
hls: {
|
|
136
|
-
latencySec: number;
|
|
137
|
-
driftSec: number;
|
|
138
|
-
liveSyncPositionSec: number;
|
|
139
|
-
targetLatencySec: number;
|
|
140
|
-
} | null;
|
|
141
|
-
video: {
|
|
142
|
-
currentTimeSec: number;
|
|
143
|
-
bufferedEndSec: number;
|
|
144
|
-
seekableEndSec: number;
|
|
145
|
-
paused: boolean;
|
|
146
|
-
playbackRate: number;
|
|
147
|
-
readyState: number;
|
|
148
|
-
} | null;
|
|
149
|
-
/** Every ad window the detector knows, sorted by start. */
|
|
150
|
-
ranges: SsaiDebugRange[];
|
|
151
|
-
markerCount: number;
|
|
152
|
-
adBreakCount: number;
|
|
153
|
-
breakActive: boolean;
|
|
154
|
-
breakSuppressed: boolean;
|
|
155
|
-
activeRangeId: string | null;
|
|
156
|
-
activeCreativeId: string | null;
|
|
157
|
-
progress: {
|
|
158
|
-
rangeId: string;
|
|
159
|
-
creativeId: string;
|
|
160
|
-
fired: SsaiProgressEvent[];
|
|
161
|
-
} | null;
|
|
162
|
-
/** Ring buffer (newest last, capped) of detector edges: discovery, drops, start/end, beacons. */
|
|
163
|
-
events: SsaiDebugEvent[];
|
|
164
|
-
};
|
|
165
|
-
export type SsaiDetector = {
|
|
166
|
-
destroy: () => void;
|
|
167
|
-
/**
|
|
168
|
-
* Mark the currently active break as user-dismissed: the detector keeps
|
|
169
|
-
* tracking it (so it knows when it ends) but stops re-showing the bar on
|
|
170
|
-
* creative changes until the break ends. A subsequent break shows again.
|
|
171
|
-
*/
|
|
172
|
-
dismissActiveBreak: () => void;
|
|
173
|
-
/**
|
|
174
|
-
* Read-only timing introspection for the debug window. Safe to call at any
|
|
175
|
-
* frequency; never affects detection.
|
|
176
|
-
*/
|
|
177
|
-
getDebugSnapshot: () => SsaiDebugSnapshot;
|
|
178
|
-
};
|
|
179
|
-
export declare const createSsaiDetector: (options: SsaiDetectorOptions) => SsaiDetector;
|
|
180
|
-
export {};
|