@clappr/hlsjs-playback 1.5.1 → 1.6.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.6.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",
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
@@ -438,13 +440,21 @@ export default class HlsjsPlayback extends HTML5Video {
438
440
 
439
441
  _onTimeUpdate() {
440
442
  const update = { current: this.getCurrentTime(), total: this.getDuration(), firstFragDateTime: this.getProgramDateTime() }
443
+ const shouldThrottle = this._shouldThrottleTimeUpdate(update)
444
+ if (shouldThrottle) return
445
+ this._lastTimeUpdate = update
446
+ this._lastTimeUpdateFiredTime = this._now
447
+ this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name)
448
+ }
449
+
450
+ _shouldThrottleTimeUpdate(update) {
441
451
  const isSameTime = Math.abs(update.current - this._lastTimeUpdate.current) < this._timeUpdateFiringRate
442
452
  const isSameDuration = Math.abs(update.total - this._lastTimeUpdate.total) < this._durationChangeMinOffset
443
453
  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)
454
+ const isSameEventPayload = isSameTime && isSameDuration && isSameFirstFragDateTime
455
+ const isThrottled = this._now - this._lastTimeUpdateFiredTime < this._timeUpdateThrottleDelay
456
+
457
+ return isSameEventPayload && isThrottled
448
458
  }
449
459
 
450
460
  _onDurationChange() {