5

I'm testing WebRTC procedure step by step for my sake.

I wrote some testing site for server-less WebRTC.

http://webrtcdevelop.appspot.com/

In fact, STUN server by google is used, but no signalling server deployed.

Session Description Protocol (SDP) is exchanged manually by hand that is CopyPaste between browser windows.

enter image description here

enter image description here

enter image description here enter image description here

So far, here is the result I've got with the code:

'use strict';

var peerCon;
var ch;

$(document)
    .ready(function()
    {
        init();

        $('#remotebtn2')
            .attr("disabled", "");

        $('#localbtn')
            .click(function()
            {
                offerCreate();

                $('#localbtn')
                    .attr("disabled", "");
                $('#remotebtn')
                    .attr("disabled", "");

                $('#remotebtn2')
                    .removeAttr("disabled");
            });

        $('#remotebtn')
            .click(function()
            {
                answerCreate(
                    new RTCSessionDescription(JSON.parse($('#remote')
                        .val())));

                $('#localbtn')
                    .attr("disabled", "");
                $('#remotebtn')
                    .attr("disabled", "");

                $('#remotebtn')
                    .attr("disabled", "");
            });

        $('#remotebtn2')
            .click(function()
            {
                answerGet(
                    new RTCSessionDescription(JSON.parse($('#remote')
                        .val())));

                $('#remotebtn2')
                    .attr("disabled", "");
            });
        $('#msgbtn')
            .click(function()
            {
                msgSend($('#msg')
                    .val());

            });
    });

var init = function()
{
    //offer------
    peerCon =
        new RTCPeerConnection(
        {
            "iceServers": [
            {
                "url": "stun:stun.l.google.com:19302"
            }]
        },
        {
            "optional": []
        });

    var localDescriptionOut = function()
    {
        console.log(JSON.stringify(peerCon.localDescription));
        $('#local')
            .text(JSON.stringify(peerCon.localDescription));


    };

    peerCon.onicecandidate = function(e)
    {
        console.log(e);

        if (e.candidate === null)
        {
            console.log('candidate empty!');
            localDescriptionOut();
        }
    };

    ch = peerCon.createDataChannel(
        'ch1',
        {
            reliable: true
        });
    ch.onopen = function()
    {
        dlog('ch.onopen');
    };
    ch.onmessage = function(e)
    {
        dlog(e.data);
    };
    ch.onclose = function(e)
    {
        dlog('closed');
    };
    ch.onerror = function(e)
    {
        dlog('error');
    };
};

var msgSend = function(msg)
{
    ch.send(msg);
}



var offerCreate = function()
{
    peerCon
        .createOffer(function(description)
        {
            peerCon
                .setLocalDescription(description, function()
                {
                    //wait for complete of peerCon.onicecandidate
                }, error);
        }, error);
};

var answerCreate = function(descreption)
{
    peerCon
        .setRemoteDescription(descreption, function()
        {
            peerCon
                .createAnswer(
                    function(description)
                    {
                        peerCon
                            .setLocalDescription(description, function()
                            {
                                //wait for complete of peerCon.onicecandidate
                            }, error);
                    }, error);
        }, error);
};
var answerGet = function(description)
{
    peerCon.setRemoteDescription(description, function()
    { //
        console.log(JSON.stringify(description));
        dlog('local-remote-setDescriptions complete!');
    }, error);
};

var error = function(e)
{
    console.log(e);
};

var dlog = function(msg)
{
    var content = $('#onmsg')
        .html();
    $('#onmsg')
        .html(content + msg + '<br>');
}
  • Firefox(26.0): RtpDataChannels onopen event is fired successfully, but send fails.

  • Chrome(31.0): RtpDataChannels onopen event is fired successfully, and send also succeeded.

A SDP object by Chrome is as follows:

{"sdp":".................. cname:L5dftYw3P3clhLve \r\ na=ssrc:2410443476 msid:ch1 ch1 \r\ na=ssrc:2410443476 mslabel:ch1 \r\ na=ssrc:2410443476 label:ch1 \r\n","type":"offer"}

where the ch1 information defined in the code;

 ch = peerCon.createDataChannel(
            'ch1',
            {
                reliable: false
            });

is bundled properly.

However, a SDP object (local description) by Firefox does not contain DataChannel at all, and moreover, the SDP is much shorter than Chrome, and less information bundled.

What do I miss?

Probably, I guess the reason that send fails on DataChannel is due to this lack of information in the SDP object by firefox.

How could I fix this? I investigated sources of various working libraries, such as peerJS, easyRTC, simpleWebRTC, but cannot figure out the reason.

Any suggestion and recommendation to read is appreciated.

  • Any progress after our chatty conversation ? I gotta go for a few days. I come back with you after xMass. Greetings to you. – Milche Patern Dec 25 '13 at 01:50
  • Thanks Millche, Greetings to you, too. Actually, this study is for P2P voIP for mobile. FF incompatibility does not matter very much, in fact, but I wanted to be share what's going one. Having said that, I shall leave this for a while and switch to study SIP instead of webRTC. –  Dec 25 '13 at 01:53
  • Well, if you're the first to publish a 'ready to use cross-everything' plugin, i want to know. – Milche Patern Dec 25 '13 at 02:07
  • I started working on this too. I am curious if you have any results! –  Dec 31 '13 at 14:00

1 Answers1

1

[not an answer, yet]

I leave this here just trying to help you. I am not much of a WebRTC developer. But, curious i am, this quite new and verry interresting for me.

Have you seen this ?

DataChannels

Supported in Firefox today, you can use DataChannels to send peer-to-peer information during an audio/video call. There is currently a bug that requires developers to set up some sort of audio/video stream (even a “fake” one) in order to initiate a DataChannel, but we will soon be fixing that.

Also, i found this bug hook, witch seems to be related.

One last point, your version of adapter.js is different from the one served on code.google. And .. alot. the webrtcDetectedVersion part is missing in yours.

https://code.google.com/p/webrtc/source/browse/stable/samples/js/base/adapter.js

Try that, come back to me with good newz. ?


After last updating, i have this line in console after clicking 'get answer'

Object { name="INVALID_STATE", message="Cannot set remote offer in state HAVE_LOCAL_OFFER", exposedProps={...}, more...}

but this might be useless info ence i copy pasted the same browser offre to answer.

.. witch made me notice you are using jQuery v1.7.1 jquery.com.

Try updating jQuery (before i kill a kitten), and in the meantime, try make sure you use all updated versions of scripts.


Woups, after fast reading this : https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC/WebRTC_basics then comparing your javascripts, i see no SHIM.

Shims

As you can imagine, with such an early API, you must use the browser prefixes and shim it to a common variable.

> var PeerConnection = window.mozRTCPeerConnection ||
> window.webkitRTCPeerConnection; var IceCandidate =
> window.mozRTCIceCandidate || window.RTCIceCandidate; var
> SessionDescription = window.mozRTCSessionDescription ||
> window.RTCSessionDescription; navigator.getUserMedia =
> navigator.getUserMedia || navigator.mozGetUserMedia ||
> navigator.webkitGetUserMedia;
Community
  • 1
  • 1
Milche Patern
  • 19,632
  • 6
  • 35
  • 52
  • Thanks, Milche. I have noticed this bug. In fact, I've heard this bug is fixed in FF-NigtlyBuild, so I tried my test-page http://webrtcdevelop.appspot.com/ , and the result is the same. So I must conclude this bug is nothing to do with the reason my test-code does not work so far. –  Dec 23 '13 at 04:10
  • i just did the same, with same results. – Milche Patern Dec 23 '13 at 04:12
  • Great to hear you confirm the same result. Confirmation is always good :), anyway, the reason is somewhere else. –  Dec 23 '13 at 04:13
  • @KenOKABE Try updating adapter.js, it's different from https://code.google.com/p/webrtc/source/browse/stable/samples/js/base/adapter.js – Milche Patern Dec 23 '13 at 04:24
  • @ Milche Patern Thanks for letting me notice that. However, the result is the same as before. Not working with FF nightly with the latest adapter.js. I updated my test site, and please confirm that. –  Dec 23 '13 at 04:56
  • @KenOKABE From Firefox : local-remote-setDescriptions complete! bot no mention about the ch.open. – Milche Patern Dec 23 '13 at 05:18
  • ch.open event is fired in both Chrome and FF(even non-nightly) at the point of this Question posted. –  Dec 23 '13 at 05:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43721/discussion-between-milche-patern-and-ken-okabe) – Milche Patern Dec 23 '13 at 05:37