mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Fix socket.io websocket connection
This commit is contained in:
parent
43483d1296
commit
89ada4e26c
7 changed files with 34 additions and 14 deletions
|
@ -6,6 +6,7 @@ import * as proxyAddr from 'proxy-addr'
|
|||
import { Server as WebSocketServer } from 'ws'
|
||||
import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants'
|
||||
import { VideoFileModel } from '../models/video/video-file'
|
||||
import { parse } from 'url'
|
||||
|
||||
const TrackerServer = bitTorrentTracker.Server
|
||||
|
||||
|
@ -61,14 +62,24 @@ trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { act
|
|||
|
||||
function createWebsocketTrackerServer (app: express.Application) {
|
||||
const server = http.createServer(app)
|
||||
const wss = new WebSocketServer({ server: server, path: '/tracker/socket' })
|
||||
const wss = new WebSocketServer({ noServer: true })
|
||||
|
||||
wss.on('connection', function (ws, req) {
|
||||
const ip = proxyAddr(req, CONFIG.TRUST_PROXY)
|
||||
ws['ip'] = ip
|
||||
ws['ip'] = proxyAddr(req, CONFIG.TRUST_PROXY)
|
||||
|
||||
trackerServer.onWebSocketConnection(ws)
|
||||
})
|
||||
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
const pathname = parse(request.url).pathname
|
||||
|
||||
if (pathname === '/tracker/socket') {
|
||||
wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
|
||||
}
|
||||
|
||||
// Don't destroy socket, we have Socket.IO too
|
||||
})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue