aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-03 14:10:54 +0100
committerChocobozzz <me@florianbigard.com>2020-12-03 15:21:16 +0100
commitbb4ba6d94c5051fdd665ebe63fffcc105778b8be (patch)
treed39302608c53e31395683bb5dd551eac6ced89f8 /server/lib/job-queue
parent19b7ebfaa822b12f6da25ad2ba10398b3ef25ec6 (diff)
downloadPeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.tar.gz
PeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.tar.zst
PeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.zip
Add permanent live support
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index d3c84ce75..e3c11caa2 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -1,5 +1,5 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { copy, readdir, remove } from 'fs-extra' 2import { copy, pathExists, readdir, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils' 4import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils'
5import { VIDEO_LIVE } from '@server/initializers/constants' 5import { VIDEO_LIVE } from '@server/initializers/constants'
@@ -14,6 +14,7 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin
14import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' 14import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models'
15import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models' 15import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models'
16import { logger } from '../../../helpers/logger' 16import { logger } from '../../../helpers/logger'
17import { LiveManager } from '@server/lib/live-manager'
17 18
18async function processVideoLiveEnding (job: Bull.Job) { 19async function processVideoLiveEnding (job: Bull.Job) {
19 const payload = job.data as VideoLiveEndingPayload 20 const payload = job.data as VideoLiveEndingPayload
@@ -36,6 +37,8 @@ async function processVideoLiveEnding (job: Bull.Job) {
36 return 37 return
37 } 38 }
38 39
40 LiveManager.Instance.cleanupShaSegments(video.uuid)
41
39 if (live.saveReplay !== true) { 42 if (live.saveReplay !== true) {
40 return cleanupLive(video, streamingPlaylist) 43 return cleanupLive(video, streamingPlaylist)
41 } 44 }
@@ -43,10 +46,19 @@ async function processVideoLiveEnding (job: Bull.Job) {
43 return saveLive(video, live) 46 return saveLive(video, live)
44} 47}
45 48
49async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
50 const hlsDirectory = getHLSDirectory(video)
51
52 await remove(hlsDirectory)
53
54 await streamingPlaylist.destroy()
55}
56
46// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
47 58
48export { 59export {
49 processVideoLiveEnding 60 processVideoLiveEnding,
61 cleanupLive
50} 62}
51 63
52// --------------------------------------------------------------------------- 64// ---------------------------------------------------------------------------
@@ -131,16 +143,9 @@ async function saveLive (video: MVideo, live: MVideoLive) {
131 await publishAndFederateIfNeeded(videoWithFiles, true) 143 await publishAndFederateIfNeeded(videoWithFiles, true)
132} 144}
133 145
134async function cleanupLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
135 const hlsDirectory = getHLSDirectory(video)
136
137 await remove(hlsDirectory)
138
139 streamingPlaylist.destroy()
140 .catch(err => logger.error('Cannot remove live streaming playlist.', { err }))
141}
142
143async function cleanupLiveFiles (hlsDirectory: string) { 146async function cleanupLiveFiles (hlsDirectory: string) {
147 if (!await pathExists(hlsDirectory)) return
148
144 const files = await readdir(hlsDirectory) 149 const files = await readdir(hlsDirectory)
145 150
146 for (const filename of files) { 151 for (const filename of files) {