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