diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/tracker.ts | 17 |
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' | |||
6 | import { Server as WebSocketServer } from 'ws' | 6 | import { Server as WebSocketServer } from 'ws' |
7 | import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' | 7 | import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' |
8 | import { VideoFileModel } from '../models/video/video-file' | 8 | import { VideoFileModel } from '../models/video/video-file' |
9 | import { parse } from 'url' | ||
9 | 10 | ||
10 | const TrackerServer = bitTorrentTracker.Server | 11 | const TrackerServer = bitTorrentTracker.Server |
11 | 12 | ||
@@ -61,14 +62,24 @@ trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { act | |||
61 | 62 | ||
62 | function createWebsocketTrackerServer (app: express.Application) { | 63 | function 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 | ||