View on GitHub

RTC.js

A webRTC library that should make an webRTC as easy as jQuery.ajax.

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

API of RTC.js

RTC.Connection

RTC.Connection is a class so that you can establish a connection by calling

var connection = new RTC.Connection({
    'localstream': mycamerastream, //a MediaStream object that you could get from RTC.getUserMedia.
    'video': document.getElementById("#remoteuser_smiling_in_the_cam"),
    'sendOffer': function (offer) {
        //and here we send the offer right to our signaling server
        jQuery.ajax({
            'url': "https://myserver/signaling/start",
            'data': {
                'offer_sdp': offer
            }
        });
    }
});

The following tables describe all options

option expected effect
sendOffer function (sdp) This function is called to start signaling. The first and only parameter is the SDP-string and it is up to YOU to deliver that to the other side of the connection. For each connection you should either define sendOffer or offer.
offer string If you just received an offer, take the SDP-string and build a connection with it to answer it. This parameter ist just the pure SDP string. For each connection you should either define sendOffer or offer. If you defined offer, you should also define the sendAnswer option.
sendAnswer function (sdp) This function is called in the middle of signaling by the side/peer that just received an offer (see offer-option). The first and only parameter is the SDP-string and it is up to YOU to deliver that to the other side of the connection. Once you have done that on the other side you must call insertAnswer on the RTC.Connection object that created the offer in the first place. For each connection you should either define sendOffer or offer.

Methods of RTC.Connection

Once you called new RTC.Connection(...) you get an object back. And this object has some important methods that are used to finish establishing the connection or send data-objects to the other side. So don't throw your object into the garbage collector, you will need it again, once you created it.

method parameter effect
insertAnswer string This is called for RTC.Connection objects that once created an offer. By calling insertAnswer(answer_sdp) you finish establishing the connection. Right after that the established-event is fired and after that you can start to communicate with each other, the video or audio streams should appear, you can send messages with the send method.
send JSON-object, string, integer Once a connection is established you can send any kind of JSON-objects to the other side with this method. On the other side for each object the event received will get fired.