@clappr/hlsjs-playback 1.2.0 → 1.3.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.2.0",
3
+ "version": "1.3.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
@@ -127,6 +127,15 @@ export default class HlsjsPlayback extends HTML5Video {
127
127
  return this.options.src
128
128
  }
129
129
 
130
+ get currentTimestamp() {
131
+ if (!this._currentFragment) return null
132
+ const startTime = this._currentFragment.programDateTime
133
+ const playbackTime = this.el.currentTime
134
+ const playTimeOffSet = playbackTime - this._currentFragment.start
135
+ const currentTimestampInMs = startTime + playTimeOffSet * 1000
136
+ return currentTimestampInMs / 1000
137
+ }
138
+
130
139
  static get HLSJS() {
131
140
  return HLSJS
132
141
  }
@@ -635,6 +644,7 @@ export default class HlsjsPlayback extends HTML5Video {
635
644
  }
636
645
 
637
646
  _onFragmentChanged(evt, data) {
647
+ this._currentFragment = data.frag
638
648
  this.trigger(Events.Custom.PLAYBACK_FRAGMENT_CHANGED, data)
639
649
  }
640
650
 
package/src/hls.test.js CHANGED
@@ -346,4 +346,27 @@ describe('HlsjsPlayback', () => {
346
346
  expect(cb).not.toHaveBeenCalled()
347
347
  })
348
348
  })
349
+
350
+ describe('currentTimestamp', () => {
351
+ it('returns the fragment time plus the current playback time', () => {
352
+ const fragmentMock = {
353
+ frag: {
354
+ programDateTime: 1556663040000, // 'Tue Apr 30 2019 19:24:00'
355
+ start: 0,
356
+ }
357
+ }
358
+ const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8' })
359
+ playback.el.currentTime = 5
360
+ playback._setup()
361
+ playback.unbindCustomListeners()
362
+ playback._hls.trigger(HLSJS.Events.FRAG_CHANGED, fragmentMock)
363
+ expect(playback.currentTimestamp).toBe(1556663045) // 'Tue Apr 30 2019 19:24:05'
364
+ })
365
+
366
+ it('returns null if the playback does not have a fragment', () => {
367
+ const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8' })
368
+ playback._setup()
369
+ expect(playback.currentTimestamp).toBe(null)
370
+ })
371
+ })
349
372
  })