1.1.0 • Published 4 years ago
@davey2/webrtc-signaling v1.1.0
WebRTC Signaling
Install
Install with npm
npm install @davey2/webrtc-signaling
or include in browser
<script src="https://unpkg.com/@davey2/webrtc-signaling"></script>
Usage
Constructor
const signaling = new WebRTCSignaling(/* optional id */);
Events
signaling.on("open", () => {
console.log(signaling.id);
// output: random uuid
});
signaling.on("error", error => {
// possible errors:
// - "id-busy" - the id in the constructor is already taken
// - "unavailable-id" - the id does not exist
console.error(error);
});
// receive incoming connections
signaling.on("connection", peer => {
// peer type is RTCPeerConnection
});
Connect
const peer = signaling.connect("REMOTE-ID");
// peer type is RTCPeerConnection
// if the id is not exist, emit the error to error event listener