blob: 83ae5759869658a966070d0b0944d2a9f1f38543 [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
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/rtc_certificate_generator.h"
22#include "rtc_base/ssl_identity.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;
Jiawei Oub1e47752018-11-13 23:48:19 -080056@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
57@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
hjon6d49a8e2016-01-26 13:06:42 -080058
59- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070060 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020061 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070062 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070063}
64
65- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070066 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080067 if (self = [super init]) {
jtteh4eeb5372017-04-03 15:06:37 -070068 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070069 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
jtteh4eeb5372017-04-03 15:06:37 -070070 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
71 [iceServers addObject:iceServer];
72 }
73 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020074 if (!config.certificates.empty()) {
75 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
76 native_cert = config.certificates[0];
77 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
78 _certificate =
79 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
80 certificate:@(native_pem.certificate().c_str())];
81 }
hjon6d49a8e2016-01-26 13:06:42 -080082 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070083 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080084 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070085 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080086 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070087 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080088 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070089 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070090 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070091 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070092 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070093 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070094 _continualGatheringPolicy =
95 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030096 _disableIPV6 = config.disable_ipv6;
97 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -070098 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010099 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700100 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
101 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
102 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800103 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700104 config.ice_backup_candidate_pair_ping_interval;
Piotr (Peter) Slatala693432d2018-10-30 16:52:06 -0700105 _useMediaTransport = config.use_media_transport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700106 _useMediaTransportForDataChannels = config.use_media_transport_for_data_channels;
tkchinab8f82f2016-01-27 17:50:11 -0800107 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700108 _iceCandidatePoolSize = config.ice_candidate_pool_size;
109 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700110 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700111 config.presume_writable_when_fully_relayed;
112 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800113 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700114 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800115 }
Steve Antond295e402017-07-14 16:06:41 -0700116 if (config.ice_regather_interval_range) {
117 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
118 _iceRegatherIntervalRange =
119 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
120 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800121 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700122 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700123 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700124 if (config.crypto_options) {
125 _cryptoOptions = [[RTCCryptoOptions alloc]
126 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
127 .enable_gcm_crypto_suites
128 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
129 .enable_aes128_sha1_32_crypto_cipher
130 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
131 .enable_encrypted_rtp_header_extensions
132 sframeRequireFrameEncryption:config.crypto_options->sframe
133 .require_frame_encryption];
134 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800135 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
136 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
hjon6d49a8e2016-01-26 13:06:42 -0800137 }
138 return self;
139}
140
141- (NSString *)description {
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300142 static NSString *formatString = @"RTCConfiguration: "
143 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
144 @"%d\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100145
Steve Anton8cb344a2018-02-27 15:34:53 -0800146 return [NSString
147 stringWithFormat:formatString,
148 _iceServers,
149 [[self class] stringForTransportPolicy:_iceTransportPolicy],
150 [[self class] stringForBundlePolicy:_bundlePolicy],
151 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
152 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
153 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
154 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
155 [[self class] stringForSdpSemantics:_sdpSemantics],
156 _audioJitterBufferMaxPackets,
157 _audioJitterBufferFastAccelerate,
158 _iceConnectionReceivingTimeout,
159 _iceBackupCandidatePairPingInterval,
160 _iceCandidatePoolSize,
161 _shouldPruneTurnPorts,
162 _shouldPresumeWritableWhenFullyRelayed,
163 _iceCheckMinInterval,
164 _iceRegatherIntervalRange,
165 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300166 _disableIPV6,
167 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700168 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700169 _activeResetSrtpParams,
170 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800171}
172
173#pragma mark - Private
174
hbosa73ca562016-05-17 03:28:58 -0700175- (webrtc::PeerConnectionInterface::RTCConfiguration *)
176 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200177 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700178 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
179 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800180
181 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200182 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800183 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200184 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800185 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200186 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800187 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200188 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800189 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200190 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800191 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700192 nativeConfig->candidate_network_policy = [[self class]
193 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200194 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700195 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300196 nativeConfig->disable_ipv6 = _disableIPV6;
197 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700198 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100199 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200200 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800201 nativeConfig->audio_jitter_buffer_fast_accelerate =
202 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200203 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800204 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200205 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800206 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700207 nativeConfig->use_media_transport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700208 nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200209 rtc::KeyType keyType =
210 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200211 if (_certificate != nullptr) {
212 // if offered a pemcert use it...
213 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
214 std::string pem_private_key = [[_certificate private_key] UTF8String];
215 std::string pem_certificate = [[_certificate certificate] UTF8String];
216 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
217 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
218 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200219 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200220 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200221 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800222 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200223 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200224 } else {
225 RTC_LOG(LS_INFO) << "Don't have configured cert.";
226 // Generate non-default certificate.
227 if (keyType != rtc::KT_DEFAULT) {
228 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
229 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
230 absl::optional<uint64_t>());
231 if (!certificate) {
232 RTCLogError(@"Failed to generate certificate.");
233 return nullptr;
234 }
235 nativeConfig->certificates.push_back(certificate);
236 }
tkchinab8f82f2016-01-27 17:50:11 -0800237 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700238 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700239 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700240 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700241 _shouldPresumeWritableWhenFullyRelayed ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800242 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200243 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800244 }
Steve Antond295e402017-07-14 16:06:41 -0700245 if (_iceRegatherIntervalRange != nil) {
246 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
247 _iceRegatherIntervalRange.nativeIntervalRange);
248 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200249 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700250 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800251 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700252 if (_turnCustomizer) {
253 nativeConfig->turn_customizer = _turnCustomizer;
254 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700255 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700256 if (_cryptoOptions) {
257 webrtc::CryptoOptions nativeCryptoOptions;
258 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
259 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
260 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
261 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
262 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
263 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
264 nativeCryptoOptions.sframe.require_frame_encryption =
265 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
266 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
267 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800268 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
269 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200270 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800271}
272
hjon6d49a8e2016-01-26 13:06:42 -0800273+ (webrtc::PeerConnectionInterface::IceTransportsType)
274 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
275 switch (policy) {
276 case RTCIceTransportPolicyNone:
277 return webrtc::PeerConnectionInterface::kNone;
278 case RTCIceTransportPolicyRelay:
279 return webrtc::PeerConnectionInterface::kRelay;
280 case RTCIceTransportPolicyNoHost:
281 return webrtc::PeerConnectionInterface::kNoHost;
282 case RTCIceTransportPolicyAll:
283 return webrtc::PeerConnectionInterface::kAll;
284 }
285}
286
287+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
288 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
289 switch (nativeType) {
290 case webrtc::PeerConnectionInterface::kNone:
291 return RTCIceTransportPolicyNone;
292 case webrtc::PeerConnectionInterface::kRelay:
293 return RTCIceTransportPolicyRelay;
294 case webrtc::PeerConnectionInterface::kNoHost:
295 return RTCIceTransportPolicyNoHost;
296 case webrtc::PeerConnectionInterface::kAll:
297 return RTCIceTransportPolicyAll;
298 }
299}
300
301+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
302 switch (policy) {
303 case RTCIceTransportPolicyNone:
304 return @"NONE";
305 case RTCIceTransportPolicyRelay:
306 return @"RELAY";
307 case RTCIceTransportPolicyNoHost:
308 return @"NO_HOST";
309 case RTCIceTransportPolicyAll:
310 return @"ALL";
311 }
312}
313
314+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
315 (RTCBundlePolicy)policy {
316 switch (policy) {
317 case RTCBundlePolicyBalanced:
318 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
319 case RTCBundlePolicyMaxCompat:
320 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
321 case RTCBundlePolicyMaxBundle:
322 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
323 }
324}
325
326+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
327 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
328 switch (nativePolicy) {
329 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
330 return RTCBundlePolicyBalanced;
331 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
332 return RTCBundlePolicyMaxCompat;
333 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
334 return RTCBundlePolicyMaxBundle;
335 }
336}
337
338+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
339 switch (policy) {
340 case RTCBundlePolicyBalanced:
341 return @"BALANCED";
342 case RTCBundlePolicyMaxCompat:
343 return @"MAX_COMPAT";
344 case RTCBundlePolicyMaxBundle:
345 return @"MAX_BUNDLE";
346 }
347}
348
349+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
350 (RTCRtcpMuxPolicy)policy {
351 switch (policy) {
352 case RTCRtcpMuxPolicyNegotiate:
353 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
354 case RTCRtcpMuxPolicyRequire:
355 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
356 }
357}
358
359+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
360 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
361 switch (nativePolicy) {
362 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
363 return RTCRtcpMuxPolicyNegotiate;
364 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
365 return RTCRtcpMuxPolicyRequire;
366 }
367}
368
369+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
370 switch (policy) {
371 case RTCRtcpMuxPolicyNegotiate:
372 return @"NEGOTIATE";
373 case RTCRtcpMuxPolicyRequire:
374 return @"REQUIRE";
375 }
376}
377
378+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
379 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
380 switch (policy) {
381 case RTCTcpCandidatePolicyEnabled:
382 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
383 case RTCTcpCandidatePolicyDisabled:
384 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
385 }
386}
387
Honghai Zhang46007ae2016-06-03 16:31:32 -0700388+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
389 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
390 switch (policy) {
391 case RTCCandidateNetworkPolicyAll:
392 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
393 case RTCCandidateNetworkPolicyLowCost:
394 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
395 }
396}
397
hjon6d49a8e2016-01-26 13:06:42 -0800398+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
399 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
400 switch (nativePolicy) {
401 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
402 return RTCTcpCandidatePolicyEnabled;
403 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
404 return RTCTcpCandidatePolicyDisabled;
405 }
406}
407
408+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
409 switch (policy) {
410 case RTCTcpCandidatePolicyEnabled:
411 return @"TCP_ENABLED";
412 case RTCTcpCandidatePolicyDisabled:
413 return @"TCP_DISABLED";
414 }
415}
416
Honghai Zhang46007ae2016-06-03 16:31:32 -0700417+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
418 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
419 switch (nativePolicy) {
420 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
421 return RTCCandidateNetworkPolicyAll;
422 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
423 return RTCCandidateNetworkPolicyLowCost;
424 }
425}
426
427+ (NSString *)stringForCandidateNetworkPolicy:
428 (RTCCandidateNetworkPolicy)policy {
429 switch (policy) {
430 case RTCCandidateNetworkPolicyAll:
431 return @"CANDIDATE_ALL_NETWORKS";
432 case RTCCandidateNetworkPolicyLowCost:
433 return @"CANDIDATE_LOW_COST_NETWORKS";
434 }
435}
436
Honghai Zhang3108fc92016-05-11 10:10:39 -0700437+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
438 nativeContinualGatheringPolicyForPolicy:
439 (RTCContinualGatheringPolicy)policy {
440 switch (policy) {
441 case RTCContinualGatheringPolicyGatherOnce:
442 return webrtc::PeerConnectionInterface::GATHER_ONCE;
443 case RTCContinualGatheringPolicyGatherContinually:
444 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
445 }
446}
447
448+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
449 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
450 switch (nativePolicy) {
451 case webrtc::PeerConnectionInterface::GATHER_ONCE:
452 return RTCContinualGatheringPolicyGatherOnce;
453 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
454 return RTCContinualGatheringPolicyGatherContinually;
455 }
456}
457
458+ (NSString *)stringForContinualGatheringPolicy:
459 (RTCContinualGatheringPolicy)policy {
460 switch (policy) {
461 case RTCContinualGatheringPolicyGatherOnce:
462 return @"GATHER_ONCE";
463 case RTCContinualGatheringPolicyGatherContinually:
464 return @"GATHER_CONTINUALLY";
465 }
466}
467
hbosf9da44d2016-06-09 03:18:28 -0700468+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
469 (RTCEncryptionKeyType)keyType {
470 switch (keyType) {
471 case RTCEncryptionKeyTypeRSA:
472 return rtc::KT_RSA;
473 case RTCEncryptionKeyTypeECDSA:
474 return rtc::KT_ECDSA;
475 }
476}
477
Steve Anton8cb344a2018-02-27 15:34:53 -0800478+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
479 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800480 case RTCSdpSemanticsPlanB:
481 return webrtc::SdpSemantics::kPlanB;
482 case RTCSdpSemanticsUnifiedPlan:
483 return webrtc::SdpSemantics::kUnifiedPlan;
484 }
485}
486
487+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
488 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800489 case webrtc::SdpSemantics::kPlanB:
490 return RTCSdpSemanticsPlanB;
491 case webrtc::SdpSemantics::kUnifiedPlan:
492 return RTCSdpSemanticsUnifiedPlan;
493 }
494}
495
496+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
497 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800498 case RTCSdpSemanticsPlanB:
499 return @"PLAN_B";
500 case RTCSdpSemanticsUnifiedPlan:
501 return @"UNIFIED_PLAN";
502 }
503}
504
hjon6d49a8e2016-01-26 13:06:42 -0800505@end