@mattebox/player-ads 1.0.0 → 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/dist/ad-info.js.map +1 -1
- package/dist/ad-link.js.map +1 -1
- package/dist/ad-progress.js.map +1 -1
- package/dist/ad-skip-button.js.map +1 -1
- package/dist/beacons.js.map +1 -1
- package/dist/cdn/mattebox-player-ads.min.js +1 -1
- package/dist/component.js +2 -2
- package/dist/component.js.map +1 -1
- package/dist/controller.d.ts +22 -0
- package/dist/controller.d.ts.map +1 -1
- package/dist/controller.js +48 -17
- package/dist/controller.js.map +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/component.js +2 -2
- package/dist/es2015/controller.js +49 -21
- package/dist/es2015/index.js +4 -3
- package/dist/es2015/shared.js +1 -1
- package/dist/es2015/vast.js +2 -2
- package/dist/host.d.ts +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/shared.js +1 -1
- package/dist/shared.js.map +1 -1
- package/package.json +3 -3
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/toPrimitive.js +0 -13
package/dist/controller.js
CHANGED
|
@@ -66,6 +66,10 @@ var Controller = class {
|
|
|
66
66
|
this.own = /* @__PURE__ */ new Set();
|
|
67
67
|
this.configure(options);
|
|
68
68
|
this.plans = /* @__PURE__ */ new Map();
|
|
69
|
+
this.given = {
|
|
70
|
+
urls: [],
|
|
71
|
+
breaks: []
|
|
72
|
+
};
|
|
69
73
|
this.current = null;
|
|
70
74
|
this.watchers = /* @__PURE__ */ new Set();
|
|
71
75
|
this.offEngine = null;
|
|
@@ -86,7 +90,7 @@ var Controller = class {
|
|
|
86
90
|
/** Follows the player until `detach`. */
|
|
87
91
|
attach() {
|
|
88
92
|
const player = this.player;
|
|
89
|
-
const video = player.
|
|
93
|
+
const video = player.media;
|
|
90
94
|
const onSource = () => {
|
|
91
95
|
this.reset();
|
|
92
96
|
this.bindEngine();
|
|
@@ -99,6 +103,7 @@ var Controller = class {
|
|
|
99
103
|
this.tick();
|
|
100
104
|
};
|
|
101
105
|
const onPlay = () => {
|
|
106
|
+
if (this.away()) return;
|
|
102
107
|
if (this.current === null && this.pending("start")) {
|
|
103
108
|
this.holding = true;
|
|
104
109
|
video.pause();
|
|
@@ -112,6 +117,7 @@ var Controller = class {
|
|
|
112
117
|
this.tick();
|
|
113
118
|
};
|
|
114
119
|
const onEnded = () => {
|
|
120
|
+
if (this.away() && this.current === null) return;
|
|
115
121
|
if (this.current?.interrupt === true) {
|
|
116
122
|
this.nextProgressive();
|
|
117
123
|
return;
|
|
@@ -197,11 +203,11 @@ var Controller = class {
|
|
|
197
203
|
get state() {
|
|
198
204
|
const current = this.current;
|
|
199
205
|
if (current === null) return null;
|
|
200
|
-
const media = this.player.
|
|
206
|
+
const media = this.player.media;
|
|
201
207
|
const ads = current.plan?.ads ?? [];
|
|
202
208
|
const assets = current.entry?.assets ?? [];
|
|
203
209
|
const total = Math.max(1, ads.length || assets.length);
|
|
204
|
-
const time = current.stitched ? this.player.
|
|
210
|
+
const time = current.stitched ? this.player.media.currentTime - (current.entry?.start ?? 0) : media.currentTime;
|
|
205
211
|
const duration = current.stitched ? current.entry?.covers ?? NaN : Number.isFinite(media.duration) ? media.duration : current.ad?.duration ?? assets[current.index]?.duration ?? NaN;
|
|
206
212
|
const later = (ads.length > 0 ? ads.map((ad) => ad.duration) : assets.map((asset) => asset.duration ?? NaN)).slice(current.index + 1).reduce((sum, value) => sum + value, 0);
|
|
207
213
|
const free = this.free(current);
|
|
@@ -233,8 +239,27 @@ var Controller = class {
|
|
|
233
239
|
this.watchers.delete(fn);
|
|
234
240
|
};
|
|
235
241
|
}
|
|
242
|
+
/** The schedule the page gave, for the page of a device. Undefined without one. */
|
|
243
|
+
remoteData() {
|
|
244
|
+
const { urls, breaks } = this.given;
|
|
245
|
+
if (urls.length === 0 && breaks.length === 0) return void 0;
|
|
246
|
+
return {
|
|
247
|
+
...urls.length === 0 ? {} : { urls: [...urls] },
|
|
248
|
+
...breaks.length === 0 ? {} : { breaks: [...breaks] }
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* A device plays in the video's place, and it is not the video itself as
|
|
253
|
+
* under AirPlay. The device's own page plays the ads then, so nothing
|
|
254
|
+
* starts here: the same break would play twice.
|
|
255
|
+
*/
|
|
256
|
+
away() {
|
|
257
|
+
const target = this.player.casting;
|
|
258
|
+
return target !== null && target.kind !== "airplay";
|
|
259
|
+
}
|
|
236
260
|
async load(source) {
|
|
237
261
|
const url = new URL(source, location.href).href;
|
|
262
|
+
this.given.urls.push(url);
|
|
238
263
|
let text;
|
|
239
264
|
this.fetching += 1;
|
|
240
265
|
try {
|
|
@@ -261,6 +286,7 @@ var Controller = class {
|
|
|
261
286
|
this.tick();
|
|
262
287
|
}
|
|
263
288
|
schedule(breaks) {
|
|
289
|
+
this.given.breaks.push(...breaks);
|
|
264
290
|
for (const entry of breaks) {
|
|
265
291
|
this.seq += 1;
|
|
266
292
|
this.add({
|
|
@@ -287,7 +313,7 @@ var Controller = class {
|
|
|
287
313
|
this.track(current, "skip");
|
|
288
314
|
this.emit("adskip", this.detail());
|
|
289
315
|
if (current.stitched && current.entry !== null) {
|
|
290
|
-
this.player.
|
|
316
|
+
this.player.media.currentTime = current.entry.start + current.entry.covers;
|
|
291
317
|
return;
|
|
292
318
|
}
|
|
293
319
|
this.engineBreaks()?.skip();
|
|
@@ -299,7 +325,7 @@ var Controller = class {
|
|
|
299
325
|
for (const url of current.ad?.clickTracking ?? []) this.send(expand(url, this.macros(current)));
|
|
300
326
|
this.track(current, "clickTracking");
|
|
301
327
|
window.open(target, "_blank", "noopener");
|
|
302
|
-
this.player.
|
|
328
|
+
this.player.media.pause();
|
|
303
329
|
this.emit("adclick", this.detail());
|
|
304
330
|
}
|
|
305
331
|
add(entry) {
|
|
@@ -382,10 +408,10 @@ var Controller = class {
|
|
|
382
408
|
}
|
|
383
409
|
/** The programme's own time, through a break. */
|
|
384
410
|
programmeTime() {
|
|
385
|
-
return this.engineBreaks()?.primary.currentTime ?? this.player.
|
|
411
|
+
return this.engineBreaks()?.primary.currentTime ?? this.player.media.currentTime;
|
|
386
412
|
}
|
|
387
413
|
programmeDuration() {
|
|
388
|
-
return this.engineBreaks()?.primary.duration ?? this.player.
|
|
414
|
+
return this.engineBreaks()?.primary.duration ?? this.player.media.duration;
|
|
389
415
|
}
|
|
390
416
|
/** Fetches the VAST of each break as it comes near, and starts the progressive ones on time. */
|
|
391
417
|
tick() {
|
|
@@ -394,6 +420,7 @@ var Controller = class {
|
|
|
394
420
|
this.followAd(this.current);
|
|
395
421
|
return;
|
|
396
422
|
}
|
|
423
|
+
if (this.away()) return;
|
|
397
424
|
const time = this.programmeTime();
|
|
398
425
|
const duration = this.programmeDuration();
|
|
399
426
|
const seeked = Math.abs(time - this.lastTime) > 2;
|
|
@@ -417,7 +444,7 @@ var Controller = class {
|
|
|
417
444
|
const playable = [];
|
|
418
445
|
const files = [];
|
|
419
446
|
for (const ad of result.ads) {
|
|
420
|
-
const file = pick(ad, engine, this.player.
|
|
447
|
+
const file = pick(ad, engine, this.player.media, height);
|
|
421
448
|
if (file === void 0 || !STREAMING.test(file.type) && this.progressive === "skip") {
|
|
422
449
|
for (const url of ad.errors) this.send(expand(url, { errorCode: 403 }));
|
|
423
450
|
continue;
|
|
@@ -445,7 +472,7 @@ var Controller = class {
|
|
|
445
472
|
const offsets = playable.flatMap((ad) => ad.skipOffset === void 0 ? [] : [ad.skipOffset]);
|
|
446
473
|
if (this.holding) {
|
|
447
474
|
this.holding = false;
|
|
448
|
-
this.player.
|
|
475
|
+
this.player.media.play()?.catch(() => {});
|
|
449
476
|
}
|
|
450
477
|
this.engineBreaks()?.schedule({
|
|
451
478
|
id: plan.id,
|
|
@@ -465,9 +492,9 @@ var Controller = class {
|
|
|
465
492
|
return;
|
|
466
493
|
}
|
|
467
494
|
plan.status = "progressive";
|
|
468
|
-
if (plan.offset === "start" && (this.holding || !this.player.
|
|
495
|
+
if (plan.offset === "start" && (this.holding || !this.player.media.paused)) {
|
|
469
496
|
this.holding = false;
|
|
470
|
-
this.player.
|
|
497
|
+
this.player.media.pause();
|
|
471
498
|
this.startProgressive(plan);
|
|
472
499
|
}
|
|
473
500
|
}
|
|
@@ -475,7 +502,7 @@ var Controller = class {
|
|
|
475
502
|
release() {
|
|
476
503
|
if (!this.holding || this.pending("start")) return;
|
|
477
504
|
this.holding = false;
|
|
478
|
-
this.player.
|
|
505
|
+
this.player.media.play()?.catch(() => {});
|
|
479
506
|
}
|
|
480
507
|
bindEngine() {
|
|
481
508
|
this.offEngine?.();
|
|
@@ -517,7 +544,7 @@ var Controller = class {
|
|
|
517
544
|
}
|
|
518
545
|
/** After a drag: in an ad the stream plays, it starts; out of it, the ad that showed ends. */
|
|
519
546
|
landed() {
|
|
520
|
-
const time = this.player.
|
|
547
|
+
const time = this.player.media.currentTime;
|
|
521
548
|
const inside = (this.engineBreaks()?.breaks ?? []).find((entry) => entry.assets.length === 0 && entry.assetList === void 0 && time >= entry.start && time < entry.start + Math.max(entry.covers, .001));
|
|
522
549
|
const current = this.current;
|
|
523
550
|
if (current?.stitched === true && current.entry?.id !== inside?.id) this.breakEnd();
|
|
@@ -669,8 +696,8 @@ var Controller = class {
|
|
|
669
696
|
}
|
|
670
697
|
/** The ad's own time: progressive quartiles, progress beacons, the stream's callbacks, viewability. */
|
|
671
698
|
followAd(current) {
|
|
672
|
-
const media = this.player.
|
|
673
|
-
const time = current.stitched ? this.player.
|
|
699
|
+
const media = this.player.media;
|
|
700
|
+
const time = current.stitched ? this.player.media.currentTime - (current.entry?.start ?? 0) : media.currentTime;
|
|
674
701
|
if (current.interrupt && !media.seeking) current.last = time;
|
|
675
702
|
if (current.interrupt && Number.isFinite(media.duration) && media.duration > 0) {
|
|
676
703
|
const reached = Math.floor(time / media.duration * 4);
|
|
@@ -697,7 +724,7 @@ var Controller = class {
|
|
|
697
724
|
}
|
|
698
725
|
adResumed(media) {
|
|
699
726
|
const current = this.current;
|
|
700
|
-
if (current === null || !current.paused || media !== this.player.
|
|
727
|
+
if (current === null || !current.paused || media !== this.player.media) return;
|
|
701
728
|
current.paused = false;
|
|
702
729
|
this.track(current, "resume");
|
|
703
730
|
}
|
|
@@ -749,7 +776,7 @@ var Controller = class {
|
|
|
749
776
|
this.emit("adviewable", this.detail());
|
|
750
777
|
}
|
|
751
778
|
macros(current) {
|
|
752
|
-
const media = this.player.
|
|
779
|
+
const media = this.player.media;
|
|
753
780
|
const offset = current.plan?.offset;
|
|
754
781
|
return {
|
|
755
782
|
mediaPlayhead: current.at,
|
|
@@ -784,6 +811,10 @@ var Controller = class {
|
|
|
784
811
|
if (this.current !== null) this.player.removeAttribute("ad");
|
|
785
812
|
this.current = null;
|
|
786
813
|
this.plans = /* @__PURE__ */ new Map();
|
|
814
|
+
this.given = {
|
|
815
|
+
urls: [],
|
|
816
|
+
breaks: []
|
|
817
|
+
};
|
|
787
818
|
this.done = /* @__PURE__ */ new Set();
|
|
788
819
|
this.own = /* @__PURE__ */ new Set();
|
|
789
820
|
this.player.breaks.set("ads", []);
|
package/dist/controller.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","names":[],"sources":["../src/controller.ts"],"sourcesContent":["/**\n * The ads of one player: the schedule a page or a VMAP gives, the VAST of\n * each break, the breaks the stream signals, the beacons, and the state the\n * ad controls draw.\n *\n * Every ad plays on the player's own video, so the controls drive it and a\n * TV with one decoder plays it. An ad with an HLS or DASH file plays\n * through the engine's interstitials stage. An ad with only a progressive\n * file (MP4, WebM) plays through `player.interrupt`, which loads it in the\n * programme's place, and `player.resume` loads the programme again where\n * it stopped. On a native session, every ad plays that way.\n */\nimport type { BreakMark, Marker, PlayerHost } from '@mattebox/player';\nimport type { AdCreative, Break, InterstitialsApi } from 'mattebox/stages/interstitials';\nimport { expand, type MacroValues, send } from './beacons.js';\nimport { fetchText, resolveVast, type VastAd, type VastFetch, type VastMediaFile } from './vast.js';\nimport { type BreakOffset, offsetTime, parseVmap, type ScheduledBreak } from './vmap.js';\n\n/** What the ad controls show while an ad plays. */\nexport interface AdState {\n readonly breakId: string;\n /** 1 for the first ad of the break. */\n readonly index: number;\n readonly total: number;\n /** Seconds into the ad that plays. */\n readonly currentTime: number;\n /** Seconds of the ad that plays, or NaN while unknown. */\n readonly duration: number;\n /** Seconds left in the whole break, or NaN while unknown. */\n readonly remaining: number;\n /** Seconds until the viewer may skip, 0 once they may, null when the ad cannot be skipped. */\n readonly skipIn: number | null;\n readonly clickThrough?: string;\n /** The VAST ad, absent for an ad the stream signalled. */\n readonly ad?: VastAd;\n /** The stream plays the break itself: a cue-out with no ad of the page's. */\n readonly stitched: boolean;\n /** An ad, or a promotion of the channel's own. */\n readonly role: 'ad' | 'promo';\n /**\n * A break the stream plays that sets no rule, under `stitched: 'free'`:\n * the programme's controls stay, the seek bar among them, and the ad can be\n * skipped at once.\n */\n readonly free: boolean;\n}\n\n/** A break the page schedules: where, and the VAST to ask. */\nexport interface AdBreakInput {\n readonly id?: string;\n /** 'start', 'end', seconds, or a VMAP `timeOffset` such as '00:10:00' or '50%'. */\n readonly offset: 'start' | 'end' | number | string;\n /** The VAST URL. */\n readonly vast: string;\n}\n\n/** A cue-out of a live stream, which the page can fill with ads. */\nexport interface AdOpportunity {\n readonly id: string;\n readonly start: number;\n readonly duration: number;\n}\n\nexport interface AdsApi {\n /** The ad that plays, or null. */\n readonly state: AdState | null;\n /** Loads a VMAP, or a VAST as one pre-roll, for the current programme. */\n load(url: string): Promise<void>;\n /** Adds breaks for the current programme. A new programme clears them. */\n schedule(breaks: readonly AdBreakInput[]): void;\n /** Skips the ad that plays, when it may be skipped by now. */\n skip(): void;\n /** Opens the ad's page, pauses the ad, and reports the click. */\n click(): void;\n /** The VAST URL to fill a cue-out with, or null to let the stream play. */\n onOpportunity: ((opportunity: AdOpportunity) => string | null) | null;\n /** Runs `fn` whenever the state changes; returns the unsubscribe. */\n watch(fn: () => void): () => void;\n}\n\nexport interface AdsOptions {\n /** How VAST and VMAP documents are fetched: a page that signs its ad requests gives its own. */\n readonly fetch?: VastFetch;\n /** Ads with only a progressive file: played on the player's video, or skipped. */\n readonly progressive?: 'play' | 'skip';\n /** Sends each beacon, in place of the add-on: a page that logs them, or sends them through its own server. */\n readonly beacon?: (url: string) => void;\n /**\n * A break the stream plays itself and that sets no rule, as every SCTE-35\n * cue: `free`, the default, keeps the programme's controls and lets the\n * viewer skip it; `strict` takes no seek, as a break that forbids one.\n */\n readonly stitched?: 'free' | 'strict';\n}\n\n/** Seconds before a break at which its VAST is fetched: fresh, and in time for the preload. */\nconst LOOKAHEAD = 10;\nconst QUARTILE_EVENTS = ['firstQuartile', 'midpoint', 'thirdQuartile'] as const;\n/** The keys that seek: the bar's arrows and media keys, the seek bar's Home, End and pages. */\nconst SEEK_KEYS = new Set([\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n 'MediaRewind',\n 'MediaFastForward',\n 'MediaTrackNext',\n 'MediaTrackPrevious',\n 'j',\n 'J',\n 'l',\n 'L',\n ...'0123456789',\n]);\nconst STREAMING = /mpegurl|dash\\+xml/i;\n\n/** What of the engine's chapters this add-on reads and writes. */\ninterface ChaptersView {\n readonly source: string;\n set(chapters: readonly { start: number; end?: number; title: string }[]): number;\n}\n\ninterface Plan {\n readonly id: string;\n readonly offset: BreakOffset;\n readonly vast: ScheduledBreak['vast'];\n readonly tracking: ScheduledBreak['tracking'];\n /** Seconds a cue-out lasts, for a fill. */\n readonly covers?: number;\n status: 'waiting' | 'resolving' | 'stream' | 'progressive' | 'done';\n ads: readonly VastAd[];\n files: readonly VastMediaFile[];\n start?: number;\n}\n\ninterface Current {\n readonly plan: Plan | null;\n readonly entry: Break | null;\n readonly stitched: boolean;\n index: number;\n ad: VastAd | undefined;\n /** What the stream says of the ad, SVTA2053, for an ad without a VAST. */\n creative: AdCreative | undefined;\n file: VastMediaFile | undefined;\n skipped: boolean;\n quartiles: number;\n /** Progress beacons and stream tracking already sent, by index. */\n sent: Set<number>;\n viewable: boolean;\n /** The viewer paused the ad: the next play is a resume. */\n paused: boolean;\n /** A progressive ad, which `player.interrupt` plays in the programme's place. */\n readonly interrupt: boolean;\n /** The ad's last time, which a refused seek goes back to. */\n last: number;\n /** The programme time where the break started, for the macros. */\n readonly at: number;\n}\n\nconst controllers = new WeakMap<PlayerHost, Controller>();\n\n/** The ads of `player`, created on first use. */\nexport function controllerFor(player: PlayerHost, options?: AdsOptions): Controller {\n let found = controllers.get(player);\n if (found === undefined) {\n found = new Controller(player, options ?? {});\n controllers.set(player, found);\n } else if (options !== undefined) {\n // The add-on's options, for a controller a page or an element made first.\n found.configure(options);\n }\n return found;\n}\n\n/** The time form of a scheduled offset. */\nfunction offsetFrom(value: AdBreakInput['offset']): BreakOffset {\n if (value === 'start' || value === 'end') return value;\n if (typeof value === 'number') return { time: value };\n if (value.endsWith('%')) return { percent: Number(value.slice(0, -1)) };\n const parts = value.split(':').map(Number);\n return { time: parts.reduce((sum, part) => sum * 60 + part, 0) };\n}\n\n/** The file to play: a streaming one the engine reads, else the progressive one closest above the player's height. */\nfunction pick(\n ad: VastAd,\n engine: boolean,\n video: HTMLVideoElement,\n height: number,\n): VastMediaFile | undefined {\n const usable = ad.mediaFiles.filter((file) => file.apiFramework === undefined);\n if (engine) {\n const stream = usable.find((file) => STREAMING.test(file.type));\n if (stream !== undefined) return stream;\n }\n const progressive = usable\n .filter((file) => !STREAMING.test(file.type) && video.canPlayType(file.type) !== '')\n .sort((a, b) => (a.height ?? 0) - (b.height ?? 0));\n return (\n progressive.find((file) => (file.height ?? 0) >= height) ?? progressive[progressive.length - 1]\n );\n}\n\nexport class Controller implements AdsApi {\n declare onOpportunity: ((opportunity: AdOpportunity) => string | null) | null;\n declare private readonly player: PlayerHost;\n declare private fetchDoc: VastFetch;\n declare private progressive: 'play' | 'skip';\n declare private send: (url: string) => void;\n declare private stitchedMode: 'free' | 'strict';\n /** The credits markers this add-on gave the player, so a page's own stay. */\n declare private own: ReadonlySet<Marker>;\n declare private plans: Map<string, Plan>;\n declare private current: Current | null;\n declare private watchers: Set<() => void>;\n declare private offEngine: (() => void) | null;\n declare private lastTime: number;\n /** A pre-roll is still being asked for: the programme waits for it. */\n declare private holding: boolean;\n /** Schedules being fetched, which may hold a pre-roll. */\n declare private fetching: number;\n declare private observer: IntersectionObserver | null;\n declare private visibleSince: number | null;\n declare private seq: number;\n /** The breaks that played, by id, which the seek bar draws faded. */\n declare private done: Set<string>;\n\n constructor(player: PlayerHost, options: AdsOptions) {\n this.onOpportunity = null;\n this.player = player;\n this.fetchDoc = fetchText;\n this.progressive = 'play';\n this.send = send;\n this.stitchedMode = 'free';\n this.own = new Set();\n this.configure(options);\n this.plans = new Map();\n this.current = null;\n this.watchers = new Set();\n this.offEngine = null;\n this.lastTime = 0;\n this.holding = false;\n this.fetching = 0;\n this.observer = null;\n this.visibleSince = null;\n this.seq = 0;\n this.done = new Set();\n }\n\n configure(options: AdsOptions): void {\n this.fetchDoc = options.fetch ?? fetchText;\n this.progressive = options.progressive ?? 'play';\n this.send = options.beacon ?? send;\n this.stitchedMode = options.stitched ?? 'free';\n }\n\n /** Follows the player until `detach`. */\n attach(): () => void {\n const player = this.player;\n const video = player.video;\n const onSource = (): void => {\n this.reset();\n this.bindEngine();\n const schedule = player.getAttribute('ad-schedule');\n if (schedule !== null && schedule !== '') void this.load(schedule);\n };\n const onTime = (): void => this.tick();\n const onMetadata = (): void => {\n this.mark();\n this.tick();\n };\n const onPlay = (): void => {\n // The pre-roll first: the programme waits while its ad server answers,\n // and a progressive pre-roll already answered starts now.\n if (this.current === null && this.pending('start')) {\n this.holding = true;\n video.pause();\n } else if (this.current === null) {\n const pre = [...this.plans.values()].find(\n (plan) => plan.offset === 'start' && plan.status === 'progressive',\n );\n if (pre !== undefined) {\n video.pause();\n this.startProgressive(pre);\n }\n }\n this.tick();\n };\n const onEnded = (): void => {\n if (this.current?.interrupt === true) {\n this.nextProgressive();\n return;\n }\n if (this.current !== null || this.engineBreaks()?.playing != null) return;\n const post = [...this.plans.values()].find(\n (plan) => plan.offset === 'end' && plan.status === 'progressive',\n );\n if (post !== undefined) this.startProgressive(post);\n };\n const onError = (): void => {\n const current = this.current;\n if (current?.interrupt !== true) return;\n if (current.ad !== undefined) {\n for (const url of current.ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n }\n this.emit('aderror', { id: current.plan?.id, code: 405 });\n this.nextProgressive();\n };\n const onSeeking = (): void => {\n // An ad takes no seek: back to where it was.\n const current = this.current;\n if (current?.interrupt !== true) return;\n if (Math.abs(video.currentTime - current.last) > 0.5) video.currentTime = current.last;\n };\n // An ad of the engine's plays on the player's own video.\n const onAdPause = (): void => {\n if (this.current !== null) this.adPaused(video);\n };\n const onAdPlay = (): void => {\n if (this.current !== null) this.adResumed(video);\n };\n const onAdVolume = (): void => {\n if (this.current !== null && !this.current.stitched) this.adVolume(video);\n };\n // An ad takes no seek: the keys that seek go nowhere while one plays.\n // Play, pause, mute and fullscreen stay the bar's. In the capture phase,\n // so the bar and the seek bar never hear them.\n const onKey = (event: KeyboardEvent): void => {\n if (this.current === null || this.free(this.current)) return;\n if (!SEEK_KEYS.has(event.key)) return;\n // The volume's own arrows, when it has focus, are the volume's.\n const volume = event\n .composedPath()\n .some((node) => node instanceof HTMLElement && node.localName.startsWith('mbx-volume'));\n if (volume) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n player.addEventListener('keydown', onKey, true);\n // A page's markers replace the list: the credits this add-on gave come back.\n const onMarkers = (): void => this.spans();\n player.addEventListener('markerschange', onMarkers);\n // At the end of a drag, the ad the stream plays where it landed, if any.\n const scrub = new MutationObserver(() => {\n if (!player.hasAttribute('scrubbing')) this.landed();\n });\n scrub.observe(player, { attributes: true, attributeFilter: ['scrubbing'] });\n player.addEventListener('sourcechange', onSource);\n video.addEventListener('timeupdate', onTime);\n video.addEventListener('play', onPlay);\n video.addEventListener('loadedmetadata', onMetadata);\n video.addEventListener('ended', onEnded);\n video.addEventListener('error', onError);\n video.addEventListener('seeking', onSeeking);\n video.addEventListener('pause', onAdPause);\n video.addEventListener('playing', onAdPlay);\n video.addEventListener('volumechange', onAdVolume);\n this.bindEngine();\n return () => {\n scrub.disconnect();\n player.removeEventListener('markerschange', onMarkers);\n player.removeEventListener('keydown', onKey, true);\n player.removeEventListener('sourcechange', onSource);\n video.removeEventListener('timeupdate', onTime);\n video.removeEventListener('play', onPlay);\n video.removeEventListener('loadedmetadata', onMetadata);\n video.removeEventListener('ended', onEnded);\n video.removeEventListener('error', onError);\n video.removeEventListener('seeking', onSeeking);\n video.removeEventListener('pause', onAdPause);\n video.removeEventListener('playing', onAdPlay);\n video.removeEventListener('volumechange', onAdVolume);\n this.reset();\n this.offEngine?.();\n this.offEngine = null;\n };\n }\n\n get state(): AdState | null {\n const current = this.current;\n if (current === null) return null;\n const media = this.player.video;\n const ads = current.plan?.ads ?? [];\n const assets = current.entry?.assets ?? [];\n const total = Math.max(1, ads.length || assets.length);\n const time = current.stitched\n ? this.player.video.currentTime - (current.entry?.start ?? 0)\n : media.currentTime;\n const duration = current.stitched\n ? (current.entry?.covers ?? Number.NaN)\n : Number.isFinite(media.duration)\n ? media.duration\n : (current.ad?.duration ?? assets[current.index]?.duration ?? Number.NaN);\n const later = (\n ads.length > 0\n ? ads.map((ad) => ad.duration)\n : assets.map((asset) => asset.duration ?? Number.NaN)\n )\n .slice(current.index + 1)\n .reduce((sum, value) => sum + value, 0);\n const free = this.free(current);\n // A break the stream plays and that sets no rule skips at once when free.\n const skipOffset =\n current.ad?.skipOffset ??\n current.creative?.skipOffset ??\n (current.ad === undefined && !current.stitched ? current.entry?.skipAfter : undefined);\n const clickThrough = current.ad?.clickThrough ?? current.creative?.clickThrough;\n return {\n breakId: current.plan?.id ?? current.entry?.id ?? '',\n index: current.index + 1,\n total,\n currentTime: time,\n duration,\n remaining: duration - time + later,\n skipIn: free ? 0 : skipOffset === undefined ? null : Math.max(0, skipOffset - time),\n ...(clickThrough !== undefined ? { clickThrough } : {}),\n ...(current.ad !== undefined ? { ad: current.ad } : {}),\n stitched: current.stitched,\n role: current.entry?.role === 'promo' ? 'promo' : 'ad',\n free,\n };\n }\n\n /** A break the stream plays itself, with no rule of its own, under `stitched: 'free'`. */\n private free(current: Current): boolean {\n const entry = current.entry;\n return (\n current.stitched &&\n this.stitchedMode === 'free' &&\n entry !== null &&\n !entry.noSkip &&\n !entry.noJump &&\n current.creative?.skipOffset === undefined\n );\n }\n\n watch(fn: () => void): () => void {\n this.watchers.add(fn);\n return () => {\n this.watchers.delete(fn);\n };\n }\n\n async load(source: string): Promise<void> {\n // Absolute, so the ad tags of a VMAP resolve against it.\n const url = new URL(source, location.href).href;\n let text: string;\n this.fetching += 1;\n try {\n text = await this.fetchDoc(url, new AbortController().signal);\n } catch {\n this.fetching -= 1;\n this.emit('aderror', { code: 900, url });\n this.release();\n return;\n }\n this.fetching -= 1;\n const breaks = parseVmap(text, url);\n if (breaks === null) {\n this.add({ id: 'preroll', offset: 'start', vast: { xml: text }, tracking: [] });\n } else {\n for (const entry of breaks) this.add(entry);\n }\n // A schedule without a pre-roll lets the programme play.\n this.release();\n this.tick();\n }\n\n schedule(breaks: readonly AdBreakInput[]): void {\n for (const entry of breaks) {\n this.seq += 1;\n this.add({\n id: entry.id ?? `ad-break-${this.seq}`,\n offset: offsetFrom(entry.offset),\n vast: { url: new URL(entry.vast, location.href).href },\n tracking: [],\n });\n }\n this.tick();\n }\n\n skip(): void {\n const current = this.current;\n const state = this.state;\n if (current === null || state === null || state.skipIn === null || state.skipIn > 0) return;\n if (current.interrupt) {\n current.skipped = true;\n this.track(current, 'skip');\n this.emit('adskip', this.detail());\n this.nextProgressive();\n return;\n }\n current.skipped = true;\n this.track(current, 'skip');\n this.emit('adskip', this.detail());\n if (current.stitched && current.entry !== null) {\n // The stream plays this ad itself: a skip is a seek past it.\n this.player.video.currentTime = current.entry.start + current.entry.covers;\n return;\n }\n this.engineBreaks()?.skip();\n }\n\n click(): void {\n const current = this.current;\n const target = current?.ad?.clickThrough ?? current?.creative?.clickThrough;\n if (current === null || target === undefined) return;\n for (const url of current.ad?.clickTracking ?? []) this.send(expand(url, this.macros(current)));\n this.track(current, 'clickTracking');\n window.open(target, '_blank', 'noopener');\n this.player.video.pause();\n this.emit('adclick', this.detail());\n }\n\n // ---- the schedule ------------------------------------------------------\n\n private add(entry: ScheduledBreak & { readonly covers?: number }): void {\n this.plans.set(entry.id, { ...entry, status: 'waiting', ads: [], files: [] });\n this.mark();\n }\n\n /**\n * The seek bar's ticks: the mid-roll breaks of the engine and of the\n * schedule, spans where a break replaces a part, faded once played. A\n * pre-roll and a post-roll sit at the ends and get none.\n */\n private mark(): void {\n const marks: BreakMark[] = [];\n const engine = this.engineBreaks();\n const ids = new Set<string>();\n for (const entry of engine?.breaks ?? []) {\n ids.add(entry.id);\n if (entry.cue !== undefined) continue;\n if (entry.role !== undefined && entry.role !== 'ad' && entry.role !== 'promo') continue;\n marks.push({\n start: entry.start,\n ...(entry.covers > 0 ? { end: entry.start + entry.covers } : {}),\n ...(this.done.has(entry.id) ? { played: true } : {}),\n });\n }\n const duration = this.programmeDuration();\n for (const plan of this.plans.values()) {\n if (ids.has(plan.id) || plan.offset === 'start' || plan.offset === 'end') continue;\n const at = offsetTime(plan.offset, duration);\n if (at === null) continue;\n marks.push({ start: at, ...(plan.status === 'done' ? { played: true } : {}) });\n }\n this.player.breaks.set('ads', marks);\n this.spans();\n }\n\n /**\n * The credits and chapters a SCTE-35 section names, as the player shows\n * them: the credits as markers, which give Skip intro and Skip credits,\n * beside the page's own, and the chapters in the chapter menu when nothing\n * else gives chapters.\n */\n private spans(): void {\n const breaks = this.engineBreaks()?.breaks ?? [];\n const credits: Marker[] = breaks.flatMap((entry) =>\n (entry.role === 'opening-credits' || entry.role === 'closing-credits') && entry.covers > 0\n ? [{ start: entry.start, end: entry.start + entry.covers, kind: entry.role }]\n : [],\n );\n const markers = this.player.markers;\n const theirs = markers.list.filter((marker) => !this.own.has(marker));\n const same =\n credits.length === this.own.size &&\n [...this.own].every((marker, i) => {\n const next = credits[i];\n return next !== undefined && next.start === marker.start && next.end === marker.end;\n }) &&\n [...this.own].every((marker) => markers.list.includes(marker));\n if (!same) {\n this.own = new Set(credits);\n markers.set([...theirs, ...credits]);\n }\n const chapters = breaks.filter((entry) => entry.role === 'chapter');\n const api = (this.player.engine as { chapters?: ChaptersView } | null)?.chapters;\n if (\n api !== undefined &&\n chapters.length > 0 &&\n api.source !== 'manifest' &&\n api.source !== 'app'\n ) {\n api.set(\n chapters.map((entry, i) => ({\n start: entry.start,\n ...(entry.covers > 0 ? { end: entry.start + entry.covers } : {}),\n title: `${i + 1}`,\n })),\n );\n }\n }\n\n private pending(offset: 'start'): boolean {\n if (this.fetching > 0) return true;\n return [...this.plans.values()].some(\n (plan) =>\n plan.offset === offset && (plan.status === 'waiting' || plan.status === 'resolving'),\n );\n }\n\n private engineBreaks(): InterstitialsApi | undefined {\n return (this.player.engine as { interstitials?: InterstitialsApi } | null)?.interstitials;\n }\n\n /** The programme's own time, through a break. */\n private programmeTime(): number {\n return this.engineBreaks()?.primary.currentTime ?? this.player.video.currentTime;\n }\n\n private programmeDuration(): number {\n return this.engineBreaks()?.primary.duration ?? this.player.video.duration;\n }\n\n /** Fetches the VAST of each break as it comes near, and starts the progressive ones on time. */\n private tick(): void {\n this.update();\n if (this.current !== null) {\n this.followAd(this.current);\n return;\n }\n const time = this.programmeTime();\n const duration = this.programmeDuration();\n const seeked = Math.abs(time - this.lastTime) > 2;\n for (const plan of this.plans.values()) {\n const at = offsetTime(plan.offset, duration);\n if (at === null) continue;\n if (plan.status === 'waiting' && (plan.offset === 'start' || at - time <= LOOKAHEAD)) {\n void this.resolve(plan, at);\n } else if (\n plan.status === 'progressive' &&\n plan.offset !== 'end' &&\n !seeked &&\n this.lastTime <= at &&\n time >= at &&\n plan.offset !== 'start'\n ) {\n this.startProgressive(plan);\n break;\n }\n }\n this.lastTime = time;\n }\n\n private async resolve(plan: Plan, at: number): Promise<void> {\n plan.status = 'resolving';\n const result = await resolveVast(plan.vast, this.fetchDoc);\n if (this.plans.get(plan.id) !== plan) return;\n const engine = this.engineBreaks() !== undefined;\n const height = this.player.clientHeight;\n const playable: VastAd[] = [];\n const files: VastMediaFile[] = [];\n for (const ad of result.ads) {\n const file = pick(ad, engine, this.player.video, height);\n if (file === undefined || (!STREAMING.test(file.type) && this.progressive === 'skip')) {\n for (const url of ad.errors) this.send(expand(url, { errorCode: 403 }));\n continue;\n }\n playable.push(ad);\n files.push(file);\n }\n if (result.ads.length === 0) {\n for (const url of result.errors) this.send(expand(url, { errorCode: result.code ?? 303 }));\n }\n plan.ads = playable;\n plan.files = files;\n plan.start = at;\n if (playable.length === 0) {\n plan.status = 'done';\n this.vmapTrack(plan, 'error');\n this.emit('aderror', { id: plan.id, code: result.code ?? 403 });\n this.release();\n return;\n }\n const streams = files.every((file) => STREAMING.test(file.type));\n if (engine && streams) {\n plan.status = 'stream';\n // A skippable ad still takes no seek: the controls skip it from its offset.\n const offsets = playable.flatMap((ad) =>\n ad.skipOffset === undefined ? [] : [ad.skipOffset],\n );\n if (this.holding) {\n this.holding = false;\n void this.player.video.play()?.catch(() => {});\n }\n this.engineBreaks()?.schedule({\n id: plan.id,\n start: at,\n ...(plan.offset === 'start'\n ? { cue: 'pre' as const }\n : plan.offset === 'end'\n ? { cue: 'post' as const }\n : {}),\n ...(plan.covers !== undefined ? { covers: plan.covers } : {}),\n assets: files.map((file, i) => ({\n url: file.url,\n duration: playable[i]?.duration ?? 0,\n mimeType: /dash/i.test(file.type)\n ? 'application/dash+xml'\n : 'application/vnd.apple.mpegurl',\n })),\n noSkip: true,\n noJump: true,\n // An ad server's break plays once per programme, as IMA plays a VMAP.\n once: true,\n ...(offsets.length > 0 ? { skipAfter: Math.min(...offsets) } : {}),\n });\n return;\n }\n plan.status = 'progressive';\n if (plan.offset === 'start' && (this.holding || !this.player.video.paused)) {\n this.holding = false;\n this.player.video.pause();\n this.startProgressive(plan);\n }\n }\n\n /** Lets the programme play once no pre-roll holds it. */\n private release(): void {\n if (!this.holding || this.pending('start')) return;\n this.holding = false;\n void this.player.video.play()?.catch(() => {});\n }\n\n // ---- the engine's breaks -----------------------------------------------\n\n private bindEngine(): void {\n this.offEngine?.();\n this.offEngine = null;\n const engine = this.player.engine;\n if (engine === null || this.engineBreaks() === undefined) return;\n const on = (name: string, fn: (payload: Record<string, unknown>) => void): (() => void) =>\n engine.on(`interstitials:${name}`, (payload) => fn(payload as Record<string, unknown>));\n const offs = [\n on('break-start', (p) => {\n // A drag on the seek bar crosses a break the stream plays at each of\n // its seeks: where the drag ends decides, not each step of it.\n if (p.stitched === true && this.player.hasAttribute('scrubbing')) return;\n this.engineBreakStart(p.break as Break, p.stitched === true);\n }),\n on('asset-start', (p) => this.engineAssetStart(Number(p.asset))),\n on('progress', (p) => this.quartile(Number(p.quartile))),\n on('asset-end', () => this.adEnd()),\n on('break-end', (p) => {\n if (p.stitched === true && this.player.hasAttribute('scrubbing')) return;\n this.breakEnd();\n }),\n on('warning', (p) => {\n const current = this.current;\n if (current?.ad !== undefined) {\n for (const url of current.ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n }\n this.emit('aderror', { id: p.id, code: 405, reason: p.reason });\n }),\n on('opportunity', (p) => this.opportunity(p.break as Break, Number(p.duration))),\n ];\n offs.push(engine.on('interstitials:changed', () => this.mark()));\n this.offEngine = () => {\n for (const off of offs) off();\n };\n this.mark();\n }\n\n /** After a drag: in an ad the stream plays, it starts; out of it, the ad that showed ends. */\n private landed(): void {\n const time = this.player.video.currentTime;\n const inside = (this.engineBreaks()?.breaks ?? []).find(\n (entry) =>\n entry.assets.length === 0 &&\n entry.assetList === undefined &&\n time >= entry.start &&\n time < entry.start + Math.max(entry.covers, 0.001),\n );\n const current = this.current;\n if (current?.stitched === true && current.entry?.id !== inside?.id) this.breakEnd();\n if (inside !== undefined && this.current === null) this.engineBreakStart(inside, true);\n }\n\n private engineBreakStart(entry: Break, stitched: boolean): void {\n const plan = this.plans.get(entry.id) ?? null;\n this.current = {\n plan,\n entry,\n stitched,\n index: -1,\n ad: undefined,\n creative: undefined,\n file: undefined,\n skipped: false,\n quartiles: 0,\n sent: new Set(),\n viewable: false,\n paused: false,\n interrupt: false,\n last: 0,\n at: this.programmeTime(),\n };\n this.breakStart();\n // A break the stream plays itself is one ad, from its start.\n if (stitched) this.engineAssetStart(0);\n }\n\n private engineAssetStart(index: number): void {\n const current = this.current;\n if (current === null) return;\n current.index = index;\n current.ad = current.plan?.ads[index];\n current.creative = current.stitched\n ? current.entry?.creatives?.[0]\n : current.entry?.assets[index]?.creatives?.[0];\n current.file = current.plan?.files[index];\n current.skipped = false;\n current.quartiles = 0;\n current.sent = new Set();\n current.viewable = false;\n this.adStart(current);\n }\n\n private opportunity(entry: Break, duration: number): void {\n const url = this.onOpportunity?.({ id: entry.id, start: entry.start, duration });\n if (url === null || url === undefined) return;\n this.add({\n id: entry.id,\n offset: { time: entry.start },\n vast: { url: new URL(url, location.href).href },\n tracking: [],\n covers: duration,\n });\n const plan = this.plans.get(entry.id);\n if (plan !== undefined) void this.resolve(plan, entry.start);\n }\n\n // ---- progressive ads, on the player's video -------------------------------\n\n /** A break of progressive ads: each in the programme's place, then the programme again. */\n private startProgressive(plan: Plan): void {\n plan.status = 'done';\n this.current = {\n plan,\n entry: null,\n stitched: false,\n index: -1,\n ad: undefined,\n creative: undefined,\n file: undefined,\n skipped: false,\n quartiles: 0,\n sent: new Set(),\n viewable: false,\n paused: false,\n interrupt: true,\n last: 0,\n at: this.programmeTime(),\n };\n this.breakStart();\n this.nextProgressive();\n }\n\n private nextProgressive(): void {\n const current = this.current;\n if (current === null || !current.interrupt || current.plan === null) return;\n if (current.index >= 0) this.adEnd();\n current.index += 1;\n const ad = current.plan.ads[current.index];\n const file = current.plan.files[current.index];\n if (ad === undefined || file === undefined) {\n const plan = current.plan;\n this.breakEnd();\n // After a post-roll the programme comes back on its last frame, paused.\n void this.player.resume(\n plan.offset === 'end' ? { at: plan.start ?? null, playing: false } : { playing: true },\n );\n return;\n }\n current.ad = ad;\n current.file = file;\n current.skipped = false;\n current.quartiles = 0;\n current.sent = new Set();\n current.viewable = false;\n current.paused = false;\n current.last = 0;\n this.player.interrupt({ url: file.url, type: file.type }).catch(() => {\n // No handler plays the file: the next ad, or the programme.\n if (this.current !== current) return;\n for (const url of ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n this.emit('aderror', { id: current.plan?.id, code: 405 });\n this.nextProgressive();\n });\n this.adStart(current);\n }\n\n // ---- one ad ------------------------------------------------------------\n\n private breakStart(): void {\n const current = this.current;\n if (current === null) return;\n // `stitched` keeps the programme's controls; any other ad takes their place.\n this.player.setAttribute('ad', this.free(current) ? 'stitched' : '');\n if (current.plan !== null) this.vmapTrack(current.plan, 'breakStart');\n this.observe();\n this.emit('adbreakstart', this.detail());\n }\n\n private adStart(current: Current): void {\n if (current.ad !== undefined) {\n for (const url of current.ad.impressions) this.send(expand(url, this.macros(current)));\n }\n // SVTA2053 names the impression among its tracking events.\n this.track(current, 'impression');\n this.track(current, 'creativeView');\n this.track(current, 'start');\n this.visibleSince = null;\n this.emit('adstart', this.detail());\n this.update();\n }\n\n private quartile(n: number): void {\n const current = this.current;\n if (current === null || n <= current.quartiles) return;\n current.quartiles = n;\n const event = QUARTILE_EVENTS[n - 1];\n if (event !== undefined) this.track(current, event);\n this.emit('adprogress', { ...this.detail(), quartile: n });\n }\n\n /** The ad's own time: progressive quartiles, progress beacons, the stream's callbacks, viewability. */\n private followAd(current: Current): void {\n const media = this.player.video;\n const time = current.stitched\n ? this.player.video.currentTime - (current.entry?.start ?? 0)\n : media.currentTime;\n if (current.interrupt && !media.seeking) current.last = time;\n if (current.interrupt && Number.isFinite(media.duration) && media.duration > 0) {\n const reached = Math.floor((time / media.duration) * 4);\n for (let n = current.quartiles + 1; n <= Math.min(3, reached); n += 1) this.quartile(n);\n }\n const progress = current.ad?.tracking ?? [];\n progress.forEach((entry, i) => {\n if (\n entry.event !== 'progress' ||\n entry.offset === undefined ||\n current.sent.has(i) ||\n time < entry.offset\n )\n return;\n current.sent.add(i);\n this.send(expand(entry.url, this.macros(current)));\n });\n // DASH callback events of a List MPD, at their offsets in the asset.\n const tracking = current.entry?.assets[current.index]?.tracking ?? [];\n tracking.forEach((entry, i) => {\n const key = 1000 + i;\n if (current.sent.has(key) || time < entry.offset) return;\n current.sent.add(key);\n this.send(entry.url);\n });\n this.view(current);\n }\n\n private adPaused(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null || media.ended || current.paused) return;\n current.paused = true;\n this.track(current, 'pause');\n }\n\n private adResumed(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null || !current.paused || media !== this.player.video) return;\n current.paused = false;\n this.track(current, 'resume');\n }\n\n private adVolume(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null) return;\n this.track(current, media.muted ? 'mute' : 'unmute');\n }\n\n private adEnd(): void {\n const current = this.current;\n if (current === null || current.index < 0) return;\n if (!current.skipped) this.track(current, 'complete');\n if (current.ad !== undefined && !current.viewable) {\n for (const url of current.ad.notViewable) this.send(expand(url, this.macros(current)));\n }\n this.emit('adend', this.detail());\n }\n\n private breakEnd(): void {\n const current = this.current;\n if (current === null) return;\n // A break the stream plays has no asset of its own to end.\n if (current.stitched) this.adEnd();\n if (current.plan !== null) {\n current.plan.status = 'done';\n this.vmapTrack(current.plan, 'breakEnd');\n }\n const detail = this.detail();\n const id = current.plan?.id ?? current.entry?.id;\n if (id !== undefined) this.done.add(id);\n this.current = null;\n this.player.removeAttribute('ad');\n this.mark();\n this.observer?.disconnect();\n this.observer = null;\n this.emit('adbreakend', detail);\n this.update();\n }\n\n // ---- viewability -------------------------------------------------------\n\n /** MRC: half the player in view for two seconds in a row. */\n private observe(): void {\n if (typeof IntersectionObserver === 'undefined' || this.observer !== null) return;\n this.observer = new IntersectionObserver(\n (entries) => {\n const seen = entries.some((entry) => entry.intersectionRatio >= 0.5);\n this.visibleSince = seen ? (this.visibleSince ?? performance.now()) : null;\n },\n { threshold: [0, 0.5] },\n );\n this.observer.observe(this.player);\n }\n\n private view(current: Current): void {\n if (current.viewable || current.ad === undefined || this.visibleSince === null) return;\n if (performance.now() - this.visibleSince < 2000) return;\n current.viewable = true;\n for (const url of current.ad.viewable) this.send(expand(url, this.macros(current)));\n this.emit('adviewable', this.detail());\n }\n\n // ---- beacons and events ------------------------------------------------\n\n private macros(current: Current): MacroValues {\n const media = this.player.video;\n const offset = current.plan?.offset;\n return {\n mediaPlayhead: current.at,\n adPlayhead: media.currentTime,\n ...(current.file !== undefined ? { assetUri: current.file.url } : {}),\n breakPosition: offset === 'start' ? 1 : offset === 'end' ? 3 : 2,\n playerSize: [this.player.clientWidth, this.player.clientHeight],\n };\n }\n\n private track(current: Current, event: string): void {\n for (const entry of current.ad?.tracking ?? []) {\n if (entry.event === event) this.send(expand(entry.url, this.macros(current)));\n }\n }\n\n private vmapTrack(plan: Plan, event: string): void {\n for (const entry of plan.tracking) if (entry.event === event) this.send(entry.url);\n }\n\n private detail(): Record<string, unknown> {\n const current = this.current;\n return {\n breakId: current?.plan?.id ?? current?.entry?.id ?? null,\n index: (current?.index ?? 0) + 1,\n ad: current?.ad ?? null,\n stitched: current?.stitched ?? false,\n };\n }\n\n private emit(name: string, detail: object): void {\n this.player.dispatchEvent(new CustomEvent(name, { detail }));\n }\n\n private update(): void {\n for (const fn of [...this.watchers]) fn();\n }\n\n private reset(): void {\n const current = this.current;\n if (current !== null) this.player.removeAttribute('ad');\n this.current = null;\n this.plans = new Map();\n this.done = new Set();\n this.own = new Set();\n this.player.breaks.set('ads', []);\n this.holding = false;\n this.lastTime = 0;\n this.observer?.disconnect();\n this.observer = null;\n this.update();\n }\n}\n"],"mappings":";;;;;AAgGA,MAAM,YAAY;AAClB,MAAM,kBAAkB;CAAC;CAAiB;CAAY;AAAe;;AAErE,MAAM,4BAAY,IAAI,IAAI;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACL,CAAC;AACD,MAAM,YAAY;AA6ClB,MAAM,8BAAc,IAAI,QAAgC;;AAGxD,SAAgB,cAAc,QAAoB,SAAkC;CAClF,IAAI,QAAQ,YAAY,IAAI,MAAM;CAClC,IAAI,UAAU,KAAA,GAAW;EACvB,QAAQ,IAAI,WAAW,QAAQ,WAAW,CAAC,CAAC;EAC5C,YAAY,IAAI,QAAQ,KAAK;CAC/B,OAAO,IAAI,YAAY,KAAA,GAErB,MAAM,UAAU,OAAO;CAEzB,OAAO;AACT;;AAGA,SAAS,WAAW,OAA4C;CAC9D,IAAI,UAAU,WAAW,UAAU,OAAO,OAAO;CACjD,IAAI,OAAO,UAAU,UAAU,OAAO,EAAE,MAAM,MAAM;CACpD,IAAI,MAAM,SAAS,GAAG,GAAG,OAAO,EAAE,SAAS,OAAO,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE;CA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AG,GAAG;CAC1C;CAEA,QAAsB;EAEpB,IADgB,KAAK,YACL,MAAM,KAAK,OAAO,gBAAgB,IAAI;EACtD,KAAK,UAAU;EACf,KAAK,wBAAQ,IAAI,IAAI;EACrB,KAAK,uBAAO,IAAI,IAAI;EACpB,KAAK,sBAAM,IAAI,IAAI;EACnB,KAAK,OAAO,OAAO,IAAI,OAAO,CAAC,CAAC;EAChC,KAAK,UAAU;EACf,KAAK,WAAW;EAChB,KAAK,UAAU,WAAW;EAC1B,KAAK,WAAW;EAChB,KAAK,OAAO;CACd;AACF"}
|
|
1
|
+
{"version":3,"file":"controller.js","names":[],"sources":["../src/controller.ts"],"sourcesContent":["/**\n * The ads of one player: the schedule a page or a VMAP gives, the VAST of\n * each break, the breaks the stream signals, the beacons, and the state the\n * ad controls draw.\n *\n * Every ad plays on the player's own video, so the controls drive it and a\n * TV with one decoder plays it. An ad with an HLS or DASH file plays\n * through the engine's interstitials stage. An ad with only a progressive\n * file (MP4, WebM) plays through `player.interrupt`, which loads it in the\n * programme's place, and `player.resume` loads the programme again where\n * it stopped. On a native session, every ad plays that way.\n */\nimport type { BreakMark, Marker, PlayerHost } from '@mattebox/player';\nimport type { AdCreative, Break, InterstitialsApi } from 'mattebox/stages/interstitials';\nimport { expand, type MacroValues, send } from './beacons.js';\nimport { fetchText, resolveVast, type VastAd, type VastFetch, type VastMediaFile } from './vast.js';\nimport { type BreakOffset, offsetTime, parseVmap, type ScheduledBreak } from './vmap.js';\n\n/** What the ad controls show while an ad plays. */\nexport interface AdState {\n readonly breakId: string;\n /** 1 for the first ad of the break. */\n readonly index: number;\n readonly total: number;\n /** Seconds into the ad that plays. */\n readonly currentTime: number;\n /** Seconds of the ad that plays, or NaN while unknown. */\n readonly duration: number;\n /** Seconds left in the whole break, or NaN while unknown. */\n readonly remaining: number;\n /** Seconds until the viewer may skip, 0 once they may, null when the ad cannot be skipped. */\n readonly skipIn: number | null;\n readonly clickThrough?: string;\n /** The VAST ad, absent for an ad the stream signalled. */\n readonly ad?: VastAd;\n /** The stream plays the break itself: a cue-out with no ad of the page's. */\n readonly stitched: boolean;\n /** An ad, or a promotion of the channel's own. */\n readonly role: 'ad' | 'promo';\n /**\n * A break the stream plays that sets no rule, under `stitched: 'free'`:\n * the programme's controls stay, the seek bar among them, and the ad can be\n * skipped at once.\n */\n readonly free: boolean;\n}\n\n/** A break the page schedules: where, and the VAST to ask. */\nexport interface AdBreakInput {\n readonly id?: string;\n /** 'start', 'end', seconds, or a VMAP `timeOffset` such as '00:10:00' or '50%'. */\n readonly offset: 'start' | 'end' | number | string;\n /** The VAST URL. */\n readonly vast: string;\n}\n\n/** A cue-out of a live stream, which the page can fill with ads. */\nexport interface AdOpportunity {\n readonly id: string;\n readonly start: number;\n readonly duration: number;\n}\n\nexport interface AdsApi {\n /** The ad that plays, or null. */\n readonly state: AdState | null;\n /** Loads a VMAP, or a VAST as one pre-roll, for the current programme. */\n load(url: string): Promise<void>;\n /** Adds breaks for the current programme. A new programme clears them. */\n schedule(breaks: readonly AdBreakInput[]): void;\n /** Skips the ad that plays, when it may be skipped by now. */\n skip(): void;\n /** Opens the ad's page, pauses the ad, and reports the click. */\n click(): void;\n /** The VAST URL to fill a cue-out with, or null to let the stream play. */\n onOpportunity: ((opportunity: AdOpportunity) => string | null) | null;\n /** Runs `fn` whenever the state changes; returns the unsubscribe. */\n watch(fn: () => void): () => void;\n}\n\n/**\n * What the add-on sends with a load to a device that plays in the video's\n * place: the schedule the page gave for the programme, through `load`,\n * `schedule` or the `ad-schedule` attribute. The page of the device gives\n * it to its own add-on, with the same two calls.\n */\nexport interface AdsRemoteData {\n /** The VMAP or VAST URLs of `load`, absolute. */\n readonly urls?: readonly string[];\n /** The breaks of `schedule`. */\n readonly breaks?: readonly AdBreakInput[];\n}\n\nexport interface AdsOptions {\n /** How VAST and VMAP documents are fetched: a page that signs its ad requests gives its own. */\n readonly fetch?: VastFetch;\n /** Ads with only a progressive file: played on the player's video, or skipped. */\n readonly progressive?: 'play' | 'skip';\n /** Sends each beacon, in place of the add-on: a page that logs them, or sends them through its own server. */\n readonly beacon?: (url: string) => void;\n /**\n * A break the stream plays itself and that sets no rule, as every SCTE-35\n * cue: `free`, the default, keeps the programme's controls and lets the\n * viewer skip it; `strict` takes no seek, as a break that forbids one.\n */\n readonly stitched?: 'free' | 'strict';\n}\n\n/** Seconds before a break at which its VAST is fetched: fresh, and in time for the preload. */\nconst LOOKAHEAD = 10;\nconst QUARTILE_EVENTS = ['firstQuartile', 'midpoint', 'thirdQuartile'] as const;\n/** The keys that seek: the bar's arrows and media keys, the seek bar's Home, End and pages. */\nconst SEEK_KEYS = new Set([\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n 'MediaRewind',\n 'MediaFastForward',\n 'MediaTrackNext',\n 'MediaTrackPrevious',\n 'j',\n 'J',\n 'l',\n 'L',\n ...'0123456789',\n]);\nconst STREAMING = /mpegurl|dash\\+xml/i;\n\n/** What of the engine's chapters this add-on reads and writes. */\ninterface ChaptersView {\n readonly source: string;\n set(chapters: readonly { start: number; end?: number; title: string }[]): number;\n}\n\ninterface Plan {\n readonly id: string;\n readonly offset: BreakOffset;\n readonly vast: ScheduledBreak['vast'];\n readonly tracking: ScheduledBreak['tracking'];\n /** Seconds a cue-out lasts, for a fill. */\n readonly covers?: number;\n status: 'waiting' | 'resolving' | 'stream' | 'progressive' | 'done';\n ads: readonly VastAd[];\n files: readonly VastMediaFile[];\n start?: number;\n}\n\ninterface Current {\n readonly plan: Plan | null;\n readonly entry: Break | null;\n readonly stitched: boolean;\n index: number;\n ad: VastAd | undefined;\n /** What the stream says of the ad, SVTA2053, for an ad without a VAST. */\n creative: AdCreative | undefined;\n file: VastMediaFile | undefined;\n skipped: boolean;\n quartiles: number;\n /** Progress beacons and stream tracking already sent, by index. */\n sent: Set<number>;\n viewable: boolean;\n /** The viewer paused the ad: the next play is a resume. */\n paused: boolean;\n /** A progressive ad, which `player.interrupt` plays in the programme's place. */\n readonly interrupt: boolean;\n /** The ad's last time, which a refused seek goes back to. */\n last: number;\n /** The programme time where the break started, for the macros. */\n readonly at: number;\n}\n\nconst controllers = new WeakMap<PlayerHost, Controller>();\n\n/** The ads of `player`, created on first use. */\nexport function controllerFor(player: PlayerHost, options?: AdsOptions): Controller {\n let found = controllers.get(player);\n if (found === undefined) {\n found = new Controller(player, options ?? {});\n controllers.set(player, found);\n } else if (options !== undefined) {\n // The add-on's options, for a controller a page or an element made first.\n found.configure(options);\n }\n return found;\n}\n\n/** The time form of a scheduled offset. */\nfunction offsetFrom(value: AdBreakInput['offset']): BreakOffset {\n if (value === 'start' || value === 'end') return value;\n if (typeof value === 'number') return { time: value };\n if (value.endsWith('%')) return { percent: Number(value.slice(0, -1)) };\n const parts = value.split(':').map(Number);\n return { time: parts.reduce((sum, part) => sum * 60 + part, 0) };\n}\n\n/** The file to play: a streaming one the engine reads, else the progressive one closest above the player's height. */\nfunction pick(\n ad: VastAd,\n engine: boolean,\n video: HTMLVideoElement,\n height: number,\n): VastMediaFile | undefined {\n const usable = ad.mediaFiles.filter((file) => file.apiFramework === undefined);\n if (engine) {\n const stream = usable.find((file) => STREAMING.test(file.type));\n if (stream !== undefined) return stream;\n }\n const progressive = usable\n .filter((file) => !STREAMING.test(file.type) && video.canPlayType(file.type) !== '')\n .sort((a, b) => (a.height ?? 0) - (b.height ?? 0));\n return (\n progressive.find((file) => (file.height ?? 0) >= height) ?? progressive[progressive.length - 1]\n );\n}\n\nexport class Controller implements AdsApi {\n declare onOpportunity: ((opportunity: AdOpportunity) => string | null) | null;\n declare private readonly player: PlayerHost;\n declare private fetchDoc: VastFetch;\n declare private progressive: 'play' | 'skip';\n declare private send: (url: string) => void;\n declare private stitchedMode: 'free' | 'strict';\n /** The credits markers this add-on gave the player, so a page's own stay. */\n declare private own: ReadonlySet<Marker>;\n declare private plans: Map<string, Plan>;\n /** What the page gave for this programme, as it gave it. */\n declare private given: { urls: string[]; breaks: AdBreakInput[] };\n declare private current: Current | null;\n declare private watchers: Set<() => void>;\n declare private offEngine: (() => void) | null;\n declare private lastTime: number;\n /** A pre-roll is still being asked for: the programme waits for it. */\n declare private holding: boolean;\n /** Schedules being fetched, which may hold a pre-roll. */\n declare private fetching: number;\n declare private observer: IntersectionObserver | null;\n declare private visibleSince: number | null;\n declare private seq: number;\n /** The breaks that played, by id, which the seek bar draws faded. */\n declare private done: Set<string>;\n\n constructor(player: PlayerHost, options: AdsOptions) {\n this.onOpportunity = null;\n this.player = player;\n this.fetchDoc = fetchText;\n this.progressive = 'play';\n this.send = send;\n this.stitchedMode = 'free';\n this.own = new Set();\n this.configure(options);\n this.plans = new Map();\n this.given = { urls: [], breaks: [] };\n this.current = null;\n this.watchers = new Set();\n this.offEngine = null;\n this.lastTime = 0;\n this.holding = false;\n this.fetching = 0;\n this.observer = null;\n this.visibleSince = null;\n this.seq = 0;\n this.done = new Set();\n }\n\n configure(options: AdsOptions): void {\n this.fetchDoc = options.fetch ?? fetchText;\n this.progressive = options.progressive ?? 'play';\n this.send = options.beacon ?? send;\n this.stitchedMode = options.stitched ?? 'free';\n }\n\n /** Follows the player until `detach`. */\n attach(): () => void {\n const player = this.player;\n const video = player.media;\n const onSource = (): void => {\n this.reset();\n this.bindEngine();\n const schedule = player.getAttribute('ad-schedule');\n if (schedule !== null && schedule !== '') void this.load(schedule);\n };\n const onTime = (): void => this.tick();\n const onMetadata = (): void => {\n this.mark();\n this.tick();\n };\n const onPlay = (): void => {\n if (this.away()) return;\n // The pre-roll first: the programme waits while its ad server answers,\n // and a progressive pre-roll already answered starts now.\n if (this.current === null && this.pending('start')) {\n this.holding = true;\n video.pause();\n } else if (this.current === null) {\n const pre = [...this.plans.values()].find(\n (plan) => plan.offset === 'start' && plan.status === 'progressive',\n );\n if (pre !== undefined) {\n video.pause();\n this.startProgressive(pre);\n }\n }\n this.tick();\n };\n const onEnded = (): void => {\n if (this.away() && this.current === null) return;\n if (this.current?.interrupt === true) {\n this.nextProgressive();\n return;\n }\n if (this.current !== null || this.engineBreaks()?.playing != null) return;\n const post = [...this.plans.values()].find(\n (plan) => plan.offset === 'end' && plan.status === 'progressive',\n );\n if (post !== undefined) this.startProgressive(post);\n };\n const onError = (): void => {\n const current = this.current;\n if (current?.interrupt !== true) return;\n if (current.ad !== undefined) {\n for (const url of current.ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n }\n this.emit('aderror', { id: current.plan?.id, code: 405 });\n this.nextProgressive();\n };\n const onSeeking = (): void => {\n // An ad takes no seek: back to where it was.\n const current = this.current;\n if (current?.interrupt !== true) return;\n if (Math.abs(video.currentTime - current.last) > 0.5) video.currentTime = current.last;\n };\n // An ad of the engine's plays on the player's own video.\n const onAdPause = (): void => {\n if (this.current !== null) this.adPaused(video);\n };\n const onAdPlay = (): void => {\n if (this.current !== null) this.adResumed(video);\n };\n const onAdVolume = (): void => {\n if (this.current !== null && !this.current.stitched) this.adVolume(video);\n };\n // An ad takes no seek: the keys that seek go nowhere while one plays.\n // Play, pause, mute and fullscreen stay the bar's. In the capture phase,\n // so the bar and the seek bar never hear them.\n const onKey = (event: KeyboardEvent): void => {\n if (this.current === null || this.free(this.current)) return;\n if (!SEEK_KEYS.has(event.key)) return;\n // The volume's own arrows, when it has focus, are the volume's.\n const volume = event\n .composedPath()\n .some((node) => node instanceof HTMLElement && node.localName.startsWith('mbx-volume'));\n if (volume) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n player.addEventListener('keydown', onKey, true);\n // A page's markers replace the list: the credits this add-on gave come back.\n const onMarkers = (): void => this.spans();\n player.addEventListener('markerschange', onMarkers);\n // At the end of a drag, the ad the stream plays where it landed, if any.\n const scrub = new MutationObserver(() => {\n if (!player.hasAttribute('scrubbing')) this.landed();\n });\n scrub.observe(player, { attributes: true, attributeFilter: ['scrubbing'] });\n player.addEventListener('sourcechange', onSource);\n video.addEventListener('timeupdate', onTime);\n video.addEventListener('play', onPlay);\n video.addEventListener('loadedmetadata', onMetadata);\n video.addEventListener('ended', onEnded);\n video.addEventListener('error', onError);\n video.addEventListener('seeking', onSeeking);\n video.addEventListener('pause', onAdPause);\n video.addEventListener('playing', onAdPlay);\n video.addEventListener('volumechange', onAdVolume);\n this.bindEngine();\n return () => {\n scrub.disconnect();\n player.removeEventListener('markerschange', onMarkers);\n player.removeEventListener('keydown', onKey, true);\n player.removeEventListener('sourcechange', onSource);\n video.removeEventListener('timeupdate', onTime);\n video.removeEventListener('play', onPlay);\n video.removeEventListener('loadedmetadata', onMetadata);\n video.removeEventListener('ended', onEnded);\n video.removeEventListener('error', onError);\n video.removeEventListener('seeking', onSeeking);\n video.removeEventListener('pause', onAdPause);\n video.removeEventListener('playing', onAdPlay);\n video.removeEventListener('volumechange', onAdVolume);\n this.reset();\n this.offEngine?.();\n this.offEngine = null;\n };\n }\n\n get state(): AdState | null {\n const current = this.current;\n if (current === null) return null;\n const media = this.player.media;\n const ads = current.plan?.ads ?? [];\n const assets = current.entry?.assets ?? [];\n const total = Math.max(1, ads.length || assets.length);\n const time = current.stitched\n ? this.player.media.currentTime - (current.entry?.start ?? 0)\n : media.currentTime;\n const duration = current.stitched\n ? (current.entry?.covers ?? Number.NaN)\n : Number.isFinite(media.duration)\n ? media.duration\n : (current.ad?.duration ?? assets[current.index]?.duration ?? Number.NaN);\n const later = (\n ads.length > 0\n ? ads.map((ad) => ad.duration)\n : assets.map((asset) => asset.duration ?? Number.NaN)\n )\n .slice(current.index + 1)\n .reduce((sum, value) => sum + value, 0);\n const free = this.free(current);\n // A break the stream plays and that sets no rule skips at once when free.\n const skipOffset =\n current.ad?.skipOffset ??\n current.creative?.skipOffset ??\n (current.ad === undefined && !current.stitched ? current.entry?.skipAfter : undefined);\n const clickThrough = current.ad?.clickThrough ?? current.creative?.clickThrough;\n return {\n breakId: current.plan?.id ?? current.entry?.id ?? '',\n index: current.index + 1,\n total,\n currentTime: time,\n duration,\n remaining: duration - time + later,\n skipIn: free ? 0 : skipOffset === undefined ? null : Math.max(0, skipOffset - time),\n ...(clickThrough !== undefined ? { clickThrough } : {}),\n ...(current.ad !== undefined ? { ad: current.ad } : {}),\n stitched: current.stitched,\n role: current.entry?.role === 'promo' ? 'promo' : 'ad',\n free,\n };\n }\n\n /** A break the stream plays itself, with no rule of its own, under `stitched: 'free'`. */\n private free(current: Current): boolean {\n const entry = current.entry;\n return (\n current.stitched &&\n this.stitchedMode === 'free' &&\n entry !== null &&\n !entry.noSkip &&\n !entry.noJump &&\n current.creative?.skipOffset === undefined\n );\n }\n\n watch(fn: () => void): () => void {\n this.watchers.add(fn);\n return () => {\n this.watchers.delete(fn);\n };\n }\n\n /** The schedule the page gave, for the page of a device. Undefined without one. */\n remoteData(): AdsRemoteData | undefined {\n const { urls, breaks } = this.given;\n if (urls.length === 0 && breaks.length === 0) return undefined;\n return {\n ...(urls.length === 0 ? {} : { urls: [...urls] }),\n ...(breaks.length === 0 ? {} : { breaks: [...breaks] }),\n };\n }\n\n /**\n * A device plays in the video's place, and it is not the video itself as\n * under AirPlay. The device's own page plays the ads then, so nothing\n * starts here: the same break would play twice.\n */\n private away(): boolean {\n const target = this.player.casting;\n return target !== null && target.kind !== 'airplay';\n }\n\n async load(source: string): Promise<void> {\n // Absolute, so the ad tags of a VMAP resolve against it.\n const url = new URL(source, location.href).href;\n this.given.urls.push(url);\n let text: string;\n this.fetching += 1;\n try {\n text = await this.fetchDoc(url, new AbortController().signal);\n } catch {\n this.fetching -= 1;\n this.emit('aderror', { code: 900, url });\n this.release();\n return;\n }\n this.fetching -= 1;\n const breaks = parseVmap(text, url);\n if (breaks === null) {\n this.add({ id: 'preroll', offset: 'start', vast: { xml: text }, tracking: [] });\n } else {\n for (const entry of breaks) this.add(entry);\n }\n // A schedule without a pre-roll lets the programme play.\n this.release();\n this.tick();\n }\n\n schedule(breaks: readonly AdBreakInput[]): void {\n this.given.breaks.push(...breaks);\n for (const entry of breaks) {\n this.seq += 1;\n this.add({\n id: entry.id ?? `ad-break-${this.seq}`,\n offset: offsetFrom(entry.offset),\n vast: { url: new URL(entry.vast, location.href).href },\n tracking: [],\n });\n }\n this.tick();\n }\n\n skip(): void {\n const current = this.current;\n const state = this.state;\n if (current === null || state === null || state.skipIn === null || state.skipIn > 0) return;\n if (current.interrupt) {\n current.skipped = true;\n this.track(current, 'skip');\n this.emit('adskip', this.detail());\n this.nextProgressive();\n return;\n }\n current.skipped = true;\n this.track(current, 'skip');\n this.emit('adskip', this.detail());\n if (current.stitched && current.entry !== null) {\n // The stream plays this ad itself: a skip is a seek past it.\n this.player.media.currentTime = current.entry.start + current.entry.covers;\n return;\n }\n this.engineBreaks()?.skip();\n }\n\n click(): void {\n const current = this.current;\n const target = current?.ad?.clickThrough ?? current?.creative?.clickThrough;\n if (current === null || target === undefined) return;\n for (const url of current.ad?.clickTracking ?? []) this.send(expand(url, this.macros(current)));\n this.track(current, 'clickTracking');\n window.open(target, '_blank', 'noopener');\n this.player.media.pause();\n this.emit('adclick', this.detail());\n }\n\n // ---- the schedule ------------------------------------------------------\n\n private add(entry: ScheduledBreak & { readonly covers?: number }): void {\n this.plans.set(entry.id, { ...entry, status: 'waiting', ads: [], files: [] });\n this.mark();\n }\n\n /**\n * The seek bar's ticks: the mid-roll breaks of the engine and of the\n * schedule, spans where a break replaces a part, faded once played. A\n * pre-roll and a post-roll sit at the ends and get none.\n */\n private mark(): void {\n const marks: BreakMark[] = [];\n const engine = this.engineBreaks();\n const ids = new Set<string>();\n for (const entry of engine?.breaks ?? []) {\n ids.add(entry.id);\n if (entry.cue !== undefined) continue;\n if (entry.role !== undefined && entry.role !== 'ad' && entry.role !== 'promo') continue;\n marks.push({\n start: entry.start,\n ...(entry.covers > 0 ? { end: entry.start + entry.covers } : {}),\n ...(this.done.has(entry.id) ? { played: true } : {}),\n });\n }\n const duration = this.programmeDuration();\n for (const plan of this.plans.values()) {\n if (ids.has(plan.id) || plan.offset === 'start' || plan.offset === 'end') continue;\n const at = offsetTime(plan.offset, duration);\n if (at === null) continue;\n marks.push({ start: at, ...(plan.status === 'done' ? { played: true } : {}) });\n }\n this.player.breaks.set('ads', marks);\n this.spans();\n }\n\n /**\n * The credits and chapters a SCTE-35 section names, as the player shows\n * them: the credits as markers, which give Skip intro and Skip credits,\n * beside the page's own, and the chapters in the chapter menu when nothing\n * else gives chapters.\n */\n private spans(): void {\n const breaks = this.engineBreaks()?.breaks ?? [];\n const credits: Marker[] = breaks.flatMap((entry) =>\n (entry.role === 'opening-credits' || entry.role === 'closing-credits') && entry.covers > 0\n ? [{ start: entry.start, end: entry.start + entry.covers, kind: entry.role }]\n : [],\n );\n const markers = this.player.markers;\n const theirs = markers.list.filter((marker) => !this.own.has(marker));\n const same =\n credits.length === this.own.size &&\n [...this.own].every((marker, i) => {\n const next = credits[i];\n return next !== undefined && next.start === marker.start && next.end === marker.end;\n }) &&\n [...this.own].every((marker) => markers.list.includes(marker));\n if (!same) {\n this.own = new Set(credits);\n markers.set([...theirs, ...credits]);\n }\n const chapters = breaks.filter((entry) => entry.role === 'chapter');\n const api = (this.player.engine as { chapters?: ChaptersView } | null)?.chapters;\n if (\n api !== undefined &&\n chapters.length > 0 &&\n api.source !== 'manifest' &&\n api.source !== 'app'\n ) {\n api.set(\n chapters.map((entry, i) => ({\n start: entry.start,\n ...(entry.covers > 0 ? { end: entry.start + entry.covers } : {}),\n title: `${i + 1}`,\n })),\n );\n }\n }\n\n private pending(offset: 'start'): boolean {\n if (this.fetching > 0) return true;\n return [...this.plans.values()].some(\n (plan) =>\n plan.offset === offset && (plan.status === 'waiting' || plan.status === 'resolving'),\n );\n }\n\n private engineBreaks(): InterstitialsApi | undefined {\n return (this.player.engine as { interstitials?: InterstitialsApi } | null)?.interstitials;\n }\n\n /** The programme's own time, through a break. */\n private programmeTime(): number {\n return this.engineBreaks()?.primary.currentTime ?? this.player.media.currentTime;\n }\n\n private programmeDuration(): number {\n return this.engineBreaks()?.primary.duration ?? this.player.media.duration;\n }\n\n /** Fetches the VAST of each break as it comes near, and starts the progressive ones on time. */\n private tick(): void {\n this.update();\n if (this.current !== null) {\n this.followAd(this.current);\n return;\n }\n if (this.away()) return;\n const time = this.programmeTime();\n const duration = this.programmeDuration();\n const seeked = Math.abs(time - this.lastTime) > 2;\n for (const plan of this.plans.values()) {\n const at = offsetTime(plan.offset, duration);\n if (at === null) continue;\n if (plan.status === 'waiting' && (plan.offset === 'start' || at - time <= LOOKAHEAD)) {\n void this.resolve(plan, at);\n } else if (\n plan.status === 'progressive' &&\n plan.offset !== 'end' &&\n !seeked &&\n this.lastTime <= at &&\n time >= at &&\n plan.offset !== 'start'\n ) {\n this.startProgressive(plan);\n break;\n }\n }\n this.lastTime = time;\n }\n\n private async resolve(plan: Plan, at: number): Promise<void> {\n plan.status = 'resolving';\n const result = await resolveVast(plan.vast, this.fetchDoc);\n if (this.plans.get(plan.id) !== plan) return;\n const engine = this.engineBreaks() !== undefined;\n const height = this.player.clientHeight;\n const playable: VastAd[] = [];\n const files: VastMediaFile[] = [];\n for (const ad of result.ads) {\n const file = pick(ad, engine, this.player.media, height);\n if (file === undefined || (!STREAMING.test(file.type) && this.progressive === 'skip')) {\n for (const url of ad.errors) this.send(expand(url, { errorCode: 403 }));\n continue;\n }\n playable.push(ad);\n files.push(file);\n }\n if (result.ads.length === 0) {\n for (const url of result.errors) this.send(expand(url, { errorCode: result.code ?? 303 }));\n }\n plan.ads = playable;\n plan.files = files;\n plan.start = at;\n if (playable.length === 0) {\n plan.status = 'done';\n this.vmapTrack(plan, 'error');\n this.emit('aderror', { id: plan.id, code: result.code ?? 403 });\n this.release();\n return;\n }\n const streams = files.every((file) => STREAMING.test(file.type));\n if (engine && streams) {\n plan.status = 'stream';\n // A skippable ad still takes no seek: the controls skip it from its offset.\n const offsets = playable.flatMap((ad) =>\n ad.skipOffset === undefined ? [] : [ad.skipOffset],\n );\n if (this.holding) {\n this.holding = false;\n void this.player.media.play()?.catch(() => {});\n }\n this.engineBreaks()?.schedule({\n id: plan.id,\n start: at,\n ...(plan.offset === 'start'\n ? { cue: 'pre' as const }\n : plan.offset === 'end'\n ? { cue: 'post' as const }\n : {}),\n ...(plan.covers !== undefined ? { covers: plan.covers } : {}),\n assets: files.map((file, i) => ({\n url: file.url,\n duration: playable[i]?.duration ?? 0,\n mimeType: /dash/i.test(file.type)\n ? 'application/dash+xml'\n : 'application/vnd.apple.mpegurl',\n })),\n noSkip: true,\n noJump: true,\n // An ad server's break plays once per programme, as IMA plays a VMAP.\n once: true,\n ...(offsets.length > 0 ? { skipAfter: Math.min(...offsets) } : {}),\n });\n return;\n }\n plan.status = 'progressive';\n if (plan.offset === 'start' && (this.holding || !this.player.media.paused)) {\n this.holding = false;\n this.player.media.pause();\n this.startProgressive(plan);\n }\n }\n\n /** Lets the programme play once no pre-roll holds it. */\n private release(): void {\n if (!this.holding || this.pending('start')) return;\n this.holding = false;\n void this.player.media.play()?.catch(() => {});\n }\n\n // ---- the engine's breaks -----------------------------------------------\n\n private bindEngine(): void {\n this.offEngine?.();\n this.offEngine = null;\n const engine = this.player.engine;\n if (engine === null || this.engineBreaks() === undefined) return;\n const on = (name: string, fn: (payload: Record<string, unknown>) => void): (() => void) =>\n engine.on(`interstitials:${name}`, (payload) => fn(payload as Record<string, unknown>));\n const offs = [\n on('break-start', (p) => {\n // A drag on the seek bar crosses a break the stream plays at each of\n // its seeks: where the drag ends decides, not each step of it.\n if (p.stitched === true && this.player.hasAttribute('scrubbing')) return;\n this.engineBreakStart(p.break as Break, p.stitched === true);\n }),\n on('asset-start', (p) => this.engineAssetStart(Number(p.asset))),\n on('progress', (p) => this.quartile(Number(p.quartile))),\n on('asset-end', () => this.adEnd()),\n on('break-end', (p) => {\n if (p.stitched === true && this.player.hasAttribute('scrubbing')) return;\n this.breakEnd();\n }),\n on('warning', (p) => {\n const current = this.current;\n if (current?.ad !== undefined) {\n for (const url of current.ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n }\n this.emit('aderror', { id: p.id, code: 405, reason: p.reason });\n }),\n on('opportunity', (p) => this.opportunity(p.break as Break, Number(p.duration))),\n ];\n offs.push(engine.on('interstitials:changed', () => this.mark()));\n this.offEngine = () => {\n for (const off of offs) off();\n };\n this.mark();\n }\n\n /** After a drag: in an ad the stream plays, it starts; out of it, the ad that showed ends. */\n private landed(): void {\n const time = this.player.media.currentTime;\n const inside = (this.engineBreaks()?.breaks ?? []).find(\n (entry) =>\n entry.assets.length === 0 &&\n entry.assetList === undefined &&\n time >= entry.start &&\n time < entry.start + Math.max(entry.covers, 0.001),\n );\n const current = this.current;\n if (current?.stitched === true && current.entry?.id !== inside?.id) this.breakEnd();\n if (inside !== undefined && this.current === null) this.engineBreakStart(inside, true);\n }\n\n private engineBreakStart(entry: Break, stitched: boolean): void {\n const plan = this.plans.get(entry.id) ?? null;\n this.current = {\n plan,\n entry,\n stitched,\n index: -1,\n ad: undefined,\n creative: undefined,\n file: undefined,\n skipped: false,\n quartiles: 0,\n sent: new Set(),\n viewable: false,\n paused: false,\n interrupt: false,\n last: 0,\n at: this.programmeTime(),\n };\n this.breakStart();\n // A break the stream plays itself is one ad, from its start.\n if (stitched) this.engineAssetStart(0);\n }\n\n private engineAssetStart(index: number): void {\n const current = this.current;\n if (current === null) return;\n current.index = index;\n current.ad = current.plan?.ads[index];\n current.creative = current.stitched\n ? current.entry?.creatives?.[0]\n : current.entry?.assets[index]?.creatives?.[0];\n current.file = current.plan?.files[index];\n current.skipped = false;\n current.quartiles = 0;\n current.sent = new Set();\n current.viewable = false;\n this.adStart(current);\n }\n\n private opportunity(entry: Break, duration: number): void {\n const url = this.onOpportunity?.({ id: entry.id, start: entry.start, duration });\n if (url === null || url === undefined) return;\n this.add({\n id: entry.id,\n offset: { time: entry.start },\n vast: { url: new URL(url, location.href).href },\n tracking: [],\n covers: duration,\n });\n const plan = this.plans.get(entry.id);\n if (plan !== undefined) void this.resolve(plan, entry.start);\n }\n\n // ---- progressive ads, on the player's video -------------------------------\n\n /** A break of progressive ads: each in the programme's place, then the programme again. */\n private startProgressive(plan: Plan): void {\n plan.status = 'done';\n this.current = {\n plan,\n entry: null,\n stitched: false,\n index: -1,\n ad: undefined,\n creative: undefined,\n file: undefined,\n skipped: false,\n quartiles: 0,\n sent: new Set(),\n viewable: false,\n paused: false,\n interrupt: true,\n last: 0,\n at: this.programmeTime(),\n };\n this.breakStart();\n this.nextProgressive();\n }\n\n private nextProgressive(): void {\n const current = this.current;\n if (current === null || !current.interrupt || current.plan === null) return;\n if (current.index >= 0) this.adEnd();\n current.index += 1;\n const ad = current.plan.ads[current.index];\n const file = current.plan.files[current.index];\n if (ad === undefined || file === undefined) {\n const plan = current.plan;\n this.breakEnd();\n // After a post-roll the programme comes back on its last frame, paused.\n void this.player.resume(\n plan.offset === 'end' ? { at: plan.start ?? null, playing: false } : { playing: true },\n );\n return;\n }\n current.ad = ad;\n current.file = file;\n current.skipped = false;\n current.quartiles = 0;\n current.sent = new Set();\n current.viewable = false;\n current.paused = false;\n current.last = 0;\n this.player.interrupt({ url: file.url, type: file.type }).catch(() => {\n // No handler plays the file: the next ad, or the programme.\n if (this.current !== current) return;\n for (const url of ad.errors)\n this.send(expand(url, { ...this.macros(current), errorCode: 405 }));\n this.emit('aderror', { id: current.plan?.id, code: 405 });\n this.nextProgressive();\n });\n this.adStart(current);\n }\n\n // ---- one ad ------------------------------------------------------------\n\n private breakStart(): void {\n const current = this.current;\n if (current === null) return;\n // `stitched` keeps the programme's controls; any other ad takes their place.\n this.player.setAttribute('ad', this.free(current) ? 'stitched' : '');\n if (current.plan !== null) this.vmapTrack(current.plan, 'breakStart');\n this.observe();\n this.emit('adbreakstart', this.detail());\n }\n\n private adStart(current: Current): void {\n if (current.ad !== undefined) {\n for (const url of current.ad.impressions) this.send(expand(url, this.macros(current)));\n }\n // SVTA2053 names the impression among its tracking events.\n this.track(current, 'impression');\n this.track(current, 'creativeView');\n this.track(current, 'start');\n this.visibleSince = null;\n this.emit('adstart', this.detail());\n this.update();\n }\n\n private quartile(n: number): void {\n const current = this.current;\n if (current === null || n <= current.quartiles) return;\n current.quartiles = n;\n const event = QUARTILE_EVENTS[n - 1];\n if (event !== undefined) this.track(current, event);\n this.emit('adprogress', { ...this.detail(), quartile: n });\n }\n\n /** The ad's own time: progressive quartiles, progress beacons, the stream's callbacks, viewability. */\n private followAd(current: Current): void {\n const media = this.player.media;\n const time = current.stitched\n ? this.player.media.currentTime - (current.entry?.start ?? 0)\n : media.currentTime;\n if (current.interrupt && !media.seeking) current.last = time;\n if (current.interrupt && Number.isFinite(media.duration) && media.duration > 0) {\n const reached = Math.floor((time / media.duration) * 4);\n for (let n = current.quartiles + 1; n <= Math.min(3, reached); n += 1) this.quartile(n);\n }\n const progress = current.ad?.tracking ?? [];\n progress.forEach((entry, i) => {\n if (\n entry.event !== 'progress' ||\n entry.offset === undefined ||\n current.sent.has(i) ||\n time < entry.offset\n )\n return;\n current.sent.add(i);\n this.send(expand(entry.url, this.macros(current)));\n });\n // DASH callback events of a List MPD, at their offsets in the asset.\n const tracking = current.entry?.assets[current.index]?.tracking ?? [];\n tracking.forEach((entry, i) => {\n const key = 1000 + i;\n if (current.sent.has(key) || time < entry.offset) return;\n current.sent.add(key);\n this.send(entry.url);\n });\n this.view(current);\n }\n\n private adPaused(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null || media.ended || current.paused) return;\n current.paused = true;\n this.track(current, 'pause');\n }\n\n private adResumed(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null || !current.paused || media !== this.player.media) return;\n current.paused = false;\n this.track(current, 'resume');\n }\n\n private adVolume(media: HTMLVideoElement): void {\n const current = this.current;\n if (current === null) return;\n this.track(current, media.muted ? 'mute' : 'unmute');\n }\n\n private adEnd(): void {\n const current = this.current;\n if (current === null || current.index < 0) return;\n if (!current.skipped) this.track(current, 'complete');\n if (current.ad !== undefined && !current.viewable) {\n for (const url of current.ad.notViewable) this.send(expand(url, this.macros(current)));\n }\n this.emit('adend', this.detail());\n }\n\n private breakEnd(): void {\n const current = this.current;\n if (current === null) return;\n // A break the stream plays has no asset of its own to end.\n if (current.stitched) this.adEnd();\n if (current.plan !== null) {\n current.plan.status = 'done';\n this.vmapTrack(current.plan, 'breakEnd');\n }\n const detail = this.detail();\n const id = current.plan?.id ?? current.entry?.id;\n if (id !== undefined) this.done.add(id);\n this.current = null;\n this.player.removeAttribute('ad');\n this.mark();\n this.observer?.disconnect();\n this.observer = null;\n this.emit('adbreakend', detail);\n this.update();\n }\n\n // ---- viewability -------------------------------------------------------\n\n /** MRC: half the player in view for two seconds in a row. */\n private observe(): void {\n if (typeof IntersectionObserver === 'undefined' || this.observer !== null) return;\n this.observer = new IntersectionObserver(\n (entries) => {\n const seen = entries.some((entry) => entry.intersectionRatio >= 0.5);\n this.visibleSince = seen ? (this.visibleSince ?? performance.now()) : null;\n },\n { threshold: [0, 0.5] },\n );\n this.observer.observe(this.player);\n }\n\n private view(current: Current): void {\n if (current.viewable || current.ad === undefined || this.visibleSince === null) return;\n if (performance.now() - this.visibleSince < 2000) return;\n current.viewable = true;\n for (const url of current.ad.viewable) this.send(expand(url, this.macros(current)));\n this.emit('adviewable', this.detail());\n }\n\n // ---- beacons and events ------------------------------------------------\n\n private macros(current: Current): MacroValues {\n const media = this.player.media;\n const offset = current.plan?.offset;\n return {\n mediaPlayhead: current.at,\n adPlayhead: media.currentTime,\n ...(current.file !== undefined ? { assetUri: current.file.url } : {}),\n breakPosition: offset === 'start' ? 1 : offset === 'end' ? 3 : 2,\n playerSize: [this.player.clientWidth, this.player.clientHeight],\n };\n }\n\n private track(current: Current, event: string): void {\n for (const entry of current.ad?.tracking ?? []) {\n if (entry.event === event) this.send(expand(entry.url, this.macros(current)));\n }\n }\n\n private vmapTrack(plan: Plan, event: string): void {\n for (const entry of plan.tracking) if (entry.event === event) this.send(entry.url);\n }\n\n private detail(): Record<string, unknown> {\n const current = this.current;\n return {\n breakId: current?.plan?.id ?? current?.entry?.id ?? null,\n index: (current?.index ?? 0) + 1,\n ad: current?.ad ?? null,\n stitched: current?.stitched ?? false,\n };\n }\n\n private emit(name: string, detail: object): void {\n this.player.dispatchEvent(new CustomEvent(name, { detail }));\n }\n\n private update(): void {\n for (const fn of [...this.watchers]) fn();\n }\n\n private reset(): void {\n const current = this.current;\n if (current !== null) this.player.removeAttribute('ad');\n this.current = null;\n this.plans = new Map();\n this.given = { urls: [], breaks: [] };\n this.done = new Set();\n this.own = new Set();\n this.player.breaks.set('ads', []);\n this.holding = false;\n this.lastTime = 0;\n this.observer?.disconnect();\n this.observer = null;\n this.update();\n }\n}\n"],"mappings":";;;;;AA6GA,MAAM,YAAY;AAClB,MAAM,kBAAkB;CAAC;CAAiB;CAAY;AAAe;;AAErE,MAAM,4BAAY,IAAI,IAAI;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACL,CAAC;AACD,MAAM,YAAY;AA6ClB,MAAM,8BAAc,IAAI,QAAgC;;AAGxD,SAAgB,cAAc,QAAoB,SAAkC;CAClF,IAAI,QAAQ,YAAY,IAAI,MAAM;CAClC,IAAI,UAAU,KAAA,GAAW;EACvB,QAAQ,IAAI,WAAW,QAAQ,WAAW,CAAC,CAAC;EAC5C,YAAY,IAAI,QAAQ,KAAK;CAC/B,OAAO,IAAI,YAAY,KAAA,GAErB,MAAM,UAAU,OAAO;CAEzB,OAAO;AACT;;AAGA,SAAS,WAAW,OAA4C;CAC9D,IAAI,UAAU,WAAW,UAAU,OAAO,OAAO;CACjD,IAAI,OAAO,UAAU,UAAU,OAAO,EAAE,MAAM,MAAM;CACpD,IAAI,MAAM,SAAS,GAAG,GAAG,OAAO,EAAE,SAAS,OAAO,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE;CAEtE,OAAO,EAAE,MADK,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAChB,CAAC,CAAC,QAAQ,KAAK,SAAS,MAAM,KAAK,MAAM,CAAC,EAAE;AACjE;;AAGA,SAAS,KACP,IACA,QACA,OACA,QAC2B;CAC3B,MAAM,SAAS,GAAG,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Q,UAAU,MAAY,OAAqB;EACjD,KAAK,MAAM,SAAS,KAAK,UAAU,IAAI,MAAM,UAAU,OAAO,KAAK,KAAK,MAAM,GAAG;CACnF;CAEQ,SAAkC;EACxC,MAAM,UAAU,KAAK;EACrB,OAAO;GACL,SAAS,SAAS,MAAM,MAAM,SAAS,OAAO,MAAM;GACpD,QAAQ,SAAS,SAAS,KAAK;GAC/B,IAAI,SAAS,MAAM;GACnB,UAAU,SAAS,YAAY;EACjC;CACF;CAEQ,KAAK,MAAc,QAAsB;EAC/C,KAAK,OAAO,cAAc,IAAI,YAAY,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7D;CAEQ,SAAe;EACrB,KAAK,MAAM,MAAM,CAAC,GAAG,KAAK,QAAQ,GAAG,GAAG;CAC1C;CAEQ,QAAc;EAEpB,IADgB,KAAK,YACL,MAAM,KAAK,OAAO,gBAAgB,IAAI;EACtD,KAAK,UAAU;EACf,KAAK,wBAAQ,IAAI,IAAI;EACrB,KAAK,QAAQ;GAAE,MAAM,CAAC;GAAG,QAAQ,CAAC;EAAE;EACpC,KAAK,uBAAO,IAAI,IAAI;EACpB,KAAK,sBAAM,IAAI,IAAI;EACnB,KAAK,OAAO,OAAO,IAAI,OAAO,CAAC,CAAC;EAChC,KAAK,UAAU;EACf,KAAK,WAAW;EAChB,KAAK,UAAU,WAAW;EAC1B,KAAK,WAAW;EAChB,KAAK,OAAO;CACd;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import toPropertyKey from "./toPropertyKey.js";
|
|
2
|
-
// \0@oxc-project+runtime@0.
|
|
2
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
3
3
|
function _defineProperty(e, r, t) {
|
|
4
4
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
5
5
|
value: t,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "./defineProperty.js";
|
|
2
|
-
// \0@oxc-project+runtime@0.
|
|
2
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/objectSpread2.js
|
|
3
3
|
function ownKeys(e, r) {
|
|
4
4
|
var t = Object.keys(e);
|
|
5
5
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _typeof from "./typeof.js";
|
|
2
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
3
|
+
function toPrimitive(t, e) {
|
|
4
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
5
|
+
var r;
|
|
6
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
7
|
+
var i = r.call(t, e || "default");
|
|
8
|
+
if ("object" != _typeof(i)) return i;
|
|
9
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
10
|
+
}
|
|
11
|
+
return ("string" === e ? String : Number)(t);
|
|
12
|
+
}
|
|
13
|
+
export { toPrimitive as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _typeof from "./typeof.js";
|
|
2
2
|
import toPrimitive from "./toPrimitive.js";
|
|
3
|
-
// \0@oxc-project+runtime@0.
|
|
3
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
4
4
|
function toPropertyKey(t) {
|
|
5
5
|
var i = toPrimitive(t, "string");
|
|
6
6
|
return "symbol" == _typeof(i) ? i : i + "";
|
package/dist/es2015/component.js
CHANGED
|
@@ -15,14 +15,14 @@ var Component = class extends HTMLElement {
|
|
|
15
15
|
const attach = () => {
|
|
16
16
|
if (epoch !== this.epoch || !this.isConnected) return;
|
|
17
17
|
customElements.upgrade(found);
|
|
18
|
-
if (!("
|
|
18
|
+
if (!("media" in found)) return;
|
|
19
19
|
this.player = found;
|
|
20
20
|
this.listen(found, ["localechange"], () => {
|
|
21
21
|
this.render();
|
|
22
22
|
});
|
|
23
23
|
this.attach(this.player);
|
|
24
24
|
};
|
|
25
|
-
if ("
|
|
25
|
+
if ("media" in found) attach();
|
|
26
26
|
else customElements.whenDefined(PLAYER).then(attach);
|
|
27
27
|
}
|
|
28
28
|
disconnectedCallback() {
|