1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
11 flushAndRunMultipleServers,
16 setAccessTokensToServers,
20 } from '../../../../shared/extra-utils'
21 import { VideoDetails } from '../../../../shared/models/videos'
22 import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
23 import { join } from 'path'
25 const expect = chai.expect
27 async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) {
28 const resolutions = [ 240, 360, 480, 720 ]
30 for (const server of servers) {
31 const res = await getVideo(server.url, videoUUID)
32 const videoDetails: VideoDetails = res.body
34 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
36 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
37 expect(hlsPlaylist).to.not.be.undefined
40 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
42 const masterPlaylist = res2.text
44 expect(masterPlaylist).to.contain('#EXT-X-STREAM-INF:BANDWIDTH=55472,RESOLUTION=640x360,FRAME-RATE=25')
46 for (const resolution of resolutions) {
47 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
52 for (const resolution of resolutions) {
53 const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
55 const subPlaylist = res2.text
56 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
61 const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls'
63 for (const resolution of resolutions) {
64 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
70 describe('Test HLS videos', function () {
71 let servers: ServerInfo[] = []
74 before(async function () {
77 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true, hls: { enabled: true } } })
79 // Get the access tokens
80 await setAccessTokensToServers(servers)
82 // Server 1 and server 2 follow each other
83 await doubleFollow(servers[0], servers[1])
86 it('Should upload a video and transcode it to HLS', async function () {
90 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
91 videoUUID = res.body.video.uuid
94 await waitJobs(servers)
96 await checkHlsPlaylist(servers, videoUUID)
99 it('Should update the video', async function () {
100 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
102 await waitJobs(servers)
104 await checkHlsPlaylist(servers, videoUUID)
107 it('Should delete the video', async function () {
108 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
110 await waitJobs(servers)
112 for (const server of servers) {
113 await getVideo(server.url, videoUUID, 404)
117 it('Should have the playlists/segment deleted from the disk', async function () {
118 for (const server of servers) {
119 await checkDirectoryIsEmpty(server, 'videos')
120 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
124 it('Should have an empty tmp directory', async function () {
125 for (const server of servers) {
126 await checkTmpIsEmpty(server)
130 after(async function () {
131 await cleanupTests(servers)