@clappr/hlsjs-playback 1.9.13 → 2.0.1
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/README.md +11 -0
- package/dist/hlsjs-playback.esm.js +4 -4
- package/dist/hlsjs-playback.esm.js.map +1 -0
- package/dist/hlsjs-playback.external.js +4 -4
- package/dist/hlsjs-playback.external.js.map +1 -0
- package/dist/hlsjs-playback.external.min.js +1 -1
- package/dist/hlsjs-playback.external.min.js.map +1 -1
- package/dist/hlsjs-playback.js +4 -4
- package/dist/hlsjs-playback.js.map +1 -0
- package/dist/hlsjs-playback.min.js +1 -1
- package/dist/hlsjs-playback.min.js.map +1 -1
- package/package.json +4 -3
- package/src/dist.smoke.test.js +109 -0
- package/src/hls.js +2 -3
- package/src/hls.test.js +780 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clappr/hlsjs-playback",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "HLS Playback based on hls.js",
|
|
5
5
|
"main": "./dist/hlsjs-playback.js",
|
|
6
6
|
"module": "./dist/hlsjs-playback.esm.js",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"build": "rollup --config --bundleConfigAsCjs",
|
|
11
11
|
"watch": "rollup --config --bundleConfigAsCjs --watch",
|
|
12
12
|
"bundle-check": "ANALYZE_BUNDLE=true rollup --config --bundleConfigAsCjs",
|
|
13
|
-
"release": "MINIMIZE=true rollup --config --bundleConfigAsCjs",
|
|
13
|
+
"release": "rm -rf dist && MINIMIZE=true rollup --config --bundleConfigAsCjs",
|
|
14
14
|
"test": "jest ./src --coverage --silent",
|
|
15
|
+
"test:smoke": "jest ./src/dist.smoke.test.js --testPathIgnorePatterns=/node_modules/ --silent",
|
|
15
16
|
"test:watch": "jest ./src --watch",
|
|
16
17
|
"lint": "eslint *.js ./src",
|
|
17
18
|
"lint:fix": "yarn lint -- --fix",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"hls.js": "1.6.16"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@clappr/core": "^0.
|
|
44
|
+
"@clappr/core": "^0.15.0",
|
|
44
45
|
"@rollup/plugin-replace": "^2.4.2",
|
|
45
46
|
"hls.js": "1.6.16",
|
|
46
47
|
"rollup-plugin-filesize": "^9.1.1",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smoke-tests the published dist/ artifacts. Core Jest maps @clappr/core to
|
|
3
|
+
* source, so without this the Rollup entry points have no CI signal.
|
|
4
|
+
*/
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
|
|
8
|
+
const DIST = path.join(__dirname, '..', 'dist')
|
|
9
|
+
|
|
10
|
+
const ARTIFACTS = {
|
|
11
|
+
main: 'hlsjs-playback.js',
|
|
12
|
+
mainMin: 'hlsjs-playback.min.js',
|
|
13
|
+
external: 'hlsjs-playback.external.js',
|
|
14
|
+
externalMin: 'hlsjs-playback.external.min.js',
|
|
15
|
+
esm: 'hlsjs-playback.esm.js'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const EMBEDS_HLS = [ARTIFACTS.main, ARTIFACTS.mainMin, ARTIFACTS.esm]
|
|
19
|
+
const EXTERNAL_HLS = [ARTIFACTS.external, ARTIFACTS.externalMin]
|
|
20
|
+
|
|
21
|
+
function readArtifact(name) {
|
|
22
|
+
return fs.readFileSync(path.join(DIST, name), 'utf8')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function loadArtifact(name) {
|
|
26
|
+
jest.resetModules()
|
|
27
|
+
return require(path.join(DIST, name))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolvePlayback(HlsjsPlaybackExport) {
|
|
31
|
+
return HlsjsPlaybackExport.default || HlsjsPlaybackExport
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function assertPlaybackContract(HlsjsPlaybackExport) {
|
|
35
|
+
// Must re-require after resetModules so the prototype identity matches the
|
|
36
|
+
// @clappr/core instance the artifact just resolved.
|
|
37
|
+
const { HTML5Video } = require('@clappr/core')
|
|
38
|
+
const Playback = resolvePlayback(HlsjsPlaybackExport)
|
|
39
|
+
|
|
40
|
+
expect(typeof Playback).toBe('function')
|
|
41
|
+
expect(Object.getPrototypeOf(Playback.prototype)).toBe(HTML5Video.prototype)
|
|
42
|
+
|
|
43
|
+
const HLSJS = Playback.HLSJS
|
|
44
|
+
expect(HLSJS).toBeTruthy()
|
|
45
|
+
expect(typeof HLSJS.isSupported).toBe('function')
|
|
46
|
+
expect(HLSJS.Events).toBeTruthy()
|
|
47
|
+
expect(typeof HLSJS.version).toBe('string')
|
|
48
|
+
expect(HLSJS.version.length).toBeGreaterThan(0)
|
|
49
|
+
|
|
50
|
+
jest.spyOn(HLSJS, 'isSupported').mockReturnValue(true)
|
|
51
|
+
jest.spyOn(window.HTMLMediaElement.prototype, 'load').mockImplementation(() => {})
|
|
52
|
+
|
|
53
|
+
expect(Playback.canPlay('http://example.com/video.m3u8')).toBe(true)
|
|
54
|
+
expect(Playback.canPlay('http://example.com/video.m3u8?token=1')).toBe(true)
|
|
55
|
+
expect(Playback.canPlay('http://example.com/video.mpd')).toBe(false)
|
|
56
|
+
|
|
57
|
+
const playback = new Playback({ src: 'http://example.com/video.m3u8' })
|
|
58
|
+
playback.destroy()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function assertSourceMappingURL(filename) {
|
|
62
|
+
expect(readArtifact(filename)).toContain(`sourceMappingURL=${filename}.map`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const EXPECTED_SOURCEMAPS = Object.values(ARTIFACTS)
|
|
66
|
+
.map(filename => `${filename}.map`)
|
|
67
|
+
.sort()
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
jest.restoreAllMocks()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe.each([
|
|
74
|
+
['main UMD', ARTIFACTS.main],
|
|
75
|
+
['main UMD minified', ARTIFACTS.mainMin],
|
|
76
|
+
['external UMD', ARTIFACTS.external],
|
|
77
|
+
['external UMD minified', ARTIFACTS.externalMin],
|
|
78
|
+
['ESM', ARTIFACTS.esm]
|
|
79
|
+
])('%s (%s)', (_label, filename) => {
|
|
80
|
+
test('exports a HlsjsPlayback class that extends HTML5Video and exposes HLSJS', () => {
|
|
81
|
+
assertPlaybackContract(loadArtifact(filename))
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('publishes a sourcemap comment', () => {
|
|
85
|
+
assertSourceMappingURL(filename)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
describe('dist sourcemap inventory', () => {
|
|
90
|
+
test('ships exactly the expected .map files', () => {
|
|
91
|
+
const maps = fs
|
|
92
|
+
.readdirSync(DIST)
|
|
93
|
+
.filter(f => f.endsWith('.map'))
|
|
94
|
+
.sort()
|
|
95
|
+
expect(maps).toEqual(EXPECTED_SOURCEMAPS)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('hls.js peer identity', () => {
|
|
100
|
+
test.each(EXTERNAL_HLS)('%s defers to the consumer hls.js', filename => {
|
|
101
|
+
const Playback = resolvePlayback(loadArtifact(filename))
|
|
102
|
+
expect(Playback.HLSJS).toBe(require('hls.js'))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test.each(EMBEDS_HLS)('%s embeds its own hls.js copy', filename => {
|
|
106
|
+
const Playback = resolvePlayback(loadArtifact(filename))
|
|
107
|
+
expect(Playback.HLSJS).not.toBe(require('hls.js'))
|
|
108
|
+
})
|
|
109
|
+
})
|
package/src/hls.js
CHANGED
|
@@ -213,7 +213,7 @@ export default class HlsjsPlayback extends HTML5Video {
|
|
|
213
213
|
this._segmentTargetDuration = null
|
|
214
214
|
// #EXT-X-PLAYLIST-TYPE
|
|
215
215
|
this._playlistType = null
|
|
216
|
-
this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts
|
|
216
|
+
this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts ?? DEFAULT_RECOVER_ATTEMPTS
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
_setup() {
|
|
@@ -372,8 +372,7 @@ export default class HlsjsPlayback extends HTML5Video {
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
seekPercentage(percentage) {
|
|
375
|
-
|
|
376
|
-
this.seek(seekTo)
|
|
375
|
+
this.seek(this._duration * (percentage / 100))
|
|
377
376
|
}
|
|
378
377
|
|
|
379
378
|
seek(time) {
|