aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/live-manager.ts')
-rw-r--r--server/lib/live-manager.ts40
1 files changed, 33 insertions, 7 deletions
diff --git a/server/lib/live-manager.ts b/server/lib/live-manager.ts
index 4f45ce530..dcf016169 100644
--- a/server/lib/live-manager.ts
+++ b/server/lib/live-manager.ts
@@ -19,6 +19,7 @@ import { VideoState, VideoStreamingPlaylistType } from '@shared/models'
19import { federateVideoIfNeeded } from './activitypub/videos' 19import { federateVideoIfNeeded } from './activitypub/videos'
20import { buildSha256Segment } from './hls' 20import { buildSha256Segment } from './hls'
21import { JobQueue } from './job-queue' 21import { JobQueue } from './job-queue'
22import { cleanupLive } from './job-queue/handlers/video-live-ending'
22import { PeerTubeSocket } from './peertube-socket' 23import { PeerTubeSocket } from './peertube-socket'
23import { isAbleToUploadVideo } from './user' 24import { isAbleToUploadVideo } from './user'
24import { getHLSDirectory } from './video-paths' 25import { getHLSDirectory } from './video-paths'
@@ -153,6 +154,10 @@ class LiveManager {
153 watchers.push(new Date().getTime()) 154 watchers.push(new Date().getTime())
154 } 155 }
155 156
157 cleanupShaSegments (videoUUID: string) {
158 this.segmentsSha256.delete(videoUUID)
159 }
160
156 private getContext () { 161 private getContext () {
157 return context 162 return context
158 } 163 }
@@ -184,6 +189,14 @@ class LiveManager {
184 return this.abortSession(sessionId) 189 return this.abortSession(sessionId)
185 } 190 }
186 191
192 // Cleanup old potential live files (could happen with a permanent live)
193 this.cleanupShaSegments(video.uuid)
194
195 const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
196 if (oldStreamingPlaylist) {
197 await cleanupLive(video, oldStreamingPlaylist)
198 }
199
187 this.videoSessions.set(video.id, sessionId) 200 this.videoSessions.set(video.id, sessionId)
188 201
189 const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) 202 const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
@@ -372,7 +385,13 @@ class LiveManager {
372 logger.info('RTMP transmuxing for video %s ended. Scheduling cleanup', rtmpUrl) 385 logger.info('RTMP transmuxing for video %s ended. Scheduling cleanup', rtmpUrl)
373 386
374 this.transSessions.delete(sessionId) 387 this.transSessions.delete(sessionId)
388
375 this.watchersPerVideo.delete(videoLive.videoId) 389 this.watchersPerVideo.delete(videoLive.videoId)
390 this.videoSessions.delete(videoLive.videoId)
391
392 const newLivesPerUser = this.livesPerUser.get(user.id)
393 .filter(o => o.liveId !== videoLive.id)
394 this.livesPerUser.set(user.id, newLivesPerUser)
376 395
377 setTimeout(() => { 396 setTimeout(() => {
378 // Wait latest segments generation, and close watchers 397 // Wait latest segments generation, and close watchers
@@ -412,14 +431,21 @@ class LiveManager {
412 const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) 431 const fullVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
413 if (!fullVideo) return 432 if (!fullVideo) return
414 433
415 JobQueue.Instance.createJob({ 434 const live = await VideoLiveModel.loadByVideoId(videoId)
416 type: 'video-live-ending', 435
417 payload: { 436 if (!live.permanentLive) {
418 videoId: fullVideo.id 437 JobQueue.Instance.createJob({
419 } 438 type: 'video-live-ending',
420 }, { delay: cleanupNow ? 0 : VIDEO_LIVE.CLEANUP_DELAY }) 439 payload: {
440 videoId: fullVideo.id
441 }
442 }, { delay: cleanupNow ? 0 : VIDEO_LIVE.CLEANUP_DELAY })
443
444 fullVideo.state = VideoState.LIVE_ENDED
445 } else {
446 fullVideo.state = VideoState.WAITING_FOR_LIVE
447 }
421 448
422 fullVideo.state = VideoState.LIVE_ENDED
423 await fullVideo.save() 449 await fullVideo.save()
424 450
425 PeerTubeSocket.Instance.sendVideoLiveNewState(fullVideo) 451 PeerTubeSocket.Instance.sendVideoLiveNewState(fullVideo)