]>
Commit | Line | Data |
---|---|---|
bb4ba6d9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
aa887096 | 4 | import { checkLiveCleanup } from '@server/tests/shared' |
c55e3d72 | 5 | import { wait } from '@shared/core-utils' |
d23dd9fb | 6 | import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' |
bb4ba6d9 | 7 | import { |
bb4ba6d9 | 8 | cleanupTests, |
65e6e260 | 9 | ConfigCommand, |
254d3579 | 10 | createMultipleServers, |
4c7e60bc | 11 | doubleFollow, |
254d3579 | 12 | PeerTubeServer, |
bb4ba6d9 C |
13 | setAccessTokensToServers, |
14 | setDefaultVideoChannel, | |
15 | stopFfmpeg, | |
4f219914 | 16 | waitJobs |
c55e3d72 | 17 | } from '@shared/server-commands' |
bb4ba6d9 | 18 | |
668f864f | 19 | describe('Permanent live', function () { |
254d3579 | 20 | let servers: PeerTubeServer[] = [] |
bb4ba6d9 C |
21 | let videoUUID: string |
22 | ||
23 | async function createLiveWrapper (permanentLive: boolean) { | |
24 | const attributes: LiveVideoCreate = { | |
89d241a7 | 25 | channelId: servers[0].store.channel.id, |
bb4ba6d9 C |
26 | privacy: VideoPrivacy.PUBLIC, |
27 | name: 'my super live', | |
28 | saveReplay: false, | |
29 | permanentLive | |
30 | } | |
31 | ||
89d241a7 | 32 | const { uuid } = await servers[0].live.create({ fields: attributes }) |
4f219914 | 33 | return uuid |
bb4ba6d9 C |
34 | } |
35 | ||
36 | async function checkVideoState (videoId: string, state: VideoState) { | |
37 | for (const server of servers) { | |
89d241a7 | 38 | const video = await server.videos.get({ id: videoId }) |
d23dd9fb | 39 | expect(video.state.id).to.equal(state) |
bb4ba6d9 C |
40 | } |
41 | } | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(120000) | |
45 | ||
254d3579 | 46 | servers = await createMultipleServers(2) |
bb4ba6d9 C |
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 | ||
89d241a7 | 55 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
56 | newConfig: { |
57 | live: { | |
bb4ba6d9 | 58 | enabled: true, |
65e6e260 C |
59 | allowReplay: true, |
60 | maxDuration: -1, | |
61 | transcoding: { | |
62 | enabled: true, | |
63 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
64 | } | |
bb4ba6d9 C |
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 | { | |
89d241a7 | 76 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 77 | expect(live.permanentLive).to.be.false |
bb4ba6d9 C |
78 | } |
79 | ||
89d241a7 | 80 | await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } }) |
bb4ba6d9 C |
81 | |
82 | { | |
89d241a7 | 83 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 84 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
85 | } |
86 | }) | |
87 | ||
88 | it('Should create a permanent live', async function () { | |
89 | this.timeout(20000) | |
90 | ||
91 | videoUUID = await createLiveWrapper(true) | |
92 | ||
89d241a7 | 93 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 94 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
95 | |
96 | await waitJobs(servers) | |
97 | }) | |
98 | ||
99 | it('Should stream into this permanent live', async function () { | |
7804e577 | 100 | this.timeout(240_000) |
bb4ba6d9 | 101 | |
7137377d | 102 | const beforePublication = new Date() |
89d241a7 | 103 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
bb4ba6d9 C |
104 | |
105 | for (const server of servers) { | |
89d241a7 | 106 | await server.live.waitUntilPublished({ videoId: videoUUID }) |
bb4ba6d9 C |
107 | } |
108 | ||
109 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
110 | ||
7137377d C |
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 | ||
4f219914 | 116 | await stopFfmpeg(ffmpegCommand) |
89d241a7 | 117 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) |
bb4ba6d9 C |
118 | |
119 | await waitJobs(servers) | |
120 | }) | |
121 | ||
4ec52d04 | 122 | it('Should have cleaned up this live', async function () { |
bb4ba6d9 C |
123 | this.timeout(40000) |
124 | ||
125 | await wait(5000) | |
126 | await waitJobs(servers) | |
127 | ||
128 | for (const server of servers) { | |
89d241a7 | 129 | const videoDetails = await server.videos.get({ id: videoUUID }) |
4ec52d04 C |
130 | |
131 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) | |
bb4ba6d9 | 132 | } |
aa887096 C |
133 | |
134 | await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID }) | |
bb4ba6d9 C |
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 () { | |
656ed49f | 144 | this.timeout(60000) |
bb4ba6d9 | 145 | |
89d241a7 | 146 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
147 | newConfig: { |
148 | live: { | |
bb4ba6d9 | 149 | enabled: true, |
65e6e260 C |
150 | allowReplay: true, |
151 | maxDuration: -1, | |
152 | transcoding: { | |
153 | enabled: true, | |
154 | resolutions: ConfigCommand.getCustomConfigResolutions(false) | |
155 | } | |
bb4ba6d9 C |
156 | } |
157 | } | |
158 | }) | |
159 | ||
89d241a7 | 160 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
bb4ba6d9 C |
161 | |
162 | for (const server of servers) { | |
89d241a7 | 163 | await server.live.waitUntilPublished({ videoId: videoUUID }) |
bb4ba6d9 C |
164 | } |
165 | ||
166 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
167 | ||
89d241a7 | 168 | const count = await servers[0].live.countPlaylists({ videoUUID }) |
bb4ba6d9 C |
169 | // master playlist and 720p playlist |
170 | expect(count).to.equal(2) | |
171 | ||
4f219914 | 172 | await stopFfmpeg(ffmpegCommand) |
bb4ba6d9 C |
173 | }) |
174 | ||
26e3e98f C |
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 | ||
aa887096 C |
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 | ||
bb4ba6d9 C |
201 | after(async function () { |
202 | await cleanupTests(servers) | |
203 | }) | |
204 | }) |