blob: c2ff8bf17a03458342e87793fe5ef26dae68f6f1 [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;
Qingsi Wang1fe119f2019-05-31 16:55:33 -070048@synthesize shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
49 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged;
skvlada5d94ff2017-02-02 13:02:30 -080050@synthesize iceCheckMinInterval = _iceCheckMinInterval;
Steve Antond295e402017-07-14 16:06:41 -070051@synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange;
Steve Anton8cb344a2018-02-27 15:34:53 -080052@synthesize sdpSemantics = _sdpSemantics;
Zeke Chinef1140e2017-10-27 15:42:08 -070053@synthesize turnCustomizer = _turnCustomizer;
Zhi Huangb57e1692018-06-12 11:41:11 -070054@synthesize activeResetSrtpParams = _activeResetSrtpParams;
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070055@synthesize useMediaTransport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -070056@synthesize useMediaTransportForDataChannels = _useMediaTransportForDataChannels;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070057@synthesize cryptoOptions = _cryptoOptions;
Jiawei Oub1e47752018-11-13 23:48:19 -080058@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
59@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
hjon6d49a8e2016-01-26 13:06:42 -080060
61- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070062 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020063 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070064 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070065}
66
67- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070068 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080069 if (self = [super init]) {
jtteh4eeb5372017-04-03 15:06:37 -070070 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070071 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
jtteh4eeb5372017-04-03 15:06:37 -070072 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
73 [iceServers addObject:iceServer];
74 }
75 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020076 if (!config.certificates.empty()) {
77 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
78 native_cert = config.certificates[0];
79 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
80 _certificate =
81 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
82 certificate:@(native_pem.certificate().c_str())];
83 }
hjon6d49a8e2016-01-26 13:06:42 -080084 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070085 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080086 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070087 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080088 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070089 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080090 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070091 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070092 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070093 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070094 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070095 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070096 _continualGatheringPolicy =
97 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030098 _disableIPV6 = config.disable_ipv6;
99 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700100 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100101 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700102 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
103 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
104 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800105 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700106 config.ice_backup_candidate_pair_ping_interval;
Piotr (Peter) Slatala693432d2018-10-30 16:52:06 -0700107 _useMediaTransport = config.use_media_transport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700108 _useMediaTransportForDataChannels = config.use_media_transport_for_data_channels;
tkchinab8f82f2016-01-27 17:50:11 -0800109 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700110 _iceCandidatePoolSize = config.ice_candidate_pool_size;
111 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700112 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700113 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700114 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
115 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700116 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800117 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700118 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800119 }
Steve Antond295e402017-07-14 16:06:41 -0700120 if (config.ice_regather_interval_range) {
121 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
122 _iceRegatherIntervalRange =
123 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
124 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800125 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700126 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700127 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700128 if (config.crypto_options) {
129 _cryptoOptions = [[RTCCryptoOptions alloc]
130 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
131 .enable_gcm_crypto_suites
132 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
133 .enable_aes128_sha1_32_crypto_cipher
134 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
135 .enable_encrypted_rtp_header_extensions
136 sframeRequireFrameEncryption:config.crypto_options->sframe
137 .require_frame_encryption];
138 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800139 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
140 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
hjon6d49a8e2016-01-26 13:06:42 -0800141 }
142 return self;
143}
144
145- (NSString *)description {
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300146 static NSString *formatString = @"RTCConfiguration: "
147 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
148 @"%d\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100149
Steve Anton8cb344a2018-02-27 15:34:53 -0800150 return [NSString
151 stringWithFormat:formatString,
152 _iceServers,
153 [[self class] stringForTransportPolicy:_iceTransportPolicy],
154 [[self class] stringForBundlePolicy:_bundlePolicy],
155 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
156 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
157 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
158 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
159 [[self class] stringForSdpSemantics:_sdpSemantics],
160 _audioJitterBufferMaxPackets,
161 _audioJitterBufferFastAccelerate,
162 _iceConnectionReceivingTimeout,
163 _iceBackupCandidatePairPingInterval,
164 _iceCandidatePoolSize,
165 _shouldPruneTurnPorts,
166 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700167 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800168 _iceCheckMinInterval,
169 _iceRegatherIntervalRange,
170 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300171 _disableIPV6,
172 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700173 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700174 _activeResetSrtpParams,
175 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800176}
177
178#pragma mark - Private
179
hbosa73ca562016-05-17 03:28:58 -0700180- (webrtc::PeerConnectionInterface::RTCConfiguration *)
181 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200182 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700183 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
184 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800185
186 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200187 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800188 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800190 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800192 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800194 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200195 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800196 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700197 nativeConfig->candidate_network_policy = [[self class]
198 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200199 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700200 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300201 nativeConfig->disable_ipv6 = _disableIPV6;
202 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700203 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100204 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200205 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800206 nativeConfig->audio_jitter_buffer_fast_accelerate =
207 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200208 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800209 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200210 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800211 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700212 nativeConfig->use_media_transport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700213 nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200214 rtc::KeyType keyType =
215 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200216 if (_certificate != nullptr) {
217 // if offered a pemcert use it...
218 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
219 std::string pem_private_key = [[_certificate private_key] UTF8String];
220 std::string pem_certificate = [[_certificate certificate] UTF8String];
221 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
222 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
223 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200224 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200225 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200226 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800227 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200228 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200229 } else {
230 RTC_LOG(LS_INFO) << "Don't have configured cert.";
231 // Generate non-default certificate.
232 if (keyType != rtc::KT_DEFAULT) {
233 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
234 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
235 absl::optional<uint64_t>());
236 if (!certificate) {
237 RTCLogError(@"Failed to generate certificate.");
238 return nullptr;
239 }
240 nativeConfig->certificates.push_back(certificate);
241 }
tkchinab8f82f2016-01-27 17:50:11 -0800242 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700243 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700244 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700245 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700246 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700247 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
248 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800249 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200250 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800251 }
Steve Antond295e402017-07-14 16:06:41 -0700252 if (_iceRegatherIntervalRange != nil) {
253 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
254 _iceRegatherIntervalRange.nativeIntervalRange);
255 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200256 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700257 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800258 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700259 if (_turnCustomizer) {
260 nativeConfig->turn_customizer = _turnCustomizer;
261 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700262 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700263 if (_cryptoOptions) {
264 webrtc::CryptoOptions nativeCryptoOptions;
265 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
266 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
267 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
268 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
269 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
270 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
271 nativeCryptoOptions.sframe.require_frame_encryption =
272 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
273 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
274 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800275 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
276 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200277 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800278}
279
hjon6d49a8e2016-01-26 13:06:42 -0800280+ (webrtc::PeerConnectionInterface::IceTransportsType)
281 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
282 switch (policy) {
283 case RTCIceTransportPolicyNone:
284 return webrtc::PeerConnectionInterface::kNone;
285 case RTCIceTransportPolicyRelay:
286 return webrtc::PeerConnectionInterface::kRelay;
287 case RTCIceTransportPolicyNoHost:
288 return webrtc::PeerConnectionInterface::kNoHost;
289 case RTCIceTransportPolicyAll:
290 return webrtc::PeerConnectionInterface::kAll;
291 }
292}
293
294+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
295 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
296 switch (nativeType) {
297 case webrtc::PeerConnectionInterface::kNone:
298 return RTCIceTransportPolicyNone;
299 case webrtc::PeerConnectionInterface::kRelay:
300 return RTCIceTransportPolicyRelay;
301 case webrtc::PeerConnectionInterface::kNoHost:
302 return RTCIceTransportPolicyNoHost;
303 case webrtc::PeerConnectionInterface::kAll:
304 return RTCIceTransportPolicyAll;
305 }
306}
307
308+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
309 switch (policy) {
310 case RTCIceTransportPolicyNone:
311 return @"NONE";
312 case RTCIceTransportPolicyRelay:
313 return @"RELAY";
314 case RTCIceTransportPolicyNoHost:
315 return @"NO_HOST";
316 case RTCIceTransportPolicyAll:
317 return @"ALL";
318 }
319}
320
321+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
322 (RTCBundlePolicy)policy {
323 switch (policy) {
324 case RTCBundlePolicyBalanced:
325 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
326 case RTCBundlePolicyMaxCompat:
327 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
328 case RTCBundlePolicyMaxBundle:
329 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
330 }
331}
332
333+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
334 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
335 switch (nativePolicy) {
336 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
337 return RTCBundlePolicyBalanced;
338 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
339 return RTCBundlePolicyMaxCompat;
340 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
341 return RTCBundlePolicyMaxBundle;
342 }
343}
344
345+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
346 switch (policy) {
347 case RTCBundlePolicyBalanced:
348 return @"BALANCED";
349 case RTCBundlePolicyMaxCompat:
350 return @"MAX_COMPAT";
351 case RTCBundlePolicyMaxBundle:
352 return @"MAX_BUNDLE";
353 }
354}
355
356+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
357 (RTCRtcpMuxPolicy)policy {
358 switch (policy) {
359 case RTCRtcpMuxPolicyNegotiate:
360 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
361 case RTCRtcpMuxPolicyRequire:
362 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
363 }
364}
365
366+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
367 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
368 switch (nativePolicy) {
369 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
370 return RTCRtcpMuxPolicyNegotiate;
371 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
372 return RTCRtcpMuxPolicyRequire;
373 }
374}
375
376+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
377 switch (policy) {
378 case RTCRtcpMuxPolicyNegotiate:
379 return @"NEGOTIATE";
380 case RTCRtcpMuxPolicyRequire:
381 return @"REQUIRE";
382 }
383}
384
385+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
386 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
387 switch (policy) {
388 case RTCTcpCandidatePolicyEnabled:
389 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
390 case RTCTcpCandidatePolicyDisabled:
391 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
392 }
393}
394
Honghai Zhang46007ae2016-06-03 16:31:32 -0700395+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
396 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
397 switch (policy) {
398 case RTCCandidateNetworkPolicyAll:
399 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
400 case RTCCandidateNetworkPolicyLowCost:
401 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
402 }
403}
404
hjon6d49a8e2016-01-26 13:06:42 -0800405+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
406 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
407 switch (nativePolicy) {
408 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
409 return RTCTcpCandidatePolicyEnabled;
410 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
411 return RTCTcpCandidatePolicyDisabled;
412 }
413}
414
415+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
416 switch (policy) {
417 case RTCTcpCandidatePolicyEnabled:
418 return @"TCP_ENABLED";
419 case RTCTcpCandidatePolicyDisabled:
420 return @"TCP_DISABLED";
421 }
422}
423
Honghai Zhang46007ae2016-06-03 16:31:32 -0700424+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
425 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
426 switch (nativePolicy) {
427 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
428 return RTCCandidateNetworkPolicyAll;
429 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
430 return RTCCandidateNetworkPolicyLowCost;
431 }
432}
433
434+ (NSString *)stringForCandidateNetworkPolicy:
435 (RTCCandidateNetworkPolicy)policy {
436 switch (policy) {
437 case RTCCandidateNetworkPolicyAll:
438 return @"CANDIDATE_ALL_NETWORKS";
439 case RTCCandidateNetworkPolicyLowCost:
440 return @"CANDIDATE_LOW_COST_NETWORKS";
441 }
442}
443
Honghai Zhang3108fc92016-05-11 10:10:39 -0700444+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
445 nativeContinualGatheringPolicyForPolicy:
446 (RTCContinualGatheringPolicy)policy {
447 switch (policy) {
448 case RTCContinualGatheringPolicyGatherOnce:
449 return webrtc::PeerConnectionInterface::GATHER_ONCE;
450 case RTCContinualGatheringPolicyGatherContinually:
451 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
452 }
453}
454
455+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
456 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
457 switch (nativePolicy) {
458 case webrtc::PeerConnectionInterface::GATHER_ONCE:
459 return RTCContinualGatheringPolicyGatherOnce;
460 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
461 return RTCContinualGatheringPolicyGatherContinually;
462 }
463}
464
465+ (NSString *)stringForContinualGatheringPolicy:
466 (RTCContinualGatheringPolicy)policy {
467 switch (policy) {
468 case RTCContinualGatheringPolicyGatherOnce:
469 return @"GATHER_ONCE";
470 case RTCContinualGatheringPolicyGatherContinually:
471 return @"GATHER_CONTINUALLY";
472 }
473}
474
hbosf9da44d2016-06-09 03:18:28 -0700475+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
476 (RTCEncryptionKeyType)keyType {
477 switch (keyType) {
478 case RTCEncryptionKeyTypeRSA:
479 return rtc::KT_RSA;
480 case RTCEncryptionKeyTypeECDSA:
481 return rtc::KT_ECDSA;
482 }
483}
484
Steve Anton8cb344a2018-02-27 15:34:53 -0800485+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
486 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800487 case RTCSdpSemanticsPlanB:
488 return webrtc::SdpSemantics::kPlanB;
489 case RTCSdpSemanticsUnifiedPlan:
490 return webrtc::SdpSemantics::kUnifiedPlan;
491 }
492}
493
494+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
495 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800496 case webrtc::SdpSemantics::kPlanB:
497 return RTCSdpSemanticsPlanB;
498 case webrtc::SdpSemantics::kUnifiedPlan:
499 return RTCSdpSemanticsUnifiedPlan;
500 }
501}
502
503+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
504 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800505 case RTCSdpSemanticsPlanB:
506 return @"PLAN_B";
507 case RTCSdpSemanticsUnifiedPlan:
508 return @"UNIFIED_PLAN";
509 }
510}
511
hjon6d49a8e2016-01-26 13:06:42 -0800512@end