ericz 12 жил өмнө
parent
commit
9760350959
1 өөрчлөгдсөн 11 нэмэгдсэн , 9 устгасан
  1. 11 9
      lib/server.js

+ 11 - 9
lib/server.js

@@ -74,9 +74,11 @@ PeerServer.prototype._initializeWSS = function() {
     if (!self._clients[key] || !self._clients[key][id]) {
       self._checkKey(key, ip, function(err) {
         if (!err) {
-          self._clients[key][id] = { token: token, ip: ip };
-          self._ips[ip]++;
-          socket.send(JSON.stringify({ type: 'OPEN' }));
+          if (!self._clients[key][id]) {
+            self._clients[key][id] = { token: token, ip: ip };
+            self._ips[ip]++;            
+            socket.send(JSON.stringify({ type: 'OPEN' }));
+          }
           self._configureWS(socket, key, id, token);
         } else {
           socket.send(JSON.stringify({ type: 'ERROR', payload: { msg: err } }));
@@ -122,7 +124,6 @@ PeerServer.prototype._configureWS = function(socket, key, id, token) {
   socket.on('message', function(data) {
     try {
       var message = JSON.parse(data);
-      util.log(message);
 
       switch (message.type) {
         case 'LEAVE':
@@ -162,11 +163,11 @@ PeerServer.prototype._checkKey = function(key, ip, cb) {
     if (!this._clients[key]) {
       this._clients[key] = {};
     }
-    if (!this._outstanding[key]) {
-      this._outstanding[key] = {};
+    if (!self._outstanding[key]) {
+      self._outstanding[key] = {};
     }
-    if (!this._ips[ip]) {
-      this._ips[ip] = 0;
+    if (!self._ips[ip]) {
+      self._ips[ip] = 0;
     }
     // Check concurrent limit
     if (Object.keys(this._clients[key]).length >= this._options.concurrent_limit) {
@@ -210,7 +211,7 @@ PeerServer.prototype._initializeHTTP = function() {
     
     if (!self._clients[key] || !self._clients[key][id]) {
       self._checkKey(key, ip, function(err) {
-        if (!err) {
+        if (!err && !self._clients[key][id]) {
           self._clients[key][id] = { token: token, ip: ip };
           self._ips[ip]++;
           self._startStreaming(res, key, id, token, true);
@@ -347,6 +348,7 @@ PeerServer.prototype._handleTransmission = function(key, message) {
   // User is connected!
   if (destination) {
     try {
+      util.log(type, 'from', src, 'to', dst);
       if (destination.socket) {
         destination.socket.send(data);
       } else if (destination.res) {