From c3441b0320f632e22318261bcd614d10187de22d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Mar 2023 10:36:33 +0100 Subject: Add video AP hooks --- support/doc/plugins/guide.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'support/doc/plugins') diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 337f3d97f..c5e3236ca 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -16,6 +16,7 @@ - [Add external auth methods](#add-external-auth-methods) - [Add new transcoding profiles](#add-new-transcoding-profiles) - [Server helpers](#server-helpers) + - [Federation](#federation) - [Client API (themes & plugins)](#client-api-themes--plugins) - [Get plugin static and router routes](#get-plugin-static-and-router-routes) - [Notifier](#notifier) @@ -587,6 +588,49 @@ async function register ({ See the [plugin API reference](https://docs.joinpeertube.org/api/plugins) to see the complete helpers list. +#### Federation + +You can use some server hooks to federate plugin data to other PeerTube instances that may have installed your plugin. + +For example to federate additional video metadata: + +```js +async function register ({ registerHook }) { + + // Send plugin metadata to remote instances + // We also update the JSON LD context because we added a new field + { + registerHook({ + target: 'filter:activity-pub.video.json-ld.build.result', + handler: async (jsonld, { video }) => { + return Object.assign(jsonld, { recordedAt: 'https://example.com/event' }) + } + }) + + registerHook({ + target: 'filter:activity-pub.activity.context.build.result', + handler: jsonld => { + return jsonld.concat([ { recordedAt: 'https://schema.org/recordedAt' } ]) + } + }) + } + + // Save remote video metadata + { + for (const h of [ 'action:activity-pub.remote-video.created', 'action:activity-pub.remote-video.updated' ]) { + registerHook({ + target: h, + handler: ({ video, videoAPObject }) => { + if (videoAPObject.recordedAt) { + // Save information about the video + } + } + }) + } + } +``` + + ### Client API (themes & plugins) #### Get plugin static and router routes -- cgit v1.2.3