]>
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 { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | |
6 | import { | |
7 | cleanupTests, | |
8 | ConfigCommand, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | getVideo, | |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
14 | setDefaultVideoChannel, | |
15 | stopFfmpeg, | |
16 | wait, | |
17 | waitJobs | |
18 | } from '../../../../shared/extra-utils' | |
19 | ||
20 | const expect = chai.expect | |
21 | ||
22 | describe('Permanent live', function () { | |
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 | ||
35 | const { uuid } = await servers[0].liveCommand.create({ fields: attributes }) | |
36 | return uuid | |
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 | ||
58 | await servers[0].configCommand.updateCustomSubConfig({ | |
59 | newConfig: { | |
60 | live: { | |
61 | enabled: true, | |
62 | allowReplay: true, | |
63 | maxDuration: -1, | |
64 | transcoding: { | |
65 | enabled: true, | |
66 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | |
67 | } | |
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 | { | |
79 | const live = await servers[0].liveCommand.get({ videoId: videoUUID }) | |
80 | expect(live.permanentLive).to.be.false | |
81 | } | |
82 | ||
83 | await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } }) | |
84 | ||
85 | { | |
86 | const live = await servers[0].liveCommand.get({ videoId: videoUUID }) | |
87 | expect(live.permanentLive).to.be.true | |
88 | } | |
89 | }) | |
90 | ||
91 | it('Should create a permanent live', async function () { | |
92 | this.timeout(20000) | |
93 | ||
94 | videoUUID = await createLiveWrapper(true) | |
95 | ||
96 | const live = await servers[0].liveCommand.get({ videoId: videoUUID }) | |
97 | expect(live.permanentLive).to.be.true | |
98 | ||
99 | await waitJobs(servers) | |
100 | }) | |
101 | ||
102 | it('Should stream into this permanent live', async function () { | |
103 | this.timeout(120000) | |
104 | ||
105 | const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) | |
106 | ||
107 | for (const server of servers) { | |
108 | await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) | |
109 | } | |
110 | ||
111 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
112 | ||
113 | await stopFfmpeg(ffmpegCommand) | |
114 | await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID }) | |
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 | ||
142 | await servers[0].configCommand.updateCustomSubConfig({ | |
143 | newConfig: { | |
144 | live: { | |
145 | enabled: true, | |
146 | allowReplay: true, | |
147 | maxDuration: -1, | |
148 | transcoding: { | |
149 | enabled: true, | |
150 | resolutions: ConfigCommand.getCustomConfigResolutions(false) | |
151 | } | |
152 | } | |
153 | } | |
154 | }) | |
155 | ||
156 | const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) | |
157 | ||
158 | for (const server of servers) { | |
159 | await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) | |
160 | } | |
161 | ||
162 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
163 | ||
164 | const count = await servers[0].liveCommand.countPlaylists({ videoUUID }) | |
165 | // master playlist and 720p playlist | |
166 | expect(count).to.equal(2) | |
167 | ||
168 | await stopFfmpeg(ffmpegCommand) | |
169 | }) | |
170 | ||
171 | after(async function () { | |
172 | await cleanupTests(servers) | |
173 | }) | |
174 | }) |