Permalink
Browse files

added getters

  • Loading branch information...
1 parent eda32ee commit a41dcd760d288fc64b4321f54c814340b9ed82c5 @michelle michelle committed Apr 3, 2013
Showing with 96 additions and 4 deletions.
  1. +56 −1 dist/peer.js
  2. +1 −1 dist/peer.min.js
  3. +31 −0 lib/dataconnection.js
  4. +8 −2 lib/peer.js
View
@@ -1,4 +1,4 @@
-/*! peerjs.js build:0.2.0, development. Copyright(c) 2013 Michelle Bu <michelle@michellebu.com> */
+/*! peerjs.js build:0.2.1, development. Copyright(c) 2013 Michelle Bu <michelle@michellebu.com> */
(function(exports){
var binaryFeatures = {};
binaryFeatures.useBlobBuilder = (function(){
@@ -1236,6 +1236,7 @@ function Peer(id, options) {
this.id = id;
this._init();
} else {
+ this.id = null;
this._getId();
}
};
@@ -1436,6 +1437,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
@@ -1457,10 +1466,25 @@ 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;
+};
+
+/**
+ * Returns true if this peer is destroyed and can no longer be used.
+ */
+Peer.prototype.isDestroyed = function() {
+ return this.destroyed;
+};
exports.Peer = Peer;
/**
@@ -1604,6 +1628,37 @@ DataConnection.prototype.send = function(data) {
}
}
};
+
+/**
+ * Returns true if the DataConnection is open and able to send messages.
+ */
+DataConnection.prototype.isOpen = function() {
+ return this.open;
+};
+
+/**
+ * Gets the metadata associated with this DataConnection.
+ */
+DataConnection.prototype.getMetadata = function() {
+ return this.metadata;
+};
+
+/**
+ * Gets the label associated with this DataConnection.
+ */
+DataConnection.prototype.getLabel = function() {
+ return this.label;
+};
+
+/**
+ * Gets the brokering ID of the peer that you are connected with.
+ * Note that this ID may be out of date if the peer has disconnected from the
+ * server, so it's not recommended that you use this ID to identify this
+ * connection.
+ */
+DataConnection.prototype.getPeer = function() {
+ return this.peer;
+};
/**
* Manages DataConnections between its peer and one other peer.
* Internally, manages PeerConnection.
Oops, something went wrong.

0 comments on commit a41dcd7

Please sign in to comment.