]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | checkDirectoryIsEmpty, | |
7 | checkSegmentHash, | |
8 | checkTmpIsEmpty, | |
9 | cleanupTests, | |
10 | doubleFollow, | |
11 | flushAndRunMultipleServers, | |
12 | getPlaylist, | |
13 | getVideo, | |
14 | removeVideo, | |
15 | ServerInfo, | |
16 | setAccessTokensToServers, | |
17 | updateVideo, | |
18 | uploadVideo, | |
19 | waitJobs | |
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' | |
24 | import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' | |
25 | ||
26 | const expect = chai.expect | |
27 | ||
28 | async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, resolutions = [ 240, 360, 480, 720 ]) { | |
29 | for (const server of servers) { | |
30 | const res = await getVideo(server.url, videoUUID) | |
31 | const videoDetails: VideoDetails = res.body | |
32 | ||
33 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
34 | ||
35 | const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
36 | expect(hlsPlaylist).to.not.be.undefined | |
37 | ||
38 | { | |
39 | const res2 = await getPlaylist(hlsPlaylist.playlistUrl) | |
40 | ||
41 | const masterPlaylist = res2.text | |
42 | ||
43 | for (const resolution of resolutions) { | |
44 | expect(masterPlaylist).to.match(new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+')) | |
45 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) | |
46 | } | |
47 | } | |
48 | ||
49 | { | |
50 | for (const resolution of resolutions) { | |
51 | const res2 = await getPlaylist(`http://localhost:${servers[0].port}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) | |
52 | ||
53 | const subPlaylist = res2.text | |
54 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) | |
55 | } | |
56 | } | |
57 | ||
58 | { | |
59 | const baseUrl = 'http://localhost:' + servers[0].port + '/static/streaming-playlists/hls' | |
60 | ||
61 | for (const resolution of resolutions) { | |
62 | await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist) | |
63 | } | |
64 | } | |
65 | } | |
66 | } | |
67 | ||
68 | describe('Test HLS videos', function () { | |
69 | let servers: ServerInfo[] = [] | |
70 | let videoUUID = '' | |
71 | let videoAudioUUID = '' | |
72 | ||
73 | before(async function () { | |
74 | this.timeout(120000) | |
75 | ||
76 | const configOverride = { | |
77 | transcoding: { | |
78 | enabled: true, | |
79 | allow_audio_files: true, | |
80 | hls: { | |
81 | enabled: true | |
82 | } | |
83 | } | |
84 | } | |
85 | servers = await flushAndRunMultipleServers(2, configOverride) | |
86 | ||
87 | // Get the access tokens | |
88 | await setAccessTokensToServers(servers) | |
89 | ||
90 | // Server 1 and server 2 follow each other | |
91 | await doubleFollow(servers[0], servers[1]) | |
92 | }) | |
93 | ||
94 | it('Should upload a video and transcode it to HLS', async function () { | |
95 | this.timeout(120000) | |
96 | ||
97 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) | |
98 | videoUUID = res.body.video.uuid | |
99 | ||
100 | await waitJobs(servers) | |
101 | ||
102 | await checkHlsPlaylist(servers, videoUUID) | |
103 | }) | |
104 | ||
105 | it('Should upload an audio file and transcode it to HLS', async function () { | |
106 | this.timeout(120000) | |
107 | ||
108 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) | |
109 | videoAudioUUID = res.body.video.uuid | |
110 | ||
111 | await waitJobs(servers) | |
112 | ||
113 | await checkHlsPlaylist(servers, videoAudioUUID, [ DEFAULT_AUDIO_RESOLUTION ]) | |
114 | }) | |
115 | ||
116 | it('Should update the video', async function () { | |
117 | this.timeout(10000) | |
118 | ||
119 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) | |
120 | ||
121 | await waitJobs(servers) | |
122 | ||
123 | await checkHlsPlaylist(servers, videoUUID) | |
124 | }) | |
125 | ||
126 | it('Should delete videos', async function () { | |
127 | this.timeout(10000) | |
128 | ||
129 | await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) | |
130 | await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) | |
131 | ||
132 | await waitJobs(servers) | |
133 | ||
134 | for (const server of servers) { | |
135 | await getVideo(server.url, videoUUID, 404) | |
136 | await getVideo(server.url, videoAudioUUID, 404) | |
137 | } | |
138 | }) | |
139 | ||
140 | it('Should have the playlists/segment deleted from the disk', async function () { | |
141 | for (const server of servers) { | |
142 | await checkDirectoryIsEmpty(server, 'videos') | |
143 | await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls')) | |
144 | } | |
145 | }) | |
146 | ||
147 | it('Should have an empty tmp directory', async function () { | |
148 | for (const server of servers) { | |
149 | await checkTmpIsEmpty(server) | |
150 | } | |
151 | }) | |
152 | ||
153 | after(async function () { | |
154 | await cleanupTests(servers) | |
155 | }) | |
156 | }) |