diff options
-rw-r--r-- | server/lib/live/shared/muxing-session.ts | 19 |
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 { | |||
17 | import { VideoFileModel } from '@server/models/video/video-file' | 17 | import { VideoFileModel } from '@server/models/video/video-file' |
18 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | 18 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' |
19 | import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' | 19 | import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' |
20 | import { wait } from '@shared/core-utils' | ||
20 | import { VideoStorage, VideoStreamingPlaylistType } from '@shared/models' | 21 | import { VideoStorage, VideoStreamingPlaylistType } from '@shared/models' |
21 | import { | 22 | import { |
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 | ||