Pārlūkot izejas kodu

Don't close negotiation PC right away

Michelle Bu 11 gadi atpakaļ
vecāks
revīzija
a92b73314a
4 mainītis faili ar 16 papildinājumiem un 22 dzēšanām
  1. 8 11
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 1 1
      examples/helloworld.html
  4. 7 10
      lib/util.js

+ 8 - 11
dist/peer.js

@@ -1110,7 +1110,7 @@ var util = {
 
     var binary = false;
     var reliable = false;
-    var onnegotiationneeded = false;
+    var onnegotiationneeded = !!window.webkitRTCPeerConnection;
 
     var pc, dc;
     try {
@@ -1149,7 +1149,9 @@ var util = {
       audioVideo = !!pc.addStream;
     }
 
-    if (/** audioVideo || */data) {
+    // 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() {
@@ -1159,21 +1161,16 @@ var util = {
           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');
+      var negotiationDC = negotiationPC.createDataChannel('_PEERJSNEGOTIATIONTEST');
 
-      negotiationPC.close();
-      negotiationDC.close();
+      setTimeout(function() {
+        negotiationPC.close();
+      }, 1000);
     }
 
-    // FIXME: Make SURE these are closed.
     if (pc) {
       pc.close();
     }
-    if (dc) {
-      dc.close();
-    }
 
     return {
       audioVideo: audioVideo,

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/peer.min.js


+ 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.

+ 7 - 10
lib/util.js

@@ -84,7 +84,7 @@ var util = {
 
     var binary = false;
     var reliable = false;
-    var onnegotiationneeded = false;
+    var onnegotiationneeded = !!window.webkitRTCPeerConnection;
 
     var pc, dc;
     try {
@@ -123,7 +123,9 @@ var util = {
       audioVideo = !!pc.addStream;
     }
 
-    if (/** audioVideo || */data) {
+    // 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() {
@@ -133,21 +135,16 @@ var util = {
           util.supports.onnegotiationneeded = true;
         }
       };
-      // FIXME: this is not great because in theory it doesn't work for
-      // av-only browsers (?).
       var negotiationDC = negotiationPC.createDataChannel('_PEERJSNEGOTIATIONTEST');
 
-      negotiationPC.close();
-      negotiationDC.close();
+      setTimeout(function() {
+        negotiationPC.close();
+      }, 1000);
     }
 
-    // FIXME: Make SURE these are closed.
     if (pc) {
       pc.close();
     }
-    if (dc) {
-      dc.close();
-    }
 
     return {
       audioVideo: audioVideo,

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels