Eric Zhang před 11 roky
rodič
revize
cf3470ac4a
1 změnil soubory, kde provedl 26 přidání a 10 odebrání
  1. 26 10
      README.md

+ 26 - 10
README.md

@@ -1,30 +1,44 @@
 # PeerJS: peer-to-peer in the browser #
 # PeerJS: peer-to-peer in the browser #
 
 
-PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC, supporting both WebRTC data channels and media streams.
+PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC, supporting both data channels and media streams.
 
 
-##[http://peerjs.com](http://peerjs.com)
+### [http://peerjs.com](http://peerjs.com)
+
+## Setup
 
 
 
 
 **Include the library**
 **Include the library**
 
 
-    <script src="http://cdn.peerjs.com/0.3/peer.js"></script>
+```html
+<script src="http://cdn.peerjs.com/0.3/peer.js"></script>
+```
 
 
-**Peer**
+**Create a Peer**
+```javascript
+var peer = new Peer('pick-an-id', {key: 'myapikey'}); 
+// You can pick your own id or omit the id if you want to get a random one from the server.
+```
 
 
+## Data connections
 ```javascript
 ```javascript
-var peer = new Peer('thing1', {key: 'myapikey'}); // You can omit the ID if you want to get a random one from the server.
 
 
-/** Data connections. */
+// Connect
+var conn = peer.connect('a-peers-id');
+conn.on('open', function(){
+  conn.send('hi!');
+});
 
 
-peer.on('connection', function(connection) {
-  connection.on('data', function(data){
+// Receive
+peer.on('connection', function(conn) {
+  conn.on('data', function(data){
     // Will print 'hi!'
     // Will print 'hi!'
     console.log(data);
     console.log(data);
   });
   });
 });
 });
+```
 
 
-/** Media calls. */
-
+**Media calls**
+```javascript
 var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
 var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
 peer.on('call', function(call) {
 peer.on('call', function(call) {
   getUserMedia({video: true, audio: true}, function(stream) {
   getUserMedia({video: true, audio: true}, function(stream) {
@@ -38,6 +52,8 @@ peer.on('call', function(call) {
 });
 });
 ```
 ```
 
 
+```
+
 **Connecting peer**
 **Connecting peer**
 
 
 ```javascript
 ```javascript