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: #3710
  • Loading branch information
jwalton committed Apr 6, 2021
1 parent 0c32415 commit cd070b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 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
8 changes: 3 additions & 5 deletions tests/unit/hls.js
Expand Up @@ -24,18 +24,16 @@ describe('Hls', function () {
});

describe('destroy', function () {
it('should allow stopLoad() after destroy()', function () {
it('should not crash on stopLoad() after destroy()', function () {
const hls = new Hls();
hls.destroy();
expect(() => hls.stopLoad()).to.not.throw();
});

it('should not allow startLoad() after destroy()', function () {
it('should not crash on startLoad() after destroy()', function () {
const hls = new Hls();
hls.destroy();
expect(() => hls.startLoad()).to.throw(
'Cannot call `startLoad()` on destroyed instance of hls'
);
expect(() => hls.startLoad()).to.not.throw();
});
});
});

0 comments on commit cd070b5

Please sign in to comment.