Skip to content

Commit

Permalink
bugfix/reset-race-conditions (#4246)
Browse files Browse the repository at this point in the history
* fix: clear timeout on reset

* fix: add null check to prevent errors when _onRemove is called after reset
  • Loading branch information
littlespex committed Aug 4, 2023
1 parent 4b4a8b1 commit 23941f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/streaming/controllers/BufferController.js
Expand Up @@ -1013,6 +1013,10 @@ function BufferController(config) {
function _onRemoved(e) {
logger.debug('onRemoved buffer from:', e.from, 'to', e.to);

if (!sourceBufferSink) {
return;
}

const ranges = sourceBufferSink.getAllBufferRanges();
_showBufferRanges(ranges);

Expand Down
10 changes: 8 additions & 2 deletions src/streaming/models/VideoModel.js
Expand Up @@ -51,7 +51,8 @@ function VideoModel() {
_currentTime,
TTMLRenderingDiv,
vttRenderingDiv,
previousPlaybackRate;
previousPlaybackRate,
timeout;

const VIDEO_MODEL_WRONG_ELEMENT_TYPE = 'element is not video or audio DOM type!';

Expand All @@ -69,6 +70,7 @@ function VideoModel() {
}

function reset() {
clearTimeout(timeout);
eventBus.off(Events.PLAYBACK_PLAYING, onPlaying, this);
}

Expand All @@ -94,6 +96,10 @@ function VideoModel() {
if (element) {
_currentTime = currentTime;
waitForReadyState(Constants.VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, () => {
if (!element) {
return;
}

// We don't set the same currentTime because it can cause firing unexpected Pause event in IE11
// providing playbackRate property equals to zero.
if (element.currentTime === _currentTime) {
Expand All @@ -112,7 +118,7 @@ function VideoModel() {
_currentTime = NaN;
} catch (e) {
if (element.readyState === 0 && e.code === e.INVALID_STATE_ERR) {
setTimeout(function () {
timeout = setTimeout(function () {
element.currentTime = _currentTime;
_currentTime = NaN;
}, 400);
Expand Down

0 comments on commit 23941f8

Please sign in to comment.