فهرست منبع

fixed a few bugs with leaving and closing connection

Michelle Bu 12 سال پیش
والد
کامیت
24dffda33d
4فایلهای تغییر یافته به همراه27 افزوده شده و 3 حذف شده
  1. 9 1
      demo/static/peer.js
  2. 9 1
      dist/peer.js
  3. 0 0
      dist/peer.min.js
  4. 9 1
      lib/peer.js

+ 9 - 1
demo/static/peer.js

@@ -1038,7 +1038,10 @@ Peer.prototype._handleServerMessage = function(message) {
       if (connection) connection.handleCandidate(message);
       break;
     case 'LEAVE':
-      if (connection) connection.handleLeave();
+      if (connection) {
+        connection.handleLeave();
+        delete this.connections[peer];
+      }
       break;
     case 'PORT':
       if (util.browserisms === 'Firefox') {
@@ -1061,6 +1064,7 @@ Peer.prototype._processQueue = function() {
 
 
 Peer.prototype._cleanup = function() {
+  this._socket.send(JSON.stringify({ type: 'LEAVE', src: this._id }));
   for (var peer in this.connections) {
     if (this.connections.hasOwnProperty(peer)) {
       this.connections[peer].close();
@@ -1089,6 +1093,10 @@ Peer.prototype.connect = function(peer, metadata, cb) {
   this.connections[peer] = connection;
 };
 
+Peer.prototype.leave = function() {
+  this._cleanup();
+};
+
 
 exports.Peer = Peer;
 

+ 9 - 1
dist/peer.js

@@ -1038,7 +1038,10 @@ Peer.prototype._handleServerMessage = function(message) {
       if (connection) connection.handleCandidate(message);
       break;
     case 'LEAVE':
-      if (connection) connection.handleLeave();
+      if (connection) {
+        connection.handleLeave();
+        delete this.connections[peer];
+      }
       break;
     case 'PORT':
       if (util.browserisms === 'Firefox') {
@@ -1061,6 +1064,7 @@ Peer.prototype._processQueue = function() {
 
 
 Peer.prototype._cleanup = function() {
+  this._socket.send(JSON.stringify({ type: 'LEAVE', src: this._id }));
   for (var peer in this.connections) {
     if (this.connections.hasOwnProperty(peer)) {
       this.connections[peer].close();
@@ -1089,6 +1093,10 @@ Peer.prototype.connect = function(peer, metadata, cb) {
   this.connections[peer] = connection;
 };
 
+Peer.prototype.leave = function() {
+  this._cleanup();
+};
+
 
 exports.Peer = Peer;
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/peer.min.js


+ 9 - 1
lib/peer.js

@@ -199,7 +199,10 @@ Peer.prototype._handleServerMessage = function(message) {
       if (connection) connection.handleCandidate(message);
       break;
     case 'LEAVE':
-      if (connection) connection.handleLeave();
+      if (connection) {
+        connection.handleLeave();
+        delete this.connections[peer];
+      }
       break;
     case 'PORT':
       if (util.browserisms === 'Firefox') {
@@ -222,6 +225,7 @@ Peer.prototype._processQueue = function() {
 
 
 Peer.prototype._cleanup = function() {
+  this._socket.send(JSON.stringify({ type: 'LEAVE', src: this._id }));
   for (var peer in this.connections) {
     if (this.connections.hasOwnProperty(peer)) {
       this.connections[peer].close();
@@ -250,6 +254,10 @@ Peer.prototype.connect = function(peer, metadata, cb) {
   this.connections[peer] = connection;
 };
 
+Peer.prototype.leave = function() {
+  this._cleanup();
+};
+
 
 exports.Peer = Peer;
 

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است