From 2d9f53ca58164734bd36bb81018e00ac5752f2f3 Mon Sep 17 00:00:00 2001 From: Yura Yaroshevich Date: Wed, 10 Mar 2021 13:03:00 +0300 Subject: [PATCH] Expose addIceCandidate with completion handler. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: None Change-Id: I91c15b36e6a63f7a7ee13203de5750d9492c19c6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211001 Reviewed-by: Kári Helgason Commit-Queue: Yura Yaroshevich Cr-Commit-Position: refs/heads/master@{#33440} --- examples/objc/AppRTCMobile/ARDAppClient.m | 9 ++++++++- .../api/peerconnection/RTCPeerConnection.h | 7 ++++++- .../api/peerconnection/RTCPeerConnection.mm | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) 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) {