]>
Commit | Line | Data |
---|---|---|
8ebf2a5d C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
c55e3d72 | 4 | import { wait } from '@shared/core-utils' |
8ebf2a5d C |
5 | import { VideoPrivacy, VideoState } from '@shared/models' |
6 | import { | |
7 | cleanupTests, | |
254d3579 | 8 | createMultipleServers, |
4c7e60bc | 9 | doubleFollow, |
254d3579 | 10 | PeerTubeServer, |
8ebf2a5d C |
11 | setAccessTokensToServers, |
12 | setDefaultVideoChannel, | |
13 | stopFfmpeg, | |
8ebf2a5d | 14 | waitJobs, |
8ebf2a5d | 15 | waitUntilLivePublishedOnAllServers |
c55e3d72 | 16 | } from '@shared/server-commands' |
8ebf2a5d | 17 | |
c8fdfab0 | 18 | describe('Test live socket messages', function () { |
254d3579 | 19 | let servers: PeerTubeServer[] = [] |
8ebf2a5d C |
20 | |
21 | before(async function () { | |
22 | this.timeout(120000) | |
23 | ||
254d3579 | 24 | servers = await createMultipleServers(2) |
8ebf2a5d C |
25 | |
26 | // Get the access tokens | |
27 | await setAccessTokensToServers(servers) | |
28 | await setDefaultVideoChannel(servers) | |
29 | ||
89d241a7 | 30 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
31 | newConfig: { |
32 | live: { | |
33 | enabled: true, | |
34 | allowReplay: true, | |
35 | transcoding: { | |
36 | enabled: false | |
37 | } | |
8ebf2a5d C |
38 | } |
39 | } | |
40 | }) | |
41 | ||
42 | // Server 1 and server 2 follow each other | |
43 | await doubleFollow(servers[0], servers[1]) | |
44 | }) | |
45 | ||
46 | describe('Live socket messages', function () { | |
47 | ||
48 | async function createLiveWrapper () { | |
49 | const liveAttributes = { | |
50 | name: 'live video', | |
89d241a7 | 51 | channelId: servers[0].store.channel.id, |
8ebf2a5d C |
52 | privacy: VideoPrivacy.PUBLIC |
53 | } | |
54 | ||
89d241a7 | 55 | const { uuid } = await servers[0].live.create({ fields: liveAttributes }) |
4f219914 | 56 | return uuid |
8ebf2a5d C |
57 | } |
58 | ||
59 | it('Should correctly send a message when the live starts and ends', async function () { | |
60 | this.timeout(60000) | |
61 | ||
62 | const localStateChanges: VideoState[] = [] | |
63 | const remoteStateChanges: VideoState[] = [] | |
64 | ||
65 | const liveVideoUUID = await createLiveWrapper() | |
66 | await waitJobs(servers) | |
67 | ||
68 | { | |
89d241a7 | 69 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
8ebf2a5d | 70 | |
89d241a7 | 71 | const localSocket = servers[0].socketIO.getLiveNotificationSocket() |
8ebf2a5d C |
72 | localSocket.on('state-change', data => localStateChanges.push(data.state)) |
73 | localSocket.emit('subscribe', { videoId }) | |
74 | } | |
75 | ||
76 | { | |
89d241a7 | 77 | const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) |
8ebf2a5d | 78 | |
89d241a7 | 79 | const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() |
8ebf2a5d C |
80 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) |
81 | remoteSocket.emit('subscribe', { videoId }) | |
82 | } | |
83 | ||
89d241a7 | 84 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
8ebf2a5d C |
85 | |
86 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | |
87 | await waitJobs(servers) | |
88 | ||
89 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | |
90 | expect(stateChanges).to.have.length.at.least(1) | |
91 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) | |
92 | } | |
93 | ||
4f219914 | 94 | await stopFfmpeg(ffmpegCommand) |
8ebf2a5d C |
95 | |
96 | for (const server of servers) { | |
89d241a7 | 97 | await server.live.waitUntilEnded({ videoId: liveVideoUUID }) |
8ebf2a5d C |
98 | } |
99 | await waitJobs(servers) | |
100 | ||
101 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | |
102 | expect(stateChanges).to.have.length.at.least(2) | |
103 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.LIVE_ENDED) | |
104 | } | |
105 | }) | |
106 | ||
107 | it('Should correctly send views change notification', async function () { | |
108 | this.timeout(60000) | |
109 | ||
110 | let localLastVideoViews = 0 | |
111 | let remoteLastVideoViews = 0 | |
112 | ||
113 | const liveVideoUUID = await createLiveWrapper() | |
114 | await waitJobs(servers) | |
115 | ||
116 | { | |
89d241a7 | 117 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
8ebf2a5d | 118 | |
89d241a7 | 119 | const localSocket = servers[0].socketIO.getLiveNotificationSocket() |
8ebf2a5d C |
120 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) |
121 | localSocket.emit('subscribe', { videoId }) | |
122 | } | |
123 | ||
124 | { | |
89d241a7 | 125 | const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) |
8ebf2a5d | 126 | |
89d241a7 | 127 | const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() |
8ebf2a5d C |
128 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) |
129 | remoteSocket.emit('subscribe', { videoId }) | |
130 | } | |
131 | ||
89d241a7 | 132 | const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
8ebf2a5d C |
133 | |
134 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | |
135 | await waitJobs(servers) | |
136 | ||
137 | expect(localLastVideoViews).to.equal(0) | |
138 | expect(remoteLastVideoViews).to.equal(0) | |
139 | ||
b2111066 C |
140 | await servers[0].views.simulateView({ id: liveVideoUUID }) |
141 | await servers[1].views.simulateView({ id: liveVideoUUID }) | |
8ebf2a5d | 142 | |
8ebf2a5d C |
143 | await waitJobs(servers) |
144 | ||
145 | expect(localLastVideoViews).to.equal(2) | |
146 | expect(remoteLastVideoViews).to.equal(2) | |
147 | ||
4f219914 | 148 | await stopFfmpeg(ffmpegCommand) |
8ebf2a5d C |
149 | }) |
150 | ||
151 | it('Should not receive a notification after unsubscribe', async function () { | |
152 | this.timeout(120000) | |
153 | ||
154 | const stateChanges: VideoState[] = [] | |
155 | ||
156 | const liveVideoUUID = await createLiveWrapper() | |
157 | await waitJobs(servers) | |
158 | ||
89d241a7 | 159 | const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) |
8ebf2a5d | 160 | |
89d241a7 | 161 | const socket = servers[0].socketIO.getLiveNotificationSocket() |
8ebf2a5d C |
162 | socket.on('state-change', data => stateChanges.push(data.state)) |
163 | socket.emit('subscribe', { videoId }) | |
164 | ||
89d241a7 | 165 | const command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) |
8ebf2a5d C |
166 | |
167 | await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) | |
168 | await waitJobs(servers) | |
169 | ||
170 | // Notifier waits before sending a notification | |
171 | await wait(10000) | |
172 | ||
173 | expect(stateChanges).to.have.lengthOf(1) | |
174 | socket.emit('unsubscribe', { videoId }) | |
175 | ||
176 | await stopFfmpeg(command) | |
177 | await waitJobs(servers) | |
178 | ||
179 | expect(stateChanges).to.have.lengthOf(1) | |
180 | }) | |
181 | }) | |
182 | ||
183 | after(async function () { | |
184 | await cleanupTests(servers) | |
185 | }) | |
186 | }) |