- 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)