You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

512 lines
21 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "RTCConfiguration+Private.h"
  11. #include <memory>
  12. #import "RTCCertificate.h"
  13. #import "RTCConfiguration+Native.h"
  14. #import "RTCIceServer+Private.h"
  15. #import "RTCIntervalRange+Private.h"
  16. #import "base/RTCLogging.h"
  17. #include "rtc_base/rtc_certificate_generator.h"
  18. #include "rtc_base/ssl_identity.h"
  19. @implementation RTCConfiguration
  20. @synthesize iceServers = _iceServers;
  21. @synthesize certificate = _certificate;
  22. @synthesize iceTransportPolicy = _iceTransportPolicy;
  23. @synthesize bundlePolicy = _bundlePolicy;
  24. @synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
  25. @synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
  26. @synthesize candidateNetworkPolicy = _candidateNetworkPolicy;
  27. @synthesize continualGatheringPolicy = _continualGatheringPolicy;
  28. @synthesize disableIPV6 = _disableIPV6;
  29. @synthesize disableIPV6OnWiFi = _disableIPV6OnWiFi;
  30. @synthesize maxIPv6Networks = _maxIPv6Networks;
  31. @synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks;
  32. @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
  33. @synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
  34. @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
  35. @synthesize iceBackupCandidatePairPingInterval =
  36. _iceBackupCandidatePairPingInterval;
  37. @synthesize keyType = _keyType;
  38. @synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
  39. @synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
  40. @synthesize shouldPresumeWritableWhenFullyRelayed =
  41. _shouldPresumeWritableWhenFullyRelayed;
  42. @synthesize shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
  43. _shouldSurfaceIceCandidatesOnIceTransportTypeChanged;
  44. @synthesize iceCheckMinInterval = _iceCheckMinInterval;
  45. @synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange;
  46. @synthesize sdpSemantics = _sdpSemantics;
  47. @synthesize turnCustomizer = _turnCustomizer;
  48. @synthesize activeResetSrtpParams = _activeResetSrtpParams;
  49. @synthesize useMediaTransport = _useMediaTransport;
  50. @synthesize useMediaTransportForDataChannels = _useMediaTransportForDataChannels;
  51. @synthesize cryptoOptions = _cryptoOptions;
  52. @synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
  53. @synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
  54. - (instancetype)init {
  55. // Copy defaults.
  56. webrtc::PeerConnectionInterface::RTCConfiguration config;
  57. return [self initWithNativeConfiguration:config];
  58. }
  59. - (instancetype)initWithNativeConfiguration:
  60. (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
  61. if (self = [super init]) {
  62. NSMutableArray *iceServers = [NSMutableArray array];
  63. for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
  64. RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
  65. [iceServers addObject:iceServer];
  66. }
  67. _iceServers = iceServers;
  68. if (!config.certificates.empty()) {
  69. rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
  70. native_cert = config.certificates[0];
  71. rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
  72. _certificate =
  73. [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
  74. certificate:@(native_pem.certificate().c_str())];
  75. }
  76. _iceTransportPolicy =
  77. [[self class] transportPolicyForTransportsType:config.type];
  78. _bundlePolicy =
  79. [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
  80. _rtcpMuxPolicy =
  81. [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
  82. _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
  83. config.tcp_candidate_policy];
  84. _candidateNetworkPolicy = [[self class]
  85. candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
  86. webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
  87. config.continual_gathering_policy;
  88. _continualGatheringPolicy =
  89. [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
  90. _disableIPV6 = config.disable_ipv6;
  91. _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
  92. _maxIPv6Networks = config.max_ipv6_networks;
  93. _disableLinkLocalNetworks = config.disable_link_local_networks;
  94. _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
  95. _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
  96. _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
  97. _iceBackupCandidatePairPingInterval =
  98. config.ice_backup_candidate_pair_ping_interval;
  99. _useMediaTransport = config.use_media_transport;
  100. _useMediaTransportForDataChannels = config.use_media_transport_for_data_channels;
  101. _keyType = RTCEncryptionKeyTypeECDSA;
  102. _iceCandidatePoolSize = config.ice_candidate_pool_size;
  103. _shouldPruneTurnPorts = config.prune_turn_ports;
  104. _shouldPresumeWritableWhenFullyRelayed =
  105. config.presume_writable_when_fully_relayed;
  106. _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
  107. config.surface_ice_candidates_on_ice_transport_type_changed;
  108. if (config.ice_check_min_interval) {
  109. _iceCheckMinInterval =
  110. [NSNumber numberWithInt:*config.ice_check_min_interval];
  111. }
  112. if (config.ice_regather_interval_range) {
  113. const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
  114. _iceRegatherIntervalRange =
  115. [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
  116. }
  117. _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
  118. _turnCustomizer = config.turn_customizer;
  119. _activeResetSrtpParams = config.active_reset_srtp_params;
  120. if (config.crypto_options) {
  121. _cryptoOptions = [[RTCCryptoOptions alloc]
  122. initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
  123. .enable_gcm_crypto_suites
  124. srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
  125. .enable_aes128_sha1_32_crypto_cipher
  126. srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
  127. .enable_encrypted_rtp_header_extensions
  128. sframeRequireFrameEncryption:config.crypto_options->sframe
  129. .require_frame_encryption];
  130. }
  131. _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
  132. _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
  133. }
  134. return self;
  135. }
  136. - (NSString *)description {
  137. static NSString *formatString = @"RTCConfiguration: "
  138. @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
  139. @"%d\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
  140. return [NSString
  141. stringWithFormat:formatString,
  142. _iceServers,
  143. [[self class] stringForTransportPolicy:_iceTransportPolicy],
  144. [[self class] stringForBundlePolicy:_bundlePolicy],
  145. [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
  146. [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
  147. [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
  148. [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
  149. [[self class] stringForSdpSemantics:_sdpSemantics],
  150. _audioJitterBufferMaxPackets,
  151. _audioJitterBufferFastAccelerate,
  152. _iceConnectionReceivingTimeout,
  153. _iceBackupCandidatePairPingInterval,
  154. _iceCandidatePoolSize,
  155. _shouldPruneTurnPorts,
  156. _shouldPresumeWritableWhenFullyRelayed,
  157. _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
  158. _iceCheckMinInterval,
  159. _iceRegatherIntervalRange,
  160. _disableLinkLocalNetworks,
  161. _disableIPV6,
  162. _disableIPV6OnWiFi,
  163. _maxIPv6Networks,
  164. _activeResetSrtpParams,
  165. _useMediaTransport];
  166. }
  167. #pragma mark - Private
  168. - (webrtc::PeerConnectionInterface::RTCConfiguration *)
  169. createNativeConfiguration {
  170. std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
  171. nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
  172. webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
  173. for (RTCIceServer *iceServer in _iceServers) {
  174. nativeConfig->servers.push_back(iceServer.nativeServer);
  175. }
  176. nativeConfig->type =
  177. [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
  178. nativeConfig->bundle_policy =
  179. [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
  180. nativeConfig->rtcp_mux_policy =
  181. [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
  182. nativeConfig->tcp_candidate_policy =
  183. [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
  184. nativeConfig->candidate_network_policy = [[self class]
  185. nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
  186. nativeConfig->continual_gathering_policy = [[self class]
  187. nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
  188. nativeConfig->disable_ipv6 = _disableIPV6;
  189. nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
  190. nativeConfig->max_ipv6_networks = _maxIPv6Networks;
  191. nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
  192. nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
  193. nativeConfig->audio_jitter_buffer_fast_accelerate =
  194. _audioJitterBufferFastAccelerate ? true : false;
  195. nativeConfig->ice_connection_receiving_timeout =
  196. _iceConnectionReceivingTimeout;
  197. nativeConfig->ice_backup_candidate_pair_ping_interval =
  198. _iceBackupCandidatePairPingInterval;
  199. nativeConfig->use_media_transport = _useMediaTransport;
  200. nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
  201. rtc::KeyType keyType =
  202. [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
  203. if (_certificate != nullptr) {
  204. // if offered a pemcert use it...
  205. RTC_LOG(LS_INFO) << "Have configured cert - using it.";
  206. std::string pem_private_key = [[_certificate private_key] UTF8String];
  207. std::string pem_certificate = [[_certificate certificate] UTF8String];
  208. rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
  209. rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
  210. RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
  211. if (!certificate) {
  212. RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
  213. return nullptr;
  214. }
  215. nativeConfig->certificates.push_back(certificate);
  216. } else {
  217. RTC_LOG(LS_INFO) << "Don't have configured cert.";
  218. // Generate non-default certificate.
  219. if (keyType != rtc::KT_DEFAULT) {
  220. rtc::scoped_refptr<rtc::RTCCertificate> certificate =
  221. rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
  222. absl::optional<uint64_t>());
  223. if (!certificate) {
  224. RTCLogError(@"Failed to generate certificate.");
  225. return nullptr;
  226. }
  227. nativeConfig->certificates.push_back(certificate);
  228. }
  229. }
  230. nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
  231. nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
  232. nativeConfig->presume_writable_when_fully_relayed =
  233. _shouldPresumeWritableWhenFullyRelayed ? true : false;
  234. nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
  235. _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
  236. if (_iceCheckMinInterval != nil) {
  237. nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
  238. }
  239. if (_iceRegatherIntervalRange != nil) {
  240. std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
  241. _iceRegatherIntervalRange.nativeIntervalRange);
  242. nativeConfig->ice_regather_interval_range =
  243. absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
  244. }
  245. nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
  246. if (_turnCustomizer) {
  247. nativeConfig->turn_customizer = _turnCustomizer;
  248. }
  249. nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
  250. if (_cryptoOptions) {
  251. webrtc::CryptoOptions nativeCryptoOptions;
  252. nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
  253. _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
  254. nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
  255. _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
  256. nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
  257. _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
  258. nativeCryptoOptions.sframe.require_frame_encryption =
  259. _cryptoOptions.sframeRequireFrameEncryption ? true : false;
  260. nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
  261. }
  262. nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
  263. nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
  264. return nativeConfig.release();
  265. }
  266. + (webrtc::PeerConnectionInterface::IceTransportsType)
  267. nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
  268. switch (policy) {
  269. case RTCIceTransportPolicyNone:
  270. return webrtc::PeerConnectionInterface::kNone;
  271. case RTCIceTransportPolicyRelay:
  272. return webrtc::PeerConnectionInterface::kRelay;
  273. case RTCIceTransportPolicyNoHost:
  274. return webrtc::PeerConnectionInterface::kNoHost;
  275. case RTCIceTransportPolicyAll:
  276. return webrtc::PeerConnectionInterface::kAll;
  277. }
  278. }
  279. + (RTCIceTransportPolicy)transportPolicyForTransportsType:
  280. (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
  281. switch (nativeType) {
  282. case webrtc::PeerConnectionInterface::kNone:
  283. return RTCIceTransportPolicyNone;
  284. case webrtc::PeerConnectionInterface::kRelay:
  285. return RTCIceTransportPolicyRelay;
  286. case webrtc::PeerConnectionInterface::kNoHost:
  287. return RTCIceTransportPolicyNoHost;
  288. case webrtc::PeerConnectionInterface::kAll:
  289. return RTCIceTransportPolicyAll;
  290. }
  291. }
  292. + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
  293. switch (policy) {
  294. case RTCIceTransportPolicyNone:
  295. return @"NONE";
  296. case RTCIceTransportPolicyRelay:
  297. return @"RELAY";
  298. case RTCIceTransportPolicyNoHost:
  299. return @"NO_HOST";
  300. case RTCIceTransportPolicyAll:
  301. return @"ALL";
  302. }
  303. }
  304. + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
  305. (RTCBundlePolicy)policy {
  306. switch (policy) {
  307. case RTCBundlePolicyBalanced:
  308. return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
  309. case RTCBundlePolicyMaxCompat:
  310. return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
  311. case RTCBundlePolicyMaxBundle:
  312. return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
  313. }
  314. }
  315. + (RTCBundlePolicy)bundlePolicyForNativePolicy:
  316. (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
  317. switch (nativePolicy) {
  318. case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
  319. return RTCBundlePolicyBalanced;
  320. case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
  321. return RTCBundlePolicyMaxCompat;
  322. case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
  323. return RTCBundlePolicyMaxBundle;
  324. }
  325. }
  326. + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
  327. switch (policy) {
  328. case RTCBundlePolicyBalanced:
  329. return @"BALANCED";
  330. case RTCBundlePolicyMaxCompat:
  331. return @"MAX_COMPAT";
  332. case RTCBundlePolicyMaxBundle:
  333. return @"MAX_BUNDLE";
  334. }
  335. }
  336. + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
  337. (RTCRtcpMuxPolicy)policy {
  338. switch (policy) {
  339. case RTCRtcpMuxPolicyNegotiate:
  340. return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
  341. case RTCRtcpMuxPolicyRequire:
  342. return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
  343. }
  344. }
  345. + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
  346. (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
  347. switch (nativePolicy) {
  348. case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
  349. return RTCRtcpMuxPolicyNegotiate;
  350. case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
  351. return RTCRtcpMuxPolicyRequire;
  352. }
  353. }
  354. + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
  355. switch (policy) {
  356. case RTCRtcpMuxPolicyNegotiate:
  357. return @"NEGOTIATE";
  358. case RTCRtcpMuxPolicyRequire:
  359. return @"REQUIRE";
  360. }
  361. }
  362. + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
  363. nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
  364. switch (policy) {
  365. case RTCTcpCandidatePolicyEnabled:
  366. return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
  367. case RTCTcpCandidatePolicyDisabled:
  368. return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
  369. }
  370. }
  371. + (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
  372. nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
  373. switch (policy) {
  374. case RTCCandidateNetworkPolicyAll:
  375. return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
  376. case RTCCandidateNetworkPolicyLowCost:
  377. return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
  378. }
  379. }
  380. + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
  381. (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
  382. switch (nativePolicy) {
  383. case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
  384. return RTCTcpCandidatePolicyEnabled;
  385. case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
  386. return RTCTcpCandidatePolicyDisabled;
  387. }
  388. }
  389. + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
  390. switch (policy) {
  391. case RTCTcpCandidatePolicyEnabled:
  392. return @"TCP_ENABLED";
  393. case RTCTcpCandidatePolicyDisabled:
  394. return @"TCP_DISABLED";
  395. }
  396. }
  397. + (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
  398. (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
  399. switch (nativePolicy) {
  400. case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
  401. return RTCCandidateNetworkPolicyAll;
  402. case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
  403. return RTCCandidateNetworkPolicyLowCost;
  404. }
  405. }
  406. + (NSString *)stringForCandidateNetworkPolicy:
  407. (RTCCandidateNetworkPolicy)policy {
  408. switch (policy) {
  409. case RTCCandidateNetworkPolicyAll:
  410. return @"CANDIDATE_ALL_NETWORKS";
  411. case RTCCandidateNetworkPolicyLowCost:
  412. return @"CANDIDATE_LOW_COST_NETWORKS";
  413. }
  414. }
  415. + (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
  416. nativeContinualGatheringPolicyForPolicy:
  417. (RTCContinualGatheringPolicy)policy {
  418. switch (policy) {
  419. case RTCContinualGatheringPolicyGatherOnce:
  420. return webrtc::PeerConnectionInterface::GATHER_ONCE;
  421. case RTCContinualGatheringPolicyGatherContinually:
  422. return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
  423. }
  424. }
  425. + (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
  426. (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
  427. switch (nativePolicy) {
  428. case webrtc::PeerConnectionInterface::GATHER_ONCE:
  429. return RTCContinualGatheringPolicyGatherOnce;
  430. case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
  431. return RTCContinualGatheringPolicyGatherContinually;
  432. }
  433. }
  434. + (NSString *)stringForContinualGatheringPolicy:
  435. (RTCContinualGatheringPolicy)policy {
  436. switch (policy) {
  437. case RTCContinualGatheringPolicyGatherOnce:
  438. return @"GATHER_ONCE";
  439. case RTCContinualGatheringPolicyGatherContinually:
  440. return @"GATHER_CONTINUALLY";
  441. }
  442. }
  443. + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
  444. (RTCEncryptionKeyType)keyType {
  445. switch (keyType) {
  446. case RTCEncryptionKeyTypeRSA:
  447. return rtc::KT_RSA;
  448. case RTCEncryptionKeyTypeECDSA:
  449. return rtc::KT_ECDSA;
  450. }
  451. }
  452. + (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
  453. switch (sdpSemantics) {
  454. case RTCSdpSemanticsPlanB:
  455. return webrtc::SdpSemantics::kPlanB;
  456. case RTCSdpSemanticsUnifiedPlan:
  457. return webrtc::SdpSemantics::kUnifiedPlan;
  458. }
  459. }
  460. + (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
  461. switch (sdpSemantics) {
  462. case webrtc::SdpSemantics::kPlanB:
  463. return RTCSdpSemanticsPlanB;
  464. case webrtc::SdpSemantics::kUnifiedPlan:
  465. return RTCSdpSemanticsUnifiedPlan;
  466. }
  467. }
  468. + (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
  469. switch (sdpSemantics) {
  470. case RTCSdpSemanticsPlanB:
  471. return @"PLAN_B";
  472. case RTCSdpSemanticsUnifiedPlan:
  473. return @"UNIFIED_PLAN";
  474. }
  475. }
  476. @end