Establish WebRTC Data Channels between browser-node and node-node with a TCP/HTTP/WebSockets "createServer/attach" like interface
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.
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);
});
});
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);