]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/fixtures/peertube-plugin-test-websocket/main.js
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test-websocket / main.js
... / ...
CommitLineData
1const WebSocketServer = require('ws').WebSocketServer
2
3async 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
27async function unregister () {
28 return
29}
30
31module.exports = {
32 register,
33 unregister
34}
35
36// ###########################################################################