Browse Source

closes #29, reliable channel now created at the right point.

Michelle Bu 12 years ago
parent
commit
d2a9bc036a
4 changed files with 27 additions and 13 deletions
  1. 1 1
      deps/reliable
  2. 20 7
      dist/peer.js
  3. 0 0
      dist/peer.min.js
  4. 6 5
      lib/dataconnection.js

+ 1 - 1
deps/reliable

@@ -1 +1 @@
-Subproject commit 674cdac650f6c737addabaf78dca4e86cc1ec011
+Subproject commit 46e84b50d2534f0f14ce7c8d90fc173277b7977e

+ 20 - 7
dist/peer.js

@@ -903,12 +903,13 @@ Reliable.prototype._intervalSend = function(msg) {
   if (self._queue.length === 0) {
   if (self._queue.length === 0) {
     clearTimeout(self._timeout);
     clearTimeout(self._timeout);
     self._timeout = null;
     self._timeout = null;
-    //self._processAcks();
+    self._processAcks();
   }
   }
 };
 };
 
 
 // Go through ACKs to send missing pieces.
 // Go through ACKs to send missing pieces.
 Reliable.prototype._processAcks = function() {
 Reliable.prototype._processAcks = function() {
+  // processAcks
   for (var id in this._outgoing) {
   for (var id in this._outgoing) {
     if (this._outgoing.hasOwnProperty(id)) {
     if (this._outgoing.hasOwnProperty(id)) {
       this._sendWindowedChunks(id);
       this._sendWindowedChunks(id);
@@ -1080,11 +1081,20 @@ Reliable.prototype._sendWindowedChunks = function(id) {
   var limit = Math.min(data.ack + this._window, ch.length);
   var limit = Math.min(data.ack + this._window, ch.length);
   for (var i = data.ack; i < limit; i += 1) {
   for (var i = data.ack; i < limit; i += 1) {
     if (!ch[i].sent || i === data.ack) {
     if (!ch[i].sent || i === data.ack) {
+      // Sliding window.
+      if (i === data.ack && ch[i].sent) {
+        this._window = Math.max(1, Math.round(this._window / 10));
+        limit = Math.min(data.ack + this._window, ch.length);
+      } else if (i === data.ack) {
+        this._window = Math.min(1000, Math.round(this._window * 10));
+        limit = Math.min(data.ack + this._window, ch.length);
+      }
+
       ch[i].sent = true;
       ch[i].sent = true;
       chunks.push(['chunk', id, i, ch[i].payload]);
       chunks.push(['chunk', id, i, ch[i].payload]);
     }
     }
   }
   }
-  if (data.ack + this._window >= ch.length) {
+  if (data.ack + this._window >= ch.length - 1) {
     chunks.push(['end', id, ch.length])
     chunks.push(['end', id, ch.length])
   }
   }
   chunks._multiple = true;
   chunks._multiple = true;
@@ -1095,10 +1105,12 @@ Reliable.prototype._sendWindowedChunks = function(id) {
 // Puts together a message from chunks.
 // Puts together a message from chunks.
 Reliable.prototype._complete = function(id) {
 Reliable.prototype._complete = function(id) {
   // FIXME: handle errors.
   // FIXME: handle errors.
+  util.log('Complete', id);
   var self = this;
   var self = this;
   var chunks = this._incoming[id].chunks;
   var chunks = this._incoming[id].chunks;
   var bl = new Blob(chunks);
   var bl = new Blob(chunks);
   util.blobToArrayBuffer(bl, function(ab) {
   util.blobToArrayBuffer(bl, function(ab) {
+    util.log('Calling onmessage with complete message');
     self.onmessage(util.unpack(ab));
     self.onmessage(util.unpack(ab));
   });
   });
   delete this._incoming[id];
   delete this._incoming[id];
@@ -1436,6 +1448,12 @@ DataConnection.prototype._configureDataChannel = function() {
     self.open = true;
     self.open = true;
     self.emit('open');
     self.emit('open');
   };
   };
+
+  // Reliable.
+  if (this._isReliable) {
+    this._reliable = new Reliable(this._dc, util.debug);
+  }
+
   if (this._reliable) {
   if (this._reliable) {
     this._reliable.onmessage = function(msg) {
     this._reliable.onmessage = function(msg) {
       self.emit('data', msg);
       self.emit('data', msg);
@@ -1450,11 +1468,6 @@ DataConnection.prototype._configureDataChannel = function() {
     self.close();
     self.close();
   };
   };
 
 
-  // Reliable.
-  if (this._isReliable) {
-    this._reliable = new Reliable(this._dc, util.debug);
-  }
-
 };
 };
 
 
 DataConnection.prototype._cleanup = function() {
 DataConnection.prototype._cleanup = function() {

File diff suppressed because it is too large
+ 0 - 0
dist/peer.min.js


+ 6 - 5
lib/dataconnection.js

@@ -37,6 +37,12 @@ DataConnection.prototype._configureDataChannel = function() {
     self.open = true;
     self.open = true;
     self.emit('open');
     self.emit('open');
   };
   };
+
+  // Reliable.
+  if (this._isReliable) {
+    this._reliable = new Reliable(this._dc, util.debug);
+  }
+
   if (this._reliable) {
   if (this._reliable) {
     this._reliable.onmessage = function(msg) {
     this._reliable.onmessage = function(msg) {
       self.emit('data', msg);
       self.emit('data', msg);
@@ -51,11 +57,6 @@ DataConnection.prototype._configureDataChannel = function() {
     self.close();
     self.close();
   };
   };
 
 
-  // Reliable.
-  if (this._isReliable) {
-    this._reliable = new Reliable(this._dc, util.debug);
-  }
-
 };
 };
 
 
 DataConnection.prototype._cleanup = function() {
 DataConnection.prototype._cleanup = function() {

Some files were not shown because too many files changed in this diff