aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/p2p-media-loader/hls-plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/p2p-media-loader/hls-plugin.ts')
-rw-r--r--client/src/assets/player/p2p-media-loader/hls-plugin.ts16
1 files changed, 7 insertions, 9 deletions
diff --git a/client/src/assets/player/p2p-media-loader/hls-plugin.ts b/client/src/assets/player/p2p-media-loader/hls-plugin.ts
index 3050110cd..78f0944ef 100644
--- a/client/src/assets/player/p2p-media-loader/hls-plugin.ts
+++ b/client/src/assets/player/p2p-media-loader/hls-plugin.ts
@@ -1,7 +1,7 @@
1// Thanks https://github.com/streamroot/videojs-hlsjs-plugin 1// Thanks https://github.com/streamroot/videojs-hlsjs-plugin
2// We duplicated this plugin to choose the hls.js version we want, because streamroot only provide a bundled file 2// We duplicated this plugin to choose the hls.js version we want, because streamroot only provide a bundled file
3 3
4import * as Hlsjs from 'hls.js/dist/hls.light.js' 4import Hlsjs, { ErrorData, HlsConfig, Level, ManifestLoadedData } from 'hls.js'
5import videojs from 'video.js' 5import videojs from 'video.js'
6import { HlsjsConfigHandlerOptions, QualityLevelRepresentation, QualityLevels, VideoJSTechHLS } from '../peertube-videojs-typings' 6import { HlsjsConfigHandlerOptions, QualityLevelRepresentation, QualityLevels, VideoJSTechHLS } from '../peertube-videojs-typings'
7 7
@@ -10,11 +10,9 @@ type ErrorCounts = {
10} 10}
11 11
12type Metadata = { 12type Metadata = {
13 levels: Hlsjs.Level[] 13 levels: Level[]
14} 14}
15 15
16type CustomAudioTrack = Hlsjs.HlsAudioTrack & { name?: string, lang?: string }
17
18const registerSourceHandler = function (vjs: typeof videojs) { 16const registerSourceHandler = function (vjs: typeof videojs) {
19 if (!Hlsjs.isSupported()) { 17 if (!Hlsjs.isSupported()) {
20 console.warn('Hls.js is not supported in this browser!') 18 console.warn('Hls.js is not supported in this browser!')
@@ -93,8 +91,8 @@ class Html5Hlsjs {
93 private readonly source: videojs.Tech.SourceObject 91 private readonly source: videojs.Tech.SourceObject
94 private readonly vjs: typeof videojs 92 private readonly vjs: typeof videojs
95 93
96 private hls: Hlsjs & { manualLevel?: number, audioTrack?: any, audioTracks?: CustomAudioTrack[] } // FIXME: typings 94 private hls: Hlsjs
97 private hlsjsConfig: Partial<Hlsjs.Config & { cueHandler: any }> = null 95 private hlsjsConfig: Partial<HlsConfig & { cueHandler: any }> = null
98 96
99 private _duration: number = null 97 private _duration: number = null
100 private metadata: Metadata = null 98 private metadata: Metadata = null
@@ -255,7 +253,7 @@ class Html5Hlsjs {
255 this.tech.trigger('error') 253 this.tech.trigger('error')
256 } 254 }
257 255
258 private _onError (_event: any, data: Hlsjs.errorData) { 256 private _onError (_event: any, data: ErrorData) {
259 const error: { message: string, code?: number } = { 257 const error: { message: string, code?: number } = {
260 message: `HLS.js error: ${data.type} - fatal: ${data.fatal} - ${data.details}` 258 message: `HLS.js error: ${data.type} - fatal: ${data.fatal} - ${data.details}`
261 } 259 }
@@ -285,7 +283,7 @@ class Html5Hlsjs {
285 this.hls.currentLevel = qualityId 283 this.hls.currentLevel = qualityId
286 } 284 }
287 285
288 private _levelLabel (level: Hlsjs.Level) { 286 private _levelLabel (level: Level) {
289 if (this.player.srOptions_.levelLabelHandler) { 287 if (this.player.srOptions_.levelLabelHandler) {
290 return this.player.srOptions_.levelLabelHandler(level as any) 288 return this.player.srOptions_.levelLabelHandler(level as any)
291 } 289 }
@@ -523,7 +521,7 @@ class Html5Hlsjs {
523 } 521 }
524 } 522 }
525 523
526 private _onMetaData (_event: any, data: Hlsjs.manifestLoadedData) { 524 private _onMetaData (_event: any, data: ManifestLoadedData) {
527 // This could arrive before 'loadedqualitydata' handlers is registered, remember it so we can raise it later 525 // This could arrive before 'loadedqualitydata' handlers is registered, remember it so we can raise it later
528 this.metadata = data as any 526 this.metadata = data as any
529 this._handleQualityLevels() 527 this._handleQualityLevels()