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