blob: 8cbb5883516dadb664578c27ff4cd30a983c91e0 [file] [log] [blame]
Zeke Chinbc7dd7e2015-05-29 14:59:14 -07001/*
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"
tkchinab8f82f2016-01-27 17:50:11 -080032#import "talk/app/webrtc/objc/public/RTCLogging.h"
Zeke Chinbc7dd7e2015-05-29 14:59:14 -070033
34@implementation RTCConfiguration
35
36@synthesize iceTransportsType = _iceTransportsType;
37@synthesize iceServers = _iceServers;
38@synthesize bundlePolicy = _bundlePolicy;
39@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
40@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
41@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
honghaiz4edc39c2015-09-01 09:53:56 -070042@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -080043@synthesize iceBackupCandidatePairPingInterval = _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080044@synthesize keyType = _keyType;
Zeke Chinbc7dd7e2015-05-29 14:59:14 -070045
46- (instancetype)init {
47 if (self = [super init]) {
48 // Copy defaults.
49 webrtc::PeerConnectionInterface::RTCConfiguration config;
50 _iceTransportsType = [RTCEnumConverter iceTransportsTypeForNativeEnum:config.type];
51 _bundlePolicy = [RTCEnumConverter bundlePolicyForNativeEnum:config.bundle_policy];
52 _rtcpMuxPolicy = [RTCEnumConverter rtcpMuxPolicyForNativeEnum:config.rtcp_mux_policy];
53 _tcpCandidatePolicy =
54 [RTCEnumConverter tcpCandidatePolicyForNativeEnum:config.tcp_candidate_policy];
55 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
honghaiz4edc39c2015-09-01 09:53:56 -070056 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
Honghai Zhang381b4212015-12-04 12:24:03 -080057 _iceBackupCandidatePairPingInterval = config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -080058 _keyType = kRTCEncryptionKeyTypeECDSA;
Zeke Chinbc7dd7e2015-05-29 14:59:14 -070059 }
60 return self;
61}
62
63- (instancetype)initWithIceTransportsType:(RTCIceTransportsType)iceTransportsType
64 bundlePolicy:(RTCBundlePolicy)bundlePolicy
65 rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy
66 tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy
honghaiz4edc39c2015-09-01 09:53:56 -070067 audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets
Honghai Zhang381b4212015-12-04 12:24:03 -080068 iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout
69 iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval {
Zeke Chinbc7dd7e2015-05-29 14:59:14 -070070 if (self = [super init]) {
71 _iceTransportsType = iceTransportsType;
72 _bundlePolicy = bundlePolicy;
73 _rtcpMuxPolicy = rtcpMuxPolicy;
74 _tcpCandidatePolicy = tcpCandidatePolicy;
75 _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets;
honghaiz4edc39c2015-09-01 09:53:56 -070076 _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout;
Honghai Zhang381b4212015-12-04 12:24:03 -080077 _iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval;
Zeke Chinbc7dd7e2015-05-29 14:59:14 -070078 }
79 return self;
80}
81
82#pragma mark - Private
83
84- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration {
85 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
86 nativeConfig.type = [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType];
87 for (RTCICEServer *iceServer : _iceServers) {
88 nativeConfig.servers.push_back(iceServer.iceServer);
89 }
90 nativeConfig.bundle_policy = [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy];
91 nativeConfig.rtcp_mux_policy = [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy];
92 nativeConfig.tcp_candidate_policy =
93 [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy];
94 nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
Honghai Zhang381b4212015-12-04 12:24:03 -080095 nativeConfig.ice_connection_receiving_timeout = _iceConnectionReceivingTimeout;
96 nativeConfig.ice_backup_candidate_pair_ping_interval = _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080097 if (_keyType == kRTCEncryptionKeyTypeECDSA) {
98 rtc::scoped_ptr<rtc::SSLIdentity> identity(
99 rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA));
100 if (identity) {
101 nativeConfig.certificates.push_back(
102 rtc::RTCCertificate::Create(std::move(identity)));
103 } else {
104 RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used.");
105 }
106 }
Zeke Chinbc7dd7e2015-05-29 14:59:14 -0700107 return nativeConfig;
108}
109
110@end