aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-11 11:07:40 +0200
committerChocobozzz <me@florianbigard.com>2022-10-11 11:11:04 +0200
commit9d4c60dccc8e7e777ad139a82e9f61feda9d21fc (patch)
tree2931338f340b398d36c43575fea95cf1fbbfeb4c /support/doc/plugins
parent9866921cbf3f8f0925f7ffb3a231d5dfe2d30953 (diff)
downloadPeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.tar.gz
PeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.tar.zst
PeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.zip
Add ability for plugins to register ws routes
Diffstat (limited to 'support/doc/plugins')
-rw-r--r--support/doc/plugins/guide.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index 431d5332f..1c809258a 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -12,6 +12,7 @@
12 - [Storage](#storage) 12 - [Storage](#storage)
13 - [Update video constants](#update-video-constants) 13 - [Update video constants](#update-video-constants)
14 - [Add custom routes](#add-custom-routes) 14 - [Add custom routes](#add-custom-routes)
15 - [Add custom WebSocket handlers](#add-custom-websocket-handlers)
15 - [Add external auth methods](#add-external-auth-methods) 16 - [Add external auth methods](#add-external-auth-methods)
16 - [Add new transcoding profiles](#add-new-transcoding-profiles) 17 - [Add new transcoding profiles](#add-new-transcoding-profiles)
17 - [Server helpers](#server-helpers) 18 - [Server helpers](#server-helpers)
@@ -317,6 +318,41 @@ The `ping` route can be accessed using:
317 * Or `/plugins/:pluginName/router/ping` 318 * Or `/plugins/:pluginName/router/ping`
318 319
319 320
321#### Add custom WebSocket handlers
322
323You can create custom WebSocket servers (like [ws](https://github.com/websockets/ws) for example) using `registerWebSocketRoute`:
324
325```js
326function register ({
327 registerWebSocketRoute,
328 peertubeHelpers
329}) {
330 const wss = new WebSocketServer({ noServer: true })
331
332 wss.on('connection', function connection(ws) {
333 peertubeHelpers.logger.info('WebSocket connected!')
334
335 setInterval(() => {
336 ws.send('WebSocket message sent by server');
337 }, 1000)
338 })
339
340 registerWebSocketRoute({
341 route: '/my-websocket-route',
342
343 handler: (request, socket, head) => {
344 wss.handleUpgrade(request, socket, head, ws => {
345 wss.emit('connection', ws, request)
346 })
347 }
348 })
349}
350```
351
352The `my-websocket-route` route can be accessed using:
353 * `/plugins/:pluginName/:pluginVersion/ws/my-websocket-route`
354 * Or `/plugins/:pluginName/ws/my-websocket-route`
355
320#### Add external auth methods 356#### Add external auth methods
321 357
322If you want to add a classic username/email and password auth method (like [LDAP](https://framagit.org/framasoft/peertube/official-plugins/-/tree/master/peertube-plugin-auth-ldap) for example): 358If you want to add a classic username/email and password auth method (like [LDAP](https://framagit.org/framasoft/peertube/official-plugins/-/tree/master/peertube-plugin-auth-ldap) for example):