Skip to content

Commit

Permalink
refactor: rename loadSourceBeforePlay to preload
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopaulovieira committed Apr 8, 2021
1 parent 6df510b commit b90c5ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var player = new Clappr.Player(
hlsMinimumDvrSize: 60,
hlsRecoverAttempts: 16,
hlsPlayback: {
loadSourceBeforePlay: true,
preload: true,
},
playback: {
extrapolatedWindowNumSegments: 2,
Expand Down Expand Up @@ -96,12 +96,12 @@ var player = new Clappr.Player(
{
...
hlsPlayback: {
loadSourceBeforePlay: true,
preload: true,
},
});
```

#### `hlsPlayback.loadSourceBeforePlay`
#### `hlsPlayback.preload`
> Default value: `true`
Configures whether the source should be loaded as soon as the `HLS.JS` internal reference is setup or only after the first play.
Expand Down
6 changes: 3 additions & 3 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class HlsjsPlayback extends HTML5Video {
}

get defaultOptions() {
return { loadSourceBeforePlay: true }
return { preload: true }
}

static get HLSJS() {
Expand Down Expand Up @@ -168,7 +168,7 @@ export default class HlsjsPlayback extends HTML5Video {
this._ccTracksUpdated = false
this._hls && this._hls.destroy()
this._hls = new HLSJS(assign({}, this.options.playback.hlsjsConfig))
this._hls.once(HLSJS.Events.MEDIA_ATTACHED, () => { this.options.hlsPlayback.loadSourceBeforePlay && this._hls.loadSource(this.options.src) })
this._hls.once(HLSJS.Events.MEDIA_ATTACHED, () => { this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src) })
this._hls.on(HLSJS.Events.MANIFEST_PARSED, () => this._manifestParsed = true)
this._hls.on(HLSJS.Events.LEVEL_LOADED, (evt, data) => this._updatePlaybackType(evt, data))
this._hls.on(HLSJS.Events.LEVEL_UPDATED, (evt, data) => this._onLevelUpdated(evt, data))
Expand Down Expand Up @@ -424,7 +424,7 @@ export default class HlsjsPlayback extends HTML5Video {

play() {
!this._hls && this._setup()
!this._manifestParsed && !this.options.hlsPlayback.loadSourceBeforePlay && this._hls.loadSource(this.options.src)
!this._manifestParsed && !this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src)

super.play()
this._startTimeUpdateTimer()
Expand Down
14 changes: 7 additions & 7 deletions src/hls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('HlsjsPlayback', () => {
})

test('defaultOptions getter returns all the default options values into one object', () => {
expect(simplePlaybackMock.defaultOptions).toEqual({ loadSourceBeforePlay: true })
expect(simplePlaybackMock.defaultOptions).toEqual({ preload: true })
})

test('should be able to identify it can play resources independently of the file extension case', () => {
Expand Down Expand Up @@ -145,15 +145,15 @@ describe('HlsjsPlayback', () => {
expect(playback._manifestParsed).toBeFalsy()
})

test('calls this._hls.loadSource when MEDIA_ATTACHED event is triggered and hlsPlayback.loadSourceBeforePlay is true', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { loadSourceBeforePlay: false } })
test('calls this._hls.loadSource when MEDIA_ATTACHED event is triggered and hlsPlayback.preload is true', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { preload: false } })
playback._setup()
jest.spyOn(playback._hls, 'loadSource')
playback._hls.trigger(HLSJS.Events.MEDIA_ATTACHED)

expect(playback._hls.loadSource).not.toHaveBeenCalled()

playback.options.hlsPlayback.loadSourceBeforePlay = true
playback.options.hlsPlayback.preload = true
playback._setup()
jest.spyOn(playback._hls, 'loadSource')
playback._hls.trigger(HLSJS.Events.MEDIA_ATTACHED)
Expand All @@ -174,15 +174,15 @@ describe('HlsjsPlayback', () => {
})

describe('play method', () => {
test('calls this._hls.loadSource if _manifestParsed flag and options.hlsPlayback.loadSourceBeforePlay are falsy', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { loadSourceBeforePlay: true } })
test('calls this._hls.loadSource if _manifestParsed flag and options.hlsPlayback.preload are falsy', () => {
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { preload: true } })
playback._setup()
jest.spyOn(playback._hls, 'loadSource')
playback.play()

expect(playback._hls.loadSource).not.toHaveBeenCalled()

playback.options.hlsPlayback.loadSourceBeforePlay = false
playback.options.hlsPlayback.preload = false
playback._manifestParsed = true
playback.play()

Expand Down

0 comments on commit b90c5ae

Please sign in to comment.