Skip to content

Commit

Permalink
fix(FEC-10662): source removed before destroy process finish (#503)
Browse files Browse the repository at this point in the history
Issue: source has been removed from video tag before destroy has been finished.
Solution: wait for mediaSource destroy before removing the src from video tag.
  • Loading branch information
Yuvalke authored Nov 24, 2020
1 parent f06aa5e commit 55b2e77
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/engines/html5/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Html5 extends FakeEventTarget implements IEngine {
*/
_canLoadMediaSourceAdapterPromise: Promise<*>;
_droppedFramesWatcher: ?DroppedFramesWatcher;

_reset: boolean = false;
/**
* The html5 class logger.
* @type {any}
Expand Down Expand Up @@ -208,19 +208,26 @@ export default class Html5 extends FakeEventTarget implements IEngine {
* @returns {void}
*/
reset(): void {
if (this._reset) return;
this._reset = true;
this._eventManager.removeAll();
if (this._droppedFramesWatcher) {
this._droppedFramesWatcher.destroy();
this._droppedFramesWatcher = null;
}
if (this._mediaSourceAdapter) {
this._canLoadMediaSourceAdapterPromise = this._mediaSourceAdapter.destroy();
this._mediaSourceAdapter = null;
}
if (this._el && this._el.src) {
Utils.Dom.setAttribute(this._el, 'src', '');
Utils.Dom.removeAttribute(this._el, 'src');
}
this._canLoadMediaSourceAdapterPromise = new Promise((resolve, reject) => {
const mediaSourceAdapterDestroyed = this._mediaSourceAdapter ? this._mediaSourceAdapter.destroy() : Promise.resolve();
if (this._el && this._el.src) {
mediaSourceAdapterDestroyed.then(() => {
Utils.Dom.setAttribute(this._el, 'src', '');
Utils.Dom.removeAttribute(this._el, 'src');
resolve();
}, reject);
} else {
mediaSourceAdapterDestroyed.then(resolve, reject);
}
});
this._mediaSourceAdapter = null;
}

/**
Expand Down Expand Up @@ -972,6 +979,7 @@ export default class Html5 extends FakeEventTarget implements IEngine {
*/
_init(source: PKMediaSourceObject, config: Object): void {
this._config = config;
this._reset = false;
this._loadMediaSourceAdapter(source);
this.attach();
}
Expand Down

0 comments on commit 55b2e77

Please sign in to comment.