ericz 12 роки тому
батько
коміт
cc5c3c0f9d
1 змінених файлів з 17 додано та 7 видалено
  1. 17 7
      lib/peer.js

+ 17 - 7
lib/peer.js

@@ -17,11 +17,13 @@ function Peer(options) {
   this._server = options.host + ':' + options.port;
 
   // Ensure alphanumeric_-
-  if (options.id && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.id))
+  if (options.id && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.id)) {
     throw new Error('Peer ID can only contain alphanumerics, "_", and "-".');
-  if (options.key && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.key))
+  }
+  if (options.key && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.key)) {
     throw new Error('API key can only contain alphanumerics, "_", and "-".');
-
+  }
+  
   this._id = options.id;
   // Not used unless using cloud server.
   this._key = options.key;
@@ -91,13 +93,19 @@ Peer.prototype._handleServerJSONMessage = function(message) {
       this.connections[peer] = connection;
       break;
     case 'ANSWER':
-      if (connection) connection.handleSDP(message);
+      if (connection) {
+        connection.handleSDP(message);
+      }
       break;
     case 'CANDIDATE':
-      if (connection) connection.handleCandidate(message);
+      if (connection) {
+        connection.handleCandidate(message);
+      }
       break;
     case 'LEAVE':
-      if (connection) connection.handleLeave();
+      if (connection) {
+        connection.handleLeave();
+      }
       break;
     case 'PORT':
       if (util.browserisms === 'Firefox') {
@@ -131,7 +139,9 @@ Peer.prototype._cleanup = function() {
 Peer.prototype._attachConnectionListeners = function(connection) {
   var self = this;
   connection.on('close', function(peer) {
-    if (self.connections[peer]) delete self.connections[peer];
+    if (self.connections[peer]) { 
+      delete self.connections[peer]; 
+    }
   });
 };