ericz před 12 roky
rodič
revize
0438663f88
17 změnil soubory, kde provedl 378 přidání a 357 odebrání
  1. 5 5
      changelog.md
  2. 1 1
      deps/reliable
  3. 18 56
      dist/peer.js
  4. 0 0
      dist/peer.min.js
  5. 1 29
      docs/api.md
  6. 257 0
      docs/index.html
  7. 78 0
      docs/style.css
  8. 1 5
      lib/dataconnection.js
  9. 0 3
      lib/mediaconnection.js
  10. 0 8
      lib/peer.js
  11. 16 30
      lib/util.js
  12. 0 4
      test/adapter.js
  13. 0 41
      test/connectionmanager.js
  14. 0 126
      test/dataconnection.js
  15. 0 16
      test/peer.js
  16. 0 32
      test/socket.js
  17. 1 1
      test/test.html

+ 5 - 5
changelog.md

@@ -1,16 +1,16 @@
 # PeerJS Changelog
 # PeerJS Changelog
 
 
-## Version 0.3.0 (TBA)
+## Version 0.3.0 (beta)
 
 
 ### Highlights
 ### Highlights
-* **Interoperable DataChannels and video/audio streams.**
-* Support for WebRTC video and audio streams.
+* Support for WebRTC video and audio streams in both Firefox and Chrome.
 * Add `util.supports.[FEATURE]` flags, which represent the WebRTC features
 * Add `util.supports.[FEATURE]` flags, which represent the WebRTC features
   supported by your browser.
   supported by your browser.
+* **Deprecate current `Peer#connections` format.** Connections will no longer be
+  keyed by label and will instead be in a list.
 
 
 ### Other changes
 ### Other changes
-* **Deprecate current Peer#connections format.** Connections will no longer be
-  keyed by label and will instead be in a list.
+* **Deprecate `Peer.browser`** in favor of `util.browser`.
 * Additional logging levels (warnings, errors, all).
 * Additional logging levels (warnings, errors, all).
 * Additional logging functionality (`logFunction`).
 * Additional logging functionality (`logFunction`).
 * SSL option now in config rather than automatic.
 * SSL option now in config rather than automatic.

+ 1 - 1
deps/reliable

@@ -1 +1 @@
-Subproject commit 856406373194f62fe68407eb680caa289a202a99
+Subproject commit 0bbaf986efa550ea261b33ae20e17d85fb5b5bfa

+ 18 - 56
dist/peer.js

@@ -1029,7 +1029,7 @@ var util = {
 
 
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_PORT: 9000,
   CLOUD_PORT: 9000,
-  
+
   // Logging logic
   // Logging logic
   logLevel: 0,
   logLevel: 0,
   setLogLevel: function(level) {
   setLogLevel: function(level) {
@@ -1038,7 +1038,7 @@ var util = {
       util.logLevel = debugLevel;
       util.logLevel = debugLevel;
     } else {
     } else {
       // If they are using truthy/falsy values for debug
       // If they are using truthy/falsy values for debug
-      util.logLevel = (!!level) ? 3 : 0;
+      util.logLevel = level ? 3 : 0;
     }
     }
     util.log = util.warn = util.error = util.noop;
     util.log = util.warn = util.error = util.noop;
     if (util.logLevel > 0) {
     if (util.logLevel > 0) {
@@ -1084,8 +1084,21 @@ var util = {
   defaultConfig: defaultConfig,
   defaultConfig: defaultConfig,
   //
   //
 
 
+  // Returns the current browser.
+  browser: (function() {
+    if (window.mozRTCPeerConnection) {
+      return 'Firefox';
+    } else if (window.webkitRTCPeerConnection) {
+      return 'Chrome';
+    } else if (window.RTCPeerConnection) {
+      return 'Supported';
+    } else {
+      return 'Unsupported';
+    }
+  })(),
+  //
+
   // Lists which features are supported
   // Lists which features are supported
-  // Temporarily set everything to true
   supports: (function() {
   supports: (function() {
     var data = true;
     var data = true;
     var audioVideo = true;
     var audioVideo = true;
@@ -1193,14 +1206,7 @@ var util = {
   },
   },
 
 
 
 
-  // OLD
-  chromeCompatible: true,
-  firefoxCompatible: true,
-  chromeVersion: 26,
-  firefoxVersion: 22,
-
   debug: false,
   debug: false,
-  browserisms: '',
 
 
   inherits: function(ctor, superCtor) {
   inherits: function(ctor, superCtor) {
     ctor.super_ = superCtor;
     ctor.super_ = superCtor;
@@ -1296,26 +1302,6 @@ var util = {
   },
   },
   //
   //
 
 
-  // When we have proper version/feature mappings we can remove this
-  isBrowserCompatible: function() {
-    var c, f;
-    if (this.chromeCompatible) {
-      if ((c = navigator.userAgent.split('Chrome/')) && c.length > 1) {
-        // Get version #.
-        var v = c[1].split('.')[0];
-        return parseInt(v) >= this.chromeVersion;
-      }
-    }
-    if (this.firefoxCompatible) {
-      if ((f = navigator.userAgent.split('Firefox/')) && f.length > 1) {
-        // Get version #.
-        var v = f[1].split('.')[0];
-        return parseInt(v) >= this.firefoxVersion;
-      }
-    }
-    return false;
-  },
-
   isSecure: function() {
   isSecure: function() {
     return location.protocol === 'https:';
     return location.protocol === 'https:';
   }
   }
@@ -1356,7 +1342,6 @@ function Peer(id, options) {
   if (options.secure === undefined && options.host !== util.CLOUD_HOST) {
   if (options.secure === undefined && options.host !== util.CLOUD_HOST) {
     options.secure = util.isSecure();
     options.secure = util.isSecure();
   }
   }
-  // TODO: document this feature
   // Set a custom log function if present
   // Set a custom log function if present
   if (options.logFunction) {
   if (options.logFunction) {
     util.setLogFunction(options.logFunction);
     util.setLogFunction(options.logFunction);
@@ -1431,7 +1416,6 @@ util.inherits(Peer, EventEmitter);
 Peer.prototype._retrieveId = function(cb) {
 Peer.prototype._retrieveId = function(cb) {
   var self = this;
   var self = this;
   var http = new XMLHttpRequest();
   var http = new XMLHttpRequest();
-  // TODO: apparently using ://something.com gives relative protocol?
   var protocol = this.options.secure ? 'https://' : 'http://';
   var protocol = this.options.secure ? 'https://' : 'http://';
   var url = protocol + this.options.host + ':' + this.options.port + '/' + this.options.key + '/id';
   var url = protocol + this.options.host + ':' + this.options.port + '/' + this.options.key + '/id';
   var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
   var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
@@ -1490,7 +1474,6 @@ Peer.prototype._handleMessage = function(message) {
       break;
       break;
 
 
     case 'EXPIRE': // The offer sent to a peer has expired without response.
     case 'EXPIRE': // The offer sent to a peer has expired without response.
-      // TODO: should this be on the DataConnection? It's currently here but I'm not so sure it belongs.
       this.emit('error', new Error('Could not connect to peer ' + peer));
       this.emit('error', new Error('Could not connect to peer ' + peer));
       break;
       break;
     case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
     case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
@@ -1536,7 +1519,6 @@ Peer.prototype._handleMessage = function(message) {
       }
       }
       break;
       break;
     default:
     default:
-      // TODO: if out of order, must queue.
       if (!payload) {
       if (!payload) {
         util.warn('You received a malformed message from ' + peer + ' of type ' + type);
         util.warn('You received a malformed message from ' + peer + ' of type ' + type);
         return;
         return;
@@ -1696,10 +1678,6 @@ Peer.prototype.disconnect = function() {
   });
   });
 }
 }
 
 
-/** The current browser. */
-// TODO: maybe expose util.supports
-Peer.browser = util.browserisms;
-
 exports.Peer = Peer;
 exports.Peer = Peer;
 /**
 /**
  * Wraps a DataChannel between two Peers.
  * Wraps a DataChannel between two Peers.
@@ -1729,11 +1707,7 @@ function DataConnection(peer, provider, options) {
   Negotiator.startConnection(
   Negotiator.startConnection(
     this,
     this,
     this.options._payload || {
     this.options._payload || {
-      originator: true,
-      multiplex: this.options.multiplex // I don't think multiplex should be a
-                                        // top-level property because it only
-                                        // applies to the originator--otherwise
-                                        // we'd just have an options.pc to use.
+      originator: true
     }
     }
   );
   );
 }
 }
@@ -1919,13 +1893,10 @@ MediaConnection.prototype.handleMessage = function(message) {
 
 
   switch (message.type) {
   switch (message.type) {
     case 'ANSWER':
     case 'ANSWER':
-      // TODO: assert sdp exists.
-      // Should we pass `this`?
       // Forward to negotiator
       // Forward to negotiator
       Negotiator.handleSDP(message.type, this, payload.sdp);
       Negotiator.handleSDP(message.type, this, payload.sdp);
       break;
       break;
     case 'CANDIDATE':
     case 'CANDIDATE':
-      // TODO
       Negotiator.handleCandidate(this, payload.candidate);
       Negotiator.handleCandidate(this, payload.candidate);
       break;
       break;
     default:
     default:
@@ -1955,6 +1926,7 @@ MediaConnection.prototype.answer = function(stream) {
 
 
 /** Allows user to close connection. */
 /** Allows user to close connection. */
 MediaConnection.prototype.close = function() {
 MediaConnection.prototype.close = function() {
+  // TODO: actually close PC.
   if (this.open) {
   if (this.open) {
     this.open = false;
     this.open = false;
     this.emit('close')
     this.emit('close')
@@ -2227,16 +2199,6 @@ Negotiator.handleSDP = function(type, connection, sdp) {
     util.log('Set remoteDescription:', type, 'for:', connection.peer);
     util.log('Set remoteDescription:', type, 'for:', connection.peer);
 
 
     if (type === 'OFFER') {
     if (type === 'OFFER') {
-      if (connection.type === 'media') {
-        if (connection.localStream) {
-          // Add local stream (from answer).
-          pc.addStream(connection.localStream);
-        }
-        //util.setZeroTimeout(function(){
-        //  // Add remote streams
-        //  connection.addStream(pc.getRemoteStreams()[0]);
-        //});
-      }
       Negotiator._makeAnswer(connection);
       Negotiator._makeAnswer(connection);
     }
     }
   }, function(err) {
   }, function(err) {

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


+ 1 - 29
docs/api.md

@@ -3,34 +3,6 @@
 **Due to browsers' incomplete support of the WebRTC DataChannel specification, many features of PeerJS have caveats.
 **Due to browsers' incomplete support of the WebRTC DataChannel specification, many features of PeerJS have caveats.
 [View the status page for full details](http://peerjs.com/status).**
 [View the status page for full details](http://peerjs.com/status).**
 
 
-- [Class: peerjs.Peer](#class-peerjspeer)
-  - [new Peer([id], [options])](#new-peerid-options)
-  - [Peer.browser](#peerbrowser)
-  - [peer.id](#peerid)
-  - [peer.connections](#peerconnections)
-  - [peer.connect(id, [options])](#peerconnectid-options)
-  - [peer.destroy()](#peerdestroy)
-  - [peer.disconnect()](#peerdisconnect)
-  - [peer.disconnected](#peerdisconnected)
-  - [peer.destroyed](#peerdestroyed)
-  - [Event: 'connection'](#event-connection)
-  - [Event: 'open'](#event-open)
-  - [Event: 'error'](#event-error)
-  - [Event: 'close'](#event-close)
-- [Class: peerjs.DataConnection](#class-peerjsdataconnection)
-  - [EXPERIMENTAL reliable and large file transfer:](#experimental-reliable-and-large-file-transfer)
-  - [connection.peer](#connectionpeer)
-  - [connection.open](#connectionopen)
-  - [connection.metadata](#connectionmetadata)
-  - [connection.label](#connectionlabel)
-  - [connection.serialization](#connectionserialization)
-  - [connection.send(data)](#connectionsenddata)
-  - [connection.close()](#connectionclose)
-  - [Event: 'data'](#event-data)
-  - [Event: 'open'](#event-open-1)
-  - [Event: 'error'](#event-error-1)
-  - [Event: 'close'](#event-close-1)
-
 ## Class: peerjs.Peer
 ## Class: peerjs.Peer
 
 
 This class is a Peer, which can connect to other peers and listen for connections. It is an `EventEmitter`.
 This class is a Peer, which can connect to other peers and listen for connections. It is an `EventEmitter`.
@@ -55,7 +27,7 @@ In the options, either a PeerServer Cloud `key` must be provided or `host` and `
 
 
 The `config` object is passed straight into instances of `RTCPeerConnection`. For compatibility with symmetric NATs, you can provide your own TURN server. By default the STUN server provided by Google is used.
 The `config` object is passed straight into instances of `RTCPeerConnection`. For compatibility with symmetric NATs, you can provide your own TURN server. By default the STUN server provided by Google is used.
 
 
-### Peer.browser
+### Peer.browser (deprecated after 0.3.0)
 
 
 The type of browser the client is on. Currently WebRTC DataChannels are not
 The type of browser the client is on. Currently WebRTC DataChannels are not
 interoperable so different browser types should not be connected.
 interoperable so different browser types should not be connected.

+ 257 - 0
docs/index.html

@@ -0,0 +1,257 @@
+<head>
+  <link href="./style.css" rel="stylesheet" type="text/css">
+  <script type="text/javascript" src="./index.js"></script>
+</head>
+
+<body>
+  <section class="api">
+
+    <h2>API Reference</h2>
+
+    <div class="peer toplevel">
+      <h3>
+        Peer
+        <span class="labels">
+          <span class="label class">class</span>
+        </span>
+        <span class="snippet">var peer = new Peer([id], [options]);</span>
+      </h3>
+
+      <p>
+        A Peer can connect to other peers and listen for connections.
+      </p>
+
+      <!-- peer args -->
+      <div class="arguments">
+        <div class="argument">
+          <span class="name">
+            id
+          </span>
+          <span class="labels">
+            <span class="label type">string</span>
+            <span class="label arg">arg</span>
+          </span>
+
+          <p>
+            Other peers can connect to this peer using the provided ID. If no ID
+            is given, one will be generated by the brokering server.
+          </p>
+
+          <p>
+            It is not
+            recommended that you use this ID to identify peers, as it's meant to
+            be used for brokering connections only. You're recommended to set the
+            <span class="code">metadata</span> option to send other identifying
+            information.
+          </p>
+
+        </div>
+
+        <div class="argument">
+          <span class="name">
+            options
+          </span>
+          <span class="labels">
+            <span class="label type">object</span>
+            <span class="label arg">arg</span>
+          </span>
+
+          <div class="options">
+            <div class="option">
+              <span class="name">
+                key
+              </span>
+              <span class="labels">
+                <span class="label">option</span>
+                <span class="label type">string</span>
+              </span>
+
+              <p>
+                API key for the cloud PeerServer. This is not used for servers
+                other than <span class="code">0.peerjs.com</span>
+              </p>
+            </div>
+
+            <div class="option">
+              <span class="name">
+                host
+              </span>
+              <span class="labels">
+                <span class="label">option</span>
+                <span class="label type">string</span>
+              </span>
+
+              <p>
+                Server host. Defaults to <span class="code">0.peerjs.com</span>.
+                Also accepts <span class="code">'/'</span> to signify relative
+                hostname.
+              </p>
+            </div>
+
+          </div>
+
+        </div>
+      </div>
+      <!-- /peer args -->
+
+      <!-- peer methods -->
+      <div class="methods">
+
+        <!-- peer.connect -->
+        <div class="method">
+          <span class="name">
+            peer.connect(id, [options])
+          </span>
+          <span class="labels">
+            <span class="label">method</span>
+          </span>
+
+          <!-- peer.connect args -->
+          <div class="arguments">
+            <div class="argument">
+              <span class="name">
+                id
+              </span>
+              <span class="labels">
+                <span class="label type">string</span>
+                <span class="label required">required</span>
+                <span class="label arg">arg</span>
+              </span>
+
+              <p>
+                Blah blah something.
+              </p>
+
+            </div>
+
+            <div class="argument">
+              <span class="name">
+                options
+              </span>
+              <span class="labels">
+                <span class="label type">object</span>
+                <span class="label arg">arg</span>
+              </span>
+
+              <div class="options">
+                <div class="option">
+                  <span class="name">
+                    serialization
+                  </span>
+                  <span class="labels">
+                    <span class="label">option</span>
+                    <span class="label type">string</span>
+                  </span>
+
+                  <p>
+                    Blah more blah.
+                  </p>
+                </div>
+
+              </div>
+
+            </div>
+          </div>
+          <!-- /peer.connect args -->
+        </div>
+        <!-- /peer.connect -->
+
+      </div>
+      <!-- /peer methods -->
+
+      <!-- peer events -->
+      <div class="events">
+      </div>
+      <!-- /peer events -->
+    </div>
+
+  </section>
+
+  <section class="start">
+    <h2>Get started with PeerJS</h2>
+
+      <div class="warning">Due to browsers' incomplete support of the WebRTC DataChannel specification, many features of PeerJS have caveats.<br><a href="/status">View the status page for full details</a>.</div>
+      <p>PeerJS requires two components: the PeerJS client library and the PeerServer.</p>
+
+    <h2>PeerServer</h2>
+
+      <p>The PeerServer brokers connections between PeerJS clients. Once two clients have established a connection with each other with the PeerServer's help, data is will flow between the clients directly.</p>
+      <p>Choose one of the following options:</p>
+      <p><a href="/peerserver">Sign up for free cloud-hosted PeerServer service</a></p>
+      <p>Alternatively, <a href="http://github.com/peers/peerjs-server">PeerServer is
+      available on GitHub</a> and on <a href="https://npmjs.org/package/peer">npm</a>:</a>
+      <pre><code>npm install peer</code></pre>
+      <p>Setting up the server on your own is just a few lines of code:</a>
+      <pre><code>var PeerServer = require('peer').PeerServer;
+      var server = new PeerServer({ port: 9000 });</code></pre>
+
+    <h2>PeerJS Client</h2>
+
+      <p>The client is where all the action is at.<p>
+      <h3>1. Include the PeerJS client in your frontend Javascript code:</h3>
+      <pre><code>&lt;script src="http://cdn.peerjs.com/0/peer.min.js"&gt;&lt;/script&gt;
+      </code></pre>
+      <h3>2. Create the Peer object.</h3>
+      <p>
+      You'll need to provide an ID. When other peers try to connect to you, they'll have to know this ID.</p>
+      <p>
+      Also you'll need to provide either the API key for your PeerServer cloud account or your own PeerServer:
+      </p>
+      <pre><code>var peer = new Peer('some-id', {key: 'myapikey'});
+      </code></pre>
+      <p>Or if you're running your own PeerServer</p>
+      <pre><code>var peer = new Peer('some-id', {host: 'localhost', port: 9000});
+      </code></pre>
+      <h3>3. That's it! You're ready to send and receive binary P2P data connections!</h3>
+      <p>Listening for incoming connections:</p>
+      <pre><code>peer.on('connection', function(conn){
+        conn.on('data', function(data) {
+          console.log('Got data:', data);
+        });
+      });
+      </code></pre>
+
+      <p>Create a peer connection:</p>
+      <pre><code>var conn = peer.connect('some-id');
+      conn.on('open', function() {
+        conn.send('Hello world!');
+      });
+      </code></pre>
+
+    <h2>Other cool things you need to know</h2>
+
+      <h3>What kind of data can I send?</h3>
+
+        <p>PeerJS has the BinaryPack serialization format built-in. This means you can send any JSON type as well as binary Blobs and ArrayBuffers. You don't have to worry about serializing yourself. Simple put objects in on one side and get objects out on the other:</p>
+        <pre><code>conn.send({
+          strings: 'hi!',
+          numbers: 150,
+          arrays: [1,2,3],
+          evenbinary: new Blob([1,2,3]),
+          andmore: {bool: true}
+        });
+        </code></pre>
+        <p>With BinaryPack, the data is never converted to strings. Everything is binary end-to-end. This results in bandwidth savings.
+        </p>
+
+      <h3>Preconnection</h3>
+
+        <p>When you try to connect to a peer, PeerServer will hold a connection offer for up to 5 seconds before rejecting it. This is useful if you want to reconnect to a peer as it disconnects and reconnects rapidly between web pages.</p>
+
+      <h3>Connection latency/bandwidth</h3>
+
+        <p>Data sent between the two peers do not touch any other servers, so the connection speed is limited only by the upload and download rates of the two peers. This also means you don't have the additional latency of an intermediary server.</p>
+        <p>The latency to establish a connection is identified by two factors: the brokering of data and identifying of clients. PeerJS has been carefully coded to minimize latency in both applications. Data is brokered through an XHR streaming request before a WebSocket connection is established, then through WebSocket afterwards. Identity is self-provided and thus a new client can report identity, accept an outstanding offer, and and provide answer and thus establish the peer-to-peer connection in very few RTTs.</p>
+        <p>Note that in the infrequent case that both peers are behind symmetric NATs, this is no longer true. See below.</p>
+
+      <h3>Peer-to-peer shortingcomings</h3>
+
+        <p>A very low percentage of users are behind symmetric NATs. When two symmetric NAT users try to connect to each other, NAT traversal is impossible and no connection can be made. A workaround is to proxy through what is known as a TURN server. The PeerServer cloud service does not provide a TURN server. You'll have to find your own. You can pass a TURN server into the <tt>Peer</tt> object options. This will allow your PeerJS app to work seamlessly for this situation</p>
+
+      <h3>Current state of browser compatibility</h3>
+
+        <p><a href="/status">Detailed browser compatibility information</a></p>
+        <p><a href="https://groups.google.com/forum/?fromgroups#!forum/peerjs">Discuss PeerJS on our Google Group</a></p>
+
+  </section>
+</body>

+ 78 - 0
docs/style.css

@@ -0,0 +1,78 @@
+body, html {
+  font: 14px Helvetica;
+  color: #454545;
+  text-shadow: 0px -1px 0 rgba(255,255,255,0.6);
+}
+
+.api, .start {
+  position: absolute;
+  top: 0px;
+  bottom: 0px;
+  overflow: scroll;
+  box-sizing: border-box;
+  padding: 20px;
+}
+
+.start {
+  right: 0px;
+  width: 60%;
+  background-color: #fff;
+}
+
+.api {
+  left: 0px;
+  width: 40%;
+  border-right: 1px solid #ccc;
+  background-color: #f5f5f5;
+}
+
+.toplevel div {
+  padding: 0 0 5px 10px;
+}
+
+.options, .arguments, .methods {
+  border-left: 1px dashed #ccc;
+}
+
+.api div p {
+  margin: 0 0 5px 0;
+}
+
+/** Label stylings */
+.api .label {
+  display: inline-block;
+  background-color: #454545;
+  border-radius: 2px;
+  border: 1px solid rgba(0,0,0,0.2);
+  color: #fff;
+  line-height: 11px;
+  padding: 1px 2px;
+  font-size: 10px;
+  font-weight: 600;
+  text-transform: uppercase;
+  text-shadow: 0px -1px 0px rgba(0,0,0,0.2);
+}
+
+span.label.type {
+  background-color: #757E2B;
+}
+
+span.label.required {
+  background-color: #8E2603;
+}
+
+.options .label {
+  background-color: #E2A62E;
+}
+/** /Label stylings */
+
+.api .snippet {
+  font: 12px Courier;
+  display: inline-block;
+}
+
+.api .name {
+  font-weight: 600;
+  display: inline-block;
+  margin-bottom: 5px;
+}

+ 1 - 5
lib/dataconnection.js

@@ -26,11 +26,7 @@ function DataConnection(peer, provider, options) {
   Negotiator.startConnection(
   Negotiator.startConnection(
     this,
     this,
     this.options._payload || {
     this.options._payload || {
-      originator: true,
-      multiplex: this.options.multiplex // I don't think multiplex should be a
-                                        // top-level property because it only
-                                        // applies to the originator--otherwise
-                                        // we'd just have an options.pc to use.
+      originator: true
     }
     }
   );
   );
 }
 }

+ 0 - 3
lib/mediaconnection.js

@@ -41,13 +41,10 @@ MediaConnection.prototype.handleMessage = function(message) {
 
 
   switch (message.type) {
   switch (message.type) {
     case 'ANSWER':
     case 'ANSWER':
-      // TODO: assert sdp exists.
-      // Should we pass `this`?
       // Forward to negotiator
       // Forward to negotiator
       Negotiator.handleSDP(message.type, this, payload.sdp);
       Negotiator.handleSDP(message.type, this, payload.sdp);
       break;
       break;
     case 'CANDIDATE':
     case 'CANDIDATE':
-      // TODO
       Negotiator.handleCandidate(this, payload.candidate);
       Negotiator.handleCandidate(this, payload.candidate);
       break;
       break;
     default:
     default:

+ 0 - 8
lib/peer.js

@@ -32,7 +32,6 @@ function Peer(id, options) {
   if (options.secure === undefined && options.host !== util.CLOUD_HOST) {
   if (options.secure === undefined && options.host !== util.CLOUD_HOST) {
     options.secure = util.isSecure();
     options.secure = util.isSecure();
   }
   }
-  // TODO: document this feature
   // Set a custom log function if present
   // Set a custom log function if present
   if (options.logFunction) {
   if (options.logFunction) {
     util.setLogFunction(options.logFunction);
     util.setLogFunction(options.logFunction);
@@ -107,7 +106,6 @@ util.inherits(Peer, EventEmitter);
 Peer.prototype._retrieveId = function(cb) {
 Peer.prototype._retrieveId = function(cb) {
   var self = this;
   var self = this;
   var http = new XMLHttpRequest();
   var http = new XMLHttpRequest();
-  // TODO: apparently using ://something.com gives relative protocol?
   var protocol = this.options.secure ? 'https://' : 'http://';
   var protocol = this.options.secure ? 'https://' : 'http://';
   var url = protocol + this.options.host + ':' + this.options.port + '/' + this.options.key + '/id';
   var url = protocol + this.options.host + ':' + this.options.port + '/' + this.options.key + '/id';
   var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
   var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
@@ -166,7 +164,6 @@ Peer.prototype._handleMessage = function(message) {
       break;
       break;
 
 
     case 'EXPIRE': // The offer sent to a peer has expired without response.
     case 'EXPIRE': // The offer sent to a peer has expired without response.
-      // TODO: should this be on the DataConnection? It's currently here but I'm not so sure it belongs.
       this.emit('error', new Error('Could not connect to peer ' + peer));
       this.emit('error', new Error('Could not connect to peer ' + peer));
       break;
       break;
     case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
     case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
@@ -212,7 +209,6 @@ Peer.prototype._handleMessage = function(message) {
       }
       }
       break;
       break;
     default:
     default:
-      // TODO: if out of order, must queue.
       if (!payload) {
       if (!payload) {
         util.warn('You received a malformed message from ' + peer + ' of type ' + type);
         util.warn('You received a malformed message from ' + peer + ' of type ' + type);
         return;
         return;
@@ -373,8 +369,4 @@ Peer.prototype.disconnect = function() {
   });
   });
 }
 }
 
 
-/** The current browser. */
-// TODO: maybe expose util.supports
-Peer.browser = util.browserisms;
-
 exports.Peer = Peer;
 exports.Peer = Peer;

+ 16 - 30
lib/util.js

@@ -4,7 +4,7 @@ var util = {
 
 
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_HOST: '0.peerjs.com',
   CLOUD_PORT: 9000,
   CLOUD_PORT: 9000,
-  
+
   // Logging logic
   // Logging logic
   logLevel: 0,
   logLevel: 0,
   setLogLevel: function(level) {
   setLogLevel: function(level) {
@@ -13,7 +13,7 @@ var util = {
       util.logLevel = debugLevel;
       util.logLevel = debugLevel;
     } else {
     } else {
       // If they are using truthy/falsy values for debug
       // If they are using truthy/falsy values for debug
-      util.logLevel = (!!level) ? 3 : 0;
+      util.logLevel = level ? 3 : 0;
     }
     }
     util.log = util.warn = util.error = util.noop;
     util.log = util.warn = util.error = util.noop;
     if (util.logLevel > 0) {
     if (util.logLevel > 0) {
@@ -59,8 +59,21 @@ var util = {
   defaultConfig: defaultConfig,
   defaultConfig: defaultConfig,
   //
   //
 
 
+  // Returns the current browser.
+  browser: (function() {
+    if (window.mozRTCPeerConnection) {
+      return 'Firefox';
+    } else if (window.webkitRTCPeerConnection) {
+      return 'Chrome';
+    } else if (window.RTCPeerConnection) {
+      return 'Supported';
+    } else {
+      return 'Unsupported';
+    }
+  })(),
+  //
+
   // Lists which features are supported
   // Lists which features are supported
-  // Temporarily set everything to true
   supports: (function() {
   supports: (function() {
     var data = true;
     var data = true;
     var audioVideo = true;
     var audioVideo = true;
@@ -168,14 +181,7 @@ var util = {
   },
   },
 
 
 
 
-  // OLD
-  chromeCompatible: true,
-  firefoxCompatible: true,
-  chromeVersion: 26,
-  firefoxVersion: 22,
-
   debug: false,
   debug: false,
-  browserisms: '',
 
 
   inherits: function(ctor, superCtor) {
   inherits: function(ctor, superCtor) {
     ctor.super_ = superCtor;
     ctor.super_ = superCtor;
@@ -271,26 +277,6 @@ var util = {
   },
   },
   //
   //
 
 
-  // When we have proper version/feature mappings we can remove this
-  isBrowserCompatible: function() {
-    var c, f;
-    if (this.chromeCompatible) {
-      if ((c = navigator.userAgent.split('Chrome/')) && c.length > 1) {
-        // Get version #.
-        var v = c[1].split('.')[0];
-        return parseInt(v) >= this.chromeVersion;
-      }
-    }
-    if (this.firefoxCompatible) {
-      if ((f = navigator.userAgent.split('Firefox/')) && f.length > 1) {
-        // Get version #.
-        var v = f[1].split('.')[0];
-        return parseInt(v) >= this.firefoxVersion;
-      }
-    }
-    return false;
-  },
-
   isSecure: function() {
   isSecure: function() {
     return location.protocol === 'https:';
     return location.protocol === 'https:';
   }
   }

+ 0 - 4
test/adapter.js

@@ -1,9 +1,5 @@
 describe('adapter', function() {
 describe('adapter', function() {
 
 
-  it('sets browerisms', function() {
-    expect(exports.util.browserisms).to.match(/^Firefox||Webkit$/);
-  });
-
   it('sets RTCPeerConnection', function() {
   it('sets RTCPeerConnection', function() {
     expect(RTCPeerConnection).to.be.a('function');
     expect(RTCPeerConnection).to.be.a('function');
   });
   });

+ 0 - 41
test/connectionmanager.js

@@ -1,41 +0,0 @@
-describe('ConnectionManager', function() {
-
-  describe('constructor', function() {
-  });
-
-  it('inherits from EventEmitter');
-
-  describe('#_setupDataChannel', function() {
-  });
-
-  describe('#_makeOffer', function() {
-  });
-
-  describe('#_makeAnswer', function() {
-  });
-
-  describe('#_cleanup', function() {
-  });
-
-  describe('#_attachConnectionListeners', function() {
-  });
-
-  describe('#handleSDP', function() {
-  });
-
-  describe('#handleCandidate', function() {
-  });
-
-  describe('#handleLeave', function() {
-  });
-
-  describe('#close', function() {
-  });
-
-  describe('#connect', function() {
-  });
-
-  describe('#update', function() {
-  });
-
-});

+ 0 - 126
test/dataconnection.js

@@ -1,126 +0,0 @@
-describe('DataConnection', function() {
-
-  // Only run tests on compatible browser.
-  if (util.isBrowserCompatible()) {
-
-    var dc, pdc;
-
-    function DataChannelStub() {};
-    DataChannelStub.prototype = {
-      close: function() {
-        if (this.readyState === 'closed') {
-          throw Error();
-        }
-        this.readyState = 'closed';
-      },
-      // Only sends to peer's dc.
-      send: function(msg) {
-        pdc._handleDataMessage({ data: msg });
-      }
-    };
-
-    describe('constructor', function() {
-      it('should accept options properly', function() {
-        // Test without 'new' keyword.
-        dc = DataConnection('peer', null,
-          { serialization: 'json',
-            metadata: { message: 'I\'m testing!'} });
-
-        expect(dc.peer).to.be('peer');
-        expect(dc.serialization).to.be('json');
-        expect(dc.metadata.message).to.be('I\'m testing!');
-
-        expect(dc._dc).to.be(null);
-        dc._dc = new DataChannelStub();
-      });
-    });
-
-    it('inherits from EventEmitter');
-
-    before(function() {
-      dc = DataConnection('peer', null,
-        { serialization: 'json',
-          metadata: { message: 'I\'m testing!'} });
-      dc._dc = new DataChannelStub();
-    });
-
-    describe('#_configureDataChannel', function() {
-      it('should set the correct binaryType', function() {
-        dc._configureDataChannel();
-
-        if (util.browserisms === 'Firefox') {
-          expect(dc._dc.binaryType).to.be('arraybuffer');
-        } else {
-          expect(dc._reliable).to.be(undefined);
-        }
-      });
-
-      it('should fire an `open` event', function(done) {
-        dc.on('open', function() {
-          expect(dc.open).to.be(true)
-          done();
-        });
-        dc._dc.onopen();
-      });
-    });
-
-    describe('#_handleDataMessage', function() {
-
-    });
-
-    describe('#addDC', function() {
-      it('should add a DataConnection properly', function() {
-        pdc = new DataConnection('ignore', null, { serialization: 'json', reliable: true });
-        pdc.addDC(new DataChannelStub());
-
-        expect(pdc._dc).not.to.be(null);
-      });
-    });
-
-    describe('#send', function() {
-      it('should send data to the peer', function(done) {
-        pdc = new DataConnection('ignore', null, { serialization: 'json' });
-        pdc.on('data', function(data) {
-          expect(data.hello).to.be('peer-tester');
-          done();
-        });
-        dc.send({ hello: 'peer-tester' });
-      });
-    });
-
-    describe('#_cleanup', function() {
-      it('should emit a `close` event', function(done) {
-        var first = true;
-        dc.on('close', function() {
-          expect(dc.open).to.be(false)
-
-          // Calling it twice should be fine.
-          if (first) {
-            first = false;
-            dc._cleanup();
-          }
-
-          done();
-        });
-
-        dc._cleanup();
-      });
-    });
-
-    // Hacks hacks
-    describe('#close', function() {
-      it('should not call _cleanup', function() {
-        dc._cleanup = function() {
-          throw Error();
-        }
-
-        // Should not call _cleanup again.
-        dc.close();
-      });
-    });
-
-
-  } else {
-    it('should not work.', function() {});
-  }
-});

+ 0 - 16
test/peer.js

@@ -1,16 +0,0 @@
-describe('Peer', function() {
-
-  describe('constructor', function() {
-  });
-
-  it('inherits from EventEmitter');
-
-  describe('.browser', function() {
-    it('should be the current browser', function() {
-      var browser = window.mozRTCPeerConnection ? 'Firefox' : 'Unknown';
-      browser = window.webkitRTCPeerConnection ? 'Webkit' : browser;
-      expect(Peer.browser).to.be(browser);
-    });
-  });
-
-});

+ 0 - 32
test/socket.js

@@ -1,32 +0,0 @@
-describe('Socket', function() {
-
-  describe('constructor', function() {
-  });
-
-  it('inherits from EventEmitter');
-
-  describe('#start', function() {
-  });
-
-  describe('#_startWebSocket', function() {
-  });
-
-  describe('#_startXhrStream', function() {
-  });
-
-  describe('#_handleStream', function() {
-  });
-
-  describe('#_setHTTPTimeout', function() {
-  });
-
-  describe('#send', function() {
-  });
-
-  describe('#close', function() {
-  });
-
-  describe('#_wsOpen', function() {
-  });
-
-});

+ 1 - 1
test/test.html

@@ -12,8 +12,8 @@
   <script src="../deps/js-binarypack/lib/bufferbuilder.js"></script>
   <script src="../deps/js-binarypack/lib/bufferbuilder.js"></script>
   <script src="../deps/js-binarypack/lib/binarypack.js"></script>
   <script src="../deps/js-binarypack/lib/binarypack.js"></script>
   <script src="../deps/EventEmitter/EventEmitter.js"></script>
   <script src="../deps/EventEmitter/EventEmitter.js"></script>
-  <script src="../lib/util.js"></script>
   <script src="../lib/adapter.js"></script>
   <script src="../lib/adapter.js"></script>
+  <script src="../lib/util.js"></script>
   <script src="../lib/dataconnection.js"></script>
   <script src="../lib/dataconnection.js"></script>
   <script src="../lib/peer.js"></script>
   <script src="../lib/peer.js"></script>
   <script src="../lib/socket.js"></script>
   <script src="../lib/socket.js"></script>

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