Michelle Bu 11 éve
szülő
commit
dc7b558875
3 módosított fájl, 108 hozzáadás és 120 törlés
  1. 54 60
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 54 60
      lib/util.js

+ 54 - 60
dist/peer.js

@@ -1101,9 +1101,17 @@ var util = {
 
   // Lists which features are supported
   supports: (function() {
+    if (typeof RTCPeerConnection === 'undefined') {
+      return {};
+    }
+
     var data = true;
     var audioVideo = true;
 
+    var binary = false;
+    var reliable = false;
+    var onnegotiationneeded = false;
+
     var pc, dc;
     try {
       pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
@@ -1114,79 +1122,65 @@ var util = {
 
     if (data) {
       try {
-        dc = pc.createDataChannel('_PEERJSDATATEST');
+        dc = pc.createDataChannel('_PEERJSTEST');
       } catch (e) {
         data = false;
       }
     }
+
+    if (data) {
+      try {
+        dc.binaryType = 'blob';
+        binary = true;
+      } catch (e) {
+      }
+
+      var reliablePC = new RTCPeerConnection(defaultConfig, {});
+      try {
+        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
+        reliable = true;
+      } catch (e) {
+      }
+      reliablePC.close();
+    }
+
     // FIXME: not really the best check...
     if (audioVideo) {
       audioVideo = !!pc.addStream;
     }
 
-    pc.close();
-    dc.close();
+    if (/** audioVideo || */data) {
+      // sync default check.
+      var negotiationPC = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
+      negotiationPC.onnegotiationneeded = function() {
+        onnegotiationneeded = true;
+        // async check.
+        if (util && util.supports) {
+          util.supports.onnegotiationneeded = true;
+        }
+      };
+      // FIXME: this is not great because in theory it doesn't work for
+      // av-only browsers (?).
+      var negotiationDC = negotiationPC.createDataChannel('_PEERJSRELIABLETEST');
+
+      negotiationPC.close();
+      negotiationDC.close();
+    }
+
+    // FIXME: Make SURE these are closed.
+    if (pc) {
+      pc.close();
+    }
+    if (dc) {
+      dc.close();
+    }
 
     return {
       audioVideo: audioVideo,
       data: data,
-      binary: data && (function() {
-        var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
-        var dc = pc.createDataChannel('_PEERJSBINARYTEST');
-
-        try {
-          dc.binaryType = 'blob';
-        } catch (e) {
-          pc.close();
-          if (e.name === 'NotSupportedError') {
-            return false
-          }
-        }
-        pc.close();
-        dc.close();
-
-        return true;
-      })(),
-
-      reliable: data && (function() {
-        // Reliable (not RTP).
-        var pc = new RTCPeerConnection(defaultConfig, {});
-        var dc;
-        try {
-          dc = pc.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
-        } catch (e) {
-          pc.close();
-          if (e.name === 'NotSupportedError') {
-            return false
-          }
-        }
-        pc.close();
-        dc.close();
-
-        return true;
-      })(),
-
-      onnegotiationneeded: (data || audioVideo) && (function() {
-        var pc = new RTCPeerConnection(defaultConfig, {});
-        // sync default check.
-        var called = false;
-        var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
-        pc.onnegotiationneeded = function() {
-          called = true;
-          // async check.
-          if (util && util.supports) {
-            util.supports.onnegotiationneeded = true;
-          }
-        };
-        // FIXME: this is not great because in theory it doesn't work for
-        // av-only browsers (?).
-        var dc = pc.createDataChannel('_PEERJSRELIABLETEST');
-
-        pc.close();
-        dc.close();
-
-        return called;
-      })()
+      binary: binary,
+      reliable: reliable,
+      onnegotiationneeded: onnegotiationneeded
     };
   }()),
   //

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/peer.min.js


+ 54 - 60
lib/util.js

@@ -75,9 +75,17 @@ var util = {
 
   // Lists which features are supported
   supports: (function() {
+    if (typeof RTCPeerConnection === 'undefined') {
+      return {};
+    }
+
     var data = true;
     var audioVideo = true;
 
+    var binary = false;
+    var reliable = false;
+    var onnegotiationneeded = false;
+
     var pc, dc;
     try {
       pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
@@ -88,79 +96,65 @@ var util = {
 
     if (data) {
       try {
-        dc = pc.createDataChannel('_PEERJSDATATEST');
+        dc = pc.createDataChannel('_PEERJSTEST');
       } catch (e) {
         data = false;
       }
     }
+
+    if (data) {
+      try {
+        dc.binaryType = 'blob';
+        binary = true;
+      } catch (e) {
+      }
+
+      var reliablePC = new RTCPeerConnection(defaultConfig, {});
+      try {
+        var reliableDC = reliablePC.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
+        reliable = true;
+      } catch (e) {
+      }
+      reliablePC.close();
+    }
+
     // FIXME: not really the best check...
     if (audioVideo) {
       audioVideo = !!pc.addStream;
     }
 
-    pc.close();
-    dc.close();
-
-    return {
-      audioVideo: audioVideo,
-      data: data,
-      binary: data && (function() {
-        var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
-        var dc = pc.createDataChannel('_PEERJSBINARYTEST');
-
-        try {
-          dc.binaryType = 'blob';
-        } catch (e) {
-          pc.close();
-          if (e.name === 'NotSupportedError') {
-            return false
-          }
-        }
-        pc.close();
-        dc.close();
-
-        return true;
-      })(),
-
-      reliable: data && (function() {
-        // Reliable (not RTP).
-        var pc = new RTCPeerConnection(defaultConfig, {});
-        var dc;
-        try {
-          dc = pc.createDataChannel('_PEERJSRELIABLETEST', {maxRetransmits: 0});
-        } catch (e) {
-          pc.close();
-          if (e.name === 'NotSupportedError') {
-            return false
-          }
+    if (/** audioVideo || */data) {
+      // sync default check.
+      var negotiationPC = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
+      negotiationPC.onnegotiationneeded = function() {
+        onnegotiationneeded = true;
+        // async check.
+        if (util && util.supports) {
+          util.supports.onnegotiationneeded = true;
         }
-        pc.close();
-        dc.close();
+      };
+      // FIXME: this is not great because in theory it doesn't work for
+      // av-only browsers (?).
+      var negotiationDC = negotiationPC.createDataChannel('_PEERJSRELIABLETEST');
 
-        return true;
-      })(),
-
-      onnegotiationneeded: (data || audioVideo) && (function() {
-        var pc = new RTCPeerConnection(defaultConfig, {});
-        // sync default check.
-        var called = false;
-        var pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
-        pc.onnegotiationneeded = function() {
-          called = true;
-          // async check.
-          if (util && util.supports) {
-            util.supports.onnegotiationneeded = true;
-          }
-        };
-        // FIXME: this is not great because in theory it doesn't work for
-        // av-only browsers (?).
-        var dc = pc.createDataChannel('_PEERJSRELIABLETEST');
+      negotiationPC.close();
+      negotiationDC.close();
+    }
 
-        pc.close();
-        dc.close();
+    // FIXME: Make SURE these are closed.
+    if (pc) {
+      pc.close();
+    }
+    if (dc) {
+      dc.close();
+    }
 
-        return called;
-      })()
+    return {
+      audioVideo: audioVideo,
+      data: data,
+      binary: binary,
+      reliable: reliable,
+      onnegotiationneeded: onnegotiationneeded
     };
   }()),
   //

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott