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