]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/live/live-permanent.ts
Introduce config command
[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 7 cleanupTests,
65e6e260 8 ConfigCommand,
bb4ba6d9
C
9 createLive,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getLive,
13 getPlaylistsCount,
14 getVideo,
15 sendRTMPStreamInVideo,
16 ServerInfo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 stopFfmpeg,
bb4ba6d9
C
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
668f864f 29describe('Permanent live', function () {
bb4ba6d9
C
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
65e6e260
C
65 await servers[0].configCommand.updateCustomSubConfig({
66 newConfig: {
67 live: {
bb4ba6d9 68 enabled: true,
65e6e260
C
69 allowReplay: true,
70 maxDuration: -1,
71 transcoding: {
72 enabled: true,
73 resolutions: ConfigCommand.getCustomConfigResolutions(true)
74 }
bb4ba6d9
C
75 }
76 }
77 })
78 })
79
80 it('Should create a non permanent live and update it to be a permanent live', async function () {
81 this.timeout(20000)
82
83 const videoUUID = await createLiveWrapper(false)
84
85 {
86 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
87 expect(res.body.permanentLive).to.be.false
88 }
89
90 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
91
92 {
93 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
94 expect(res.body.permanentLive).to.be.true
95 }
96 })
97
98 it('Should create a permanent live', async function () {
99 this.timeout(20000)
100
101 videoUUID = await createLiveWrapper(true)
102
103 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
104 expect(res.body.permanentLive).to.be.true
105
106 await waitJobs(servers)
107 })
108
109 it('Should stream into this permanent live', async function () {
17b064e3 110 this.timeout(120000)
bb4ba6d9
C
111
112 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
113
114 for (const server of servers) {
0d8de275 115 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
bb4ba6d9
C
116 }
117
118 await checkVideoState(videoUUID, VideoState.PUBLISHED)
119
120 await stopFfmpeg(command)
59fd824c 121 await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
bb4ba6d9
C
122
123 await waitJobs(servers)
124 })
125
126 it('Should not have cleaned up this live', async function () {
127 this.timeout(40000)
128
129 await wait(5000)
130 await waitJobs(servers)
131
132 for (const server of servers) {
133 const res = await getVideo(server.url, videoUUID)
134
135 const videoDetails = res.body as VideoDetails
136 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
137 }
138 })
139
140 it('Should have set this live to waiting for live state', async function () {
141 this.timeout(20000)
142
143 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
144 })
145
146 it('Should be able to stream again in the permanent live', async function () {
147 this.timeout(20000)
148
65e6e260
C
149 await servers[0].configCommand.updateCustomSubConfig({
150 newConfig: {
151 live: {
bb4ba6d9 152 enabled: true,
65e6e260
C
153 allowReplay: true,
154 maxDuration: -1,
155 transcoding: {
156 enabled: true,
157 resolutions: ConfigCommand.getCustomConfigResolutions(false)
158 }
bb4ba6d9
C
159 }
160 }
161 })
162
163 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
164
165 for (const server of servers) {
0d8de275 166 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
bb4ba6d9
C
167 }
168
169 await checkVideoState(videoUUID, VideoState.PUBLISHED)
170
171 const count = await getPlaylistsCount(servers[0], videoUUID)
172 // master playlist and 720p playlist
173 expect(count).to.equal(2)
174
175 await stopFfmpeg(command)
176 })
177
178 after(async function () {
179 await cleanupTests(servers)
180 })
181})