首页 > 技术文章 > 解决 flutter webrtc 有时候无法进行视频通话,但有时候又好使(前提:turn 和stun 已准备好)

zhangyy3 2021-04-27 18:10 原文

现像:

   a和b通话的时候,有时候能通话,有时候不能通话,表现现象为 onIceConnectionState 的结果是failed 或者根本不调用onIceConnectionState 这个方法

   看日志,addIceCandidate ,和onIceCandidate 都是ok的,都有 typ relay类似的candidate

原因:

   暂时得出的结论是,不是任何时候调用peerConnection.addIceCandidate都有效,

   应该只有在IceGathering 开始后再调用addIceCandidate才可以。

解决方法:

监听onIceGatheringState,当值为RTCIceGatheringStateGathering的时候,把remote传过来的iceCandidate加到本地。即调用peerConnection.addCondidate
目前观测的是这样的结果,有可能不对,谨慎参考

推荐阅读