+ if (savedResolutions.length === 0) {
+ return checkUnsavedLiveCleanup(server, videoUUID, hlsPath)
+ }
+
+ return checkSavedLiveCleanup(hlsPath, savedResolutions)
+}
+
+// ---------------------------------------------------------------------------
+
+async function testVideoResolutions (options: {
+ originServer: PeerTubeServer
+ servers: PeerTubeServer[]
+ liveVideoId: string
+ resolutions: number[]
+ transcoded: boolean
+ objectStorage: boolean
+}) {
+ const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options
+
+ for (const server of servers) {
+ const { data } = await server.videos.list()
+ expect(data.find(v => v.uuid === liveVideoId)).to.exist
+
+ const video = await server.videos.get({ id: liveVideoId })
+ expect(video.streamingPlaylists).to.have.lengthOf(1)
+
+ const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
+ expect(hlsPlaylist).to.exist
+ expect(hlsPlaylist.files).to.have.lengthOf(0) // Only fragmented mp4 files are displayed
+
+ await checkResolutionsInMasterPlaylist({
+ server,
+ playlistUrl: hlsPlaylist.playlistUrl,
+ resolutions,
+ transcoded,
+ withRetry: objectStorage
+ })
+
+ if (objectStorage) {
+ expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ }
+
+ for (let i = 0; i < resolutions.length; i++) {
+ const segmentNum = 3
+ const segmentName = `${i}-00000${segmentNum}.ts`
+ await originServer.live.waitUntilSegmentGeneration({
+ server: originServer,
+ videoUUID: video.uuid,
+ playlistNumber: i,
+ segment: segmentNum,
+ objectStorage
+ })
+
+ const baseUrl = objectStorage
+ ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+ : originServer.url + '/static/streaming-playlists/hls'
+
+ if (objectStorage) {
+ expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ }
+
+ const subPlaylist = await originServer.streamingPlaylists.get({
+ url: `${baseUrl}/${video.uuid}/${i}.m3u8`,
+ withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
+ })
+
+ expect(subPlaylist).to.contain(segmentName)
+
+ await checkLiveSegmentHash({
+ server,
+ baseUrlSegment: baseUrl,
+ videoUUID: video.uuid,
+ segmentName,
+ hlsPlaylist
+ })
+ }
+ }
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ checkLiveCleanup,
+ testVideoResolutions
+}
+
+// ---------------------------------------------------------------------------
+
+async function checkSavedLiveCleanup (hlsPath: string, savedResolutions: number[] = []) {