diff options
Diffstat (limited to 'server/tests/api/live/live-socket-messages.ts')
-rw-r--r-- | server/tests/api/live/live-socket-messages.ts | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index e00909ade..2a1f9f108 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts | |||
@@ -2,47 +2,42 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' | ||
6 | import { VideoPrivacy, VideoState } from '@shared/models' | 5 | import { VideoPrivacy, VideoState } from '@shared/models' |
7 | import { | 6 | import { |
8 | cleanupTests, | 7 | cleanupTests, |
9 | createLive, | 8 | createMultipleServers, |
10 | doubleFollow, | 9 | doubleFollow, |
11 | flushAndRunMultipleServers, | 10 | PeerTubeServer, |
12 | getVideoIdFromUUID, | ||
13 | sendRTMPStreamInVideo, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
16 | setDefaultVideoChannel, | 12 | setDefaultVideoChannel, |
17 | stopFfmpeg, | 13 | stopFfmpeg, |
18 | updateCustomSubConfig, | ||
19 | viewVideo, | ||
20 | wait, | 14 | wait, |
21 | waitJobs, | 15 | waitJobs, |
22 | waitUntilLiveEnded, | ||
23 | waitUntilLivePublishedOnAllServers | 16 | waitUntilLivePublishedOnAllServers |
24 | } from '../../../../shared/extra-utils' | 17 | } from '../../../../shared/extra-utils' |
25 | 18 | ||
26 | const expect = chai.expect | 19 | const expect = chai.expect |
27 | 20 | ||
28 | describe('Test live', function () { | 21 | describe('Test live', function () { |
29 | let servers: ServerInfo[] = [] | 22 | let servers: PeerTubeServer[] = [] |
30 | 23 | ||
31 | before(async function () { | 24 | before(async function () { |
32 | this.timeout(120000) | 25 | this.timeout(120000) |
33 | 26 | ||
34 | servers = await flushAndRunMultipleServers(2) | 27 | servers = await createMultipleServers(2) |
35 | 28 | ||
36 | // Get the access tokens | 29 | // Get the access tokens |
37 | await setAccessTokensToServers(servers) | 30 | await setAccessTokensToServers(servers) |
38 | await setDefaultVideoChannel(servers) | 31 | await setDefaultVideoChannel(servers) |
39 | 32 | ||
40 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 33 | await servers[0].config.updateCustomSubConfig({ |
41 | live: { | 34 | newConfig: { |
42 | enabled: true, | 35 | live: { |
43 | allowReplay: true, | 36 | enabled: true, |
44 | transcoding: { | 37 | allowReplay: true, |
45 | enabled: false | 38 | transcoding: { |
39 | enabled: false | ||
40 | } | ||
46 | } | 41 | } |
47 | } | 42 | } |
48 | }) | 43 | }) |
@@ -56,12 +51,12 @@ describe('Test live', function () { | |||
56 | async function createLiveWrapper () { | 51 | async function createLiveWrapper () { |
57 | const liveAttributes = { | 52 | const liveAttributes = { |
58 | name: 'live video', | 53 | name: 'live video', |
59 | channelId: servers[0].videoChannel.id, | 54 | channelId: servers[0].store.channel.id, |
60 | privacy: VideoPrivacy.PUBLIC | 55 | privacy: VideoPrivacy.PUBLIC |
61 | } | 56 | } |
62 | 57 | ||
63 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | 58 | const { uuid } = await servers[0].live.create({ fields: liveAttributes }) |
64 | return res.body.video.uuid | 59 | return uuid |
65 | } | 60 | } |
66 | 61 | ||
67 | it('Should correctly send a message when the live starts and ends', async function () { | 62 | it('Should correctly send a message when the live starts and ends', async function () { |
@@ -74,22 +69,22 @@ describe('Test live', function () { | |||
74 | await waitJobs(servers) | 69 | await waitJobs(servers) |
75 | 70 | ||
76 | { | 71 | { |
77 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 72 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
78 | 73 | ||
79 | const localSocket = getLiveNotificationSocket(servers[0].url) | 74 | const localSocket = servers[0].socketIO.getLiveNotificationSocket() |
80 | localSocket.on('state-change', data => localStateChanges.push(data.state)) | 75 | localSocket.on('state-change', data => localStateChanges.push(data.state)) |
81 | localSocket.emit('subscribe', { videoId }) | 76 | localSocket.emit('subscribe', { videoId }) |
82 | } | 77 | } |
83 | 78 | ||
84 | { | 79 | { |
85 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | 80 | const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) |
86 | 81 | ||
87 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | 82 | const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() |
88 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) | 83 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) |
89 | remoteSocket.emit('subscribe', { videoId }) | 84 | remoteSocket.emit('subscribe', { videoId }) |
90 | } | 85 | } |
91 | 86 | ||
92 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 87 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
93 | 88 | ||
94 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 89 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
95 | await waitJobs(servers) | 90 | await waitJobs(servers) |
@@ -99,10 +94,10 @@ describe('Test live', function () { | |||
99 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) | 94 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) |
100 | } | 95 | } |
101 | 96 | ||
102 | await stopFfmpeg(command) | 97 | await stopFfmpeg(ffmpegCommand) |
103 | 98 | ||
104 | for (const server of servers) { | 99 | for (const server of servers) { |
105 | await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) | 100 | await server.live.waitUntilEnded({ videoId: liveVideoUUID }) |
106 | } | 101 | } |
107 | await waitJobs(servers) | 102 | await waitJobs(servers) |
108 | 103 | ||
@@ -122,22 +117,22 @@ describe('Test live', function () { | |||
122 | await waitJobs(servers) | 117 | await waitJobs(servers) |
123 | 118 | ||
124 | { | 119 | { |
125 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 120 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
126 | 121 | ||
127 | const localSocket = getLiveNotificationSocket(servers[0].url) | 122 | const localSocket = servers[0].socketIO.getLiveNotificationSocket() |
128 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) | 123 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) |
129 | localSocket.emit('subscribe', { videoId }) | 124 | localSocket.emit('subscribe', { videoId }) |
130 | } | 125 | } |
131 | 126 | ||
132 | { | 127 | { |
133 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | 128 | const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) |
134 | 129 | ||
135 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | 130 | const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() |
136 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) | 131 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) |
137 | remoteSocket.emit('subscribe', { videoId }) | 132 | remoteSocket.emit('subscribe', { videoId }) |
138 | } | 133 | } |
139 | 134 | ||
140 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 135 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
141 | 136 | ||
142 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 137 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
143 | await waitJobs(servers) | 138 | await waitJobs(servers) |
@@ -145,8 +140,8 @@ describe('Test live', function () { | |||
145 | expect(localLastVideoViews).to.equal(0) | 140 | expect(localLastVideoViews).to.equal(0) |
146 | expect(remoteLastVideoViews).to.equal(0) | 141 | expect(remoteLastVideoViews).to.equal(0) |
147 | 142 | ||
148 | await viewVideo(servers[0].url, liveVideoUUID) | 143 | await servers[0].videos.view({ id: liveVideoUUID }) |
149 | await viewVideo(servers[1].url, liveVideoUUID) | 144 | await servers[1].videos.view({ id: liveVideoUUID }) |
150 | 145 | ||
151 | await waitJobs(servers) | 146 | await waitJobs(servers) |
152 | await wait(5000) | 147 | await wait(5000) |
@@ -155,7 +150,7 @@ describe('Test live', function () { | |||
155 | expect(localLastVideoViews).to.equal(2) | 150 | expect(localLastVideoViews).to.equal(2) |
156 | expect(remoteLastVideoViews).to.equal(2) | 151 | expect(remoteLastVideoViews).to.equal(2) |
157 | 152 | ||
158 | await stopFfmpeg(command) | 153 | await stopFfmpeg(ffmpegCommand) |
159 | }) | 154 | }) |
160 | 155 | ||
161 | it('Should not receive a notification after unsubscribe', async function () { | 156 | it('Should not receive a notification after unsubscribe', async function () { |
@@ -166,13 +161,13 @@ describe('Test live', function () { | |||
166 | const liveVideoUUID = await createLiveWrapper() | 161 | const liveVideoUUID = await createLiveWrapper() |
167 | await waitJobs(servers) | 162 | await waitJobs(servers) |
168 | 163 | ||
169 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 164 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
170 | 165 | ||
171 | const socket = getLiveNotificationSocket(servers[0].url) | 166 | const socket = servers[0].socketIO.getLiveNotificationSocket() |
172 | socket.on('state-change', data => stateChanges.push(data.state)) | 167 | socket.on('state-change', data => stateChanges.push(data.state)) |
173 | socket.emit('subscribe', { videoId }) | 168 | socket.emit('subscribe', { videoId }) |
174 | 169 | ||
175 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | 170 | const command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
176 | 171 | ||
177 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | 172 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) |
178 | await waitJobs(servers) | 173 | await waitJobs(servers) |