1
繼方法here我試圖回答從iPhone模擬器(使用React Native)的Chrome瀏覽器啓動的音頻呼叫。RTCPeerConnection.iceConnectionState從檢查更改爲關閉
事件序列的總結:
- 接收到的呼叫信號
- 得到本地流
- 發送加入
- 接收到的遠程描述(報價)呼叫信號,
- 創建PeerConnection等
- 新增本地流
- 收到候選人
- 加入候選
- 7和8重複15次(即總共16次)
- onnegotiationneeded觸發
- signalingState改變爲具有遠程要約
- onaddstream觸發
- 的回調函數setRemoteDescription被觸發,創建答案。
- signalingState變成變成穩定
- iceconnectionstate檢查
- onicecandidate引發的第一次。
- 來自15名候選人
- onicecandidate第二次觸發。該名候選人是
null
- iceconnectionstate變成關閉
步驟7,8,9 5月6日之後的不同地方和19
之前,我一直停留在這個問題上相當而。我甚至不知道現在要調試什麼。關閉連接的可能原因是什麼?如果需要,我可以發佈更多日誌。
一個觀察是,對應於iceconnectionstatechange
兩個RTCEvent
具有以下屬性:
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));
}
};
我懷疑[react-native-webrtc](https://github.com/oney/react-native-webrtc)與原始webrtc軟件包略有不同。但我對此很陌生,所以我也可能不遵循webrtc協議的正確軌道 –
模擬器和瀏覽器是否位於同一網絡中?您是否在createpeerconnection中使用任何STUN或TURN服務器?你有ios或chrome libjingle日誌嗎? – manishg
模擬器和瀏覽器位於同一網絡(127.0.0.1)。對等連接是通過將STUN服務器設置爲'stun:stun.l.google.com:19302'創建的。我不確定什麼是libjingle日誌或如何打開它。你能否指點我一個參考?我用代碼生成了一些更詳細的日誌。 –