|
@@ -64,6 +64,7 @@ function Peer(id, options) {
|
|
|
this.id = id;
|
|
|
this._init();
|
|
|
} else {
|
|
|
+ this.id = null;
|
|
|
this._getId();
|
|
|
}
|
|
|
};
|
|
@@ -263,6 +264,14 @@ Peer.prototype.connect = function(peer, options) {
|
|
|
return connectionInfo[1];
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * 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.
|
|
@@ -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;
|