+ addViewTo (videoId: number) {
+ if (this.videoSessions.has(videoId) === false) return
+
+ let watchers = this.watchersPerVideo.get(videoId)
+
+ if (!watchers) {
+ watchers = []
+ this.watchersPerVideo.set(videoId, watchers)
+ }
+
+ watchers.push(new Date().getTime())
+ }
+
+ cleanupShaSegments (videoUUID: string) {
+ this.segmentsSha256.delete(videoUUID)
+ }
+
+ addSegmentToReplay (hlsVideoPath: string, segmentPath: string) {
+ const segmentName = basename(segmentPath)
+ const dest = join(hlsVideoPath, VIDEO_LIVE.REPLAY_DIRECTORY, this.buildConcatenatedName(segmentName))
+
+ return readFile(segmentPath)
+ .then(data => appendFile(dest, data))
+ .catch(err => logger.error('Cannot copy segment %s to repay directory.', segmentPath, { err }))
+ }
+
+ buildConcatenatedName (segmentOrPlaylistPath: string) {
+ const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
+
+ return 'concat-' + num[1] + '.ts'
+ }
+
+ private processSegments (hlsVideoPath: string, videoUUID: string, videoLive: MVideoLive, segmentPaths: string[]) {
+ Bluebird.mapSeries(segmentPaths, async previousSegment => {
+ // Add sha hash of previous segments, because ffmpeg should have finished generating them
+ await this.addSegmentSha(videoUUID, previousSegment)
+
+ if (videoLive.saveReplay) {
+ await this.addSegmentToReplay(hlsVideoPath, previousSegment)
+ }
+ }).catch(err => logger.error('Cannot process segments in %s', hlsVideoPath, { err }))
+ }
+