aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/tracker.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-08 15:51:52 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commit89ada4e26ca1df8ff0dd02acda1d1661f121a294 (patch)
treeb8c8d373d8140227c3b73bbf14d5e1b15d877ee2 /server/controllers/tracker.ts
parent43483d12963ed7a82adee2e35a7bcb7e55e54b3e (diff)
downloadPeerTube-89ada4e26ca1df8ff0dd02acda1d1661f121a294.tar.gz
PeerTube-89ada4e26ca1df8ff0dd02acda1d1661f121a294.tar.zst
PeerTube-89ada4e26ca1df8ff0dd02acda1d1661f121a294.zip
Fix socket.io websocket connection
Diffstat (limited to 'server/controllers/tracker.ts')
-rw-r--r--server/controllers/tracker.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts
index 53f1653b5..1deb8c402 100644
--- a/server/controllers/tracker.ts
+++ b/server/controllers/tracker.ts
@@ -6,6 +6,7 @@ import * as proxyAddr from 'proxy-addr'
6import { Server as WebSocketServer } from 'ws' 6import { Server as WebSocketServer } from 'ws'
7import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' 7import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants'
8import { VideoFileModel } from '../models/video/video-file' 8import { VideoFileModel } from '../models/video/video-file'
9import { parse } from 'url'
9 10
10const TrackerServer = bitTorrentTracker.Server 11const TrackerServer = bitTorrentTracker.Server
11 12
@@ -61,14 +62,24 @@ trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { act
61 62
62function createWebsocketTrackerServer (app: express.Application) { 63function createWebsocketTrackerServer (app: express.Application) {
63 const server = http.createServer(app) 64 const server = http.createServer(app)
64 const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) 65 const wss = new WebSocketServer({ noServer: true })
66
65 wss.on('connection', function (ws, req) { 67 wss.on('connection', function (ws, req) {
66 const ip = proxyAddr(req, CONFIG.TRUST_PROXY) 68 ws['ip'] = proxyAddr(req, CONFIG.TRUST_PROXY)
67 ws['ip'] = ip
68 69
69 trackerServer.onWebSocketConnection(ws) 70 trackerServer.onWebSocketConnection(ws)
70 }) 71 })
71 72
73 server.on('upgrade', (request, socket, head) => {
74 const pathname = parse(request.url).pathname
75
76 if (pathname === '/tracker/socket') {
77 wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
78 }
79
80 // Don't destroy socket, we have Socket.IO too
81 })
82
72 return server 83 return server
73} 84}
74 85