소스 검색

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