aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'support/doc/plugins')
-rw-r--r--support/doc/plugins/guide.md136
1 files changed, 109 insertions, 27 deletions
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index 3785246a7..52e3b6052 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -16,11 +16,10 @@
16 - [Add new transcoding profiles](#add-new-transcoding-profiles) 16 - [Add new transcoding profiles](#add-new-transcoding-profiles)
17 - [Server helpers](#server-helpers) 17 - [Server helpers](#server-helpers)
18 - [Client API (themes & plugins)](#client-api-themes--plugins) 18 - [Client API (themes & plugins)](#client-api-themes--plugins)
19 - [Plugin static route](#plugin-static-route) 19 - [Get plugin static and router routes](#get-plugin-static-and-router-routes)
20 - [Notifier](#notifier) 20 - [Notifier](#notifier)
21 - [Markdown Renderer](#markdown-renderer) 21 - [Markdown Renderer](#markdown-renderer)
22 - [Auth header](#auth-header) 22 - [Auth header](#auth-header)
23 - [Plugin router route](#plugin-router-route)
24 - [Custom Modal](#custom-modal) 23 - [Custom Modal](#custom-modal)
25 - [Translate](#translate) 24 - [Translate](#translate)
26 - [Get public settings](#get-public-settings) 25 - [Get public settings](#get-public-settings)
@@ -30,6 +29,7 @@
30 - [Plugin selector on HTML elements](#plugin-selector-on-html-elements) 29 - [Plugin selector on HTML elements](#plugin-selector-on-html-elements)
31 - [HTML placeholder elements](#html-placeholder-elements) 30 - [HTML placeholder elements](#html-placeholder-elements)
32 - [Add/remove left menu links](#addremove-left-menu-links) 31 - [Add/remove left menu links](#addremove-left-menu-links)
32 - [Create client page](#create-client-page)
33 - [Publishing](#publishing) 33 - [Publishing](#publishing)
34- [Write a plugin/theme](#write-a-plugintheme) 34- [Write a plugin/theme](#write-a-plugintheme)
35 - [Clone the quickstart repository](#clone-the-quickstart-repository) 35 - [Clone the quickstart repository](#clone-the-quickstart-repository)
@@ -531,7 +531,7 @@ See the [plugin API reference](https://docs.joinpeertube.org/api-plugins) to see
531 531
532### Client API (themes & plugins) 532### Client API (themes & plugins)
533 533
534#### Plugin static route 534#### Get plugin static and router routes
535 535
536To get your plugin static route: 536To get your plugin static route:
537 537
@@ -542,6 +542,24 @@ function register (...) {
542} 542}
543``` 543```
544 544
545And to get your plugin router route, use `peertubeHelpers.getBaseRouterRoute()`:
546
547```js
548function register (...) {
549 registerHook({
550 target: 'action:video-watch.video.loaded',
551 handler: ({ video }) => {
552 fetch(peertubeHelpers.getBaseRouterRoute() + '/my/plugin/api', {
553 method: 'GET',
554 headers: peertubeHelpers.getAuthHeader()
555 }).then(res => res.json())
556 .then(data => console.log('Hi %s.', data))
557 }
558 })
559}
560```
561
562
545#### Notifier 563#### Notifier
546 564
547To notify the user with the PeerTube ToastModule: 565To notify the user with the PeerTube ToastModule:
@@ -594,27 +612,6 @@ function register (...) {
594} 612}
595``` 613```
596 614
597#### Plugin router route
598
599**PeerTube >= 3.3**
600
601To get your plugin router route, you can use `peertubeHelpers.getBaseRouterRoute()`:
602
603```js
604function register (...) {
605 registerHook({
606 target: 'action:video-watch.video.loaded',
607 handler: ({ video }) => {
608 fetch(peertubeHelpers.getBaseRouterRoute() + '/my/plugin/api', {
609 method: 'GET',
610 headers: peertubeHelpers.getAuthHeader()
611 }).then(res => res.json())
612 .then(data => console.log('Hi %s.', data))
613 }
614 })
615}
616```
617
618#### Custom Modal 615#### Custom Modal
619 616
620To show a custom modal: 617To show a custom modal:
@@ -686,18 +683,37 @@ async function register ({ registerVideoField, peertubeHelpers }) {
686 name: 'my-field-name, 683 name: 'my-field-name,
687 label: 'My added field', 684 label: 'My added field',
688 descriptionHTML: 'Optional description', 685 descriptionHTML: 'Optional description',
686
687 // type: 'input' | 'input-checkbox' | 'input-password' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' | 'select' | 'html'
688 // /!\ 'input-checkbox' could send "false" and "true" strings instead of boolean
689 type: 'input-textarea', 689 type: 'input-textarea',
690
690 default: '', 691 default: '',
692
691 // Optional, to hide a field depending on the current form state 693 // Optional, to hide a field depending on the current form state
692 // liveVideo is in the options object when the user is creating/updating a live 694 // liveVideo is in the options object when the user is creating/updating a live
693 // videoToUpdate is in the options object when the user is updating a video 695 // videoToUpdate is in the options object when the user is updating a video
694 hidden: ({ formValues, videoToUpdate, liveVideo }) => { 696 hidden: ({ formValues, videoToUpdate, liveVideo }) => {
695 return formValues.pluginData['other-field'] === 'toto' 697 return formValues.pluginData['other-field'] === 'toto'
698 },
699
700 // Optional, to display an error depending on the form state
701 error: ({ formValues, value }) => {
702 if (formValues['privacy'] !== 1 && formValues['privacy'] !== 2) return { error: false }
703 if (value === true) return { error: false }
704
705 return { error: true, text: 'Should be enabled' }
696 } 706 }
697 } 707 }
698 708
709 const videoFormOptions = {
710 // Optional, to choose to put your setting in a specific tab in video form
711 // type: 'main' | 'plugin-settings'
712 tab: 'main'
713 }
714
699 for (const type of [ 'upload', 'import-url', 'import-torrent', 'update', 'go-live' ]) { 715 for (const type of [ 'upload', 'import-url', 'import-torrent', 'update', 'go-live' ]) {
700 registerVideoField(commonOptions, { type }) 716 registerVideoField(commonOptions, { type, ...videoFormOptions })
701 } 717 }
702} 718}
703``` 719```
@@ -787,6 +803,21 @@ See the complete list on https://docs.joinpeertube.org/api-plugins
787 803
788Left menu links can be filtered (add/remove a section or add/remove links) using the `filter:left-menu.links.create.result` client hook. 804Left menu links can be filtered (add/remove a section or add/remove links) using the `filter:left-menu.links.create.result` client hook.
789 805
806#### Create client page
807
808To create a client page, register a new client route:
809
810```js
811function register ({ registerClientRoute }) {
812 registerClientRoute({
813 route: 'my-super/route',
814 onMount: ({ rootEl }) => {
815 rootEl.innerHTML = 'hello'
816 }
817 })
818}
819```
820
790 821
791### Publishing 822### Publishing
792 823
@@ -875,11 +906,62 @@ And if you don't need CSS or client script files, use an empty `array`:
875### Write code 906### Write code
876 907
877Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :) 908Now you can register hooks or settings, write CSS and add static directories to your plugin or your theme :)
909It's up to you to check the code you write will be compatible with the PeerTube NodeJS version, and will be supported by web browsers.
910
911**JavaScript**
878 912
879**Caution:** It's up to you to check the code you write will be compatible with the PeerTube NodeJS version,
880and will be supported by web browsers.
881If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/). 913If you want to write modern JavaScript, please use a transpiler like [Babel](https://babeljs.io/).
882 914
915**Typescript**
916
917If you want to use __Typescript__, you can add __PeerTube__ types as dev dependencies:
918
919```
920npm install --save-dev @peertube/peertube-types
921```
922
923This package exposes *server* definition files by default:
924```ts
925import { RegisterServerOptions } from '@peertube/peertube-types'
926
927export async function register ({ registerHook }: RegisterServerOptions) {
928 registerHook({
929 target: 'action:application.listening',
930 handler: () => displayHelloWorld()
931 })
932}
933```
934
935But it also exposes client types and various models used in __PeerTube__:
936```ts
937import { Video } from '@peertube/peertube-types';
938import { RegisterClientOptions } from '@peertube/peertube-types/client';
939
940function register({ registerHook, peertubeHelpers }: RegisterClientOptions) {
941 registerHook({
942 target: 'action:admin-plugin-settings.init',
943 handler: ({ npmName }: { npmName: string }) => {
944 if ('peertube-plugin-transcription' !== npmName) {
945 return;
946 }
947 },
948 });
949
950 registerHook({
951 target: 'action:video-watch.video.loaded',
952 handler: ({ video }: { video: Video }) => {
953 fetch(`${peertubeHelpers.getBaseRouterRoute()}/videos/${video.uuid}/captions`, {
954 method: 'PUT',
955 headers: peertubeHelpers.getAuthHeader(),
956 }).then((res) => res.json())
957 .then((data) => console.log('Hi %s.', data));
958 },
959 });
960}
961
962export { register };
963```
964
883### Add translations 965### Add translations
884 966
885If you want to translate strings of your plugin (like labels of your registered settings), create a file and add it to `package.json`: 967If you want to translate strings of your plugin (like labels of your registered settings), create a file and add it to `package.json`: