RTCPeerConnection.iceConnectionState 从检查变为关闭 [英] RTCPeerConnection.iceConnectionState changed from checking to closed
问题描述
按照此处的方法,我正在尝试从 iPhone 模拟器接听 Chrome 浏览器发起的音频呼叫(使用 React Native).
Following the method here I'm trying to answer an audio call initiated with a Chrome browser from an iPhone simulator(with React Native).
事件序列总结:
- 收到呼叫信号
- 获得本地流
- 发送加入通话信号
- 收到远程描述(offer),
- 已创建 PeerConnection
- 添加本地流
- 收到候选人
- 已添加候选人
- 7 和 8 重复 15 次(总共 16 次)
- 需要触发协商
- signalingState 更改为 have-remote-offer
- onaddstream 触发
- setRemoteDescription 的回调函数被触发,创建了答案.
- signalingState 变为稳定
- iceconnectionstate 变成了 checking
- 首次触发了烟酸.
- 发出来自 15 的候选人
- 第二次触发了烟酸.候选人是
null
- iceconnectionstate 更改为 closed
步骤 7、8、9 可能出现在 6 之后和 19 之前的不同位置.
Step 7,8,9 may appear at different places after 6 and before 19.
我已经被这个问题困住了很长一段时间.我什至不知道此时要调试什么.连接关闭的可能原因是什么?如果需要,我可以发布更多日志.
I have been stuck on this problem for quite a while. I don't even know what to debug at this time. What are the possible causes of the closing of connection? I can post more logs if needed.
一个观察是,对应于iceconnectionstatechange
的两个RTCEvent
具有以下属性:
One observation is that the two RTCEvent
corresponding to iceconnectionstatechange
has the following properties:
isTrusted:false
目标 RTCPeerConnection 有
The target RTCPeerConnection has
iceConnectionState:"closed"
iceGatheringState:"complete"
这是我处理 remoteOffer 和 remoteCandidates 的函数:
Here are my functions to handle remoteOffer and remoteCandidates:
WebRTCClass.prototype.onRemoteOffer = function(data) {
var ref;
if (this.active !== true) {
return;
}
var peerConnection = this.getPeerConnection(data.from);
console.log('onRemoteOffer', data,peerConnection.signalingState);
if (peerConnection.iceConnectionState !== 'new') {
return;
}
var onSuccess = (function(_this){
return function(){
console.log("setRemoteDescription onSuccess function");
_this.getLocalUserMedia((function(_this) {
return function(onSuccess,stream) {
peerConnection.addStream(_this.localStream);
var onAnswer = (function(_this) {
return function(answer) {
var onLocalDescription = function() {
return _this.transport.sendDescription({
to: data.from,
type: 'answer',
ts: peerConnection.createdAt,
description: {
sdp: answer.sdp,
type: answer.type
}
});
};
return peerConnection.setLocalDescription(new RTCSessionDescription(answer), onLocalDescription, _this.onError);
};
})(_this);
return peerConnection.createAnswer(onAnswer, _this.onError);
}
})(_this)
);
}
})(this);
return peerConnection.setRemoteDescription(new RTCSessionDescription(data.description),onSuccess,console.warn);
};
<小时>
WebRTCClass.prototype.onRemoteCandidate = function(data) {
var peerConnection, ref;
if (this.active !== true) {
return;
}
if (data.to !== this.selfId) {
return;
}
console.log('onRemoteCandidate', data);
peerConnection = this.getPeerConnection(data.from);
if ((ref = peerConnection.iceConnectionState) !== "closed" && ref !== "failed" && ref !== "disconnected" && ref !== "completed") {
peerConnection.addIceCandidate(new RTCIceCandidate(data.candidate));
}
};
推荐答案
我发现如果我把下面两个函数一一调用,就可以了.
I found that if I call the following two functions one by one, then it will work.
peerConnection.setRemoteDescription(new RTCSessionDescription(data.description),onSuccess,console.warn);
(...definition of onAnswer ...)
peerConnection.createAnswer(onAnswer, this.onError);
我之前的代码在 setRemoteDescription
的 onSuccess
回调中调用了 createAnswer
.这确实适用于 react-native-webrtc
演示,但不适用于 Rocket.Chat.还是没有完全理解.但我的项目现在可以继续了.
My previous codes called createAnswer
within the onSuccess
callback of setRemoteDescription
. That did work for the react-native-webrtc
demo, but not with Rocket.Chat. Still don't fully understand it. But my project can move on now.
这篇关于RTCPeerConnection.iceConnectionState 从检查变为关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!