WebSync Signaling Server

Muaz Khan edited this page Sep 11, 2015 · 1 revision

Use WebSync Signaling Server in any RTCMultiConnection demo

This wiki page explains how to use websync as signaling medium within any RTCMultiConnection demo.

You don't need to install WebSync server yourself. You simply need to copy/paste following HTML in your own PHP/ASPX/Python/etc. webpage and it will work!

Remember, it requires RTCMultiConnection v2.2.2 or earlier builds. It doesn't works with most recent version i.e. v3.0

<script src="http://websync.somee.com/fm.js"> </script>
<script src="http://websync.somee.com/fm.websync.js"> </script>
<script src="http://websync.somee.com/fm.websync.subscribers.js"> </script>
<script src="http://websync.somee.com/fm.websync.chat.js"> </script>

<script src="//cdn.webrtc-experiment.com/RTCMultiConnection.js"></script>
<button id="openNewSessionButton">Open New Room</button>
<script>
var connection = new RTCMultiConnection();

// easiest way to customize what you need!
connection.session = {
    audio: true,
    video: true
};

// on getting local or remote media stream
connection.onstream = function(e) {
    document.body.appendChild(e.mediaElement);
};

// open new session
document.querySelector('#openNewSessionButton').onclick = function() {
    connection.open();
};
</script>

<!-- WebSync signaling stuff happens below -->

<script>
var channels = {};
var username = connection.userid;

var domain = 'http://websync.somee.com/';

var client = new fm.websync.client(domain + 'websync.ashx');

client.setAutoDisconnect({
    synchronous: true
});

client.connect({
    onSuccess: function() {
        client.join({
            channel: domain + 'chat',
            userId: username,
            userNickname: username,
            onReceive: function(event) {
                var message = JSON.parse(event.getData().text);
                if (channels[message.channel] && channels[message.channel].onmessage) {
                    channels[message.channel].onmessage(message.message);
                }
            }
        });
    }
});

connection.openSignalingChannel = function(config) {
    var channel = config.channel || this.channel;
    channels[channel] = config;

    if (config.onopen) setTimeout(config.onopen, 1000);
    return {
        send: function(message) {
            client.publish({
                channel: domain + 'chat',
                data: {
                    username: username,
                    text: JSON.stringify({
                        message: message,
                        channel: channel
                    })
                }
            });
        }
    };
};
</script>

<!-- Don't forget calling "connect" or "join" after overriding above "openSignalingChannel" method -->

<script>
// setup signaling channel
connection.connect();
</script>

Private WebSync Server?

If you are still interested to deploy and install your own WebSync server then you can take source code from this github repository:

SSL/HTTPs?

WebSync demo is deployed on somee.com which doesn't supports HTTPs.

You should deploy it on Azure clouds or on any other ASP.NET hosting.