Skip to content

Commit f5b5085

Browse files
committed
Support trickle ICE in controller
1 parent 14b5003 commit f5b5085

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

examples/camera-controller/webrtc-manager/WebRTCManager.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

examples/camera-controller/webrtc-manager/WebRTCManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class WebRTCManager
9999
// Track the current video stream ID for the session
100100
uint16_t mCurrentVideoStreamId = 0;
101101

102+
// Flag to track if initial ICE candidates batch has been sent
103+
bool mHasSentInitialICECandidates = false;
104+
102105
// UDP socket for RTP forwarding
103106
int mRTPSocket = -1;
104107
int mAudioRTPSocket = -1;

0 commit comments

Comments
 (0)