File tree Expand file tree Collapse file tree 2 files changed +15
-22
lines changed
Expand file tree Collapse file tree 2 files changed +15
-22
lines changed Original file line number Diff line number Diff line change @@ -61,23 +61,9 @@ class Server extends EventEmitter {
6161 this . peersCacheLength = peersCacheLength
6262 this . peersCacheTtl = peersCacheTtl
6363
64- if ( opts . http !== false ) attachHttpService ( this , onListening )
65- if ( opts . ws !== false ) attachWSService ( this , onListening )
66- if ( opts . stats !== false ) setupStatsRoute ( this , onListening )
67-
68- // TODO: UGH
69- let num = ! ! this . http
70- this . num = num
71-
72- const self = this
73- function onListening ( ) {
74- num -= 1
75- if ( num === 0 ) {
76- self . listening = true
77- debug ( 'listening' )
78- self . emit ( 'listening' )
79- }
80- }
64+ if ( opts . http !== false ) attachHttpService ( this )
65+ if ( opts . ws !== false ) attachWSService ( this )
66+ if ( opts . stats !== false ) setupStatsRoute ( this )
8167 }
8268
8369 onError ( err ) {
Original file line number Diff line number Diff line change 1+ const debug = require ( 'debug' ) ( 'bittorrent-tracker:server' )
2+
13const http = require ( 'http' )
24const bencode = require ( 'bencode' )
35
46const common = require ( '../../../lib/common' )
57const parseHttpRequest = require ( './parseHttpRequest' )
68
7- function attachHttpServer ( server , onListening ) {
8- const {
9- onError
10- } = server
11-
9+ function attachHttpServer ( server ) {
1210 const httpServer = http . createServer ( )
1311
12+ const onListening = ( ) => {
13+ server . listening = true
14+ debug ( 'listening' )
15+ server . emit ( 'listening' )
16+ }
17+
18+ const onError = ( ...args ) => { server . onError ( ...args ) }
19+
20+
1421 httpServer . on ( 'error' , onError )
1522 httpServer . on ( 'listening' , onListening )
1623
You can’t perform that action at this time.
0 commit comments