aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-11-15 11:57:49 +0100
committerChocobozzz <me@florianbigard.com>2022-11-15 11:57:49 +0100
commit59a643aa5cf6775d27dfcc147b19c4537292d53c (patch)
tree74bc87e2f0f5581306c8ea9dd1f8acf05833a74a /client/src/standalone/videos/embed.ts
parentc2419476302b20e9fe3708d7a0a889ae18c95c1b (diff)
downloadPeerTube-59a643aa5cf6775d27dfcc147b19c4537292d53c.tar.gz
PeerTube-59a643aa5cf6775d27dfcc147b19c4537292d53c.tar.zst
PeerTube-59a643aa5cf6775d27dfcc147b19c4537292d53c.zip
Force autoplay when live starts
Using the mute
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r--client/src/standalone/videos/embed.ts45
1 files changed, 33 insertions, 12 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 2b826b9a2..5bb3b43c2 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -8,7 +8,16 @@ import { PeertubePlayerManager } from '../../assets/player'
8import { TranslationsManager } from '../../assets/player/translations-manager' 8import { TranslationsManager } from '../../assets/player/translations-manager'
9import { getParamString, logger, videoRequiresAuth } from '../../root-helpers' 9import { getParamString, logger, videoRequiresAuth } from '../../root-helpers'
10import { PeerTubeEmbedApi } from './embed-api' 10import { PeerTubeEmbedApi } from './embed-api'
11import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, Translations, VideoFetcher } from './shared' 11import {
12 AuthHTTP,
13 LiveManager,
14 PeerTubePlugin,
15 PlayerManagerOptions,
16 PlaylistFetcher,
17 PlaylistTracker,
18 Translations,
19 VideoFetcher
20} from './shared'
12import { PlayerHTML } from './shared/player-html' 21import { PlayerHTML } from './shared/player-html'
13 22
14export class PeerTubeEmbed { 23export class PeerTubeEmbed {
@@ -81,7 +90,7 @@ export class PeerTubeEmbed {
81 90
82 if (!videoId) return 91 if (!videoId) return
83 92
84 return this.loadVideoAndBuildPlayer(videoId) 93 return this.loadVideoAndBuildPlayer({ uuid: videoId, forceAutoplay: false })
85 } 94 }
86 95
87 private async initPlaylist () { 96 private async initPlaylist () {
@@ -138,7 +147,7 @@ export class PeerTubeEmbed {
138 147
139 this.playlistTracker.setCurrentElement(next) 148 this.playlistTracker.setCurrentElement(next)
140 149
141 return this.loadVideoAndBuildPlayer(next.video.uuid) 150 return this.loadVideoAndBuildPlayer({ uuid: next.video.uuid, forceAutoplay: false })
142 } 151 }
143 152
144 async playPreviousPlaylistVideo () { 153 async playPreviousPlaylistVideo () {
@@ -150,7 +159,7 @@ export class PeerTubeEmbed {
150 159
151 this.playlistTracker.setCurrentElement(previous) 160 this.playlistTracker.setCurrentElement(previous)
152 161
153 await this.loadVideoAndBuildPlayer(previous.video.uuid) 162 await this.loadVideoAndBuildPlayer({ uuid: previous.video.uuid, forceAutoplay: false })
154 } 163 }
155 164
156 getCurrentPlaylistPosition () { 165 getCurrentPlaylistPosition () {
@@ -159,17 +168,28 @@ export class PeerTubeEmbed {
159 168
160 // --------------------------------------------------------------------------- 169 // ---------------------------------------------------------------------------
161 170
162 private async loadVideoAndBuildPlayer (uuid: string) { 171 private async loadVideoAndBuildPlayer (options: {
172 uuid: string
173 forceAutoplay: boolean
174 }) {
175 const { uuid, forceAutoplay } = options
176
163 try { 177 try {
164 const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo(uuid) 178 const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo(uuid)
165 179
166 return this.buildVideoPlayer(videoResponse, captionsPromise) 180 return this.buildVideoPlayer({ videoResponse, captionsPromise, forceAutoplay })
167 } catch (err) { 181 } catch (err) {
168 this.playerHTML.displayError(err.message, await this.translationsPromise) 182 this.playerHTML.displayError(err.message, await this.translationsPromise)
169 } 183 }
170 } 184 }
171 185
172 private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise<Response>) { 186 private async buildVideoPlayer (options: {
187 videoResponse: Response
188 captionsPromise: Promise<Response>
189 forceAutoplay: boolean
190 }) {
191 const { videoResponse, captionsPromise, forceAutoplay } = options
192
173 const alreadyHadPlayer = this.resetPlayerElement() 193 const alreadyHadPlayer = this.resetPlayerElement()
174 194
175 const videoInfoPromise = videoResponse.json() 195 const videoInfoPromise = videoResponse.json()
@@ -201,7 +221,7 @@ export class PeerTubeEmbed {
201 221
202 const PlayerManager: typeof PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager 222 const PlayerManager: typeof PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager
203 223
204 const options = await this.playerManagerOptions.getPlayerOptions({ 224 const playerOptions = await this.playerManagerOptions.getPlayerOptions({
205 video, 225 video,
206 captionsResponse, 226 captionsResponse,
207 alreadyHadPlayer, 227 alreadyHadPlayer,
@@ -211,16 +231,17 @@ export class PeerTubeEmbed {
211 authorizationHeader: () => this.http.getHeaderTokenValue(), 231 authorizationHeader: () => this.http.getHeaderTokenValue(),
212 videoFileToken: () => videoFileToken, 232 videoFileToken: () => videoFileToken,
213 233
214 onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer(uuid), 234 onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer({ uuid, forceAutoplay: false }),
215 235
216 playlistTracker: this.playlistTracker, 236 playlistTracker: this.playlistTracker,
217 playNextPlaylistVideo: () => this.playNextPlaylistVideo(), 237 playNextPlaylistVideo: () => this.playNextPlaylistVideo(),
218 playPreviousPlaylistVideo: () => this.playPreviousPlaylistVideo(), 238 playPreviousPlaylistVideo: () => this.playPreviousPlaylistVideo(),
219 239
220 live 240 live,
241 forceAutoplay
221 }) 242 })
222 243
223 this.player = await PlayerManager.initialize(this.playerManagerOptions.getMode(), options, (player: videojs.Player) => { 244 this.player = await PlayerManager.initialize(this.playerManagerOptions.getMode(), playerOptions, (player: videojs.Player) => {
224 this.player = player 245 this.player = player
225 }) 246 })
226 247
@@ -256,7 +277,7 @@ export class PeerTubeEmbed {
256 video, 277 video,
257 onPublishedVideo: () => { 278 onPublishedVideo: () => {
258 this.liveManager.stopListeningForChanges(video) 279 this.liveManager.stopListeningForChanges(video)
259 this.loadVideoAndBuildPlayer(video.uuid) 280 this.loadVideoAndBuildPlayer({ uuid: video.uuid, forceAutoplay: true })
260 } 281 }
261 }) 282 })
262 283