Skip to content

Commit

Permalink
refactor: Update fix to networkControllers and coreComponents based o…
Browse files Browse the repository at this point in the history
…n feedback from review.

re: video-dev#3710
  • Loading branch information
jwalton committed Apr 6, 2021
1 parent 0c32415 commit 0532e8b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/hls.ts
Expand Up @@ -40,7 +40,7 @@ export default class Hls implements HlsEventEmitter {
public readonly userConfig: Partial<HlsConfig>;

private coreComponents: ComponentAPI[];
private networkControllers: NetworkComponentAPI[] | undefined;
private networkControllers: NetworkComponentAPI[];

private _emitter: HlsEventEmitter = new EventEmitter();
private _autoLevelCapping: number;
Expand Down Expand Up @@ -282,15 +282,12 @@ export default class Hls implements HlsEventEmitter {
this.removeAllListeners();
this._autoLevelCapping = -1;
this.url = null;
if (this.networkControllers) {
this.networkControllers.forEach((component) => component.destroy());
this.networkControllers = undefined;
}
if (this.coreComponents) {
this.coreComponents.forEach((component) => component.destroy());
// @ts-ignore
this.coreComponents = null;
}

this.networkControllers.forEach((component) => component.destroy());
this.networkControllers.length = 0;

this.coreComponents.forEach((component) => component.destroy());
this.coreComponents.length = 0;
}

/**
Expand Down Expand Up @@ -341,9 +338,6 @@ export default class Hls implements HlsEventEmitter {
*/
startLoad(startPosition: number = -1) {
logger.log(`startLoad(${startPosition})`);
if (!this.networkControllers) {
throw new Error('Cannot call `startLoad()` on destroyed instance of hls');
}
this.networkControllers.forEach((controller) => {
controller.startLoad(startPosition);
});
Expand All @@ -354,11 +348,9 @@ export default class Hls implements HlsEventEmitter {
*/
stopLoad() {
logger.log('stopLoad');
if (this.networkControllers) {
this.networkControllers.forEach((controller) => {
controller.stopLoad();
});
}
this.networkControllers.forEach((controller) => {
controller.stopLoad();
});
}

/**
Expand Down

0 comments on commit 0532e8b

Please sign in to comment.