aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-11-15 08:55:27 +0100
committerChocobozzz <me@florianbigard.com>2022-11-15 10:50:57 +0100
commitc2419476302b20e9fe3708d7a0a889ae18c95c1b (patch)
tree3276a4b6979ce3bba80f776f116d7e5cc55863db
parent90dbc73132f22888a60628d921c92f938499bd7b (diff)
downloadPeerTube-c2419476302b20e9fe3708d7a0a889ae18c95c1b.tar.gz
PeerTube-c2419476302b20e9fe3708d7a0a889ae18c95c1b.tar.zst
PeerTube-c2419476302b20e9fe3708d7a0a889ae18c95c1b.zip
Correctly terminate an ended live
-rw-r--r--client/src/standalone/videos/embed.ts44
-rw-r--r--client/src/standalone/videos/shared/live-manager.ts15
-rw-r--r--server/tests/api/views/video-views-counter.ts2
-rw-r--r--server/tests/api/views/video-views-overall-stats.ts4
-rw-r--r--server/tests/api/views/video-views-retention-stats.ts2
-rw-r--r--server/tests/api/views/video-views-timeserie-stats.ts4
6 files changed, 50 insertions, 21 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 356f149c0..2b826b9a2 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -3,12 +3,12 @@ import '../../assets/player/shared/dock/peertube-dock-component'
3import '../../assets/player/shared/dock/peertube-dock-plugin' 3import '../../assets/player/shared/dock/peertube-dock-plugin'
4import videojs from 'video.js' 4import videojs from 'video.js'
5import { peertubeTranslate } from '../../../../shared/core-utils/i18n' 5import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
6import { HTMLServerConfig, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement } from '../../../../shared/models' 6import { HTMLServerConfig, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement, VideoState } from '../../../../shared/models'
7import { PeertubePlayerManager } from '../../assets/player' 7import { 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, VideoFetcher } from './shared' 11import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, Translations, VideoFetcher } from './shared'
12import { PlayerHTML } from './shared/player-html' 12import { PlayerHTML } from './shared/player-html'
13 13
14export class PeerTubeEmbed { 14export class PeerTubeEmbed {
@@ -251,18 +251,25 @@ export class PeerTubeEmbed {
251 }) 251 })
252 } 252 }
253 253
254 this.peertubePlugin.getPluginsManager().runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video })
255
256 if (video.isLive) { 254 if (video.isLive) {
257 this.liveManager.displayInfoAndListenForChanges({ 255 this.liveManager.listenForChanges({
258 video, 256 video,
259 translations,
260 onPublishedVideo: () => { 257 onPublishedVideo: () => {
261 this.liveManager.stopListeningForChanges(video) 258 this.liveManager.stopListeningForChanges(video)
262 this.loadVideoAndBuildPlayer(video.uuid) 259 this.loadVideoAndBuildPlayer(video.uuid)
263 } 260 }
264 }) 261 })
262
263 if (video.state.id === VideoState.WAITING_FOR_LIVE || video.state.id === VideoState.LIVE_ENDED) {
264 this.liveManager.displayInfo({ state: video.state.id, translations })
265
266 this.disablePlayer()
267 } else {
268 this.correctlyHandleLiveEnding(translations)
269 }
265 } 270 }
271
272 this.peertubePlugin.getPluginsManager().runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video })
266 } 273 }
267 274
268 private resetPlayerElement () { 275 private resetPlayerElement () {
@@ -351,6 +358,31 @@ export class PeerTubeEmbed {
351 private isPlaylistEmbed () { 358 private isPlaylistEmbed () {
352 return window.location.pathname.split('/')[1] === 'video-playlists' 359 return window.location.pathname.split('/')[1] === 'video-playlists'
353 } 360 }
361
362 // ---------------------------------------------------------------------------
363
364 private correctlyHandleLiveEnding (translations: Translations) {
365 this.player.one('ended', () => {
366 // Display the live ended information
367 this.liveManager.displayInfo({ state: VideoState.LIVE_ENDED, translations })
368
369 this.disablePlayer()
370 })
371 }
372
373 private disablePlayer () {
374 if (this.player.isFullscreen()) {
375 this.player.exitFullscreen()
376 }
377
378 // Disable player
379 this.player.hasStarted(false)
380 this.player.removeClass('vjs-has-autoplay')
381 this.player.bigPlayButton.hide();
382
383 (this.player.el() as HTMLElement).style.pointerEvents = 'none'
384 }
385
354} 386}
355 387
356PeerTubeEmbed.main() 388PeerTubeEmbed.main()
diff --git a/client/src/standalone/videos/shared/live-manager.ts b/client/src/standalone/videos/shared/live-manager.ts
index ec11d0b61..5fac229ba 100644
--- a/client/src/standalone/videos/shared/live-manager.ts
+++ b/client/src/standalone/videos/shared/live-manager.ts
@@ -14,15 +14,12 @@ export class LiveManager {
14 14
15 } 15 }
16 16
17 async displayInfoAndListenForChanges (options: { 17 async listenForChanges (options: {
18 video: VideoDetails 18 video: VideoDetails
19 translations: Translations
20 onPublishedVideo: () => any 19 onPublishedVideo: () => any
21 }) { 20 }) {
22 const { video, onPublishedVideo } = options 21 const { video, onPublishedVideo } = options
23 22
24 this.displayAppropriateInfo(options)
25
26 if (!this.liveSocket) { 23 if (!this.liveSocket) {
27 const io = (await import('socket.io-client')).io 24 const io = (await import('socket.io-client')).io
28 this.liveSocket = io(window.location.origin + '/live-videos') 25 this.liveSocket = io(window.location.origin + '/live-videos')
@@ -51,18 +48,18 @@ export class LiveManager {
51 this.liveSocket.emit('unsubscribe', { videoId: video.id }) 48 this.liveSocket.emit('unsubscribe', { videoId: video.id })
52 } 49 }
53 50
54 private displayAppropriateInfo (options: { 51 displayInfo (options: {
55 video: VideoDetails 52 state: VideoState
56 translations: Translations 53 translations: Translations
57 }) { 54 }) {
58 const { video, translations } = options 55 const { state, translations } = options
59 56
60 if (video.state.id === VideoState.WAITING_FOR_LIVE) { 57 if (state === VideoState.WAITING_FOR_LIVE) {
61 this.displayWaitingForLiveInfo(translations) 58 this.displayWaitingForLiveInfo(translations)
62 return 59 return
63 } 60 }
64 61
65 if (video.state.id === VideoState.LIVE_ENDED) { 62 if (state === VideoState.LIVE_ENDED) {
66 this.displayEndedLiveInfo(translations) 63 this.displayEndedLiveInfo(translations)
67 return 64 return
68 } 65 }
diff --git a/server/tests/api/views/video-views-counter.ts b/server/tests/api/views/video-views-counter.ts
index ca33ff9cd..0c1b7859c 100644
--- a/server/tests/api/views/video-views-counter.ts
+++ b/server/tests/api/views/video-views-counter.ts
@@ -76,7 +76,7 @@ describe('Test video views/viewers counters', function () {
76 let command: FfmpegCommand 76 let command: FfmpegCommand
77 77
78 before(async function () { 78 before(async function () {
79 this.timeout(120000); 79 this.timeout(240000);
80 80
81 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true })) 81 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true }))
82 }) 82 })
diff --git a/server/tests/api/views/video-views-overall-stats.ts b/server/tests/api/views/video-views-overall-stats.ts
index bb00684ef..3aadc9689 100644
--- a/server/tests/api/views/video-views-overall-stats.ts
+++ b/server/tests/api/views/video-views-overall-stats.ts
@@ -20,7 +20,7 @@ describe('Test views overall stats', function () {
20 let command: FfmpegCommand 20 let command: FfmpegCommand
21 21
22 before(async function () { 22 before(async function () {
23 this.timeout(120000); 23 this.timeout(240000);
24 24
25 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true })) 25 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true }))
26 }) 26 })
@@ -179,7 +179,7 @@ describe('Test views overall stats', function () {
179 let before2Watchers: Date 179 let before2Watchers: Date
180 180
181 before(async function () { 181 before(async function () {
182 this.timeout(120000); 182 this.timeout(240000);
183 183
184 ({ vodVideoId: videoUUID } = await prepareViewsVideos({ servers, live: true, vod: true })) 184 ({ vodVideoId: videoUUID } = await prepareViewsVideos({ servers, live: true, vod: true }))
185 }) 185 })
diff --git a/server/tests/api/views/video-views-retention-stats.ts b/server/tests/api/views/video-views-retention-stats.ts
index 621b05110..5b9ce4c92 100644
--- a/server/tests/api/views/video-views-retention-stats.ts
+++ b/server/tests/api/views/video-views-retention-stats.ts
@@ -17,7 +17,7 @@ describe('Test views retention stats', function () {
17 let vodVideoId: string 17 let vodVideoId: string
18 18
19 before(async function () { 19 before(async function () {
20 this.timeout(120000); 20 this.timeout(240000);
21 21
22 ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true })) 22 ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true }))
23 }) 23 })
diff --git a/server/tests/api/views/video-views-timeserie-stats.ts b/server/tests/api/views/video-views-timeserie-stats.ts
index e8cb34ad6..2d991d7ea 100644
--- a/server/tests/api/views/video-views-timeserie-stats.ts
+++ b/server/tests/api/views/video-views-timeserie-stats.ts
@@ -30,7 +30,7 @@ describe('Test views timeserie stats', function () {
30 let vodVideoId: string 30 let vodVideoId: string
31 31
32 before(async function () { 32 before(async function () {
33 this.timeout(120000); 33 this.timeout(240000);
34 34
35 ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true })) 35 ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true }))
36 }) 36 })
@@ -81,7 +81,7 @@ describe('Test views timeserie stats', function () {
81 } 81 }
82 82
83 before(async function () { 83 before(async function () {
84 this.timeout(120000); 84 this.timeout(240000);
85 85
86 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true })) 86 ({ vodVideoId, liveVideoId, ffmpegCommand: command } = await prepareViewsVideos({ servers, live: true, vod: true }))
87 }) 87 })