Getting started with WebRTC, I'm lost

4

I need to develop a simple project: link between points that share video and audio (video calling in the case), simple, only in theory.

I started searching on the subject and am completely lost, there is peerjs , there is webrtc , there are thousands of libraries and I do not know which one is the best / safe, I just do not know where to start. >

I would like to do with pure code but I do not know if it is feasible or if it has like.

    
asked by anonymous 15.07.2015 / 17:02

1 answer

1

You can even use WebRTC with the "pure" API, I recommend this tutorial in English: link

But I found it easier to use the libraries available at link

There are several examples to make video calling with sound, screen sharing, text chat and etc, like the one here that is one of the most complete: link

It's usually pretty simple, just include some javascript files, copy some calls, and it works.

To create a communication channel using the RTCMultiConnection library, you should do something like:

var connection = new RTCMultiConnection();
connection.firebase = false;

connection.session = {
    audio: true,
    video: true
};
var current_user = 'test user';

To create "rooms" for video conferencing, a "signaling server" is used, you can read more about it at: link

Below is an example code that initiates the connection to a signaling server using WebSockets (but you can use FireBase, or even TUN / STUN or other protocols with little variation, as described in the link above) p>

connection.openSignalingChannel = function(config) {

    var channel = location.href.replace(/\/|:|#|%|\.|\[|\]/g, '');
    var websocket = new WebSocket("ws://localhost");
    websocket.channel = channel;

    websocket.onopen = function () {
            websocket.push(JSON.stringify({
                    open: true,
                    channel: channel
            }));
            if (config.callback) {
                config.callback(websocket);
            }

    };
    websocket.onmessage = function(event) {
        config.onmessage(JSON.parse(event.data));
    };
    websocket.push = websocket.send;
    websocket.send = function (data) {
            if (websocket.readyState != 1) {
                    return setTimeout(function() {
                            websocket.send(data);
                    }, 300);
            }

            websocket.push(JSON.stringify({
                    data: data,
                    channel: channel
            }));
    };
    return websocket;
};

There are a few other events that you should implement as per the examples and as you can see at: link

At the end you should remember to make the connection itself, by executing:

connection.connect();
    
24.12.2015 / 03:19