aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-24 13:36:47 +0100
committerChocobozzz <chocobozzz@cpy.re>2022-04-15 09:49:35 +0200
commitb211106695bb82f6c32e53306081b5262c3d109d (patch)
treefa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/tests/api/live
parent69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff)
downloadPeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz
PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst
PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip
Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint * Merge watching and view endpoints * Introduce WatchAction AP activity * Add tables to store viewer information of local videos * Add endpoints to fetch video views/viewers stats of local videos * Refactor views/viewers handlers * Support "views" and "viewers" counters for both VOD and live videos
Diffstat (limited to 'server/tests/api/live')
-rw-r--r--server/tests/api/live/index.ts1
-rw-r--r--server/tests/api/live/live-socket-messages.ts4
-rw-r--r--server/tests/api/live/live-views.ts132
3 files changed, 2 insertions, 135 deletions
diff --git a/server/tests/api/live/index.ts b/server/tests/api/live/index.ts
index 105416b8d..71bc150d8 100644
--- a/server/tests/api/live/index.ts
+++ b/server/tests/api/live/index.ts
@@ -3,5 +3,4 @@ import './live-socket-messages'
3import './live-permanent' 3import './live-permanent'
4import './live-rtmps' 4import './live-rtmps'
5import './live-save-replay' 5import './live-save-replay'
6import './live-views'
7import './live' 6import './live'
diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts
index 50b16443e..7668ed5b9 100644
--- a/server/tests/api/live/live-socket-messages.ts
+++ b/server/tests/api/live/live-socket-messages.ts
@@ -140,8 +140,8 @@ describe('Test live', function () {
140 expect(localLastVideoViews).to.equal(0) 140 expect(localLastVideoViews).to.equal(0)
141 expect(remoteLastVideoViews).to.equal(0) 141 expect(remoteLastVideoViews).to.equal(0)
142 142
143 await servers[0].videos.view({ id: liveVideoUUID }) 143 await servers[0].views.simulateView({ id: liveVideoUUID })
144 await servers[1].videos.view({ id: liveVideoUUID }) 144 await servers[1].views.simulateView({ id: liveVideoUUID })
145 145
146 await waitJobs(servers) 146 await waitJobs(servers)
147 147
diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts
deleted file mode 100644
index 446d0913c..000000000
--- a/server/tests/api/live/live-views.ts
+++ /dev/null
@@ -1,132 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { wait } from '@shared/core-utils'
7import { VideoPrivacy } from '@shared/models'
8import {
9 cleanupTests,
10 createMultipleServers,
11 doubleFollow,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
15 stopFfmpeg,
16 waitJobs,
17 waitUntilLivePublishedOnAllServers
18} from '@shared/server-commands'
19
20const expect = chai.expect
21
22describe('Live views', function () {
23 let servers: PeerTubeServer[] = []
24
25 before(async function () {
26 this.timeout(120000)
27
28 servers = await createMultipleServers(2)
29
30 // Get the access tokens
31 await setAccessTokensToServers(servers)
32 await setDefaultVideoChannel(servers)
33
34 await servers[0].config.updateCustomSubConfig({
35 newConfig: {
36 live: {
37 enabled: true,
38 allowReplay: true,
39 transcoding: {
40 enabled: false
41 }
42 }
43 }
44 })
45
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
48 })
49
50 let liveVideoId: string
51 let command: FfmpegCommand
52
53 async function countViewers (expectedViewers: number) {
54 for (const server of servers) {
55 const video = await server.videos.get({ id: liveVideoId })
56 expect(video.viewers).to.equal(expectedViewers)
57 }
58 }
59
60 async function countViews (expectedViews: number) {
61 for (const server of servers) {
62 const video = await server.videos.get({ id: liveVideoId })
63 expect(video.views).to.equal(expectedViews)
64 }
65 }
66
67 before(async function () {
68 this.timeout(30000)
69
70 const liveAttributes = {
71 name: 'live video',
72 channelId: servers[0].store.channel.id,
73 privacy: VideoPrivacy.PUBLIC
74 }
75
76 const live = await servers[0].live.create({ fields: liveAttributes })
77 liveVideoId = live.uuid
78
79 command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
80 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
81 await waitJobs(servers)
82 })
83
84 it('Should display no views and viewers for a live', async function () {
85 await countViews(0)
86 await countViewers(0)
87 })
88
89 it('Should view a live twice and display 1 view/viewer', async function () {
90 this.timeout(30000)
91
92 await servers[0].videos.view({ id: liveVideoId })
93 await servers[0].videos.view({ id: liveVideoId })
94
95 await waitJobs(servers)
96 await countViewers(1)
97
98 await wait(7000)
99 await countViews(1)
100 })
101
102 it('Should wait and display 0 viewers while still have 1 view', async function () {
103 this.timeout(30000)
104
105 await wait(12000)
106 await waitJobs(servers)
107
108 await countViews(1)
109 await countViewers(0)
110 })
111
112 it('Should view a live on a remote and on local and display 2 viewers and 3 views', async function () {
113 this.timeout(30000)
114
115 await servers[0].videos.view({ id: liveVideoId })
116 await servers[1].videos.view({ id: liveVideoId })
117 await servers[1].videos.view({ id: liveVideoId })
118 await waitJobs(servers)
119
120 await countViewers(2)
121
122 await wait(7000)
123 await waitJobs(servers)
124
125 await countViews(3)
126 })
127
128 after(async function () {
129 await stopFfmpeg(command)
130 await cleanupTests(servers)
131 })
132})