Verified Commit 4f219914 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce live command

parent 2c27e704
......@@ -2,27 +2,24 @@
import 'mocha'
import { omit } from 'lodash'
import { LiveVideo, VideoCreateResult, VideoPrivacy } from '@shared/models'
import { VideoCreateResult, VideoPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
buildAbsoluteFixturePath,
cleanupTests,
createUser,
flushAndRunServer,
getLive,
getMyUserInformation,
immutableAssign,
LiveCommand,
makePostBodyRequest,
makeUploadRequest,
runAndTestFfmpegStreamError,
sendRTMPStream,
ServerInfo,
setAccessTokensToServers,
stopFfmpeg,
updateLive,
uploadVideoAndGetId,
userLogin,
waitUntilLivePublished
userLogin
} from '../../../../shared/extra-utils'
describe('Test video lives API validator', function () {
......@@ -32,6 +29,7 @@ describe('Test video lives API validator', function () {
let channelId: number
let video: VideoCreateResult
let videoIdNotLive: number
let command: LiveCommand
// ---------------------------------------------------------------
......@@ -66,6 +64,8 @@ describe('Test video lives API validator', function () {
{
videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
}
command = server.liveCommand
})
describe('When creating a live', function () {
......@@ -337,70 +337,72 @@ describe('Test video lives API validator', function () {
describe('When getting live information', function () {
it('Should fail without access token', async function () {
await getLive(server.url, '', video.id, HttpStatusCode.UNAUTHORIZED_401)
await command.getLive({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with a bad access token', async function () {
await getLive(server.url, 'toto', video.id, HttpStatusCode.UNAUTHORIZED_401)
await command.getLive({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with access token of another user', async function () {
await getLive(server.url, userAccessToken, video.id, HttpStatusCode.FORBIDDEN_403)
await command.getLive({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should fail with a bad video id', async function () {
await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400)
await command.getLive({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with an unknown video id', async function () {
await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404)
await command.getLive({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should fail with a non live video', async function () {
await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404)
await command.getLive({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should succeed with the correct params', async function () {
await getLive(server.url, server.accessToken, video.id)
await getLive(server.url, server.accessToken, video.shortUUID)
await command.getLive({ videoId: video.id })
await command.getLive({ videoId: video.uuid })
await command.getLive({ videoId: video.shortUUID })
})
})
describe('When updating live information', async function () {
it('Should fail without access token', async function () {
await updateLive(server.url, '', video.id, {}, HttpStatusCode.UNAUTHORIZED_401)
await command.updateLive({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with a bad access token', async function () {
await updateLive(server.url, 'toto', video.id, {}, HttpStatusCode.UNAUTHORIZED_401)
await command.updateLive({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with access token of another user', async function () {
await updateLive(server.url, userAccessToken, video.id, {}, HttpStatusCode.FORBIDDEN_403)
await command.updateLive({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should fail with a bad video id', async function () {
await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400)
await command.updateLive({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with an unknown video id', async function () {
await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404)
await command.updateLive({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should fail with a non live video', async function () {
await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404)
await command.updateLive({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should fail with save replay and permanent live set to true', async function () {
const fields = { saveReplay: true, permanentLive: true }
await updateLive(server.url, server.accessToken, video.id, fields, HttpStatusCode.BAD_REQUEST_400)
await command.updateLive({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should succeed with the correct params', async function () {
await updateLive(server.url, server.accessToken, video.id, { saveReplay: false })
await updateLive(server.url, server.accessToken, video.shortUUID, { saveReplay: false })
await command.updateLive({ videoId: video.id, fields: { saveReplay: false } })
await command.updateLive({ videoId: video.uuid, fields: { saveReplay: false } })
await command.updateLive({ videoId: video.shortUUID, fields: { saveReplay: false } })
})
it('Should fail to update replay status if replay is not allowed on the instance', async function () {
......@@ -413,36 +415,34 @@ describe('Test video lives API validator', function () {
}
})
await updateLive(server.url, server.accessToken, video.id, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403)
await command.updateLive({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should fail to update a live if it has already started', async function () {
this.timeout(40000)
const resLive = await getLive(server.url, server.accessToken, video.id)
const live: LiveVideo = resLive.body
const live = await command.getLive({ videoId: video.id })
const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
await waitUntilLivePublished(server.url, server.accessToken, video.id)
await updateLive(server.url, server.accessToken, video.id, {}, HttpStatusCode.BAD_REQUEST_400)
await command.waitUntilLivePublished({ videoId: video.id })
await command.updateLive({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
await stopFfmpeg(command)
await stopFfmpeg(ffmpegCommand)
})
it('Should fail to stream twice in the save live', async function () {
this.timeout(40000)
const resLive = await getLive(server.url, server.accessToken, video.id)
const live: LiveVideo = resLive.body
const live = await command.getLive({ videoId: video.id })
const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
await waitUntilLivePublished(server.url, server.accessToken, video.id)
await command.waitUntilLivePublished({ videoId: video.id })
await runAndTestFfmpegStreamError(server.url, server.accessToken, video.id, true)
await command.runAndTestFfmpegStreamError({ videoId: video.id, shouldHaveError: true })
await stopFfmpeg(command)
await stopFfmpeg(ffmpegCommand)
})
})
......
......@@ -7,19 +7,16 @@ import {
checkLiveCleanup,
cleanupTests,
ConfigCommand,
createLive,
doubleFollow,
flushAndRunMultipleServers,
generateUser,
getVideo,
runAndTestFfmpegStreamError,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
updateUser,
wait,
waitJobs,
waitUntilLivePublished
waitJobs
} from '../../../../shared/extra-utils'
const expect = chai.expect
......@@ -38,8 +35,8 @@ describe('Test live constraints', function () {
saveReplay
}
const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
return res.body.video.uuid as string
const { uuid } = await servers[0].liveCommand.createLive({ token: userAccessToken, fields: liveAttributes })
return uuid
}
async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
......@@ -56,7 +53,7 @@ describe('Test live constraints', function () {
async function waitUntilLivePublishedOnAllServers (videoId: string) {
for (const server of servers) {
await waitUntilLivePublished(server.url, server.accessToken, videoId)
await server.liveCommand.waitUntilLivePublished({ videoId })
}
}
......@@ -108,7 +105,7 @@ describe('Test live constraints', function () {
this.timeout(60000)
const userVideoLiveoId = await createLiveWrapper(false)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
})
it('Should have size limit depending on user global quota if save replay is enabled', async function () {
......@@ -118,7 +115,7 @@ describe('Test live constraints', function () {
await wait(5000)
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
......@@ -135,7 +132,7 @@ describe('Test live constraints', function () {
await updateQuota({ total: -1, daily: 1 })
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
......@@ -152,7 +149,7 @@ describe('Test live constraints', function () {
await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
})
it('Should have max duration limit', async function () {
......@@ -173,7 +170,7 @@ describe('Test live constraints', function () {
})
const userVideoLiveoId = await createLiveWrapper(true)
await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
......
......@@ -6,22 +6,15 @@ import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared
import {
cleanupTests,
ConfigCommand,
createLive,
doubleFollow,
flushAndRunMultipleServers,
getLive,
getPlaylistsCount,
getVideo,
sendRTMPStreamInVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
updateLive,
wait,
waitJobs,
waitUntilLivePublished,
waitUntilLiveWaiting
waitJobs
} from '../../../../shared/extra-utils'
const expect = chai.expect
......@@ -39,8 +32,8 @@ describe('Permanent live', function () {
permanentLive
}
const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
return res.body.video.uuid
const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes })
return uuid
}
async function checkVideoState (videoId: string, state: VideoState) {
......@@ -83,15 +76,15 @@ describe('Permanent live', function () {
const videoUUID = await createLiveWrapper(false)
{
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.false
const live = await servers[0].liveCommand.getLive({ videoId: videoUUID })
expect(live.permanentLive).to.be.false
}
await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
await servers[0].liveCommand.updateLive({ videoId: videoUUID, fields: { permanentLive: true } })
{
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.true
const live = await servers[0].liveCommand.getLive({ videoId: videoUUID })
expect(live.permanentLive).to.be.true
}
})
......@@ -100,8 +93,8 @@ describe('Permanent live', function () {
videoUUID = await createLiveWrapper(true)
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.true
const live = await servers[0].liveCommand.getLive({ videoId: videoUUID })
expect(live.permanentLive).to.be.true
await waitJobs(servers)
})
......@@ -109,16 +102,16 @@ describe('Permanent live', function () {
it('Should stream into this permanent live', async function () {
this.timeout(120000)
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
for (const server of servers) {
await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID })
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
await stopFfmpeg(command)
await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
await stopFfmpeg(ffmpegCommand)
await servers[0].liveCommand.waitUntilLiveWaiting({ videoId: videoUUID })
await waitJobs(servers)
})
......@@ -160,19 +153,19 @@ describe('Permanent live', function () {
}
})
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
for (const server of servers) {
await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID })
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
const count = await getPlaylistsCount(servers[0], videoUUID)
const count = await servers[0].liveCommand.getPlaylistsCount({ videoUUID })
// master playlist and 720p playlist
expect(count).to.equal(2)
await stopFfmpeg(command)
await stopFfmpeg(ffmpegCommand)
})
after(async function () {
......
......@@ -10,13 +10,11 @@ import {
checkLiveCleanup,
cleanupTests,
ConfigCommand,
createLive,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
getVideosList,
removeVideo,
sendRTMPStreamInVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
......@@ -24,10 +22,7 @@ import {
testFfmpegStreamError,
updateVideo,
wait,
waitJobs,
waitUntilLiveEnded,
waitUntilLivePublished,
waitUntilLiveSaved
waitJobs
} from '../../../../shared/extra-utils'
const expect = chai.expect
......@@ -52,8 +47,8 @@ describe('Save replay setting', function () {
saveReplay
}
const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
return res.body.video.uuid
const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes })
return uuid
}
async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) {
......@@ -79,13 +74,13 @@ describe('Save replay setting', function () {
async function waitUntilLivePublishedOnAllServers (videoId: string) {
for (const server of servers) {
await waitUntilLivePublished(server.url, server.accessToken, videoId)
await server.liveCommand.waitUntilLivePublished({ videoId })
}
}
async function waitUntilLiveSavedOnAllServers (videoId: string) {
for (const server of servers) {
await waitUntilLiveSaved(server.url, server.accessToken, videoId)
await server.liveCommand.waitUntilLiveSaved({ videoId })
}
}
......@@ -136,7 +131,7 @@ describe('Save replay setting', function () {
it('Should correctly have updated the live and federated it when streaming in the live', async function () {
this.timeout(30000)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
......@@ -152,7 +147,7 @@ describe('Save replay setting', function () {
await stopFfmpeg(ffmpegCommand)
for (const server of servers) {
await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID)
await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID })
}
await waitJobs(servers)
......@@ -169,7 +164,7 @@ describe('Save replay setting', function () {
liveVideoUUID = await createLiveWrapper(false)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
......@@ -198,7 +193,7 @@ describe('Save replay setting', function () {
liveVideoUUID = await createLiveWrapper(false)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
......@@ -234,7 +229,7 @@ describe('Save replay setting', function () {
it('Should correctly have updated the live and federated it when streaming in the live', async function () {
this.timeout(20000)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
await waitJobs(servers)
......@@ -278,7 +273,7 @@ describe('Save replay setting', function () {
liveVideoUUID = await createLiveWrapper(true)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
await waitJobs(servers)
......@@ -306,7 +301,7 @@ describe('Save replay setting', function () {
liveVideoUUID = await createLiveWrapper(true)
ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(liveVideoUUID)
await waitJobs(servers)
......
......@@ -5,11 +5,9 @@ import * as chai from 'chai'
import { VideoPrivacy, VideoState } from '@shared/models'
import {
cleanupTests,
createLive,
doubleFollow,
flushAndRunMultipleServers,
getVideoIdFromUUID,
sendRTMPStreamInVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
......@@ -17,7 +15,6 @@ import {
viewVideo,
wait,
waitJobs,
waitUntilLiveEnded,
waitUntilLivePublishedOnAllServers
} from '../../../../shared/extra-utils'
......@@ -60,8 +57,8 @@ describe('Test live', function () {
privacy: VideoPrivacy.PUBLIC
}
const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
return res.body.video.uuid
const { uuid } = await servers[0].liveCommand.createLive({ fields: liveAttributes })
return uuid
}
it('Should correctly send a message when the live starts and ends', async function () {
......@@ -89,7 +86,7 @@ describe('Test live', function () {
remoteSocket.emit('subscribe', { videoId })
}
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
......@@ -99,10 +96,10 @@ describe('Test live', function () {
expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED)
}
await stopFfmpeg(command)
await stopFfmpeg(ffmpegCommand)
for (const server of servers) {
await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID)
await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID })
}
await waitJobs(servers)
......@@ -137,7 +134,7 @@ describe('Test live', function () {
remoteSocket.emit('subscribe', { videoId })
}
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
......@@ -155,7 +152,7 @@ describe('Test live', function () {
expect(localLastVideoViews).to.equal(2)
expect(remoteLastVideoViews).to.equal(2)
await stopFfmpeg(command)
await stopFfmpeg(ffmpegCommand)
})
it('Should not receive a notification after unsubscribe', async function () {
......@@ -172,7 +169,7 @@ describe('Test live', function () {
socket.on('state-change', data => stateChanges.push(data.state))
socket.emit('subscribe', { videoId })
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
const command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID })