@@ -299,7 +299,7 @@ Server.prototype.onWebSocketConnection = function (socket, opts) {
299299 if ( ! opts ) opts = { }
300300 opts . trustProxy = opts . trustProxy || self . _trustProxy
301301 socket . peerId = null // as hex
302- socket . infoHashes = [ ]
302+ socket . infoHashes = [ ] // swarms that this socket is participating in
303303 socket . onSend = self . _onWebSocketSend . bind ( self , socket )
304304 socket . on ( 'message' , self . _onWebSocketRequest . bind ( self , socket , opts ) )
305305 socket . on ( 'error' , self . _onWebSocketError . bind ( self , socket ) )
@@ -337,22 +337,19 @@ 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- } )
348-
349340 response . action = params . action === common . ACTIONS . ANNOUNCE ? 'announce' : 'scrape'
350341
351342 var peers
352343 if ( response . action === 'announce' ) {
353344 peers = response . peers
354345 delete response . peers
355346
347+ params . info_hash . forEach ( function ( info_hash ) {
348+ if ( socket . infoHashes . indexOf ( info_hash ) === - 1 ) {
349+ socket . infoHashes . push ( info_hash )
350+ }
351+ } )
352+
356353 response . info_hash = common . hexToBinary ( params . info_hash )
357354
358355 // WebSocket tracker should have a shorter interval – default: 2 minutes
0 commit comments