]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { checkLiveCleanup } from '@server/tests/shared' | |
5 | import { wait } from '@shared/core-utils' | |
6 | import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | ConfigCommand, | |
10 | createMultipleServers, | |
11 | doubleFollow, | |
12 | PeerTubeServer, | |
13 | setAccessTokensToServers, | |
14 | setDefaultVideoChannel, | |
15 | stopFfmpeg, | |
16 | waitJobs | |
17 | } from '@shared/server-commands' | |
18 | ||
19 | describe('Permanent live', function () { | |
20 | let servers: PeerTubeServer[] = [] | |
21 | let videoUUID: string | |
22 | ||
23 | async function createLiveWrapper (permanentLive: boolean) { | |
24 | const attributes: LiveVideoCreate = { | |
25 | channelId: servers[0].store.channel.id, | |
26 | privacy: VideoPrivacy.PUBLIC, | |
27 | name: 'my super live', | |
28 | saveReplay: false, | |
29 | permanentLive | |
30 | } | |
31 | ||
32 | const { uuid } = await servers[0].live.create({ fields: attributes }) | |
33 | return uuid | |
34 | } | |
35 | ||
36 | async function checkVideoState (videoId: string, state: VideoState) { | |
37 | for (const server of servers) { | |
38 | const video = await server.videos.get({ id: videoId }) | |
39 | expect(video.state.id).to.equal(state) | |
40 | } | |
41 | } | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(120000) | |
45 | ||
46 | servers = await createMultipleServers(2) | |
47 | ||
48 | // Get the access tokens | |
49 | await setAccessTokensToServers(servers) | |
50 | await setDefaultVideoChannel(servers) | |
51 | ||
52 | // Server 1 and server 2 follow each other | |
53 | await doubleFollow(servers[0], servers[1]) | |
54 | ||
55 | await servers[0].config.updateCustomSubConfig({ | |
56 | newConfig: { | |
57 | live: { | |
58 | enabled: true, | |
59 | allowReplay: true, | |
60 | maxDuration: -1, | |
61 | transcoding: { | |
62 | enabled: true, | |
63 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
64 | } | |
65 | } | |
66 | } | |
67 | }) | |
68 | }) | |
69 | ||
70 | it('Should create a non permanent live and update it to be a permanent live', async function () { | |
71 | this.timeout(20000) | |
72 | ||
73 | const videoUUID = await createLiveWrapper(false) | |
74 | ||
75 | { | |
76 | const live = await servers[0].live.get({ videoId: videoUUID }) | |
77 | expect(live.permanentLive).to.be.false | |
78 | } | |
79 | ||
80 | await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } }) | |
81 | ||
82 | { | |
83 | const live = await servers[0].live.get({ videoId: videoUUID }) | |
84 | expect(live.permanentLive).to.be.true | |
85 | } | |
86 | }) | |
87 | ||
88 | it('Should create a permanent live', async function () { | |
89 | this.timeout(20000) | |
90 | ||
91 | videoUUID = await createLiveWrapper(true) | |
92 | ||
93 | const live = await servers[0].live.get({ videoId: videoUUID }) | |
94 | expect(live.permanentLive).to.be.true | |
95 | ||
96 | await waitJobs(servers) | |
97 | }) | |
98 | ||
99 | it('Should stream into this permanent live', async function () { | |
100 | this.timeout(240_000) | |
101 | ||
102 | const beforePublication = new Date() | |
103 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) | |
104 | ||
105 | for (const server of servers) { | |
106 | await server.live.waitUntilPublished({ videoId: videoUUID }) | |
107 | } | |
108 | ||
109 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
110 | ||
111 | for (const server of servers) { | |
112 | const video = await server.videos.get({ id: videoUUID }) | |
113 | expect(new Date(video.publishedAt)).greaterThan(beforePublication) | |
114 | } | |
115 | ||
116 | await stopFfmpeg(ffmpegCommand) | |
117 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) | |
118 | ||
119 | await waitJobs(servers) | |
120 | }) | |
121 | ||
122 | it('Should have cleaned up this live', async function () { | |
123 | this.timeout(40000) | |
124 | ||
125 | await wait(5000) | |
126 | await waitJobs(servers) | |
127 | ||
128 | for (const server of servers) { | |
129 | const videoDetails = await server.videos.get({ id: videoUUID }) | |
130 | ||
131 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) | |
132 | } | |
133 | ||
134 | await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID }) | |
135 | }) | |
136 | ||
137 | it('Should have set this live to waiting for live state', async function () { | |
138 | this.timeout(20000) | |
139 | ||
140 | await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE) | |
141 | }) | |
142 | ||
143 | it('Should be able to stream again in the permanent live', async function () { | |
144 | this.timeout(60000) | |
145 | ||
146 | await servers[0].config.updateCustomSubConfig({ | |
147 | newConfig: { | |
148 | live: { | |
149 | enabled: true, | |
150 | allowReplay: true, | |
151 | maxDuration: -1, | |
152 | transcoding: { | |
153 | enabled: true, | |
154 | resolutions: ConfigCommand.getCustomConfigResolutions(false) | |
155 | } | |
156 | } | |
157 | } | |
158 | }) | |
159 | ||
160 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) | |
161 | ||
162 | for (const server of servers) { | |
163 | await server.live.waitUntilPublished({ videoId: videoUUID }) | |
164 | } | |
165 | ||
166 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
167 | ||
168 | const count = await servers[0].live.countPlaylists({ videoUUID }) | |
169 | // master playlist and 720p playlist | |
170 | expect(count).to.equal(2) | |
171 | ||
172 | await stopFfmpeg(ffmpegCommand) | |
173 | }) | |
174 | ||
175 | it('Should have appropriate sessions', async function () { | |
176 | this.timeout(60000) | |
177 | ||
178 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) | |
179 | ||
180 | const { data, total } = await servers[0].live.listSessions({ videoId: videoUUID }) | |
181 | expect(total).to.equal(2) | |
182 | expect(data).to.have.lengthOf(2) | |
183 | ||
184 | for (const session of data) { | |
185 | expect(session.startDate).to.exist | |
186 | expect(session.endDate).to.exist | |
187 | ||
188 | expect(session.error).to.not.exist | |
189 | } | |
190 | }) | |
191 | ||
192 | it('Should remove the live and have cleaned up the directory', async function () { | |
193 | this.timeout(60000) | |
194 | ||
195 | await servers[0].videos.remove({ id: videoUUID }) | |
196 | await waitJobs(servers) | |
197 | ||
198 | await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID }) | |
199 | }) | |
200 | ||
201 | after(async function () { | |
202 | await cleanupTests(servers) | |
203 | }) | |
204 | }) |