X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fp2p-media-loader%2Fhls-plugin.ts;h=ca7a341b423a2f2ac4a7376117689d548acd9b79;hb=adc1f09c0dbd997f34028c1c82d1c118dc8ead80;hp=d78e1ab9021ec498f8afd6dc38a577010530ac54;hpb=134cf2bce96a8c5aefd55154e884964975d8cf23;p=github%2FChocobozzz%2FPeerTube.git 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 d78e1ab90..ca7a341b4 100644 --- a/client/src/assets/player/p2p-media-loader/hls-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/hls-plugin.ts @@ -1,8 +1,8 @@ // Thanks https://github.com/streamroot/videojs-hlsjs-plugin // We duplicated this plugin to choose the hls.js version we want, because streamroot only provide a bundled file -import * as Hlsjs from 'hls.js' -import videojs, { VideoJsPlayer } from 'video.js' +import * as Hlsjs from 'hls.js/dist/hls.light.js' +import videojs from 'video.js' import { HlsjsConfigHandlerOptions, QualityLevelRepresentation, QualityLevels, VideoJSTechHLS } from '../peertube-videojs-typings' type ErrorCounts = { @@ -13,6 +13,8 @@ type Metadata = { levels: Hlsjs.Level[] } +type CustomAudioTrack = Hlsjs.HlsAudioTrack & { name?: string, lang?: string } + const registerSourceHandler = function (vjs: typeof videojs) { if (!Hlsjs.isSupported()) { console.warn('Hls.js is not supported in this browser!') @@ -53,7 +55,7 @@ const registerSourceHandler = function (vjs: typeof videojs) { (vjs as any).Html5Hlsjs = Html5Hlsjs } -function hlsjsConfigHandler (this: VideoJsPlayer, options: HlsjsConfigHandlerOptions) { +function hlsjsConfigHandler (this: videojs.Player, options: HlsjsConfigHandlerOptions) { const player = this if (!options) return @@ -86,12 +88,12 @@ class Html5Hlsjs { private readonly videoElement: HTMLVideoElement private readonly errorCounts: ErrorCounts = {} - private readonly player: VideoJsPlayer + private readonly player: videojs.Player private readonly tech: videojs.Tech private readonly source: videojs.Tech.SourceObject private readonly vjs: typeof videojs - private hls: Hlsjs & { manualLevel?: number } // FIXME: typings + private hls: Hlsjs & { manualLevel?: number, audioTrack?: any, audioTracks?: CustomAudioTrack[] } // FIXME: typings private hlsjsConfig: Partial = null private _duration: number = null @@ -178,8 +180,6 @@ class Html5Hlsjs { this.player.textTracks().removeEventListener('change', this.handlers.textTracksChange) this.uiTextTrackHandled = false - this.player.audioTracks().removeEventListener('change', this.handlers.audioTracksChange) - this.hls.destroy() } @@ -226,6 +226,7 @@ class Html5Hlsjs { if (this.errorCounts[ Hlsjs.ErrorTypes.MEDIA_ERROR ] > 2) { console.info('bubbling media error up to VIDEOJS') + this.hls.destroy() this.tech.error = () => error this.tech.trigger('error') return @@ -393,7 +394,7 @@ class Html5Hlsjs { } private _onAudioTracks () { - const hlsAudioTracks = this.hls.audioTracks as (AudioTrack & { name?: string, lang?: string })[] // FIXME typings + const hlsAudioTracks = this.hls.audioTracks const playerAudioTracks = this.tech.audioTracks() if (hlsAudioTracks.length > 1 && playerAudioTracks.length === 0) {