Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Camomot committed Dec 21, 2018
1 parent 01eaf75 commit 84f136f
Show file tree
Hide file tree
Showing 9 changed files with 5,562 additions and 1,195 deletions.
105 changes: 44 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,62 @@
# firepeer

secure signalling and authentication for [simple-peer](https://github.com/feross/simple-peer) using [firebase realtime database](https://firebase.google.com/docs/database/).

## Getting Started

### setup firebase

Create a firebase project and setup the JS client SDK.

- https://firebase.google.com/docs/web/setup
- https://firebase.google.com/docs/database/web/start

### configure security rules

Add these security rules in the firebase console to secure the signalling data.

```json
{
"rules": {
"peers": {
"$uid": {
"$id": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid",
"$otherUid": {
"$otherId": {
".read": "auth != null && auth.uid == $otherUid",
".write": "auth != null && auth.uid == $otherUid",
".validate": "newData.hasChildren(['sdp', 'type']) || newData.hasChildren(['type', 'error'])",
"sdp": {
".validate": "newData.isString() && newData.val().length < 4000"
},
"error": {
".validate": "newData.isString() && newData.val().length < 1000"
},
"type": {
".validate": "newData.val() == 'offer' || newData.val() == 'answer'"
Secure p2p signalling and authentication for [simple-peer](https://github.com/feross/simple-peer) using [firebase realtime database](https://firebase.google.com/docs/database/).

## Setup firebase

1. [Create a firebase project and setup the javascript client SDK](https://firebase.google.com/docs/database/web/start).

2. Add these security rules in the firebase console to secure the signalling data.

```json
{
"rules": {
"peers": {
"$uid": {
"$id": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid",
"$otherUid": {
"$otherId": {
".read": "auth != null && auth.uid == $otherUid",
".write": "auth != null && auth.uid == $otherUid",
".validate": "newData.hasChildren(['sdp', 'type']) || newData.hasChildren(['type', 'error'])",
"sdp": {
".validate": "newData.isString() && newData.val().length < 4000"
},
"error": {
".validate": "newData.isString() && newData.val().length < 1000"
},
"type": {
".validate": "newData.val() == 'offer' || newData.val() == 'answer'"
}
}
}
}
}
}
}
}
}
}
```

Signaling data is exchanged in `/peers/$uid/$id/$otherUid/$otherId`.

Security rules ensure that only the intended users can exchange signalling data and the signals are valid.
```

- https://firebase.google.com/docs/database/security
Signaling data is exchanged in `/peers/$uid/$id/$otherUid/$otherId`. Security rules ensure that only the intended users can access signalling data and the signals are valid.

### enable sign-in method
> Shortcut: `https://console.firebase.google.com/project/<YOUR_PROJECT_ID>/database/rules`

By default, firebase does not enable any sign-in method. You will have to enable one in the firebase console. Right now, firebase supports Email/Password, Phone, Google, Facebook, Twitter, Github.

Firepeer requires authentication so at the very least you have to select [Anonymous authentication](https://firebase.google.com/docs/auth/web/anonymous-auth).
3. Enable your prefered sign-in method in the firebase console. Firepeer requires authentication so at the very least you have to select [anonymous authentication](https://firebase.google.com/docs/auth/web/anonymous-auth).

- https://firebase.google.com/docs/auth/web/start
> Shortcut: `https://console.firebase.google.com/project/<YOUR_PROJECT_ID>/authentication/providers`

### install
### Install
```js
npm install --save firepeer
```
```html
<script src="https://cdn.jsdelivr.net/npm/firepeer@<FIREPEER_VERSION>/lib/firepeer.min.js"></script>
```

### use firepeer
### Usage

```javascript
//alice side
Expand All @@ -79,7 +67,7 @@ firebase.initializeApp({

const alice = new FirePeer(firebase);

console.log(alice.id) // client id of alice
console.log(alice.id) // peer id of alice

//authenticate with the sign-in method you enabled in the console
await firebase.auth().signInWith*()
Expand All @@ -104,12 +92,12 @@ const bob = new FirePeer({
app: firebase.app()
});

console.log(bob.id) // client id of bob
console.log(bob.id) // id

//authenticate
await firebase.auth().signInWith*()

console.log(bob.uid) // uid of bob
console.log(bob.uid) // peer id of bob

// wait for connection and receive message
bob.on('connection', (connection)=>{
Expand All @@ -119,13 +107,8 @@ bob.on('connection', (connection)=>{
})
```

Connections are just instances of [SimplePeer](https://github.com/feross/simple-peer#api) already connected!

## API Reference

https://natzcam.github.io/firepeer
Connections are just instances of [simple-peer](https://github.com/feross/simple-peer#api) already connected!

## Demo
## [Reference](https://natzcam.github.io/firepeer)

- https://firepeer-demo.firebaseapp.com
- https://github.com/natzcam/firepeer-demo
## [Demo](https://firepeer-demo.firebaseapp.com)
3 changes: 0 additions & 3 deletions TODO

This file was deleted.

2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 84f136f

Please sign in to comment.