소개
WebRTC용 PeerConnection 브로커
기타 프로젝트측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalWebRTC peer-to-peer
This is a browser JS library that makes it easy to manage RTC peer connections, streams and data channels. It's currently used in emscripten to provide data transport for the posix sockets implementation.
Requirements
You will need either Firefox, or Chrome.
What it does
- Firefox and Chrome supported
- Binary transport using arraybuffers (Firefox only!)
- Multiple connections
- Broker service (on heroku), or run your own
- Connection timeouts
What it doesn't do (yet!)
- Peer brokering for establishing new connections through existing peer-to-peer
Quick start
Setting up a peer is easy. The code below will create a new peer and listen for incoming connections.
The onconnection handler is called each time a new connection is ready.
// Create a new Peer
var peer = new Peer(
'wss://webrtc-p2p-broker.herokuapp.com', // You can use this broker if you don't want to set one up
{
binaryType: 'arraybuffer',
video: false,
audio: false
}
);
// Listen for incoming connections
peer.listen();
var connections = {};
// Handle new connections
peer.onconnection = function(connection) {
// Store connections here so we can use them later
connections[connection.id] = connection; // Each connection has a unique ID
connection.ondisconnect = function(reason) {
delete connections[connection.id];
};
connection.onerror = function(error) {
console.error(error);
};
// Handle messages from this channel
// The label will be 'reliable' or 'unreliable', depending on how it was received
connection.onmessage = function(label, message) {
console.log(label, message);
};
// Sends a message to the other peer using the reliable data channel
connection.send('reliable', 'hi!');
// The connection exposes the underlying media streams
// You can attach them to DOM elements to get video/audio, if available
console.log(connection.streams.local, connection.streams.remote);
// Closes the connection
// This will cause `ondisconnect` to fire
connection.close();
};
// Print our route when it's available
peer.onroute = function(route) {
// This is our routing address from the broker
// It's used by peers who wish to connect with us
console.log('route:', route);
};
peer.onerror = function(error) {
console.log(error);
};
Another peer can connect easily to the one we made above by calling connect() on its routing address.
peer.connect(route);
Demo
There are some files in the demo directory that offer an example.
You can load it here and open the connect URL in another window.
For this example, the route is added to the URL query string so that the other peer can parse it and connect when the page loads, so all you need to share is the URL.
관련 프로젝트 살펴보기
불러오는 중…