Просмотр исходного кода

Some util.supports.reliable fixes for Chrome

Michelle Bu 11 лет назад
Родитель
Сommit
e171ee02e0
4 измененных файлов с 16 добавлено и 12 удалено
  1. 8 6
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 2 4
      lib/negotiator.js
  4. 6 2
      lib/util.js

+ 8 - 6
dist/peer.js

@@ -1129,16 +1129,20 @@ var util = {
     }
 
     if (data) {
+      // Binary test
       try {
         dc.binaryType = 'blob';
         binary = true;
       } catch (e) {
       }
 
+      // Reliable test.
+      // Unfortunately Chrome is a bit unreliable about whether or not they
+      // support reliable.
       var reliablePC = new RTCPeerConnection(defaultConfig, {});
       try {
-        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
-        reliable = true;
+        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {});
+        reliable = reliableDC.reliable && navigator.mozRTCPeerConnection;
       } catch (e) {
       }
       reliablePC.close();
@@ -1962,8 +1966,6 @@ Negotiator.startConnection = function(connection, options) {
       if (util.supports.reliable && !options.reliable) {
         // If we have canonical reliable support...
         config = {maxRetransmits: 0}
-      } else if (!util.supports.reliable) {
-        config = {reliable: options.reliable};
       }
       var dc = pc.createDataChannel(connection.label, config);
       connection.initialize(dc);
@@ -2129,7 +2131,7 @@ Negotiator._makeOffer = function(connection) {
   pc.createOffer(function(offer) {
     util.log('Created offer.');
 
-    if (!util.supports.reliable && connection.type === 'data') {
+    if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
       offer.sdp = Reliable.higherBandwidthSDP(offer.sdp);
     }
 
@@ -2164,7 +2166,7 @@ Negotiator._makeAnswer = function(connection) {
   pc.createAnswer(function(answer) {
     util.log('Created answer.');
 
-    if (!util.supports.reliable && connection.type === 'data') {
+    if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
       answer.sdp = Reliable.higherBandwidthSDP(answer.sdp);
     }
 

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
dist/peer.min.js


+ 2 - 4
lib/negotiator.js

@@ -31,8 +31,6 @@ Negotiator.startConnection = function(connection, options) {
       if (util.supports.reliable && !options.reliable) {
         // If we have canonical reliable support...
         config = {maxRetransmits: 0}
-      } else if (!util.supports.reliable) {
-        config = {reliable: options.reliable};
       }
       var dc = pc.createDataChannel(connection.label, config);
       connection.initialize(dc);
@@ -198,7 +196,7 @@ Negotiator._makeOffer = function(connection) {
   pc.createOffer(function(offer) {
     util.log('Created offer.');
 
-    if (!util.supports.reliable && connection.type === 'data') {
+    if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
       offer.sdp = Reliable.higherBandwidthSDP(offer.sdp);
     }
 
@@ -233,7 +231,7 @@ Negotiator._makeAnswer = function(connection) {
   pc.createAnswer(function(answer) {
     util.log('Created answer.');
 
-    if (!util.supports.reliable && connection.type === 'data') {
+    if (!util.supports.reliable && connection.type === 'data' && connection.reliable) {
       answer.sdp = Reliable.higherBandwidthSDP(answer.sdp);
     }
 

+ 6 - 2
lib/util.js

@@ -103,16 +103,20 @@ var util = {
     }
 
     if (data) {
+      // Binary test
       try {
         dc.binaryType = 'blob';
         binary = true;
       } catch (e) {
       }
 
+      // Reliable test.
+      // Unfortunately Chrome is a bit unreliable about whether or not they
+      // support reliable.
       var reliablePC = new RTCPeerConnection(defaultConfig, {});
       try {
-        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
-        reliable = true;
+        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {});
+        reliable = reliableDC.reliable && navigator.mozRTCPeerConnection;
       } catch (e) {
       }
       reliablePC.close();

Некоторые файлы не были показаны из-за большого количества измененных файлов