部分代码如下所示:
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
之后空白并且注意到了。 Callee准备接收流,但是来电者被卡住了。
答案 0 :(得分:3)
我认为问题是因为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));
}