javascript - Firefox 不创建报价 : Cannot create an offer with no local tracks, 没有 offerToReceiveAudio/Video,也没有 DataChannel

标签 javascript firefox webrtc

我在使用 Firefox 时遇到问题。此代码在 Chrome 中完美运行。

function create_offer() {
    pc = new peer_connection({iceServers: [
        {urls: "stun:stun.l.google.com:19302"}
    ]});
    //pc.createDataChannel('channel');

    pc.createOffer(
        create_offer_success,
        create_offer_error,
        setSdpConstraints()
    );

    pc.onaddstream = on_add_stream;
    pc.onicecandidate = on_ice_candidate;
}

function create_offer_success(desc) {
    pc.setLocalDescription(desc);
}

function create_offer_error(error) {
    console.error("create_offer_error() error:", error);
}

function on_ice_candidate(event){
    if (event.candidate) {
        ice.push(event.candidate);
    } else {
        return send('/offer', {
            'id': id,
            'desc': pc.localDescription,
            'ice': ice
        })
        .then(function(data) {
            return pc.setRemoteDescription(new session_description(data.desc), function() {
                for(var i = 0, l = data.ice.length; i < l; i++) {
                    pc.addIceCandidate(new ice_candidate(data.ice[i]));
                }
                return data;
             }, function(err) {
                console.error(err);
            });
        })
        .catch(function(err) {
            console.error('on_ice_candidate() catch: ', err);
        });
    }
}

function on_add_stream(event) {
    console.log(event);
    stream = event.stream;
    var vid = document.getElementById("stream");
    if(isFirefox) {
        vid.mozSrcObject = stream;
    } else {
        vid.src = URL.createObjectURL(stream)
    }
}

function setSdpConstraints() {
    return !!navigator.mozGetUserMedia && firefoxVersion > 34 ?
    {
        OfferToReceiveAudio: true,
        OfferToReceiveVideo: true
    } :
    {
        optional: [],
        mandatory: {
            OfferToReceiveAudio: true,
            OfferToReceiveVideo: true
        }
    };
}

Firefox 显示错误:无法创建没有本地轨道、没有 offerToReceiveAudio/Video 和 DataChannel 的报价。 Firefox 版本为 44。 我做错了什么?

最佳答案

您为 Firefox 设置了错误的约束:

{
    OfferToReceiveAudio: true,
    OfferToReceiveVideo: true
}

您需要设置的内容(自 Chrome 38 起 Chrome 也支持此设置)应该是:

{
    offerToReceiveAudio: 1,
    offerToReceiveVideo: 1
}

注意大小写的区别。

关于javascript - Firefox 不创建报价 : Cannot create an offer with no local tracks, 没有 offerToReceiveAudio/Video,也没有 DataChannel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817908/

相关文章:

javascript - 在 Backbone destroy() 方法中发送额外信息

javascript - 数组中的数组 Angular react 形式

javascript - 将多个值附加到单个 div

javascript - 如何在快速工作区中转换简单的 react 组件

firefox - CSS3 动画只适用于 webkit?

android - 是否可以在显示键盘时处理 Firefox 移动版中的 jQuery 输入事件?

javascript - 在 Firefox 中使用 JavaScript 在 iframe 中打印 PDF

node.js - webrtc onaddstream 未在第一个对等点上调用

android - 几秒钟后 WebRTC 远程视频卡住

javascript - webrtc对等连接: can not create an answer