webtorrent perf: create 5 offers at a time

This commit is contained in:
Feross Aboukhadijeh 2015-12-04 23:38:50 -08:00
parent a26a2107a8
commit 582ac990a4

View File

@ -42,9 +42,8 @@ WebSocketTracker.prototype.announce = function (opts) {
return self.socket.once('connect', self.announce.bind(self, opts))
}
// TODO: Limit number of offers (temporarily)
// TODO: remove this when we cleanup old RTCPeerConnections cleanly
var numwant = Math.min(opts.numwant, 10)
// Limit the number of offers that are generated, since it can be slow
var numwant = Math.min(opts.numwant, 5)
self._generateOffers(numwant, function (offers) {
var params = {
@ -177,6 +176,7 @@ WebSocketTracker.prototype._onSocketData = function (data) {
var peer
if (data.offer && data.peer_id) {
debug('creating peer (from remote offer)')
peer = new Peer({
trickle: false,
config: self.client._rtcConfig,
@ -260,6 +260,7 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
function generateOffer () {
var offerId = hat(160)
debug('creating peer (from _generateOffers)')
var peer = self.peers[offerId] = new Peer({
initiator: true,
trickle: false,