From b211106695bb82f6c32e53306081b5262c3d109d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 Mar 2022 13:36:47 +0100 Subject: 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 --- server/tests/shared/views.ts | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 server/tests/shared/views.ts (limited to 'server/tests/shared/views.ts') 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 @@ +import { FfmpegCommand } from 'fluent-ffmpeg' +import { wait } from '@shared/core-utils' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' +import { + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel, + waitJobs, + waitUntilLivePublishedOnAllServers +} from '@shared/server-commands' + +async function processViewersStats (servers: PeerTubeServer[]) { + await wait(6000) + + for (const server of servers) { + await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } }) + await server.debug.sendCommand({ body: { command: 'process-video-viewers' } }) + } + + await waitJobs(servers) +} + +async function processViewsBuffer (servers: PeerTubeServer[]) { + for (const server of servers) { + await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } }) + } + + await waitJobs(servers) +} + +async function prepareViewsServers () { + const servers = await createMultipleServers(2) + await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) + + await servers[0].config.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } + } + } + }) + + await doubleFollow(servers[0], servers[1]) + + return servers +} + +async function prepareViewsVideos (options: { + servers: PeerTubeServer[] + live: boolean + vod: boolean +}) { + const { servers } = options + + const liveAttributes = { + name: 'live video', + channelId: servers[0].store.channel.id, + privacy: VideoPrivacy.PUBLIC + } + + let ffmpegCommand: FfmpegCommand + let live: VideoCreateResult + let vod: VideoCreateResult + + if (options.live) { + live = await servers[0].live.create({ fields: liveAttributes }) + + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: live.uuid }) + await waitUntilLivePublishedOnAllServers(servers, live.uuid) + } + + if (options.vod) { + vod = await servers[0].videos.quickUpload({ name: 'video' }) + } + + await waitJobs(servers) + + return { liveVideoId: live?.uuid, vodVideoId: vod?.uuid, ffmpegCommand } +} + +export { + processViewersStats, + prepareViewsServers, + processViewsBuffer, + prepareViewsVideos +} -- cgit v1.2.3