按照方法here我正在尝试使用iPhone模拟器(使用React Native)回答使用Chrome浏览器发起的音频通话。
事件序列摘要:
null
步骤7,8,9可能会在6之后和19之前的不同地方出现。
我一直坚持这个问题。我现在甚至都不知道要调试什么。关闭连接的可能原因是什么?如果需要,我可以发布更多日志。
一个观察结果是,与RTCEvent
对应的两个iceconnectionstatechange
具有以下属性:
isTrusted:false
目标RTCPeerConnection已
iceConnectionState:"closed"
iceGatheringState:"complete"
以下是处理remoteOffer和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));
}
};
答案 0 :(得分:0)
我发现如果我逐个调用以下两个函数,那么它就可以了。
peerConnection.setRemoteDescription(new RTCSessionDescription(data.description),onSuccess,console.warn);
(...definition of onAnswer ...)
peerConnection.createAnswer(onAnswer, this.onError);
我之前的代码在createAnswer
的{{1}}回调中名为onSuccess
。这确实适用于setRemoteDescription
演示,但不适用于Rocket.Chat。仍然没有完全理解它。但我的项目现在可以继续。