@@ -27,22 +27,22 @@ function WebSocketTracker (client, announceUrl, opts) {
2727 self . _opts = opts
2828 self . _announceUrl = announceUrl
2929 self . _peers = { } // peers (offer id -> peer)
30- self . _ready = false
3130 self . _socket = null
3231 self . _intervalMs = self . client . _intervalMs // use client interval initially
3332 self . _interval = null
3433
3534 if ( socketPool [ announceUrl ] ) self . _socket = socketPool [ announceUrl ]
3635 else self . _socket = socketPool [ announceUrl ] = new Socket ( announceUrl )
3736
38- self . _socket . on ( 'warning' , self . _onSocketWarning . bind ( self ) )
39- self . _socket . on ( 'error' , self . _onSocketWarning . bind ( self ) ) // TODO: handle error
40- self . _socket . on ( 'message' , self . _onSocketMessage . bind ( self ) )
37+ self . _socket . on ( 'error' , self . _onSocketError . bind ( self ) )
38+ self . _socket . on ( 'data' , self . _onSocketData . bind ( self ) )
4139}
4240
4341WebSocketTracker . prototype . announce = function ( opts ) {
4442 var self = this
45- if ( ! self . _socket . ready ) return self . _socket . on ( 'ready' , self . announce . bind ( self , opts ) )
43+ if ( ! self . _socket . connected ) {
44+ return self . _socket . on ( 'connect' , self . announce . bind ( self , opts ) )
45+ }
4646
4747 opts . info_hash = self . client . _infoHash . toString ( 'binary' )
4848 opts . peer_id = self . client . _peerId . toString ( 'binary' )
@@ -59,8 +59,7 @@ WebSocketTracker.prototype.announce = function (opts) {
5959
6060WebSocketTracker . prototype . scrape = function ( opts ) {
6161 var self = this
62- self . client . emit ( 'error' , new Error ( 'scrape not supported ' + self . _announceUrl ) )
63- return
62+ self . _onSocketError ( new Error ( 'scrape not supported ' + self . _announceUrl ) )
6463}
6564
6665// TODO: Improve this interface
@@ -76,11 +75,12 @@ WebSocketTracker.prototype.setInterval = function (intervalMs) {
7675 }
7776}
7877
79- WebSocketTracker . prototype . _onSocketWarning = function ( err ) {
80- debug ( 'tracker warning %s' , err . message )
78+ WebSocketTracker . prototype . _onSocketError = function ( err ) {
79+ var self = this
80+ self . client . emit ( 'error' , err )
8181}
8282
83- WebSocketTracker . prototype . _onSocketMessage = function ( data ) {
83+ WebSocketTracker . prototype . _onSocketData = function ( data ) {
8484 var self = this
8585
8686 if ( ! ( typeof data === 'object' && data !== null ) ) {
0 commit comments