6

为了我的缘故,我正在逐步测试 WebRTC 程序。

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

http://webrtcdevelop.appspot.com/

其实用的是google的STUN server,但没有部署信令服务器。

会话描述协议 (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): RtpDataChannels onopen事件成功触发,但send失败。

  • Chrome(31.0): RtpDataChannels onopen未触发事件。

所以,我的问题是,

我想知道为什么 Chrome 在RtpDataChannels onopen事件中失败,以及如何修复。

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

例如,从 STUN 服务器反馈的 Offer Local Description。如下:

{"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"}

我能看到的唯一 IP127.0.0.1localhost,但我想一些全局地址应该包含在 SDP 信息中,因为没有它,我们只能在本地连接。

所以,我想我需要将各种 ICE 候选人 onicecaditate event 与 SDP 进行匹配,但我不确定如何,我认为这个问题与测试失败有关。

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

编辑: 好的,可能这与我现在关注的主题相同:

有必要发送ICE候选人,或者他们是否包含在报价/答案数据中? https://groups.google.com/forum/#!topic/discuss-webrtc/UOnopWJ1l44

4

1 回答 1

3

有必要发送ICE候选人,或者他们是否包含在报价/答案数据中?> https://groups.google.com/forum/#!topic/discuss-webrtc/UOnopWJ1l44

除了初始 SDP 包之外,Chrome 发送 ICE 候选者独立到达,当 ICE 候选者到达时,它们会自动进入 /update LocalDescription。

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

有了上面的发现修改了代码,现在情况发生了变化:详情请看我的下一个问题。(到目前为止尚未解决 2013/12/17)

Firefox 的 WebRTC SDP 对象(本地描述)不包含与 Chrome 不同的 DataChannel 信息?

于 2013-12-16T23:13:30.980 回答