Jelajahi Sumber

Updated the README

- The files associated with the patch to PeerJS have now been moved to
the `patch/` directory
- Updated `build.sh` so that it can now handle the new file structure
during the building of `node-peerjs`
- Updated the main project README
- Added a README for using the example scripts
Satnam Singh Brar 5 tahun lalu
induk
melakukan
ec70feb35c
7 mengubah file dengan 33 tambahan dan 54 penghapusan
  1. 12 47
      README.md
  2. 2 2
      build.sh
  3. 19 0
      examples/README.md
  4. 0 0
      patch/base_code_changes.diff
  5. 0 0
      patch/footer_patch.js
  6. 0 0
      patch/header_patch.js
  7. 0 5
      pull.sh

+ 12 - 47
README.md

@@ -1,57 +1,22 @@
-# React Native PeerJS
+# Node PeerJS
 
-[react-native-webrtc](https://github.com/react-native-webrtc/react-native-webrtc) has brought WebRTC to React Native. [PeerJS](https://github.com/peers/peerjs) is a simple API to work with WebRTC in the Browser.
-
-I made it so that PeerJS works with react-native-webrtc in a React Native application.
+A port of the [PeerJS library](https://github.com/peers/peerjs) which currently only works on browsers. It uses the `wrtc` node module to provide webrtc functionality and fixes various compatibility issues with NodeJS.
 
 ## Install
 
-Install react-native-webrtc according to their install guide. Then add react-native-peerjs:
-
 ```
-yarn add react-native-peerjs
+npm i --save node-peerjs
 ```
 
 ## Usage
 
-Just refer to the PeerJS documentation. Here is an example:
-
-```js
-import Peer from 'react-native-peerjs';
-
-const localPeer = new Peer();
-localPeer.on('error', console.log);
-
-localPeer.on('open', localPeerId => {
-  console.log('Local peer open with ID', localPeerId);
-
-  const remotePeer = new Peer();
-  remotePeer.on('error', console.log);
-  remotePeer.on('open', remotePeerId => {
-    console.log('Remote peer open with ID', remotePeerId);
-
-    const conn = remotePeer.connect(localPeerId);
-    conn.on('error', console.log);
-    conn.on('open', () => {
-      console.log('Remote peer has opened connection.');
-      console.log('conn', conn);
-      conn.on('data', data => console.log('Received from local peer', data));
-      console.log('Remote peer sending data.');
-      conn.send('Hello, this is the REMOTE peer!');
-    });
-  });
-});
-
-localPeer.on('connection', conn => {
-  console.log('Local peer has received connection.');
-  conn.on('error', console.log);
-  conn.on('open', () => {
-    console.log('Local peer has opened connection.');
-    console.log('conn', conn);
-    conn.on('data', data => console.log('Received from remote peer', data));
-    console.log('Local peer sending data.');
-    conn.send('Hello, this is the LOCAL peer!');
-  });
-});
-```
+Just refer to the PeerJS documentation for a more detailed description of how the module works. You can also take a look at the `examples/` directory in this repo to see a small example using `node-peerjs`
+
+## Build history
+
+#### v1.0.0
 
+- Based on commit [0645dc3ddd51cbc1649ed13af56d9b66958fd62b](https://github.com/peers/peerjs/commit/0645dc3ddd51cbc1649ed13af56d9b66958fd62b) of PeerJS
+- First release version that tries to make most of the peerJS functionality work on NodeJS
+- See file `patch.diff` for all the modification made to the base PeerJS code and get it running on NodeJS
+- PeerJS code not included in this repo

+ 2 - 2
build.sh

@@ -9,14 +9,14 @@ rm -rf dist/
 cd peerjs
 
 # Generate a file documenting the changes made to peerjs source code for future reference
-git diff -- . ':(exclude)dist/*' > ../patch.diff
+git diff -- . ':(exclude)dist/*' > ../patch/base_code_changes.diff
 
 # Build the existing peerjs project into ../dist
 ../node_modules/.bin/parcel build --no-source-maps lib/exports.ts -d ../dist --out-file peerjs.min.js
 cd ../
 
 # Append some of our modifications onto the built peerjs code
-cat header_patch.js dist/peerjs.min.js footer_patch.js > dist/node-peerjs.js
+cat patch/header_patch.js dist/peerjs.min.js patch/footer_patch.js > dist/node-peerjs.js
 rm dist/peerjs.min.js
 
 echo "Done. dist/node-peerjs.js"

+ 19 - 0
examples/README.md

@@ -0,0 +1,19 @@
+# node-peerjs examples
+
+- The example scripts in this directory implements a simple echo server over a P2P webRTC connection using `node-peerjs`
+- Run the server
+    
+    ```
+    node echo_server.js
+    ```
+
+    - The echo server tries claims the id of `abcdefghijklmnopqrstuvwxyz` on the PeerJS signalling server
+- Run the client in a separate terminal window
+
+    ```
+    node echo_client.js
+    ```
+
+    - The client script allows the signalling server to give it an arbirary id
+    - It initiates a direct connection to our server which we know has an id of `abcdefghijklmnopqrstuvwxyz`
+- You can now type in anything into the client terminal and the echo server script will simple echo it back

+ 0 - 0
patch.diff → patch/base_code_changes.diff


+ 0 - 0
footer_patch.js → patch/footer_patch.js


+ 0 - 0
header_patch.js → patch/header_patch.js


+ 0 - 5
pull.sh

@@ -1,5 +0,0 @@
-git clone https://github.com/peers/peerjs
-cd peerjs
-
-# This is the commit of peerjs master branch that this module was created from
-git reset --hard 0645dc3ddd51cbc1649ed13af56d9b66958fd62b