diff --git a/src/hls.ts b/src/hls.ts index db32379ae2d..643672669f6 100644 --- a/src/hls.ts +++ b/src/hls.ts @@ -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; } /** diff --git a/tests/unit/hls.js b/tests/unit/hls.js index b6dcadbca7d..235750badc5 100644 --- a/tests/unit/hls.js +++ b/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 () { @@ -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(); + }); + }); });