]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/live/live-permanent.ts
Merge branch 'develop' into release/3.0.0
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-permanent.ts
CommitLineData
bb4ba6d9
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
6import {
bb4ba6d9
C
7 cleanupTests,
8 createLive,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getLive,
12 getPlaylistsCount,
13 getVideo,
14 sendRTMPStreamInVideo,
15 ServerInfo,
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
18 stopFfmpeg,
19 updateCustomSubConfig,
20 updateLive,
21 wait,
22 waitJobs,
59fd824c
C
23 waitUntilLivePublished,
24 waitUntilLiveWaiting
bb4ba6d9
C
25} from '../../../../shared/extra-utils'
26
27const expect = chai.expect
28
29describe('Permenant live', function () {
30 let servers: ServerInfo[] = []
31 let videoUUID: string
32
33 async function createLiveWrapper (permanentLive: boolean) {
34 const attributes: LiveVideoCreate = {
35 channelId: servers[0].videoChannel.id,
36 privacy: VideoPrivacy.PUBLIC,
37 name: 'my super live',
38 saveReplay: false,
39 permanentLive
40 }
41
42 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
43 return res.body.video.uuid
44 }
45
46 async function checkVideoState (videoId: string, state: VideoState) {
47 for (const server of servers) {
48 const res = await getVideo(server.url, videoId)
49 expect((res.body as VideoDetails).state.id).to.equal(state)
50 }
51 }
52
53 before(async function () {
54 this.timeout(120000)
55
56 servers = await flushAndRunMultipleServers(2)
57
58 // Get the access tokens
59 await setAccessTokensToServers(servers)
60 await setDefaultVideoChannel(servers)
61
62 // Server 1 and server 2 follow each other
63 await doubleFollow(servers[0], servers[1])
64
65 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
66 live: {
67 enabled: true,
68 allowReplay: true,
c9bc850e 69 maxDuration: -1,
bb4ba6d9
C
70 transcoding: {
71 enabled: true,
72 resolutions: {
73 '240p': true,
74 '360p': true,
75 '480p': true,
76 '720p': true,
77 '1080p': true,
78 '2160p': true
79 }
80 }
81 }
82 })
83 })
84
85 it('Should create a non permanent live and update it to be a permanent live', async function () {
86 this.timeout(20000)
87
88 const videoUUID = await createLiveWrapper(false)
89
90 {
91 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
92 expect(res.body.permanentLive).to.be.false
93 }
94
95 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
96
97 {
98 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
99 expect(res.body.permanentLive).to.be.true
100 }
101 })
102
103 it('Should create a permanent live', async function () {
104 this.timeout(20000)
105
106 videoUUID = await createLiveWrapper(true)
107
108 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
109 expect(res.body.permanentLive).to.be.true
110
111 await waitJobs(servers)
112 })
113
114 it('Should stream into this permanent live', async function () {
59fd824c 115 this.timeout(60000)
bb4ba6d9
C
116
117 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
118
119 for (const server of servers) {
0d8de275 120 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
bb4ba6d9
C
121 }
122
123 await checkVideoState(videoUUID, VideoState.PUBLISHED)
124
125 await stopFfmpeg(command)
59fd824c 126 await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
bb4ba6d9
C
127
128 await waitJobs(servers)
129 })
130
131 it('Should not have cleaned up this live', async function () {
132 this.timeout(40000)
133
134 await wait(5000)
135 await waitJobs(servers)
136
137 for (const server of servers) {
138 const res = await getVideo(server.url, videoUUID)
139
140 const videoDetails = res.body as VideoDetails
141 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
142 }
143 })
144
145 it('Should have set this live to waiting for live state', async function () {
146 this.timeout(20000)
147
148 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
149 })
150
151 it('Should be able to stream again in the permanent live', async function () {
152 this.timeout(20000)
153
154 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
155 live: {
156 enabled: true,
157 allowReplay: true,
c9bc850e 158 maxDuration: -1,
bb4ba6d9
C
159 transcoding: {
160 enabled: true,
161 resolutions: {
162 '240p': false,
163 '360p': false,
164 '480p': false,
165 '720p': false,
166 '1080p': false,
167 '2160p': false
168 }
169 }
170 }
171 })
172
173 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
174
175 for (const server of servers) {
0d8de275 176 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
bb4ba6d9
C
177 }
178
179 await checkVideoState(videoUUID, VideoState.PUBLISHED)
180
181 const count = await getPlaylistsCount(servers[0], videoUUID)
182 // master playlist and 720p playlist
183 expect(count).to.equal(2)
184
185 await stopFfmpeg(command)
186 })
187
188 after(async function () {
189 await cleanupTests(servers)
190 })
191})