]>
Commit | Line | Data |
---|---|---|
bb4ba6d9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
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 C |
18 | |
19 | const expect = chai.expect | |
20 | ||
668f864f | 21 | describe('Permanent live', function () { |
254d3579 | 22 | let servers: PeerTubeServer[] = [] |
bb4ba6d9 C |
23 | let videoUUID: string |
24 | ||
25 | async function createLiveWrapper (permanentLive: boolean) { | |
26 | const attributes: LiveVideoCreate = { | |
89d241a7 | 27 | channelId: servers[0].store.channel.id, |
bb4ba6d9 C |
28 | privacy: VideoPrivacy.PUBLIC, |
29 | name: 'my super live', | |
30 | saveReplay: false, | |
31 | permanentLive | |
32 | } | |
33 | ||
89d241a7 | 34 | const { uuid } = await servers[0].live.create({ fields: attributes }) |
4f219914 | 35 | return uuid |
bb4ba6d9 C |
36 | } |
37 | ||
38 | async function checkVideoState (videoId: string, state: VideoState) { | |
39 | for (const server of servers) { | |
89d241a7 | 40 | const video = await server.videos.get({ id: videoId }) |
d23dd9fb | 41 | expect(video.state.id).to.equal(state) |
bb4ba6d9 C |
42 | } |
43 | } | |
44 | ||
45 | before(async function () { | |
46 | this.timeout(120000) | |
47 | ||
254d3579 | 48 | servers = await createMultipleServers(2) |
bb4ba6d9 C |
49 | |
50 | // Get the access tokens | |
51 | await setAccessTokensToServers(servers) | |
52 | await setDefaultVideoChannel(servers) | |
53 | ||
54 | // Server 1 and server 2 follow each other | |
55 | await doubleFollow(servers[0], servers[1]) | |
56 | ||
89d241a7 | 57 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
58 | newConfig: { |
59 | live: { | |
bb4ba6d9 | 60 | enabled: true, |
65e6e260 C |
61 | allowReplay: true, |
62 | maxDuration: -1, | |
63 | transcoding: { | |
64 | enabled: true, | |
65 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
66 | } | |
bb4ba6d9 C |
67 | } |
68 | } | |
69 | }) | |
70 | }) | |
71 | ||
72 | it('Should create a non permanent live and update it to be a permanent live', async function () { | |
73 | this.timeout(20000) | |
74 | ||
75 | const videoUUID = await createLiveWrapper(false) | |
76 | ||
77 | { | |
89d241a7 | 78 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 79 | expect(live.permanentLive).to.be.false |
bb4ba6d9 C |
80 | } |
81 | ||
89d241a7 | 82 | await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } }) |
bb4ba6d9 C |
83 | |
84 | { | |
89d241a7 | 85 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 86 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
87 | } |
88 | }) | |
89 | ||
90 | it('Should create a permanent live', async function () { | |
91 | this.timeout(20000) | |
92 | ||
93 | videoUUID = await createLiveWrapper(true) | |
94 | ||
89d241a7 | 95 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 96 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
97 | |
98 | await waitJobs(servers) | |
99 | }) | |
100 | ||
101 | it('Should stream into this permanent live', async function () { | |
17b064e3 | 102 | this.timeout(120000) |
bb4ba6d9 | 103 | |
7137377d | 104 | const beforePublication = new Date() |
89d241a7 | 105 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
bb4ba6d9 C |
106 | |
107 | for (const server of servers) { | |
89d241a7 | 108 | await server.live.waitUntilPublished({ videoId: videoUUID }) |
bb4ba6d9 C |
109 | } |
110 | ||
111 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
112 | ||
7137377d C |
113 | for (const server of servers) { |
114 | const video = await server.videos.get({ id: videoUUID }) | |
115 | expect(new Date(video.publishedAt)).greaterThan(beforePublication) | |
116 | } | |
117 | ||
4f219914 | 118 | await stopFfmpeg(ffmpegCommand) |
89d241a7 | 119 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) |
bb4ba6d9 C |
120 | |
121 | await waitJobs(servers) | |
122 | }) | |
123 | ||
4ec52d04 | 124 | it('Should have cleaned up this live', async function () { |
bb4ba6d9 C |
125 | this.timeout(40000) |
126 | ||
127 | await wait(5000) | |
128 | await waitJobs(servers) | |
129 | ||
130 | for (const server of servers) { | |
89d241a7 | 131 | const videoDetails = await server.videos.get({ id: videoUUID }) |
4ec52d04 C |
132 | |
133 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) | |
bb4ba6d9 C |
134 | } |
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 | ||
bb4ba6d9 C |
192 | after(async function () { |
193 | await cleanupTests(servers) | |
194 | }) | |
195 | }) |