@@ -277,13 +277,11 @@ class Server extends EventEmitter {
277277 }
278278
279279 listen ( ...args ) /* port, hostname, onlistening */ {
280- const self = this
281-
282- if ( self . _listenCalled || self . listening ) throw new Error ( 'server already listening' )
283- self . _listenCalled = true
280+ if ( this . _listenCalled || this . listening ) throw new Error ( 'server already listening' )
281+ this . _listenCalled = true
284282
285283 const lastArg = args [ args . length - 1 ]
286- if ( typeof lastArg === 'function' ) self . once ( 'listening' , lastArg )
284+ if ( typeof lastArg === 'function' ) this . once ( 'listening' , lastArg )
287285
288286 const port = toNumber ( args [ 0 ] ) || args [ 0 ] || 0
289287 const hostname = typeof args [ 1 ] !== 'function' ? args [ 1 ] : undefined
@@ -303,9 +301,9 @@ class Server extends EventEmitter {
303301 const udp4Hostname = isObject ( hostname ) ? hostname . udp : hostname
304302 const udp6Hostname = isObject ( hostname ) ? hostname . udp6 : hostname
305303
306- if ( self . http ) self . http . listen ( httpPort , httpHostname )
307- if ( self . udp4 ) self . udp4 . bind ( udpPort , udp4Hostname )
308- if ( self . udp6 ) self . udp6 . bind ( udpPort , udp6Hostname )
304+ if ( this . http ) this . http . listen ( httpPort , httpHostname )
305+ if ( this . udp4 ) this . udp4 . bind ( udpPort , udp4Hostname )
306+ if ( this . udp6 ) this . udp6 . bind ( udpPort , udp6Hostname )
309307 }
310308
311309 close ( cb = noop ) {
@@ -429,28 +427,27 @@ class Server extends EventEmitter {
429427 }
430428
431429 onWebSocketConnection ( socket , opts ) {
432- const self = this
433430 if ( ! opts ) opts = { }
434- opts . trustProxy = opts . trustProxy || self . _trustProxy
431+ opts . trustProxy = opts . trustProxy || this . _trustProxy
435432
436433 socket . peerId = null // as hex
437434 socket . infoHashes = [ ] // swarms that this socket is participating in
438435 socket . onSend = err => {
439- self . _onWebSocketSend ( socket , err )
436+ this . _onWebSocketSend ( socket , err )
440437 }
441438
442439 socket . onMessageBound = params => {
443- self . _onWebSocketRequest ( socket , opts , params )
440+ this . _onWebSocketRequest ( socket , opts , params )
444441 }
445442 socket . on ( 'message' , socket . onMessageBound )
446443
447444 socket . onErrorBound = err => {
448- self . _onWebSocketError ( socket , err )
445+ this . _onWebSocketError ( socket , err )
449446 }
450447 socket . on ( 'error' , socket . onErrorBound )
451448
452449 socket . onCloseBound = ( ) => {
453- self . _onWebSocketClose ( socket )
450+ this . _onWebSocketClose ( socket )
454451 }
455452 socket . on ( 'close' , socket . onCloseBound )
456453 }
@@ -564,18 +561,16 @@ class Server extends EventEmitter {
564561 }
565562
566563 _onWebSocketSend ( socket , err ) {
567- const self = this
568- if ( err ) self . _onWebSocketError ( socket , err )
564+ if ( err ) this . _onWebSocketError ( socket , err )
569565 }
570566
571567 _onWebSocketClose ( socket ) {
572- const self = this
573568 debug ( 'websocket close %s' , socket . peerId )
574569 socket . destroyed = true
575570
576571 if ( socket . peerId ) {
577572 socket . infoHashes . slice ( 0 ) . forEach ( infoHash => {
578- const swarm = self . torrents [ infoHash ]
573+ const swarm = this . torrents [ infoHash ]
579574 if ( swarm ) {
580575 swarm . announce ( {
581576 type : 'ws' ,
@@ -611,20 +606,18 @@ class Server extends EventEmitter {
611606 }
612607
613608 _onWebSocketError ( socket , err ) {
614- const self = this
615609 debug ( 'websocket error %s' , err . message || err )
616- self . emit ( 'warning' , err )
617- self . _onWebSocketClose ( socket )
610+ this . emit ( 'warning' , err )
611+ this . _onWebSocketClose ( socket )
618612 }
619613
620614 _onRequest ( params , cb ) {
621- const self = this
622615 if ( params && params . action === common . ACTIONS . CONNECT ) {
623616 cb ( null , { action : common . ACTIONS . CONNECT } )
624617 } else if ( params && params . action === common . ACTIONS . ANNOUNCE ) {
625- self . _onAnnounce ( params , cb )
618+ this . _onAnnounce ( params , cb )
626619 } else if ( params && params . action === common . ACTIONS . SCRAPE ) {
627- self . _onScrape ( params , cb )
620+ this . _onScrape ( params , cb )
628621 } else {
629622 cb ( new Error ( 'Invalid action' ) )
630623 }
0 commit comments