Skip to content

Commit a4ae90c

Browse files
author
Pavel Fomin
committed
fixies after review
1 parent fcdef48 commit a4ae90c

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

api-extractor/report/hls.js.api.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,12 @@ export class ContentSteeringController extends Logger implements NetworkComponen
792792
// (undocumented)
793793
filterParsedLevels(levels: Level[]): Level[];
794794
// (undocumented)
795+
getPathwaysList(levels: Level[]): string[];
796+
// (undocumented)
797+
get levels(): Level[];
798+
// (undocumented)
795799
get pathwayPriority(): string[] | null;
796-
set pathwayPriority(pathwayPriority: string[] | null);
800+
set pathwayPriority(pathwayPriority: string[]);
797801
// (undocumented)
798802
removeLevel(levelToRemove: Level): void;
799803
// (undocumented)
@@ -1630,7 +1634,7 @@ class Hls implements HlsEventEmitter {
16301634
// (undocumented)
16311635
once<E extends keyof HlsListeners, Context = undefined>(event: E, listener: HlsListeners[E], context?: Context): void;
16321636
get pathwayPriority(): string[] | null;
1633-
set pathwayPriority(pathwayPriority: string[] | null);
1637+
set pathwayPriority(pathwayPriority: string[]);
16341638
pauseBuffering(): void;
16351639
get playingDate(): Date | null;
16361640
recoverMediaError(): void;

src/controller/content-steering-controller.ts

+29-23
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class ContentSteeringController
6262
private updated: number = 0;
6363
private started: boolean = false;
6464
private enabled: boolean = true;
65-
private levels: Level[] | null = null;
65+
private _levels: Level[] | null = null;
6666
private audioTracks: MediaPlaylist[] | null = null;
6767
private subtitleTracks: MediaPlaylist[] | null = null;
6868
private penalizedPathways: { [pathwayId: string]: number } = {};
@@ -92,14 +92,25 @@ export default class ContentSteeringController
9292
hls.off(Events.ERROR, this.onError, this);
9393
}
9494

95-
get pathwayPriority() {
95+
getPathwaysList(levels: Level[]) {
96+
return levels.reduce((pathways, level) => {
97+
if (pathways.indexOf(level.pathwayId) === -1) {
98+
pathways.push(level.pathwayId);
99+
}
100+
return pathways;
101+
}, [] as string[]);
102+
}
103+
104+
get pathwayPriority(): string[] | null {
96105
return this._pathwayPriority;
97106
}
98107

99-
set pathwayPriority(pathwayPriority) {
100-
if (pathwayPriority) {
101-
this.updatePathwayPriority(pathwayPriority);
102-
}
108+
set pathwayPriority(pathwayPriority: string[]) {
109+
this.updatePathwayPriority(pathwayPriority);
110+
}
111+
112+
get levels(): Level[] {
113+
return this._levels || [];
103114
}
104115

105116
startLoad() {
@@ -138,13 +149,13 @@ export default class ContentSteeringController
138149
this.stopLoad();
139150
// @ts-ignore
140151
this.hls = null;
141-
this.levels = this.audioTracks = this.subtitleTracks = null;
152+
this._levels = this.audioTracks = this.subtitleTracks = null;
142153
}
143154

144155
removeLevel(levelToRemove: Level) {
145-
const levels = this.levels;
156+
const levels = this._levels;
146157
if (levels) {
147-
this.levels = levels.filter((level) => level !== levelToRemove);
158+
this._levels = levels.filter((level) => level !== levelToRemove);
148159
}
149160
}
150161

@@ -155,7 +166,7 @@ export default class ContentSteeringController
155166
this.updated = 0;
156167
this.uri = null;
157168
this.pathwayId = '.';
158-
this.levels = this.audioTracks = this.subtitleTracks = null;
169+
this._levels = this.audioTracks = this.subtitleTracks = null;
159170
}
160171

161172
private onManifestLoaded(
@@ -187,7 +198,7 @@ export default class ContentSteeringController
187198
errorAction?.action === NetworkErrorAction.SendAlternateToPenaltyBox &&
188199
errorAction.flags === ErrorActionFlags.MoveAllAlternatesMatchingHost
189200
) {
190-
const levels = this.levels;
201+
const levels = this._levels;
191202
let pathwayPriority = this._pathwayPriority;
192203
let errorPathway = this.pathwayId;
193204
if (data.context) {
@@ -203,12 +214,7 @@ export default class ContentSteeringController
203214
}
204215
if (!pathwayPriority && levels) {
205216
// If PATHWAY-PRIORITY was not provided, list pathways for error handling
206-
pathwayPriority = levels.reduce((pathways, level) => {
207-
if (pathways.indexOf(level.pathwayId) === -1) {
208-
pathways.push(level.pathwayId);
209-
}
210-
return pathways;
211-
}, [] as string[]);
217+
pathwayPriority = this.getPathwaysList(levels);
212218
}
213219
if (pathwayPriority && pathwayPriority.length > 1) {
214220
this.updatePathwayPriority(pathwayPriority);
@@ -230,7 +236,7 @@ export default class ContentSteeringController
230236

231237
public filterParsedLevels(levels: Level[]): Level[] {
232238
// Filter levels to only include those that are in the initial pathway
233-
this.levels = levels;
239+
this._levels = levels;
234240
let pathwayLevels = this.getLevelsForPathway(this.pathwayId);
235241
if (pathwayLevels.length === 0) {
236242
const pathwayId = levels[0].pathwayId;
@@ -250,10 +256,10 @@ export default class ContentSteeringController
250256
}
251257

252258
private getLevelsForPathway(pathwayId: string): Level[] {
253-
if (this.levels === null) {
259+
if (this._levels === null) {
254260
return [];
255261
}
256-
return this.levels.filter((level) => pathwayId === level.pathwayId);
262+
return this._levels.filter((level) => pathwayId === level.pathwayId);
257263
}
258264

259265
private updatePathwayPriority(pathwayPriority: string[]) {
@@ -286,7 +292,7 @@ export default class ContentSteeringController
286292
this.hls.trigger(Events.LEVELS_UPDATED, { levels });
287293
// Set LevelController's level to trigger LEVEL_SWITCHING which loads playlist if needed
288294
const levelAfterChange = this.hls.levels[selectedIndex];
289-
if (selectedLevel && levelAfterChange && this.levels) {
295+
if (selectedLevel && levelAfterChange && this._levels) {
290296
if (
291297
levelAfterChange.attrs['STABLE-VARIANT-ID'] !==
292298
selectedLevel.attrs['STABLE-VARIANT-ID'] &&
@@ -309,7 +315,7 @@ export default class ContentSteeringController
309315
defaultPathway: string,
310316
): string {
311317
const levels = this.getLevelsForPathway(defaultPathway).concat(
312-
this.levels || [],
318+
this._levels || [],
313319
);
314320
for (let i = 0; i < levels.length; i++) {
315321
if (
@@ -325,7 +331,7 @@ export default class ContentSteeringController
325331
}
326332

327333
private clonePathways(pathwayClones: PathwayClone[]) {
328-
const levels = this.levels;
334+
const levels = this._levels;
329335
if (!levels) {
330336
return;
331337
}

src/controller/level-controller.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,19 @@ export default class LevelController extends BasePlaylistController {
513513
return null;
514514
}
515515

516-
set pathwayPriority(pathwayPriority) {
517-
if (this.steering) {
518-
this.steering.pathwayPriority = pathwayPriority;
516+
set pathwayPriority(pathwayPriority: string[]) {
517+
if (this.steering?.levels?.length) {
518+
const pathwaysList = this.steering.getPathwaysList(this.steering.levels);
519+
const filteredPathwayPriority = pathwayPriority.filter((pathwayId) => {
520+
return pathwaysList.indexOf(pathwayId) !== -1;
521+
});
522+
if (pathwayPriority.length < 1) {
523+
this.warn(
524+
`pathwayPriority ${pathwayPriority} should contain at least one pathway from list: ${pathwaysList}`,
525+
);
526+
return;
527+
}
528+
this.steering.pathwayPriority = filteredPathwayPriority;
519529
}
520530
}
521531

src/hls.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ export default class Hls implements HlsEventEmitter {
989989
return this.levelController.pathwayPriority;
990990
}
991991

992-
set pathwayPriority(pathwayPriority: string[] | null) {
992+
set pathwayPriority(pathwayPriority: string[]) {
993993
this.levelController.pathwayPriority = pathwayPriority;
994994
}
995995
}

0 commit comments

Comments
 (0)