@clappr/hlsjs-playback 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clappr/hlsjs-playback",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "HLS Playback based on hls.js",
5
5
  "main": "./dist/hlsjs-playback.js",
6
6
  "module": "./dist/hlsjs-playback.esm.js",
@@ -37,12 +37,12 @@
37
37
  "homepage": "https://github.com/clappr/hlsjs-playback",
38
38
  "peerDependencies": {
39
39
  "@clappr/core": "*",
40
- "hls.js": "^1.2.4"
40
+ "hls.js": "1.5.14"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.14.2",
44
44
  "@babel/preset-env": "^7.14.2",
45
- "@clappr/core": "^0.8.0",
45
+ "@clappr/core": "^0.9.0",
46
46
  "@rollup/plugin-babel": "^5.3.0",
47
47
  "@rollup/plugin-commonjs": "^19.0.0",
48
48
  "@rollup/plugin-node-resolve": "^13.0.0",
@@ -51,7 +51,7 @@
51
51
  "coveralls": "^3.1.0",
52
52
  "cz-conventional-changelog": "^3.3.0",
53
53
  "eslint": "^7.26.0",
54
- "hls.js": "^1.2.4",
54
+ "hls.js": "1.5.14",
55
55
  "jest": "^26.6.3",
56
56
  "rollup": "^2.47.0",
57
57
  "rollup-plugin-filesize": "^9.1.1",
package/src/hls.js CHANGED
@@ -143,6 +143,8 @@ export default class HlsjsPlayback extends HTML5Video {
143
143
  constructor(...args) {
144
144
  super(...args)
145
145
  this.options.hlsPlayback = { ...this.defaultOptions, ...this.options.hlsPlayback }
146
+ this._timeUpdateFiringRate = 0.2
147
+ this._durationChangeMinOffset = 0.5
146
148
  this._setInitialState()
147
149
  }
148
150
 
@@ -155,7 +157,7 @@ export default class HlsjsPlayback extends HTML5Video {
155
157
  this._extrapolatedWindowNumSegments = !this.options.playback || typeof (this.options.playback.extrapolatedWindowNumSegments) === 'undefined' ? 2 : this.options.playback.extrapolatedWindowNumSegments
156
158
 
157
159
  this._playbackType = Playback.VOD
158
- this._lastTimeUpdate = { current: 0, total: 0 }
160
+ this._lastTimeUpdate = { current: 0, total: 0, firstFragDateTime: 0 }
159
161
  this._lastDuration = null
160
162
  // for hls streams which have dvr with a sliding window,
161
163
  // the content at the start of the playlist is removed as new
@@ -265,10 +267,12 @@ export default class HlsjsPlayback extends HTML5Video {
265
267
  if (!this._recoveredDecodingError) {
266
268
  this._recoveredDecodingError = true
267
269
  this._hls.recoverMediaError()
270
+ this.play()
268
271
  } else if (!this._recoveredAudioCodecError) {
269
272
  this._recoveredAudioCodecError = true
270
273
  this._hls.swapAudioCodec()
271
274
  this._hls.recoverMediaError()
275
+ this.play()
272
276
  } else {
273
277
  Log.error('hlsjs: failed to recover', { evt, data })
274
278
  error.level = PlayerError.Levels.FATAL
@@ -333,8 +337,6 @@ export default class HlsjsPlayback extends HTML5Video {
333
337
  Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.')
334
338
  time = this.getDuration()
335
339
  }
336
- // assume live if time within 3 seconds of end of stream
337
- this.dvrEnabled && this._updateDvr(time < this.getDuration()-3)
338
340
  time += this._startTime
339
341
  this.el.currentTime = time
340
342
  }
@@ -343,11 +345,6 @@ export default class HlsjsPlayback extends HTML5Video {
343
345
  this.seek(this.getDuration())
344
346
  }
345
347
 
346
- _updateDvr(status) {
347
- this.trigger(Events.PLAYBACK_DVR, status)
348
- this.trigger(Events.PLAYBACK_STATS_ADD, { 'dvr': status })
349
- }
350
-
351
348
  _updateSettings() {
352
349
  if (this._playbackType === Playback.VOD)
353
350
  this.settings.left = ['playpause', 'position', 'duration']
@@ -441,9 +438,10 @@ export default class HlsjsPlayback extends HTML5Video {
441
438
 
442
439
  _onTimeUpdate() {
443
440
  const update = { current: this.getCurrentTime(), total: this.getDuration(), firstFragDateTime: this.getProgramDateTime() }
444
- const isSame = this._lastTimeUpdate && (
445
- update.current === this._lastTimeUpdate.current &&
446
- update.total === this._lastTimeUpdate.total)
441
+ const isSameTime = Math.abs(update.current - this._lastTimeUpdate.current) < this._timeUpdateFiringRate
442
+ const isSameDuration = Math.abs(update.total - this._lastTimeUpdate.total) < this._durationChangeMinOffset
443
+ const isSameFirstFragDateTime = update.firstFragDateTime === this._lastTimeUpdate.firstFragDateTime
444
+ const isSame = isSameTime && isSameDuration && isSameFirstFragDateTime
447
445
  if (isSame) return
448
446
  this._lastTimeUpdate = update
449
447
  this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name)
@@ -451,7 +449,8 @@ export default class HlsjsPlayback extends HTML5Video {
451
449
 
452
450
  _onDurationChange() {
453
451
  const duration = this.getDuration()
454
- if (this._lastDuration === duration) return
452
+ const isSameDuration = Math.abs(this._lastDuration - duration) < this._durationChangeMinOffset
453
+ if (isSameDuration) return
455
454
  this._lastDuration = duration
456
455
  super._onDurationChange()
457
456
  }
@@ -494,7 +493,6 @@ export default class HlsjsPlayback extends HTML5Video {
494
493
  pause() {
495
494
  if (!this._hls) return
496
495
  this.el.pause()
497
- if (this.dvrEnabled) this._updateDvr(true)
498
496
  }
499
497
 
500
498
  stop() {