@clappr/hlsjs-playback 1.5.1 → 1.7.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.5.1",
3
+ "version": "1.7.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",
@@ -42,7 +42,7 @@
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.14.2",
44
44
  "@babel/preset-env": "^7.14.2",
45
- "@clappr/core": "^0.10.0",
45
+ "@clappr/core": "^0.11.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",
package/src/hls.js CHANGED
@@ -143,6 +143,7 @@ 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._timeUpdateThrottleDelay = 200
146
147
  this._timeUpdateFiringRate = 0.2
147
148
  this._durationChangeMinOffset = 0.5
148
149
  this._setInitialState()
@@ -158,6 +159,7 @@ export default class HlsjsPlayback extends HTML5Video {
158
159
 
159
160
  this._playbackType = Playback.VOD
160
161
  this._lastTimeUpdate = { current: 0, total: 0, firstFragDateTime: 0 }
162
+ this._lastTimeUpdateFiredTime = 0
161
163
  this._lastDuration = null
162
164
  // for hls streams which have dvr with a sliding window,
163
165
  // the content at the start of the playlist is removed as new
@@ -225,6 +227,7 @@ export default class HlsjsPlayback extends HTML5Video {
225
227
  this._hls.on(HLSJS.Events.LEVEL_SWITCHED, (evt,data) => this._onLevelSwitch(evt, data))
226
228
  this._hls.on(HLSJS.Events.FRAG_CHANGED, (evt, data) => this._onFragmentChanged(evt, data))
227
229
  this._hls.on(HLSJS.Events.FRAG_LOADED, (evt, data) => this._onFragmentLoaded(evt, data))
230
+ this._hls.on(HLSJS.Events.FRAG_BUFFERED, (evt, data) => this._onFragmentBuffered(evt, data))
228
231
  this._hls.on(HLSJS.Events.FRAG_PARSING_METADATA, (evt, data) => this._onFragmentParsingMetadata(evt, data))
229
232
  this._hls.on(HLSJS.Events.ERROR, (evt, data) => this._onHLSJSError(evt, data))
230
233
  this._hls.on(HLSJS.Events.SUBTITLE_TRACK_LOADED, (evt, data) => this._onSubtitleLoaded(evt, data))
@@ -438,13 +441,21 @@ export default class HlsjsPlayback extends HTML5Video {
438
441
 
439
442
  _onTimeUpdate() {
440
443
  const update = { current: this.getCurrentTime(), total: this.getDuration(), firstFragDateTime: this.getProgramDateTime() }
444
+ const shouldThrottle = this._shouldThrottleTimeUpdate(update)
445
+ if (shouldThrottle) return
446
+ this._lastTimeUpdate = update
447
+ this._lastTimeUpdateFiredTime = this._now
448
+ this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name)
449
+ }
450
+
451
+ _shouldThrottleTimeUpdate(update) {
441
452
  const isSameTime = Math.abs(update.current - this._lastTimeUpdate.current) < this._timeUpdateFiringRate
442
453
  const isSameDuration = Math.abs(update.total - this._lastTimeUpdate.total) < this._durationChangeMinOffset
443
454
  const isSameFirstFragDateTime = update.firstFragDateTime === this._lastTimeUpdate.firstFragDateTime
444
- const isSame = isSameTime && isSameDuration && isSameFirstFragDateTime
445
- if (isSame) return
446
- this._lastTimeUpdate = update
447
- this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name)
455
+ const isSameEventPayload = isSameTime && isSameDuration && isSameFirstFragDateTime
456
+ const isThrottled = this._now - this._lastTimeUpdateFiredTime < this._timeUpdateThrottleDelay
457
+
458
+ return isSameEventPayload && isThrottled
448
459
  }
449
460
 
450
461
  _onDurationChange() {
@@ -650,6 +661,10 @@ export default class HlsjsPlayback extends HTML5Video {
650
661
  this.trigger(Events.PLAYBACK_FRAGMENT_LOADED, data)
651
662
  }
652
663
 
664
+ _onFragmentBuffered(evt, data) {
665
+ this.trigger(Events.PLAYBACK_FRAGMENT_BUFFERED, data)
666
+ }
667
+
653
668
  _onSubtitleLoaded() {
654
669
  // This event may be triggered multiple times
655
670
  // Setup CC only once (disable CC by default)