diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.h b/sdk/objc/api/peerconnection/RTCPeerConnection.h index 77a8dccac1..d0cd99ce74 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnection.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnection.h @@ -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 diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.mm b/sdk/objc/api/peerconnection/RTCPeerConnection.mm index e3ab65ae30..3cc714b238 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnection.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnection.mm @@ -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 observer(new rtc::RefCountedObject (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 observer(new rtc::RefCountedObject (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 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 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 observer( new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler)); _peerConnection->SetRemoteDescription(sdp.nativeDescription->Clone(), observer);