Fix P2P text chat timeout on WebRTC regions and delay voice renegotiation on disconnect (#5706)

* Fix P2P text chat timeout on WebRTC regions and delay voice renegotiation on disconnect

Text chat: On WebRTC regions, getOutgoingCallInterface() returns nullptr,
causing mP2PAsAdhocCall to be true for all P2P sessions including text-only
IMs. This routed text chat through startP2PVoiceCoro which sent a "start p2p
voice" request and waited for a server reply that never came, resulting in a
30-second session initialization timeout. Fix by gating the p2p-as-adhoc
server init on mStartedAsIMCall so text-only sessions initialize immediately.

WebRTC: Split kFailed and kDisconnected handling in OnConnectionChange.
kFailed still renegotiates immediately. kDisconnected now waits 10 seconds
before renegotiating, giving the connection time to recover on its own. Uses
a sequence counter to ensure only the most recent disconnect transition can
trigger renegotiation, preventing stale delayed tasks from firing early
after disconnect/reconnect cycles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Revert im-change for not using the voice subsystem when doing a text-only IM

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roxanne Skelly
2026-05-06 03:21:05 +10:00
committed by Hecklezz
co-authored by Claude Opus 4.6
parent 13862c0723
commit 4b7565370b
2 changed files with 38 additions and 2 deletions
+27 -2
View File
@@ -1039,6 +1039,8 @@ LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() :
mPeerConnection(nullptr),
mMute(MUTE_INITIAL),
mAnswerReceived(false),
mPeerConnectionState(webrtc::PeerConnectionInterface::PeerConnectionState::kNew),
mDisconnectCount(0),
mPendingJobs(0)
{
}
@@ -1465,11 +1467,15 @@ void LLWebRTCPeerConnectionImpl::OnIceGatheringChange(webrtc::PeerConnectionInte
}
}
static const webrtc::TimeDelta DISCONNECT_RENEGOTIATE_DELAY = webrtc::TimeDelta::Millis(10000);
// Called any time the PeerConnectionState changes.
void LLWebRTCPeerConnectionImpl::OnConnectionChange(webrtc::PeerConnectionInterface::PeerConnectionState new_state)
{
RTC_LOG(LS_ERROR) << __FUNCTION__ << " Peer Connection State Change " << new_state;
mPeerConnectionState = new_state;
switch (new_state)
{
case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected:
@@ -1485,13 +1491,32 @@ void LLWebRTCPeerConnectionImpl::OnConnectionChange(webrtc::PeerConnectionInterf
break;
}
case webrtc::PeerConnectionInterface::PeerConnectionState::kFailed:
case webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected:
{
for (auto &observer : mSignalingObserverList)
{
observer->OnRenegotiationNeeded();
}
break;
}
case webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected:
{
// Wait 10 seconds before renegotiating in case the connection recovers on its own.
// Use a sequence count so that only the most recent disconnect transition can trigger
// a renegotiation, avoiding stale delayed tasks from earlier disconnect/reconnect cycles.
uint32_t disconnect_count = ++mDisconnectCount;
mWebRTCImpl->PostDelayedSignalingTask(
[this, disconnect_count]()
{
if (disconnect_count == mDisconnectCount
&& mPeerConnectionState == webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected)
{
for (auto &observer : mSignalingObserverList)
{
observer->OnRenegotiationNeeded();
}
}
},
DISCONNECT_RENEGOTIATE_DELAY);
break;
}
default:
+11
View File
@@ -480,6 +480,13 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceO
mSignalingThread->PostTask(std::move(task), location);
}
void PostDelayedSignalingTask(absl::AnyInvocable<void() &&> task,
webrtc::TimeDelta delay,
const webrtc::Location& location = webrtc::Location::Current())
{
mSignalingThread->PostDelayedTask(std::move(task), delay, location);
}
void PostNetworkTask(absl::AnyInvocable<void() &&> task,
const webrtc::Location& location = webrtc::Location::Current())
{
@@ -674,6 +681,10 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnectionInterface,
std::vector<LLWebRTCDataObserver *> mDataObserverList;
webrtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel;
// connection state tracking for delayed renegotiation on disconnect
webrtc::PeerConnectionInterface::PeerConnectionState mPeerConnectionState;
uint32_t mDisconnectCount;
std::atomic<int> mPendingJobs;
};