Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #38 from MatthiasLohr/master

new method Peer.isConnected() and Peer.getId()
  • Loading branch information...
commit c0b8e0ab5616531150d8eb99310ed8ed33e4054b 2 parents f8ce0c1 + 178e7b7
@michelle michelle authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/peer.js
View
18 lib/peer.js
@@ -64,6 +64,7 @@ function Peer(id, options) {
this.id = id;
this._init();
} else {
+ this.id = null;
this._getId();
}
};
@@ -264,6 +265,14 @@ Peer.prototype.connect = function(peer, options) {
};
/**
+ * Return the peer id or null, if there's no id at the moment.
+ * Reasons for no id could be 'connect in progress' or 'disconnected'
+ */
+Peer.prototype.getId = function() {
+ return this.id;
+};
+
+/**
* Destroys the Peer: closes all active connections as well as the connection
* to the server.
* Warning: The peer can no longer create or accept connections after being
@@ -285,9 +294,18 @@ Peer.prototype.destroy = function() {
Peer.prototype.disconnect = function() {
if (!this.disconnected) {
this._socket.close();
+ this.id = null;
this.disconnected = true;
}
};
+/**
+ * Provides a clean method for checking if there's an active connection to the
+ * peer server.
+ */
+Peer.prototype.isConnected = function() {
+ return (!this.disconnected);
+}
+
exports.Peer = Peer;
Please sign in to comment.
Something went wrong with that request. Please try again.