]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-socket-messages.ts
Shorter live methods
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-socket-messages.ts
index 0159d5199ba1693a063a1f101898693bce2302ca..4a6677c0aef20cd9cd3232591a3075b9e23552a9 100644 (file)
@@ -2,15 +2,12 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
 import { VideoPrivacy, VideoState } from '@shared/models'
 import {
   cleanupTests,
-  createLive,
   doubleFollow,
   flushAndRunMultipleServers,
   getVideoIdFromUUID,
-  sendRTMPStreamInVideo,
   ServerInfo,
   setAccessTokensToServers,
   setDefaultVideoChannel,
@@ -18,7 +15,6 @@ import {
   viewVideo,
   wait,
   waitJobs,
-  waitUntilLiveEnded,
   waitUntilLivePublishedOnAllServers
 } from '../../../../shared/extra-utils'
 
@@ -61,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.create({ fields: liveAttributes })
+      return uuid
     }
 
     it('Should correctly send a message when the live starts and ends', async function () {
@@ -77,7 +73,7 @@ describe('Test live', function () {
       {
         const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
 
-        const localSocket = getLiveNotificationSocket(servers[0].url)
+        const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
         localSocket.on('state-change', data => localStateChanges.push(data.state))
         localSocket.emit('subscribe', { videoId })
       }
@@ -85,12 +81,12 @@ describe('Test live', function () {
       {
         const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
 
-        const remoteSocket = getLiveNotificationSocket(servers[1].url)
+        const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
         remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
         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)
@@ -100,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.waitUntilEnded({ videoId: liveVideoUUID })
       }
       await waitJobs(servers)
 
@@ -125,7 +121,7 @@ describe('Test live', function () {
       {
         const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
 
-        const localSocket = getLiveNotificationSocket(servers[0].url)
+        const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
         localSocket.on('views-change', data => { localLastVideoViews = data.views })
         localSocket.emit('subscribe', { videoId })
       }
@@ -133,12 +129,12 @@ describe('Test live', function () {
       {
         const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
 
-        const remoteSocket = getLiveNotificationSocket(servers[1].url)
+        const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
         remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
         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)
@@ -156,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 () {
@@ -169,11 +165,11 @@ describe('Test live', function () {
 
       const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
 
-      const socket = getLiveNotificationSocket(servers[0].url)
+      const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
       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 })
 
       await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
       await waitJobs(servers)