From d46692622d5df31851508b23a8baa25ea0182198 Mon Sep 17 00:00:00 2001 From: Jonas Gloning <34194370+jonasgloning@users.noreply.github.com> Date: Wed, 27 Apr 2022 02:00:51 +0200 Subject: [PATCH] style: configure prettier --- .github/workflows/prettier.yml | 23 + .prettierignore | 3 + .prettierrc.toml | 3 + README.md | 112 +- changelog.md | 3 +- index.d.ts | 383 +- lib/api.ts | 172 +- lib/baseconnection.ts | 36 +- lib/dataconnection.ts | 657 +- lib/encodingQueue.ts | 88 +- lib/enums.ts | 89 +- lib/exports.ts | 4 +- lib/logger.ts | 89 +- lib/mediaconnection.ts | 241 +- lib/negotiator.ts | 722 +- lib/peer.ts | 1114 +- lib/servermessage.ts | 6 +- lib/socket.ts | 317 +- lib/supports.ts | 137 +- lib/util.ts | 290 +- package-lock.json | 44978 ++++++++++++++++--------------- package.json | 125 +- test/faker.ts | 98 +- test/logger.ts | 76 +- test/peer.ts | 399 +- test/setup.ts | 4 +- test/util.ts | 10 +- tsconfig.json | 18 +- webrtc-adapter.d.ts | 30 +- 29 files changed, 25205 insertions(+), 25022 deletions(-) create mode 100644 .github/workflows/prettier.yml create mode 100644 .prettierignore create mode 100644 .prettierrc.toml 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