diff --git a/examples/objc/AppRTCMobile/ARDAppClient.m b/examples/objc/AppRTCMobile/ARDAppClient.m index 8d12ff2627..ccd5bb0662 100644 --- a/examples/objc/AppRTCMobile/ARDAppClient.m +++ b/examples/objc/AppRTCMobile/ARDAppClient.m @@ -634,7 +634,14 @@ static int const kKbpsMultiplier = 1000; case kARDSignalingMessageTypeCandidate: { ARDICECandidateMessage *candidateMessage = (ARDICECandidateMessage *)message; - [_peerConnection addIceCandidate:candidateMessage.candidate]; + __weak ARDAppClient *weakSelf = self; + [_peerConnection addIceCandidate:candidateMessage.candidate + completionHandler:^(NSError *error) { + ARDAppClient *strongSelf = weakSelf; + if (error) { + [strongSelf.delegate appClient:strongSelf didError:error]; + } + }]; break; } case kARDSignalingMessageTypeCandidateRemoval: { diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.h b/sdk/objc/api/peerconnection/RTCPeerConnection.h index d0cd99ce74..79e0625b28 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnection.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnection.h @@ -219,7 +219,12 @@ RTC_OBJC_EXPORT - (void)close; /** Provide a remote candidate to the ICE Agent. */ -- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate; +- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate + DEPRECATED_MSG_ATTRIBUTE("Please use addIceCandidate:completionHandler: instead"); + +/** Provide a remote candidate to the ICE Agent. */ +- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate + completionHandler:(void (^)(NSError *_Nullable error))completionHandler; /** Remove a group of remote candidates from the ICE Agent. */ - (void)removeIceCandidates:(NSArray *)candidates; diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.mm b/sdk/objc/api/peerconnection/RTCPeerConnection.mm index 3cc714b238..8a47d22772 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnection.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnection.mm @@ -433,7 +433,24 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack( candidate.nativeCandidate); _peerConnection->AddIceCandidate(iceCandidate.get()); } - +- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate + completionHandler:(void (^)(NSError *_Nullable error))completionHandler { + RTC_DCHECK(completionHandler != nil); + auto iceCandidate = webrtc::CreateIceCandidate(candidate.nativeCandidate->sdp_mid(), + candidate.nativeCandidate->sdp_mline_index(), + candidate.nativeCandidate->candidate()); + _peerConnection->AddIceCandidate(std::move(iceCandidate), [completionHandler](const auto &error) { + if (error.ok()) { + completionHandler(nil); + } else { + NSString *str = [NSString stringForStdString:error.message()]; + NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain + code:static_cast(error.type()) + userInfo:@{NSLocalizedDescriptionKey : str}]; + completionHandler(err); + } + }); +} - (void)removeIceCandidates:(NSArray *)iceCandidates { std::vector candidates; for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) {