瀏覽代碼

update README

afrokick 6 年之前
父節點
當前提交
05d57bf436
共有 1 個文件被更改,包括 21 次插入22 次删除
  1. 21 22
      README.md

+ 21 - 22
README.md

@@ -5,7 +5,7 @@
 
 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)
+### [https://peerjs.com](https://peerjs.com)
 
 ## Setup
 
@@ -21,24 +21,23 @@ PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built
 
 
 **Create a Peer**  
-Get a [free API key](http://peerjs.com/peerserver). Your id only needs to be unique to the namespace of your API key.
 ```javascript
-var peer = new Peer('pick-an-id', {key: 'myapikey'}); 
+const peer = new Peer('pick-an-id'); 
 // You can pick your own id or omit the id if you want to get a random one from the server.
 ```
 
 ## Data connections
 **Connect**
 ```javascript
-var conn = peer.connect('another-peers-id');
-conn.on('open', function(){
+const conn = peer.connect('another-peers-id');
+conn.on('open', () => {
   conn.send('hi!');
 });
 ```
 **Receive**
 ```javascript
-peer.on('connection', function(conn) {
-  conn.on('data', function(data){
+peer.on('connection', (conn) => {
+  conn.on('data', (data) => {
     // Will print 'hi!'
     console.log(data);
   });
@@ -49,40 +48,40 @@ peer.on('connection', function(conn) {
 **Call**
 ```javascript
 navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
-navigator.getUserMedia({video: true, audio: true}, function(stream) {
-  var call = peer.call('another-peers-id', stream);
-  call.on('stream', function(remoteStream) {
+navigator.getUserMedia({video: true, audio: true}, (stream) => {
+  const call = peer.call('another-peers-id', stream);
+  call.on('stream', (remoteStream) => {
     // Show stream in some <video> element.
   });
-}, function(err) {
-  console.log('Failed to get local stream' ,err);
+}, (err) => {
+  console.error('Failed to get local stream', err);
 });
 
 ```
 **Answer**
 ```javascript
 navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
-peer.on('call', function(call) {
-  navigator.getUserMedia({video: true, audio: true}, function(stream) {
+peer.on('call', (call) => {
+  navigator.getUserMedia({video: true, audio: true}, (stream) => {
     call.answer(stream); // Answer the call with an A/V stream.
-    call.on('stream', function(remoteStream) {
+    call.on('stream', (remoteStream) => {
       // Show stream in some <video> element.
     });
-  }, function(err) {
-    console.log('Failed to get local stream' ,err);
+  }, (err) => {
+    console.error('Failed to get local stream', err);
   });
 });
 ```
 
-## Run tests
+## Running tests
 
-`npm test`
+```bash
+npm test
+```
 
 ## Links
 
-### [Documentation / API Reference](http://peerjs.com/docs)
-
-### [WebRTC Browser compatibility status](http://peerjs.com/status)
+### [Documentation / API Reference](https://peerjs.com/docs)
 
 ### [PeerServer](https://github.com/peers/peerjs-server)