How to get started with Webrtc, I’m lost

Asked

Viewed 1,536 times

5

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

I started researching the subject and I’m completely lost, there is peerjs, exists webrtc, there are thousands of libraries and I don’t know which is the best/safe, I just don’t know where to start.

I’d like to do it with pure code but I don’t know if it’s viable or if it has a way.

  • I know the http://webrtc2sip.org/ I’ve used it to make audio and video conversations between browser/phone and browser/browser using SIP protocol.

1 answer

1

You can even use Webrtc with the "pure" API, I recommend this tutorial in English: http://www.html5rocks.com/en/tutorials/webrtc/basics/

But I found it easier to use the libraries available on https://www.webrtc-experiment.com/

There are several examples, to make video call with sound, share screen, text chat and etc, like this one which is one of the most complete: https://www.webrtc-experiment.com/RTCMultiConnection/MultiRTC/

It is usually quite simple, just include some javascript files, copy some calls and 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 conference, a "signage server" is used, you can read more about it at: https://github.com/muaz-khan/WebRTC-Experiment/blob/master/Signaling.md

Below is an example of code that starts connecting to a signage server using Websockets (but you can use Firebase, or even TUN/STUN or other protocols with little variation, as described in the link above):

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 some other events that you should implement as examples and as you can see in: https://github.com/danielneis/moodle-mod_webrtcexperiments/blob/master/module.js#L11

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

connection.connect();
  • 1

    Hello, Daniel. Welcome to Stack Overflow. The OS has a policy that answers should not be based solely on links. Learn more here: http://meta.pt.stackoverflow.com/questions/42/queremos-respostas-que-contenham-somente-links

  • But Daniel presented example code as well, it wasn’t just based on links.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.