Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #import "talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h" |
| 29 | |
| 30 | #import "talk/app/webrtc/objc/RTCEnumConverter.h" |
| 31 | #import "talk/app/webrtc/objc/RTCICEServer+Internal.h" |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 32 | #import "talk/app/webrtc/objc/public/RTCLogging.h" |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 33 | |
kwiberg | 84cc918 | 2016-03-11 22:12:57 -0800 | [diff] [blame^] | 34 | #include <memory> |
| 35 | |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 36 | @implementation RTCConfiguration |
| 37 | |
| 38 | @synthesize iceTransportsType = _iceTransportsType; |
| 39 | @synthesize iceServers = _iceServers; |
| 40 | @synthesize bundlePolicy = _bundlePolicy; |
| 41 | @synthesize rtcpMuxPolicy = _rtcpMuxPolicy; |
| 42 | @synthesize tcpCandidatePolicy = _tcpCandidatePolicy; |
| 43 | @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 44 | @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 45 | @synthesize iceBackupCandidatePairPingInterval = _iceBackupCandidatePairPingInterval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 46 | @synthesize keyType = _keyType; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 47 | |
| 48 | - (instancetype)init { |
| 49 | if (self = [super init]) { |
| 50 | // Copy defaults. |
| 51 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 52 | _iceTransportsType = [RTCEnumConverter iceTransportsTypeForNativeEnum:config.type]; |
| 53 | _bundlePolicy = [RTCEnumConverter bundlePolicyForNativeEnum:config.bundle_policy]; |
| 54 | _rtcpMuxPolicy = [RTCEnumConverter rtcpMuxPolicyForNativeEnum:config.rtcp_mux_policy]; |
| 55 | _tcpCandidatePolicy = |
| 56 | [RTCEnumConverter tcpCandidatePolicyForNativeEnum:config.tcp_candidate_policy]; |
| 57 | _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 58 | _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 59 | _iceBackupCandidatePairPingInterval = config.ice_backup_candidate_pair_ping_interval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 60 | _keyType = kRTCEncryptionKeyTypeECDSA; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 61 | } |
| 62 | return self; |
| 63 | } |
| 64 | |
| 65 | - (instancetype)initWithIceTransportsType:(RTCIceTransportsType)iceTransportsType |
| 66 | bundlePolicy:(RTCBundlePolicy)bundlePolicy |
| 67 | rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy |
| 68 | tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 69 | audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 70 | iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout |
| 71 | iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval { |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 72 | if (self = [super init]) { |
| 73 | _iceTransportsType = iceTransportsType; |
| 74 | _bundlePolicy = bundlePolicy; |
| 75 | _rtcpMuxPolicy = rtcpMuxPolicy; |
| 76 | _tcpCandidatePolicy = tcpCandidatePolicy; |
| 77 | _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame] | 78 | _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 79 | _iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 80 | } |
| 81 | return self; |
| 82 | } |
| 83 | |
| 84 | #pragma mark - Private |
| 85 | |
| 86 | - (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration { |
| 87 | webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; |
| 88 | nativeConfig.type = [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; |
| 89 | for (RTCICEServer *iceServer : _iceServers) { |
| 90 | nativeConfig.servers.push_back(iceServer.iceServer); |
| 91 | } |
| 92 | nativeConfig.bundle_policy = [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; |
| 93 | nativeConfig.rtcp_mux_policy = [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; |
| 94 | nativeConfig.tcp_candidate_policy = |
| 95 | [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy]; |
| 96 | nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; |
Honghai Zhang | 381b421 | 2015-12-04 12:24:03 -0800 | [diff] [blame] | 97 | nativeConfig.ice_connection_receiving_timeout = _iceConnectionReceivingTimeout; |
| 98 | nativeConfig.ice_backup_candidate_pair_ping_interval = _iceBackupCandidatePairPingInterval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 99 | if (_keyType == kRTCEncryptionKeyTypeECDSA) { |
kwiberg | 84cc918 | 2016-03-11 22:12:57 -0800 | [diff] [blame^] | 100 | std::unique_ptr<rtc::SSLIdentity> identity( |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 101 | rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA)); |
| 102 | if (identity) { |
| 103 | nativeConfig.certificates.push_back( |
kwiberg | 84cc918 | 2016-03-11 22:12:57 -0800 | [diff] [blame^] | 104 | rtc::RTCCertificate::Create( |
| 105 | rtc::UniqueToScoped(std::move(identity)))); |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 106 | } else { |
| 107 | RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used."); |
| 108 | } |
| 109 | } |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 110 | return nativeConfig; |
| 111 | } |
| 112 | |
| 113 | @end |