Find file History
muaz-khan file-hangout, meeting.js, screen-sharing, MultiStreamsMixer, audio-br…

video-broadcast, video-conferencing, chat-hangout, RTCMultiConnection,
text-chat, file-sharing,, websocket and WebRTC-FileSharing
demos are updated.
Latest commit 5e20ee0 Dec 22, 2018

WebRTC Text Chat i.e. Data Sharing / Demo

DataConnection.js library lets you:

  1. Share file of any size
  2. Share text message of any length
  3. Text data regardless of the size and type


First Step: Link the library

<script src=""></script>


Last Step: Start using it!

var connection = new DataConnection( /* 'optional::firebase-channel' */);

// check pre-established connections

document.getElementById('setup-new-connection').onclick = function() {


Text Chat i.e. Text Sharing

connection.send('longest possible text message');

You may want to share direct messages:

connection.channels['user-id'].send('longest possible text message');


Errors Handling

// error to open data connection
connection.onerror = function(event, userid) {}

// data ports suddenly dropped
connection.onclose = function(event, userid) {}


Custom user-ids?

connection.userid = 'username';


Custom signaling channel?

You can use each and every signaling channel:

  1. SIP-over-WebSockets
  2. WebSocket over Node.js/PHP/etc.
  3. over Node.js/etc.
  4. XMPP/etc.
  5. XHR-POST-ing
connection.openSignalingChannel = function(callback) {
    return io.connect().on('message', callback);

If you want to write over node.js; here is the server code:

io.sockets.on('connection', function (socket) {
    socket.on('message', function (data) {
        socket.broadcast.emit('message', data);

That's it! Isn't it easiest method ever!

Want to use Firebase for signaling?

// "chat" is your firebase id
connection.firebase = 'chat';

Want to use XHR, WebSockets, SIP, XMPP, etc. for signaling? Read this post.


Want to manually join rooms?

connection.onconnection = function(room) {
    var button = document.createElement('button');
    button.onclick = function() {

onconnection is called for each new data connection; and join method allows you manually join previously created connections.


If someone leaves...

Participants' presence can be detected using onuserleft:

connection.onuserleft = function(userid) {
    console.debug(userid, 'left');


Browser Support

This DataConnection.js library is compatible to following web-browsers:

Browser Support
Firefox Stable / Aurora / Nightly
Google Chrome Stable / Canary / Beta / Dev
Android Chrome Beta



DataConnection.js is released under MIT licence . Copyright (c) 2013 Muaz Khan.