소스 검색

merge in crash fixes. fixes #93; fixes #95

Michelle Bu 11 년 전
부모
커밋
da45d4f4d6
6개의 변경된 파일113개의 추가작업 그리고 124개의 파일을 삭제
  1. 1 1
      deps/reliable
  2. 55 60
      dist/peer.js
  3. 0 0
      dist/peer.min.js
  4. 1 2
      examples/chat.html
  5. 1 1
      examples/helloworld.html
  6. 55 60
      lib/util.js

+ 1 - 1
deps/reliable

@@ -1 +1 @@
-Subproject commit 856406373194f62fe68407eb680caa289a202a99
+Subproject commit 591112cd22542d01f30bf9cd01afedf412f6e9b8

+ 55 - 60
dist/peer.js

@@ -1114,9 +1114,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 = !!window.webkitRTCPeerConnection;
+
     var pc, dc;
     try {
       pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
@@ -1127,79 +1135,66 @@ var util = {
 
     if (data) {
       try {
-        dc = pc.createDataChannel('_PEERJSDATATEST');
+        dc = pc.createDataChannel('_PEERJSTEST');
       } catch (e) {
         data = false;
       }
     }
+
+    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', {});
+        reliable = reliableDC.reliable;
+      } catch (e) {
+      }
+      reliablePC.close();
+    }
+
     // FIXME: not really the best check...
     if (audioVideo) {
       audioVideo = !!pc.addStream;
     }
 
-    pc.close();
-    dc.close();
+    // FIXME: this is not great because in theory it doesn't work for
+    // av-only browsers (?).
+    if (!onnegotiationneeded && 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;
+        }
+      };
+      var negotiationDC = negotiationPC.createDataChannel('_PEERJSNEGOTIATIONTEST');
+
+      setTimeout(function() {
+        negotiationPC.close();
+      }, 1000);
+    }
+
+    if (pc) {
+      pc.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
     };
   }()),
   //

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/peer.min.js


+ 1 - 2
examples/chat.html

@@ -111,14 +111,13 @@ $(document).ready(function() {
       var c = peer.connect(requestedPeer, {
         label: 'chat',
         serialization: 'none',
-        reliable: false,
         metadata: {message: 'hi i want to chat with you!'}
       });
       c.on('open', function() {
         connect(c);
       });
       c.on('error', function(err) { alert(err); });
-      var f = peer.connect(requestedPeer, { label: 'file' });
+      var f = peer.connect(requestedPeer, { label: 'file', reliable: true });
       f.on('open', function() {
         connect(f);
       });

+ 1 - 1
examples/helloworld.html

@@ -6,7 +6,7 @@
 <meta http-equiv="Content-Language" content="en-us"> 
 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
-<script type="text/javascript" src="http://cdn.peerjs.com/0.3/peer.min.js"></script>
+<script type="text/javascript" src="../dist/peer.js"></script>
 <script>
   // This is a very simple code example. See chat.html for a more involved
   // example.

+ 55 - 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 = !!window.webkitRTCPeerConnection;
+
     var pc, dc;
     try {
       pc = new RTCPeerConnection(defaultConfig, {optional: [{RtpDataChannels: true}]});
@@ -88,79 +96,66 @@ var util = {
 
     if (data) {
       try {
-        dc = pc.createDataChannel('_PEERJSDATATEST');
+        dc = pc.createDataChannel('_PEERJSTEST');
       } catch (e) {
         data = false;
       }
     }
+
+    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', {});
+        reliable = reliableDC.reliable;
+      } 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
-          }
+    // FIXME: this is not great because in theory it doesn't work for
+    // av-only browsers (?).
+    if (!onnegotiationneeded && 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();
-
-        return true;
-      })(),
+      };
+      var negotiationDC = negotiationPC.createDataChannel('_PEERJSNEGOTIATIONTEST');
 
-      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');
+      setTimeout(function() {
+        negotiationPC.close();
+      }, 1000);
+    }
 
-        pc.close();
-        dc.close();
+    if (pc) {
+      pc.close();
+    }
 
-        return called;
-      })()
+    return {
+      audioVideo: audioVideo,
+      data: data,
+      binary: binary,
+      reliable: reliable,
+      onnegotiationneeded: onnegotiationneeded
     };
   }()),
   //

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.