@@ -170,6 +170,13 @@ CHIP_ERROR WebRTCManager::HandleAnswer(uint16_t sessionId, const std::string & s
170170 [](chip::System::Layer * systemLayer, void * appState) {
171171 auto * self = static_cast <WebRTCManager *>(appState);
172172 self->ProvideICECandidates (self->mPendingSessionId );
173+ // Mark that we've sent the initial batch, enabling trickle ICE
174+ if (!self->mHasSentInitialICECandidates )
175+ {
176+ self->mHasSentInitialICECandidates = true ;
177+ ChipLogProgress (Camera, " Initial ICE candidates batch sent for session %u, trickle ICE enabled" ,
178+ self->mPendingSessionId );
179+ }
173180 },
174181 this );
175182
@@ -241,8 +248,9 @@ void WebRTCManager::Disconnect()
241248 audioTrack.reset ();
242249
243250 // Clear state
244- mCurrentVideoStreamId = 0 ;
245- mPendingSessionId = 0 ;
251+ mCurrentVideoStreamId = 0 ;
252+ mPendingSessionId = 0 ;
253+ mHasSentInitialICECandidates = false ;
246254 mLocalDescription .clear ();
247255 mLocalCandidates .clear ();
248256}
@@ -284,6 +292,14 @@ CHIP_ERROR WebRTCManager::Connnect(Controller::DeviceCommissioner & commissioner
284292 mLocalCandidates .push_back (candidateStr);
285293 ChipLogProgress (Camera, " Local Candidate:" );
286294 ChipLogProgress (Camera, " %s" , candidateStr.c_str ());
295+
296+ // If we've already sent the initial batch, send this candidate immediately (trickle ICE)
297+ if (mHasSentInitialICECandidates )
298+ {
299+ ChipLogProgress (Camera, " Sending trickle ICE candidate immediately for session %u" , mPendingSessionId );
300+ // Send only the new candidate(s) that were just added
301+ ProvideICECandidates (mPendingSessionId );
302+ }
287303 });
288304
289305 mPeerConnection ->onStateChange ([this ](rtc::PeerConnection::State state) {
0 commit comments