暂无描述

Jairo ddc7205c7c Update README.md 5 年之前
dist 66862d8aba no regeneratorRuntime 5 年之前
.gitignore 88e062dc33 dont ignore dist 6 年之前
LICENSE fc7c88d3e3 Update LICENSE 10 年之前
README.md ddc7205c7c Update README.md 5 年之前
index.js d859315a46 v2 5 年之前
package.json 66862d8aba no regeneratorRuntime 5 年之前
yarn.lock d859315a46 v2 5 年之前

README.md

PeerJS: Simple peer-to-peer with WebRTC

https://t.me/joinchat/ENhPuhTvhm8WlIxTjQf7Og

Backers on Open Collective Sponsors on Open Collective

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.

It uses the concept of room, you can only connect to rooms, if you want to speak with someone, you both join to the same room. If you want to speak with multiple people, everyone join to the same room.

A room has one type (audio, video, data) and it cannot change, but you can join to as many rooms as you want.


v2 Roadmap:

  • Connection metadata
  • Max number of peers in a room
  • Room password
  • Disconnections
  • Allow configurate custom MQTT server and TURN/STUN servers
  • Test joining to multiple rooms
  • Mute/unmute audio

Install

  yarn add peers/peerjs#v2.0.0

Example

import Peer from 'peerjs'

const p = new Peer("Random room ID", {
  mode: 'video', // 'audio' for audio only; 'data' for DataChannel
  onRemoteStream: rs => {
    document.querySelector('#remote_vid').srcObject = rs
  },
  onLocalStream: ls => {
    document.querySelector('#local_vid').srcObject = ls
  },
  onDataStream: ds => {
    ds.onmessage = m => {
      console.log('Got message', m)
    }

    setTimeout(() => {
      ds.send('hello')
    }, 3000)
  }
})

// unpause video send
document.querySelector('#en').onclick = () => {
  p.video(true)
}
// pause video send
document.querySelector('#di').onclick = () => {
  p.video(false)
}


Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

PeerJS is licensed under the MIT License.