- describe('Live views', function () {
- let liveVideoId: string
- let command: FfmpegCommand
-
- async function countViews (expected: number) {
- for (const server of servers) {
- const res = await getVideo(server.url, liveVideoId)
- const video: VideoDetails = res.body
-
- expect(video.views).to.equal(expected)
- }
- }
-
- before(async function () {
- this.timeout(30000)
-
- const liveAttributes = {
- name: 'live video',
- channelId: servers[0].videoChannel.id,
- privacy: VideoPrivacy.PUBLIC
- }
-
- const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
- liveVideoId = res.body.video.uuid
-
- command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
- await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoId)
- await waitJobs(servers)
- })
-
- it('Should display no views for a live', async function () {
- await countViews(0)
- })
-
- it('Should view a live twice and display 1 view', async function () {
- this.timeout(30000)
-
- await viewVideo(servers[0].url, liveVideoId)
- await viewVideo(servers[0].url, liveVideoId)
-
- await wait(7000)
-
- await waitJobs(servers)
-
- await countViews(1)
- })
-
- it('Should wait and display 0 views', async function () {
- this.timeout(30000)
-
- await wait(7000)
- await waitJobs(servers)
-
- await countViews(0)
- })
-
- it('Should view a live on a remote and on local and display 2 views', async function () {
- this.timeout(30000)
-
- await viewVideo(servers[0].url, liveVideoId)
- await viewVideo(servers[1].url, liveVideoId)
- await viewVideo(servers[1].url, liveVideoId)
-
- await wait(7000)
- await waitJobs(servers)
-
- await countViews(2)
- })
-
- after(async function () {
- await stopFfmpeg(command)
- })
- })
-
- describe('Live socket messages', function () {
-
- async function createLiveWrapper () {
- const liveAttributes = {
- name: 'live video',
- channelId: servers[0].videoChannel.id,
- privacy: VideoPrivacy.PUBLIC
- }
-
- const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
- return res.body.video.uuid
- }
-
- it('Should correctly send a message when the live starts and ends', async function () {
- this.timeout(60000)
-
- const localStateChanges: VideoState[] = []
- const remoteStateChanges: VideoState[] = []
-
- const liveVideoUUID = await createLiveWrapper()
- await waitJobs(servers)
-
- {
- const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
-
- const localSocket = getLiveNotificationSocket(servers[0].url)
- localSocket.on('state-change', data => localStateChanges.push(data.state))
- localSocket.emit('subscribe', { videoId })
- }
-
- {
- const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
-
- const remoteSocket = getLiveNotificationSocket(servers[1].url)
- remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
- remoteSocket.emit('subscribe', { videoId })
- }
-
- const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
- await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
- await waitJobs(servers)
-
- for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
- expect(stateChanges).to.have.lengthOf(1)
- expect(stateChanges[0]).to.equal(VideoState.PUBLISHED)
- }
-
- await stopFfmpeg(command)
- await waitJobs(servers)
-
- for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
- expect(stateChanges).to.have.lengthOf(2)
- expect(stateChanges[1]).to.equal(VideoState.LIVE_ENDED)
- }
- })
-
- it('Should not receive a notification after unsubscribe', async function () {
- this.timeout(60000)
-
- const stateChanges: VideoState[] = []
-
- const liveVideoUUID = await createLiveWrapper()
- await waitJobs(servers)
-
- const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
-
- const socket = getLiveNotificationSocket(servers[0].url)
- socket.on('state-change', data => stateChanges.push(data.state))
- socket.emit('subscribe', { videoId })
-
- const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
- await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
- await waitJobs(servers)
-
- expect(stateChanges).to.have.lengthOf(1)
- socket.emit('unsubscribe', { videoId })
-
- await stopFfmpeg(command)
- await waitJobs(servers)
-
- expect(stateChanges).to.have.lengthOf(1)
- })
- })
-