gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:43:09 27 4
gpt4 key购买 nike

我在使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com