Kaynağa Gözat

add brackets

ericz 12 yıl önce
ebeveyn
işleme
323c119f61
2 değiştirilmiş dosya ile 9 ekleme ve 7 silme
  1. 5 5
      lib/peer.js
  2. 4 2
      lib/socket.js

+ 5 - 5
lib/peer.js

@@ -48,8 +48,9 @@ Peer.prototype._startSocket = function() {
   });
   this._socket.on('unavailable', function(peer) {
     util.log('Destination peer not available.', peer);
-    if (self.connections[peer])
+    if (self.connections[peer]) {
       self.connections[peer].close();
+    }
   });
   this._socket.on('error', function(error) {
     util.log(error);
@@ -119,10 +120,9 @@ Peer.prototype._processQueue = function() {
 
 
 Peer.prototype._cleanup = function() {
-  for (var peer in this.connections) {
-    if (this.connections.hasOwnProperty(peer)) {
-      this.connections[peer].close();
-    }
+  var peers = Object.keys(this.connections);
+  for (var i = 0, ii = peers.length; i < ii; i++) {
+    this.connections[peers[i]].close();
   }
   this._socket.close();
 };

+ 4 - 2
lib/socket.js

@@ -167,8 +167,9 @@ Socket.prototype._handleHTTPErrors = function(message) {
 Socket.prototype.send = function(data) {
   var type = data.type;
   message = JSON.stringify(data);
-  if (!type)
+  if (!type) {
     this.emit('error', 'Invalid message');
+  }
 
   if (!!this._socket && this._socket.readyState == 1) {
     this._socket.send(message);
@@ -193,8 +194,9 @@ Socket.prototype.send = function(data) {
 };
 
 Socket.prototype.close = function() {
-  if (!!this._socket && this._socket.readyState == 1)
+  if (!!this._socket && this._socket.readyState == 1) {
     this._socket.close();
+  }
 };
 
 Socket.prototype.start = function() {