diff options
author | Chocobozzz <me@florianbigard.com> | 2022-10-11 11:07:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-10-11 11:11:04 +0200 |
commit | 9d4c60dccc8e7e777ad139a82e9f61feda9d21fc (patch) | |
tree | 2931338f340b398d36c43575fea95cf1fbbfeb4c /server/tests/fixtures | |
parent | 9866921cbf3f8f0925f7ffb3a231d5dfe2d30953 (diff) | |
download | PeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.tar.gz PeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.tar.zst PeerTube-9d4c60dccc8e7e777ad139a82e9f61feda9d21fc.zip |
Add ability for plugins to register ws routes
Diffstat (limited to 'server/tests/fixtures')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-websocket/main.js | 36 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-websocket/package.json | 20 |
2 files changed, 56 insertions, 0 deletions
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 @@ | |||
1 | const WebSocketServer = require('ws').WebSocketServer | ||
2 | |||
3 | async function register ({ | ||
4 | registerWebSocketRoute | ||
5 | }) { | ||
6 | const wss = new WebSocketServer({ noServer: true }) | ||
7 | |||
8 | wss.on('connection', function connection(ws) { | ||
9 | ws.on('message', function message(data) { | ||
10 | if (data.toString() === 'ping') { | ||
11 | ws.send('pong') | ||
12 | } | ||
13 | }) | ||
14 | }) | ||
15 | |||
16 | registerWebSocketRoute({ | ||
17 | route: '/toto', | ||
18 | |||
19 | handler: (request, socket, head) => { | ||
20 | wss.handleUpgrade(request, socket, head, ws => { | ||
21 | wss.emit('connection', ws, request) | ||
22 | }) | ||
23 | } | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | async function unregister () { | ||
28 | return | ||
29 | } | ||
30 | |||
31 | module.exports = { | ||
32 | register, | ||
33 | unregister | ||
34 | } | ||
35 | |||
36 | // ########################################################################### | ||
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 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-websocket", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Plugin test websocket", | ||
5 | "engine": { | ||
6 | "peertube": ">=1.3.0" | ||
7 | }, | ||
8 | "keywords": [ | ||
9 | "peertube", | ||
10 | "plugin" | ||
11 | ], | ||
12 | "homepage": "https://github.com/Chocobozzz/PeerTube", | ||
13 | "author": "Chocobozzz", | ||
14 | "bugs": "https://github.com/Chocobozzz/PeerTube/issues", | ||
15 | "library": "./main.js", | ||
16 | "staticDirs": {}, | ||
17 | "css": [], | ||
18 | "clientScripts": [], | ||
19 | "translations": {} | ||
20 | } | ||