Skip to content

Commit

Permalink
style: configure prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgloning committed Apr 27, 2022
1 parent ed56c93 commit d466926
Show file tree
Hide file tree
Showing 29 changed files with 25,205 additions and 25,022 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# From https://til.simonwillison.net/github-actions/prettier-github-actions
name: Check JavaScript for conformance with Prettier

on:
push:
pull_request:

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v2
- uses: actions/cache@v2
name: Configure npm caching
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/workflows/prettier.yml') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Run prettier
run: |-
npx prettier --check .
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
docs
package-json.lock
3 changes: 3 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trailingComma = "all"
semi = true
useTabs = true
112 changes: 61 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# PeerJS: Simple peer-to-peer with WebRTC #
# PeerJS: Simple peer-to-peer with WebRTC

### https://t.me/joinchat/VWI0UBxnG7f7_DV7

[![Backers on Open Collective](https://opencollective.com/peer/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/peer/sponsors/badge.svg)](#sponsors)
[![Sponsors on Open Collective](https://opencollective.com/peer/sponsors/badge.svg)](#sponsors)

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.

Expand All @@ -13,71 +13,86 @@ Here's an example application that uses both media and data connections: https:/

## Setup


**Include the library**

with npm:
`npm install peerjs`

with yarn:
`yarn add peerjs`
```js
// The usage -
import Peer from 'peerjs';
```
with npm:
`npm install peerjs`

with yarn:
`yarn add peerjs`

```js
// The usage -
import Peer from "peerjs";
```

**Create a Peer**

**Create a Peer**
```javascript
const peer = new Peer('pick-an-id');
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
const conn = peer.connect('another-peers-id');
conn.on('open', () => {
conn.send('hi!');
const conn = peer.connect("another-peers-id");
conn.on("open", () => {
conn.send("hi!");
});
```

**Receive**

```javascript
peer.on('connection', (conn) => {
conn.on('data', (data) => {
// Will print 'hi!'
console.log(data);
});
conn.on('open', () => {
conn.send('hello!');
});
peer.on("connection", (conn) => {
conn.on("data", (data) => {
// Will print 'hi!'
console.log(data);
});
conn.on("open", () => {
conn.send("hello!");
});
});
```

## Media calls

**Call**
```javascript
navigator.mediaDevices.getUserMedia({video: true, audio: true}, (stream) => {
const call = peer.call('another-peers-id', stream);
call.on('stream', (remoteStream) => {
// Show stream in some <video> element.
});
}, (err) => {
console.error('Failed to get local stream', err);
});

```javascript
navigator.mediaDevices.getUserMedia(
{ video: true, audio: true },
(stream) => {
const call = peer.call("another-peers-id", stream);
call.on("stream", (remoteStream) => {
// Show stream in some <video> element.
});
},
(err) => {
console.error("Failed to get local stream", err);
},
);
```

**Answer**

```javascript
peer.on('call', (call) => {
navigator.mediaDevices.getUserMedia({video: true, audio: true}, (stream) => {
call.answer(stream); // Answer the call with an A/V stream.
call.on('stream', (remoteStream) => {
// Show stream in some <video> element.
});
}, (err) => {
console.error('Failed to get local stream', err);
});
peer.on("call", (call) => {
navigator.mediaDevices.getUserMedia(
{ video: true, audio: true },
(stream) => {
call.answer(stream); // Answer the call with an A/V stream.
call.on("stream", (remoteStream) => {
// Show stream in some <video> element.
});
},
(err) => {
console.error("Failed to get local stream", err);
},
);
});
```

Expand All @@ -90,20 +105,19 @@ npm test
## Browsers support

| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
| --------- | --------- | --------- |
| last 4 versions| last 4 versions| 12.1+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| last 4 versions | last 4 versions | 12.1+ |

## Safari

1. Safari supports only string data when sending via DataConnection. Use JSON serialization type if you want to communicate with Safari. By default, DataConnection uses Binary serialization type.

## FAQ

Q. I have a message ```Critical dependency: the request of a dependency is an expression``` in browser's console
Q. I have a message `Critical dependency: the request of a dependency is an expression` in browser's console

A. The message occurs when you use PeerJS with Webpack. It is not critical! It relates to Parcel https://github.com/parcel-bundler/parcel/issues/2883 We'll resolve it when updated to Parcel V2.


## Links

### [Documentation / API Reference](https://peerjs.com/docs/)
Expand Down Expand Up @@ -225,7 +239,6 @@ Thank you to all our backers! [[Become a backer](https://opencollective.com/peer
<a href="https://opencollective.com/peer/backer/99/website?requireActive=false" target="_blank"><img src="https://opencollective.com/peer/backer/99/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/peer/backer/100/website?requireActive=false" target="_blank"><img src="https://opencollective.com/peer/backer/100/avatar.svg?requireActive=false"></a>


## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/peer#sponsor)]
Expand All @@ -241,9 +254,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<a href="https://opencollective.com/peer/sponsor/8/website" target="_blank"><img src="https://opencollective.com/peer/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/peer/sponsor/9/website" target="_blank"><img src="https://opencollective.com/peer/sponsor/9/avatar.svg"></a>



## License

PeerJS is licensed under the [MIT License](https://tldrlegal.com/l/mit).

3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ All notable changes will be documented in this file.
## 1.0.3 (2019-08-21)

- add pingInterval option

<a name="1.0.2"></a>

## 1.0.2 (2019-07-20)
Expand Down Expand Up @@ -97,6 +97,7 @@ Almost all project was refactored!!!
- changed: fetch api instead of xhr

### Features

- added: heartbeat #502

### Bug Fixes
Expand Down
Loading

0 comments on commit d466926

Please sign in to comment.