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