@@ -369,6 +369,10 @@ CHIP_ERROR WebRTCProviderManager::HandleProvideAnswer(uint16_t sessionId, const
369369 transport->MoveToState (WebrtcTransport::State::SendingICECandidates);
370370 ScheduleICECandidatesSend (sessionId);
371371
372+ // Set the flag after successfully handling the answer and scheduling ICE candidates
373+ transport->SetHasSentInitialICECandidates (true );
374+ ChipLogProgress (Camera, " Initial ICE candidates batch will be sent for sessionID: %u, trickle ICE enabled" , sessionId);
375+
372376 return CHIP_NO_ERROR;
373377}
374378
@@ -409,6 +413,13 @@ CHIP_ERROR WebRTCProviderManager::HandleProvideICECandidates(uint16_t sessionId,
409413 transport->MoveToState (WebrtcTransport::State::SendingICECandidates);
410414 ScheduleICECandidatesSend (sessionId);
411415
416+ if (!transport->GetHasSentInitialICECandidates ())
417+ {
418+ // Set the flag after successfully handling ICE candidates
419+ transport->SetHasSentInitialICECandidates (true );
420+ ChipLogProgress (Camera, " Initial ICE candidates batch will be sent for sessionID: %u, trickle ICE enabled" , sessionId);
421+ }
422+
412423 return CHIP_NO_ERROR;
413424}
414425
@@ -712,6 +723,10 @@ void WebRTCProviderManager::OnDeviceConnected(void * context, Messaging::Exchang
712723 }
713724
714725 err = self->SendEndCommand (exchangeMgr, sessionHandle, sessionId, endReason);
726+
727+ // Unset the flag when session closes
728+ transport->SetHasSentInitialICECandidates (false );
729+
715730 // Release the Video and Audio Streams from the CameraAVStreamManagement
716731 // cluster and update the reference counts.
717732 self->ReleaseAudioVideoStreams (sessionId);
0 commit comments