rx-player 4.5.0-dev.2026012302 → 4.5.0-dev.2026031700
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/CHANGELOG.md +21 -3
- package/VERSION +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/commonjs/compat/should_seek_at_zero.d.ts +12 -0
- package/dist/commonjs/compat/should_seek_at_zero.d.ts.map +1 -0
- package/dist/commonjs/compat/should_seek_at_zero.js +23 -0
- package/dist/commonjs/core/cmcd/cmcd_data_builder.js +2 -2
- package/dist/commonjs/core/entry/FreezeResolver.js +2 -2
- package/dist/commonjs/core/entry/content_preparer.d.ts +1 -6
- package/dist/commonjs/core/entry/content_preparer.d.ts.map +1 -1
- package/dist/commonjs/core/entry/content_preparer.js +2 -125
- package/dist/commonjs/core/entry/content_time_boundaries_observer.d.ts.map +1 -1
- package/dist/commonjs/core/entry/content_time_boundaries_observer.js +8 -0
- package/dist/commonjs/core/entry/core_entry.d.ts +1 -1
- package/dist/commonjs/core/entry/core_entry.d.ts.map +1 -1
- package/dist/commonjs/core/entry/core_entry.js +2 -7
- package/dist/commonjs/core/entry/core_text_displayer_interface.d.ts.map +1 -1
- package/dist/commonjs/core/entry/core_text_displayer_interface.js +3 -1
- package/dist/commonjs/core/entry/index.d.ts +1 -1
- package/dist/commonjs/core/entry/index.d.ts.map +1 -1
- package/dist/commonjs/core/entry/utils.d.ts +64 -0
- package/dist/commonjs/core/entry/utils.d.ts.map +1 -1
- package/dist/commonjs/core/entry/utils.js +165 -0
- package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts +5 -6
- package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts.map +1 -1
- package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
- package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.js +34 -30
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.d.ts +70 -0
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.d.ts.map +1 -0
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.js +107 -0
- package/dist/commonjs/core/stream/representation/representation_stream.d.ts.map +1 -1
- package/dist/commonjs/core/stream/representation/representation_stream.js +12 -60
- package/dist/commonjs/core/stream/representation/utils/get_needed_segments.js +1 -1
- package/dist/commonjs/default_config.d.ts +5 -0
- package/dist/commonjs/default_config.d.ts.map +1 -1
- package/dist/commonjs/default_config.js +5 -0
- package/dist/commonjs/experimental/features/worker/index.d.ts +2 -1
- package/dist/commonjs/experimental/features/worker/index.d.ts.map +1 -1
- package/dist/commonjs/experimental/features/worker/index.js +4 -3
- package/dist/commonjs/main_thread/api/public_api.d.ts.map +1 -1
- package/dist/commonjs/main_thread/api/public_api.js +28 -4
- package/dist/commonjs/main_thread/init/directfile_content_initializer.d.ts.map +1 -1
- package/dist/commonjs/main_thread/init/directfile_content_initializer.js +23 -1
- package/dist/commonjs/main_thread/init/utils/initial_seek_and_play.d.ts.map +1 -1
- package/dist/commonjs/main_thread/init/utils/initial_seek_and_play.js +3 -1
- package/dist/commonjs/manifest/classes/index.d.ts +2 -1
- package/dist/commonjs/manifest/classes/index.d.ts.map +1 -1
- package/dist/commonjs/manifest/classes/representation.d.ts +1 -1
- package/dist/commonjs/manifest/classes/representation.d.ts.map +1 -1
- package/dist/commonjs/manifest/classes/representation.js +2 -2
- package/dist/commonjs/manifest/classes/representation_index/types.d.ts +2 -2
- package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
- package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
- package/dist/commonjs/utils/base64.d.ts +15 -1
- package/dist/commonjs/utils/base64.d.ts.map +1 -1
- package/dist/commonjs/utils/base64.js +6 -0
- package/dist/commonjs/utils/ranges.d.ts +1 -1
- package/dist/commonjs/utils/ranges.js +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/es2017/compat/should_seek_at_zero.d.ts +12 -0
- package/dist/es2017/compat/should_seek_at_zero.d.ts.map +1 -0
- package/dist/es2017/compat/should_seek_at_zero.js +20 -0
- package/dist/es2017/core/cmcd/cmcd_data_builder.js +2 -2
- package/dist/es2017/core/entry/FreezeResolver.js +1 -1
- package/dist/es2017/core/entry/content_preparer.d.ts +1 -6
- package/dist/es2017/core/entry/content_preparer.d.ts.map +1 -1
- package/dist/es2017/core/entry/content_preparer.js +1 -76
- package/dist/es2017/core/entry/content_time_boundaries_observer.d.ts.map +1 -1
- package/dist/es2017/core/entry/content_time_boundaries_observer.js +8 -0
- package/dist/es2017/core/entry/core_entry.d.ts +1 -1
- package/dist/es2017/core/entry/core_entry.d.ts.map +1 -1
- package/dist/es2017/core/entry/core_entry.js +2 -7
- package/dist/es2017/core/entry/core_text_displayer_interface.d.ts.map +1 -1
- package/dist/es2017/core/entry/core_text_displayer_interface.js +3 -1
- package/dist/es2017/core/entry/index.d.ts +1 -1
- package/dist/es2017/core/entry/index.d.ts.map +1 -1
- package/dist/es2017/core/entry/utils.d.ts +64 -0
- package/dist/es2017/core/entry/utils.d.ts.map +1 -1
- package/dist/es2017/core/entry/utils.js +98 -0
- package/dist/es2017/core/fetchers/segment/segment_queue.d.ts +5 -6
- package/dist/es2017/core/fetchers/segment/segment_queue.d.ts.map +1 -1
- package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
- package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.js +21 -16
- package/dist/es2017/core/stream/representation/encryption_data_notifier.d.ts +70 -0
- package/dist/es2017/core/stream/representation/encryption_data_notifier.d.ts.map +1 -0
- package/dist/es2017/core/stream/representation/encryption_data_notifier.js +80 -0
- package/dist/es2017/core/stream/representation/representation_stream.d.ts.map +1 -1
- package/dist/es2017/core/stream/representation/representation_stream.js +10 -38
- package/dist/es2017/core/stream/representation/utils/get_needed_segments.js +1 -1
- package/dist/es2017/default_config.d.ts +5 -0
- package/dist/es2017/default_config.d.ts.map +1 -1
- package/dist/es2017/default_config.js +5 -0
- package/dist/es2017/experimental/features/worker/index.d.ts +2 -1
- package/dist/es2017/experimental/features/worker/index.d.ts.map +1 -1
- package/dist/es2017/experimental/features/worker/index.js +2 -3
- package/dist/es2017/main_thread/api/public_api.d.ts.map +1 -1
- package/dist/es2017/main_thread/api/public_api.js +28 -4
- package/dist/es2017/main_thread/init/directfile_content_initializer.d.ts.map +1 -1
- package/dist/es2017/main_thread/init/directfile_content_initializer.js +23 -1
- package/dist/es2017/main_thread/init/utils/initial_seek_and_play.d.ts.map +1 -1
- package/dist/es2017/main_thread/init/utils/initial_seek_and_play.js +3 -1
- package/dist/es2017/manifest/classes/index.d.ts +2 -1
- package/dist/es2017/manifest/classes/index.d.ts.map +1 -1
- package/dist/es2017/manifest/classes/representation.d.ts +1 -1
- package/dist/es2017/manifest/classes/representation.d.ts.map +1 -1
- package/dist/es2017/manifest/classes/representation.js +1 -1
- package/dist/es2017/manifest/classes/representation_index/types.d.ts +2 -2
- package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
- package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
- package/dist/es2017/utils/base64.d.ts +15 -1
- package/dist/es2017/utils/base64.d.ts.map +1 -1
- package/dist/es2017/utils/base64.js +6 -0
- package/dist/es2017/utils/ranges.d.ts +1 -1
- package/dist/es2017/utils/ranges.js +1 -1
- package/dist/mpd-parser.wasm +0 -0
- package/dist/worker.js +8 -8
- package/package.json +26 -23
- package/src/__GENERATED_CODE/embedded_dash_wasm.ts +1 -1
- package/src/__GENERATED_CODE/embedded_worker.ts +1 -1
- package/src/compat/should_seek_at_zero.ts +23 -0
- package/src/core/adaptive/__tests__/adaptive_representation_selector.test.ts +734 -0
- package/src/core/adaptive/__tests__/guess_based_chooser.test.ts +793 -0
- package/src/core/adaptive/__tests__/network_analyzer.test.ts +514 -0
- package/src/core/adaptive/utils/__tests__/bandwidth_estimator.test.ts +117 -0
- package/src/core/adaptive/utils/__tests__/last_estimate_storage.test.ts +76 -0
- package/src/core/adaptive/utils/__tests__/pending_requests_store.test.ts +288 -0
- package/src/core/adaptive/utils/__tests__/representation_score_calculator.test.ts +249 -0
- package/src/core/cmcd/__tests__/cmcd_data_builder.test.ts +464 -0
- package/src/core/cmcd/cmcd_data_builder.ts +2 -2
- package/src/core/entry/FreezeResolver.ts +1 -1
- package/src/core/entry/__tests__/FreezeResolver.test.ts +542 -0
- package/src/core/entry/__tests__/content_time_boundaries_observer.test.ts +867 -0
- package/src/core/entry/__tests__/core_text_displayer_interface.test.ts +205 -0
- package/src/core/entry/__tests__/get_buffered_data_per_media_buffer.test.ts +95 -0
- package/src/core/entry/__tests__/track_choice_setter.test.ts +288 -0
- package/src/core/entry/__tests__/utils.test.ts +309 -0
- package/src/core/entry/content_preparer.ts +7 -118
- package/src/core/entry/content_time_boundaries_observer.ts +10 -0
- package/src/core/entry/core_entry.ts +7 -14
- package/src/core/entry/core_text_displayer_interface.ts +3 -1
- package/src/core/entry/index.ts +1 -1
- package/src/core/entry/utils.ts +151 -0
- package/src/core/fetchers/__tests__/cdn_prioritizer.test.ts +166 -0
- package/src/core/fetchers/manifest/__tests__/manifest_fetcher.test.ts +803 -0
- package/src/core/fetchers/segment/__tests__/segment_fetcher.test.ts +872 -0
- package/src/core/fetchers/segment/__tests__/segment_queue.test.ts +557 -0
- package/src/core/fetchers/segment/segment_queue.ts +5 -6
- package/src/core/fetchers/thumbnails/__tests__/thumbnail_fetcher.test.ts +435 -0
- package/src/core/fetchers/thumbnails/thumbnail_fetcher.ts +28 -20
- package/src/core/fetchers/utils/__tests__/schedule_request.test.ts +331 -0
- package/src/core/stream/adaptation/__tests__/get_representations_switch_strategy.test.ts +593 -0
- package/src/core/stream/period/utils/__tests__/get_adaptation_switch_strategy.test.ts +646 -0
- package/src/core/stream/representation/__tests__/encryption_data_notifier.test.ts +531 -0
- package/src/core/stream/representation/encryption_data_notifier.ts +122 -0
- package/src/core/stream/representation/representation_stream.ts +11 -49
- package/src/core/stream/representation/utils/__tests__/append_segment_to_buffer.test.ts +321 -0
- package/src/core/stream/representation/utils/__tests__/check_for_discontinuity.test.ts +513 -0
- package/src/core/stream/representation/utils/__tests__/get_segment_priority.test.ts +132 -0
- package/src/core/stream/representation/utils/__tests__/push_init_segment.test.ts +209 -0
- package/src/core/stream/representation/utils/__tests__/push_media_segment.test.ts +343 -0
- package/src/core/stream/representation/utils/get_needed_segments.ts +1 -1
- package/src/default_config.ts +6 -0
- package/src/experimental/features/worker/index.ts +2 -4
- package/src/main_thread/api/public_api.ts +33 -4
- package/src/main_thread/init/directfile_content_initializer.ts +26 -1
- package/src/main_thread/init/utils/initial_seek_and_play.ts +5 -1
- package/src/manifest/classes/index.ts +2 -0
- package/src/manifest/classes/representation.ts +2 -1
- package/src/manifest/classes/representation_index/types.ts +2 -2
- package/src/mse/__tests__/main_media_source_interface.test.ts +846 -0
- package/src/parsers/texttracks/ttml/html/apply_line_height.ts +16 -1
- package/src/utils/__tests__/base64.test.ts +159 -191
- package/src/utils/base64.ts +30 -1
- package/src/utils/ranges.ts +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import noop from "../../../utils/noop";
|
|
3
|
+
import { CancellationError } from "../../../utils/task_canceller";
|
|
4
|
+
import { CoreMessageType } from "../../types";
|
|
5
|
+
import CoreTextDisplayerInterface from "../core_text_displayer_interface";
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
12
|
+
|
|
13
|
+
const mockLogError = vi.hoisted(() => {
|
|
14
|
+
return vi.fn();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
vi.mock("../../../log", () => ({
|
|
18
|
+
default: {
|
|
19
|
+
error: mockLogError,
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock("../../../utils/task_canceller", () => ({
|
|
24
|
+
CancellationError: class MockCancellationError extends Error {
|
|
25
|
+
constructor(name: string, reason: string) {
|
|
26
|
+
super(reason);
|
|
27
|
+
this.name = name;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
describe("CoreTextDisplayerInterface", () => {
|
|
33
|
+
let messageSender: any;
|
|
34
|
+
let cdi: CoreTextDisplayerInterface;
|
|
35
|
+
const CONTENT_ID = "test-content-id";
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
messageSender = vi.fn();
|
|
39
|
+
mockLogError.mockReset();
|
|
40
|
+
cdi = new CoreTextDisplayerInterface(CONTENT_ID, messageSender);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("constructor", () => {
|
|
44
|
+
it("should initialize with empty queues", () => {
|
|
45
|
+
expect(cdi._queues.pushTextData).toHaveLength(0);
|
|
46
|
+
expect(cdi._queues.remove).toHaveLength(0);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("pushTextData", () => {
|
|
51
|
+
it("should send a PushTextData message with contentId and infos", () => {
|
|
52
|
+
const infos = { data: "subtitle data" } as any;
|
|
53
|
+
cdi.pushTextData(infos);
|
|
54
|
+
expect(messageSender).toHaveBeenCalledOnce();
|
|
55
|
+
expect(messageSender).toHaveBeenCalledWith({
|
|
56
|
+
type: CoreMessageType.PushTextData,
|
|
57
|
+
contentId: CONTENT_ID,
|
|
58
|
+
value: infos,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should push a resolve/reject pair into pushTextData queue", () => {
|
|
63
|
+
cdi.pushTextData({} as any);
|
|
64
|
+
expect(cdi._queues.pushTextData).toHaveLength(1);
|
|
65
|
+
expect(cdi._queues.remove).toHaveLength(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should return a promise that resolves via onPushedTrackSuccess", async () => {
|
|
69
|
+
const ranges = [{ start: 0, end: 10 }];
|
|
70
|
+
const promise = cdi.pushTextData({} as any);
|
|
71
|
+
cdi.onPushedTrackSuccess(ranges);
|
|
72
|
+
await expect(promise).resolves.toEqual(ranges);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should return a promise that rejects via onPushedTrackError", async () => {
|
|
76
|
+
const error = new Error("push failed");
|
|
77
|
+
const promise = cdi.pushTextData({} as any);
|
|
78
|
+
cdi.onPushedTrackError(error);
|
|
79
|
+
await expect(promise).rejects.toThrow("push failed");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("remove", () => {
|
|
84
|
+
it("should send a RemoveTextData message with contentId, start, and end", () => {
|
|
85
|
+
cdi.remove(5, 20);
|
|
86
|
+
expect(messageSender).toHaveBeenCalledOnce();
|
|
87
|
+
expect(messageSender).toHaveBeenCalledWith({
|
|
88
|
+
type: CoreMessageType.RemoveTextData,
|
|
89
|
+
contentId: CONTENT_ID,
|
|
90
|
+
value: { start: 5, end: 20 },
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should push a resolve/reject pair into remove queue", () => {
|
|
95
|
+
cdi.remove(0, 10);
|
|
96
|
+
expect(cdi._queues.remove).toHaveLength(1);
|
|
97
|
+
expect(cdi._queues.pushTextData).toHaveLength(0);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should return a promise that resolves via onRemoveSuccess", async () => {
|
|
101
|
+
const ranges = [{ start: 5, end: 20 }];
|
|
102
|
+
const promise = cdi.remove(5, 20);
|
|
103
|
+
cdi.onRemoveSuccess(ranges);
|
|
104
|
+
await expect(promise).resolves.toEqual(ranges);
|
|
105
|
+
});
|
|
106
|
+
it("should return a promise that rejects via onPushedTrackError", async () => {
|
|
107
|
+
const error = new Error("remove failed");
|
|
108
|
+
const promise = cdi.remove(5, 20);
|
|
109
|
+
cdi.onRemoveError(error);
|
|
110
|
+
await expect(promise).rejects.toThrow("remove failed");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("reset", () => {
|
|
115
|
+
it("should send a ResetTextDisplayer message", () => {
|
|
116
|
+
cdi.reset();
|
|
117
|
+
expect(messageSender).toHaveBeenCalledWith({
|
|
118
|
+
type: CoreMessageType.ResetTextDisplayer,
|
|
119
|
+
contentId: CONTENT_ID,
|
|
120
|
+
value: null,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should reject all pending pushTextData and remove promises", async () => {
|
|
125
|
+
const pushPromise = cdi.pushTextData({} as any);
|
|
126
|
+
const removePromise = cdi.remove(0, 10);
|
|
127
|
+
cdi.reset();
|
|
128
|
+
await expect(pushPromise).rejects.toBeInstanceOf(CancellationError);
|
|
129
|
+
await expect(removePromise).rejects.toBeInstanceOf(CancellationError);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should clear both queues after reset", () => {
|
|
133
|
+
cdi.pushTextData({} as any).catch(noop);
|
|
134
|
+
cdi.remove(0, 10).catch(noop);
|
|
135
|
+
cdi.reset();
|
|
136
|
+
expect(cdi._queues.pushTextData).toHaveLength(0);
|
|
137
|
+
expect(cdi._queues.remove).toHaveLength(0);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("stop", () => {
|
|
142
|
+
it("should send a StopTextDisplayer message", () => {
|
|
143
|
+
cdi.stop("user stopped");
|
|
144
|
+
expect(messageSender).toHaveBeenCalledWith({
|
|
145
|
+
type: CoreMessageType.StopTextDisplayer,
|
|
146
|
+
contentId: CONTENT_ID,
|
|
147
|
+
value: null,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should reject all pending promises with a CancellationError", async () => {
|
|
152
|
+
const pushPromise = cdi.pushTextData({} as any);
|
|
153
|
+
const removePromise = cdi.remove(0, 10);
|
|
154
|
+
cdi.stop("stopped for test");
|
|
155
|
+
await expect(pushPromise).rejects.toBeInstanceOf(CancellationError);
|
|
156
|
+
await expect(removePromise).rejects.toBeInstanceOf(CancellationError);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("should use 'reset' as fallback reason when undefined is passed", async () => {
|
|
160
|
+
const pushPromise = cdi.pushTextData({} as any);
|
|
161
|
+
cdi.stop(undefined);
|
|
162
|
+
const err = await pushPromise.catch((e) => e);
|
|
163
|
+
expect(err.message).toBe("reset");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("onPushedTrackSuccess", () => {
|
|
168
|
+
it("should log an error and not throw when queue is empty", () => {
|
|
169
|
+
expect(() => cdi.onPushedTrackSuccess([])).not.toThrow();
|
|
170
|
+
expect(mockLogError).toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should resolve operations in FIFO order", async () => {
|
|
174
|
+
const ranges1 = [{ start: 0, end: 1 }];
|
|
175
|
+
const ranges2 = [{ start: 2, end: 3 }];
|
|
176
|
+
const p1 = cdi.pushTextData({} as any);
|
|
177
|
+
const p2 = cdi.pushTextData({} as any);
|
|
178
|
+
cdi.onPushedTrackSuccess(ranges1);
|
|
179
|
+
cdi.onPushedTrackSuccess(ranges2);
|
|
180
|
+
await expect(p1).resolves.toEqual(ranges1);
|
|
181
|
+
await expect(p2).resolves.toEqual(ranges2);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("onPushedTrackError", () => {
|
|
186
|
+
it("should log an error and not throw when queue is empty", () => {
|
|
187
|
+
expect(() => cdi.onPushedTrackError(new Error())).not.toThrow();
|
|
188
|
+
expect(mockLogError).toHaveBeenCalled();
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("onRemoveSuccess", () => {
|
|
193
|
+
it("should log an error and not throw when queue is empty", () => {
|
|
194
|
+
expect(() => cdi.onRemoveSuccess([])).not.toThrow();
|
|
195
|
+
expect(mockLogError).toHaveBeenCalled();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("onRemoveError", () => {
|
|
200
|
+
it("should log an error and not throw when queue is empty", () => {
|
|
201
|
+
expect(() => cdi.onRemoveError(new Error())).not.toThrow();
|
|
202
|
+
expect(mockLogError).toHaveBeenCalled();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { SourceBufferType } from "../../../mse";
|
|
3
|
+
|
|
4
|
+
const mockArrayFind = vi.hoisted(() => vi.fn());
|
|
5
|
+
|
|
6
|
+
vi.mock("../../../utils/array_find", () => ({
|
|
7
|
+
default: mockArrayFind,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
import getBufferedDataPerMediaBuffer from "../get_buffered_data_per_media_buffer";
|
|
11
|
+
|
|
12
|
+
describe("getBufferedDataPerMediaBuffer", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockArrayFind.mockReset();
|
|
15
|
+
// Default: mimic real arrayFind behavior
|
|
16
|
+
mockArrayFind.mockImplementation(
|
|
17
|
+
// eslint-disable-next-line no-restricted-properties
|
|
18
|
+
(arr: unknown[], predicate: (item: unknown) => boolean) => arr.find(predicate),
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should return all nulls when both arguments are null", () => {
|
|
23
|
+
const result = getBufferedDataPerMediaBuffer(null, null);
|
|
24
|
+
expect(result).toEqual({ audio: null, video: null, text: null });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should return text ranges from textDisplayer when provided", () => {
|
|
28
|
+
const textRanges = [{ start: 0, end: 10 }];
|
|
29
|
+
const textDisplayer = { getBufferedRanges: vi.fn(() => textRanges) };
|
|
30
|
+
const result = getBufferedDataPerMediaBuffer(null, textDisplayer as never);
|
|
31
|
+
expect(result.text).toBe(textRanges);
|
|
32
|
+
expect(result.audio).toBeNull();
|
|
33
|
+
expect(result.video).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should return audio and video ranges from mediaSourceInterface", () => {
|
|
37
|
+
const audioRanges = [{ start: 0, end: 5 }];
|
|
38
|
+
const videoRanges = [{ start: 0, end: 8 }];
|
|
39
|
+
|
|
40
|
+
const audioSourceBuffer = {
|
|
41
|
+
type: SourceBufferType.Audio,
|
|
42
|
+
getBuffered: vi.fn(() => audioRanges),
|
|
43
|
+
};
|
|
44
|
+
const videoSourceBuffer = {
|
|
45
|
+
type: SourceBufferType.Video,
|
|
46
|
+
getBuffered: vi.fn(() => videoRanges),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
mockArrayFind
|
|
50
|
+
.mockImplementationOnce(() => audioSourceBuffer)
|
|
51
|
+
.mockImplementationOnce(() => videoSourceBuffer);
|
|
52
|
+
|
|
53
|
+
const mediaSourceInterface = {
|
|
54
|
+
sourceBuffers: [audioSourceBuffer, videoSourceBuffer],
|
|
55
|
+
};
|
|
56
|
+
const result = getBufferedDataPerMediaBuffer(mediaSourceInterface as never, null);
|
|
57
|
+
|
|
58
|
+
expect(result.audio).toBe(audioRanges);
|
|
59
|
+
expect(result.video).toBe(videoRanges);
|
|
60
|
+
expect(result.text).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should keep audio/video as null if source buffers are not found", () => {
|
|
64
|
+
mockArrayFind.mockReturnValue(undefined);
|
|
65
|
+
const mediaSourceInterface = { sourceBuffers: [] };
|
|
66
|
+
const result = getBufferedDataPerMediaBuffer(mediaSourceInterface as never, null);
|
|
67
|
+
expect(result.audio).toBeNull();
|
|
68
|
+
expect(result.video).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should combine text displayer and mediaSourceInterface results", () => {
|
|
72
|
+
const textRanges = [{ start: 1, end: 3 }];
|
|
73
|
+
const audioRanges = [{ start: 0, end: 10 }];
|
|
74
|
+
const textDisplayer = { getBufferedRanges: vi.fn(() => textRanges) };
|
|
75
|
+
|
|
76
|
+
const audioSourceBuffer = {
|
|
77
|
+
type: SourceBufferType.Audio,
|
|
78
|
+
getBuffered: vi.fn(() => audioRanges),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
mockArrayFind
|
|
82
|
+
.mockImplementationOnce(() => audioSourceBuffer)
|
|
83
|
+
.mockImplementationOnce(() => undefined);
|
|
84
|
+
|
|
85
|
+
const mediaSourceInterface = { sourceBuffers: [audioSourceBuffer] };
|
|
86
|
+
const result = getBufferedDataPerMediaBuffer(
|
|
87
|
+
mediaSourceInterface as never,
|
|
88
|
+
textDisplayer as never,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(result.text).toBe(textRanges);
|
|
92
|
+
expect(result.audio).toBe(audioRanges);
|
|
93
|
+
expect(result.video).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
|
|
2
|
+
import TrackChoiceSetter from "../track_choice_setter";
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
8
|
+
|
|
9
|
+
const mockLog = vi.hoisted(() => {
|
|
10
|
+
return { warn: vi.fn(), debug: vi.fn() };
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
vi.mock("../../../log", () => ({
|
|
14
|
+
default: mockLog,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const mockIsNullOrUndefined = vi.hoisted(() => {
|
|
18
|
+
return vi.fn((val: unknown) => val === null || val === undefined);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
vi.mock("../../../utils/is_null_or_undefined", () => ({
|
|
22
|
+
default: mockIsNullOrUndefined,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const mockObjectAssign = vi.hoisted(() => {
|
|
26
|
+
return vi.fn((target: object, ...sources: object[]) =>
|
|
27
|
+
// eslint-disable-next-line no-restricted-properties
|
|
28
|
+
Object.assign(target, ...sources),
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
vi.mock("../../../utils/object_assign", () => ({
|
|
33
|
+
default: mockObjectAssign,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
// We need a real SharedReference-like implementation to make tests meaningful
|
|
37
|
+
const MockSharedReference = vi.hoisted(() => {
|
|
38
|
+
return class MockedSharedReference<T> {
|
|
39
|
+
private _value: T;
|
|
40
|
+
public finish = vi.fn();
|
|
41
|
+
|
|
42
|
+
constructor(initialValue: T) {
|
|
43
|
+
this._value = initialValue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getValue(): T {
|
|
47
|
+
return this._value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setValue(val: T): void {
|
|
51
|
+
this._value = val;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
vi.mock("../../../utils/reference", () => ({
|
|
57
|
+
default: MockSharedReference,
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
function makeRef<T>(val: T): any {
|
|
61
|
+
return new MockSharedReference(val);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe("TrackChoiceSetter", () => {
|
|
65
|
+
let setter: TrackChoiceSetter;
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
setter = new TrackChoiceSetter();
|
|
69
|
+
});
|
|
70
|
+
afterEach(() => {
|
|
71
|
+
vi.resetAllMocks();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("addTrackSetter", () => {
|
|
75
|
+
it("should add a track setter without error for a new period/type", () => {
|
|
76
|
+
const ref = makeRef(null);
|
|
77
|
+
expect(() => setter.addTrackSetter("p1", "audio", ref)).not.toThrow();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should warn and finish old references if track setter already declared for same period/type", () => {
|
|
81
|
+
const ref1 = makeRef(null);
|
|
82
|
+
const ref2 = makeRef(null);
|
|
83
|
+
setter.addTrackSetter("p1", "audio", ref1);
|
|
84
|
+
setter.addTrackSetter("p1", "audio", ref2);
|
|
85
|
+
expect(mockLog.warn).toHaveBeenCalledOnce();
|
|
86
|
+
expect(ref1.finish).toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should handle a non-null initial value on the ref", () => {
|
|
90
|
+
const representationsRef = makeRef({
|
|
91
|
+
representationIds: ["r1"],
|
|
92
|
+
switchingMode: "direct",
|
|
93
|
+
});
|
|
94
|
+
const choice = {
|
|
95
|
+
adaptationId: "a1",
|
|
96
|
+
switchingMode: "direct",
|
|
97
|
+
representations: representationsRef,
|
|
98
|
+
relativeResumingPosition: undefined,
|
|
99
|
+
};
|
|
100
|
+
const ref = makeRef(choice);
|
|
101
|
+
setter.addTrackSetter("p1", "video", ref);
|
|
102
|
+
// objectAssign should have been called to replace representations with a SharedReference
|
|
103
|
+
expect(mockObjectAssign).toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("setTrack", () => {
|
|
108
|
+
it("should return false and log debug when periodId not found", () => {
|
|
109
|
+
const result = setter.setTrack("unknown", "audio", null);
|
|
110
|
+
expect(result).toBe(false);
|
|
111
|
+
expect(mockLog.debug).toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should return true and set null track choice", () => {
|
|
115
|
+
const ref = makeRef(null);
|
|
116
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
117
|
+
const result = setter.setTrack("p1", "audio", null);
|
|
118
|
+
expect(result).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should return true and set a valid track choice", () => {
|
|
122
|
+
const ref = makeRef(null);
|
|
123
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
124
|
+
const result = setter.setTrack("p1", "audio", {
|
|
125
|
+
adaptationId: "a1",
|
|
126
|
+
switchingMode: "direct",
|
|
127
|
+
initialRepresentations: {
|
|
128
|
+
representationIds: ["r1"],
|
|
129
|
+
switchingMode: "direct",
|
|
130
|
+
},
|
|
131
|
+
relativeResumingPosition: undefined,
|
|
132
|
+
});
|
|
133
|
+
expect(result).toBe(true);
|
|
134
|
+
const val = ref.getValue();
|
|
135
|
+
expect(val.adaptationId).toBe("a1");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should return false when bufferType not registered for a known period", () => {
|
|
139
|
+
const ref = makeRef(null);
|
|
140
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
141
|
+
const result = setter.setTrack("p1", "video", null);
|
|
142
|
+
expect(result).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("updateRepresentations", () => {
|
|
147
|
+
it("should return false when period not found", () => {
|
|
148
|
+
const result = setter.updateRepresentations("unknown", "a1", "audio", {
|
|
149
|
+
representationIds: [],
|
|
150
|
+
switchingMode: "direct",
|
|
151
|
+
});
|
|
152
|
+
expect(result).toBe(false);
|
|
153
|
+
expect(mockLog.debug).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should return false when current trackReference value is null", () => {
|
|
157
|
+
const ref = makeRef(null);
|
|
158
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
159
|
+
const result = setter.updateRepresentations("p1", "a1", "audio", {
|
|
160
|
+
representationIds: [],
|
|
161
|
+
switchingMode: "direct",
|
|
162
|
+
});
|
|
163
|
+
expect(result).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should return false when adaptationId is desynchronized", () => {
|
|
167
|
+
const representationsRef = makeRef({
|
|
168
|
+
representationIds: [],
|
|
169
|
+
switchingMode: "direct",
|
|
170
|
+
});
|
|
171
|
+
const ref = makeRef({
|
|
172
|
+
adaptationId: "a1",
|
|
173
|
+
switchingMode: "direct",
|
|
174
|
+
representations: representationsRef,
|
|
175
|
+
relativeResumingPosition: undefined,
|
|
176
|
+
});
|
|
177
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
178
|
+
// setTrack to ensure internal state is set
|
|
179
|
+
const result = setter.updateRepresentations("p1", "different-id", "audio", {
|
|
180
|
+
representationIds: [],
|
|
181
|
+
switchingMode: "direct",
|
|
182
|
+
});
|
|
183
|
+
expect(result).toBe(false);
|
|
184
|
+
expect(mockLog.debug).toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should return true and update representations when adaptationId matches", () => {
|
|
188
|
+
const ref = makeRef(null);
|
|
189
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
190
|
+
setter.setTrack("p1", "audio", {
|
|
191
|
+
adaptationId: "a1",
|
|
192
|
+
switchingMode: "direct",
|
|
193
|
+
initialRepresentations: {
|
|
194
|
+
representationIds: ["r1"],
|
|
195
|
+
switchingMode: "direct",
|
|
196
|
+
},
|
|
197
|
+
relativeResumingPosition: undefined,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const result = setter.updateRepresentations("p1", "a1", "audio", {
|
|
201
|
+
representationIds: ["r2"],
|
|
202
|
+
switchingMode: "direct",
|
|
203
|
+
});
|
|
204
|
+
expect(result).toBe(true);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("removeTrackSetter", () => {
|
|
209
|
+
it("should return false and log debug when period not found", () => {
|
|
210
|
+
const result = setter.removeTrackSetter("unknown", "audio");
|
|
211
|
+
expect(result).toBe(false);
|
|
212
|
+
expect(mockLog.debug).toHaveBeenCalled();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("should return false when bufferType not registered", () => {
|
|
216
|
+
const ref = makeRef(null);
|
|
217
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
218
|
+
const result = setter.removeTrackSetter("p1", "video");
|
|
219
|
+
expect(result).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("should return true, finish references, and clean up on removal", () => {
|
|
223
|
+
const ref = makeRef(null);
|
|
224
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
225
|
+
const result = setter.removeTrackSetter("p1", "audio");
|
|
226
|
+
expect(result).toBe(true);
|
|
227
|
+
// trackReference.finish should have been called
|
|
228
|
+
expect(ref.finish).toHaveBeenCalled();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("should allow re-adding after removal", () => {
|
|
232
|
+
const ref = makeRef(null);
|
|
233
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
234
|
+
setter.removeTrackSetter("p1", "audio");
|
|
235
|
+
const ref2 = makeRef(null);
|
|
236
|
+
expect(() => setter.addTrackSetter("p1", "audio", ref2)).not.toThrow();
|
|
237
|
+
expect(mockLog.warn).not.toHaveBeenCalled();
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe("reset", () => {
|
|
242
|
+
it("should finish all references and clear state", () => {
|
|
243
|
+
const refAudio = makeRef(null);
|
|
244
|
+
const refVideo = makeRef(null);
|
|
245
|
+
setter.addTrackSetter("p1", "audio", refAudio);
|
|
246
|
+
setter.addTrackSetter("p1", "video", refVideo);
|
|
247
|
+
setter.reset();
|
|
248
|
+
// After reset, setting a track should return false (no period registered)
|
|
249
|
+
const result = setter.setTrack("p1", "audio", null);
|
|
250
|
+
expect(result).toBe(false);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("should finish all SharedReferences on reset", () => {
|
|
254
|
+
const ref = makeRef(null);
|
|
255
|
+
setter.addTrackSetter("p1", "audio", ref);
|
|
256
|
+
setter.reset();
|
|
257
|
+
expect(ref.finish).toHaveBeenCalled();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("should handle reset on empty setter without error", () => {
|
|
261
|
+
expect(() => setter.reset()).not.toThrow();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("multiple periods", () => {
|
|
266
|
+
it("should handle multiple periods independently", () => {
|
|
267
|
+
const ref1 = makeRef(null);
|
|
268
|
+
const ref2 = makeRef(null);
|
|
269
|
+
setter.addTrackSetter("p1", "audio", ref1);
|
|
270
|
+
setter.addTrackSetter("p2", "audio", ref2);
|
|
271
|
+
|
|
272
|
+
const r1 = setter.setTrack("p1", "audio", null);
|
|
273
|
+
const r2 = setter.setTrack("p2", "audio", null);
|
|
274
|
+
expect(r1).toBe(true);
|
|
275
|
+
expect(r2).toBe(true);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("removing one period should not affect another", () => {
|
|
279
|
+
const ref1 = makeRef(null);
|
|
280
|
+
const ref2 = makeRef(null);
|
|
281
|
+
setter.addTrackSetter("p1", "audio", ref1);
|
|
282
|
+
setter.addTrackSetter("p2", "audio", ref2);
|
|
283
|
+
setter.removeTrackSetter("p1", "audio");
|
|
284
|
+
const result = setter.setTrack("p2", "audio", null);
|
|
285
|
+
expect(result).toBe(true);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|