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}
This commit is contained in:
@ -16,13 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@interface RTCConfiguration ()
|
@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)
|
+ (webrtc::PeerConnectionInterface::IceTransportsType)
|
||||||
nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy;
|
nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy;
|
||||||
|
|
||||||
@ -55,6 +48,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy;
|
+ (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
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@ -75,7 +75,8 @@
|
|||||||
|
|
||||||
#pragma mark - Private
|
#pragma mark - Private
|
||||||
|
|
||||||
- (webrtc::PeerConnectionInterface::RTCConfiguration*)nativeConfiguration {
|
- (webrtc::PeerConnectionInterface::RTCConfiguration *)
|
||||||
|
createNativeConfiguration {
|
||||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
|
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
|
||||||
nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration());
|
nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration());
|
||||||
|
|
||||||
@ -105,7 +106,7 @@
|
|||||||
rtc::RTCCertificateGenerator::GenerateCertificate(
|
rtc::RTCCertificateGenerator::GenerateCertificate(
|
||||||
rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
|
rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
|
||||||
if (!certificate) {
|
if (!certificate) {
|
||||||
RTCLogWarning(@"Failed to generate certificate.");
|
RTCLogError(@"Failed to generate certificate.");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
nativeConfig->certificates.push_back(certificate);
|
nativeConfig->certificates.push_back(certificate);
|
||||||
|
|||||||
@ -199,9 +199,10 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
|
|||||||
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
||||||
NSParameterAssert(factory);
|
NSParameterAssert(factory);
|
||||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
||||||
configuration.nativeConfiguration);
|
[configuration createNativeConfiguration]);
|
||||||
if (!config)
|
if (!config) {
|
||||||
return nullptr;
|
return nil;
|
||||||
|
}
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
|
_observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
|
||||||
std::unique_ptr<webrtc::MediaConstraints> nativeConstraints =
|
std::unique_ptr<webrtc::MediaConstraints> nativeConstraints =
|
||||||
@ -255,9 +256,10 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
|
|||||||
|
|
||||||
- (BOOL)setConfiguration:(RTCConfiguration *)configuration {
|
- (BOOL)setConfiguration:(RTCConfiguration *)configuration {
|
||||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
||||||
configuration.nativeConfiguration);
|
[configuration createNativeConfiguration]);
|
||||||
if (!config)
|
if (!config) {
|
||||||
return false;
|
return NO;
|
||||||
|
}
|
||||||
return _peerConnection->SetConfiguration(*config);
|
return _peerConnection->SetConfiguration(*config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,8 @@
|
|||||||
RTCContinualGatheringPolicyGatherContinually;
|
RTCContinualGatheringPolicyGatherContinually;
|
||||||
|
|
||||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
|
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
|
||||||
nativeConfig(config.nativeConfiguration);
|
nativeConfig([config createNativeConfiguration]);
|
||||||
|
EXPECT_TRUE(nativeConfig.get());
|
||||||
EXPECT_EQ(1u, nativeConfig->servers.size());
|
EXPECT_EQ(1u, nativeConfig->servers.size());
|
||||||
webrtc::PeerConnectionInterface::IceServer nativeServer =
|
webrtc::PeerConnectionInterface::IceServer nativeServer =
|
||||||
nativeConfig->servers.front();
|
nativeConfig->servers.front();
|
||||||
|
|||||||
Reference in New Issue
Block a user