OLD | NEW |
| (Empty) |
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" | |
32 #import "talk/app/webrtc/objc/public/RTCLogging.h" | |
33 | |
34 #include <memory> | |
35 | |
36 #include "webrtc/base/rtccertificategenerator.h" | |
37 | |
38 @implementation RTCConfiguration | |
39 | |
40 @synthesize iceTransportsType = _iceTransportsType; | |
41 @synthesize iceServers = _iceServers; | |
42 @synthesize bundlePolicy = _bundlePolicy; | |
43 @synthesize rtcpMuxPolicy = _rtcpMuxPolicy; | |
44 @synthesize tcpCandidatePolicy = _tcpCandidatePolicy; | |
45 @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; | |
46 @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; | |
47 @synthesize iceBackupCandidatePairPingInterval = _iceBackupCandidatePairPingInte
rval; | |
48 @synthesize keyType = _keyType; | |
49 | |
50 - (instancetype)init { | |
51 if (self = [super init]) { | |
52 // Copy defaults. | |
53 webrtc::PeerConnectionInterface::RTCConfiguration config; | |
54 _iceTransportsType = [RTCEnumConverter iceTransportsTypeForNativeEnum:config
.type]; | |
55 _bundlePolicy = [RTCEnumConverter bundlePolicyForNativeEnum:config.bundle_po
licy]; | |
56 _rtcpMuxPolicy = [RTCEnumConverter rtcpMuxPolicyForNativeEnum:config.rtcp_mu
x_policy]; | |
57 _tcpCandidatePolicy = | |
58 [RTCEnumConverter tcpCandidatePolicyForNativeEnum:config.tcp_candidate_p
olicy]; | |
59 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; | |
60 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; | |
61 _iceBackupCandidatePairPingInterval = config.ice_backup_candidate_pair_ping_
interval; | |
62 _keyType = kRTCEncryptionKeyTypeECDSA; | |
63 } | |
64 return self; | |
65 } | |
66 | |
67 - (instancetype)initWithIceTransportsType:(RTCIceTransportsType)iceTransportsTyp
e | |
68 bundlePolicy:(RTCBundlePolicy)bundlePolicy | |
69 rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy | |
70 tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePol
icy | |
71 audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets | |
72 iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout | |
73 iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterva
l { | |
74 if (self = [super init]) { | |
75 _iceTransportsType = iceTransportsType; | |
76 _bundlePolicy = bundlePolicy; | |
77 _rtcpMuxPolicy = rtcpMuxPolicy; | |
78 _tcpCandidatePolicy = tcpCandidatePolicy; | |
79 _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets; | |
80 _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout; | |
81 _iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval; | |
82 } | |
83 return self; | |
84 } | |
85 | |
86 #pragma mark - Private | |
87 | |
88 - (webrtc::PeerConnectionInterface::RTCConfiguration *) | |
89 createNativeConfiguration { | |
90 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> | |
91 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration()); | |
92 nativeConfig->type = | |
93 [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; | |
94 for (RTCICEServer *iceServer : _iceServers) { | |
95 nativeConfig->servers.push_back(iceServer.iceServer); | |
96 } | |
97 nativeConfig->bundle_policy = | |
98 [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; | |
99 nativeConfig->rtcp_mux_policy = | |
100 [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; | |
101 nativeConfig->tcp_candidate_policy = | |
102 [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy]; | |
103 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; | |
104 nativeConfig->ice_connection_receiving_timeout = | |
105 _iceConnectionReceivingTimeout; | |
106 nativeConfig->ice_backup_candidate_pair_ping_interval = | |
107 _iceBackupCandidatePairPingInterval; | |
108 rtc::KeyType keyType = | |
109 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType]; | |
110 if (keyType != rtc::KT_DEFAULT) { | |
111 rtc::scoped_refptr<rtc::RTCCertificate> certificate = | |
112 rtc::RTCCertificateGenerator::GenerateCertificate( | |
113 rtc::KeyParams(keyType), rtc::Optional<uint64_t>()); | |
114 if (!certificate) { | |
115 RTCLogError(@"Failed to generate certificate."); | |
116 return nullptr; | |
117 } | |
118 nativeConfig->certificates.push_back(certificate); | |
119 } | |
120 return nativeConfig.release(); | |
121 } | |
122 | |
123 + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: | |
124 (RTCEncryptionKeyType)keyType { | |
125 switch (keyType) { | |
126 case kRTCEncryptionKeyTypeRSA: | |
127 return rtc::KT_RSA; | |
128 case kRTCEncryptionKeyTypeECDSA: | |
129 return rtc::KT_ECDSA; | |
130 } | |
131 } | |
132 | |
133 @end | |
OLD | NEW |