hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCConfiguration+Private.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 12 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 15 | #import "RTCIceServer+Private.h" |
| 16 | #import "WebRTC/RTCLogging.h" |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 17 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 18 | #include "webrtc/base/sslidentity.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 19 | |
| 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 Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 27 | @synthesize continualGatheringPolicy = _continualGatheringPolicy; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 28 | @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; |
| 29 | @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; |
| 30 | @synthesize iceBackupCandidatePairPingInterval = |
| 31 | _iceBackupCandidatePairPingInterval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 32 | @synthesize keyType = _keyType; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 33 | |
| 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 Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 47 | webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy = |
| 48 | config.continual_gathering_policy; |
| 49 | _continualGatheringPolicy = |
| 50 | [[self class] continualGatheringPolicyForNativePolicy:nativePolicy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 51 | _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; |
| 52 | _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; |
| 53 | _iceBackupCandidatePairPingInterval = |
| 54 | config.ice_backup_candidate_pair_ping_interval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 55 | _keyType = RTCEncryptionKeyTypeECDSA; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 56 | } |
| 57 | return self; |
| 58 | } |
| 59 | |
| 60 | - (NSString *)description { |
| 61 | return [NSString stringWithFormat: |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 62 | @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n", |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 63 | _iceServers, |
| 64 | [[self class] stringForTransportPolicy:_iceTransportPolicy], |
| 65 | [[self class] stringForBundlePolicy:_bundlePolicy], |
| 66 | [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], |
| 67 | [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 68 | [[self class] |
| 69 | stringForContinualGatheringPolicy:_continualGatheringPolicy], |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 70 | _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) { |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 81 | nativeConfig.servers.push_back(iceServer.nativeServer); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 82 | } |
| 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 Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 91 | nativeConfig.continual_gathering_policy = [[self class] |
| 92 | nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 93 | 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; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 98 | if (_keyType == RTCEncryptionKeyTypeECDSA) { |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 99 | std::unique_ptr<rtc::SSLIdentity> identity( |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 100 | 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 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 108 | |
| 109 | return nativeConfig; |
| 110 | } |
| 111 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 112 | + (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 Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 246 | + (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 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 277 | @end |