首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebRTC服务器如何反馈SDP和ICE候选人?

WebRTC服务器如何反馈SDP和ICE候选人?
EN

Stack Overflow用户
提问于 2013-12-16 09:10:05
回答 1查看 2.9K关注 0票数 6

为了我,我正在一步一步地测试WebRTC过程。

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

http://webrtcdevelop.appspot.com/

事实上,google使用的是STUN服务器,但没有部署信令服务器。

会话描述协议(SDP)是手动交换的,即浏览器窗口之间的CopyPaste。

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

代码语言:javascript
复制
'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);
};
  • 火狐(26.0):RtpDataChannels onopen事件被成功触发,但send失败。
  • Chrome(31.0):不触发RtpDataChannels onopen事件。

所以我的问题是

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

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

例如,来自STUN服务器的本地描述反馈服务是。如下所示:

代码语言:javascript
复制
{"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信息中包含一些全局地址,因为没有它,我们只能在本地连接。

所以,我想我需要用SDP来标记各种ICE候选人的活动,但我不知道怎么做,我认为这个问题与考试失败有关。

如有任何建议或建议,敬请阅读。

编辑: Ok,可能,这是我现在要关注的同一个主题:

需要发送冰的候选人通过,或他们来包装提供/回答数据?https://groups.google.com/forum/#!topic/discuss-webrtc/UOnopWJ1l44

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-16 23:13:30

需要发送冰的候选人通过,或者他们来打包提供/回答数据?>https://groups.google.com/forum/#!topic/discuss-webrtc/UOnopWJ1l44

Chrome除了最初的SDP包之外,还会独立地发送ICE候选人,当ICE候选人到达时,他们会自动进入/update the LocalDescription。

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

使用上述发现修改代码,现在情况发生了变化:请参阅我的下一个问题以了解细节。(2013/12/17年度尚未解决)

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20607002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档