@clappr/hlsjs-playback 1.8.3 → 1.9.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/dist/hlsjs-playback.esm.js +49 -11
- package/dist/hlsjs-playback.external.js +49 -11
- package/dist/hlsjs-playback.external.min.js +1 -1
- package/dist/hlsjs-playback.external.min.js.map +1 -1
- package/dist/hlsjs-playback.js +49 -11
- package/dist/hlsjs-playback.min.js +1 -1
- package/dist/hlsjs-playback.min.js.map +1 -1
- package/package.json +3 -4
- package/src/hls.js +188 -114
- package/src/hls.test.js +59 -26
package/src/hls.test.js
CHANGED
|
@@ -6,7 +6,10 @@ const simplePlaybackMock = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8
|
|
|
6
6
|
|
|
7
7
|
describe('HlsjsPlayback', () => {
|
|
8
8
|
test('have a getter called defaultOptions', () => {
|
|
9
|
-
expect(
|
|
9
|
+
expect(
|
|
10
|
+
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(simplePlaybackMock), 'defaultOptions')
|
|
11
|
+
.get
|
|
12
|
+
).toBeTruthy()
|
|
10
13
|
})
|
|
11
14
|
|
|
12
15
|
test('defaultOptions getter returns all the default options values into one object', () => {
|
|
@@ -14,7 +17,10 @@ describe('HlsjsPlayback', () => {
|
|
|
14
17
|
})
|
|
15
18
|
|
|
16
19
|
test('have a getter called customListeners', () => {
|
|
17
|
-
expect(
|
|
20
|
+
expect(
|
|
21
|
+
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(simplePlaybackMock), 'customListeners')
|
|
22
|
+
.get
|
|
23
|
+
).toBeTruthy()
|
|
18
24
|
})
|
|
19
25
|
|
|
20
26
|
test('customListeners getter returns all configured custom listeners for each hls.js event', () => {
|
|
@@ -33,19 +39,34 @@ describe('HlsjsPlayback', () => {
|
|
|
33
39
|
expect(HlsjsPlayback.canPlay('/relative/video.m3u8')).toBeTruthy()
|
|
34
40
|
expect(HlsjsPlayback.canPlay('/relative/VIDEO.M3U8')).toBeTruthy()
|
|
35
41
|
expect(HlsjsPlayback.canPlay('/relative/video.m3u8?foobarQuery=1234#somefragment')).toBeTruthy()
|
|
36
|
-
expect(
|
|
37
|
-
|
|
42
|
+
expect(
|
|
43
|
+
HlsjsPlayback.canPlay(
|
|
44
|
+
'whatever_no_extension?foobarQuery=1234#somefragment',
|
|
45
|
+
'application/x-mpegURL'
|
|
46
|
+
)
|
|
47
|
+
).toBeTruthy()
|
|
48
|
+
expect(
|
|
49
|
+
HlsjsPlayback.canPlay(
|
|
50
|
+
'//whatever_no_extension?foobarQuery=1234#somefragment',
|
|
51
|
+
'application/x-mpegURL'
|
|
52
|
+
)
|
|
53
|
+
).toBeTruthy()
|
|
38
54
|
})
|
|
39
55
|
|
|
40
56
|
test('can play regardless of any mime type letter case', () => {
|
|
41
57
|
jest.spyOn(HLSJS, 'isSupported').mockImplementation(() => true)
|
|
42
|
-
expect(HlsjsPlayback.canPlay('/path/list.m3u8', 'APPLICATION/VND.APPLE.MPEGURL'
|
|
43
|
-
expect(
|
|
58
|
+
expect(HlsjsPlayback.canPlay('/path/list.m3u8', 'APPLICATION/VND.APPLE.MPEGURL')).toBeTruthy()
|
|
59
|
+
expect(
|
|
60
|
+
HlsjsPlayback.canPlay(
|
|
61
|
+
'whatever_no_extension?foobarQuery=1234#somefragment',
|
|
62
|
+
'application/x-mpegurl'
|
|
63
|
+
)
|
|
64
|
+
).toBeTruthy()
|
|
44
65
|
})
|
|
45
66
|
|
|
46
67
|
test('should ensure it does not create an audio tag if audioOnly is not set', () => {
|
|
47
|
-
let options = { src: 'http://clappr.io/video.m3u8' }
|
|
48
|
-
|
|
68
|
+
let options = { src: 'http://clappr.io/video.m3u8' }
|
|
69
|
+
let playback = new HlsjsPlayback(options)
|
|
49
70
|
expect(playback.tagName).toEqual('video')
|
|
50
71
|
options = { src: 'http://clappr.io/video.m3u8', mimeType: 'application/x-mpegurl' }
|
|
51
72
|
playback = new HlsjsPlayback(options)
|
|
@@ -53,18 +74,18 @@ describe('HlsjsPlayback', () => {
|
|
|
53
74
|
})
|
|
54
75
|
|
|
55
76
|
test('should play on an audio tag if audioOnly is set', () => {
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const options = { src: 'http://clappr.io/video.m3u8', playback: { audioOnly: true } }
|
|
78
|
+
const playback = new HlsjsPlayback(options)
|
|
58
79
|
expect(playback.tagName).toEqual('audio')
|
|
59
80
|
})
|
|
60
81
|
|
|
61
82
|
test('should trigger a playback error if source load failed', () => {
|
|
62
83
|
jest.spyOn(window.HTMLMediaElement.prototype, 'play').mockImplementation(() => {})
|
|
63
|
-
let resolveFn
|
|
64
|
-
const promise = new Promise(
|
|
84
|
+
let resolveFn
|
|
85
|
+
const promise = new Promise(resolve => {
|
|
65
86
|
resolveFn = resolve
|
|
66
87
|
})
|
|
67
|
-
|
|
88
|
+
const options = {
|
|
68
89
|
src: 'http://clappr.io/notfound.m3u8',
|
|
69
90
|
hlsRecoverAttempts: 0,
|
|
70
91
|
mute: true
|
|
@@ -72,10 +93,10 @@ describe('HlsjsPlayback', () => {
|
|
|
72
93
|
|
|
73
94
|
const core = new Core({})
|
|
74
95
|
const playback = new HlsjsPlayback(options, null, core.playerError)
|
|
75
|
-
playback.on(Events.PLAYBACK_ERROR,
|
|
96
|
+
playback.on(Events.PLAYBACK_ERROR, e => resolveFn(e))
|
|
76
97
|
playback.play()
|
|
77
98
|
|
|
78
|
-
promise.then(
|
|
99
|
+
promise.then(e => {
|
|
79
100
|
expect(e.raw.type).toEqual(HLSJS.ErrorTypes.NETWORK_ERROR)
|
|
80
101
|
expect(e.raw.details).toEqual(HLSJS.ErrorDetails.MANIFEST_LOAD_ERROR)
|
|
81
102
|
})
|
|
@@ -86,13 +107,14 @@ describe('HlsjsPlayback', () => {
|
|
|
86
107
|
})
|
|
87
108
|
|
|
88
109
|
test('registers PLAYBACK_FRAGMENT_PARSING_METADATA event', () => {
|
|
89
|
-
expect(Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA).toEqual(
|
|
110
|
+
expect(Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA).toEqual(
|
|
111
|
+
'playbackFragmentParsingMetadata'
|
|
112
|
+
)
|
|
90
113
|
})
|
|
91
114
|
|
|
92
115
|
test('levels supports specifying the level', () => {
|
|
93
|
-
let playback
|
|
94
116
|
const options = { src: 'http://clappr.io/foo.m3u8' }
|
|
95
|
-
playback = new HlsjsPlayback(options)
|
|
117
|
+
const playback = new HlsjsPlayback(options)
|
|
96
118
|
playback._setup()
|
|
97
119
|
// NOTE: rather than trying to call playback.setupHls, we'll punch a new one in place
|
|
98
120
|
playback._hls = { levels: [] }
|
|
@@ -143,10 +165,13 @@ describe('HlsjsPlayback', () => {
|
|
|
143
165
|
test('merges defaultOptions with received options.hlsPlayback', () => {
|
|
144
166
|
const options = {
|
|
145
167
|
src: 'http://clappr.io/foo.m3u8',
|
|
146
|
-
hlsPlayback: { foo: 'bar' }
|
|
168
|
+
hlsPlayback: { foo: 'bar' }
|
|
147
169
|
}
|
|
148
170
|
const playback = new HlsjsPlayback(options)
|
|
149
|
-
expect(playback.options.hlsPlayback).toEqual({
|
|
171
|
+
expect(playback.options.hlsPlayback).toEqual({
|
|
172
|
+
...options.hlsPlayback,
|
|
173
|
+
...playback.defaultOptions
|
|
174
|
+
})
|
|
150
175
|
})
|
|
151
176
|
})
|
|
152
177
|
|
|
@@ -161,7 +186,10 @@ describe('HlsjsPlayback', () => {
|
|
|
161
186
|
})
|
|
162
187
|
|
|
163
188
|
test('calls this._hls.loadSource when MEDIA_ATTACHED event is triggered and hlsPlayback.preload is true', () => {
|
|
164
|
-
const playback = new HlsjsPlayback({
|
|
189
|
+
const playback = new HlsjsPlayback({
|
|
190
|
+
src: 'http://clappr.io/foo.m3u8',
|
|
191
|
+
hlsPlayback: { preload: false }
|
|
192
|
+
})
|
|
165
193
|
playback._setup()
|
|
166
194
|
jest.spyOn(playback._hls, 'loadSource')
|
|
167
195
|
playback._hls.trigger(HLSJS.Events.MEDIA_ATTACHED, { media: playback.el })
|
|
@@ -207,7 +235,7 @@ describe('HlsjsPlayback', () => {
|
|
|
207
235
|
expect(playback._setup).not.toHaveBeenCalled()
|
|
208
236
|
})
|
|
209
237
|
|
|
210
|
-
test(
|
|
238
|
+
test("call _setup method if HLS.JS internal don't exists", () => {
|
|
211
239
|
const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' })
|
|
212
240
|
jest.spyOn(playback, '_setup')
|
|
213
241
|
playback._ready()
|
|
@@ -270,7 +298,10 @@ describe('HlsjsPlayback', () => {
|
|
|
270
298
|
|
|
271
299
|
describe('load method', () => {
|
|
272
300
|
test('loads a new source when called', () => {
|
|
273
|
-
const playback = new HlsjsPlayback({
|
|
301
|
+
const playback = new HlsjsPlayback({
|
|
302
|
+
src: 'http://clappr.io/foo.m3u8',
|
|
303
|
+
hlsPlayback: { preload: true }
|
|
304
|
+
})
|
|
274
305
|
const url = 'http://clappr.io/foo2.m3u8'
|
|
275
306
|
playback.load(url)
|
|
276
307
|
jest.spyOn(playback._hls, 'loadSource')
|
|
@@ -298,7 +329,7 @@ describe('HlsjsPlayback', () => {
|
|
|
298
329
|
expect(cb).toHaveBeenCalledTimes(2)
|
|
299
330
|
})
|
|
300
331
|
|
|
301
|
-
test(
|
|
332
|
+
test("don't add one listener without a valid configuration", () => {
|
|
302
333
|
const cb = jest.fn()
|
|
303
334
|
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8' })
|
|
304
335
|
playback._setup()
|
|
@@ -313,7 +344,9 @@ describe('HlsjsPlayback', () => {
|
|
|
313
344
|
|
|
314
345
|
expect(cb).not.toHaveBeenCalled()
|
|
315
346
|
|
|
316
|
-
playback.options.hlsPlayback.customListeners.push([
|
|
347
|
+
playback.options.hlsPlayback.customListeners.push([
|
|
348
|
+
{ eventName: 'invalid_name', callback: cb }
|
|
349
|
+
])
|
|
317
350
|
|
|
318
351
|
expect(cb).not.toHaveBeenCalled()
|
|
319
352
|
})
|
|
@@ -358,7 +391,7 @@ describe('HlsjsPlayback', () => {
|
|
|
358
391
|
const fragmentMock = {
|
|
359
392
|
frag: {
|
|
360
393
|
programDateTime: 1556663040000, // 'Tue Apr 30 2019 19:24:00'
|
|
361
|
-
start: 0
|
|
394
|
+
start: 0
|
|
362
395
|
}
|
|
363
396
|
}
|
|
364
397
|
const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8' })
|