|
5 年之前 | |
---|---|---|
dist | 5 年之前 | |
.gitignore | 6 年之前 | |
LICENSE | 10 年之前 | |
README.md | 5 年之前 | |
index.js | 5 年之前 | |
package.json | 5 年之前 | |
yarn.lock | 5 年之前 |
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.
yarn add peers/peerjs#v2.0.0
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)
}
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
PeerJS is licensed under the MIT License.