From 7c56a14c842e58e5f80a601527edc384620568bd Mon Sep 17 00:00:00 2001 From: Mike Griffith Date: Thu, 7 Oct 2021 11:10:25 -0400 Subject: [PATCH 1/3] fix(html5_video): avoid memory leak in getDuration call --- src/playbacks/html5_video/html5_video.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/playbacks/html5_video/html5_video.js b/src/playbacks/html5_video/html5_video.js index 7ead0216..aef96a67 100644 --- a/src/playbacks/html5_video/html5_video.js +++ b/src/playbacks/html5_video/html5_video.js @@ -521,15 +521,25 @@ export default class HTML5Video extends Playback { getDuration() { if (this.isLive) { - try { + if (this.el.seekable.length > 0) { return this.el.seekable.end(0) - this.el.seekable.start(0) - } catch (e) { - setTimeout(() => this._updateSettings(), 1000) + } else { + // `seekable` is not available; this is probably OK, but make sure we're + // updating the control bar to reflect it + this._scheduleUpdateSettingsCheck() } } return this.el.duration } + _scheduleUpdateSettingsCheck() { + if (this._updateSettingsCheckInFlight) return; + this._updateSettingsCheckInFlight = setTimeout(() => { + this._updateSettings() + this._updateSettingsCheckInFlight = null; + }, 1000) + } + _onTimeUpdate() { const duration = this.isLive ? this.getDuration() : this.el.duration this.trigger(Events.PLAYBACK_TIMEUPDATE, { current: this.el.currentTime, total: duration }, this.name) From 276e948fdd908a0b5526a577f1160be0d4bcbbbd Mon Sep 17 00:00:00 2001 From: Mike Griffith Date: Thu, 7 Oct 2021 11:17:39 -0400 Subject: [PATCH 2/3] thanks hound --- src/playbacks/html5_video/html5_video.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/playbacks/html5_video/html5_video.js b/src/playbacks/html5_video/html5_video.js index aef96a67..887c0f16 100644 --- a/src/playbacks/html5_video/html5_video.js +++ b/src/playbacks/html5_video/html5_video.js @@ -533,10 +533,10 @@ export default class HTML5Video extends Playback { } _scheduleUpdateSettingsCheck() { - if (this._updateSettingsCheckInFlight) return; + if (this._updateSettingsCheckInFlight) return this._updateSettingsCheckInFlight = setTimeout(() => { this._updateSettings() - this._updateSettingsCheckInFlight = null; + this._updateSettingsCheckInFlight = null }, 1000) } From eadd645620618e6a1101918419c46d9e0f39a15c Mon Sep 17 00:00:00 2001 From: Mike Griffith Date: Thu, 7 Oct 2021 11:21:56 -0400 Subject: [PATCH 3/3] fix spec --- src/playbacks/html5_video/html5_video.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/playbacks/html5_video/html5_video.test.js b/src/playbacks/html5_video/html5_video.test.js index 87883175..dac3f4e5 100644 --- a/src/playbacks/html5_video/html5_video.test.js +++ b/src/playbacks/html5_video/html5_video.test.js @@ -453,12 +453,12 @@ describe('HTML5Video playback', function() { expect(html5Video.getDuration).toHaveReturnedWith(30) }) - test('retry to get duration for live medias when occurs transient unavailability', () => { + test('retry to get duration for live media when there is no seekable range', () => { jest.useFakeTimers() let start = [] let end = [] let html5Video = new HTML5Video({ src: 'http://example.com/video.m3u8' }) - html5Video.setElement({ get seekable() { return undefined } }) + html5Video.setElement({ get seekable() { return { length: 0 } } }) jest.spyOn(html5Video, 'getDuration') jest.spyOn(html5Video, 'getPlaybackType').mockReturnValue('live')