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
@@ -4,8 +4,9 @@ const fs = require("fs");
4
4
 
5
5
 
6
6
  describe("Subtitle slicer", () => {
7
- let mockWebVtt;
8
- let mockWebVtt2;
7
+ let mockWebVtt: any;
8
+ let mockWebVtt2: any;
9
+ let vttFile: string;
9
10
  beforeEach(() => {
10
11
  mockWebVtt = fs.createReadStream("spec/testvectors/subtitle_file.webvtt");
11
12
  mockWebVtt2 = fs.createReadStream("spec/testvectors/subtitle_file_2.webvtt");
@@ -14,9 +15,9 @@ describe("Subtitle slicer", () => {
14
15
  it("generate sliced vtt with correct time stamps", async (done) => {
15
16
  let subslice = new SubtitleSlicer();
16
17
  let params = new URLSearchParams();
17
- params.append("starttime", 15);
18
- params.append("endtime", 20);
19
- params.append("elapsedtime", 0);
18
+ params.append("starttime", "15");
19
+ params.append("endtime", "20");
20
+ params.append("elapsedtime", "0");
20
21
  vttFile = await subslice.generateVtt(params, mockWebVtt)
21
22
  const subStrings = vttFile.split("\n")
22
23
  expect(subStrings[0]).toEqual("WEBVTT");
@@ -31,9 +32,9 @@ describe("Subtitle slicer", () => {
31
32
  it("generate sliced with correct line without comment", async (done) => {
32
33
  let subslice = new SubtitleSlicer();
33
34
  let params = new URLSearchParams();
34
- params.append("starttime", 26);
35
- params.append("endtime", 27);
36
- params.append("elapsedtime", 0);
35
+ params.append("starttime", "26");
36
+ params.append("endtime", "27");
37
+ params.append("elapsedtime", "0");
37
38
  vttFile = await subslice.generateVtt(params, mockWebVtt)
38
39
  const subStrings = vttFile.split("\n")
39
40
  expect(subStrings[2]).toEqual("");
@@ -45,9 +46,9 @@ describe("Subtitle slicer", () => {
45
46
  it("with explicit cue positions", async (done) => {
46
47
  let subslice = new SubtitleSlicer();
47
48
  let params = new URLSearchParams();
48
- params.append("starttime", 51);
49
- params.append("endtime", 53);
50
- params.append("elapsedtime", 0);
49
+ params.append("starttime", "51");
50
+ params.append("endtime", "53");
51
+ params.append("elapsedtime", "0");
51
52
  vttFile = await subslice.generateVtt(params, mockWebVtt)
52
53
  const subStrings = vttFile.split("\n")
53
54
  expect(subStrings[3]).toEqual("00:00:51.000 --> 00:00:53.000 align:left size:50%");
@@ -58,9 +59,9 @@ describe("Subtitle slicer", () => {
58
59
  it("generate sliced with all lines relevant to timestamp", async (done) => {
59
60
  let subslice = new SubtitleSlicer();
60
61
  let params = new URLSearchParams();
61
- params.append("starttime", 55);
62
- params.append("endtime", 57);
63
- params.append("elapsedtime", 0);
62
+ params.append("starttime", "55");
63
+ params.append("endtime", "57");
64
+ params.append("elapsedtime", "0");
64
65
  vttFile = await subslice.generateVtt(params, mockWebVtt)
65
66
  const subStrings = vttFile.split("\n")
66
67
  expect(subStrings[3]).toEqual("00:00:55.000 --> 00:00:57.000");
@@ -73,9 +74,9 @@ describe("Subtitle slicer", () => {
73
74
  it("with chapters", async (done) => {
74
75
  let subslice = new SubtitleSlicer();
75
76
  let params = new URLSearchParams();
76
- params.append("starttime", 62);
77
- params.append("endtime", 63);
78
- params.append("elapsedtime", 0);
77
+ params.append("starttime", "62");
78
+ params.append("endtime", "63");
79
+ params.append("elapsedtime", "0");
79
80
  vttFile = await subslice.generateVtt(params, mockWebVtt)
80
81
  const subStrings = vttFile.split("\n")
81
82
  expect(subStrings[3]).toEqual("Slide 3");
@@ -87,9 +88,9 @@ describe("Subtitle slicer", () => {
87
88
  it("with text that is longer than one segment", async (done) => {
88
89
  let subslice = new SubtitleSlicer();
89
90
  let params = new URLSearchParams();
90
- params.append("starttime", 64);
91
- params.append("endtime", 68);
92
- params.append("elapsedtime", 0);
91
+ params.append("starttime", "64");
92
+ params.append("endtime", "68");
93
+ params.append("elapsedtime", "0");
93
94
  vttFile = await subslice.generateVtt(params, mockWebVtt)
94
95
  const subStrings = vttFile.split("\n")
95
96
  expect(subStrings[3]).toEqual("00:01:03.000 --> 00:01:09.000");
@@ -101,13 +102,13 @@ describe("Subtitle slicer", () => {
101
102
  let subslice = new SubtitleSlicer();
102
103
  let params = new URLSearchParams();
103
104
  let perviousParams = new URLSearchParams();
104
- perviousParams.append("starttime", 63)
105
- perviousParams.append("endtime", 69)
106
- perviousParams.append("elapsedtime", 0)
107
- params.append("previousvtturi", perviousParams)
108
- params.append("starttime", 0)
109
- params.append("endtime", 3)
110
- params.append("elapsedtime", 69)
105
+ perviousParams.append("starttime", "63")
106
+ perviousParams.append("endtime", "69")
107
+ perviousParams.append("elapsedtime", "0")
108
+ params.append("previousvtturi", String(perviousParams))
109
+ params.append("starttime", "0")
110
+ params.append("endtime", "3")
111
+ params.append("elapsedtime", "69")
111
112
  vttFile = await subslice.generateVtt(params, mockWebVtt2, mockWebVtt)
112
113
  const subStrings = vttFile.split("\n")
113
114
  expect(subStrings[3]).toEqual("00:01:03.000 --> 00:01:09.000");
@@ -0,0 +1,65 @@
1
+ // TS migration bridge (see CONTRIBUTING.md "TypeScript migration").
2
+ //
3
+ // The engine tree is being migrated incrementally to TypeScript. Consumers
4
+ // (other engine modules and the specs) still `require('./foo.js')` with a
5
+ // literal `.js` extension, but the target file may already have been converted
6
+ // to `foo.ts`.
7
+ //
8
+ // This jasmine helper (helpers load before specs) installs two shims used only
9
+ // during the source-tree test run:
10
+ //
11
+ // 1. A `.js` -> `.ts` filename-resolution fallback, so existing
12
+ // `require('./foo.js')` calls keep working after `foo.js` becomes `foo.ts`.
13
+ // 2. A `require.extensions['.ts']` compile hook that transpiles the `.ts`
14
+ // source to CommonJS with the `typescript` package and hands the emitted
15
+ // JS to `module._compile`.
16
+ //
17
+ // Crucially, ALL `.ts` loading goes through `ts.transpileModule` rather than
18
+ // Node's built-in type-stripping, so the tests behave identically on Node 20.x
19
+ // (no strip-types) and Node 22.x (strip-types varies by minor). Production is
20
+ // unaffected — it runs the compiled `dist/` tree, not this hook.
21
+ const fs = require("fs");
22
+ const Module = require("module");
23
+ const ts = require("typescript");
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // 1. `.js` -> `.ts` resolution fallback.
27
+ // ---------------------------------------------------------------------------
28
+ const originalResolveFilename = Module._resolveFilename;
29
+ Module._resolveFilename = function (request, parent, isMain, options) {
30
+ try {
31
+ return originalResolveFilename.call(this, request, parent, isMain, options);
32
+ } catch (err) {
33
+ if (typeof request === "string") {
34
+ // `require('./foo.js')` -> try `./foo.ts`
35
+ // `require('./foo')` -> try `./foo.ts`
36
+ const candidate = request.endsWith(".js")
37
+ ? request.slice(0, -3) + ".ts"
38
+ : request + ".ts";
39
+ try {
40
+ return originalResolveFilename.call(this, candidate, parent, isMain, options);
41
+ } catch (_) {
42
+ throw err;
43
+ }
44
+ }
45
+ throw err;
46
+ }
47
+ };
48
+
49
+ // ---------------------------------------------------------------------------
50
+ // 2. `.ts` compile hook — transpile with `typescript`, never native strip-types.
51
+ // `require.extensions['.js']` is deliberately left untouched so the many
52
+ // remaining `.js` engine modules keep loading the normal way.
53
+ // ---------------------------------------------------------------------------
54
+ require.extensions[".ts"] = function (module, filename) {
55
+ const source = fs.readFileSync(filename, "utf8");
56
+ const { outputText } = ts.transpileModule(source, {
57
+ fileName: filename,
58
+ compilerOptions: {
59
+ module: ts.ModuleKind.CommonJS,
60
+ target: ts.ScriptTarget.ES2022,
61
+ esModuleInterop: true
62
+ }
63
+ });
64
+ module._compile(outputText, filename);
65
+ };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "spec_dir": "spec",
3
3
  "spec_files": [
4
- "**/*[sS]pec.js"
4
+ "**/*[sS]pec.ts"
5
5
  ],
6
6
  "helpers": [
7
7
  "helpers/**/*.js"
@@ -0,0 +1,12 @@
1
+ {
2
+ "_comment": "Repro for Eyevinn/channel-engine#325 / #384. The exact channel-engine session config.subtitleTracks used against master.m3u8 (whose SUBTITLES media tag has NAME=\"French\" but NO LANGUAGE attribute). channel-engine forwards this to @eyevinn/hls-vodtolive as expectedSubtitleTracks (engine/session.ts _tickAsync, hlsOpts ~line 1341). Session started with useVTTSubtitles/use_vtt_subtitles enabled.",
3
+ "useVTTSubtitles": true,
4
+ "matchingName": {
5
+ "_comment": "config name equals the manifest NAME -> real cues served today (NAME fallback works on @eyevinn/hls-vodtolive@4.1.10). Evidence: evidence_real_cues_name_match.m3u8",
6
+ "subtitleTracks": [{ "language": "fr", "name": "French" }]
7
+ },
8
+ "mismatchedName": {
9
+ "_comment": "config name differs from the manifest NAME and there is no LANGUAGE to fall back on -> matching fails, only dummy vtt segments served (the residual #325 bug). Evidence: evidence_dummy_segments_name_mismatch.m3u8",
10
+ "subtitleTracks": [{ "language": "fr", "name": "Francais" }]
11
+ }
12
+ }
@@ -0,0 +1,24 @@
1
+ #EXTM3U
2
+ #EXT-X-VERSION:6
3
+ #EXT-X-INDEPENDENT-SEGMENTS
4
+ #EXT-X-TARGETDURATION:6
5
+ #EXT-X-MEDIA-SEQUENCE:0
6
+ #EXT-X-DISCONTINUITY-SEQUENCE:0
7
+ #EXTINF:6.00000,
8
+ /dummysubs.vtt?p=0
9
+ #EXTINF:6.00000,
10
+ /dummysubs.vtt?p=1
11
+ #EXTINF:6.00000,
12
+ /dummysubs.vtt?p=2
13
+ #EXTINF:6.00000,
14
+ /dummysubs.vtt?p=3
15
+ #EXTINF:6.00000,
16
+ /dummysubs.vtt?p=4
17
+ #EXTINF:6.00000,
18
+ /dummysubs.vtt?p=5
19
+ #EXTINF:6.00000,
20
+ /dummysubs.vtt?p=6
21
+ #EXTINF:6.00000,
22
+ /dummysubs.vtt?p=7
23
+ #EXTINF:6.00000,
24
+ /dummysubs.vtt?p=8
@@ -0,0 +1,24 @@
1
+ #EXTM3U
2
+ #EXT-X-VERSION:6
3
+ #EXT-X-INDEPENDENT-SEGMENTS
4
+ #EXT-X-TARGETDURATION:6
5
+ #EXT-X-MEDIA-SEQUENCE:0
6
+ #EXT-X-DISCONTINUITY-SEQUENCE:0
7
+ #EXTINF:6.00000,
8
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=0&endtime=6&elapsedtime=0
9
+ #EXTINF:6.00000,
10
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=6&endtime=12&elapsedtime=0
11
+ #EXTINF:6.00000,
12
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=12&endtime=18&elapsedtime=0
13
+ #EXTINF:6.00000,
14
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=18&endtime=24&elapsedtime=0
15
+ #EXTINF:6.00000,
16
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=24&endtime=30&elapsedtime=0
17
+ #EXTINF:6.00000,
18
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=30&endtime=36&elapsedtime=0
19
+ #EXTINF:6.00000,
20
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=36&endtime=42&elapsedtime=0
21
+ #EXTINF:6.00000,
22
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=42&endtime=48&elapsedtime=0
23
+ #EXTINF:6.00000,
24
+ /subtitlevtt.vtt?vtturi=http%3A%2F%2Fmock.com%2Fsubtitlechunk_french_0.webvtt&starttime=48&endtime=54&elapsedtime=0
@@ -0,0 +1,9 @@
1
+ #EXTM3U
2
+ #EXT-X-VERSION:3
3
+ #EXT-X-TARGETDURATION:60
4
+ #EXT-X-MEDIA-SEQUENCE:0
5
+ #EXTINF:60.0,
6
+ subtitlechunk_french_0.webvtt
7
+ #EXTINF:60.0,
8
+ subtitlechunk_french_1.webvtt
9
+ #EXT-X-ENDLIST
@@ -0,0 +1,11 @@
1
+ #EXTM3U
2
+ #EXT-X-VERSION:3
3
+ # Minimal repro for Eyevinn/channel-engine#325 / #384:
4
+ # The SUBTITLES media tag below carries a NAME attribute but NO LANGUAGE attribute.
5
+ # channel-engine forwards config.subtitleTracks to @eyevinn/hls-vodtolive as
6
+ # expectedSubtitleTracks; the dependency matches the manifest track's LANGUAGE (falling
7
+ # back to NAME) against expected {language,name}. With no LANGUAGE here, matching must
8
+ # rely on NAME. This fixture exists so #385 can build/verify the fix.
9
+ #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="French",FORCED=NO,AUTOSELECT=YES,DEFAULT=YES,URI="french.m3u8"
10
+ #EXT-X-STREAM-INF:BANDWIDTH=2962000,NAME="Main",CODECS="avc1.66.30",RESOLUTION=1280x720,SUBTITLES="subs"
11
+ video.m3u8
@@ -0,0 +1,25 @@
1
+ #EXTM3U
2
+ #EXT-X-VERSION:3
3
+ #EXT-X-TARGETDURATION:6
4
+ #EXT-X-MEDIA-SEQUENCE:0
5
+ #EXTINF:6.0,
6
+ media_0.ts
7
+ #EXTINF:6.0,
8
+ media_1.ts
9
+ #EXTINF:6.0,
10
+ media_2.ts
11
+ #EXTINF:6.0,
12
+ media_3.ts
13
+ #EXTINF:6.0,
14
+ media_4.ts
15
+ #EXTINF:6.0,
16
+ media_5.ts
17
+ #EXTINF:6.0,
18
+ media_6.ts
19
+ #EXTINF:6.0,
20
+ media_7.ts
21
+ #EXTINF:6.0,
22
+ media_8.ts
23
+ #EXTINF:6.0,
24
+ media_9.ts
25
+ #EXT-X-ENDLIST
@@ -0,0 +1,3 @@
1
+ #EXTM3U
2
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1497000,RESOLUTION=768x432,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
3
+ media.m3u8
@@ -0,0 +1,9 @@
1
+ #EXTM3U
2
+ #EXT-X-TARGETDURATION:4
3
+ #EXT-X-ALLOW-CACHE:YES
4
+ #EXT-X-PLAYLIST-TYPE:VOD
5
+ #EXT-X-VERSION:3
6
+ #EXT-X-MEDIA-SEQUENCE:1
7
+ #EXTINF:4.000,
8
+ https://slate.example.com/slate/segment1.ts
9
+ #EXT-X-ENDLIST
package/tsconfig.json CHANGED
@@ -1,15 +1,32 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "outDir": "./dist",
4
- "allowJs": true,
4
+ "forceConsistentCasingInFileNames": true,
5
5
  "target": "es2022",
6
6
  "module": "node16",
7
7
  "moduleResolution": "node16",
8
8
  "esModuleInterop": true,
9
- "declaration": true
9
+ "declaration": true,
10
+ // Strict mode is on. Two strict sub-flags are still held back because the
11
+ // engine sources carry pre-existing debt that is being cleaned up in its own
12
+ // follow-up slice (they surface ~700 legacy findings unrelated to this spec
13
+ // migration): `noImplicitAny` (implicit-any params across session/server/
14
+ // session_live/stream_switcher) and `strictNullChecks` (possibly-undefined
15
+ // accesses in the same modules). Everything else strict enables
16
+ // (strictFunctionTypes, strictBindCallApply, strictPropertyInitialization,
17
+ // noImplicitThis, alwaysStrict, useUnknownInCatchVariables, ...) is on and
18
+ // passes for both the engine and the migrated TypeScript spec suite.
19
+ "strict": true,
20
+ "noImplicitAny": false,
21
+ "strictNullChecks": false,
22
+ "types": ["node", "jasmine"]
10
23
  },
24
+ // The production build emits only the engine + examples into `dist/`. The
25
+ // migrated TypeScript spec suite is type-checked separately via
26
+ // `tsconfig.spec.json` (see the `typecheck:spec` / `pretest` scripts) so the
27
+ // specs never leak into the published `dist/` tree.
11
28
  "include": [
12
- "./examples/*",
29
+ "./examples/*",
13
30
  "./engine/**/*"
14
31
  ]
15
- }
32
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ // Type-checks the migrated TypeScript spec suite. It never emits — the specs
3
+ // run through the jasmine `ts-resolve` helper, and the production `dist/` is
4
+ // built from `tsconfig.json`. Strict mode matches the production build
5
+ // (`noImplicitAny`/`strictNullChecks` stay off for parity with the engine
6
+ // sources the specs import via untyped CommonJS `require`).
7
+ "extends": "./tsconfig.json",
8
+ "compilerOptions": {
9
+ "noEmit": true,
10
+ "declaration": false
11
+ },
12
+ "include": [
13
+ "./engine/**/*",
14
+ "./spec/**/*"
15
+ ]
16
+ }
@@ -1,17 +0,0 @@
1
- const debug = require('debug')('chaos-monkey');
2
-
3
- const CHAOS_MONKEY_PROBABILITY = process.env.CHAOS_MONKEY_PROBABILITY || 0.5;
4
- const doChaos = () => process.env.CHAOS_MONKEY === "true" && Math.random() < CHAOS_MONKEY_PROBABILITY;
5
-
6
- const loadVod = async (p) => {
7
- if (doChaos()) {
8
- debug("Chaos Monkey is doing stuff");
9
- throw new Error("Chaos monkey prevented you from loading a VOD");
10
- } else {
11
- return await p;
12
- }
13
- };
14
-
15
- module.exports = {
16
- loadVod
17
- };
@@ -1,63 +0,0 @@
1
- const debug = require("debug")("memory-state-store");
2
-
3
- class MemoryStateStore {
4
- constructor(type, opts) {
5
- this.sharedStates = {};
6
- this.globalSharedStates = {};
7
- }
8
-
9
- async initAsync(id, initData) {
10
- if (!this.sharedStates[id]) {
11
- this.sharedStates[id] = {};
12
- Object.keys(initData).forEach((key) => {
13
- this.sharedStates[id][key] = initData[key];
14
- });
15
- }
16
- return this.sharedStates[id];
17
- }
18
-
19
- async resetAsync(id, initData) {
20
- this.sharedStates[id] = null;
21
- await this.initAsync(id, initData);
22
- }
23
-
24
- async resetAllAsync() {
25
- this.sharedStates = {};
26
- this.globalSharedStates = {};
27
- }
28
-
29
- async getAsync(id, key) {
30
- let value;
31
- if (id === "" || id === null) {
32
- value = this.globalSharedStates[key];
33
- } else {
34
- if (!this.sharedStates[id]) {
35
- return null;
36
- }
37
- value = this.sharedStates[id][key];
38
- }
39
- return value;
40
- }
41
-
42
- async setAsync(id, key, value) {
43
- if (id === "" || id === null) {
44
- this.globalSharedStates[key] = value;
45
- } else {
46
- if (!this.sharedStates[id]) {
47
- this.sharedStates[id] = {};
48
- }
49
- this.sharedStates[id][key] = value;
50
- return this.sharedStates[id][key];
51
- }
52
- }
53
-
54
- async setVolatileAsync(id, key, value) {
55
- return await this.setAsync(id, key, value);
56
- }
57
-
58
- async removeAsync(id, key) {
59
- delete this.sharedStates[id][key];
60
- }
61
- }
62
-
63
- module.exports = MemoryStateStore;
@@ -1,116 +0,0 @@
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
- describe("Session", () => {
7
- let sessionLiveStore = undefined;
8
- beforeEach(() => {
9
- sessionLiveStore = {
10
- sessionStateStore: new SessionStateStore(),
11
- playheadStateStore: new PlayheadStateStore(),
12
- };
13
- });
14
-
15
- it("creates a unique session ID", () => {
16
- const id1 = new Session("dummy", null, sessionLiveStore).sessionId;
17
- const id2 = new Session("dummy", null, sessionLiveStore).sessionId;
18
- expect(id1).not.toEqual(id2);
19
- });
20
-
21
- it("for demuxed, returns the appropriate audio increment value when desync is within acceptable limit, case I", async () => {
22
- const session = new Session("dummy", null, sessionLiveStore);
23
- const mockFinalAudioIdx = 50; // current Vod has 50 media sequences to serve.
24
- const mockCurrentVideoPosition = 200.0 * 1000; // Video is 200s deep into its content.
25
- const mockMseqAudio = 25; // current mseq for audio on vod, 25 out of 50.
26
- const mock_getAudioPlayheadPosition = async (pos_n_current) => {
27
- const mockPositions = [196.0, 199.84, 203.68, 207.52];
28
- return mockPositions[pos_n_current - mockMseqAudio];
29
- };
30
- const output = await session._determineExtraMediaIncrement(
31
- "audio",
32
- mockCurrentVideoPosition,
33
- mockFinalAudioIdx,
34
- mockMseqAudio,
35
- mock_getAudioPlayheadPosition,
36
- 24
37
- );
38
- expect(output.increment).toBe(1);
39
- });
40
-
41
- it("for demuxed, returns the appropriate audio increment value when desync is within acceptable limit, case II", async () => {
42
- const session = new Session("dummy", null, sessionLiveStore);
43
- const mockFinalAudioIdx = 50; // current Vod has 50 media sequences to serve.
44
- const mockCurrentVideoPosition = 200.0 * 1000; // Video is 200s deep into its content.
45
- const mockMseqAudio = 25; // current mseq for audio on vod, 25 out of 50.
46
- const mock_getAudioPlayheadPosition = async (pos_n_current) => {
47
- const mockPositions = [192.16, 196.0, 199.84, 203.68, 207.52];
48
- return mockPositions[pos_n_current - mockMseqAudio];
49
- };
50
- const output = await session._determineExtraMediaIncrement(
51
- "audio",
52
- mockCurrentVideoPosition,
53
- mockFinalAudioIdx,
54
- mockMseqAudio,
55
- mock_getAudioPlayheadPosition,
56
- 24
57
- );
58
- expect(output.increment).toBe(2);
59
- });
60
-
61
- it("for demuxed, returns the appropriate audio increment value when they are in sync but there is a floating point error", async () => {
62
- const session = new Session("dummy", null, sessionLiveStore);
63
- const mockFinalAudioIdx = 50;
64
- const mockCurrentVideoPosition = 441.7599999999981697 * 1000;
65
- const mockMseqAudio = 25;
66
- const mock_getAudioPlayheadPosition = async (pos_n_current) => {
67
- const mockPositions = [437.919999999999, 441.75999999999897];
68
- return mockPositions[pos_n_current - mockMseqAudio];
69
- };
70
- const output = await session._determineExtraMediaIncrement(
71
- "audio",
72
- mockCurrentVideoPosition,
73
- mockFinalAudioIdx,
74
- mockMseqAudio,
75
- mock_getAudioPlayheadPosition,
76
- 24
77
- );
78
- expect(output.increment).toBe(1);
79
- });
80
- it("for demuxed, returns the appropriate audio increment value, normal case I", async () => {
81
- const session = new Session("dummy", null, sessionLiveStore);
82
- const mockFinalAudioIdx = 50;
83
- const mockCurrentVideoPosition = 3.840 * 8 * 1000;
84
- const mockMseqAudio = 5;
85
- const mock_getAudioPlayheadPosition = async (pos_n_current) => {
86
- const mockPositions = [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52];
87
- return mockPositions[pos_n_current];
88
- };
89
- const output = await session._determineExtraMediaIncrement(
90
- "audio",
91
- mockCurrentVideoPosition,
92
- mockFinalAudioIdx,
93
- mockMseqAudio,
94
- mock_getAudioPlayheadPosition
95
- );
96
- expect(output.increment).toBe(3);
97
- });
98
- it("for demuxed, returns the appropriate audio increment value, normal case II", async () => {
99
- const session = new Session("dummy", null, sessionLiveStore);
100
- const mockFinalAudioIdx = 50;
101
- const mockCurrentVideoPosition = 14 * 1000;
102
- const mockMseqAudio = 0;
103
- const mock_getAudioPlayheadPosition = async (pos_n_current) => {
104
- const mockPositions = [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52];
105
- return mockPositions[pos_n_current];
106
- };
107
- const output = await session._determineExtraMediaIncrement(
108
- "subtitle",
109
- mockCurrentVideoPosition,
110
- mockFinalAudioIdx,
111
- mockMseqAudio,
112
- mock_getAudioPlayheadPosition
113
- );
114
- expect(output.increment).toBe(4);
115
- });
116
- });
File without changes