mattebox 0.16.2 → 0.17.1
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/cdn/mattebox.dash-drm.min.js +3 -3
- package/dist/cdn/mattebox.dash-ll.min.js +3 -3
- package/dist/cdn/mattebox.dash.min.js +3 -3
- package/dist/cdn/mattebox.dual-drm.min.js +3 -3
- package/dist/cdn/mattebox.dual-ll.min.js +3 -3
- package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
- package/dist/cdn/mattebox.dual-ts.min.js +3 -3
- package/dist/cdn/mattebox.dual.min.js +3 -3
- package/dist/cdn/mattebox.hls-drm.min.js +3 -3
- package/dist/cdn/mattebox.hls-ll.min.js +3 -3
- package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
- package/dist/cdn/mattebox.hls-ts.min.js +3 -3
- package/dist/cdn/mattebox.hls.min.js +3 -3
- package/dist/cdn/mattebox.kernel.min.js +1 -1
- package/dist/cdn/mattebox.min.js +5 -5
- package/dist/containers/emsg.d.ts +16 -0
- package/dist/containers/emsg.d.ts.map +1 -1
- package/dist/containers/emsg.js +31 -1
- package/dist/containers/emsg.js.map +1 -1
- package/dist/eme/index.d.ts.map +1 -1
- package/dist/eme/index.js +2 -0
- package/dist/eme/index.js.map +1 -1
- package/dist/es2015/containers/emsg.js +28 -2
- package/dist/es2015/eme/index.js +8 -0
- package/dist/es2015/index.js +6 -4
- package/dist/es2015/kernel/context.js +6 -0
- package/dist/es2015/kernel/dry-run.js +2 -2
- package/dist/es2015/kernel/reducer.js +60 -7
- package/dist/es2015/protocols/dash-cmaf/parse.js +17 -2
- package/dist/es2015/protocols/hls-cmaf/parse.js +58 -2
- package/dist/es2015/stages/interstitials/breaks.js +341 -0
- package/dist/es2015/stages/interstitials/index.js +750 -0
- package/dist/es2015/stages/timed-metadata/index.js +10 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/kernel/context.d.ts.map +1 -1
- package/dist/kernel/context.js +8 -0
- package/dist/kernel/context.js.map +1 -1
- package/dist/kernel/dry-run.d.ts +2 -0
- package/dist/kernel/dry-run.d.ts.map +1 -1
- package/dist/kernel/dry-run.js +1 -0
- package/dist/kernel/dry-run.js.map +1 -1
- package/dist/kernel/reducer.d.ts.map +1 -1
- package/dist/kernel/reducer.js +60 -4
- package/dist/kernel/reducer.js.map +1 -1
- package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
- package/dist/protocols/dash-cmaf/parse.js +16 -0
- package/dist/protocols/dash-cmaf/parse.js.map +1 -1
- package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/parse.js +75 -4
- package/dist/protocols/hls-cmaf/parse.js.map +1 -1
- package/dist/stages/interstitials/breaks.d.ts +113 -0
- package/dist/stages/interstitials/breaks.d.ts.map +1 -0
- package/dist/stages/interstitials/breaks.js +390 -0
- package/dist/stages/interstitials/breaks.js.map +1 -0
- package/dist/stages/interstitials/index.d.ts +57 -0
- package/dist/stages/interstitials/index.d.ts.map +1 -0
- package/dist/stages/interstitials/index.js +853 -0
- package/dist/stages/interstitials/index.js.map +1 -0
- package/dist/stages/timed-metadata/index.d.ts.map +1 -1
- package/dist/stages/timed-metadata/index.js +10 -27
- package/dist/stages/timed-metadata/index.js.map +1 -1
- package/dist/types/facade.d.ts +2 -19
- package/dist/types/facade.d.ts.map +1 -1
- package/dist/types/ir.d.ts +13 -1
- package/dist/types/ir.d.ts.map +1 -1
- package/dist/types/kernel.d.ts +11 -0
- package/dist/types/kernel.d.ts.map +1 -1
- package/dist/types/load.d.ts +28 -0
- package/dist/types/load.d.ts.map +1 -0
- package/dist/types/load.js +3 -0
- package/dist/types/load.js.map +1 -0
- package/dist/types/messages.d.ts +2 -0
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/stage.d.ts +10 -0
- package/dist/types/stage.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import { scte35Summary } from "../../containers/scte35.js";
|
|
3
|
+
import { resolveUrl } from "../../kernel/url.js";
|
|
4
|
+
// src/stages/interstitials/breaks.ts
|
|
5
|
+
/**
|
|
6
|
+
* Breaks from what the stream signals, as plain data. HLS interstitials
|
|
7
|
+
* (draft-pantos-hls-rfc8216bis Appendix D), DASH alternative MPD events
|
|
8
|
+
* (ISO/IEC 23009-1 6th edition), and SCTE-35 cue-outs in either protocol
|
|
9
|
+
* become one descriptor, so one schedule plays them all. Nothing here
|
|
10
|
+
* touches the element or the network.
|
|
11
|
+
*/
|
|
12
|
+
const INTERSTITIAL = "com.apple.hls.interstitial";
|
|
13
|
+
const ALT_INSERT = "urn:mpeg:dash:event:alternativeMPD:insert:2025";
|
|
14
|
+
const ALT_REPLACE = "urn:mpeg:dash:event:alternativeMPD:replace:2025";
|
|
15
|
+
/** SCTE 214-1 §6.6 and §6.7: a splice in binary (base64) or in XML. */
|
|
16
|
+
const SCTE35_SCHEMES = /* @__PURE__ */ new Set(["urn:scte:scte35:2013:bin", "urn:scte:scte35:2014:xml+bin"]);
|
|
17
|
+
/**
|
|
18
|
+
* The role of each segmentation_type_id that starts a span, by ANSI/SCTE 35's
|
|
19
|
+
* table of them: a break, an ad, a placement opportunity, an ad block, a
|
|
20
|
+
* promotion, the credits, a chapter. The end ids, the programme's
|
|
21
|
+
* boundaries, overlays, unscheduled events and the network's start and end
|
|
22
|
+
* start no span the viewer sees.
|
|
23
|
+
*/
|
|
24
|
+
const ROLES = /* @__PURE__ */ new Map([
|
|
25
|
+
[32, "chapter"],
|
|
26
|
+
[34, "ad"],
|
|
27
|
+
[36, "opening-credits"],
|
|
28
|
+
[38, "closing-credits"],
|
|
29
|
+
[48, "ad"],
|
|
30
|
+
[50, "ad"],
|
|
31
|
+
[52, "ad"],
|
|
32
|
+
[54, "ad"],
|
|
33
|
+
[60, "promo"],
|
|
34
|
+
[62, "promo"],
|
|
35
|
+
[68, "ad"],
|
|
36
|
+
[70, "ad"]
|
|
37
|
+
]);
|
|
38
|
+
/**
|
|
39
|
+
* The role and the length a SCTE-35 section gives a span: the first of its
|
|
40
|
+
* segmentation descriptors with a role, the outermost, as SCTE 35 nests
|
|
41
|
+
* them. A section without descriptors, a splice_insert, is an ad break. Null
|
|
42
|
+
* for a section whose descriptors start no span the viewer sees.
|
|
43
|
+
*/
|
|
44
|
+
function roleOf(summary) {
|
|
45
|
+
if (summary === null || summary.segmentations.length === 0) return { role: "ad" };
|
|
46
|
+
for (const segmentation of summary.segmentations) {
|
|
47
|
+
if (segmentation.cancel || segmentation.typeId === void 0) continue;
|
|
48
|
+
const role = ROLES.get(segmentation.typeId);
|
|
49
|
+
if (role !== void 0) return segmentation.duration === void 0 ? { role } : {
|
|
50
|
+
role,
|
|
51
|
+
duration: segmentation.duration
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/** SVTA2053-1: the creatives of a span, as JSON in a DASH Event. */
|
|
57
|
+
const AD_CREATIVES = "urn:svta:advertising-wg:ad-creative-signaling";
|
|
58
|
+
/**
|
|
59
|
+
* The creatives of an SVTA2053 payload, version 2: JSON with a `payload`
|
|
60
|
+
* list of creatives, each with `identifiers`, `tracking` (a `type` and
|
|
61
|
+
* its `urls`), `duration`, `skipOffset` and `clickThrough`. HLS carries it
|
|
62
|
+
* in `X-AD-CREATIVE-SIGNALING`, base64 or as written. Nothing for a
|
|
63
|
+
* payload that does not read.
|
|
64
|
+
*/
|
|
65
|
+
function creativesOf(text) {
|
|
66
|
+
if (text === void 0 || text === "") return [];
|
|
67
|
+
let value;
|
|
68
|
+
try {
|
|
69
|
+
value = JSON.parse(text);
|
|
70
|
+
} catch (_unused) {
|
|
71
|
+
try {
|
|
72
|
+
value = JSON.parse(atob(text.replace(/-/g, "+").replace(/_/g, "/")));
|
|
73
|
+
} catch (_unused2) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const list = value === null || value === void 0 ? void 0 : value.payload;
|
|
78
|
+
if (!Array.isArray(list)) return [];
|
|
79
|
+
return list.flatMap((item) => {
|
|
80
|
+
if (item === null || typeof item !== "object") return [];
|
|
81
|
+
const tracking = (Array.isArray(item.tracking) ? item.tracking : []).flatMap((entry) => typeof (entry === null || entry === void 0 ? void 0 : entry.type) === "string" && Array.isArray(entry.urls) ? entry.urls.filter((url) => typeof url === "string").map((url) => ({
|
|
82
|
+
event: entry.type,
|
|
83
|
+
url
|
|
84
|
+
})) : []);
|
|
85
|
+
const identifiers = (Array.isArray(item.identifiers) ? item.identifiers : []).filter((id) => typeof (id === null || id === void 0 ? void 0 : id.scheme) === "string" && typeof id.value === "string");
|
|
86
|
+
return [_objectSpread2(_objectSpread2(_objectSpread2({}, typeof item.duration === "number" ? { duration: item.duration } : {}), {}, {
|
|
87
|
+
identifiers,
|
|
88
|
+
tracking
|
|
89
|
+
}, typeof item.skipOffset === "number" ? { skipOffset: item.skipOffset } : {}), typeof item.clickThrough === "string" ? { clickThrough: item.clickThrough } : {})];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Seconds from a number or an xs:duration such as `PT5S`; undefined otherwise. */
|
|
93
|
+
function seconds(text) {
|
|
94
|
+
var _match$, _match$2, _match$3;
|
|
95
|
+
if (text === void 0 || text === "") return void 0;
|
|
96
|
+
const plain = Number(text);
|
|
97
|
+
if (Number.isFinite(plain)) return plain;
|
|
98
|
+
const match = /^PT(?:([\d.]+)H)?(?:([\d.]+)M)?(?:([\d.]+)S)?$/.exec(text);
|
|
99
|
+
if (match === null) return void 0;
|
|
100
|
+
return Number((_match$ = match[1]) !== null && _match$ !== void 0 ? _match$ : 0) * 3600 + Number((_match$2 = match[2]) !== null && _match$2 !== void 0 ? _match$2 : 0) * 60 + Number((_match$3 = match[3]) !== null && _match$3 !== void 0 ? _match$3 : 0);
|
|
101
|
+
}
|
|
102
|
+
function hexBytes(value) {
|
|
103
|
+
if (value === void 0 || !/^0x([0-9a-f]{2})+$/i.test(value)) return void 0;
|
|
104
|
+
const out = new Uint8Array((value.length - 2) / 2);
|
|
105
|
+
for (let i = 0; i < out.length; i += 1) out[i] = Number.parseInt(value.slice(2 + i * 2, 4 + i * 2), 16);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
function base64Bytes(text) {
|
|
109
|
+
if (text === void 0) return void 0;
|
|
110
|
+
try {
|
|
111
|
+
const binary = atob(text.replace(/\s+/g, ""));
|
|
112
|
+
return Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
113
|
+
} catch (_unused3) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** An HLS interstitial date range, or a cue-out date range, as a break. */
|
|
118
|
+
function fromDateRange(range, base, duration) {
|
|
119
|
+
var _ref;
|
|
120
|
+
const a = range.attributes;
|
|
121
|
+
const span = range.end !== void 0 ? range.end - range.start : void 0;
|
|
122
|
+
if (a.CLASS === INTERSTITIAL && (a["X-ASSET-URI"] !== void 0 || a["X-ASSET-LIST"] !== void 0)) {
|
|
123
|
+
var _a$CUE, _a$XRESTRICT, _a$XSNAP, _seconds;
|
|
124
|
+
const cues = ((_a$CUE = a.CUE) !== null && _a$CUE !== void 0 ? _a$CUE : "").split(",");
|
|
125
|
+
const cue = cues.includes("PRE") ? "pre" : cues.includes("POST") ? "post" : void 0;
|
|
126
|
+
const restrict = ((_a$XRESTRICT = a["X-RESTRICT"]) !== null && _a$XRESTRICT !== void 0 ? _a$XRESTRICT : "").split(",");
|
|
127
|
+
const covers = a["X-TIMELINE-OCCUPIES"] === "RANGE" ? span !== null && span !== void 0 ? span : 0 : 0;
|
|
128
|
+
const limit = seconds(a["X-PLAYOUT-LIMIT"]);
|
|
129
|
+
const skipAfter = seconds(a["X-SKIP-CONTROL-OFFSET"]);
|
|
130
|
+
const snap = ((_a$XSNAP = a["X-SNAP"]) !== null && _a$XSNAP !== void 0 ? _a$XSNAP : "").split(",");
|
|
131
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
132
|
+
id: range.id,
|
|
133
|
+
source: "hls",
|
|
134
|
+
start: cue === "pre" ? 0 : cue === "post" ? duration !== null && duration !== void 0 ? duration : range.start : range.start
|
|
135
|
+
}, cue !== void 0 ? { cue } : {}), {}, {
|
|
136
|
+
once: cues.includes("ONCE"),
|
|
137
|
+
assets: a["X-ASSET-URI"] !== void 0 ? [{ url: resolveUrl(a["X-ASSET-URI"], base) }] : []
|
|
138
|
+
}, a["X-ASSET-LIST"] !== void 0 ? { assetList: resolveUrl(a["X-ASSET-LIST"], base) } : {}), {}, {
|
|
139
|
+
covers,
|
|
140
|
+
resumeOffset: (_seconds = seconds(a["X-RESUME-OFFSET"])) !== null && _seconds !== void 0 ? _seconds : cue === void 0 ? span !== null && span !== void 0 ? span : 0 : 0
|
|
141
|
+
}, limit !== void 0 ? { playoutLimit: limit } : {}), {}, {
|
|
142
|
+
noSkip: restrict.includes("SKIP"),
|
|
143
|
+
noJump: restrict.includes("JUMP")
|
|
144
|
+
}, skipAfter !== void 0 ? { skipAfter } : {}), snap.includes("OUT") || snap.includes("IN") ? { snap: {
|
|
145
|
+
out: snap.includes("OUT"),
|
|
146
|
+
in: snap.includes("IN")
|
|
147
|
+
} } : {}), withCreatives(creativesOf(a["X-AD-CREATIVE-SIGNALING"]))), {}, { attributes: a });
|
|
148
|
+
}
|
|
149
|
+
const creatives = creativesOf(a["X-AD-CREATIVE-SIGNALING"]);
|
|
150
|
+
const section = hexBytes(a["SCTE35-OUT"]);
|
|
151
|
+
if (section === void 0 && a["CUE-OUT"] === void 0) {
|
|
152
|
+
const found = opportunity(range.id, range.start, span !== null && span !== void 0 ? span : 0, null, a);
|
|
153
|
+
return creatives.length === 0 || found === null ? null : _objectSpread2(_objectSpread2({}, found), {}, {
|
|
154
|
+
source: "hls",
|
|
155
|
+
creatives
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const summary = section === void 0 ? null : scte35Summary(section);
|
|
159
|
+
const planned = range.plannedEnd !== void 0 ? range.plannedEnd - range.start : void 0;
|
|
160
|
+
const found = opportunity(range.id, range.start, (_ref = span !== null && span !== void 0 ? span : planned) !== null && _ref !== void 0 ? _ref : 0, summary, a);
|
|
161
|
+
return found === null ? null : _objectSpread2(_objectSpread2({}, found), withCreatives(creatives));
|
|
162
|
+
}
|
|
163
|
+
const withCreatives = (creatives) => creatives.length > 0 ? { creatives } : {};
|
|
164
|
+
/**
|
|
165
|
+
* A span the stream plays itself, from a cue-out or a SCTE-35 section: its
|
|
166
|
+
* length is the stream's, else the section's. Null for a section that
|
|
167
|
+
* starts no span the viewer sees.
|
|
168
|
+
*/
|
|
169
|
+
function opportunity(id, start, length, summary, attributes) {
|
|
170
|
+
var _ref2, _role$duration;
|
|
171
|
+
const role = roleOf(summary);
|
|
172
|
+
if (role === null) return null;
|
|
173
|
+
const covers = length > 0 ? length : (_ref2 = (_role$duration = role.duration) !== null && _role$duration !== void 0 ? _role$duration : summary === null || summary === void 0 ? void 0 : summary.breakDuration) !== null && _ref2 !== void 0 ? _ref2 : 0;
|
|
174
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({
|
|
175
|
+
id,
|
|
176
|
+
source: "scte35",
|
|
177
|
+
start,
|
|
178
|
+
once: false,
|
|
179
|
+
assets: [],
|
|
180
|
+
covers,
|
|
181
|
+
resumeOffset: covers,
|
|
182
|
+
noSkip: false,
|
|
183
|
+
noJump: false
|
|
184
|
+
}, summary !== null ? { scte35: summary } : {}), role.role !== "ad" ? { role: role.role } : {}), {}, { attributes });
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Annex I of ISO/IEC 23009-1: a `RequestParam` with `useMPDUrlQuery`
|
|
188
|
+
* whose template holds `$querypart$` carries the MPD URL's query to the
|
|
189
|
+
* requests it names. livesim2 sends a viewer's `sessionId` and `interests`
|
|
190
|
+
* to its ad server this way.
|
|
191
|
+
*/
|
|
192
|
+
function withQuery(url, params, kind, mpd) {
|
|
193
|
+
const param = params.find((p) => {
|
|
194
|
+
var _p$attributes$queryTe, _p$attributes$include;
|
|
195
|
+
return p.name === "RequestParam" && p.attributes.useMPDUrlQuery === "true" && ((_p$attributes$queryTe = p.attributes.queryTemplate) !== null && _p$attributes$queryTe !== void 0 ? _p$attributes$queryTe : "").includes("$querypart$") && ((_p$attributes$include = p.attributes.includeInRequests) !== null && _p$attributes$include !== void 0 ? _p$attributes$include : "").split(" ").includes(kind);
|
|
196
|
+
});
|
|
197
|
+
const query = mpd.includes("?") ? mpd.slice(mpd.indexOf("?") + 1) : "";
|
|
198
|
+
if (param === void 0 || query === "") return url;
|
|
199
|
+
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
200
|
+
}
|
|
201
|
+
/** A DASH alternative MPD event, or an SCTE-35 event, as a break. */
|
|
202
|
+
function fromEvent(event, mpd) {
|
|
203
|
+
var _event$duration3;
|
|
204
|
+
if (event.scheme === ALT_INSERT || event.scheme === ALT_REPLACE) {
|
|
205
|
+
var _event$elements, _element$attributes$u, _event$timescale, _event$duration, _ticks, _event$streamElements;
|
|
206
|
+
const element = (_event$elements = event.elements) === null || _event$elements === void 0 ? void 0 : _event$elements.find((e) => e.name === "InsertPresentation" || e.name === "ReplacePresentation");
|
|
207
|
+
const uri = (_element$attributes$u = element === null || element === void 0 ? void 0 : element.attributes.uri) !== null && _element$attributes$u !== void 0 ? _element$attributes$u : element === null || element === void 0 ? void 0 : element.attributes.url;
|
|
208
|
+
if (element === void 0 || uri === void 0) return null;
|
|
209
|
+
const a = element.attributes;
|
|
210
|
+
const scale = (_event$timescale = event.timescale) !== null && _event$timescale !== void 0 ? _event$timescale : 1;
|
|
211
|
+
const ticks = (name) => {
|
|
212
|
+
const value = Number(a[name]);
|
|
213
|
+
return Number.isFinite(value) && a[name] !== void 0 ? value / scale : void 0;
|
|
214
|
+
};
|
|
215
|
+
const replace = event.scheme === ALT_REPLACE;
|
|
216
|
+
const length = (_event$duration = event.duration) !== null && _event$duration !== void 0 ? _event$duration : 0;
|
|
217
|
+
const limit = ticks("maxDuration");
|
|
218
|
+
const ahead = ticks("earliestResolutionTimeOffset");
|
|
219
|
+
const skipAfter = seconds(a.skipAfter);
|
|
220
|
+
const resume = (_ticks = ticks("returnOffset")) !== null && _ticks !== void 0 ? _ticks : replace ? length : 0;
|
|
221
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
222
|
+
id: event.id,
|
|
223
|
+
source: "dash",
|
|
224
|
+
start: event.start,
|
|
225
|
+
once: a.executeOnce === "true",
|
|
226
|
+
assets: [],
|
|
227
|
+
assetList: withQuery(resolveUrl(uri, mpd), (_event$streamElements = event.streamElements) !== null && _event$streamElements !== void 0 ? _event$streamElements : [], "altmpd", mpd),
|
|
228
|
+
covers: replace ? length : 0,
|
|
229
|
+
resumeOffset: resume
|
|
230
|
+
}, limit !== void 0 ? { playoutLimit: limit } : {}), {}, {
|
|
231
|
+
noSkip: false,
|
|
232
|
+
noJump: a.noJump !== void 0 && a.noJump !== "0"
|
|
233
|
+
}, skipAfter !== void 0 ? { skipAfter } : {}), ahead !== void 0 ? { resolveAhead: ahead } : {}), {}, { attributes: a });
|
|
234
|
+
}
|
|
235
|
+
if (event.scheme === AD_CREATIVES) {
|
|
236
|
+
var _ref3, _event$duration2, _creatives$;
|
|
237
|
+
const creatives = creativesOf(event.data);
|
|
238
|
+
const length = (_ref3 = (_event$duration2 = event.duration) !== null && _event$duration2 !== void 0 ? _event$duration2 : (_creatives$ = creatives[0]) === null || _creatives$ === void 0 ? void 0 : _creatives$.duration) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
239
|
+
const found = opportunity(`${event.scheme}|${event.id}`, event.start, length, null, {});
|
|
240
|
+
if (creatives.length === 0 || length <= 0 || found === null) return null;
|
|
241
|
+
return _objectSpread2(_objectSpread2({}, found), {}, {
|
|
242
|
+
source: "dash",
|
|
243
|
+
creatives
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (!SCTE35_SCHEMES.has(event.scheme)) return null;
|
|
247
|
+
const section = base64Bytes(event.data);
|
|
248
|
+
const summary = section === void 0 ? null : scte35Summary(section);
|
|
249
|
+
const found = opportunity(`${event.scheme}|${event.id}`, event.start, (_event$duration3 = event.duration) !== null && _event$duration3 !== void 0 ? _event$duration3 : 0, summary, {});
|
|
250
|
+
if (found === null || found.covers <= 0 && (summary === null || summary === void 0 ? void 0 : summary.outOfNetwork) !== true) return null;
|
|
251
|
+
return found;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Every break the presentation signals now, by start. Date ranges merge
|
|
255
|
+
* by ID across renditions, as RFC 8216bis §4.4.5.1 merges later tags:
|
|
256
|
+
* attributes add, none changes. Relative URIs resolve against the media
|
|
257
|
+
* playlist that carried them, or the MPD.
|
|
258
|
+
*/
|
|
259
|
+
function breaksOf(presentation, url) {
|
|
260
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
261
|
+
const out = [];
|
|
262
|
+
for (const period of presentation.periods) {
|
|
263
|
+
var _period$events;
|
|
264
|
+
for (const track of period.tracks) for (const rendition of track.renditions) {
|
|
265
|
+
var _rendition$dateRanges;
|
|
266
|
+
for (const range of (_rendition$dateRanges = rendition.dateRanges) !== null && _rendition$dateRanges !== void 0 ? _rendition$dateRanges : []) {
|
|
267
|
+
var _ref4, _known$base;
|
|
268
|
+
const known = ranges.get(range.id);
|
|
269
|
+
ranges.set(range.id, {
|
|
270
|
+
range: known === void 0 ? range : _objectSpread2(_objectSpread2(_objectSpread2({}, known.range), known.range.end === void 0 && range.end !== void 0 ? { end: range.end } : {}), {}, { attributes: _objectSpread2(_objectSpread2({}, range.attributes), known.range.attributes) }),
|
|
271
|
+
base: (_ref4 = (_known$base = known === null || known === void 0 ? void 0 : known.base) !== null && _known$base !== void 0 ? _known$base : rendition.playlistUrl) !== null && _ref4 !== void 0 ? _ref4 : url
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
for (const event of (_period$events = period.events) !== null && _period$events !== void 0 ? _period$events : []) {
|
|
276
|
+
const entry = fromEvent(event, url);
|
|
277
|
+
if (entry !== null) out.push(entry);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (const { range, base } of ranges.values()) {
|
|
281
|
+
const entry = fromDateRange(range, base, presentation.duration);
|
|
282
|
+
if (entry !== null) out.push(entry);
|
|
283
|
+
}
|
|
284
|
+
return out.sort((a, b) => a.start - b.start || a.id.localeCompare(b.id));
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The assets an asset list names. An HLS asset list is JSON with an
|
|
288
|
+
* `ASSETS` array of `URI` and `DURATION` (Appendix D). A DASH List MPD
|
|
289
|
+
* imports each asset as an `ImportedMPD` in a Period, with its callback
|
|
290
|
+
* events as beacons (ISO/IEC 23009-1 6th edition). Any other MPD is the
|
|
291
|
+
* asset itself.
|
|
292
|
+
*/
|
|
293
|
+
function assetsOf(text, url) {
|
|
294
|
+
const trimmed = text.trimStart();
|
|
295
|
+
if (trimmed.startsWith("{")) {
|
|
296
|
+
var _list$ASSETS;
|
|
297
|
+
return ((_list$ASSETS = JSON.parse(trimmed).ASSETS) !== null && _list$ASSETS !== void 0 ? _list$ASSETS : []).flatMap((asset) => asset.URI === void 0 ? [] : [_objectSpread2({ url: resolveUrl(asset.URI, url) }, typeof asset.DURATION === "number" ? { duration: asset.DURATION } : {})]);
|
|
298
|
+
}
|
|
299
|
+
const mpd = new DOMParser().parseFromString(text, "application/xml").documentElement;
|
|
300
|
+
if (mpd === null || mpd.localName !== "MPD" || mpd.getAttribute("type") !== "list") return [{
|
|
301
|
+
url,
|
|
302
|
+
mimeType: "application/dash+xml"
|
|
303
|
+
}];
|
|
304
|
+
const assets = [];
|
|
305
|
+
for (const period of Array.from(mpd.children).filter((e) => e.localName === "Period")) {
|
|
306
|
+
var _imported$getAttribut, _imported$textContent, _period$getAttribute;
|
|
307
|
+
const imported = Array.from(period.children).find((e) => e.localName === "ImportedMPD");
|
|
308
|
+
const href = (_imported$getAttribut = imported === null || imported === void 0 ? void 0 : imported.getAttribute("uri")) !== null && _imported$getAttribut !== void 0 ? _imported$getAttribut : imported === null || imported === void 0 || (_imported$textContent = imported.textContent) === null || _imported$textContent === void 0 ? void 0 : _imported$textContent.trim();
|
|
309
|
+
if (href === void 0 || href === "") continue;
|
|
310
|
+
const tracking = [];
|
|
311
|
+
for (const stream of Array.from(period.children).filter((e) => e.localName === "EventStream")) {
|
|
312
|
+
var _stream$getAttribute;
|
|
313
|
+
if (stream.getAttribute("schemeIdUri") !== "urn:mpeg:dash:event:callback:2015") continue;
|
|
314
|
+
const scale = Number((_stream$getAttribute = stream.getAttribute("timescale")) !== null && _stream$getAttribute !== void 0 ? _stream$getAttribute : 1) || 1;
|
|
315
|
+
const params = Array.from(stream.children).filter((e) => e.localName === "RequestParam").map((e) => ({
|
|
316
|
+
name: "RequestParam",
|
|
317
|
+
attributes: Object.fromEntries(Array.from(e.attributes, (x) => [x.localName, x.value]))
|
|
318
|
+
}));
|
|
319
|
+
for (const event of Array.from(stream.children).filter((e) => e.localName === "Event")) {
|
|
320
|
+
var _event$textContent, _event$getAttribute;
|
|
321
|
+
const target = (_event$textContent = event.textContent) === null || _event$textContent === void 0 ? void 0 : _event$textContent.trim();
|
|
322
|
+
if (target === void 0 || target === "") continue;
|
|
323
|
+
tracking.push({
|
|
324
|
+
offset: Number((_event$getAttribute = event.getAttribute("presentationTime")) !== null && _event$getAttribute !== void 0 ? _event$getAttribute : 0) / scale,
|
|
325
|
+
url: withQuery(resolveUrl(target, url), params, "callback", url)
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const duration = seconds((_period$getAttribute = period.getAttribute("duration")) !== null && _period$getAttribute !== void 0 ? _period$getAttribute : void 0);
|
|
330
|
+
const creatives = Array.from(period.children).filter((e) => e.localName === "EventStream" && e.getAttribute("schemeIdUri") === AD_CREATIVES).flatMap((stream) => Array.from(stream.children).filter((e) => e.localName === "Event")).flatMap((event) => {
|
|
331
|
+
var _event$textContent2;
|
|
332
|
+
return creativesOf((_event$textContent2 = event.textContent) === null || _event$textContent2 === void 0 ? void 0 : _event$textContent2.trim());
|
|
333
|
+
});
|
|
334
|
+
assets.push(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
335
|
+
url: resolveUrl(href, url),
|
|
336
|
+
mimeType: "application/dash+xml"
|
|
337
|
+
}, duration !== void 0 ? { duration } : {}), tracking.length > 0 ? { tracking } : {}), withCreatives(creatives)));
|
|
338
|
+
}
|
|
339
|
+
return assets;
|
|
340
|
+
}
|
|
341
|
+
export { assetsOf, breaksOf, creativesOf, fromEvent, seconds };
|