blob: c17ce24ae40f8c5c588c9ab57db13d1851e7d910 [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;
Piotr (Peter) Slatala693432d2018-10-30 16:52:06 -070098 _useMediaTransport = config.use_media_transport;
tkchinab8f82f2016-01-27 17:50:11 -080099 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700100 _iceCandidatePoolSize = config.ice_candidate_pool_size;
101 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700102 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700103 config.presume_writable_when_fully_relayed;
104 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800105 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700106 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800107 }
Steve Antond295e402017-07-14 16:06:41 -0700108 if (config.ice_regather_interval_range) {
109 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
110 _iceRegatherIntervalRange =
111 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
112 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800113 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700114 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700115 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700116 if (config.crypto_options) {
117 _cryptoOptions = [[RTCCryptoOptions alloc]
118 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
119 .enable_gcm_crypto_suites
120 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
121 .enable_aes128_sha1_32_crypto_cipher
122 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
123 .enable_encrypted_rtp_header_extensions
124 sframeRequireFrameEncryption:config.crypto_options->sframe
125 .require_frame_encryption];
126 }
hjon6d49a8e2016-01-26 13:06:42 -0800127 }
128 return self;
129}
130
131- (NSString *)description {
Steve Anton8cb344a2018-02-27 15:34:53 -0800132 static NSString *formatString =
133 @"RTCConfiguration: "
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700134 @"{\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 +0100135
Steve Anton8cb344a2018-02-27 15:34:53 -0800136 return [NSString
137 stringWithFormat:formatString,
138 _iceServers,
139 [[self class] stringForTransportPolicy:_iceTransportPolicy],
140 [[self class] stringForBundlePolicy:_bundlePolicy],
141 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
142 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
143 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
144 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
145 [[self class] stringForSdpSemantics:_sdpSemantics],
146 _audioJitterBufferMaxPackets,
147 _audioJitterBufferFastAccelerate,
148 _iceConnectionReceivingTimeout,
149 _iceBackupCandidatePairPingInterval,
150 _iceCandidatePoolSize,
151 _shouldPruneTurnPorts,
152 _shouldPresumeWritableWhenFullyRelayed,
153 _iceCheckMinInterval,
154 _iceRegatherIntervalRange,
155 _disableLinkLocalNetworks,
Zhi Huangb57e1692018-06-12 11:41:11 -0700156 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700157 _activeResetSrtpParams,
158 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800159}
160
161#pragma mark - Private
162
hbosa73ca562016-05-17 03:28:58 -0700163- (webrtc::PeerConnectionInterface::RTCConfiguration *)
164 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200165 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700166 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
167 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800168
169 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200170 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800171 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200172 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800173 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200174 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800175 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200176 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800177 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200178 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800179 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700180 nativeConfig->candidate_network_policy = [[self class]
181 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200182 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700183 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
deadbeef2059bb32017-07-26 18:25:43 -0700184 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100185 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200186 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800187 nativeConfig->audio_jitter_buffer_fast_accelerate =
188 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800190 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800192 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700193 nativeConfig->use_media_transport = _useMediaTransport;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200194 rtc::KeyType keyType =
195 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200196 if (_certificate != nullptr) {
197 // if offered a pemcert use it...
198 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
199 std::string pem_private_key = [[_certificate private_key] UTF8String];
200 std::string pem_certificate = [[_certificate certificate] UTF8String];
201 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
202 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
203 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200204 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200205 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800207 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200208 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200209 } else {
210 RTC_LOG(LS_INFO) << "Don't have configured cert.";
211 // Generate non-default certificate.
212 if (keyType != rtc::KT_DEFAULT) {
213 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
214 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
215 absl::optional<uint64_t>());
216 if (!certificate) {
217 RTCLogError(@"Failed to generate certificate.");
218 return nullptr;
219 }
220 nativeConfig->certificates.push_back(certificate);
221 }
tkchinab8f82f2016-01-27 17:50:11 -0800222 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700223 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700224 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700225 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700226 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800227 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200228 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800229 }
Steve Antond295e402017-07-14 16:06:41 -0700230 if (_iceRegatherIntervalRange != nil) {
231 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
232 _iceRegatherIntervalRange.nativeIntervalRange);
233 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200234 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700235 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800236 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700237 if (_turnCustomizer) {
238 nativeConfig->turn_customizer = _turnCustomizer;
239 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700240 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700241 if (_cryptoOptions) {
242 webrtc::CryptoOptions nativeCryptoOptions;
243 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
244 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
245 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
246 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
247 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
248 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
249 nativeCryptoOptions.sframe.require_frame_encryption =
250 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
251 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
252 }
253
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200254 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800255}
256
hjon6d49a8e2016-01-26 13:06:42 -0800257+ (webrtc::PeerConnectionInterface::IceTransportsType)
258 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
259 switch (policy) {
260 case RTCIceTransportPolicyNone:
261 return webrtc::PeerConnectionInterface::kNone;
262 case RTCIceTransportPolicyRelay:
263 return webrtc::PeerConnectionInterface::kRelay;
264 case RTCIceTransportPolicyNoHost:
265 return webrtc::PeerConnectionInterface::kNoHost;
266 case RTCIceTransportPolicyAll:
267 return webrtc::PeerConnectionInterface::kAll;
268 }
269}
270
271+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
272 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
273 switch (nativeType) {
274 case webrtc::PeerConnectionInterface::kNone:
275 return RTCIceTransportPolicyNone;
276 case webrtc::PeerConnectionInterface::kRelay:
277 return RTCIceTransportPolicyRelay;
278 case webrtc::PeerConnectionInterface::kNoHost:
279 return RTCIceTransportPolicyNoHost;
280 case webrtc::PeerConnectionInterface::kAll:
281 return RTCIceTransportPolicyAll;
282 }
283}
284
285+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
286 switch (policy) {
287 case RTCIceTransportPolicyNone:
288 return @"NONE";
289 case RTCIceTransportPolicyRelay:
290 return @"RELAY";
291 case RTCIceTransportPolicyNoHost:
292 return @"NO_HOST";
293 case RTCIceTransportPolicyAll:
294 return @"ALL";
295 }
296}
297
298+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
299 (RTCBundlePolicy)policy {
300 switch (policy) {
301 case RTCBundlePolicyBalanced:
302 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
303 case RTCBundlePolicyMaxCompat:
304 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
305 case RTCBundlePolicyMaxBundle:
306 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
307 }
308}
309
310+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
311 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
312 switch (nativePolicy) {
313 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
314 return RTCBundlePolicyBalanced;
315 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
316 return RTCBundlePolicyMaxCompat;
317 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
318 return RTCBundlePolicyMaxBundle;
319 }
320}
321
322+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
323 switch (policy) {
324 case RTCBundlePolicyBalanced:
325 return @"BALANCED";
326 case RTCBundlePolicyMaxCompat:
327 return @"MAX_COMPAT";
328 case RTCBundlePolicyMaxBundle:
329 return @"MAX_BUNDLE";
330 }
331}
332
333+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
334 (RTCRtcpMuxPolicy)policy {
335 switch (policy) {
336 case RTCRtcpMuxPolicyNegotiate:
337 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
338 case RTCRtcpMuxPolicyRequire:
339 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
340 }
341}
342
343+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
344 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
345 switch (nativePolicy) {
346 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
347 return RTCRtcpMuxPolicyNegotiate;
348 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
349 return RTCRtcpMuxPolicyRequire;
350 }
351}
352
353+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
354 switch (policy) {
355 case RTCRtcpMuxPolicyNegotiate:
356 return @"NEGOTIATE";
357 case RTCRtcpMuxPolicyRequire:
358 return @"REQUIRE";
359 }
360}
361
362+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
363 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
364 switch (policy) {
365 case RTCTcpCandidatePolicyEnabled:
366 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
367 case RTCTcpCandidatePolicyDisabled:
368 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
369 }
370}
371
Honghai Zhang46007ae2016-06-03 16:31:32 -0700372+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
373 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
374 switch (policy) {
375 case RTCCandidateNetworkPolicyAll:
376 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
377 case RTCCandidateNetworkPolicyLowCost:
378 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
379 }
380}
381
hjon6d49a8e2016-01-26 13:06:42 -0800382+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
383 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
384 switch (nativePolicy) {
385 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
386 return RTCTcpCandidatePolicyEnabled;
387 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
388 return RTCTcpCandidatePolicyDisabled;
389 }
390}
391
392+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
393 switch (policy) {
394 case RTCTcpCandidatePolicyEnabled:
395 return @"TCP_ENABLED";
396 case RTCTcpCandidatePolicyDisabled:
397 return @"TCP_DISABLED";
398 }
399}
400
Honghai Zhang46007ae2016-06-03 16:31:32 -0700401+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
402 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
403 switch (nativePolicy) {
404 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
405 return RTCCandidateNetworkPolicyAll;
406 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
407 return RTCCandidateNetworkPolicyLowCost;
408 }
409}
410
411+ (NSString *)stringForCandidateNetworkPolicy:
412 (RTCCandidateNetworkPolicy)policy {
413 switch (policy) {
414 case RTCCandidateNetworkPolicyAll:
415 return @"CANDIDATE_ALL_NETWORKS";
416 case RTCCandidateNetworkPolicyLowCost:
417 return @"CANDIDATE_LOW_COST_NETWORKS";
418 }
419}
420
Honghai Zhang3108fc92016-05-11 10:10:39 -0700421+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
422 nativeContinualGatheringPolicyForPolicy:
423 (RTCContinualGatheringPolicy)policy {
424 switch (policy) {
425 case RTCContinualGatheringPolicyGatherOnce:
426 return webrtc::PeerConnectionInterface::GATHER_ONCE;
427 case RTCContinualGatheringPolicyGatherContinually:
428 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
429 }
430}
431
432+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
433 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
434 switch (nativePolicy) {
435 case webrtc::PeerConnectionInterface::GATHER_ONCE:
436 return RTCContinualGatheringPolicyGatherOnce;
437 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
438 return RTCContinualGatheringPolicyGatherContinually;
439 }
440}
441
442+ (NSString *)stringForContinualGatheringPolicy:
443 (RTCContinualGatheringPolicy)policy {
444 switch (policy) {
445 case RTCContinualGatheringPolicyGatherOnce:
446 return @"GATHER_ONCE";
447 case RTCContinualGatheringPolicyGatherContinually:
448 return @"GATHER_CONTINUALLY";
449 }
450}
451
hbosf9da44d2016-06-09 03:18:28 -0700452+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
453 (RTCEncryptionKeyType)keyType {
454 switch (keyType) {
455 case RTCEncryptionKeyTypeRSA:
456 return rtc::KT_RSA;
457 case RTCEncryptionKeyTypeECDSA:
458 return rtc::KT_ECDSA;
459 }
460}
461
Steve Anton8cb344a2018-02-27 15:34:53 -0800462+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
463 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800464 case RTCSdpSemanticsPlanB:
465 return webrtc::SdpSemantics::kPlanB;
466 case RTCSdpSemanticsUnifiedPlan:
467 return webrtc::SdpSemantics::kUnifiedPlan;
468 }
469}
470
471+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
472 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800473 case webrtc::SdpSemantics::kPlanB:
474 return RTCSdpSemanticsPlanB;
475 case webrtc::SdpSemantics::kUnifiedPlan:
476 return RTCSdpSemanticsUnifiedPlan;
477 }
478}
479
480+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
481 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800482 case RTCSdpSemanticsPlanB:
483 return @"PLAN_B";
484 case RTCSdpSemanticsUnifiedPlan:
485 return @"UNIFIED_PLAN";
486 }
487}
488
hjon6d49a8e2016-01-26 13:06:42 -0800489@end