Skip to content

Commit

Permalink
Merge pull request #3710 from jwalton/stop-load-after-destroy
Browse files Browse the repository at this point in the history
fix: stopLoad() after destroy() becomes no-op, startLoad() after destroy() throws nicer error message.
  • Loading branch information
robwalch committed Apr 7, 2021
2 parents 9944756 + cd070b5 commit 496c511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/hls.ts
Expand Up @@ -282,16 +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());
// @ts-ignore
this.networkControllers = null;
}
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
15 changes: 15 additions & 0 deletions tests/unit/hls.js
@@ -1,5 +1,6 @@
import Hls from '../../src/hls';
import { hlsDefaultConfig } from '../../src/config';
import { expect } from 'chai';

describe('Hls', function () {
describe('bandwidthEstimate', function () {
Expand All @@ -21,4 +22,18 @@ describe('Hls', function () {
);
});
});

describe('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 crash on startLoad() after destroy()', function () {
const hls = new Hls();
hls.destroy();
expect(() => hls.startLoad()).to.not.throw();
});
});
});

0 comments on commit 496c511

Please sign in to comment.