blob: 55bf26f38d66547208fde2b08ca246bc2a790abd [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;
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030034@synthesize disableIPV6 = _disableIPV6;
35@synthesize disableIPV6OnWiFi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -070036@synthesize maxIPv6Networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010037@synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks;
hjon6d49a8e2016-01-26 13:06:42 -080038@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -080039@synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
hjon6d49a8e2016-01-26 13:06:42 -080040@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
41@synthesize iceBackupCandidatePairPingInterval =
42 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080043@synthesize keyType = _keyType;
deadbeefbe0c96f2016-05-18 16:20:14 -070044@synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -070045@synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
46@synthesize shouldPresumeWritableWhenFullyRelayed =
47 _shouldPresumeWritableWhenFullyRelayed;
skvlada5d94ff2017-02-02 13:02:30 -080048@synthesize iceCheckMinInterval = _iceCheckMinInterval;
Steve Antond295e402017-07-14 16:06:41 -070049@synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange;
Steve Anton8cb344a2018-02-27 15:34:53 -080050@synthesize sdpSemantics = _sdpSemantics;
Zeke Chinef1140e2017-10-27 15:42:08 -070051@synthesize turnCustomizer = _turnCustomizer;
Zhi Huangb57e1692018-06-12 11:41:11 -070052@synthesize activeResetSrtpParams = _activeResetSrtpParams;
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070053@synthesize useMediaTransport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -070054@synthesize useMediaTransportForDataChannels = _useMediaTransportForDataChannels;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070055@synthesize cryptoOptions = _cryptoOptions;
hjon6d49a8e2016-01-26 13:06:42 -080056
57- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070058 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020059 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070060 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070061}
62
63- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070064 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080065 if (self = [super init]) {
jtteh4eeb5372017-04-03 15:06:37 -070066 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070067 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
jtteh4eeb5372017-04-03 15:06:37 -070068 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
69 [iceServers addObject:iceServer];
70 }
71 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020072 if (!config.certificates.empty()) {
73 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
74 native_cert = config.certificates[0];
75 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
76 _certificate =
77 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
78 certificate:@(native_pem.certificate().c_str())];
79 }
hjon6d49a8e2016-01-26 13:06:42 -080080 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070081 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080082 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070083 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080084 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070085 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080086 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070087 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070088 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070089 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070090 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070091 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070092 _continualGatheringPolicy =
93 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030094 _disableIPV6 = config.disable_ipv6;
95 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -070096 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010097 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -070098 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
99 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
100 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800101 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700102 config.ice_backup_candidate_pair_ping_interval;
Piotr (Peter) Slatala693432d2018-10-30 16:52:06 -0700103 _useMediaTransport = config.use_media_transport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700104 _useMediaTransportForDataChannels = config.use_media_transport_for_data_channels;
tkchinab8f82f2016-01-27 17:50:11 -0800105 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700106 _iceCandidatePoolSize = config.ice_candidate_pool_size;
107 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700108 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700109 config.presume_writable_when_fully_relayed;
110 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800111 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700112 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800113 }
Steve Antond295e402017-07-14 16:06:41 -0700114 if (config.ice_regather_interval_range) {
115 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
116 _iceRegatherIntervalRange =
117 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
118 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800119 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700120 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700121 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700122 if (config.crypto_options) {
123 _cryptoOptions = [[RTCCryptoOptions alloc]
124 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
125 .enable_gcm_crypto_suites
126 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
127 .enable_aes128_sha1_32_crypto_cipher
128 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
129 .enable_encrypted_rtp_header_extensions
130 sframeRequireFrameEncryption:config.crypto_options->sframe
131 .require_frame_encryption];
132 }
hjon6d49a8e2016-01-26 13:06:42 -0800133 }
134 return self;
135}
136
137- (NSString *)description {
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300138 static NSString *formatString = @"RTCConfiguration: "
139 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
140 @"%d\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100141
Steve Anton8cb344a2018-02-27 15:34:53 -0800142 return [NSString
143 stringWithFormat:formatString,
144 _iceServers,
145 [[self class] stringForTransportPolicy:_iceTransportPolicy],
146 [[self class] stringForBundlePolicy:_bundlePolicy],
147 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
148 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
149 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
150 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
151 [[self class] stringForSdpSemantics:_sdpSemantics],
152 _audioJitterBufferMaxPackets,
153 _audioJitterBufferFastAccelerate,
154 _iceConnectionReceivingTimeout,
155 _iceBackupCandidatePairPingInterval,
156 _iceCandidatePoolSize,
157 _shouldPruneTurnPorts,
158 _shouldPresumeWritableWhenFullyRelayed,
159 _iceCheckMinInterval,
160 _iceRegatherIntervalRange,
161 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300162 _disableIPV6,
163 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700164 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700165 _activeResetSrtpParams,
166 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800167}
168
169#pragma mark - Private
170
hbosa73ca562016-05-17 03:28:58 -0700171- (webrtc::PeerConnectionInterface::RTCConfiguration *)
172 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200173 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700174 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
175 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800176
177 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200178 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800179 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200180 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800181 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200182 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800183 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200184 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800185 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200186 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800187 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700188 nativeConfig->candidate_network_policy = [[self class]
189 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200190 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700191 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300192 nativeConfig->disable_ipv6 = _disableIPV6;
193 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700194 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100195 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200196 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800197 nativeConfig->audio_jitter_buffer_fast_accelerate =
198 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200199 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800200 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200201 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800202 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700203 nativeConfig->use_media_transport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700204 nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200205 rtc::KeyType keyType =
206 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200207 if (_certificate != nullptr) {
208 // if offered a pemcert use it...
209 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
210 std::string pem_private_key = [[_certificate private_key] UTF8String];
211 std::string pem_certificate = [[_certificate certificate] UTF8String];
212 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
213 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
214 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200215 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200216 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200217 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800218 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200219 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200220 } else {
221 RTC_LOG(LS_INFO) << "Don't have configured cert.";
222 // Generate non-default certificate.
223 if (keyType != rtc::KT_DEFAULT) {
224 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
225 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
226 absl::optional<uint64_t>());
227 if (!certificate) {
228 RTCLogError(@"Failed to generate certificate.");
229 return nullptr;
230 }
231 nativeConfig->certificates.push_back(certificate);
232 }
tkchinab8f82f2016-01-27 17:50:11 -0800233 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700234 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700235 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700236 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700237 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800238 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200239 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800240 }
Steve Antond295e402017-07-14 16:06:41 -0700241 if (_iceRegatherIntervalRange != nil) {
242 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
243 _iceRegatherIntervalRange.nativeIntervalRange);
244 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200245 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700246 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800247 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700248 if (_turnCustomizer) {
249 nativeConfig->turn_customizer = _turnCustomizer;
250 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700251 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700252 if (_cryptoOptions) {
253 webrtc::CryptoOptions nativeCryptoOptions;
254 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
255 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
256 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
257 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
258 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
259 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
260 nativeCryptoOptions.sframe.require_frame_encryption =
261 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
262 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
263 }
264
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200265 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800266}
267
hjon6d49a8e2016-01-26 13:06:42 -0800268+ (webrtc::PeerConnectionInterface::IceTransportsType)
269 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
270 switch (policy) {
271 case RTCIceTransportPolicyNone:
272 return webrtc::PeerConnectionInterface::kNone;
273 case RTCIceTransportPolicyRelay:
274 return webrtc::PeerConnectionInterface::kRelay;
275 case RTCIceTransportPolicyNoHost:
276 return webrtc::PeerConnectionInterface::kNoHost;
277 case RTCIceTransportPolicyAll:
278 return webrtc::PeerConnectionInterface::kAll;
279 }
280}
281
282+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
283 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
284 switch (nativeType) {
285 case webrtc::PeerConnectionInterface::kNone:
286 return RTCIceTransportPolicyNone;
287 case webrtc::PeerConnectionInterface::kRelay:
288 return RTCIceTransportPolicyRelay;
289 case webrtc::PeerConnectionInterface::kNoHost:
290 return RTCIceTransportPolicyNoHost;
291 case webrtc::PeerConnectionInterface::kAll:
292 return RTCIceTransportPolicyAll;
293 }
294}
295
296+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
297 switch (policy) {
298 case RTCIceTransportPolicyNone:
299 return @"NONE";
300 case RTCIceTransportPolicyRelay:
301 return @"RELAY";
302 case RTCIceTransportPolicyNoHost:
303 return @"NO_HOST";
304 case RTCIceTransportPolicyAll:
305 return @"ALL";
306 }
307}
308
309+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
310 (RTCBundlePolicy)policy {
311 switch (policy) {
312 case RTCBundlePolicyBalanced:
313 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
314 case RTCBundlePolicyMaxCompat:
315 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
316 case RTCBundlePolicyMaxBundle:
317 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
318 }
319}
320
321+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
322 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
323 switch (nativePolicy) {
324 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
325 return RTCBundlePolicyBalanced;
326 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
327 return RTCBundlePolicyMaxCompat;
328 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
329 return RTCBundlePolicyMaxBundle;
330 }
331}
332
333+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
334 switch (policy) {
335 case RTCBundlePolicyBalanced:
336 return @"BALANCED";
337 case RTCBundlePolicyMaxCompat:
338 return @"MAX_COMPAT";
339 case RTCBundlePolicyMaxBundle:
340 return @"MAX_BUNDLE";
341 }
342}
343
344+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
345 (RTCRtcpMuxPolicy)policy {
346 switch (policy) {
347 case RTCRtcpMuxPolicyNegotiate:
348 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
349 case RTCRtcpMuxPolicyRequire:
350 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
351 }
352}
353
354+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
355 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
356 switch (nativePolicy) {
357 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
358 return RTCRtcpMuxPolicyNegotiate;
359 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
360 return RTCRtcpMuxPolicyRequire;
361 }
362}
363
364+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
365 switch (policy) {
366 case RTCRtcpMuxPolicyNegotiate:
367 return @"NEGOTIATE";
368 case RTCRtcpMuxPolicyRequire:
369 return @"REQUIRE";
370 }
371}
372
373+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
374 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
375 switch (policy) {
376 case RTCTcpCandidatePolicyEnabled:
377 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
378 case RTCTcpCandidatePolicyDisabled:
379 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
380 }
381}
382
Honghai Zhang46007ae2016-06-03 16:31:32 -0700383+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
384 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
385 switch (policy) {
386 case RTCCandidateNetworkPolicyAll:
387 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
388 case RTCCandidateNetworkPolicyLowCost:
389 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
390 }
391}
392
hjon6d49a8e2016-01-26 13:06:42 -0800393+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
394 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
395 switch (nativePolicy) {
396 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
397 return RTCTcpCandidatePolicyEnabled;
398 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
399 return RTCTcpCandidatePolicyDisabled;
400 }
401}
402
403+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
404 switch (policy) {
405 case RTCTcpCandidatePolicyEnabled:
406 return @"TCP_ENABLED";
407 case RTCTcpCandidatePolicyDisabled:
408 return @"TCP_DISABLED";
409 }
410}
411
Honghai Zhang46007ae2016-06-03 16:31:32 -0700412+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
413 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
414 switch (nativePolicy) {
415 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
416 return RTCCandidateNetworkPolicyAll;
417 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
418 return RTCCandidateNetworkPolicyLowCost;
419 }
420}
421
422+ (NSString *)stringForCandidateNetworkPolicy:
423 (RTCCandidateNetworkPolicy)policy {
424 switch (policy) {
425 case RTCCandidateNetworkPolicyAll:
426 return @"CANDIDATE_ALL_NETWORKS";
427 case RTCCandidateNetworkPolicyLowCost:
428 return @"CANDIDATE_LOW_COST_NETWORKS";
429 }
430}
431
Honghai Zhang3108fc92016-05-11 10:10:39 -0700432+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
433 nativeContinualGatheringPolicyForPolicy:
434 (RTCContinualGatheringPolicy)policy {
435 switch (policy) {
436 case RTCContinualGatheringPolicyGatherOnce:
437 return webrtc::PeerConnectionInterface::GATHER_ONCE;
438 case RTCContinualGatheringPolicyGatherContinually:
439 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
440 }
441}
442
443+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
444 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
445 switch (nativePolicy) {
446 case webrtc::PeerConnectionInterface::GATHER_ONCE:
447 return RTCContinualGatheringPolicyGatherOnce;
448 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
449 return RTCContinualGatheringPolicyGatherContinually;
450 }
451}
452
453+ (NSString *)stringForContinualGatheringPolicy:
454 (RTCContinualGatheringPolicy)policy {
455 switch (policy) {
456 case RTCContinualGatheringPolicyGatherOnce:
457 return @"GATHER_ONCE";
458 case RTCContinualGatheringPolicyGatherContinually:
459 return @"GATHER_CONTINUALLY";
460 }
461}
462
hbosf9da44d2016-06-09 03:18:28 -0700463+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
464 (RTCEncryptionKeyType)keyType {
465 switch (keyType) {
466 case RTCEncryptionKeyTypeRSA:
467 return rtc::KT_RSA;
468 case RTCEncryptionKeyTypeECDSA:
469 return rtc::KT_ECDSA;
470 }
471}
472
Steve Anton8cb344a2018-02-27 15:34:53 -0800473+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
474 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800475 case RTCSdpSemanticsPlanB:
476 return webrtc::SdpSemantics::kPlanB;
477 case RTCSdpSemanticsUnifiedPlan:
478 return webrtc::SdpSemantics::kUnifiedPlan;
479 }
480}
481
482+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
483 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800484 case webrtc::SdpSemantics::kPlanB:
485 return RTCSdpSemanticsPlanB;
486 case webrtc::SdpSemantics::kUnifiedPlan:
487 return RTCSdpSemanticsUnifiedPlan;
488 }
489}
490
491+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
492 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800493 case RTCSdpSemanticsPlanB:
494 return @"PLAN_B";
495 case RTCSdpSemanticsUnifiedPlan:
496 return @"UNIFIED_PLAN";
497 }
498}
499
hjon6d49a8e2016-01-26 13:06:42 -0800500@end