View on GitHub

Datachannel.io

Realtime application framework for Node.JS, with HTML5 WebRTC and Socket.io

Download this project as a .zip file Download this project as a tar.gz file

Datachannel.io is inspired by the amazing socket.io framework and implements a real-time communication using the WebRTC technology. Peers are directly connected and datas are exchanged between clients without passing throug the server.

Socket.io has two purposes:

Installing

npm install datachannel.io

On the Server

var server = require('http').createServer();
var dc = require('dataChannel.io').listen(server, options);

server.listen(8080);

Redis Store

If you want to implement sessions management or horizontal scaling you need a redis server.

Note: By default, redis-server binds to local only. Edit redis.conf to comment out this option or you will receive an ECONNECTREFUSED error. The line to comment out is: bind 127.0.0.1

var server = require('http').createServer();
var dc = require('dataChannel.io').listen(server, {
    redis: {port: [INTEGER], host: [STRING], options: { pass: [STRING] }},
});

server.listen(8080);

Static File

If you do not want to serve the static client file at /datachannel.io/datachannel.io.js you need to add the parameter static: false.

var server = require('http').createServer();
var dc = require('dataChannel.io').listen(server, {
    static: false
});

server.listen(8080);

Add a Namespace

You need to add at least one namespace:

dc.addNameSpace([STRING], {
    session: {
        cookie: {name: [STRING], secret: [STRING]},
        auth: function(session) {
            return true;
        }
    }
});

Session management is optional, if you want to use it you need a Redis server configured. The session object has this parameters:

On the Client

index.html

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <script src="http://<yourHost>/datachannel.io/datachannel.io.js"></script>
        <script>
            var datachannel = new DataChannel({
                socketServer: 'http://<yourHost>'
            });
        </script>
    </body>
</html>

Initialization

The parameters of the new DataChannel(object) are:

Join a Room

datachannel.join("room");

Leave a Room

datachannel.leave("room");

Send a Message

datachannel.in("room").emit("chat", {text: 'Hi!'});

Get a Message

datachannel.in("room").on("chat", function(data) {
    console.log(data);
});

ToDo

Tested on Chrome v25 and Firefox v20.

Some examples at https://github.com/marcolanaro/DataChannel.IO-Examples.

More information at http://www.datachannel.io.

License

MIT