Fix nullability of completion handlers in iOS SDK.

Bug: None
Change-Id: I74d3d976760fd620a8f749a3c187430dbe80ef57
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/210961
Commit-Queue: Yura Yaroshevich <yura.yaroshevich@gmail.com>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33416}
This commit is contained in:
Yura Yaroshevich
2021-03-10 13:07:27 +03:00
committed by Commit Bot
parent 89127190ce
commit 8bfa2756a5
2 changed files with 25 additions and 26 deletions

View File

@ -81,6 +81,12 @@ typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
RTCStatsOutputLevelDebug,
};
typedef void (^RTCCreateSessionDescriptionCompletionHandler)(RTC_OBJC_TYPE(RTCSessionDescription) *
_Nullable sdp,
NSError *_Nullable error);
typedef void (^RTCSetSessionDescriptionCompletionHandler)(NSError *_Nullable error);
@class RTC_OBJC_TYPE(RTCPeerConnection);
RTC_OBJC_EXPORT
@ -293,27 +299,24 @@ RTC_OBJC_EXPORT
/** Generate an SDP offer. */
- (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(nullable void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * _Nullable sdp,
NSError *_Nullable error))completionHandler;
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Generate an SDP answer. */
- (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:
(nullable void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * _Nullable sdp,
NSError *_Nullable error))completionHandler;
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Apply the supplied RTCSessionDescription as the local description. */
- (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(nullable void (^)(NSError *_Nullable error))completionHandler;
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Creates an offer or answer (depending on current signaling state) and sets
* it as the local session description. */
- (void)setLocalDescriptionWithCompletionHandler:
(nullable void (^)(NSError *_Nullable error))completionHandler;
(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Apply the supplied RTCSessionDescription as the remote description. */
- (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(nullable void (^)(NSError *_Nullable error))completionHandler;
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Limits the bandwidth allocated for all RTP streams sent by this
* PeerConnection. Nil parameters will be unchanged. Setting

View File

@ -37,33 +37,26 @@
NSString *const kRTCPeerConnectionErrorDomain = @"org.webrtc.RTC_OBJC_TYPE(RTCPeerConnection)";
int const kRTCPeerConnnectionSessionDescriptionError = -1;
typedef void (^RTCSetSessionDescriptionCompletionHandler)(NSError *_Nullable error);
namespace {
class SetSessionDescriptionObserver : public webrtc::SetLocalDescriptionObserverInterface,
public webrtc::SetRemoteDescriptionObserverInterface {
public:
SetSessionDescriptionObserver(
RTCSetSessionDescriptionCompletionHandler _Nullable completionHandler) {
SetSessionDescriptionObserver(RTCSetSessionDescriptionCompletionHandler completionHandler) {
completion_handler_ = completionHandler;
}
virtual void OnSetLocalDescriptionComplete(webrtc::RTCError error) override {
if (completion_handler_ != nil) {
OnCompelete(error);
}
OnCompelete(error);
}
virtual void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override {
if (completion_handler_ != nil) {
OnCompelete(error);
}
OnCompelete(error);
}
private:
void OnCompelete(webrtc::RTCError error) {
RTC_DCHECK(completion_handler_);
RTC_DCHECK(completion_handler_ != nil);
if (error.ok()) {
completion_handler_(nil);
} else {
@ -542,8 +535,8 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
}
- (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription,
NSError *error))completionHandler {
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter>
observer(new rtc::RefCountedObject
<webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler));
@ -554,8 +547,8 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
}
- (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription,
NSError *error))completionHandler {
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter>
observer(new rtc::RefCountedObject
<webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler));
@ -566,21 +559,24 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
}
- (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(nullable void (^)(NSError *error))completionHandler {
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer(
new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler));
_peerConnection->SetLocalDescription(sdp.nativeDescription->Clone(), observer);
}
- (void)setLocalDescriptionWithCompletionHandler:
(nullable void (^)(NSError *error))completionHandler {
(RTCSetSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer(
new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler));
_peerConnection->SetLocalDescription(observer);
}
- (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(nullable void (^)(NSError *error))completionHandler {
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface> observer(
new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler));
_peerConnection->SetRemoteDescription(sdp.nativeDescription->Clone(), observer);