1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { LiveVideo, LiveVideoCreate, User, VideoDetails, VideoPrivacy } from '@shared/models'
12 flushAndRunMultipleServers,
21 setAccessTokensToServers,
22 setDefaultVideoChannel,
23 testFfmpegStreamError,
25 updateCustomSubConfig,
29 } from '../../../../shared/extra-utils'
31 const expect = chai.expect
33 describe('Test live', function () {
34 let servers: ServerInfo[] = []
36 let userAccessToken: string
37 let userChannelId: number
39 before(async function () {
42 servers = await flushAndRunMultipleServers(2)
44 // Get the access tokens
45 await setAccessTokensToServers(servers)
46 await setDefaultVideoChannel(servers)
48 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
59 const user = { username: 'user1', password: 'superpassword' }
60 const res = await createUser({
62 accessToken: servers[0].accessToken,
63 username: user.username,
64 password: user.password
66 userId = res.body.user.id
68 userAccessToken = await userLogin(servers[0], user)
70 const resMe = await getMyUserInformation(servers[0].url, userAccessToken)
71 userChannelId = (resMe.body as User).videoChannels[0].id
74 // Server 1 and server 2 follow each other
75 await doubleFollow(servers[0], servers[1])
78 describe('Live creation, update and delete', function () {
79 let liveVideoUUID: string
81 it('Should create a live with the appropriate parameters', async function () {
84 const attributes: LiveVideoCreate = {
88 description: 'super live description',
89 support: 'support field',
90 channelId: servers[0].videoChannel.id,
92 waitTranscoding: false,
93 name: 'my super live',
94 tags: [ 'tag1', 'tag2' ],
95 commentsEnabled: false,
96 downloadEnabled: false,
98 privacy: VideoPrivacy.PUBLIC,
99 previewfile: 'video_short1-preview.webm.jpg',
100 thumbnailfile: 'video_short1.webm.jpg'
103 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
104 liveVideoUUID = res.body.video.uuid
106 await waitJobs(servers)
108 for (const server of servers) {
109 const resVideo = await getVideo(server.url, liveVideoUUID)
110 const video: VideoDetails = resVideo.body
112 expect(video.category.id).to.equal(1)
113 expect(video.licence.id).to.equal(2)
114 expect(video.language.id).to.equal('fr')
115 expect(video.description).to.equal('super live description')
116 expect(video.support).to.equal('support field')
118 expect(video.channel.name).to.equal(servers[0].videoChannel.name)
119 expect(video.channel.host).to.equal(servers[0].videoChannel.host)
121 expect(video.nsfw).to.be.false
122 expect(video.waitTranscoding).to.be.false
123 expect(video.name).to.equal('my super live')
124 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
125 expect(video.commentsEnabled).to.be.false
126 expect(video.downloadEnabled).to.be.false
127 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
129 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
130 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
132 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID)
133 const live: LiveVideo = resLive.body
135 if (server.url === servers[0].url) {
136 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
137 expect(live.streamKey).to.not.be.empty
139 expect(live.rtmpUrl).to.be.null
140 expect(live.streamKey).to.be.null
143 expect(live.saveReplay).to.be.true
147 it('Should have a default preview and thumbnail', async function () {
150 const attributes: LiveVideoCreate = {
151 name: 'default live thumbnail',
152 channelId: servers[0].videoChannel.id,
153 privacy: VideoPrivacy.UNLISTED,
157 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
158 const videoId = res.body.video.uuid
160 await waitJobs(servers)
162 for (const server of servers) {
163 const resVideo = await getVideo(server.url, videoId)
164 const video: VideoDetails = resVideo.body
166 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
167 expect(video.nsfw).to.be.true
169 await makeRawRequest(server.url + video.thumbnailPath, 200)
170 await makeRawRequest(server.url + video.previewPath, 200)
174 it('Should not have the live listed since nobody streams into', async function () {
175 for (const server of servers) {
176 const res = await getVideosList(server.url)
178 expect(res.body.total).to.equal(0)
179 expect(res.body.data).to.have.lengthOf(0)
183 it('Should not be able to update a live of another server', async function () {
184 await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, 403)
187 it('Should update the live', async function () {
190 await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false })
191 await waitJobs(servers)
194 it('Have the live updated', async function () {
195 for (const server of servers) {
196 const res = await getLive(server.url, server.accessToken, liveVideoUUID)
197 const live: LiveVideo = res.body
199 if (server.url === servers[0].url) {
200 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
201 expect(live.streamKey).to.not.be.empty
203 expect(live.rtmpUrl).to.be.null
204 expect(live.streamKey).to.be.null
207 expect(live.saveReplay).to.be.false
211 it('Delete the live', async function () {
214 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
215 await waitJobs(servers)
218 it('Should have the live deleted', async function () {
219 for (const server of servers) {
220 await getVideo(server.url, liveVideoUUID, 404)
221 await getLive(server.url, server.accessToken, liveVideoUUID, 404)
226 describe('Stream checks', function () {
227 let liveVideo: LiveVideo & VideoDetails
231 rtmpUrl = 'rtmp://' + servers[0].hostname + ':1936'
234 async function createLiveWrapper () {
235 const liveAttributes = {
237 channelId: userChannelId,
238 privacy: VideoPrivacy.PUBLIC,
242 const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
243 const uuid = res.body.video.uuid
245 const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid)
246 const resVideo = await getVideo(servers[0].url, uuid)
248 return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails
251 it('Should not allow a stream without the appropriate path', async function () {
254 liveVideo = await createLiveWrapper()
256 const command = sendRTMPStream(rtmpUrl + '/bad-live', liveVideo.streamKey)
257 await testFfmpegStreamError(command, true)
260 it('Should not allow a stream without the appropriate stream key', async function () {
263 const command = sendRTMPStream(rtmpUrl + '/live', 'bad-stream-key')
264 await testFfmpegStreamError(command, true)
267 it('Should succeed with the correct params', async function () {
270 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
271 await testFfmpegStreamError(command, false)
274 it('Should not allow a stream on a live that was blacklisted', async function () {
277 liveVideo = await createLiveWrapper()
279 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid)
281 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
282 await testFfmpegStreamError(command, true)
285 it('Should not allow a stream on a live that was deleted', async function () {
288 liveVideo = await createLiveWrapper()
290 await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid)
292 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
293 await testFfmpegStreamError(command, true)
297 describe('Live transcoding', function () {
299 it('Should enable transcoding without additional resolutions', async function () {
302 // wait federation + test
306 it('Should enable transcoding with some resolutions', async function () {
309 // wait federation + test
312 it('Should enable transcoding with some resolutions and correctly save them', async function () {
316 // wait federation + test
319 it('Should correctly have cleaned up the live files', async function () {
324 describe('Live socket messages', function () {
326 it('Should correctly send a message when the live starts', async function () {
331 it('Should correctly send a message when the live ends', async function () {
337 after(async function () {
338 await cleanupTests(servers)