From 2a71d286cec31964e0b70b5a7c53bfad401af554 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Aug 2020 14:00:36 +0200 Subject: Handle playlist position in URL --- client/src/standalone/videos/embed.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'client/src/standalone/videos') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index a2902ce58..7372c80c6 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -179,6 +179,8 @@ export class PeerTubeEmbed { const errorText = document.getElementById('error-content') errorText.innerHTML = translatedText + + this.wrapperElement.style.display = 'none' } videoNotFound (translations?: Translations) { @@ -395,7 +397,7 @@ export class PeerTubeEmbed { } private getPreviousPlaylistElement (position?: number): VideoPlaylistElement { - if (!position) position = this.currentPlaylistElement.position -1 + if (!position) position = this.currentPlaylistElement.position - 1 if (position < 1) { return undefined @@ -561,7 +563,28 @@ export class PeerTubeEmbed { const playlistElementResult = await res.videosResponse.json() this.playlistElements = await this.loadAllPlaylistVideos(playlistId, playlistElementResult) - this.currentPlaylistElement = this.playlistElements[0] + const params = new URL(window.location.toString()).searchParams + const playlistPositionParam = this.getParamString(params, 'playlistPosition') + + let position = 1 + + if (playlistPositionParam) { + position = parseInt(playlistPositionParam + '', 10) + } + + this.currentPlaylistElement = this.playlistElements.find(e => e.position === position) + if (!this.currentPlaylistElement || !this.currentPlaylistElement.video) { + console.error('Current playlist element is not valid.', this.currentPlaylistElement) + this.currentPlaylistElement = this.getNextPlaylistElement() + } + + if (!this.currentPlaylistElement) { + console.error('This playlist does not have any valid element.') + const serverTranslations = await this.translationsPromise + this.playlistFetchError(serverTranslations) + return + } + videoId = this.currentPlaylistElement.video.uuid } else { videoId = this.getResourceId() -- cgit v1.2.3