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