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

5 html5 webrtc

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

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

http://webrtcdevelop.appspot.com/

事实上,谷歌的STUN服务器被使用,但没有部署信令服务器.

会话描述协议(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", "");
            });
        $('#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>');
}
Run Code Online (Sandbox Code Playgroud)
  • Firefox(26.0): RtpDataChannels onopen事件成功触发,但send失败.

  • Chrome(31.0): RtpDataChannels onopen事件成功触发,send也成功了.

Chrome的SDP对象如下:

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

其中ch1信息在代码中定义;

 ch = peerCon.createDataChannel(
            'ch1',
            {
                reliable: false
            });
Run Code Online (Sandbox Code Playgroud)

捆绑得当.

但是,Firefox的SDP对象(本地描述)根本不包含DataChannel,而且,SDP比Chrome短得多,捆绑的信息也少.

我错过了什么?

可能,我猜sendDataChannel失败的原因是由于firefox在SDP对象中缺少信息.

我怎么能解决这个问题?我调查了各种工作库的来源,比如peerJS,easyRTC,simpleWebRTC,但无法弄清楚原因.

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

Mil*_*ern 1

[还没有答案]

\n

我把这个留在这里只是想帮助你。我并不是一名 WebRTC 开发人员。但是,我很好奇,这对我来说非常新鲜且非常有趣。

\n

你见过这个吗 ?

\n
\n

数据通道

\n

Firefox 现已支持,您可以使用 DataChannel 在音频/视频通话期间\n发送点对点信息。目前存在一个错误,要求开发人员设置某种\n音频/视频流(甚至是 \xe2\x80\x9cfake\xe2\x80\x9d 一个)才能启动\nDataChannel,但我们很快就会解决这个问题。

\n
\n

另外,我发现了这个 bug hook,女巫似乎与之相关。

\n

最后一点,您的adapter.js 版本与code.google 上提供的版本不同。还有..很多。你的 webrtcDetectedVersion 部分丢失了。

\n

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

\n

尝试一下,带着好消息回来找我。?

\n
\n

上次更新后,单击“获取答案”后,我在控制台中看到了这一行

\n
\n

Object { name="INVALID_STATE", message="无法在\n状态 HAVE_LOCAL_OFFER 中设置远程优惠", displayedProps ={...}, more...}

\n
\n

但这可能是无用的信息,因为我复制粘贴了相同的浏览器来回答。

\n

..女巫让我注意到你正在使用 jQuery v1.7.1 jquery.com。

\n

尝试更新 jQuery(在我杀死一只小猫之前),同时尝试确保使用所有更新版本的脚本。

\n
\n

Woups,快速阅读完此内容后:https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC/WebRTC_basics然后比较你的 JavaScript,我没有看到 SHIM。

\n
\n

垫片

\n

正如您可以想象的那样,对于这样一个早期的 API,您必须使用浏览器前缀并将其填充到一个公共变量。

\n
\n
> var PeerConnection = window.mozRTCPeerConnection ||\n> window.webkitRTCPeerConnection; var IceCandidate =\n> window.mozRTCIceCandidate || window.RTCIceCandidate; var\n> SessionDescription = window.mozRTCSessionDescription ||\n> window.RTCSessionDescription; navigator.getUserMedia =\n> navigator.getUserMedia || navigator.mozGetUserMedia ||\n> navigator.webkitGetUserMedia;\n
Run Code Online (Sandbox Code Playgroud)\n