@@ -327,7 +327,7 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
327327 self . _onRequest ( params , function ( err , response ) {
328328 if ( err ) {
329329 socket . send ( JSON . stringify ( {
330- action : params . action ,
330+ action : params . action === common . ACTIONS . ANNOUNCE ? 'announce' : 'scrape' ,
331331 'failure reason' : err . message ,
332332 info_hash : common . hexToBinary ( params . info_hash )
333333 } ) , socket . onSend )
@@ -337,22 +337,18 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
337337 }
338338 if ( self . destroyed ) return
339339
340- var hashes
341- if ( typeof params . info_hash === 'string' ) hashes = [ params . info_hash ]
342- else hashes = params . info_hash
343- hashes . forEach ( function ( info_hash ) {
344- if ( socket . infoHashes . indexOf ( info_hash ) === - 1 ) {
345- socket . infoHashes . push ( info_hash )
346- }
347- } )
340+ response . action = params . action === common . ACTIONS . ANNOUNCE ? 'announce' : 'scrape'
348341
349- var peers = response . peers
350- delete response . peers
342+ var peers
343+ if ( response . action === 'announce' ) {
344+ peers = response . peers
345+ delete response . peers
351346
352- // WebSocket tracker should have a shorter interval – default: 2 minutes
353- response . interval = Math . ceil ( self . intervalMs / 1000 / 5 )
347+ response . info_hash = common . hexToBinary ( params . info_hash )
354348
355- response . info_hash = common . hexToBinary ( params . info_hash )
349+ // WebSocket tracker should have a shorter interval – default: 2 minutes
350+ response . interval = Math . ceil ( self . intervalMs / 1000 / 5 )
351+ }
356352
357353 socket . send ( JSON . stringify ( response ) , socket . onSend )
358354 debug ( 'sent response %s to %s' , JSON . stringify ( response ) , params . peer_id )
0 commit comments