From 0f2f274c9837bbcd95446778314c9c32831faa0e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 22 Nov 2019 17:16:11 +0100 Subject: Auto load HLS player in embed too --- client/src/standalone/videos/embed.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'client/src') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 896d90de2..40d945824 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -116,7 +116,7 @@ export class PeerTubeEmbed { this.api.initialize() } - private loadParams () { + private loadParams (video: VideoDetails) { try { const params = new URL(window.location.toString()).searchParams @@ -136,7 +136,15 @@ export class PeerTubeEmbed { this.bigPlayBackgroundColor = this.getParamString(params, 'bigPlayBackgroundColor') this.foregroundColor = this.getParamString(params, 'foregroundColor') - this.mode = this.getParamString(params, 'mode') === 'p2p-media-loader' ? 'p2p-media-loader' : 'webtorrent' + const modeParam = this.getParamString(params, 'mode') + + if (modeParam) { + if (modeParam === 'p2p-media-loader') this.mode = 'p2p-media-loader' + else this.mode = 'webtorrent' + } else { + if (Array.isArray(video.streamingPlaylists) && video.streamingPlaylists.length !== 0) this.mode = 'p2p-media-loader' + else this.mode = 'webtorrent' + } } catch (err) { console.error('Cannot get params from URL.', err) } @@ -162,7 +170,7 @@ export class PeerTubeEmbed { const videoInfo: VideoDetails = await videoResponse.json() const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse) - this.loadParams() + this.loadParams(videoInfo) const options: PeertubePlayerManagerOptions = { common: { -- cgit v1.2.3