部分代码如下所示:
if (message.type === 'offer') {
console.log("got offer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message));
console.log(pc);
createAnswer();
}
else if (message.type === 'answer') {
console.log("got answer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message));
console.log(pc);
}
Calee成功设置了远程描述,
pc.remoteDescription
已填写。但是,呼叫者...收到与被呼叫者相同的消息,但在pc.setRemoteDescription(new SessionDescription(message));
变为pc.remoteDescription
为空并且注意到发生之后。被叫方准备接收流,但被叫方卡住。 最佳答案
我认为问题是因为setRemoteDescription
失败,或者在与createAnswer
之间存在竞争条件,因此请将其添加到成功回调中,并且为了清楚起见,也添加错误回调...
就像是:
if (message.type === 'offer') {
console.log("got offer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message), function(){
console.log(pc);
createAnswer();
}, console.error.bind(console));
}
else if (message.type === 'answer') {
console.log("got answer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message), console.log.bind(console, 'success'), console.error.bind(console));
}
如果支持Promise和ES6:
if (message.type === 'offer') {
console.log("got offer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message))
.then(() =>{
console.log('success...', pc);
createAnswer();
}).catch(e => console.error(e));
}
else if (message.type === 'answer') {
console.log("got answer");
console.log(message);
pc.setRemoteDescription(new SessionDescription(message))
.then(() => console.log('success...', pc))
.catch(e => console.error(e));
}
关于javascript - Webrtc setRemoteDescription对调用者无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33681797/