1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 checkTmpIsEmpty, cleanupTests,
10 flushAndRunMultipleServers,
17 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils'
22 import { VideoDetails } from '../../../../shared/models/videos'
23 import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
24 import { join } from 'path'
26 const expect = chai.expect
28 async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) {
29 const resolutions = [ 240, 360, 480, 720 ]
31 for (const server of servers) {
32 const res = await getVideo(server.url, videoUUID)
33 const videoDetails: VideoDetails = res.body
35 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
37 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
38 expect(hlsPlaylist).to.not.be.undefined
41 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
43 const masterPlaylist = res2.text
45 expect(masterPlaylist).to.contain('#EXT-X-STREAM-INF:BANDWIDTH=55472,RESOLUTION=640x360,FRAME-RATE=25')
47 for (const resolution of resolutions) {
48 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
53 for (const resolution of resolutions) {
54 const res2 = await getPlaylist(`http://localhost:9001/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
56 const subPlaylist = res2.text
57 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
62 const baseUrl = 'http://localhost:9001/static/streaming-playlists/hls'
64 for (const resolution of resolutions) {
65 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
71 describe('Test HLS videos', function () {
72 let servers: ServerInfo[] = []
75 before(async function () {
78 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true, hls: { enabled: true } } })
80 // Get the access tokens
81 await setAccessTokensToServers(servers)
83 // Server 1 and server 2 follow each other
84 await doubleFollow(servers[0], servers[1])
87 it('Should upload a video and transcode it to HLS', async function () {
91 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
92 videoUUID = res.body.video.uuid
95 await waitJobs(servers)
97 await checkHlsPlaylist(servers, videoUUID)
100 it('Should update the video', async function () {
101 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
103 await waitJobs(servers)
105 await checkHlsPlaylist(servers, videoUUID)
108 it('Should delete the video', async function () {
109 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
111 await waitJobs(servers)
113 for (const server of servers) {
114 await getVideo(server.url, videoUUID, 404)
118 it('Should have the playlists/segment deleted from the disk', async function () {
119 for (const server of servers) {
120 await checkDirectoryIsEmpty(server, 'videos')
121 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
125 it('Should have an empty tmp directory', async function () {
126 for (const server of servers) {
127 await checkTmpIsEmpty(server)
131 after(async function () {
132 await cleanupTests(servers)