diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-03 14:10:54 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-12-03 15:21:16 +0100 |
commit | bb4ba6d94c5051fdd665ebe63fffcc105778b8be (patch) | |
tree | d39302608c53e31395683bb5dd551eac6ced89f8 /server/lib/job-queue/handlers | |
parent | 19b7ebfaa822b12f6da25ad2ba10398b3ef25ec6 (diff) | |
download | PeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.tar.gz PeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.tar.zst PeerTube-bb4ba6d94c5051fdd665ebe63fffcc105778b8be.zip |
Add permanent live support
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 27 |
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 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { copy, readdir, remove } from 'fs-extra' | 2 | import { copy, pathExists, readdir, remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils' | 4 | import { getDurationFromVideoFile, getVideoFileResolution } from '@server/helpers/ffprobe-utils' |
5 | import { VIDEO_LIVE } from '@server/initializers/constants' | 5 | import { VIDEO_LIVE } from '@server/initializers/constants' |
@@ -14,6 +14,7 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin | |||
14 | import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' | 14 | import { MStreamingPlaylist, MVideo, MVideoLive } from '@server/types/models' |
15 | import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models' | 15 | import { ThumbnailType, VideoLiveEndingPayload, VideoState } from '@shared/models' |
16 | import { logger } from '../../../helpers/logger' | 16 | import { logger } from '../../../helpers/logger' |
17 | import { LiveManager } from '@server/lib/live-manager' | ||
17 | 18 | ||
18 | async function processVideoLiveEnding (job: Bull.Job) { | 19 | async 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 | ||
49 | async 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 | ||
48 | export { | 59 | export { |
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 | ||
134 | async 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 | |||
143 | async function cleanupLiveFiles (hlsDirectory: string) { | 146 | async 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) { |