diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 000000000..6bbf8808a --- /dev/null +++ b/.github/workflows/prettier.yml @@ -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 . \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..3242df658 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +dist +docs +package-json.lock \ No newline at end of file diff --git a/.prettierrc.toml b/.prettierrc.toml new file mode 100644 index 000000000..437054d3b --- /dev/null +++ b/.prettierrc.toml @@ -0,0 +1,3 @@ +trailingComma = "all" +semi = true +useTabs = true \ No newline at end of file diff --git a/README.md b/README.md index 5803a57ff..e67cc59f1 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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