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

 兰陵殇lu_734_168 发布于 2023-02-10 06:19

为了我的缘故,我正在逐步测试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 + '
'); }

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
            });

捆绑得当.

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

我错过了什么?

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

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

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有