Skip to content

Commit

Permalink
Do not detach and reattach media if in an hls.js event loop (prevents…
Browse files Browse the repository at this point in the history
… recursive calls when handlers call loadSource)

Resolves #3732
  • Loading branch information
Rob Walch committed Apr 9, 2021
1 parent d38b0c1 commit 99f044e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hls.ts
Expand Up @@ -54,6 +54,7 @@ export default class Hls implements HlsEventEmitter {
private emeController: EMEController;

private _media: HTMLMediaElement | null = null;
private _eventLoop: Events | null = null;
private url: string | null = null;

static get version(): string {
Expand Down Expand Up @@ -235,7 +236,10 @@ export default class Hls implements HlsEventEmitter {
name: E,
eventObject: Parameters<HlsListeners[E]>[1]
): boolean {
return this._emitter.emit(event, name, eventObject);
this._eventLoop = event;
const result = this._emitter.emit(event, name, eventObject);
this._eventLoop = null;
return result;
}

trigger<E extends keyof HlsListeners>(
Expand Down Expand Up @@ -316,7 +320,7 @@ export default class Hls implements HlsEventEmitter {
loadSource(url: string) {
this.stopLoad();
const media = this.media;
if (media && this.url) {
if (media && this.url && this._eventLoop === null) {
this.detachMedia();
this.attachMedia(media);
}
Expand Down

0 comments on commit 99f044e

Please sign in to comment.