Permalink
Browse files

destroyed check when connecting

  • Loading branch information...
1 parent a116ed5 commit e0d9e221554946a5a5da2561638a3a89860f8b10 @michelle michelle committed Feb 21, 2013
Showing with 10 additions and 4 deletions.
  1. +2 −2 docs/api.md
  2. +8 −2 lib/peer.js
View
@@ -86,8 +86,8 @@ The `error` object also has a `type` parameter that may be helpful in responding
* `server-error`: Unable to reach the server.
* `socket-error`: An error from the underlying socket.
* `socket-closed`: The underlying socket closed unexpectedly.
-
-The Peer object is destroyed after one of the errors above are emitted.
+(The Peer object is destroyed after one of the errors above are emitted.)
+* `peer-destroyed`: A Peer that has been destroyed is being used to try to connect.
### Event: 'close'
View
@@ -175,7 +175,6 @@ Peer.prototype._cleanup = function() {
self._socket.close();
});
this.emit('close');
- this.destroyed = true;
};
/** Listeners for DataConnection events. */
@@ -195,6 +194,10 @@ Peer.prototype._attachConnectionListeners = function(connection) {
// TODO: pause XHR streaming when not in use and start again when this is
// called.
Peer.prototype.connect = function(peer, options) {
+ if (this.destroyed) {
+ this._abort('peer-destroyed', 'This Peer has been destroyed and is no longer able to make connections.')
+ }
+
options = util.extend({
config: this._options.config
}, options);
@@ -210,7 +213,10 @@ Peer.prototype.connect = function(peer, options) {
};
Peer.prototype.destroy = function() {
- this._cleanup();
+ if (!this.destroyed) {
+ this._cleanup();
+ this.destroyed = true;
+ }
};

0 comments on commit e0d9e22

Please sign in to comment.