Skip to content

Commit

Permalink
refactor(src): avoid to trigger PLAYBACK_READY event unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopaulovieira committed Apr 9, 2021
1 parent fb8627e commit 69aaded
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export default class HlsjsPlayback extends HTML5Video {
}

_ready() {
if (this._isReadyState) return
!this._hls && this._setup()
this._isReadyState = true
this.trigger(Events.PLAYBACK_READY, this.name)
Expand Down
9 changes: 9 additions & 0 deletions src/hls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ describe('HlsjsPlayback', () => {
})

describe('_ready method', () => {
test('avoid to run internal logic if _isReadyState flag is true', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
playback._isReadyState = true
jest.spyOn(playback, '_setup')
playback._ready()

expect(playback._setup).not.toHaveBeenCalled()
})

test('call _setup method if HLS.JS internal don\'t exists', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
jest.spyOn(playback, '_setup')
Expand Down

0 comments on commit 69aaded

Please sign in to comment.