Federation

Each PeerTube instance is able to fetch video from other compatible servers it follows, in a process known as “federation”. Federation is implemented using the ActivityPub protocol, in order to leverage existing tools and be compatible with other services such as Mastodon, Pleroma and many more.

Federation in PeerTube is twofold: videos metadata are shared as activities for inter-server communication in what amounts to sharing parts of one’s database, and user interaction via comments which are compatible with the kind of activity textual platforms like Mastodon use.

Supported Activities


The current document is not exhaustive and explains PeerTube's implementation of the ActivityPub specification, as well as the extensions made to it using ActivityStreams vocubulary.

ActivityPub ActivityStreams

Custom activities supported that are not part of the ActivityPub specification:

  • Flag (for abuse reports)

Every activity extends the following basic type:

export interface BaseActivity {
  '@context'?: any[];
  id: string;
  to?: string[];
  cc?: string[];
  actor: string | ActivityPubActor;
  type: ActivityType;
  signature?: ActivityPubSignature;
}

Follow

Follow is an activity standardized in the ActivityPub specification (see Follow Activity). The Follow activity is used to subscribe to the activities of another actor (a server subscribing to another server’s videos, a user subscribing to another user’s videos).

Supported on

  • Actor URI

Accept

Supported on

  • Follow

Reject

Reject is an activity standardized in the ActivityPub specification (see Reject Activity).

Supported on

  • Follow

Undo

Undo is an activity standardized in the ActivityPub specification (see Undo Activity). The Undo activity is used to undo a previous activity.

Supported on

Like

Like is an activity standardized in the ActivityPub specification (see Like Activity).

Supported on

Update

Update is an activity standardized in the ActivityPub specification (see Update Activity). The Update activity is used when updating an already existing object.

Supported on

Create

Create is an activity standardized in the ActivityPub specification (see Create Activity). The Create activity is used when posting a new object. This has the side effect that the object embedded within the Activity (in the object property) is created.

Supported on

Example

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/v1",
    {}
  ],
  "to": ["https://peertube2.cpy.re/accounts/root/activity"],
  "type": "Create",
  "actor": "https://peertube2.cpy.re/accounts/root",
  "object": {}
}

Announce

Announce is an activity standardized in the ActivityPub specification (see Announce Activity).

Supported on

Example

{
  "type": "Announce",
  "id": "https://peertube2.cpy.re/videos/watch/997111d4-e8d8-4f45-99d3-857905785d05/announces/1",
  "actor": "https://peertube2.cpy.re/accounts/root",
  "object": "https://peertube2.cpy.re/videos/watch/997111d4-e8d8-4f45-99d3-857905785d05",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public",
    "https://peertube2.cpy.re/accounts/root/followers",
    "https://peertube2.cpy.re/video-channels/root_channel/followers"
  ],
  "cc": []
}

Supported Objects

Objects are the core concept around which both ActivityStreams and ActivityPub are built. Objects are often wrapped in Activities and are contained in streams of Collections, which are themselves subclasses of Objects.

Video

Example

Structure

The model structure definition lies in shared/models/activitypub/objects/video-torrent-object.ts.

export interface VideoTorrentObject {
  type: 'Video'
  id: string
  name: string
  duration: string
  uuid: string
  tag: ActivityTagObject[]
  category: ActivityIdentifierObject
  licence: ActivityIdentifierObject
  language: ActivityIdentifierObject
  subtitleLanguage: ActivityIdentifierObject[]
  views: number
  sensitive: boolean
  commentsEnabled: boolean
  waitTranscoding: boolean
  state: VideoState
  published: string
  updated: string
  mediaType: 'text/markdown'
  content: string
  support: string
  icon: ActivityIconObject
  url: ActivityUrlObject[]
  likes: string
  dislikes: string
  shares: string
  comments: string
  attributedTo: ActivityPubAttributedTo[]
  to?: string[]
  cc?: string[]
}

CacheFile

The object is used to represent a cached file. It is usually sent by third-party servers to the origin server hosting a video file (a resolution from a Video), to notify it that they have put up a copy of that file. The origin server should then add the server emitting the CacheFile to the list of WebSeeds for that file.

Example

Structure

The model structure definition lies in shared/models/activitypub/objects/cache-file-object.ts.

export interface CacheFileObject {
  id: string
  type: 'CacheFile',
  object: string
  expires: string
  url: ActivityVideoUrlObject
}

Note

A Note is usually a comment made to a video. Since most ActivityPub textual platforms use the Note object for their messages, most of them can interact in the same way with PeerTube videos, making them able to comment PeerTube videos directly! A Note is emitted along the Video publication object: the former is used to notify textual platforms of the Fediverse, the latter to notify the Vidiverse.

Example

Structure

The model structure definition lies in shared/models/activitypub/objects/video-comment-object.ts.

export interface VideoCommentObject {
  type: 'Note'
  id: string
  content: string
  inReplyTo: string
  published: string
  updated: string
  url: string
  attributedTo: string
  tag: ActivityTagObject[]
}

Flag

A Flag represents a report transfered to a remote instance.

Example

Structure

The model structure definition lies in shared/models/activitypub/objects/video-abuse-object.ts.

export interface VideoAbuseObject {
  type: 'Flag',
  content: string
  object: string
}

Dislike

Example

Structure

The model structure definition lies in shared/models/activitypub/objects/dislike-object.ts.

export interface DislikeObject {
  id: string
  type: 'Dislike'
  actor: string
  object: string
}

_[Fediverse]: several servers following one another, several users following each other. Designates federated communities in general _[Vidiverse]: same as Fediverse, but federating videos specifically