blob: f550a3a24f2e599c77b7a123d65aa594cc3fcbb1 [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;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700192 nativeConfig->use_media_transport = _useMediaTransport;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 rtc::KeyType keyType =
194 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200195 if (_certificate != nullptr) {
196 // if offered a pemcert use it...
197 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
198 std::string pem_private_key = [[_certificate private_key] UTF8String];
199 std::string pem_certificate = [[_certificate certificate] UTF8String];
200 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
201 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
202 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200203 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200204 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200205 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800206 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200207 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200208 } else {
209 RTC_LOG(LS_INFO) << "Don't have configured cert.";
210 // Generate non-default certificate.
211 if (keyType != rtc::KT_DEFAULT) {
212 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
213 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
214 absl::optional<uint64_t>());
215 if (!certificate) {
216 RTCLogError(@"Failed to generate certificate.");
217 return nullptr;
218 }
219 nativeConfig->certificates.push_back(certificate);
220 }
tkchinab8f82f2016-01-27 17:50:11 -0800221 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700222 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700223 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700224 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700225 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800226 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200227 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800228 }
Steve Antond295e402017-07-14 16:06:41 -0700229 if (_iceRegatherIntervalRange != nil) {
230 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
231 _iceRegatherIntervalRange.nativeIntervalRange);
232 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200233 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700234 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800235 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700236 if (_turnCustomizer) {
237 nativeConfig->turn_customizer = _turnCustomizer;
238 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700239 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700240 if (_cryptoOptions) {
241 webrtc::CryptoOptions nativeCryptoOptions;
242 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
243 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
244 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
245 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
246 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
247 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
248 nativeCryptoOptions.sframe.require_frame_encryption =
249 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
250 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
251 }
252
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200253 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800254}
255
hjon6d49a8e2016-01-26 13:06:42 -0800256+ (webrtc::PeerConnectionInterface::IceTransportsType)
257 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
258 switch (policy) {
259 case RTCIceTransportPolicyNone:
260 return webrtc::PeerConnectionInterface::kNone;
261 case RTCIceTransportPolicyRelay:
262 return webrtc::PeerConnectionInterface::kRelay;
263 case RTCIceTransportPolicyNoHost:
264 return webrtc::PeerConnectionInterface::kNoHost;
265 case RTCIceTransportPolicyAll:
266 return webrtc::PeerConnectionInterface::kAll;
267 }
268}
269
270+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
271 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
272 switch (nativeType) {
273 case webrtc::PeerConnectionInterface::kNone:
274 return RTCIceTransportPolicyNone;
275 case webrtc::PeerConnectionInterface::kRelay:
276 return RTCIceTransportPolicyRelay;
277 case webrtc::PeerConnectionInterface::kNoHost:
278 return RTCIceTransportPolicyNoHost;
279 case webrtc::PeerConnectionInterface::kAll:
280 return RTCIceTransportPolicyAll;
281 }
282}
283
284+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
285 switch (policy) {
286 case RTCIceTransportPolicyNone:
287 return @"NONE";
288 case RTCIceTransportPolicyRelay:
289 return @"RELAY";
290 case RTCIceTransportPolicyNoHost:
291 return @"NO_HOST";
292 case RTCIceTransportPolicyAll:
293 return @"ALL";
294 }
295}
296
297+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
298 (RTCBundlePolicy)policy {
299 switch (policy) {
300 case RTCBundlePolicyBalanced:
301 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
302 case RTCBundlePolicyMaxCompat:
303 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
304 case RTCBundlePolicyMaxBundle:
305 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
306 }
307}
308
309+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
310 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
311 switch (nativePolicy) {
312 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
313 return RTCBundlePolicyBalanced;
314 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
315 return RTCBundlePolicyMaxCompat;
316 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
317 return RTCBundlePolicyMaxBundle;
318 }
319}
320
321+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
322 switch (policy) {
323 case RTCBundlePolicyBalanced:
324 return @"BALANCED";
325 case RTCBundlePolicyMaxCompat:
326 return @"MAX_COMPAT";
327 case RTCBundlePolicyMaxBundle:
328 return @"MAX_BUNDLE";
329 }
330}
331
332+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
333 (RTCRtcpMuxPolicy)policy {
334 switch (policy) {
335 case RTCRtcpMuxPolicyNegotiate:
336 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
337 case RTCRtcpMuxPolicyRequire:
338 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
339 }
340}
341
342+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
343 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
344 switch (nativePolicy) {
345 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
346 return RTCRtcpMuxPolicyNegotiate;
347 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
348 return RTCRtcpMuxPolicyRequire;
349 }
350}
351
352+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
353 switch (policy) {
354 case RTCRtcpMuxPolicyNegotiate:
355 return @"NEGOTIATE";
356 case RTCRtcpMuxPolicyRequire:
357 return @"REQUIRE";
358 }
359}
360
361+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
362 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
363 switch (policy) {
364 case RTCTcpCandidatePolicyEnabled:
365 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
366 case RTCTcpCandidatePolicyDisabled:
367 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
368 }
369}
370
Honghai Zhang46007ae2016-06-03 16:31:32 -0700371+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
372 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
373 switch (policy) {
374 case RTCCandidateNetworkPolicyAll:
375 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
376 case RTCCandidateNetworkPolicyLowCost:
377 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
378 }
379}
380
hjon6d49a8e2016-01-26 13:06:42 -0800381+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
382 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
383 switch (nativePolicy) {
384 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
385 return RTCTcpCandidatePolicyEnabled;
386 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
387 return RTCTcpCandidatePolicyDisabled;
388 }
389}
390
391+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
392 switch (policy) {
393 case RTCTcpCandidatePolicyEnabled:
394 return @"TCP_ENABLED";
395 case RTCTcpCandidatePolicyDisabled:
396 return @"TCP_DISABLED";
397 }
398}
399
Honghai Zhang46007ae2016-06-03 16:31:32 -0700400+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
401 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
402 switch (nativePolicy) {
403 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
404 return RTCCandidateNetworkPolicyAll;
405 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
406 return RTCCandidateNetworkPolicyLowCost;
407 }
408}
409
410+ (NSString *)stringForCandidateNetworkPolicy:
411 (RTCCandidateNetworkPolicy)policy {
412 switch (policy) {
413 case RTCCandidateNetworkPolicyAll:
414 return @"CANDIDATE_ALL_NETWORKS";
415 case RTCCandidateNetworkPolicyLowCost:
416 return @"CANDIDATE_LOW_COST_NETWORKS";
417 }
418}
419
Honghai Zhang3108fc92016-05-11 10:10:39 -0700420+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
421 nativeContinualGatheringPolicyForPolicy:
422 (RTCContinualGatheringPolicy)policy {
423 switch (policy) {
424 case RTCContinualGatheringPolicyGatherOnce:
425 return webrtc::PeerConnectionInterface::GATHER_ONCE;
426 case RTCContinualGatheringPolicyGatherContinually:
427 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
428 }
429}
430
431+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
432 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
433 switch (nativePolicy) {
434 case webrtc::PeerConnectionInterface::GATHER_ONCE:
435 return RTCContinualGatheringPolicyGatherOnce;
436 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
437 return RTCContinualGatheringPolicyGatherContinually;
438 }
439}
440
441+ (NSString *)stringForContinualGatheringPolicy:
442 (RTCContinualGatheringPolicy)policy {
443 switch (policy) {
444 case RTCContinualGatheringPolicyGatherOnce:
445 return @"GATHER_ONCE";
446 case RTCContinualGatheringPolicyGatherContinually:
447 return @"GATHER_CONTINUALLY";
448 }
449}
450
hbosf9da44d2016-06-09 03:18:28 -0700451+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
452 (RTCEncryptionKeyType)keyType {
453 switch (keyType) {
454 case RTCEncryptionKeyTypeRSA:
455 return rtc::KT_RSA;
456 case RTCEncryptionKeyTypeECDSA:
457 return rtc::KT_ECDSA;
458 }
459}
460
Steve Anton8cb344a2018-02-27 15:34:53 -0800461+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
462 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800463 case RTCSdpSemanticsPlanB:
464 return webrtc::SdpSemantics::kPlanB;
465 case RTCSdpSemanticsUnifiedPlan:
466 return webrtc::SdpSemantics::kUnifiedPlan;
467 }
468}
469
470+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
471 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800472 case webrtc::SdpSemantics::kPlanB:
473 return RTCSdpSemanticsPlanB;
474 case webrtc::SdpSemantics::kUnifiedPlan:
475 return RTCSdpSemanticsUnifiedPlan;
476 }
477}
478
479+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
480 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800481 case RTCSdpSemanticsPlanB:
482 return @"PLAN_B";
483 case RTCSdpSemanticsUnifiedPlan:
484 return @"UNIFIED_PLAN";
485 }
486}
487
hjon6d49a8e2016-01-26 13:06:42 -0800488@end