浏览代码

probably id is taken messages

ericz 12 年之前
父节点
当前提交
f5a6148993
共有 1 个文件被更改,包括 7 次插入7 次删除
  1. 7 7
      lib/server.js

+ 7 - 7
lib/server.js

@@ -67,7 +67,8 @@ PeerServer.prototype._initializeWSS = function() {
         delete self._timeouts[id];
         self._clients[id].end(JSON.stringify({ type: 'HTTP-SOCKET' }));
       } else {
-        socket.send(JSON.stringify({ type: 'ERROR', msg: 'ID is taken' }));
+        socket.send(JSON.stringify({ type: 'ID-TAKEN', msg: 'ID is taken' }));
+        socket.close();
         return;
       }
     } else if (id === undefined) {
@@ -108,10 +109,10 @@ PeerServer.prototype._initializeWSS = function() {
             self._handleTransmission(message);
             break;
           default:
-            util.prettyError('message unrecognized');
+            util.prettyError('Message unrecognized');
         }
       } catch(e) {
-        util.log('invalid message');
+        util.log('Invalid message', data);
       }
     });
   });
@@ -214,7 +215,6 @@ PeerServer.prototype._startStreaming = function(res, id, write) {
     }, 30000);
     this._processOutstandingOffers(id);
   } else {
-    res.write(JSON.stringify({ type: 'ERROR', msg: 'ID is taken' }) + '\n');
     res.end(JSON.stringify({ type: 'HTTP-ERROR' }));
   }
 
@@ -266,7 +266,7 @@ PeerServer.prototype._handleTransmission = function(message, res) {
         setTimeout(function() {
           if(!!self._outstandingOffers[dst][src]) {
             delete self._outstandingOffers[dst][src];
-            this._handleTransmission({
+            self._handleTransmission({
               type: 'EXPIRE',
               src: dst,
               dst: src
@@ -275,10 +275,10 @@ PeerServer.prototype._handleTransmission = function(message, res) {
         }, this._options.timeout);
       }
       this._outstandingOffers[dst][src].push(Array.prototype.slice.apply(arguments));
-      res.send(200);
+      if (!!res) res.send(200);
     } else if (type === 'LEAVE' && !dst) {
       this._removePeer(src);
-      res.send(200);
+      if (!!res) res.send(200);
     } else {
       // Assume a disconnect if the client no longer exists.
       this._handleTransmission({