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/peertube-plugin-test-websocket/main.js | |
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/peertube-plugin-test-websocket/main.js')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-websocket/main.js | 36 |
1 files changed, 36 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 | // ########################################################################### | ||