eyevinn-channel-engine 5.1.2 → 5.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.
Files changed (97) hide show
  1. package/.github/workflows/nodejs.yml +1 -1
  2. package/.github/workflows/publish.yml +1 -1
  3. package/.github/workflows/rc.yml +1 -1
  4. package/CONTRIBUTING.md +40 -0
  5. package/Dockerfile +1 -1
  6. package/README.md +70 -8
  7. package/dist/engine/chaos_monkey.d.ts +1 -1
  8. package/dist/engine/chaos_monkey.js +1 -0
  9. package/dist/engine/event_stream.d.ts +1 -6
  10. package/dist/engine/event_stream.js +2 -0
  11. package/dist/engine/memcached_state_store.d.ts +1 -13
  12. package/dist/engine/memcached_state_store.js +4 -0
  13. package/dist/engine/memory_state_store.d.ts +1 -13
  14. package/dist/engine/memory_state_store.js +5 -0
  15. package/dist/engine/playhead_state.d.ts +0 -26
  16. package/dist/engine/playhead_state.js +9 -0
  17. package/dist/engine/preflight.d.ts +1 -1
  18. package/dist/engine/preflight.js +1 -0
  19. package/dist/engine/redis_state_store.d.ts +1 -19
  20. package/dist/engine/redis_state_store.js +5 -0
  21. package/dist/engine/server.d.ts +27 -0
  22. package/dist/engine/server.js +140 -6
  23. package/dist/engine/session.d.ts +1 -148
  24. package/dist/engine/session.js +398 -11
  25. package/dist/engine/session_live.d.ts +1 -181
  26. package/dist/engine/session_live.js +19 -4
  27. package/dist/engine/session_live_state.d.ts +0 -23
  28. package/dist/engine/session_live_state.js +5 -0
  29. package/dist/engine/session_state.d.ts +0 -45
  30. package/dist/engine/session_state.js +10 -0
  31. package/dist/engine/shared_state_store.d.ts +1 -25
  32. package/dist/engine/shared_state_store.js +10 -0
  33. package/dist/engine/state_store_types.d.ts +32 -0
  34. package/dist/engine/state_store_types.js +5 -0
  35. package/dist/engine/stream_switcher.d.ts +1 -40
  36. package/dist/engine/stream_switcher.js +108 -20
  37. package/dist/engine/subtitle_slicer.d.ts +1 -8
  38. package/dist/engine/subtitle_slicer.js +1 -0
  39. package/dist/engine/util.d.ts +1 -29
  40. package/dist/engine/util.js +2 -1
  41. package/dist/examples/adbreak.d.ts +1 -0
  42. package/dist/examples/adbreak.js +104 -0
  43. package/dist/index.d.ts +1 -1
  44. package/dist/package.json +20 -4
  45. package/docs/design/mixing-muxed-demuxed-audio.md +153 -0
  46. package/docs/design/subtitles-live-mix-demux.md +135 -0
  47. package/docs/reference.md +67 -0
  48. package/engine/chaos_monkey.ts +17 -0
  49. package/engine/{event_stream.js → event_stream.ts} +5 -3
  50. package/engine/{memcached_state_store.js → memcached_state_store.ts} +19 -12
  51. package/engine/memory_state_store.ts +71 -0
  52. package/engine/{playhead_state.js → playhead_state.ts} +92 -82
  53. package/engine/{preflight.js → preflight.ts} +1 -1
  54. package/engine/{redis_state_store.js → redis_state_store.ts} +216 -208
  55. package/engine/server.ts +210 -8
  56. package/engine/{session.js → session.ts} +421 -22
  57. package/engine/{session_live.js → session_live.ts} +54 -31
  58. package/engine/{session_live_state.js → session_live_state.ts} +129 -120
  59. package/engine/{session_state.js → session_state.ts} +269 -248
  60. package/engine/{shared_state_store.js → shared_state_store.ts} +31 -19
  61. package/engine/state_store_types.ts +35 -0
  62. package/engine/{stream_switcher.js → stream_switcher.ts} +133 -34
  63. package/engine/{subtitle_slicer.js → subtitle_slicer.ts} +10 -8
  64. package/engine/{util.js → util.ts} +28 -24
  65. package/examples/adbreak.ts +115 -0
  66. package/index.ts +2 -0
  67. package/package.json +20 -4
  68. package/spec/engine/custom_vod_request_params_spec.ts +99 -0
  69. package/spec/engine/drm_spec.ts +128 -0
  70. package/spec/engine/{engine_spec.js → engine_spec.ts} +44 -1
  71. package/spec/engine/{ha_spec.js → ha_spec.ts} +7 -4
  72. package/spec/engine/{init_switching_spec.js → init_switching_spec.ts} +10 -6
  73. package/spec/engine/{interface_spec.js → interface_spec.ts} +16 -4
  74. package/spec/engine/{playhead_live_spec.js → playhead_live_spec.ts} +2 -1
  75. package/spec/engine/{playhead_spec.js → playhead_spec.ts} +15 -8
  76. package/spec/engine/session_spec.ts +800 -0
  77. package/spec/engine/stream_switcher_audio_reconcile_spec.ts +158 -0
  78. package/spec/engine/{stream_switcher_spec.js → stream_switcher_spec.ts} +111 -13
  79. package/spec/engine/subtitle_missing_language_spec.ts +196 -0
  80. package/spec/engine/{subtitle_spec.js → subtitle_spec.ts} +28 -27
  81. package/spec/helpers/ts-resolve.js +65 -0
  82. package/spec/support/jasmine.json +1 -1
  83. package/spec/testvectors/hls_subs_no_language/config.subtitleTracks.json +12 -0
  84. package/spec/testvectors/hls_subs_no_language/evidence_dummy_segments_name_mismatch.m3u8 +24 -0
  85. package/spec/testvectors/hls_subs_no_language/evidence_real_cues_name_match.m3u8 +24 -0
  86. package/spec/testvectors/hls_subs_no_language/french.m3u8 +9 -0
  87. package/spec/testvectors/hls_subs_no_language/master.m3u8 +11 -0
  88. package/spec/testvectors/hls_subs_no_language/video.m3u8 +25 -0
  89. package/spec/testvectors/slate/master.m3u8 +3 -0
  90. package/spec/testvectors/slate/media.m3u8 +9 -0
  91. package/tsconfig.json +21 -4
  92. package/tsconfig.spec.json +16 -0
  93. package/engine/chaos_monkey.js +0 -17
  94. package/engine/memory_state_store.js +0 -63
  95. package/spec/engine/session_spec.js +0 -116
  96. /package/spec/engine/{session_live_spec.js → session_live_spec.ts} +0 -0
  97. /package/spec/engine/{util_spec.js → util_spec.ts} +0 -0
@@ -0,0 +1,115 @@
1
+ /*
2
+ * Reference implementation showing a channel configured for
3
+ * HLS-interstitial (SGAI) ad breaks.
4
+ *
5
+ * When `adBreak.enabled` is true and an `adServerUri` is configured, the
6
+ * engine annotates the served manifest with an EXT-X-DATERANGE HLS
7
+ * interstitial (class `com.apple.hls.interstitial`) at the VOD boundary and
8
+ * resolves the ad asset from the ad-serving endpoint. If the endpoint cannot
9
+ * be reached in time (2s), the break falls back to the configured slate.
10
+ * See `docs/reference.md` for the full field reference.
11
+ */
12
+
13
+ import { ChannelEngine, ChannelEngineOpts,
14
+ IAssetManager, IChannelManager,
15
+ VodRequest, VodResponse, Channel, ChannelProfile
16
+ } from "../index";
17
+
18
+ class RefAssetManager implements IAssetManager {
19
+ private assets;
20
+ private pos;
21
+ constructor(opts?) {
22
+ this.assets = {
23
+ "1": [
24
+ {
25
+ id: 1,
26
+ title: "Tears of Steel",
27
+ uri: "https://maitv-vod.lab.eyevinn.technology/tearsofsteel_4k.mov/master.m3u8",
28
+ },
29
+ {
30
+ id: 2,
31
+ title: "VINN",
32
+ uri: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8",
33
+ },
34
+ ],
35
+ };
36
+ this.pos = { "1": 0 };
37
+ }
38
+
39
+ getNextVod(vodRequest: VodRequest): Promise<VodResponse> {
40
+ return new Promise((resolve, reject) => {
41
+ const channelId = vodRequest.playlistId;
42
+ if (this.assets[channelId]) {
43
+ const vod = this.assets[channelId][this.pos[channelId]++];
44
+ if (this.pos[channelId] > this.assets[channelId].length - 1) {
45
+ this.pos[channelId] = 0;
46
+ }
47
+ resolve({ id: vod.id, title: vod.title, uri: vod.uri });
48
+ } else {
49
+ reject("Invalid channelId provided");
50
+ }
51
+ });
52
+ }
53
+ }
54
+
55
+ class RefChannelManager implements IChannelManager {
56
+ private channels: Channel[];
57
+
58
+ constructor() {
59
+ this.channels = [
60
+ {
61
+ id: "1",
62
+ profile: this._getProfile(),
63
+ // Per-channel ad-break configuration. Overrides the engine-level
64
+ // `adBreak` default when present.
65
+ adBreak: {
66
+ // Master enable flag. When false (the default) no interstitial
67
+ // metadata is emitted and the manifest is unchanged.
68
+ enabled: true,
69
+ // Ad-serving endpoint queried to fill the break. Must be an
70
+ // absolute http(s) URL when enabled. It should answer with JSON
71
+ // shaped as { assetUri } | { assetList } | { assets: [...] }.
72
+ adServerUri: "https://ad-endpoint.example.com/vast",
73
+ // Slate shown while the break is being resolved, and used as the
74
+ // fallback if the ad-serving endpoint times out or errors.
75
+ slate: {
76
+ uri: "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
77
+ repetitions: 10,
78
+ duration: 4000,
79
+ },
80
+ },
81
+ },
82
+ ];
83
+ }
84
+
85
+ getChannels(): Channel[] {
86
+ return this.channels;
87
+ }
88
+
89
+ _getProfile(): ChannelProfile[] {
90
+ return [
91
+ { bw: 6134000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [1024, 458] },
92
+ { bw: 2323000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [640, 286] },
93
+ { bw: 1313000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [480, 214] },
94
+ ];
95
+ }
96
+ }
97
+
98
+ const refAssetManager = new RefAssetManager();
99
+ const refChannelManager = new RefChannelManager();
100
+
101
+ const engineOptions: ChannelEngineOpts = {
102
+ heartbeat: "/",
103
+ averageSegmentDuration: 2000,
104
+ channelManager: refChannelManager,
105
+ defaultSlateUri:
106
+ "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
107
+ slateRepetitions: 10,
108
+ // Engine-level default applied to channels that do not carry their own
109
+ // `adBreak`. Left disabled here so only channel "1" opens ad breaks.
110
+ adBreak: { enabled: false },
111
+ };
112
+
113
+ const engine = new ChannelEngine(refAssetManager, engineOptions);
114
+ engine.start();
115
+ engine.listen(process.env.PORT || 8000);
package/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { ChannelEngine,
2
2
  ChannelEngineOpts,
3
+ AdBreakOpts,
4
+ SlateOpts,
3
5
  IAssetManager,
4
6
  IChannelManager,
5
7
  IStreamSwitchManager,
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "eyevinn-channel-engine",
3
- "version": "5.1.2",
3
+ "version": "5.2.0",
4
4
  "description": "OTT TV Channel Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc --project ./ && cp ./package.json dist/",
9
9
  "debug-server": "DEBUG=engine-*,vod-to-live node dist/server.js",
10
+ "typecheck:spec": "tsc --project ./tsconfig.spec.json",
11
+ "pretest": "npm run typecheck:spec",
10
12
  "test": "jasmine",
11
13
  "version:rc": "npm version prerelease --preid=rc",
12
14
  "postversion": "git push && git push --tags",
@@ -16,7 +18,7 @@
16
18
  "start-livemix-demux": "node dist/examples/livemix-demux.js"
17
19
  },
18
20
  "engines": {
19
- "node": ">=20"
21
+ "node": "^22.23.4 || >=24.22.1"
20
22
  },
21
23
  "author": "Eyevinn Technology AB <work@eyevinn.se>",
22
24
  "contributors": [
@@ -36,18 +38,32 @@
36
38
  "@eyevinn/hls-truncate": "^0.4.0",
37
39
  "@eyevinn/hls-vodtolive": "^4.1.10",
38
40
  "@eyevinn/m3u8": "^0.5.6",
39
- "@fastify/static": "^9.1.1",
41
+ "@fastify/static": "^10.1.2",
40
42
  "abort-controller": "^3.0.0",
41
43
  "debug": "^3.2.7",
42
- "fastify": "^5.0.0",
44
+ "fastify": "^5.12.1",
43
45
  "ioredis": "^5.3.2",
44
46
  "memcache-client": "^0.10.1",
45
47
  "node-fetch": "^2.6.1",
46
48
  "promise.allsettled": "^1.0.4",
47
49
  "uuid": "^14.0.0"
48
50
  },
51
+ "overrides": {
52
+ "fast-uri": "^3.1.6",
53
+ "@eyevinn/hls-truncate": {
54
+ "node-fetch": "^2.6.7"
55
+ },
56
+ "@fastify/static": {
57
+ "brace-expansion": "^5.0.12"
58
+ },
59
+ "jasmine": {
60
+ "brace-expansion": "^1.1.21"
61
+ }
62
+ },
49
63
  "devDependencies": {
64
+ "@types/jasmine": "^3.10.19",
50
65
  "@types/node": "^22.0.0",
66
+ "@types/uuid": "^10.0.0",
51
67
  "jasmine": "^3.1.0",
52
68
  "nock": "^13.1.1",
53
69
  "typescript": "^5.0.0",
@@ -0,0 +1,99 @@
1
+ const Session = require("../../engine/session.js");
2
+
3
+ const { SessionStateStore } = require("../../engine/session_state.js");
4
+ const { PlayheadStateStore } = require("../../engine/playhead_state.js");
5
+
6
+ // End-to-end contract test for the custom getNextVod pass-through params
7
+ // feature (issues #377/#378/#379/#380).
8
+ //
9
+ // The plumbing spans two seams:
10
+ // 1. engine/server.ts `_handleMasterManifest` filters the incoming
11
+ // `request.query` by the `customVodRequestParams` allowlist and calls
12
+ // `session.setCustomParams(filtered)` on every master-manifest request.
13
+ // 2. engine/session.ts forwards those params onto `VodRequest.customParams`
14
+ // from `_getNextVod()` when (and only when) at least one is present.
15
+ //
16
+ // The module-level fastify instance is a process singleton, so only ONE
17
+ // successful `ChannelEngine` construction (and therefore one live HTTP route
18
+ // set) is possible per process — see the note in interface_spec.ts. Driving
19
+ // three distinct master-manifest HTTP requests through a real engine is
20
+ // therefore impractical in-suite. Instead we exercise the exact same contract
21
+ // deterministically at the seam we CAN drive repeatedly: the allowlist filter
22
+ // (identical to the handler's logic) feeding the real `session.setCustomParams`
23
+ // + `session._getNextVod()` path, asserting what a stubbed asset manager's
24
+ // `getNextVod` actually receives. This proves the observable behaviour the
25
+ // handler produces for each of the three required cases (a/b/c).
26
+
27
+ // Mirrors engine/server.ts `_handleMasterManifest` (#379): keep only query
28
+ // params whose name is in the configured allowlist. An empty/absent allowlist
29
+ // (the default) yields no custom params.
30
+ function filterAllowlistedParams(query, allowlist) {
31
+ const customParams = {};
32
+ for (const key of allowlist || []) {
33
+ if (query[key] !== undefined) {
34
+ customParams[key] = query[key];
35
+ }
36
+ }
37
+ return customParams;
38
+ }
39
+
40
+ describe("custom getNextVod pass-through params (issue #380)", () => {
41
+ let sessionLiveStore;
42
+
43
+ beforeEach(() => {
44
+ sessionLiveStore = {
45
+ sessionStateStore: new SessionStateStore(),
46
+ playheadStateStore: new PlayheadStateStore(),
47
+ };
48
+ });
49
+
50
+ // Builds a session whose stubbed asset manager records the VodRequest it
51
+ // receives, then drives the full handler contract: allowlist-filter the
52
+ // query exactly as `_handleMasterManifest` does, push the result through
53
+ // `setCustomParams`, and trigger a `_getNextVod()`.
54
+ async function driveMasterManifestRequest({ query, allowlist }) {
55
+ let received;
56
+ const session = new Session(
57
+ {
58
+ getNextVod: async (vodRequest) => {
59
+ received = vodRequest;
60
+ return { id: "1", uri: "https://example.com/vod.m3u8" };
61
+ },
62
+ },
63
+ null,
64
+ sessionLiveStore
65
+ );
66
+ session.setCustomParams(filterAllowlistedParams(query, allowlist));
67
+ await session._getNextVod();
68
+ return received;
69
+ }
70
+
71
+ it("(a) forwards an allowlisted query param to getNextVod as customParams", async () => {
72
+ const vodRequest = await driveMasterManifestRequest({
73
+ query: { myparam: "foo" },
74
+ allowlist: ["myparam"],
75
+ });
76
+ expect(vodRequest.customParams).toEqual({ myparam: "foo" });
77
+ });
78
+
79
+ it("(b) strips a non-allowlisted query param before it reaches getNextVod", async () => {
80
+ const vodRequest = await driveMasterManifestRequest({
81
+ // `myparam` is allowlisted and passes through; `evil` is not and must be
82
+ // dropped entirely (not merely emptied).
83
+ query: { myparam: "foo", evil: "bar" },
84
+ allowlist: ["myparam"],
85
+ });
86
+ expect(vodRequest.customParams).toEqual({ myparam: "foo" });
87
+ expect(vodRequest.customParams.evil).toBeUndefined();
88
+ });
89
+
90
+ it("(c) sends no customParams when no allowlist is configured (existing behaviour preserved)", async () => {
91
+ const vodRequest = await driveMasterManifestRequest({
92
+ query: { myparam: "foo" },
93
+ allowlist: [], // the ChannelEngine default when customVodRequestParams is unset
94
+ });
95
+ // The field is omitted entirely so asset managers that don't expect it are
96
+ // unaffected — matching the pre-#379 request shape.
97
+ expect(vodRequest.customParams).toBeUndefined();
98
+ });
99
+ });
@@ -0,0 +1,128 @@
1
+ const HLSVod = require("@eyevinn/hls-vodtolive");
2
+ const fs = require("fs");
3
+
4
+ /*
5
+ * Regression coverage for issue #401 — Widevine DRM over HLS + CMAF.
6
+ *
7
+ * `examples/drm.ts` wires the engine up with `useDemuxedAudio: true` and feeds
8
+ * it Widevine-encrypted HLS+CMAF (fMP4) VODs. The DRM signalling itself is not
9
+ * something the engine rewrites: the engine leans on @eyevinn/hls-vodtolive to
10
+ * convert each VOD into the live media sequences it serves, and that conversion
11
+ * must carry the source's EXT-X-KEY (Widevine) and EXT-X-MAP (CMAF init
12
+ * segment) tags through unchanged so a player can still acquire a licence.
13
+ *
14
+ * This spec drives the exact same seam the engine uses at VOD creation
15
+ * (`new HLSVod(...).load(masterLoader, mediaLoader, audioLoader)` — see
16
+ * engine/session.js) against the vod-lib `hls_widevine` fixture, which is a
17
+ * genuine Shaka-packaged Widevine + CMAF asset (SAMPLE-AES-CTR, Widevine
18
+ * system id urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed), and asserts the
19
+ * DRM/CMAF signalling survives into both the video playlist and the demuxed
20
+ * audio rendition.
21
+ *
22
+ * What this does NOT cover (documented honestly): it does not exercise a real
23
+ * Widevine licence server, does not decrypt media, and does not assert end-to-end
24
+ * playback in a browser. Those require a real licence proxy and DRM-capable
25
+ * player, neither of which is available in CI. The strongest offline guarantee
26
+ * — that the engine's VOD2Live conversion never strips or corrupts the Widevine
27
+ * key material or the CMAF init segment for a demuxed HLS+CMAF asset — is what
28
+ * is asserted here.
29
+ */
30
+
31
+ // The Widevine DRM system id (Common PSSH / EME) as it appears in KEYFORMAT.
32
+ const WIDEVINE_SYSTEM_ID = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";
33
+
34
+ // jasmine runs from the repo root, so paths are relative to it.
35
+ const WIDEVINE_TV = "node_modules/@eyevinn/hls-vodtolive/testvectors/hls_widevine/";
36
+
37
+ // The fixture master (index.m3u8) advertises each video variant by BANDWIDTH;
38
+ // hls-vodtolive asks its media loader for a playlist by bandwidth, so map them.
39
+ const BW_TO_PLAYLIST = {
40
+ 831086: "playlist_v-0144p-0100k-libx264.mp4.m3u8",
41
+ 8065760: "playlist_v-0576p-1400k-libx264.mp4.m3u8",
42
+ 6099164: "playlist_v-0480p-1000k-libx264.mp4.m3u8",
43
+ 2193558: "playlist_v-0240p-0400k-libx264.mp4.m3u8",
44
+ 4008262: "playlist_v-0360p-0750k-libx264.mp4.m3u8",
45
+ };
46
+ const AUDIO_PLAYLIST = "playlist_a-eng-0384k-aac-6c.mp4.m3u8";
47
+
48
+ const masterLoader = () => fs.createReadStream(WIDEVINE_TV + "index.m3u8");
49
+ const mediaLoader = (bandwidth) =>
50
+ fs.createReadStream(WIDEVINE_TV + BW_TO_PLAYLIST[bandwidth]);
51
+ // audio loader is called with (groupId, language); this fixture has one of each.
52
+ const audioLoader = () => fs.createReadStream(WIDEVINE_TV + AUDIO_PLAYLIST);
53
+
54
+ const FIXED_TS = Date.UTC(2026, 8, 4, 0, 0, 0); // 2026-09-04T00:00:00.000Z
55
+
56
+ async function loadWidevineVod() {
57
+ const vod = new HLSVod("http://mock.com/index.m3u8", [], FIXED_TS, 0);
58
+ await vod.load(masterLoader, mediaLoader, audioLoader);
59
+ return vod;
60
+ }
61
+
62
+ describe("DRM: Widevine over HLS + CMAF (issue #401)", () => {
63
+ it("loads the Widevine+CMAF VOD used by examples/drm.ts without stripping DRM", async () => {
64
+ const vod = await loadWidevineVod();
65
+ // A successfully loaded VOD exposes variants; if the DRM/CMAF manifest had
66
+ // failed to parse, load() would have rejected and we would not get here.
67
+ expect(vod.getBandwidths().length).toBeGreaterThan(0);
68
+ expect(vod.getAudioGroups().length).toBeGreaterThan(0);
69
+ });
70
+
71
+ it("carries the Widevine EXT-X-KEY through into the served video playlist", async () => {
72
+ const vod = await loadWidevineVod();
73
+ const bw = vod.getBandwidths().sort((a, b) => a - b)[0];
74
+ const playlist = vod.getLiveMediaSequences(0, bw, 0, 0);
75
+
76
+ const keyLine = playlist
77
+ .split("\n")
78
+ .find((l) => l.startsWith("#EXT-X-KEY"));
79
+
80
+ expect(keyLine).toBeDefined();
81
+ // Widevine, not FairPlay: assert the Widevine system id and the CMAF
82
+ // sample encryption method the fixture uses.
83
+ expect(keyLine).toContain(`KEYFORMAT="${WIDEVINE_SYSTEM_ID}"`);
84
+ expect(keyLine).toContain("METHOD=SAMPLE-AES-CTR");
85
+ // FairPlay would surface as com.apple.streamingkeydelivery; make sure the
86
+ // conversion did not somehow relabel the key as FairPlay.
87
+ expect(playlist).not.toContain("com.apple.streamingkeydelivery");
88
+ });
89
+
90
+ it("carries the CMAF EXT-X-MAP init segment through into the served video playlist", async () => {
91
+ const vod = await loadWidevineVod();
92
+ const bw = vod.getBandwidths().sort((a, b) => a - b)[0];
93
+ const playlist = vod.getLiveMediaSequences(0, bw, 0, 0);
94
+
95
+ const mapLine = playlist
96
+ .split("\n")
97
+ .find((l) => l.startsWith("#EXT-X-MAP"));
98
+
99
+ // Presence of EXT-X-MAP is what distinguishes CMAF/fMP4 from TS here.
100
+ expect(mapLine).toBeDefined();
101
+ expect(mapLine).toContain('URI="');
102
+ expect(mapLine).toContain("-init.mp4");
103
+ });
104
+
105
+ it("carries the Widevine key and CMAF init through the demuxed audio rendition", async () => {
106
+ // examples/drm.ts runs with useDemuxedAudio: true, so the audio group is
107
+ // served separately and must keep its own DRM/CMAF signalling.
108
+ const vod = await loadWidevineVod();
109
+ const group = vod.getAudioGroups()[0];
110
+ const lang = vod.getAudioLangsForAudioGroup(group)[0];
111
+ const audioSegments = vod.getLiveMediaSequenceAudioSegments(group, lang, 0);
112
+
113
+ // Find a real (non-discontinuity) segment that carries key material.
114
+ const keyed = audioSegments.find(
115
+ (seg) => seg && seg.keys && seg.keys[WIDEVINE_SYSTEM_ID]
116
+ );
117
+ expect(keyed).toBeDefined();
118
+ expect(keyed.keys[WIDEVINE_SYSTEM_ID].method).toEqual("SAMPLE-AES-CTR");
119
+ expect(keyed.keys[WIDEVINE_SYSTEM_ID].keyId).toBeDefined();
120
+
121
+ // And the demuxed audio must still reference its CMAF init segment.
122
+ const withInit = audioSegments.find(
123
+ (seg) => seg && typeof seg.initSegment === "string"
124
+ );
125
+ expect(withInit).toBeDefined();
126
+ expect(withInit.initSegment).toContain("-init.mp4");
127
+ });
128
+ });
@@ -1,6 +1,7 @@
1
1
  const { ChannelEngine } = require('../../dist/index.js');
2
2
 
3
3
  class TestChannelManager {
4
+ declare _tick: number;
4
5
  constructor() {
5
6
  this._tick = 0;
6
7
  }
@@ -40,7 +41,7 @@ class TestAssetManager {
40
41
 
41
42
  }
42
43
 
43
- getNextVod(vodRequest) {
44
+ getNextVod(vodRequest?: any) {
44
45
  return new Promise((resolve, reject) => {
45
46
  resolve({})
46
47
  });
@@ -56,6 +57,48 @@ describe("Channel Engine", () => {
56
57
  jasmine.clock().uninstall();
57
58
  });
58
59
 
60
+ describe("ad-break config validation (issue #367)", () => {
61
+ let testAssetManager;
62
+ let testChannelManager;
63
+
64
+ beforeEach(() => {
65
+ testAssetManager = new TestAssetManager();
66
+ testChannelManager = new TestChannelManager();
67
+ });
68
+
69
+ // NOTE: the module-level fastify instance is a singleton, so a *successful*
70
+ // ChannelEngine construction registers routes on it and cannot be repeated
71
+ // within a single process. These specs therefore only cover the validation
72
+ // paths that throw before any route registration happens (issue #367).
73
+
74
+ it("throws when an enabled ad-break config is missing the endpoint URL", () => {
75
+ expect(() => {
76
+ new ChannelEngine(testAssetManager, {
77
+ channelManager: testChannelManager,
78
+ adBreak: { enabled: true }
79
+ });
80
+ }).toThrowError(/adServerUri/);
81
+ });
82
+
83
+ it("throws when the ad-break endpoint URL is malformed", () => {
84
+ expect(() => {
85
+ new ChannelEngine(testAssetManager, {
86
+ channelManager: testChannelManager,
87
+ adBreak: { enabled: true, adServerUri: "not-a-url" }
88
+ });
89
+ }).toThrowError(/invalid adServerUri/);
90
+ });
91
+
92
+ it("throws when the ad-break endpoint URL is not http(s)", () => {
93
+ expect(() => {
94
+ new ChannelEngine(testAssetManager, {
95
+ channelManager: testChannelManager,
96
+ adBreak: { enabled: true, adServerUri: "ftp://ads.example.com/vast" }
97
+ });
98
+ }).toThrowError(/http\(s\)/);
99
+ });
100
+ });
101
+
59
102
  xit("is updated when new channels are added", async () => {
60
103
  const testAssetManager = new TestAssetManager();
61
104
  const testChannelManager = new TestChannelManager();
@@ -6,7 +6,10 @@ const { SessionStateStore } = require('../../engine/session_state.js');
6
6
  const { PlayheadStateStore } = require('../../engine/playhead_state.js');
7
7
 
8
8
  class TestAssetManager {
9
- constructor(opts, assets) {
9
+ declare assets: any;
10
+ declare pos: number;
11
+ declare doFail: boolean;
12
+ constructor(opts?: any, assets?: any) {
10
13
  this.assets = [
11
14
  { id: 1, title: "Tears of Steel", uri: "https://maitv-vod.lab.eyevinn.technology/tearsofsteel_4k.mov/master.m3u8" },
12
15
  { id: 2, title: "VINN", uri: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8" }
@@ -20,7 +23,7 @@ class TestAssetManager {
20
23
  this.doFail = true;
21
24
  }
22
25
  }
23
- getNextVod(vodRequest) {
26
+ getNextVod(vodRequest?: any) {
24
27
  return new Promise((resolve, reject) => {
25
28
  if (this.doFail) {
26
29
  reject("should fail");
@@ -35,9 +38,9 @@ class TestAssetManager {
35
38
  }
36
39
  }
37
40
 
38
- const parseMediaManifest = async (manifest) => {
41
+ const parseMediaManifest = async (manifest: any) => {
39
42
  const parser = m3u8.createStream();
40
- const m3u = await new Promise((resolve, reject) => {
43
+ const m3u = await new Promise<any>((resolve, reject) => {
41
44
  let manifestStream = new Readable();
42
45
  manifestStream.push(manifest);
43
46
  manifestStream.push(null);
@@ -237,7 +237,11 @@ const mockLiveSegments = {
237
237
  };
238
238
 
239
239
  class TestAssetManager {
240
- constructor(opts, assets) {
240
+ declare assets: any;
241
+ declare pos: number;
242
+ declare doFail: boolean;
243
+ declare failOnIndex: number;
244
+ constructor(opts?: any, assets?: any) {
241
245
  this.assets = [
242
246
  {
243
247
  id: 1,
@@ -263,7 +267,7 @@ class TestAssetManager {
263
267
  }
264
268
  }
265
269
 
266
- getNextVod(vodRequest) {
270
+ getNextVod(vodRequest?: any) {
267
271
  return new Promise((resolve, reject) => {
268
272
  if (this.doFail || this.pos === this.failOnIndex) {
269
273
  reject("should fail");
@@ -319,8 +323,8 @@ describe("The initialize switching", () => {
319
323
  await sessionLive.initAsync();
320
324
  sessionLive.startPlayheadAsync();
321
325
 
322
- currVodSegments = await session.getCurrentMediaSequenceSegments();
323
- currVodCounts = await session.getCurrentMediaAndDiscSequenceCount();
326
+ let currVodSegments = await session.getCurrentMediaSequenceSegments();
327
+ let currVodCounts = await session.getCurrentMediaAndDiscSequenceCount();
324
328
  expect(currVodCounts).toEqual({
325
329
  mediaSeq: 2,
326
330
  discSeq: 0,
@@ -847,8 +851,8 @@ describe("The initialize switching", () => {
847
851
  }
848
852
  await sessionLive.initAsync();
849
853
 
850
- currVodSegments = await session.getCurrentMediaSequenceSegments();
851
- currVodCounts = await session.getCurrentMediaAndDiscSequenceCount();
854
+ let currVodSegments = await session.getCurrentMediaSequenceSegments();
855
+ let currVodCounts = await session.getCurrentMediaAndDiscSequenceCount();
852
856
 
853
857
  await sessionLive.setCurrentMediaAndDiscSequenceCount(currVodCounts.mediaSeq, currVodCounts.discSeq);
854
858
  await sessionLive.setCurrentMediaSequenceSegments(currVodSegments);
@@ -1,19 +1,20 @@
1
1
  const { ChannelEngine } = require('../../dist/index.js');
2
2
 
3
3
  class TestAssetManager {
4
- constructor(opts, assets) {
4
+ declare errorHandlerFn: any;
5
+ constructor(opts?: any, assets?: any) {
5
6
  if (opts && opts.errorHandler) {
6
7
  this.errorHandlerFn = opts.errorHandler;
7
8
  }
8
9
  }
9
10
 
10
- getNextVod(vodRequest) {
11
+ getNextVod(vodRequest?: any) {
11
12
  return new Promise((resolve, reject) => {
12
13
  resolve({ id: 1, title: "Tears of Steel", uri: "https://maitv-vod.lab.eyevinn.technology/404/master.m3u8" });
13
14
  });
14
15
  }
15
16
 
16
- handleError(err, vodResponse) {
17
+ handleError(err: any, vodResponse?: any) {
17
18
  if (this.errorHandlerFn) {
18
19
  this.errorHandlerFn(err, vodResponse);
19
20
  }
@@ -52,7 +53,18 @@ describe("Asset Manager Interface", () => {
52
53
  const testAssetManager = new TestAssetManager({ errorHandler: errorHandler });
53
54
  const testChannelManager = new TestChannelManager();
54
55
 
55
- const engine = new ChannelEngine(testAssetManager, { channelManager: testChannelManager });
56
+ // NOTE: the module-level fastify instance is a singleton, so only one
57
+ // *successful* ChannelEngine construction is possible per process (a second
58
+ // one throws FST_ERR_DUPLICATED_ROUTE). This is the suite's single such
59
+ // construction, so the custom-VOD-request-parameter allowlist (issue #377)
60
+ // is asserted here rather than in a separate construction. It is stored on
61
+ // the instance verbatim; config surface only — no forwarding to getNextVod()
62
+ // is wired up yet (#378/#379/#380).
63
+ const engine = new ChannelEngine(testAssetManager, {
64
+ channelManager: testChannelManager,
65
+ customVodRequestParams: ["category"]
66
+ });
67
+ expect(engine.customVodRequestParams).toEqual(["category"]);
56
68
  await engine.start();
57
69
  jasmine.clock().tick((10 * 1000) + 1);
58
70
  });
@@ -251,6 +251,7 @@ const verificationLoop = async (session, increments) => {
251
251
  let lastUri = null;
252
252
  let lastManifest = null;
253
253
  let lastMediaSeq = null;
254
+ let manifest;
254
255
  for (let promiseFn of promiseFns) {
255
256
  manifest = await promiseFn();
256
257
  const parser = m3u8.createStream();
@@ -269,7 +270,7 @@ const verificationLoop = async (session, increments) => {
269
270
  }
270
271
  lastUri = firstItem.get('uri');
271
272
  lastMediaSeq = m3u.get('mediaSequence');
272
- resolve();
273
+ resolve(undefined);
273
274
  });
274
275
  });
275
276
  lastManifest = manifest;