]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/shared/live.ts
Fix saving permanent live replay on quick restream
[github/Chocobozzz/PeerTube.git] / server / tests / shared / live.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { pathExists, readdir } from 'fs-extra'
5 import { join } from 'path'
6 import { LiveVideo } from '@shared/models'
7 import { PeerTubeServer } from '@shared/server-commands'
8
9 async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
10 let live: LiveVideo
11
12 try {
13 live = await server.live.get({ videoId: videoUUID })
14 } catch {}
15
16 const basePath = server.servers.buildDirectory('streaming-playlists')
17 const hlsPath = join(basePath, 'hls', videoUUID)
18
19 if (savedResolutions.length === 0) {
20
21 if (live?.permanentLive) {
22 expect(await pathExists(hlsPath)).to.be.true
23
24 const hlsFiles = await readdir(hlsPath)
25 expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
26
27 const replayDir = join(hlsPath, 'replay')
28 expect(await pathExists(replayDir)).to.be.true
29
30 const replayFiles = await readdir(join(hlsPath, 'replay'))
31 expect(replayFiles).to.have.lengthOf(0)
32 } else {
33 expect(await pathExists(hlsPath)).to.be.false
34 }
35
36 return
37 }
38
39 const files = await readdir(hlsPath)
40
41 // fragmented file and playlist per resolution + master playlist + segments sha256 json file
42 expect(files).to.have.lengthOf(savedResolutions.length * 2 + 2)
43
44 for (const resolution of savedResolutions) {
45 const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))
46 expect(fragmentedFile).to.exist
47
48 const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`))
49 expect(playlistFile).to.exist
50 }
51
52 const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'))
53 expect(masterPlaylistFile).to.exist
54
55 const shaFile = files.find(f => f.endsWith('-segments-sha256.json'))
56 expect(shaFile).to.exist
57 }
58
59 export {
60 checkLiveCleanup
61 }