From 9d4c60dccc8e7e777ad139a82e9f61feda9d21fc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Oct 2022 11:07:40 +0200 Subject: Add ability for plugins to register ws routes --- .../peertube-plugin-test-websocket/main.js | 36 ++++++++++++++++++++++ .../peertube-plugin-test-websocket/package.json | 20 ++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 server/tests/fixtures/peertube-plugin-test-websocket/main.js create mode 100644 server/tests/fixtures/peertube-plugin-test-websocket/package.json (limited to 'server/tests/fixtures/peertube-plugin-test-websocket') diff --git a/server/tests/fixtures/peertube-plugin-test-websocket/main.js b/server/tests/fixtures/peertube-plugin-test-websocket/main.js new file mode 100644 index 000000000..3fde76cfe --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-websocket/main.js @@ -0,0 +1,36 @@ +const WebSocketServer = require('ws').WebSocketServer + +async function register ({ + registerWebSocketRoute +}) { + const wss = new WebSocketServer({ noServer: true }) + + wss.on('connection', function connection(ws) { + ws.on('message', function message(data) { + if (data.toString() === 'ping') { + ws.send('pong') + } + }) + }) + + registerWebSocketRoute({ + route: '/toto', + + handler: (request, socket, head) => { + wss.handleUpgrade(request, socket, head, ws => { + wss.emit('connection', ws, request) + }) + } + }) +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ########################################################################### diff --git a/server/tests/fixtures/peertube-plugin-test-websocket/package.json b/server/tests/fixtures/peertube-plugin-test-websocket/package.json new file mode 100644 index 000000000..89c8baa04 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-websocket/package.json @@ -0,0 +1,20 @@ +{ + "name": "peertube-plugin-test-websocket", + "version": "0.0.1", + "description": "Plugin test websocket", + "engine": { + "peertube": ">=1.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://github.com/Chocobozzz/PeerTube", + "author": "Chocobozzz", + "bugs": "https://github.com/Chocobozzz/PeerTube/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {} +} -- cgit v1.2.3