Fixes for PR #128

This commit is contained in:
Feross Aboukhadijeh 2016-03-15 21:33:43 -07:00
parent 5d4cf75e0a
commit ede2119f78

View File

@ -87,24 +87,25 @@ function Client (peerId, port, torrent, opts) {
} else if (protocol === 'udp:' && typeof UDPTracker === 'function') {
return new UDPTracker(self, announceUrl)
} else if ((protocol === 'ws:' || protocol === 'wss:') && webrtcSupport) {
// Don't try to add http tracker on an https website
if (protocol === 'ws:' && location && location.protocol && location.protocol === 'https:') {
process.nextTick(function () {
var err = new Error('unsupported http tracker on https: ' + announceUrl)
self.emit('warning', err)
})
// Skip ws:// trackers on https:// sites because they throw SecurityError
if (protocol === 'ws:' && typeof window !== 'undefined' &&
window.location.protocol === 'https:') {
nextTickWarn(new Error('Unsupported tracker protocol: ' + announceUrl))
return null
}
return new WebSocketTracker(self, announceUrl)
} else {
nextTickWarn(new Error('Unsupported tracker protocol: ' + announceUrl))
return null
}
})
.filter(Boolean)
function nextTickWarn (err) {
process.nextTick(function () {
var err = new Error('unsupported tracker protocol for ' + announceUrl)
self.emit('warning', err)
})
}
return null
})
.filter(Boolean)
}
/**