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 --- shared/models/activitypub/activity.ts | 8 +++++--- shared/models/activitypub/context.ts | 3 ++- shared/models/activitypub/objects/index.ts | 1 + .../activitypub/objects/watch-action-object.ts | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 shared/models/activitypub/objects/watch-action-object.ts (limited to 'shared/models/activitypub') diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts index d6284e283..fd5d38316 100644 --- a/shared/models/activitypub/activity.ts +++ b/shared/models/activitypub/activity.ts @@ -1,6 +1,6 @@ import { ActivityPubActor } from './activitypub-actor' import { ActivityPubSignature } from './activitypub-signature' -import { ActivityFlagReasonObject, CacheFileObject, VideoObject } from './objects' +import { ActivityFlagReasonObject, CacheFileObject, VideoObject, WatchActionObject } from './objects' import { AbuseObject } from './objects/abuse-object' import { DislikeObject } from './objects/dislike-object' import { APObject } from './objects/object.model' @@ -52,7 +52,7 @@ export interface BaseActivity { export interface ActivityCreate extends BaseActivity { type: 'Create' - object: VideoObject | AbuseObject | DislikeObject | VideoCommentObject | CacheFileObject | PlaylistObject + object: VideoObject | AbuseObject | DislikeObject | VideoCommentObject | CacheFileObject | PlaylistObject | WatchActionObject } export interface ActivityUpdate extends BaseActivity { @@ -99,7 +99,9 @@ export interface ActivityView extends BaseActivity { type: 'View' actor: string object: APObject - expires: string + + // If sending a "viewer" event + expires?: string } export interface ActivityDislike extends BaseActivity { diff --git a/shared/models/activitypub/context.ts b/shared/models/activitypub/context.ts index 4ada3b083..e9df38207 100644 --- a/shared/models/activitypub/context.ts +++ b/shared/models/activitypub/context.ts @@ -12,4 +12,5 @@ export type ContextType = 'Rate' | 'Flag' | 'Actor' | - 'Collection' + 'Collection' | + 'WatchAction' diff --git a/shared/models/activitypub/objects/index.ts b/shared/models/activitypub/objects/index.ts index 9e2c6b728..47a8e847a 100644 --- a/shared/models/activitypub/objects/index.ts +++ b/shared/models/activitypub/objects/index.ts @@ -8,3 +8,4 @@ export * from './playlist-object' export * from './video-comment-object' export * from './video-torrent-object' export * from './view-object' +export * from './watch-action-object' diff --git a/shared/models/activitypub/objects/watch-action-object.ts b/shared/models/activitypub/objects/watch-action-object.ts new file mode 100644 index 000000000..ed336602f --- /dev/null +++ b/shared/models/activitypub/objects/watch-action-object.ts @@ -0,0 +1,22 @@ +export interface WatchActionObject { + id: string + type: 'WatchAction' + + startTime: string + endTime: string + + location?: { + addressCountry: string + } + + uuid: string + object: string + actionStatus: 'CompletedActionStatus' + + duration: string + + watchSections: { + startTimestamp: number + endTimestamp: number + }[] +} -- cgit v1.2.3