aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc/plugins/guide.md
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-03-16 10:36:33 +0100
committerChocobozzz <me@florianbigard.com>2023-03-16 10:36:33 +0100
commitc3441b0320f632e22318261bcd614d10187de22d (patch)
treee5273fa7d232d52169f59d17a8aa5f6a908c8ed1 /support/doc/plugins/guide.md
parent30f939c4b785e8cf2ad829a86f4b2f5892c2fda8 (diff)
downloadPeerTube-c3441b0320f632e22318261bcd614d10187de22d.tar.gz
PeerTube-c3441b0320f632e22318261bcd614d10187de22d.tar.zst
PeerTube-c3441b0320f632e22318261bcd614d10187de22d.zip
Add video AP hooks
Diffstat (limited to 'support/doc/plugins/guide.md')
-rw-r--r--support/doc/plugins/guide.md44
1 files changed, 44 insertions, 0 deletions
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 @@
16 - [Add external auth methods](#add-external-auth-methods) 16 - [Add external auth methods](#add-external-auth-methods)
17 - [Add new transcoding profiles](#add-new-transcoding-profiles) 17 - [Add new transcoding profiles](#add-new-transcoding-profiles)
18 - [Server helpers](#server-helpers) 18 - [Server helpers](#server-helpers)
19 - [Federation](#federation)
19 - [Client API (themes & plugins)](#client-api-themes--plugins) 20 - [Client API (themes & plugins)](#client-api-themes--plugins)
20 - [Get plugin static and router routes](#get-plugin-static-and-router-routes) 21 - [Get plugin static and router routes](#get-plugin-static-and-router-routes)
21 - [Notifier](#notifier) 22 - [Notifier](#notifier)
@@ -587,6 +588,49 @@ async function register ({
587 588
588See the [plugin API reference](https://docs.joinpeertube.org/api/plugins) to see the complete helpers list. 589See the [plugin API reference](https://docs.joinpeertube.org/api/plugins) to see the complete helpers list.
589 590
591#### Federation
592
593You can use some server hooks to federate plugin data to other PeerTube instances that may have installed your plugin.
594
595For example to federate additional video metadata:
596
597```js
598async function register ({ registerHook }) {
599
600 // Send plugin metadata to remote instances
601 // We also update the JSON LD context because we added a new field
602 {
603 registerHook({
604 target: 'filter:activity-pub.video.json-ld.build.result',
605 handler: async (jsonld, { video }) => {
606 return Object.assign(jsonld, { recordedAt: 'https://example.com/event' })
607 }
608 })
609
610 registerHook({
611 target: 'filter:activity-pub.activity.context.build.result',
612 handler: jsonld => {
613 return jsonld.concat([ { recordedAt: 'https://schema.org/recordedAt' } ])
614 }
615 })
616 }
617
618 // Save remote video metadata
619 {
620 for (const h of [ 'action:activity-pub.remote-video.created', 'action:activity-pub.remote-video.updated' ]) {
621 registerHook({
622 target: h,
623 handler: ({ video, videoAPObject }) => {
624 if (videoAPObject.recordedAt) {
625 // Save information about the video
626 }
627 }
628 })
629 }
630 }
631```
632
633
590### Client API (themes & plugins) 634### Client API (themes & plugins)
591 635
592#### Get plugin static and router routes 636#### Get plugin static and router routes