我正在逐步测试WebRTC过程。

我为无服务器的WebRTC编写了一些测试站点。

http://webrtcdevelop.appspot.com/

实际上,使用了Google的STUN服务器,但未部署任何信令服务器。

session 描述协议(protocol)(SDP)可以通过浏览器窗口之间的CopyPaste手动进行手动交换。




到目前为止,这是我在代码中得到的结果:

'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", "");
            });
    });


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

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

    ch = peerCon.createDataChannel(
        'ch1',
        {
            reliable: false
        });
    ch.onopen = function()
    {
        alert('ch.onopen');
        ch.send("hello chat!");
    };
    ch.onmessage = function(e)
    {
        alert(e.data);
    };


};

var offerCreate = function()
{
    peerCon
        .createOffer(function(description)
        {
            peerCon
                .setLocalDescription(description, function()
                {
                    console.log(JSON.stringify(description));
                    $('#local')
                        .text(JSON.stringify(description));
                }, error);
        }, error);

};

var answerCreate = function(descreption)
{
    peerCon
        .setRemoteDescription(descreption, function()
        {
            peerCon
                .createAnswer(
                    function(description)
                    {
                        peerCon
                            .setLocalDescription(description, function()
                            {
                                console.log(JSON.stringify(description));
                                $('#local')
                                    .text(JSON.stringify(description));

                            }, error);
                    }, error);
        }, error);

};
var answerGet = function(description)
{
    peerCon.setRemoteDescription(description, function()
    { //
        console.log(JSON.stringify(description));
        alert('local-remote-setDescriptions complete!');
    }, error);
};

var error = function(e)
{
    console.log(e);
};
  • Firefox(26.0):RtpDataChannelsonopen事件已成功触发,但send失败。
  • Chrome(31.0):RtpDataChannels 不会触发onopen事件。

  • 所以,我的问题是

    我想知道为什么Chrome无法在RtpDataChannels上失败onopen事件,以及如何解决。

    可能更重要的是,我想了解如何管理ICE .onicecandidate事件。

    例如,从STUN服务器反馈的商品本地描述。如下:
    {"sdp":"v=0\r\no=- 7430372191078664219 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio data\r\na=msid-semantic: WMS\r\nm=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=ice-ufrag:Gj7WBxZNS7HswoxM\r\na=ice-pwd:FsXen3Tz2sXdXV31splr7WKg\r\na=ice-options:google-ice\r\na=fingerprint:sha-256 EF:67:28:00:41:B6:08:A3:C5:27:BF:38:84:83:CF:8D:DC:CC:95:A9:6C:DB:77:44:DA:B2:D1:05:39:73:99:D1\r\na=setup:actpass\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=recvonly\r\na=rtcp-mux\r\na=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:ZTGRIJAdH3o1Y1T/6gF3YUtCF5CTdsaEkjWCtWJ+\r\na=rtpmap:111 opus/48000/2\r\na=fmtp:111 minptime=10\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:126 telephone-event/8000\r\na=maxptime:60\r\nm=application 1 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\na=rtcp:1 IN IP4 0.0.0.0\r\na=ice-ufrag:Gj7WBxZNS7HswoxM\r\na=ice-pwd:FsXen3Tz2sXdXV31splr7WKg\r\na=ice-options:google-ice\r\na=fingerprint:sha-256 EF:67:28:00:41:B6:08:A3:C5:27:BF:38:84:83:CF:8D:DC:CC:95:A9:6C:DB:77:44:DA:B2:D1:05:39:73:99:D1\r\na=setup:actpass\r\na=mid:data\r\na=sendrecv\r\nb=AS:30\r\na=rtcp-mux\r\na=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:ZTGRIJAdH3o1Y1T/6gF3YUtCF5CTdsaEkjWCtWJ+\r\na=rtpmap:101 google-data/90000\r\na=ssrc:3757983348 cname:ojw6/osqSDh7tsMo\r\na=ssrc:3757983348 msid:ch1 ch1\r\na=ssrc:3757983348 mslabel:ch1\r\na=ssrc:3757983348 label:ch1\r\n","type":"offer"}
    

    我可以看到的唯一IP是127.0.0.1,即localhost,但是我想应该在SDP信息中包含一些全局地址,因为如果没有它,我们只能在本地连接。

    因此,我想我需要将各种ICE候选者与SDP一起纳入onicecaditate事件,但我不确定如何进行,并且我认为此问题与测试失败有关。

    任何建议和阅读建议表示赞赏。

    编辑:
    好的,大概是我现在正在关注的同一主题:

    最佳答案



    Chrome发送ICE候选人独立于初始SDP程序包而到达,而ICE候选人到达时,他们自动进入/更新LocalDescription。

    因此,需要等待系列ICE候选对象的完成(以空ICE候选对象标记),然后输出/发送至信令服务器。

    通过上面的发现修改了代码,现在情况发生了变化:
    请参阅我的下一个问题以获取详细信息。 (至今未解决2013/12/17)

    WebRTC SDP object (local description) by Firefox does not contain DataChannel info unlike Chrome?

    关于javascript - WebRTC STUN服务器如何反馈SDP和ICE候选人?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20607002/

    10-12 05:59