blob: 35cdc466e919f4b7316ec600020c6c80baf00b81 [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;
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070051@synthesize useMediaTransport = _useMediaTransport;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070052@synthesize cryptoOptions = _cryptoOptions;
hjon6d49a8e2016-01-26 13:06:42 -080053
54- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070055 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020056 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070057 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070058}
59
60- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070061 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080062 if (self = [super init]) {
jtteh4eeb5372017-04-03 15:06:37 -070063 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070064 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
jtteh4eeb5372017-04-03 15:06:37 -070065 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
66 [iceServers addObject:iceServer];
67 }
68 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020069 if (!config.certificates.empty()) {
70 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
71 native_cert = config.certificates[0];
72 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
73 _certificate =
74 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
75 certificate:@(native_pem.certificate().c_str())];
76 }
hjon6d49a8e2016-01-26 13:06:42 -080077 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070078 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080079 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070080 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080081 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070082 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080083 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070084 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070085 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070086 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070087 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070088 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070089 _continualGatheringPolicy =
90 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
deadbeef2059bb32017-07-26 18:25:43 -070091 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010092 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -070093 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
94 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
95 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -080096 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -070097 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -080098 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -070099 _iceCandidatePoolSize = config.ice_candidate_pool_size;
100 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700101 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700102 config.presume_writable_when_fully_relayed;
103 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800104 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700105 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800106 }
Steve Antond295e402017-07-14 16:06:41 -0700107 if (config.ice_regather_interval_range) {
108 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
109 _iceRegatherIntervalRange =
110 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
111 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800112 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700113 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700114 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700115 if (config.crypto_options) {
116 _cryptoOptions = [[RTCCryptoOptions alloc]
117 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
118 .enable_gcm_crypto_suites
119 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
120 .enable_aes128_sha1_32_crypto_cipher
121 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
122 .enable_encrypted_rtp_header_extensions
123 sframeRequireFrameEncryption:config.crypto_options->sframe
124 .require_frame_encryption];
125 }
hjon6d49a8e2016-01-26 13:06:42 -0800126 }
127 return self;
128}
129
130- (NSString *)description {
Steve Anton8cb344a2018-02-27 15:34:53 -0800131 static NSString *formatString =
132 @"RTCConfiguration: "
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700133 @"{\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}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100134
Steve Anton8cb344a2018-02-27 15:34:53 -0800135 return [NSString
136 stringWithFormat:formatString,
137 _iceServers,
138 [[self class] stringForTransportPolicy:_iceTransportPolicy],
139 [[self class] stringForBundlePolicy:_bundlePolicy],
140 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
141 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
142 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
143 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
144 [[self class] stringForSdpSemantics:_sdpSemantics],
145 _audioJitterBufferMaxPackets,
146 _audioJitterBufferFastAccelerate,
147 _iceConnectionReceivingTimeout,
148 _iceBackupCandidatePairPingInterval,
149 _iceCandidatePoolSize,
150 _shouldPruneTurnPorts,
151 _shouldPresumeWritableWhenFullyRelayed,
152 _iceCheckMinInterval,
153 _iceRegatherIntervalRange,
154 _disableLinkLocalNetworks,
Zhi Huangb57e1692018-06-12 11:41:11 -0700155 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700156 _activeResetSrtpParams,
157 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800158}
159
160#pragma mark - Private
161
hbosa73ca562016-05-17 03:28:58 -0700162- (webrtc::PeerConnectionInterface::RTCConfiguration *)
163 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200164 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700165 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
166 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800167
168 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200169 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800170 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200171 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800172 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200173 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800174 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200175 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800176 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200177 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800178 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700179 nativeConfig->candidate_network_policy = [[self class]
180 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200181 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700182 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
deadbeef2059bb32017-07-26 18:25:43 -0700183 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100184 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200185 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800186 nativeConfig->audio_jitter_buffer_fast_accelerate =
187 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200188 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800189 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200190 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800191 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200192 rtc::KeyType keyType =
193 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200194 if (_certificate != nullptr) {
195 // if offered a pemcert use it...
196 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
197 std::string pem_private_key = [[_certificate private_key] UTF8String];
198 std::string pem_certificate = [[_certificate certificate] UTF8String];
199 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
200 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
201 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200202 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200203 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200204 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800205 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200207 } else {
208 RTC_LOG(LS_INFO) << "Don't have configured cert.";
209 // Generate non-default certificate.
210 if (keyType != rtc::KT_DEFAULT) {
211 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
212 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
213 absl::optional<uint64_t>());
214 if (!certificate) {
215 RTCLogError(@"Failed to generate certificate.");
216 return nullptr;
217 }
218 nativeConfig->certificates.push_back(certificate);
219 }
tkchinab8f82f2016-01-27 17:50:11 -0800220 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700221 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700222 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700223 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700224 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800225 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200226 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800227 }
Steve Antond295e402017-07-14 16:06:41 -0700228 if (_iceRegatherIntervalRange != nil) {
229 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
230 _iceRegatherIntervalRange.nativeIntervalRange);
231 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200232 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700233 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800234 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700235 if (_turnCustomizer) {
236 nativeConfig->turn_customizer = _turnCustomizer;
237 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700238 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700239 if (_cryptoOptions) {
240 webrtc::CryptoOptions nativeCryptoOptions;
241 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
242 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
243 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
244 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
245 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
246 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
247 nativeCryptoOptions.sframe.require_frame_encryption =
248 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
249 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
250 }
251
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200252 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800253}
254
hjon6d49a8e2016-01-26 13:06:42 -0800255+ (webrtc::PeerConnectionInterface::IceTransportsType)
256 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
257 switch (policy) {
258 case RTCIceTransportPolicyNone:
259 return webrtc::PeerConnectionInterface::kNone;
260 case RTCIceTransportPolicyRelay:
261 return webrtc::PeerConnectionInterface::kRelay;
262 case RTCIceTransportPolicyNoHost:
263 return webrtc::PeerConnectionInterface::kNoHost;
264 case RTCIceTransportPolicyAll:
265 return webrtc::PeerConnectionInterface::kAll;
266 }
267}
268
269+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
270 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
271 switch (nativeType) {
272 case webrtc::PeerConnectionInterface::kNone:
273 return RTCIceTransportPolicyNone;
274 case webrtc::PeerConnectionInterface::kRelay:
275 return RTCIceTransportPolicyRelay;
276 case webrtc::PeerConnectionInterface::kNoHost:
277 return RTCIceTransportPolicyNoHost;
278 case webrtc::PeerConnectionInterface::kAll:
279 return RTCIceTransportPolicyAll;
280 }
281}
282
283+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
284 switch (policy) {
285 case RTCIceTransportPolicyNone:
286 return @"NONE";
287 case RTCIceTransportPolicyRelay:
288 return @"RELAY";
289 case RTCIceTransportPolicyNoHost:
290 return @"NO_HOST";
291 case RTCIceTransportPolicyAll:
292 return @"ALL";
293 }
294}
295
296+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
297 (RTCBundlePolicy)policy {
298 switch (policy) {
299 case RTCBundlePolicyBalanced:
300 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
301 case RTCBundlePolicyMaxCompat:
302 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
303 case RTCBundlePolicyMaxBundle:
304 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
305 }
306}
307
308+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
309 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
310 switch (nativePolicy) {
311 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
312 return RTCBundlePolicyBalanced;
313 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
314 return RTCBundlePolicyMaxCompat;
315 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
316 return RTCBundlePolicyMaxBundle;
317 }
318}
319
320+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
321 switch (policy) {
322 case RTCBundlePolicyBalanced:
323 return @"BALANCED";
324 case RTCBundlePolicyMaxCompat:
325 return @"MAX_COMPAT";
326 case RTCBundlePolicyMaxBundle:
327 return @"MAX_BUNDLE";
328 }
329}
330
331+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
332 (RTCRtcpMuxPolicy)policy {
333 switch (policy) {
334 case RTCRtcpMuxPolicyNegotiate:
335 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
336 case RTCRtcpMuxPolicyRequire:
337 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
338 }
339}
340
341+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
342 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
343 switch (nativePolicy) {
344 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
345 return RTCRtcpMuxPolicyNegotiate;
346 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
347 return RTCRtcpMuxPolicyRequire;
348 }
349}
350
351+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
352 switch (policy) {
353 case RTCRtcpMuxPolicyNegotiate:
354 return @"NEGOTIATE";
355 case RTCRtcpMuxPolicyRequire:
356 return @"REQUIRE";
357 }
358}
359
360+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
361 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
362 switch (policy) {
363 case RTCTcpCandidatePolicyEnabled:
364 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
365 case RTCTcpCandidatePolicyDisabled:
366 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
367 }
368}
369
Honghai Zhang46007ae2016-06-03 16:31:32 -0700370+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
371 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
372 switch (policy) {
373 case RTCCandidateNetworkPolicyAll:
374 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
375 case RTCCandidateNetworkPolicyLowCost:
376 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
377 }
378}
379
hjon6d49a8e2016-01-26 13:06:42 -0800380+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
381 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
382 switch (nativePolicy) {
383 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
384 return RTCTcpCandidatePolicyEnabled;
385 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
386 return RTCTcpCandidatePolicyDisabled;
387 }
388}
389
390+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
391 switch (policy) {
392 case RTCTcpCandidatePolicyEnabled:
393 return @"TCP_ENABLED";
394 case RTCTcpCandidatePolicyDisabled:
395 return @"TCP_DISABLED";
396 }
397}
398
Honghai Zhang46007ae2016-06-03 16:31:32 -0700399+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
400 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
401 switch (nativePolicy) {
402 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
403 return RTCCandidateNetworkPolicyAll;
404 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
405 return RTCCandidateNetworkPolicyLowCost;
406 }
407}
408
409+ (NSString *)stringForCandidateNetworkPolicy:
410 (RTCCandidateNetworkPolicy)policy {
411 switch (policy) {
412 case RTCCandidateNetworkPolicyAll:
413 return @"CANDIDATE_ALL_NETWORKS";
414 case RTCCandidateNetworkPolicyLowCost:
415 return @"CANDIDATE_LOW_COST_NETWORKS";
416 }
417}
418
Honghai Zhang3108fc92016-05-11 10:10:39 -0700419+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
420 nativeContinualGatheringPolicyForPolicy:
421 (RTCContinualGatheringPolicy)policy {
422 switch (policy) {
423 case RTCContinualGatheringPolicyGatherOnce:
424 return webrtc::PeerConnectionInterface::GATHER_ONCE;
425 case RTCContinualGatheringPolicyGatherContinually:
426 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
427 }
428}
429
430+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
431 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
432 switch (nativePolicy) {
433 case webrtc::PeerConnectionInterface::GATHER_ONCE:
434 return RTCContinualGatheringPolicyGatherOnce;
435 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
436 return RTCContinualGatheringPolicyGatherContinually;
437 }
438}
439
440+ (NSString *)stringForContinualGatheringPolicy:
441 (RTCContinualGatheringPolicy)policy {
442 switch (policy) {
443 case RTCContinualGatheringPolicyGatherOnce:
444 return @"GATHER_ONCE";
445 case RTCContinualGatheringPolicyGatherContinually:
446 return @"GATHER_CONTINUALLY";
447 }
448}
449
hbosf9da44d2016-06-09 03:18:28 -0700450+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
451 (RTCEncryptionKeyType)keyType {
452 switch (keyType) {
453 case RTCEncryptionKeyTypeRSA:
454 return rtc::KT_RSA;
455 case RTCEncryptionKeyTypeECDSA:
456 return rtc::KT_ECDSA;
457 }
458}
459
Steve Anton8cb344a2018-02-27 15:34:53 -0800460+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
461 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800462 case RTCSdpSemanticsPlanB:
463 return webrtc::SdpSemantics::kPlanB;
464 case RTCSdpSemanticsUnifiedPlan:
465 return webrtc::SdpSemantics::kUnifiedPlan;
466 }
467}
468
469+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
470 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800471 case webrtc::SdpSemantics::kPlanB:
472 return RTCSdpSemanticsPlanB;
473 case webrtc::SdpSemantics::kUnifiedPlan:
474 return RTCSdpSemanticsUnifiedPlan;
475 }
476}
477
478+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
479 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800480 case RTCSdpSemanticsPlanB:
481 return @"PLAN_B";
482 case RTCSdpSemanticsUnifiedPlan:
483 return @"UNIFIED_PLAN";
484 }
485}
486
hjon6d49a8e2016-01-26 13:06:42 -0800487@end