Pārlūkot izejas kodu

managers check DOES need to happen

Michelle Bu 12 gadi atpakaļ
vecāks
revīzija
d72165d36e
1 mainītis faili ar 11 papildinājumiem un 13 dzēšanām
  1. 11 13
      lib/peer.js

+ 11 - 13
lib/peer.js

@@ -12,8 +12,11 @@ function Peer(id, options) {
   // First check if browser can use PeerConnection/DataChannels.
   // TODO: when media is supported, lower browser version limit and move DC
   // check to where`connect` is called.
+  var self = this;
   if (!util.isBrowserCompatible()) {
-    this._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
+    util.setZeroTimeout(function() {
+      self._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
+    });
     return;
   }
 
@@ -33,18 +36,17 @@ function Peer(id, options) {
   util.debug = options.debug;
 
   // Ensure alphanumeric_-
-  var self = this;
   if (id && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id)) {
     util.setZeroTimeout(function() {
       self._abort('invalid-id', 'ID "' + id + '" is invalid');
     });
-    return
+    return;
   }
   if (options.key && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.key)) {
     util.setZeroTimeout(function() {
       self._abort('invalid-key', 'API KEY "' + options.key + '" is invalid');
     });
-    return
+    return;
   }
 
   // States.
@@ -172,11 +174,6 @@ Peer.prototype._handleServerJSONMessage = function(message) {
     case 'INVALID-KEY':
       this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
       break;
-    case 'PORT':
-      //if (util.browserisms === 'Firefox') {
-      //  connection.handlePort(payload);
-      //  break;
-      //}
     default:
       util.log('Unrecognized message type:', message.type);
       break;
@@ -221,9 +218,11 @@ Peer.prototype._abort = function(type, message) {
 
 Peer.prototype._cleanup = function() {
   var self = this;
-  var peers = Object.keys(this.managers);
-  for (var i = 0, ii = peers.length; i < ii; i++) {
-    this.managers[peers[i]].close();
+  if (!!this.managers) {
+    var peers = Object.keys(this.managers);
+    for (var i = 0, ii = peers.length; i < ii; i++) {
+      this.managers[peers[i]].close();
+    }
   }
   util.setZeroTimeout(function(){
     self.disconnect();
@@ -232,7 +231,6 @@ Peer.prototype._cleanup = function() {
 };
 
 
-
 /** Exposed connect function for users. Will try to connect later if user
  * is waiting for an ID. */
 Peer.prototype.connect = function(peer, options) {