@blockcast/mmt-container 2.2.0-main.d79fbb738dc0 → 2.2.0-main.d95034c2b864
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-beacon.d.ts +39 -0
- package/dist/ad-beacon.d.ts.map +1 -0
- package/dist/ad-beacon.js +23 -0
- package/dist/ad-beacon.js.map +7 -0
- package/dist/ad-creative-timeline.d.ts +1 -0
- package/dist/ad-creative-timeline.d.ts.map +1 -1
- package/dist/ad-creative-timeline.js +21 -0
- package/dist/ad-creative-timeline.js.map +3 -3
- package/package.json +5 -5
- package/src/ad-beacon.ts +54 -0
- package/src/ad-creative-timeline.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockcast/mmt-container",
|
|
3
|
-
"version": "2.2.0-main.
|
|
3
|
+
"version": "2.2.0-main.d95034c2b864",
|
|
4
4
|
"description": "MMTP/LOC container parsing for MMT over MoQ and SSM",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -181,10 +181,10 @@
|
|
|
181
181
|
"test:watch": "vitest"
|
|
182
182
|
},
|
|
183
183
|
"dependencies": {
|
|
184
|
-
"@blockcast/fec-worker": "2.2.0-main.
|
|
185
|
-
"@blockcast/mmt-base": "2.2.0-main.
|
|
186
|
-
"@blockcast/mmt-fec": "2.2.0-main.
|
|
187
|
-
"@blockcast/mmt-manifest-verify": "2.2.0-main.
|
|
184
|
+
"@blockcast/fec-worker": "2.2.0-main.d95034c2b864",
|
|
185
|
+
"@blockcast/mmt-base": "2.2.0-main.d95034c2b864",
|
|
186
|
+
"@blockcast/mmt-fec": "2.2.0-main.d95034c2b864",
|
|
187
|
+
"@blockcast/mmt-manifest-verify": "2.2.0-main.d95034c2b864",
|
|
188
188
|
"@noble/curves": "^1.9.7",
|
|
189
189
|
"@noble/hashes": "^1.8.0",
|
|
190
190
|
"ajv": "^8.17.1",
|
package/src/ad-beacon.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beacon planning for ad creative signaling (draft-riedl-moq-ad-creative-signaling-01 7, 12):
|
|
3
|
+
* which URL to request and when. No I/O and no timers here (the cmcd-producer.ts precedent):
|
|
4
|
+
* the player sends each plan at sendAtMs with
|
|
5
|
+
* fetch(url, { mode: 'no-cors', credentials: 'omit', keepalive: true, referrerPolicy: 'no-referrer' }).
|
|
6
|
+
* The player calls this only for events the timeline emitted, so only for verified records.
|
|
7
|
+
*/
|
|
8
|
+
import type { AdTrackEvent } from './ad-creative-timeline.js'
|
|
9
|
+
|
|
10
|
+
export interface AdBeaconPolicy {
|
|
11
|
+
/** Lower-case host[:port] beacons may go to (riedl 12.1), typically the distributor's beacon proxy. Empty: nothing is sent. */
|
|
12
|
+
readonly authorities: readonly string[]
|
|
13
|
+
/** Uniform jitter window W in ms (riedl 7.2). Size it from the audience: W >= 1000 * N * k / C ms, for N receivers,
|
|
14
|
+
* k requests each at that instant and C beacon-proxy requests/s. */
|
|
15
|
+
readonly jitterMs: number
|
|
16
|
+
/** Event types sent at once, unjittered: the verification-critical ones (riedl 7.2). */
|
|
17
|
+
readonly immediate?: readonly string[]
|
|
18
|
+
/** Pseudonymous, session-scoped client id appended as a query parameter (riedl 7.1). Never a device id. */
|
|
19
|
+
readonly clientId?: { readonly param: string; readonly value: string }
|
|
20
|
+
/** Query parameter carrying the event's wallclock ms on a jittered request (riedl 7.2). */
|
|
21
|
+
readonly eventTimeParam?: string
|
|
22
|
+
/** URLs sent per event at most; the rest are suppressed (riedl 12.2). Default 16, also used for a NaN, infinite or negative value. */
|
|
23
|
+
readonly maxUrlsPerEvent?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type AdBeaconPlan =
|
|
27
|
+
| { readonly url: string; readonly sendAtMs: number; readonly eventType: string }
|
|
28
|
+
| { readonly url: string; readonly suppressed: 'authority' | 'cap' | 'macro'; readonly eventType: string }
|
|
29
|
+
|
|
30
|
+
/** A VAST macro such as [CACHEBUSTING]: riedl 7's first pattern (client-side substitution) is not supported. */
|
|
31
|
+
const VAST_MACRO = /\[[A-Z0-9_]+\]/
|
|
32
|
+
|
|
33
|
+
/** `random` gives the jitter phase in [0, 1). The player passes one phase drawn per session, so a device's events
|
|
34
|
+
* keep their order and spacing while the audience still spreads uniformly over [0, W) (riedl 7.2). */
|
|
35
|
+
export function planAdBeacons(event: AdTrackEvent, policy: AdBeaconPolicy, nowMs: number, random: () => number = Math.random): AdBeaconPlan[] {
|
|
36
|
+
const jittered = policy.jitterMs > 0 && !(policy.immediate ?? []).includes(event.eventType)
|
|
37
|
+
const delay = jittered ? Math.floor(random() * policy.jitterMs) : 0
|
|
38
|
+
const params: string[] = []
|
|
39
|
+
if (policy.clientId) params.push(`${encodeURIComponent(policy.clientId.param)}=${encodeURIComponent(policy.clientId.value)}`)
|
|
40
|
+
if (policy.eventTimeParam && jittered) params.push(`${encodeURIComponent(policy.eventTimeParam)}=${nowMs}`)
|
|
41
|
+
// A malformed setting (NaN from Number(undefined)) must not turn the cap off: i >= NaN is always false.
|
|
42
|
+
const max = policy.maxUrlsPerEvent
|
|
43
|
+
const cap = max !== undefined && Number.isFinite(max) && max >= 0 ? max : 16
|
|
44
|
+
return event.urls.map((raw, i): AdBeaconPlan => {
|
|
45
|
+
if (i >= cap) return { url: raw, suppressed: 'cap', eventType: event.eventType }
|
|
46
|
+
// Never sent unexpanded, and a device-identifier macro is never expanded (riedl 7.1, R33).
|
|
47
|
+
if (VAST_MACRO.test(raw)) return { url: raw, suppressed: 'macro', eventType: event.eventType }
|
|
48
|
+
const url = new URL(raw) // https and parseable: checked when the record was accepted (riedl 12.3)
|
|
49
|
+
if (!policy.authorities.includes(url.host)) return { url: raw, suppressed: 'authority', eventType: event.eventType }
|
|
50
|
+
// Append without re-encoding the capability URL's own query; a fragment stays last.
|
|
51
|
+
if (params.length > 0) url.search = url.search ? `${url.search}&${params.join('&')}` : `?${params.join('&')}`
|
|
52
|
+
return { url: url.href, sendAtMs: nowMs + delay, eventType: event.eventType }
|
|
53
|
+
})
|
|
54
|
+
}
|