blob: 0bb85a29b6d937fb8d5f2fc8be77cb401bed079d [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
tkchin9eeb6242016-04-27 01:54:20 -070015#import "RTCIceServer+Private.h"
16#import "WebRTC/RTCLogging.h"
tkchinab8f82f2016-01-27 17:50:11 -080017
tkchin9eeb6242016-04-27 01:54:20 -070018#include "webrtc/base/sslidentity.h"
hjon6d49a8e2016-01-26 13:06:42 -080019
20@implementation RTCConfiguration
21
22@synthesize iceServers = _iceServers;
23@synthesize iceTransportPolicy = _iceTransportPolicy;
24@synthesize bundlePolicy = _bundlePolicy;
25@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
26@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070027@synthesize continualGatheringPolicy = _continualGatheringPolicy;
hjon6d49a8e2016-01-26 13:06:42 -080028@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
29@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
30@synthesize iceBackupCandidatePairPingInterval =
31 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080032@synthesize keyType = _keyType;
hjon6d49a8e2016-01-26 13:06:42 -080033
34- (instancetype)init {
35 if (self = [super init]) {
36 _iceServers = [NSMutableArray array];
37 // Copy defaults.
38 webrtc::PeerConnectionInterface::RTCConfiguration config;
39 _iceTransportPolicy =
40 [[self class] transportPolicyForTransportsType:config.type];
41 _bundlePolicy =
42 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
43 _rtcpMuxPolicy =
44 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
45 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
46 config.tcp_candidate_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070047 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
48 config.continual_gathering_policy;
49 _continualGatheringPolicy =
50 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
hjon6d49a8e2016-01-26 13:06:42 -080051 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
52 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
53 _iceBackupCandidatePairPingInterval =
54 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -080055 _keyType = RTCEncryptionKeyTypeECDSA;
hjon6d49a8e2016-01-26 13:06:42 -080056 }
57 return self;
58}
59
60- (NSString *)description {
61 return [NSString stringWithFormat:
Honghai Zhang3108fc92016-05-11 10:10:39 -070062 @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n",
hjon6d49a8e2016-01-26 13:06:42 -080063 _iceServers,
64 [[self class] stringForTransportPolicy:_iceTransportPolicy],
65 [[self class] stringForBundlePolicy:_bundlePolicy],
66 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
67 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
Honghai Zhang3108fc92016-05-11 10:10:39 -070068 [[self class]
69 stringForContinualGatheringPolicy:_continualGatheringPolicy],
hjon6d49a8e2016-01-26 13:06:42 -080070 _audioJitterBufferMaxPackets,
71 _iceConnectionReceivingTimeout,
72 _iceBackupCandidatePairPingInterval];
73}
74
75#pragma mark - Private
76
77- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration {
78 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
79
80 for (RTCIceServer *iceServer in _iceServers) {
hjona2f77982016-03-04 07:09:09 -080081 nativeConfig.servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -080082 }
83 nativeConfig.type =
84 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
85 nativeConfig.bundle_policy =
86 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
87 nativeConfig.rtcp_mux_policy =
88 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
89 nativeConfig.tcp_candidate_policy =
90 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070091 nativeConfig.continual_gathering_policy = [[self class]
92 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
hjon6d49a8e2016-01-26 13:06:42 -080093 nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
94 nativeConfig.ice_connection_receiving_timeout =
95 _iceConnectionReceivingTimeout;
96 nativeConfig.ice_backup_candidate_pair_ping_interval =
97 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080098 if (_keyType == RTCEncryptionKeyTypeECDSA) {
jbauch555604a2016-04-26 03:13:22 -070099 std::unique_ptr<rtc::SSLIdentity> identity(
tkchinab8f82f2016-01-27 17:50:11 -0800100 rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA));
101 if (identity) {
102 nativeConfig.certificates.push_back(
103 rtc::RTCCertificate::Create(std::move(identity)));
104 } else {
105 RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used.");
106 }
107 }
hjon6d49a8e2016-01-26 13:06:42 -0800108
109 return nativeConfig;
110}
111
hjon6d49a8e2016-01-26 13:06:42 -0800112+ (webrtc::PeerConnectionInterface::IceTransportsType)
113 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
114 switch (policy) {
115 case RTCIceTransportPolicyNone:
116 return webrtc::PeerConnectionInterface::kNone;
117 case RTCIceTransportPolicyRelay:
118 return webrtc::PeerConnectionInterface::kRelay;
119 case RTCIceTransportPolicyNoHost:
120 return webrtc::PeerConnectionInterface::kNoHost;
121 case RTCIceTransportPolicyAll:
122 return webrtc::PeerConnectionInterface::kAll;
123 }
124}
125
126+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
127 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
128 switch (nativeType) {
129 case webrtc::PeerConnectionInterface::kNone:
130 return RTCIceTransportPolicyNone;
131 case webrtc::PeerConnectionInterface::kRelay:
132 return RTCIceTransportPolicyRelay;
133 case webrtc::PeerConnectionInterface::kNoHost:
134 return RTCIceTransportPolicyNoHost;
135 case webrtc::PeerConnectionInterface::kAll:
136 return RTCIceTransportPolicyAll;
137 }
138}
139
140+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
141 switch (policy) {
142 case RTCIceTransportPolicyNone:
143 return @"NONE";
144 case RTCIceTransportPolicyRelay:
145 return @"RELAY";
146 case RTCIceTransportPolicyNoHost:
147 return @"NO_HOST";
148 case RTCIceTransportPolicyAll:
149 return @"ALL";
150 }
151}
152
153+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
154 (RTCBundlePolicy)policy {
155 switch (policy) {
156 case RTCBundlePolicyBalanced:
157 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
158 case RTCBundlePolicyMaxCompat:
159 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
160 case RTCBundlePolicyMaxBundle:
161 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
162 }
163}
164
165+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
166 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
167 switch (nativePolicy) {
168 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
169 return RTCBundlePolicyBalanced;
170 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
171 return RTCBundlePolicyMaxCompat;
172 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
173 return RTCBundlePolicyMaxBundle;
174 }
175}
176
177+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
178 switch (policy) {
179 case RTCBundlePolicyBalanced:
180 return @"BALANCED";
181 case RTCBundlePolicyMaxCompat:
182 return @"MAX_COMPAT";
183 case RTCBundlePolicyMaxBundle:
184 return @"MAX_BUNDLE";
185 }
186}
187
188+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
189 (RTCRtcpMuxPolicy)policy {
190 switch (policy) {
191 case RTCRtcpMuxPolicyNegotiate:
192 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
193 case RTCRtcpMuxPolicyRequire:
194 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
195 }
196}
197
198+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
199 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
200 switch (nativePolicy) {
201 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
202 return RTCRtcpMuxPolicyNegotiate;
203 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
204 return RTCRtcpMuxPolicyRequire;
205 }
206}
207
208+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
209 switch (policy) {
210 case RTCRtcpMuxPolicyNegotiate:
211 return @"NEGOTIATE";
212 case RTCRtcpMuxPolicyRequire:
213 return @"REQUIRE";
214 }
215}
216
217+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
218 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
219 switch (policy) {
220 case RTCTcpCandidatePolicyEnabled:
221 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
222 case RTCTcpCandidatePolicyDisabled:
223 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
224 }
225}
226
227+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
228 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
229 switch (nativePolicy) {
230 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
231 return RTCTcpCandidatePolicyEnabled;
232 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
233 return RTCTcpCandidatePolicyDisabled;
234 }
235}
236
237+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
238 switch (policy) {
239 case RTCTcpCandidatePolicyEnabled:
240 return @"TCP_ENABLED";
241 case RTCTcpCandidatePolicyDisabled:
242 return @"TCP_DISABLED";
243 }
244}
245
Honghai Zhang3108fc92016-05-11 10:10:39 -0700246+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
247 nativeContinualGatheringPolicyForPolicy:
248 (RTCContinualGatheringPolicy)policy {
249 switch (policy) {
250 case RTCContinualGatheringPolicyGatherOnce:
251 return webrtc::PeerConnectionInterface::GATHER_ONCE;
252 case RTCContinualGatheringPolicyGatherContinually:
253 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
254 }
255}
256
257+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
258 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
259 switch (nativePolicy) {
260 case webrtc::PeerConnectionInterface::GATHER_ONCE:
261 return RTCContinualGatheringPolicyGatherOnce;
262 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
263 return RTCContinualGatheringPolicyGatherContinually;
264 }
265}
266
267+ (NSString *)stringForContinualGatheringPolicy:
268 (RTCContinualGatheringPolicy)policy {
269 switch (policy) {
270 case RTCContinualGatheringPolicyGatherOnce:
271 return @"GATHER_ONCE";
272 case RTCContinualGatheringPolicyGatherContinually:
273 return @"GATHER_CONTINUALLY";
274 }
275}
276
hjon6d49a8e2016-01-26 13:06:42 -0800277@end