Polishing code to handle certificate generation failure in .mm files.
This is a follow-up to https://codereview.webrtc.org/1965313002/ which
was TBR-landed.
Minor code clean-up/corrections:
Property nativeConfiguration -> - method createNativeConfiguration.
RTCLogWarning -> RTCLogError.
setConfiguration returning NO instead of false.
initWithFactory returning nil instead of nullptr.
Braces around ifs.
Review-Url: https://codereview.webrtc.org/1978233002
Cr-Commit-Position: refs/heads/master@{#12770}
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h
index 4c020f9..7f90b35 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h
+++ b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h
@@ -16,13 +16,6 @@
@interface RTCConfiguration ()
-/**
- * RTCConfiguration struct representation of this RTCConfiguration. This is
- * needed to pass to the underlying C++ APIs.
- */
-@property(nonatomic, readonly)
- webrtc::PeerConnectionInterface::RTCConfiguration* nativeConfiguration;
-
+ (webrtc::PeerConnectionInterface::IceTransportsType)
nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy;
@@ -55,6 +48,13 @@
+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy;
+/**
+ * RTCConfiguration struct representation of this RTCConfiguration. This is
+ * needed to pass to the underlying C++ APIs.
+ */
+- (webrtc::PeerConnectionInterface::RTCConfiguration *)
+ createNativeConfiguration;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm
index 5beae99..0a63f69 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm
@@ -75,7 +75,8 @@
#pragma mark - Private
-- (webrtc::PeerConnectionInterface::RTCConfiguration*)nativeConfiguration {
+- (webrtc::PeerConnectionInterface::RTCConfiguration *)
+ createNativeConfiguration {
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration());
@@ -105,7 +106,7 @@
rtc::RTCCertificateGenerator::GenerateCertificate(
rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
if (!certificate) {
- RTCLogWarning(@"Failed to generate certificate.");
+ RTCLogError(@"Failed to generate certificate.");
return nullptr;
}
nativeConfig->certificates.push_back(certificate);
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm
index b91a200..9a488fd 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm
@@ -199,9 +199,10 @@
delegate:(id<RTCPeerConnectionDelegate>)delegate {
NSParameterAssert(factory);
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
- configuration.nativeConfiguration);
- if (!config)
- return nullptr;
+ [configuration createNativeConfiguration]);
+ if (!config) {
+ return nil;
+ }
if (self = [super init]) {
_observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
std::unique_ptr<webrtc::MediaConstraints> nativeConstraints =
@@ -255,9 +256,10 @@
- (BOOL)setConfiguration:(RTCConfiguration *)configuration {
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
- configuration.nativeConfiguration);
- if (!config)
- return false;
+ [configuration createNativeConfiguration]);
+ if (!config) {
+ return NO;
+ }
return _peerConnection->SetConfiguration(*config);
}