8000 fix(html5_video): avoid memory leak in getDuration call by bikegriffith · Pull Request #71 · clappr/clappr-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(html5_video): avoid memory leak in getDuration call #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/playbacks/html5_video/html5_video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/playbacks/html5_video/html5_video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
0