zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Webrtc Native C++如何自定义断网重联

C++ 如何 自定义 native Webrtc 断网
2023-09-14 09:12:42 时间

在 m76 版本的 WebRTC 中,可以使用 PeerConnection 的 OnIceConnectionChange 方法来监听 ICE 连接状态的变化。当 ICE 连接状态变为 kIceConnectionDisconnected 时,可以在一定时间后进行重连。可以通过设置一个计时器,在一定时间后尝试重新连接。

具体实现方式如下:

首先,在 PeerConnection 对象的创建和配置过程中,需要设置一个 rtc::scoped_refptr 对象,用于监听 ICE 连接状态变化。例如:

auto connection = peerConnectionFactory->CreatePeerConnection(rtcConfiguration, nullptr, nullptr, nullptr, &connectionObserver