Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/feross/simple-peer

📡 Simple WebRTC video, voice, and data channels
https://github.com/feross/simple-peer

browser data-channels javascript nodejs p2p peer-connection webrtc

Last synced: about 1 month ago
JSON representation

📡 Simple WebRTC video, voice, and data channels

Lists

README

        

# simple-peer [![ci][ci-image]][ci-url] [![coveralls][coveralls-image]][coveralls-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] [![javascript style guide][sauce-image]][sauce-url]

[ci-image]: https://img.shields.io/github/workflow/status/feross/simple-peer/ci/master
[ci-url]: https://github.com/feross/simple-peer/actions
[coveralls-image]: https://coveralls.io/repos/github/feross/simple-peer/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/feross/simple-peer?branch=master
[npm-image]: https://img.shields.io/npm/v/simple-peer.svg
[npm-url]: https://npmjs.org/package/simple-peer
[downloads-image]: https://img.shields.io/npm/dm/simple-peer.svg
[downloads-url]: https://npmjs.org/package/simple-peer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
[sauce-image]: https://saucelabs.com/buildstatus/simple-peer
[sauce-url]: https://saucelabs.com/u/simple-peer

#### Simple WebRTC video, voice, and data channels


Sponsored by    DFINITY

> We are hiring a peer-to-peer WebRTC mobile Web application expert.
>
> [DFINITY](http://dfinity.org/) is building an exciting peer-to-peer WebRTC-based mobile Web app to help improve democracy on the Internet Computer blockchain. The mobile web app connects groups of up to four people in a peer-to-peer WebRTC audio and video call so that they can mutually prove unique personhood.
>
> We are looking for a software engineer or consultant who can help us solve (platform-dependent) reliability issues of our implementation. We are interested in applicants with substantial WebRTC experience for mobile Web apps, experience with different communication patterns (e.g., peer-to-peer, server relay), and substantial problem-solving skills. Having experience in automated testing of this type of applications is a plus. Pay is extremely competitive for the right expertise. For details, please see the [full job description](https://boards.greenhouse.io/dfinity/jobs/5910101002?gh_src=c28327ae2us).

## features

- concise, **node.js style** API for [WebRTC](https://en.wikipedia.org/wiki/WebRTC)
- **works in node and the browser!**
- supports **video/voice streams**
- supports **data channel**
- text and binary data
- node.js [duplex stream](http://nodejs.org/api/stream.html) interface
- supports advanced options like:
- enable/disable [trickle ICE candidates](http://webrtchacks.com/trickle-ice/)
- manually set config options
- transceivers and renegotiation

This package is used by [WebTorrent](https://webtorrent.io) and [many others](#who-is-using-simple-peer).

- [install](#install)
- [examples](#usage)
* [A simpler example](#a-simpler-example)
* [data channels](#data-channels)
* [video/voice](#videovoice)
* [dynamic video/voice](#dynamic-videovoice)
* [in node](#in-node)
- [api](#api)
- [events](#events)
- [error codes](#error-codes)
- [connecting more than 2 peers?](#connecting-more-than-2-peers)
- [memory usage](#memory-usage)
- [connection does not work on some networks?](#connection-does-not-work-on-some-networks)
- [Who is using `simple-peer`?](#who-is-using-simple-peer)
- [license](#license)

## install

```
npm install simple-peer
```

This package works in the browser with [browserify](https://browserify.org). If
you do not use a bundler, you can use the `simplepeer.min.js` standalone script
directly in a `` tag. This exports a `SimplePeer` constructor on
`window`. Wherever you see `Peer` in the examples below, substitute that with
`SimplePeer`.

## usage

Let's create an html page that lets you manually connect two peers:

```html
<html>
<body>
<style>
#outgoing {
width: 600px;
word-wrap: break-word;
white-space: normal;
}
</style>
<form>
<textarea id="incoming"></textarea>
<button type="submit">submit</button>
</form>
<pre id="outgoing"></pre>
<script src="simplepeer.min.js">

const p = new SimplePeer({
initiator: location.hash === '#1',
trickle: false
})

p.on('error', err => console.log('error', err))

p.on('signal', data => {
console.log('SIGNAL', JSON.stringify(data))
document.querySelector('#outgoing').textContent = JSON.stringify(data)
})

document.querySelector('form').addEventListener('submit', ev => {
ev.preventDefault()
p.signal(JSON.parse(document.querySelector('#incoming').value))
})

p.on('connect', () => {
console.log('CONNECT')
p.send('whatever' + Math.random())
})

p.on('data', data => {
console.log('data: ' + data)
})