@clappr/hlsjs-playback 1.1.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.1.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",
@@ -15,7 +15,8 @@
15
15
  "test:debug": "node --inspect node_modules/.bin/jest ./src --runInBand",
16
16
  "test:watch": "jest ./src --watch",
17
17
  "lint": "eslint *.js ./src",
18
- "lint:fix": "yarn lint -- --fix"
18
+ "lint:fix": "yarn lint -- --fix",
19
+ "prepublishOnly": "npm run release"
19
20
  },
20
21
  "files": [
21
22
  "/dist",
package/src/hls.js CHANGED
@@ -40,6 +40,14 @@ export default class HlsjsPlayback extends HTML5Video {
40
40
  this._hls.currentLevel = this._currentLevel
41
41
  }
42
42
 
43
+ get latency() {
44
+ return this._hls.latency
45
+ }
46
+
47
+ get currentProgramDateTime() {
48
+ return this._hls.playingDate
49
+ }
50
+
43
51
  get _startTime() {
44
52
  if (this._playbackType === Playback.LIVE && this._playlistType !== 'EVENT')
45
53
  return this._extrapolatedStartTime
@@ -119,6 +127,15 @@ export default class HlsjsPlayback extends HTML5Video {
119
127
  return this.options.src
120
128
  }
121
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
+
122
139
  static get HLSJS() {
123
140
  return HLSJS
124
141
  }
@@ -627,6 +644,7 @@ export default class HlsjsPlayback extends HTML5Video {
627
644
  }
628
645
 
629
646
  _onFragmentChanged(evt, data) {
647
+ this._currentFragment = data.frag
630
648
  this.trigger(Events.Custom.PLAYBACK_FRAGMENT_CHANGED, data)
631
649
  }
632
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
  })