Michelle Bu před 12 roky
rodič
revize
a41dcd760d
4 změnil soubory, kde provedl 95 přidání a 3 odebrání
  1. 56 1
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 31 0
      lib/dataconnection.js
  4. 8 2
      lib/peer.js

+ 56 - 1
dist/peer.js

@@ -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();
   }
 };
@@ -1435,6 +1436,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.
@@ -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.

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
dist/peer.min.js


+ 31 - 0
lib/dataconnection.js

@@ -139,3 +139,34 @@ 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;
+};

+ 8 - 2
lib/peer.js

@@ -304,8 +304,14 @@ Peer.prototype.disconnect = function() {
  * peer server.
  */
 Peer.prototype.isConnected = function() {
-  return (!this.disconnected);
-}
+  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;

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů