blob: 31805f192302594e62325e480c3975feea90301b [file] [log] [blame]
hjon6d49a8e2016-01-26 13:06:42 -08001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCConfiguration+Private.h"
hjon6d49a8e2016-01-26 13:06:42 -080012
jbauch555604a2016-04-26 03:13:22 -070013#include <memory>
14
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#import "RTCCertificate.h"
Zeke Chinef1140e2017-10-27 15:42:08 -070016#import "RTCConfiguration+Native.h"
tkchin9eeb6242016-04-27 01:54:20 -070017#import "RTCIceServer+Private.h"
Steve Antond295e402017-07-14 16:06:41 -070018#import "RTCIntervalRange+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020019#import "base/RTCLogging.h"
tkchinab8f82f2016-01-27 17:50:11 -080020
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/rtccertificategenerator.h"
22#include "rtc_base/sslidentity.h"
hjon6d49a8e2016-01-26 13:06:42 -080023
24@implementation RTCConfiguration
25
26@synthesize iceServers = _iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020027@synthesize certificate = _certificate;
hjon6d49a8e2016-01-26 13:06:42 -080028@synthesize iceTransportPolicy = _iceTransportPolicy;
29@synthesize bundlePolicy = _bundlePolicy;
30@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
31@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
Honghai Zhang46007ae2016-06-03 16:31:32 -070032@synthesize candidateNetworkPolicy = _candidateNetworkPolicy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070033@synthesize continualGatheringPolicy = _continualGatheringPolicy;
deadbeef2059bb32017-07-26 18:25:43 -070034@synthesize maxIPv6Networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010035@synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks;
hjon6d49a8e2016-01-26 13:06:42 -080036@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -080037@synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
hjon6d49a8e2016-01-26 13:06:42 -080038@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
39@synthesize iceBackupCandidatePairPingInterval =
40 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080041@synthesize keyType = _keyType;
deadbeefbe0c96f2016-05-18 16:20:14 -070042@synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -070043@synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
44@synthesize shouldPresumeWritableWhenFullyRelayed =
45 _shouldPresumeWritableWhenFullyRelayed;
skvlada5d94ff2017-02-02 13:02:30 -080046@synthesize iceCheckMinInterval = _iceCheckMinInterval;
Steve Antond295e402017-07-14 16:06:41 -070047@synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange;
Steve Anton8cb344a2018-02-27 15:34:53 -080048@synthesize sdpSemantics = _sdpSemantics;
Zeke Chinef1140e2017-10-27 15:42:08 -070049@synthesize turnCustomizer = _turnCustomizer;
Zhi Huangb57e1692018-06-12 11:41:11 -070050@synthesize activeResetSrtpParams = _activeResetSrtpParams;
hjon6d49a8e2016-01-26 13:06:42 -080051
52- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070053 // Copy defaults.
54 webrtc::PeerConnectionInterface::RTCConfiguration config(
55 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive);
jtteh465faf02017-04-04 14:00:16 -070056 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070057}
58
59- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070060 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080061 if (self = [super init]) {
jtteh4eeb5372017-04-03 15:06:37 -070062 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070063 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
jtteh4eeb5372017-04-03 15:06:37 -070064 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
65 [iceServers addObject:iceServer];
66 }
67 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020068 if (!config.certificates.empty()) {
69 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
70 native_cert = config.certificates[0];
71 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
72 _certificate =
73 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
74 certificate:@(native_pem.certificate().c_str())];
75 }
hjon6d49a8e2016-01-26 13:06:42 -080076 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070077 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080078 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070079 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080080 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070081 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080082 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070083 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070084 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070085 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070086 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070087 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070088 _continualGatheringPolicy =
89 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
deadbeef2059bb32017-07-26 18:25:43 -070090 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010091 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -070092 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
93 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
94 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -080095 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -070096 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -080097 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -070098 _iceCandidatePoolSize = config.ice_candidate_pool_size;
99 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700100 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700101 config.presume_writable_when_fully_relayed;
102 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800103 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700104 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800105 }
Steve Antond295e402017-07-14 16:06:41 -0700106 if (config.ice_regather_interval_range) {
107 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
108 _iceRegatherIntervalRange =
109 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
110 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800111 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700112 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700113 _activeResetSrtpParams = config.active_reset_srtp_params;
hjon6d49a8e2016-01-26 13:06:42 -0800114 }
115 return self;
116}
117
118- (NSString *)description {
Steve Anton8cb344a2018-02-27 15:34:53 -0800119 static NSString *formatString =
120 @"RTCConfiguration: "
Zhi Huangb57e1692018-06-12 11:41:11 -0700121 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%@\n%@\n%d\n%d\n%d\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100122
Steve Anton8cb344a2018-02-27 15:34:53 -0800123 return [NSString
124 stringWithFormat:formatString,
125 _iceServers,
126 [[self class] stringForTransportPolicy:_iceTransportPolicy],
127 [[self class] stringForBundlePolicy:_bundlePolicy],
128 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
129 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
130 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
131 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
132 [[self class] stringForSdpSemantics:_sdpSemantics],
133 _audioJitterBufferMaxPackets,
134 _audioJitterBufferFastAccelerate,
135 _iceConnectionReceivingTimeout,
136 _iceBackupCandidatePairPingInterval,
137 _iceCandidatePoolSize,
138 _shouldPruneTurnPorts,
139 _shouldPresumeWritableWhenFullyRelayed,
140 _iceCheckMinInterval,
141 _iceRegatherIntervalRange,
142 _disableLinkLocalNetworks,
Zhi Huangb57e1692018-06-12 11:41:11 -0700143 _maxIPv6Networks,
144 _activeResetSrtpParams];
hjon6d49a8e2016-01-26 13:06:42 -0800145}
146
147#pragma mark - Private
148
hbosa73ca562016-05-17 03:28:58 -0700149- (webrtc::PeerConnectionInterface::RTCConfiguration *)
150 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200151 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700152 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
153 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800154
155 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200156 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800157 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200158 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800159 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200160 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800161 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200162 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800163 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200164 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800165 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700166 nativeConfig->candidate_network_policy = [[self class]
167 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200168 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700169 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
deadbeef2059bb32017-07-26 18:25:43 -0700170 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100171 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200172 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800173 nativeConfig->audio_jitter_buffer_fast_accelerate =
174 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200175 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800176 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200177 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800178 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200179 rtc::KeyType keyType =
180 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200181 if (_certificate != nullptr) {
182 // if offered a pemcert use it...
183 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
184 std::string pem_private_key = [[_certificate private_key] UTF8String];
185 std::string pem_certificate = [[_certificate certificate] UTF8String];
186 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
187 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
188 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200190 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800192 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200194 } else {
195 RTC_LOG(LS_INFO) << "Don't have configured cert.";
196 // Generate non-default certificate.
197 if (keyType != rtc::KT_DEFAULT) {
198 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
199 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
200 absl::optional<uint64_t>());
201 if (!certificate) {
202 RTCLogError(@"Failed to generate certificate.");
203 return nullptr;
204 }
205 nativeConfig->certificates.push_back(certificate);
206 }
tkchinab8f82f2016-01-27 17:50:11 -0800207 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700208 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700209 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700210 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700211 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800212 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200213 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800214 }
Steve Antond295e402017-07-14 16:06:41 -0700215 if (_iceRegatherIntervalRange != nil) {
216 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
217 _iceRegatherIntervalRange.nativeIntervalRange);
218 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200219 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700220 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800221 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700222 if (_turnCustomizer) {
223 nativeConfig->turn_customizer = _turnCustomizer;
224 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700225 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200226 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800227}
228
hjon6d49a8e2016-01-26 13:06:42 -0800229+ (webrtc::PeerConnectionInterface::IceTransportsType)
230 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
231 switch (policy) {
232 case RTCIceTransportPolicyNone:
233 return webrtc::PeerConnectionInterface::kNone;
234 case RTCIceTransportPolicyRelay:
235 return webrtc::PeerConnectionInterface::kRelay;
236 case RTCIceTransportPolicyNoHost:
237 return webrtc::PeerConnectionInterface::kNoHost;
238 case RTCIceTransportPolicyAll:
239 return webrtc::PeerConnectionInterface::kAll;
240 }
241}
242
243+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
244 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
245 switch (nativeType) {
246 case webrtc::PeerConnectionInterface::kNone:
247 return RTCIceTransportPolicyNone;
248 case webrtc::PeerConnectionInterface::kRelay:
249 return RTCIceTransportPolicyRelay;
250 case webrtc::PeerConnectionInterface::kNoHost:
251 return RTCIceTransportPolicyNoHost;
252 case webrtc::PeerConnectionInterface::kAll:
253 return RTCIceTransportPolicyAll;
254 }
255}
256
257+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
258 switch (policy) {
259 case RTCIceTransportPolicyNone:
260 return @"NONE";
261 case RTCIceTransportPolicyRelay:
262 return @"RELAY";
263 case RTCIceTransportPolicyNoHost:
264 return @"NO_HOST";
265 case RTCIceTransportPolicyAll:
266 return @"ALL";
267 }
268}
269
270+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
271 (RTCBundlePolicy)policy {
272 switch (policy) {
273 case RTCBundlePolicyBalanced:
274 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
275 case RTCBundlePolicyMaxCompat:
276 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
277 case RTCBundlePolicyMaxBundle:
278 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
279 }
280}
281
282+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
283 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
284 switch (nativePolicy) {
285 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
286 return RTCBundlePolicyBalanced;
287 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
288 return RTCBundlePolicyMaxCompat;
289 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
290 return RTCBundlePolicyMaxBundle;
291 }
292}
293
294+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
295 switch (policy) {
296 case RTCBundlePolicyBalanced:
297 return @"BALANCED";
298 case RTCBundlePolicyMaxCompat:
299 return @"MAX_COMPAT";
300 case RTCBundlePolicyMaxBundle:
301 return @"MAX_BUNDLE";
302 }
303}
304
305+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
306 (RTCRtcpMuxPolicy)policy {
307 switch (policy) {
308 case RTCRtcpMuxPolicyNegotiate:
309 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
310 case RTCRtcpMuxPolicyRequire:
311 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
312 }
313}
314
315+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
316 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
317 switch (nativePolicy) {
318 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
319 return RTCRtcpMuxPolicyNegotiate;
320 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
321 return RTCRtcpMuxPolicyRequire;
322 }
323}
324
325+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
326 switch (policy) {
327 case RTCRtcpMuxPolicyNegotiate:
328 return @"NEGOTIATE";
329 case RTCRtcpMuxPolicyRequire:
330 return @"REQUIRE";
331 }
332}
333
334+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
335 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
336 switch (policy) {
337 case RTCTcpCandidatePolicyEnabled:
338 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
339 case RTCTcpCandidatePolicyDisabled:
340 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
341 }
342}
343
Honghai Zhang46007ae2016-06-03 16:31:32 -0700344+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
345 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
346 switch (policy) {
347 case RTCCandidateNetworkPolicyAll:
348 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
349 case RTCCandidateNetworkPolicyLowCost:
350 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
351 }
352}
353
hjon6d49a8e2016-01-26 13:06:42 -0800354+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
355 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
356 switch (nativePolicy) {
357 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
358 return RTCTcpCandidatePolicyEnabled;
359 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
360 return RTCTcpCandidatePolicyDisabled;
361 }
362}
363
364+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
365 switch (policy) {
366 case RTCTcpCandidatePolicyEnabled:
367 return @"TCP_ENABLED";
368 case RTCTcpCandidatePolicyDisabled:
369 return @"TCP_DISABLED";
370 }
371}
372
Honghai Zhang46007ae2016-06-03 16:31:32 -0700373+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
374 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
375 switch (nativePolicy) {
376 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
377 return RTCCandidateNetworkPolicyAll;
378 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
379 return RTCCandidateNetworkPolicyLowCost;
380 }
381}
382
383+ (NSString *)stringForCandidateNetworkPolicy:
384 (RTCCandidateNetworkPolicy)policy {
385 switch (policy) {
386 case RTCCandidateNetworkPolicyAll:
387 return @"CANDIDATE_ALL_NETWORKS";
388 case RTCCandidateNetworkPolicyLowCost:
389 return @"CANDIDATE_LOW_COST_NETWORKS";
390 }
391}
392
Honghai Zhang3108fc92016-05-11 10:10:39 -0700393+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
394 nativeContinualGatheringPolicyForPolicy:
395 (RTCContinualGatheringPolicy)policy {
396 switch (policy) {
397 case RTCContinualGatheringPolicyGatherOnce:
398 return webrtc::PeerConnectionInterface::GATHER_ONCE;
399 case RTCContinualGatheringPolicyGatherContinually:
400 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
401 }
402}
403
404+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
405 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
406 switch (nativePolicy) {
407 case webrtc::PeerConnectionInterface::GATHER_ONCE:
408 return RTCContinualGatheringPolicyGatherOnce;
409 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
410 return RTCContinualGatheringPolicyGatherContinually;
411 }
412}
413
414+ (NSString *)stringForContinualGatheringPolicy:
415 (RTCContinualGatheringPolicy)policy {
416 switch (policy) {
417 case RTCContinualGatheringPolicyGatherOnce:
418 return @"GATHER_ONCE";
419 case RTCContinualGatheringPolicyGatherContinually:
420 return @"GATHER_CONTINUALLY";
421 }
422}
423
hbosf9da44d2016-06-09 03:18:28 -0700424+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
425 (RTCEncryptionKeyType)keyType {
426 switch (keyType) {
427 case RTCEncryptionKeyTypeRSA:
428 return rtc::KT_RSA;
429 case RTCEncryptionKeyTypeECDSA:
430 return rtc::KT_ECDSA;
431 }
432}
433
Steve Anton8cb344a2018-02-27 15:34:53 -0800434+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
435 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800436 case RTCSdpSemanticsPlanB:
437 return webrtc::SdpSemantics::kPlanB;
438 case RTCSdpSemanticsUnifiedPlan:
439 return webrtc::SdpSemantics::kUnifiedPlan;
440 }
441}
442
443+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
444 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800445 case webrtc::SdpSemantics::kPlanB:
446 return RTCSdpSemanticsPlanB;
447 case webrtc::SdpSemantics::kUnifiedPlan:
448 return RTCSdpSemanticsUnifiedPlan;
449 }
450}
451
452+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
453 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800454 case RTCSdpSemanticsPlanB:
455 return @"PLAN_B";
456 case RTCSdpSemanticsUnifiedPlan:
457 return @"UNIFIED_PLAN";
458 }
459}
460
hjon6d49a8e2016-01-26 13:06:42 -0800461@end