Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 1179899

Browse files
Merge pull request #14 from clappr/fix-ready-state
Ensure the existence of the HLS.JS internal instance on the ready state
2 parents d4d3023 + 69aaded commit 1179899

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/hls.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export default class HlsjsPlayback extends HTML5Video {
192192
}
193193

194194
_ready() {
195+
if (this._isReadyState) return
196+
!this._hls && this._setup()
195197
this._isReadyState = true
196198
this.trigger(Events.PLAYBACK_READY, this.name)
197199
}

src/hls.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,50 @@ describe('HlsjsPlayback', () => {
173173
})
174174
})
175175

176+
describe('_ready method', () => {
177+
test('avoid to run internal logic if _isReadyState flag is true', () => {
178+
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
179+
playback._isReadyState = true
180+
jest.spyOn(playback, '_setup')
181+
playback._ready()
182+
183+
expect(playback._setup).not.toHaveBeenCalled()
184+
})
185+
186+
test('call _setup method if HLS.JS internal don\'t exists', () => {
187+
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
188+
jest.spyOn(playback, '_setup')
189+
playback._ready()
190+
191+
expect(playback._setup).toHaveBeenCalledTimes(1)
192+
193+
playback._ready()
194+
expect(playback._setup).toHaveBeenCalledTimes(1)
195+
})
196+
197+
test('update _isReadyState flag value to true', () => {
198+
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
199+
200+
expect(playback._isReadyState).toBeFalsy()
201+
202+
playback._ready()
203+
204+
expect(playback._isReadyState).toBeTruthy()
205+
})
206+
207+
test('triggers PLAYBACK_READY event', done => {
208+
const cb = jest.fn()
209+
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
210+
211+
playback.listenTo(playback, Events.PLAYBACK_READY, cb)
212+
playback.listenTo(playback, Events.PLAYBACK_READY, () => {
213+
expect(cb).toHaveBeenCalledTimes(1)
214+
done()
215+
})
216+
playback._ready()
217+
})
218+
})
219+
176220
describe('play method', () => {
177221
test('calls this._hls.loadSource if _manifestParsed flag and options.hlsPlayback.preload are falsy', () => {
178222
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { preload: true } })

0 commit comments

Comments
 (0)