소스 검색

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;
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.