You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ConnectyCube视频通话切换网络后会话中断的重连方案咨询

Fixing ConnectyCube Video Call Reconnection on Network Switch

When switching between Wi-Fi and mobile data, ConnectyCube's built-in reconnection often fails—here's a manual approach to get it working:

1. Detect Network Changes First

You can't rely on ConnectyCube to catch every network transition, so implement platform-level listeners to trigger your reconnection logic:

Android

Use ConnectivityManager to watch for network availability:

val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() {
    override fun onAvailable(network: Network) {
        // Run reconnection on main thread
        Handler(Looper.getMainLooper()).post { reconnectVideoCall() }
    }
})

iOS

Use NWPathMonitor to track network status:

let pathMonitor = NWPathMonitor()
pathMonitor.pathUpdateHandler = { path in
    guard path.status == .satisfied else { return }
    DispatchQueue.main.async { self.reconnectVideoCall() }
}
pathMonitor.start(queue: DispatchQueue.global(qos: .utility))

2. Manual Reconnection Flow

Skip the built-in functions and roll your own sequence:

  • Pause media first
    Don't destroy the session immediately—pause streams to avoid state corruption:

    // Android example
    ConnectyCube.video.pauseCall(session)
    
  • Refresh session token
    Fetch a new session token to ensure validity with the new network:

    ConnectyCube.createSession { newSession, error ->
        if (error == null) {
            // Proceed with reconnection
        }
    }
    
  • Reinitialize peer connection with fresh ICE servers
    Outdated ICE servers are a common culprit. Fetch new ones and rebuild the peer connection:

    // iOS example
    ConnectyCube.video.getICEServers { iceServers, error in
        guard let servers = iceServers else { return }
        let config = RTCConfiguration()
        config.iceServers = servers
        // Create new RTC peer connection with this config
        let peerConnection = ConnectyCube.video.createPeerConnection(config)
        // Reattach local media streams to this new peer connection
    }
    
  • Reattach media streams
    Recreate your local camera/audio streams and attach them to the new peer connection. Then trigger a renegotiation to sync with the remote user.

  • Signal the remote peer
    Use ConnectyCube's chat API to send a custom message (like "RECONNECT_REQUEST") to the other participant, so they can also reinitialize their end of the connection.

3. Critical Tips

  • Avoid calling destroyCall right away—keeping the session context cuts down on reconnection time.
  • Add a cooldown period between reconnection attempts to prevent loops if the network is unstable.
  • Double-check permissions (camera, mic) after reinitializing streams—some platforms reset permissions on network changes.

内容的提问来源于stack exchange,提问作者Manish Nithin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 11:53:27