]>
Commit | Line | Data |
---|---|---|
bb4ba6d9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
c55e3d72 | 4 | import { wait } from '@shared/core-utils' |
d23dd9fb | 5 | import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' |
bb4ba6d9 | 6 | import { |
bb4ba6d9 | 7 | cleanupTests, |
65e6e260 | 8 | ConfigCommand, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
bb4ba6d9 C |
12 | setAccessTokensToServers, |
13 | setDefaultVideoChannel, | |
14 | stopFfmpeg, | |
4f219914 | 15 | waitJobs |
c55e3d72 | 16 | } from '@shared/server-commands' |
bb4ba6d9 | 17 | |
668f864f | 18 | describe('Permanent live', function () { |
254d3579 | 19 | let servers: PeerTubeServer[] = [] |
bb4ba6d9 C |
20 | let videoUUID: string |
21 | ||
22 | async function createLiveWrapper (permanentLive: boolean) { | |
23 | const attributes: LiveVideoCreate = { | |
89d241a7 | 24 | channelId: servers[0].store.channel.id, |
bb4ba6d9 C |
25 | privacy: VideoPrivacy.PUBLIC, |
26 | name: 'my super live', | |
27 | saveReplay: false, | |
28 | permanentLive | |
29 | } | |
30 | ||
89d241a7 | 31 | const { uuid } = await servers[0].live.create({ fields: attributes }) |
4f219914 | 32 | return uuid |
bb4ba6d9 C |
33 | } |
34 | ||
35 | async function checkVideoState (videoId: string, state: VideoState) { | |
36 | for (const server of servers) { | |
89d241a7 | 37 | const video = await server.videos.get({ id: videoId }) |
d23dd9fb | 38 | expect(video.state.id).to.equal(state) |
bb4ba6d9 C |
39 | } |
40 | } | |
41 | ||
42 | before(async function () { | |
43 | this.timeout(120000) | |
44 | ||
254d3579 | 45 | servers = await createMultipleServers(2) |
bb4ba6d9 C |
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 | ||
89d241a7 | 54 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
55 | newConfig: { |
56 | live: { | |
bb4ba6d9 | 57 | enabled: true, |
65e6e260 C |
58 | allowReplay: true, |
59 | maxDuration: -1, | |
60 | transcoding: { | |
61 | enabled: true, | |
62 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
63 | } | |
bb4ba6d9 C |
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 | { | |
89d241a7 | 75 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 76 | expect(live.permanentLive).to.be.false |
bb4ba6d9 C |
77 | } |
78 | ||
89d241a7 | 79 | await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } }) |
bb4ba6d9 C |
80 | |
81 | { | |
89d241a7 | 82 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 83 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
84 | } |
85 | }) | |
86 | ||
87 | it('Should create a permanent live', async function () { | |
88 | this.timeout(20000) | |
89 | ||
90 | videoUUID = await createLiveWrapper(true) | |
91 | ||
89d241a7 | 92 | const live = await servers[0].live.get({ videoId: videoUUID }) |
4f219914 | 93 | expect(live.permanentLive).to.be.true |
bb4ba6d9 C |
94 | |
95 | await waitJobs(servers) | |
96 | }) | |
97 | ||
98 | it('Should stream into this permanent live', async function () { | |
7804e577 | 99 | this.timeout(240_000) |
bb4ba6d9 | 100 | |
7137377d | 101 | const beforePublication = new Date() |
89d241a7 | 102 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
bb4ba6d9 C |
103 | |
104 | for (const server of servers) { | |
89d241a7 | 105 | await server.live.waitUntilPublished({ videoId: videoUUID }) |
bb4ba6d9 C |
106 | } |
107 | ||
108 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
109 | ||
7137377d C |
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 | ||
4f219914 | 115 | await stopFfmpeg(ffmpegCommand) |
89d241a7 | 116 | await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) |
bb4ba6d9 C |
117 | |
118 | await waitJobs(servers) | |
119 | }) | |
120 | ||
4ec52d04 | 121 | it('Should have cleaned up this live', async function () { |
bb4ba6d9 C |
122 | this.timeout(40000) |
123 | ||
124 | await wait(5000) | |
125 | await waitJobs(servers) | |
126 | ||
127 | for (const server of servers) { | |
89d241a7 | 128 | const videoDetails = await server.videos.get({ id: videoUUID }) |
4ec52d04 C |
129 | |
130 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) | |
bb4ba6d9 C |
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 () { | |
656ed49f | 141 | this.timeout(60000) |
bb4ba6d9 | 142 | |
89d241a7 | 143 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
144 | newConfig: { |
145 | live: { | |
bb4ba6d9 | 146 | enabled: true, |
65e6e260 C |
147 | allowReplay: true, |
148 | maxDuration: -1, | |
149 | transcoding: { | |
150 | enabled: true, | |
151 | resolutions: ConfigCommand.getCustomConfigResolutions(false) | |
152 | } | |
bb4ba6d9 C |
153 | } |
154 | } | |
155 | }) | |
156 | ||
89d241a7 | 157 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) |
bb4ba6d9 C |
158 | |
159 | for (const server of servers) { | |
89d241a7 | 160 | await server.live.waitUntilPublished({ videoId: videoUUID }) |
bb4ba6d9 C |
161 | } |
162 | ||
163 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
164 | ||
89d241a7 | 165 | const count = await servers[0].live.countPlaylists({ videoUUID }) |
bb4ba6d9 C |
166 | // master playlist and 720p playlist |
167 | expect(count).to.equal(2) | |
168 | ||
4f219914 | 169 | await stopFfmpeg(ffmpegCommand) |
bb4ba6d9 C |
170 | }) |
171 | ||
26e3e98f C |
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 | ||
bb4ba6d9 C |
189 | after(async function () { |
190 | await cleanupTests(servers) | |
191 | }) | |
192 | }) |