rtc-data-connection
v0.0.1
Published
Simple wrapper around native RTCPeerConnnection data channels
Downloads
6
Readme
RTC Data Connection
A slightly simplified and smoothed-over wrapper around the native WebRTC peer connection and data channels APIs. This is for data connections only - no audio/video streams. See simple-rtc-data-connection for an even simpler version and example stuffs.
Installation
npm install rtc-data-connection
Usage
var RTCDataConnection = require('rtc-data-connection');
var dataConnection = new RTCDataConnection();
dataConnection.on('offer', function (offer) {
// send offer to peer
socket.emit('offer', offer);
})
dataConnection.on('answer', function (answer) {
// send answer to peer
socket.emit('answer', answer);
})
dataConnection.on('candidate', function (candidate) {
// send candidate to peer
socket.emit('candidate', candidate);
})
dataConnection.on('open', function () {
// connection opened!
this.send('hello, world!');
})
// assume a websocket signaling server
socket.on('offer', function (offer) {
// set local description and create an answer
dataConnection.setDescription(offer);
dataConnection.createAnswer();
});
socket.on('answer', function (answer) {
dataConnection.setDescription(answer);
});
socket.on('candidate', function (candidate) {
dataConnection.addCandidate(candidate);
});
// someone needs to be the first to offer...
dataConnection.createOffer();
Using in node w/ wrtc
This package was originally built for the browser, but it also works in node by leveraging the wrtc module. The module just needs to be installed and rtc-data-connection will use it.
License
Copyright 2014 Cameron Lakenen