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/api/activitypub/client.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'server/tests/api/activitypub/client.ts') diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index e69ab3cb9..655fa30d0 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -2,6 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { processViewersStats } from '@server/tests/shared' +import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -11,7 +13,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' -import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -115,6 +116,23 @@ describe('Test activitypub', function () { expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) }) + it('Should return the watch action', async function () { + this.timeout(50000) + + await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] }) + await processViewersStats(servers) + + const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200) + + const object: WatchActionObject = res.body + expect(object.type).to.equal('WatchAction') + expect(object.duration).to.equal('PT2S') + expect(object.actionStatus).to.equal('CompletedActionStatus') + expect(object.watchSections).to.have.lengthOf(1) + expect(object.watchSections[0].startTimestamp).to.equal(0) + expect(object.watchSections[0].endTimestamp).to.equal(2) + }) + after(async function () { await cleanupTests(servers) }) -- cgit v1.2.3