Skip to content

Commit

Permalink
the exchange seems to work with more peers (test up to 6...), fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Chat-Wane committed May 28, 2015
1 parent 1d9369b commit e6cb651
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/spray.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ util.inherits(Spray, EventEmitter);
function Spray(id, options){
EventEmitter.call(this);
// #A constants
this.DELTATIME = 1000 * 60 * 10; // 10min
this.DELTATIME = 1000 * 60 * 2; // 10min
this.TIMEOUT = 1000 * 60 * 1 // 1min
this.ID = id;

Expand All @@ -34,12 +34,12 @@ function Spray(id, options){
this.forwards = new Sockets();

// #C webrtc specifics
// var self = this;
// setInterval(function(){
// if (self.partialView.length()>0){
// self.exchange();
// };
// }, this.DELTATIME);
var self = this;
setInterval(function(){
if (self.partialView.length()>0){
self.exchange();
};
}, this.DELTATIME);
};

/*!
Expand Down Expand Up @@ -120,7 +120,6 @@ Spray.prototype.exchange = function(){
var socket = this.sockets.removeSocket(sample[i]);
// #8C close the socket after a while
setTimeout(function(s){
console.log("miaou");
s.destroy();
}, this.TIMEOUT, socket);
};
Expand All @@ -134,7 +133,7 @@ Spray.prototype.exchange = function(){
*/
Spray.prototype.onExchange = function(id, initiator){
// #1 get a sample of neighbors from our partial view
var sample = this.partialView.getSample(this.ID, initiator, false);
var sample = this.partialView.getSample(initiator, false);
// #2 ask to each neighbor in the sample to create an offer ticket to
// give to the initiator peer
for (var i = 0; i < sample.length; ++i){
Expand Down Expand Up @@ -167,7 +166,6 @@ Spray.prototype.onExchange = function(id, initiator){
var socket = this.sockets.removeSocket(sample[i])
// #5C close the socket after a while
setTimeout(function(s){
console.log("miaou2");
s.destroy();
}, this.TIMEOUT, socket);
};
Expand Down

0 comments on commit e6cb651

Please sign in to comment.