Skip to content

Commit

Permalink
implement reloading even with worker
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Aug 31, 2023
1 parent 0ac5a2d commit 956466f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/api/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import features from "../../features";
import log from "../../log";
import sendMessage from "../../main/send_message";
import {
import Manifest, {
getLivePosition,
getMaximumSafePosition,
getMinimumSafePosition,
Expand All @@ -46,6 +46,7 @@ import {
IManifestMetadata,
IPeriodMetadata,
IRepresentationMetadata,
ManifestMetadataFormat,
} from "../../manifest";
import {
IAudioRepresentation,
Expand Down Expand Up @@ -274,7 +275,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
* Manifest loaded for the last content that should be used once `reload`
* is called.
*/
manifest?: IManifestMetadata;
manifest?: Manifest;
/**
* If `true`, the player should be paused after reloading.
* If `false`, the player should be playing after reloading.
Expand Down Expand Up @@ -524,7 +525,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
if (autoPlay !== undefined) {
newOptions.autoPlay = autoPlay;
}
// this._priv_initializeContentPlayback(newOptions);
this._priv_initializeContentPlayback(newOptions);
}

public createDebugElement(element : HTMLElement) : {
Expand Down Expand Up @@ -2092,13 +2093,16 @@ class Player extends EventEmitter<IPublicAPIEvent> {
*/
private _priv_onManifestReady(
contentInfos : IPublicApiContentInfos,
manifest : IManifestMetadata
manifest : Manifest | IManifestMetadata
) : void {
if (contentInfos.contentId !== this._priv_contentInfos?.contentId) {
return; // Event for another content
}
contentInfos.manifest = manifest;
this._priv_reloadingMetadata.manifest = manifest;

if (manifest.manifestFormat === ManifestMetadataFormat.Class) {
this._priv_reloadingMetadata.manifest = manifest as Manifest;
}

const tracksStore = new TracksStore({
preferTrickModeTracks: this._priv_preferTrickModeTracks,
Expand Down
5 changes: 5 additions & 0 deletions src/manifest/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
// IAdaptationMetadata,
IManifestMetadata,
IPeriodMetadata,
ManifestMetadataFormat,
MANIFEST_UPDATE_TYPE,
} from "./types";
import {
Expand Down Expand Up @@ -104,6 +105,8 @@ export interface IManifestEvents {
export default class Manifest extends EventEmitter<IManifestEvents>
implements IManifestMetadata
{
public manifestFormat: ManifestMetadataFormat.Class;

/**
* ID uniquely identifying this Manifest.
* No two Manifests should have this ID.
Expand Down Expand Up @@ -321,6 +324,7 @@ export default class Manifest extends EventEmitter<IManifestEvents>
super();
const { representationFilter,
manifestUpdateUrl } = options;
this.manifestFormat = ManifestMetadataFormat.Class;
this.id = generateNewManifestId();
this.expired = parsedManifest.expired ?? null;
this.transport = parsedManifest.transportType;
Expand Down Expand Up @@ -574,6 +578,7 @@ export default class Manifest extends EventEmitter<IManifestEvents>
}

return {
manifestFormat: ManifestMetadataFormat.MetadataObject,
id: this.id,
periods,
isDynamic: this.isDynamic,
Expand Down
30 changes: 30 additions & 0 deletions src/manifest/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ export enum MANIFEST_UPDATE_TYPE {
Partial,
}

/**
* Various formats an `IManifestMetadata` object can take.
*/
export const enum ManifestMetadataFormat {
/**
* This is actually a `Manifest` class, with its event listeners, methods and
* all properties.
*/
Class,
/**
* This is only an object anouncing the properties required by the
* `IManifestMetadata` interface.
*
* The main advantages of this smaller structure is that:
* - it takes less place in memory
* - it can be serialized and thus communicated between threads
* without loss of information.
*
* However it does not contain the full information like `Class` would.
*/
MetadataObject,
}

/**
* Object describing the metadata of a given content.
*
Expand All @@ -51,6 +74,13 @@ export enum MANIFEST_UPDATE_TYPE {
* `IManifestMetadata` object, rather than the full `Manifest` class.
*/
export interface IManifestMetadata {
/**
* Format of the current object respecting the `IManifestMetadata` interface.
* Allowing for several type of formats allows to accomodate several
* environments such as multi-thread scenarios without badly impacting much
* advanced features of a mono-thread scenario.
*/
manifestFormat: ManifestMetadataFormat;
/**
* ID uniquely identifying this Manifest.
* No two Manifests should have this ID.
Expand Down

0 comments on commit 956466f

Please sign in to comment.