|
@@ -175,7 +175,6 @@ Peer.prototype._cleanup = function() {
|
|
self._socket.close();
|
|
self._socket.close();
|
|
});
|
|
});
|
|
this.emit('close');
|
|
this.emit('close');
|
|
- this.destroyed = true;
|
|
|
|
};
|
|
};
|
|
|
|
|
|
/** Listeners for DataConnection events. */
|
|
/** 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
|
|
// TODO: pause XHR streaming when not in use and start again when this is
|
|
// called.
|
|
// called.
|
|
Peer.prototype.connect = function(peer, options) {
|
|
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({
|
|
options = util.extend({
|
|
config: this._options.config
|
|
config: this._options.config
|
|
}, options);
|
|
}, options);
|
|
@@ -210,7 +213,10 @@ Peer.prototype.connect = function(peer, options) {
|
|
};
|
|
};
|
|
|
|
|
|
Peer.prototype.destroy = function() {
|
|
Peer.prototype.destroy = function() {
|
|
- this._cleanup();
|
|
|
|
|
|
+ if (!this.destroyed) {
|
|
|
|
+ this._cleanup();
|
|
|
|
+ this.destroyed = true;
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|