aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-19 12:01:36 +0200
committerChocobozzz <me@florianbigard.com>2023-05-19 12:01:36 +0200
commit30453cb5ba523020c488dfb7986a9848870393a5 (patch)
tree99b84d630775911cf28ecd06e37f8d37ee170890 /server
parent72d606dc07543b04c18476b3cb4bf9d08aa74358 (diff)
downloadPeerTube-30453cb5ba523020c488dfb7986a9848870393a5.tar.gz
PeerTube-30453cb5ba523020c488dfb7986a9848870393a5.tar.zst
PeerTube-30453cb5ba523020c488dfb7986a9848870393a5.zip
Wait master playlist generation
Diffstat (limited to 'server')
-rw-r--r--server/lib/live/shared/muxing-session.ts19
1 files changed, 12 insertions, 7 deletions
diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts
index c9e5df906..0921254cb 100644
--- a/server/lib/live/shared/muxing-session.ts
+++ b/server/lib/live/shared/muxing-session.ts
@@ -17,6 +17,7 @@ import {
17import { VideoFileModel } from '@server/models/video/video-file' 17import { VideoFileModel } from '@server/models/video/video-file'
18import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 18import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
19import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' 19import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models'
20import { wait } from '@shared/core-utils'
20import { VideoStorage, VideoStreamingPlaylistType } from '@shared/models' 21import { VideoStorage, VideoStreamingPlaylistType } from '@shared/models'
21import { 22import {
22 generateHLSMasterPlaylistFilename, 23 generateHLSMasterPlaylistFilename,
@@ -184,14 +185,21 @@ class MuxingSession extends EventEmitter {
184 } 185 }
185 186
186 private watchMasterFile () { 187 private watchMasterFile () {
187 const watcher = this.filesWatcher.on('change', async path => { 188 this.filesWatcher.on('add', async path => {
188 if (path !== join(this.outDirectory, this.streamingPlaylist.playlistFilename)) return 189 if (path !== join(this.outDirectory, this.streamingPlaylist.playlistFilename)) return
189 if (this.masterPlaylistCreated === true) return 190 if (this.masterPlaylistCreated === true) return
190 191
191 try { 192 try {
192 const masterPlaylistContent = await readFile(path, 'utf8') 193 let masterPlaylistContent: string
193 // Not generated yet 194
194 if (!masterPlaylistContent) return 195 do {
196 masterPlaylistContent = await readFile(path, 'utf8')
197
198 if (!masterPlaylistContent) {
199 await wait(250)
200 logger.debug('Waiting for master playlist generation for ' + this.videoUUID, this.lTags())
201 }
202 } while (!masterPlaylistContent) // Not generated yet
195 203
196 if (this.streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) { 204 if (this.streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) {
197 const url = await storeHLSFileFromFilename(this.streamingPlaylist, this.streamingPlaylist.playlistFilename) 205 const url = await storeHLSFileFromFilename(this.streamingPlaylist, this.streamingPlaylist.playlistFilename)
@@ -209,9 +217,6 @@ class MuxingSession extends EventEmitter {
209 this.masterPlaylistCreated = true 217 this.masterPlaylistCreated = true
210 218
211 logger.info('Master playlist file for %s has been created', this.videoUUID, this.lTags()) 219 logger.info('Master playlist file for %s has been created', this.videoUUID, this.lTags())
212
213 watcher.close()
214 .catch(err => logger.error('Cannot close watcher', { err }))
215 }) 220 })
216 } 221 }
217 222