Establish WebRTC Data Channels between browser-node and node-node with a TCP/HTTP/WebSockets "createServer/attach" like interface
Switch branches/tags
Nothing to show
Clone or download
Latest commit 0d7f9b8 Dec 9, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples add requirelx example Jun 3, 2015
node_modules add codestyle and precmmit hook May 27, 2015
src Add check for existence of origin header and add error arg to README … Dec 8, 2015
tests add one simple test case May 27, 2015
.gitignore add codestyle and precommit hook May 27, 2015
LICENSE
README.md Add check for existence of origin header and add error arg to README … Dec 8, 2015
package.json
webrtc-connect.min.js Add check for existence of origin header and add error arg to README … Dec 8, 2015

README.md

webrtc-connect

Establish WebRTC Data Channels between browser-node and node-node with a TCP/HTTP/WebSockets "createServer/attach" like interface

Badgers

js-standard-style

Why no use WebSockets instead?

WebRTC provides a set of different features, one of them being confidentiality, that is, WebRTC Data Channels are encrypted by default and can't be eavesdropped, while for WebSockets, we need first to set up TLS/SSL.

When it comes to implement authenticity, make sure to reference to "WebRTC and MITM Attacks" article from on WebRTC Hacks, as it offers a very good insight.

Usage

Client

Works in node.js and in the browser(one that supports WebRTC that is :)) with browserify or by including the standalone file webrtc-connect.min.js which exports a rtcc object to window.

var rtcc = require('webrtc-connect');

rtcc.connect({url: 'http://localhost', port: 9999}, function(err, channel) {
    if (err)
        return console.log('err', err);
    channel.send('hey! how are you?');
    channel.on('data', function(data){
        console.log('received message - ', data);
    });
});

Server

Boot a fresh http server to establish the connection:

var rtcc = require('webrtc-connect');

rtcc.createServer(function(err, channel){
    if (err)
        return console.log('err', err);
    channel.on('data', function(data){
        console.log('received message - ', data);
        channel.send('good and you?');
    });

}).listen('9999');

Attach to an existing http server of your app:

var rtcc = require('webrtc-connect');

rtcc.createServer(function(err, channel){
    if (err)
        return console.log('err', err);
    channel.on('data', function(data){
        console.log('received message - ', data);
        channel.send('good and you?');
    });

}).attach(EXISTING_HTTP_SERVER);