Skip to content

Commit

Permalink
Fire STEERING_MANIFEST_LOADED event when loading a Content Steering M…
Browse files Browse the repository at this point in the history
…anifest (#5417)

* Fire STEERING_MANIFEST_LOADED event when loading a Content Steering Manifest

* Use steeringManifest instead of response inside STEERING_MANIFEST_LOADED content

* Fire STEERING_MANIFEST_LOADED between clonePathways and updatePathwayPriority
  • Loading branch information
guillemcabrera authored May 26, 2023
1 parent 15d9ef3 commit 966bd3d
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 39 deletions.
50 changes: 50 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,8 @@ export enum Events {
// (undocumented)
NON_NATIVE_TEXT_TRACKS_FOUND = "hlsNonNativeTextTracksFound",
// (undocumented)
STEERING_MANIFEST_LOADED = "hlsSteeringManifestLoaded",
// (undocumented)
SUBTITLE_FRAG_PROCESSED = "hlsSubtitleFragProcessed",
// (undocumented)
SUBTITLE_TRACK_LOADED = "hlsSubtitleTrackLoaded",
Expand Down Expand Up @@ -1770,6 +1772,8 @@ export interface HlsListeners {
// (undocumented)
[Events.NON_NATIVE_TEXT_TRACKS_FOUND]: (event: Events.NON_NATIVE_TEXT_TRACKS_FOUND, data: NonNativeTextTracksData) => void;
// (undocumented)
[Events.STEERING_MANIFEST_LOADED]: (event: Events.STEERING_MANIFEST_LOADED, data: SteeringManifestLoadedData) => void;
// (undocumented)
[Events.SUBTITLE_FRAG_PROCESSED]: (event: Events.SUBTITLE_FRAG_PROCESSED, data: SubtitleFragProcessedData) => void;
// (undocumented)
[Events.SUBTITLE_TRACK_LOADED]: (event: Events.SUBTITLE_TRACK_LOADED, data: SubtitleTrackLoadedData) => void;
Expand Down Expand Up @@ -2810,6 +2814,15 @@ export class Part extends BaseSegment {
stats: LoadStats;
}

// Warning: (ae-missing-release-tag) "PathwayClone" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type PathwayClone = {
'BASE-ID': string;
ID: string;
'URI-REPLACEMENT': UriReplacement;
};

// Warning: (ae-missing-release-tag) "PlaylistContextType" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -2891,6 +2904,27 @@ export type RetryConfig = {
// @public (undocumented)
export type SourceBufferName = 'video' | 'audio' | 'audiovideo';

// Warning: (ae-missing-release-tag) "SteeringManifest" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type SteeringManifest = {
VERSION: 1;
TTL: number;
'RELOAD-URI'?: string;
'PATHWAY-PRIORITY': string[];
'PATHWAY-CLONES'?: PathwayClone[];
};

// Warning: (ae-missing-release-tag) "SteeringManifestLoadedData" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface SteeringManifestLoadedData {
// (undocumented)
steeringManifest: SteeringManifest;
// (undocumented)
url: string;
}

// Warning: (ae-missing-release-tag) "StreamControllerConfig" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -3143,6 +3177,22 @@ export type TSDemuxerConfig = {
forceKeyFrameOnDiscontinuity: boolean;
};

// Warning: (ae-missing-release-tag) "UriReplacement" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type UriReplacement = {
HOST?: string;
PARAMS?: {
[queryParameter: string]: string;
};
'PER-VARIANT-URIS'?: {
[stableVariantId: string]: string;
};
'PER-RENDITION-URIS'?: {
[stableRenditionId: string]: string;
};
};

// Warning: (ae-missing-release-tag) "UserdataSample" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down
2 changes: 2 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,8 @@ Full list of Events is available below:
- data: { levels : [available quality levels], audioTracks : [available audio tracks], captions? [available closed-captions media], subtitles?: [available subtitle tracks], url : manifestURL, stats : [LoaderStats], sessionData: [parsed #EXT-X-SESSION-DATA], networkDetails: [Loader specific object for debugging (XMLHttpRequest or fetch Response)]}
- `Hls.Events.MANIFEST_PARSED` - fired after manifest has been parsed
- data: { levels : [ available quality levels ], firstLevel : index of first quality level appearing in Manifest, audioTracks, subtitleTracks, stats, audio: boolean, video: boolean, altAudio: boolean }
- `Hls.Events.STEERING_MANIFEST_LOADED` - fired when the Content Steering Manifest is loaded
- data: { `url`: steering manifest URL, `steeringManifest`: SteeringManifest object } }
- `Hls.Events.LEVEL_SWITCHING` - fired when a level switch is requested
- data: { `level` and Level object properties (please see [below](#level) for more information) }
- `Hls.Events.LEVEL_SWITCHED` - fired when a level switch is effective
Expand Down
12 changes: 10 additions & 2 deletions src/controller/content-steering-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { logger } from '../utils/logger';
import type Hls from '../hls';
import type { NetworkComponentAPI } from '../types/component-api';
import type {
SteeringManifestLoadedData,
ErrorData,
ManifestLoadedData,
ManifestParsedData,
Expand All @@ -31,13 +32,13 @@ export type SteeringManifest = {
'PATHWAY-CLONES'?: PathwayClone[];
};

type PathwayClone = {
export type PathwayClone = {
'BASE-ID': string;
ID: string;
'URI-REPLACEMENT': UriReplacement;
};

type UriReplacement = {
export type UriReplacement = {
HOST?: string;
PARAMS?: { [queryParameter: string]: string };
'PER-VARIANT-URIS'?: { [stableVariantId: string]: string };
Expand Down Expand Up @@ -398,6 +399,13 @@ export default class ContentSteeringController implements NetworkComponentAPI {
if (pathwayClones) {
this.clonePathways(pathwayClones);
}

const loadedSteeringData: SteeringManifestLoadedData = {
steeringManifest: steeringData,
url: url.toString(),
};
this.hls.trigger(Events.STEERING_MANIFEST_LOADED, loadedSteeringData);

if (pathwayPriority) {
this.updatePathwayPriority(pathwayPriority);
}
Expand Down
7 changes: 7 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
LiveBackBufferData,
TrackLoadingData,
BufferFlushedData,
SteeringManifestLoadedData,
} from './types/events';

export enum Events {
Expand Down Expand Up @@ -162,6 +163,8 @@ export enum Events {
LIVE_BACK_BUFFER_REACHED = 'hlsLiveBackBufferReached',
// fired when the back buffer is reached as defined by the backBufferLength config option - data : { bufferEnd: number }
BACK_BUFFER_REACHED = 'hlsBackBufferReached',
// fired after steering manifest has been loaded - data: { steeringManifest: SteeringManifest object, url: steering manifest URL }
STEERING_MANIFEST_LOADED = 'hlsSteeringManifestLoaded',
}

/**
Expand Down Expand Up @@ -361,6 +364,10 @@ export interface HlsListeners {
event: Events.BACK_BUFFER_REACHED,
data: BackBufferData
) => void;
[Events.STEERING_MANIFEST_LOADED]: (
event: Events.STEERING_MANIFEST_LOADED,
data: SteeringManifestLoadedData
) => void;
}
export interface HlsEventEmitter {
on<E extends keyof HlsListeners, Context = undefined>(
Expand Down
6 changes: 6 additions & 0 deletions src/hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ export type {
} from './config';
export type { MediaKeySessionContext } from './controller/eme-controller';
export type { ILogger } from './utils/logger';
export type {
PathwayClone,
SteeringManifest,
UriReplacement,
} from './controller/content-steering-controller';
export type { SubtitleStreamController } from './controller/subtitle-stream-controller';
export type { TimelineController } from './controller/timeline-controller';
export type { CuesInterface } from './utils/cues';
Expand Down Expand Up @@ -1035,6 +1040,7 @@ export type {
MediaAttachingData,
NonNativeTextTrack,
NonNativeTextTracksData,
SteeringManifestLoadedData,
SubtitleFragProcessedData,
SubtitleTrackLoadedData,
SubtitleTracksUpdatedData,
Expand Down
6 changes: 6 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { HlsListeners } from '../events';
import type { KeyLoaderInfo } from '../loader/key-loader';
import type { LevelKey } from '../loader/level-key';
import type { IErrorAction } from '../controller/error-controller';
import type { SteeringManifest } from '../controller/content-steering-controller';

export interface MediaAttachingData {
media: HTMLMediaElement;
Expand Down Expand Up @@ -366,3 +367,8 @@ export interface BackBufferData {
* @deprecated Use BackBufferData
*/
export interface LiveBackBufferData extends BackBufferData {}

export interface SteeringManifestLoadedData {
steeringManifest: SteeringManifest;
url: string;
}
Loading

0 comments on commit 966bd3d

Please sign in to comment.