blob: b006319cae43ae81e1556cd9035b9051b1a16b62 [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;
27@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
28@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
29@synthesize iceBackupCandidatePairPingInterval =
30 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080031@synthesize keyType = _keyType;
hjon6d49a8e2016-01-26 13:06:42 -080032
33- (instancetype)init {
34 if (self = [super init]) {
35 _iceServers = [NSMutableArray array];
36 // Copy defaults.
37 webrtc::PeerConnectionInterface::RTCConfiguration config;
38 _iceTransportPolicy =
39 [[self class] transportPolicyForTransportsType:config.type];
40 _bundlePolicy =
41 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
42 _rtcpMuxPolicy =
43 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
44 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
45 config.tcp_candidate_policy];
46 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
47 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
48 _iceBackupCandidatePairPingInterval =
49 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -080050 _keyType = RTCEncryptionKeyTypeECDSA;
hjon6d49a8e2016-01-26 13:06:42 -080051 }
52 return self;
53}
54
55- (NSString *)description {
56 return [NSString stringWithFormat:
57 @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n",
58 _iceServers,
59 [[self class] stringForTransportPolicy:_iceTransportPolicy],
60 [[self class] stringForBundlePolicy:_bundlePolicy],
61 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
62 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
63 _audioJitterBufferMaxPackets,
64 _iceConnectionReceivingTimeout,
65 _iceBackupCandidatePairPingInterval];
66}
67
68#pragma mark - Private
69
70- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration {
71 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
72
73 for (RTCIceServer *iceServer in _iceServers) {
hjona2f77982016-03-04 07:09:09 -080074 nativeConfig.servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -080075 }
76 nativeConfig.type =
77 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
78 nativeConfig.bundle_policy =
79 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
80 nativeConfig.rtcp_mux_policy =
81 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
82 nativeConfig.tcp_candidate_policy =
83 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
84 nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
85 nativeConfig.ice_connection_receiving_timeout =
86 _iceConnectionReceivingTimeout;
87 nativeConfig.ice_backup_candidate_pair_ping_interval =
88 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080089 if (_keyType == RTCEncryptionKeyTypeECDSA) {
jbauch555604a2016-04-26 03:13:22 -070090 std::unique_ptr<rtc::SSLIdentity> identity(
tkchinab8f82f2016-01-27 17:50:11 -080091 rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA));
92 if (identity) {
93 nativeConfig.certificates.push_back(
94 rtc::RTCCertificate::Create(std::move(identity)));
95 } else {
96 RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used.");
97 }
98 }
hjon6d49a8e2016-01-26 13:06:42 -080099
100 return nativeConfig;
101}
102
hjon6d49a8e2016-01-26 13:06:42 -0800103+ (webrtc::PeerConnectionInterface::IceTransportsType)
104 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
105 switch (policy) {
106 case RTCIceTransportPolicyNone:
107 return webrtc::PeerConnectionInterface::kNone;
108 case RTCIceTransportPolicyRelay:
109 return webrtc::PeerConnectionInterface::kRelay;
110 case RTCIceTransportPolicyNoHost:
111 return webrtc::PeerConnectionInterface::kNoHost;
112 case RTCIceTransportPolicyAll:
113 return webrtc::PeerConnectionInterface::kAll;
114 }
115}
116
117+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
118 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
119 switch (nativeType) {
120 case webrtc::PeerConnectionInterface::kNone:
121 return RTCIceTransportPolicyNone;
122 case webrtc::PeerConnectionInterface::kRelay:
123 return RTCIceTransportPolicyRelay;
124 case webrtc::PeerConnectionInterface::kNoHost:
125 return RTCIceTransportPolicyNoHost;
126 case webrtc::PeerConnectionInterface::kAll:
127 return RTCIceTransportPolicyAll;
128 }
129}
130
131+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
132 switch (policy) {
133 case RTCIceTransportPolicyNone:
134 return @"NONE";
135 case RTCIceTransportPolicyRelay:
136 return @"RELAY";
137 case RTCIceTransportPolicyNoHost:
138 return @"NO_HOST";
139 case RTCIceTransportPolicyAll:
140 return @"ALL";
141 }
142}
143
144+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
145 (RTCBundlePolicy)policy {
146 switch (policy) {
147 case RTCBundlePolicyBalanced:
148 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
149 case RTCBundlePolicyMaxCompat:
150 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
151 case RTCBundlePolicyMaxBundle:
152 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
153 }
154}
155
156+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
157 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
158 switch (nativePolicy) {
159 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
160 return RTCBundlePolicyBalanced;
161 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
162 return RTCBundlePolicyMaxCompat;
163 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
164 return RTCBundlePolicyMaxBundle;
165 }
166}
167
168+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
169 switch (policy) {
170 case RTCBundlePolicyBalanced:
171 return @"BALANCED";
172 case RTCBundlePolicyMaxCompat:
173 return @"MAX_COMPAT";
174 case RTCBundlePolicyMaxBundle:
175 return @"MAX_BUNDLE";
176 }
177}
178
179+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
180 (RTCRtcpMuxPolicy)policy {
181 switch (policy) {
182 case RTCRtcpMuxPolicyNegotiate:
183 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
184 case RTCRtcpMuxPolicyRequire:
185 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
186 }
187}
188
189+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
190 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
191 switch (nativePolicy) {
192 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
193 return RTCRtcpMuxPolicyNegotiate;
194 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
195 return RTCRtcpMuxPolicyRequire;
196 }
197}
198
199+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
200 switch (policy) {
201 case RTCRtcpMuxPolicyNegotiate:
202 return @"NEGOTIATE";
203 case RTCRtcpMuxPolicyRequire:
204 return @"REQUIRE";
205 }
206}
207
208+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
209 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
210 switch (policy) {
211 case RTCTcpCandidatePolicyEnabled:
212 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
213 case RTCTcpCandidatePolicyDisabled:
214 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
215 }
216}
217
218+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
219 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
220 switch (nativePolicy) {
221 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
222 return RTCTcpCandidatePolicyEnabled;
223 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
224 return RTCTcpCandidatePolicyDisabled;
225 }
226}
227
228+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
229 switch (policy) {
230 case RTCTcpCandidatePolicyEnabled:
231 return @"TCP_ENABLED";
232 case RTCTcpCandidatePolicyDisabled:
233 return @"TCP_DISABLED";
234 }
235}
236
237@end