diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/tests/shared | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-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/shared')
-rw-r--r-- | server/tests/shared/index.ts | 1 | ||||
-rw-r--r-- | server/tests/shared/views.ts | 93 |
2 files changed, 94 insertions, 0 deletions
diff --git a/server/tests/shared/index.ts b/server/tests/shared/index.ts index 47019d6a8..9f7ade53d 100644 --- a/server/tests/shared/index.ts +++ b/server/tests/shared/index.ts | |||
@@ -13,3 +13,4 @@ export * from './streaming-playlists' | |||
13 | export * from './tests' | 13 | export * from './tests' |
14 | export * from './tracker' | 14 | export * from './tracker' |
15 | export * from './videos' | 15 | export * from './videos' |
16 | export * from './views' | ||
diff --git a/server/tests/shared/views.ts b/server/tests/shared/views.ts new file mode 100644 index 000000000..e6b289715 --- /dev/null +++ b/server/tests/shared/views.ts | |||
@@ -0,0 +1,93 @@ | |||
1 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
2 | import { wait } from '@shared/core-utils' | ||
3 | import { VideoCreateResult, VideoPrivacy } from '@shared/models' | ||
4 | import { | ||
5 | createMultipleServers, | ||
6 | doubleFollow, | ||
7 | PeerTubeServer, | ||
8 | setAccessTokensToServers, | ||
9 | setDefaultVideoChannel, | ||
10 | waitJobs, | ||
11 | waitUntilLivePublishedOnAllServers | ||
12 | } from '@shared/server-commands' | ||
13 | |||
14 | async function processViewersStats (servers: PeerTubeServer[]) { | ||
15 | await wait(6000) | ||
16 | |||
17 | for (const server of servers) { | ||
18 | await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } }) | ||
19 | await server.debug.sendCommand({ body: { command: 'process-video-viewers' } }) | ||
20 | } | ||
21 | |||
22 | await waitJobs(servers) | ||
23 | } | ||
24 | |||
25 | async function processViewsBuffer (servers: PeerTubeServer[]) { | ||
26 | for (const server of servers) { | ||
27 | await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } }) | ||
28 | } | ||
29 | |||
30 | await waitJobs(servers) | ||
31 | } | ||
32 | |||
33 | async function prepareViewsServers () { | ||
34 | const servers = await createMultipleServers(2) | ||
35 | await setAccessTokensToServers(servers) | ||
36 | await setDefaultVideoChannel(servers) | ||
37 | |||
38 | await servers[0].config.updateCustomSubConfig({ | ||
39 | newConfig: { | ||
40 | live: { | ||
41 | enabled: true, | ||
42 | allowReplay: true, | ||
43 | transcoding: { | ||
44 | enabled: false | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | }) | ||
49 | |||
50 | await doubleFollow(servers[0], servers[1]) | ||
51 | |||
52 | return servers | ||
53 | } | ||
54 | |||
55 | async function prepareViewsVideos (options: { | ||
56 | servers: PeerTubeServer[] | ||
57 | live: boolean | ||
58 | vod: boolean | ||
59 | }) { | ||
60 | const { servers } = options | ||
61 | |||
62 | const liveAttributes = { | ||
63 | name: 'live video', | ||
64 | channelId: servers[0].store.channel.id, | ||
65 | privacy: VideoPrivacy.PUBLIC | ||
66 | } | ||
67 | |||
68 | let ffmpegCommand: FfmpegCommand | ||
69 | let live: VideoCreateResult | ||
70 | let vod: VideoCreateResult | ||
71 | |||
72 | if (options.live) { | ||
73 | live = await servers[0].live.create({ fields: liveAttributes }) | ||
74 | |||
75 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: live.uuid }) | ||
76 | await waitUntilLivePublishedOnAllServers(servers, live.uuid) | ||
77 | } | ||
78 | |||
79 | if (options.vod) { | ||
80 | vod = await servers[0].videos.quickUpload({ name: 'video' }) | ||
81 | } | ||
82 | |||
83 | await waitJobs(servers) | ||
84 | |||
85 | return { liveVideoId: live?.uuid, vodVideoId: vod?.uuid, ffmpegCommand } | ||
86 | } | ||
87 | |||
88 | export { | ||
89 | processViewersStats, | ||
90 | prepareViewsServers, | ||
91 | processViewsBuffer, | ||
92 | prepareViewsVideos | ||
93 | } | ||