fix exception in websocket tracker

This commit is contained in:
Feross Aboukhadijeh 2015-05-30 14:20:42 -07:00
parent fdb94e98d7
commit da5036424b
3 changed files with 6 additions and 0 deletions

View File

@ -44,6 +44,7 @@ function HTTPTracker (client, announceUrl, opts) {
HTTPTracker.prototype.announce = function (opts) {
var self = this
if (self.destroyed) return
if (self._trackerId) opts.trackerid = self._trackerId
if (opts.compact == null) opts.compact = 1
@ -58,6 +59,7 @@ HTTPTracker.prototype.announce = function (opts) {
HTTPTracker.prototype.scrape = function (opts) {
var self = this
if (self.destroyed) return
if (!self._scrapeUrl) {
self.client.emit('error', new Error('scrape not supported ' + self._announceUrl))

View File

@ -39,11 +39,13 @@ function UDPTracker (client, announceUrl, opts) {
UDPTracker.prototype.announce = function (opts) {
var self = this
if (self.destroyed) return
self._request(opts)
}
UDPTracker.prototype.scrape = function (opts) {
var self = this
if (self.destroyed) return
opts._scrape = true
self._request(opts) // udp scrape uses same announce url
}

View File

@ -46,6 +46,7 @@ function WebSocketTracker (client, announceUrl, opts) {
WebSocketTracker.prototype.announce = function (opts) {
var self = this
if (self.destroyed) return
if (!self._socket.connected) {
return self._socket.once('connect', self.announce.bind(self, opts))
}
@ -69,6 +70,7 @@ WebSocketTracker.prototype.announce = function (opts) {
WebSocketTracker.prototype.scrape = function (opts) {
var self = this
if (self.destroyed) return
self._onSocketError(new Error('scrape not supported ' + self._announceUrl))
}