Quellcode durchsuchen

Make Chrome and Firefox interoperable for large messages

Sören Balko vor 11 Jahren
Ursprung
Commit
02468a9d24
2 geänderte Dateien mit 6 neuen und 2 gelöschten Zeilen
  1. 2 1
      lib/dataconnection.js
  2. 4 1
      lib/util.js

+ 2 - 1
lib/dataconnection.js

@@ -163,7 +163,8 @@ DataConnection.prototype.send = function(data, chunked) {
     var utf8 = (this.serialization === 'binary-utf8');
     var utf8 = (this.serialization === 'binary-utf8');
     var blob = util.pack(data, utf8);
     var blob = util.pack(data, utf8);
 
 
-    if (util.browser !== 'Firefox' && !chunked && blob.size > util.chunkedMTU) {
+    // For Chrome-Firefox interoperability, we need to make Firefox "chunking" the data it sends out. Future sophistication of this approach could make the decision on chunking dependent on the remote browser.
+    if (/*util.browser !== 'Firefox' && */!chunked && blob.size > util.chunkedMTU) {
       this._sendChunks(blob);
       this._sendChunks(blob);
       return;
       return;
     }
     }

+ 4 - 1
lib/util.js

@@ -6,7 +6,7 @@ var util = {
 
 
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_PORT: 9000,
   CLOUD_PORT: 9000,
-  chunkedMTU: 60000, // 60KB
+  chunkedMTU: 16300, // The original 60000 bytes setting does not work when sending data from Firefox to Chrome, which is "cut off" after 16384 bytes and delivered individually. I suspect a bug in either Chrome or Firefox behind this.
 
 
   // Logging logic
   // Logging logic
   logLevel: 0,
   logLevel: 0,
@@ -107,11 +107,14 @@ var util = {
 
 
     if (data) {
     if (data) {
       // Binary test
       // Binary test
+      // Commented out the "binary blob" feature detection. Firefox supports sending Blobs, whereas Chrome does not. Hence we agree on the common denominator (which is using plain ArrayBuffers).
+      /*
       try {
       try {
         dc.binaryType = 'blob';
         dc.binaryType = 'blob';
         binaryBlob = true;
         binaryBlob = true;
       } catch (e) {
       } catch (e) {
       }
       }
+      */
 
 
       // Reliable test.
       // Reliable test.
       // Unfortunately Chrome is a bit unreliable about whether or not they
       // Unfortunately Chrome is a bit unreliable about whether or not they