Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releases 2.0 #927

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9d6fd16
init
afrokick Feb 19, 2022
6bfb586
add workflows
afrokick Feb 19, 2022
a930635
rename util to Utils
afrokick Feb 19, 2022
c8a0db3
Merge pull request #926 from afrokick/refactoring/target-es6
afrokick Feb 19, 2022
e4de8dd
separate dist files to esm, cjs and iife
afrokick Feb 20, 2022
12e3a68
simplify import
afrokick Feb 20, 2022
fe7243e
Merge pull request #928 from afrokick/features/nodejs-support
afrokick Feb 20, 2022
28a84ae
2.0.0-beta.0
afrokick Feb 20, 2022
b58ae5f
update readme
afrokick Feb 20, 2022
a578e0b
update example
afrokick Feb 20, 2022
76636b7
update FAQ with empty stream
afrokick Feb 20, 2022
73d72b8
add iOS question
afrokick Feb 20, 2022
15539dc
add Edge to supported browsers
afrokick Feb 20, 2022
27b37cf
clean empty connections
afrokick Feb 20, 2022
59966a2
add 'change quality/codecs' to FAQ
afrokick Feb 20, 2022
3e9f6f7
fix tests for nodejs
afrokick Feb 20, 2022
4c035d3
fix buffered messaged #864
afrokick Feb 20, 2022
f08c81d
node 14 for tests
afrokick Feb 21, 2022
f524498
maybe fix tests(sigfault)
afrokick Feb 21, 2022
be8a5cf
revert Node version to 16 for tests
afrokick Feb 21, 2022
8de0afe
update readme
afrokick Feb 21, 2022
d84e10c
2.0.0-beta.1
afrokick Feb 21, 2022
764281b
fix build
afrokick Feb 21, 2022
1294749
2.0.0-beta.2
afrokick Feb 21, 2022
8a3a45d
fix api fetch
afrokick Feb 21, 2022
1a54d1f
2.0.0-beta.3
afrokick Feb 21, 2022
0e1efd0
style: cherry pick prettier config from master
jonasgloning Sep 11, 2022
302b2b2
style: run prettier
jonasgloning Sep 11, 2022
e351bd4
tests: switch to wrtc fork
jonasgloning Sep 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/prettifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Template for commit messages from Prettifier.
# Placeholders are:
# - {{commitSha}}: the SHA of your commit that Prettifier formats
commitMessage: 'AutoFormat {{commitSha}}'

fixByCommit: true

fixByPullRequest: false

prettified-message: >
I have adjusted the formatting of this pull request for you.

To stop seeing this message, please install Prettier on your machine and run
`meteor npm run format` to format your changes before submitting them.
Comment on lines +10 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message should be updated (not using meteor or having a script called format).


# Whether to only check branches that have an active pull request.
pulls-only: true
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Unit tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: 'npm'
- run: npm i
- name: Run tsc-check
run: npm run tsc-check
- name: Run tests
run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ npm-debug.log
test/output
.tscache
test/public
.vscode/
.vscode/
dist
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
*.html

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not format HTML files?

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120,
"arrowParens": "avoid",
"endOfLine": "auto"
}
95 changes: 93 additions & 2 deletions changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,100 @@

All notable changes will be documented in this file.

## vNEXT
## vNext

...

<a name="2.0.0"></a>

## v2.0.0 (upcoming)

The main goals of the second version:

- modernize the code base: use `es6` and latest tools;
- target to the latest browsers API(you can use webrtc adapter to shim old browsers);
- shrink the package size;
- NodeJS support.

### Breaking changes

#### Drop ES5 supports

If you need to support es5, you can recompile the lib from the sources or use the latest version from the v1 branch like `npm i peerjs@1`.

#### Remove `webrtc-adapter` package from `dependencies`

The modern browsers mostly works good without any additional libs like webrtc-adapter.

You can increase cross browsers support by manually add `webrtc-adapter` package to your project:

`npm install webrtc-adapter`

Then import it as soon as possible. For example, you have an entry point for your application in the file `index.tsx`. So, lets add the import:

```
import 'webrtc-adapter'; // as soon as possible

//
//... your startup code
//

```

See more: https://github.com/webrtcHacks/adapter

#### Remove browser detection features from the library.

The `browser` field was removed from the `util` class
and the `OFFER` packet.

#### The `main` field of `package.json` now points to the non minified version.

Today, most projects use bundlers with a minification step. Sometimes, double minification can lead to issues.

If you want to use the minified version, use it directly from the `dist` folder like:

```
import Peer from 'peerjs/dist/peerjs.min.js';

...
```

#### Remove `dist` folder from git

Please, try to host the package by yourself. It is more securely and you don't depend on third party.

In any case, you can use a CDN like `unpkg.com`:

```html
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
```

#### Replace `util.supports` to `Peer.getFeatures()`

You can check the possible features of WebRTC by static method `Peer.getFeatures()`
before instantiating a `Peer` object.

#### Use `ESBuild` as bundler.

Parcel 1 was a good choice years ago, but now esbuild seems like simple and good solution!

### New

#### NodeJS support

Yeah! You can use `peerjs` in NodeJS!

See details in https://github.com/peers/peerjs/pull/928

### Another changes

- update `devDependencies`
- apply `Prettier` for the code style
- rename `util` to `Utils`
- remove `peerjs` export.
- fix #864

<a name="1.3.2"></a>

## 1.3.2 (2021-03-11)
Expand Down Expand Up @@ -61,7 +151,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 +187,7 @@ Almost all project was refactored!!!
- changed: fetch api instead of xhr

### Features

- added: heartbeat #502

### Bug Fixes
Expand Down
117 changes: 76 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
# 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.

## Features

- TypeScript 100%
- respects CommonJS, ES Module
- NodeJS support
- Simple API
- DataChannel + MediaStream

## Live Example

Here's an example application that uses both media and data connections: https://glitch.com/~peerjs-video. The example also uses its own [PeerServer](https://github.com/peers/peerjs-server).

## Setup

**Install a dependency**

with npm:

`npm install peerjs`

with yarn:

`yarn add peerjs`

**Include the library**

with npm:
`npm install peerjs`

with yarn:
`yarn add peerjs`
```js
// The usage -
import Peer from 'peerjs';
```
```js
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!');
});
```

**Receive**

```javascript
peer.on('connection', (conn) => {
conn.on('data', (data) => {
peer.on('connection', conn => {
conn.on('data', data => {
// Will print 'hi!'
console.log(data);
});
Expand All @@ -55,29 +70,40 @@ peer.on('connection', (conn) => {
```

## 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);
});

```
**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) => {
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) => {
},
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);
}
);
});
```

Expand All @@ -89,20 +115,33 @@ 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+
Firefox: 70

Chrome: 76

Edge: 79

Opera: 63

Safari: 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
- How to create an empty stream?

https://github.com/peers/peerjs/issues/594#issuecomment-1046147052

- It doesn't work for iOS, any idea?

https://github.com/peers/peerjs/issues/599#issuecomment-559981544

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.
- How to change the codecs/quality of streams?

You should modify the sdp message: https://github.com/peers/peerjs/issues/901#issuecomment-1046230997

## Links

Expand Down Expand Up @@ -225,7 +264,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 +279,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).