Update API for Objective-C RTCConfiguration.

BUG=

Review URL: https://codereview.webrtc.org/1616303002

Cr-Commit-Position: refs/heads/master@{#11386}
This commit is contained in:
hjon
2016-01-26 13:06:42 -08:00
committed by Commit bot
parent 7b582a2e4f
commit 6d49a8ed17
10 changed files with 590 additions and 3 deletions

View File

@ -35,6 +35,9 @@ if (is_ios) {
#"objc/RTCAudioTrack+Private.h",
#"objc/RTCAudioTrack.h",
#"objc/RTCAudioTrack.mm",
#"objc/RTCConfiguration+Private.h",
#"objc/RTCConfiguration.h",
#"objc/RTCConfiguration.mm",
#"objc/RTCDataChannel+Private.h",
#"objc/RTCDataChannel.h",
#"objc/RTCDataChannel.mm",

View File

@ -25,6 +25,9 @@
'objc/RTCAudioTrack+Private.h',
'objc/RTCAudioTrack.h',
'objc/RTCAudioTrack.mm',
'objc/RTCConfiguration+Private.h',
'objc/RTCConfiguration.h',
'objc/RTCConfiguration.mm',
'objc/RTCDataChannel+Private.h',
'objc/RTCDataChannel.h',
'objc/RTCDataChannel.mm',

View File

@ -19,6 +19,7 @@
'<(webrtc_root)/base/base_tests.gyp:rtc_base_tests_utils',
],
'sources': [
'objctests/RTCConfigurationTest.mm',
'objctests/RTCIceCandidateTest.mm',
'objctests/RTCIceServerTest.mm',
'objctests/RTCMediaConstraintsTest.mm',

View File

@ -0,0 +1,63 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "RTCConfiguration.h"
#include "talk/app/webrtc/peerconnectioninterface.h"
NS_ASSUME_NONNULL_BEGIN
@interface RTCConfiguration ()
/**
* RTCConfiguration struct representation of this RTCConfiguration. This is
* needed to pass to the underlying C++ APIs.
*/
@property(nonatomic, readonly)
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfiguration;
- (instancetype)initWithNativeConfiguration:
(webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration;
+ (webrtc::PeerConnectionInterface::IceTransportsType)
nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy;
+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
(webrtc::PeerConnectionInterface::IceTransportsType)nativeType;
+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy;
+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
(RTCBundlePolicy)policy;
+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy;
+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy;
+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
(RTCRtcpMuxPolicy)policy;
+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
(webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy;
+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy;
+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy;
+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy;
+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,80 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import <Foundation/Foundation.h>
@class RTCIceServer;
/**
* Represents the ice transport policy. This exposes the same states in C++,
* which include one more state than what exists in the W3C spec.
*/
typedef NS_ENUM(NSInteger, RTCIceTransportPolicy) {
RTCIceTransportPolicyNone,
RTCIceTransportPolicyRelay,
RTCIceTransportPolicyNoHost,
RTCIceTransportPolicyAll
};
/** Represents the bundle policy. */
typedef NS_ENUM(NSInteger, RTCBundlePolicy) {
RTCBundlePolicyBalanced,
RTCBundlePolicyMaxCompat,
RTCBundlePolicyMaxBundle
};
/** Represents the rtcp mux policy. */
typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) {
RTCRtcpMuxPolicyNegotiate,
RTCRtcpMuxPolicyRequire
};
/** Represents the tcp candidate policy. */
typedef NS_ENUM(NSInteger, RTCTcpCandidatePolicy) {
RTCTcpCandidatePolicyEnabled,
RTCTcpCandidatePolicyDisabled
};
NS_ASSUME_NONNULL_BEGIN
@interface RTCConfiguration : NSObject
/** An array of Ice Servers available to be used by ICE. */
@property(nonatomic, copy) NSArray<RTCIceServer *> *iceServers;
/** Which candidates the ICE agent is allowed to use. The W3C calls it
* |iceTransportPolicy|, while in C++ it is called |type|. */
@property(nonatomic, assign) RTCIceTransportPolicy iceTransportPolicy;
/** The media-bundling policy to use when gathering ICE candidates. */
@property(nonatomic, assign) RTCBundlePolicy bundlePolicy;
/** The rtcp-mux policy to use when gathering ICE candidates. */
@property(nonatomic, assign) RTCRtcpMuxPolicy rtcpMuxPolicy;
@property(nonatomic, assign) RTCTcpCandidatePolicy tcpCandidatePolicy;
@property(nonatomic, assign) int audioJitterBufferMaxPackets;
@property(nonatomic, assign) int iceConnectionReceivingTimeout;
@property(nonatomic, assign) int iceBackupCandidatePairPingInterval;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithIceServers:
(nullable NSArray<RTCIceServer *> *)iceServers
iceTransportPolicy:(RTCIceTransportPolicy)iceTransportPolicy
bundlePolicy:(RTCBundlePolicy)bundlePolicy
rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy
tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy
audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets
iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout
iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,276 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "RTCConfiguration.h"
#import "webrtc/api/objc/RTCConfiguration+Private.h"
#import "webrtc/api/objc/RTCIceServer+Private.h"
@implementation RTCConfiguration
@synthesize iceServers = _iceServers;
@synthesize iceTransportPolicy = _iceTransportPolicy;
@synthesize bundlePolicy = _bundlePolicy;
@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
@synthesize iceBackupCandidatePairPingInterval =
_iceBackupCandidatePairPingInterval;
- (instancetype)init {
if (self = [super init]) {
_iceServers = [NSMutableArray array];
// Copy defaults.
webrtc::PeerConnectionInterface::RTCConfiguration config;
_iceTransportPolicy =
[[self class] transportPolicyForTransportsType:config.type];
_bundlePolicy =
[[self class] bundlePolicyForNativePolicy:config.bundle_policy];
_rtcpMuxPolicy =
[[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
_tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
config.tcp_candidate_policy];
_audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
_iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
_iceBackupCandidatePairPingInterval =
config.ice_backup_candidate_pair_ping_interval;
}
return self;
}
- (instancetype)initWithIceServers:(NSArray<RTCIceServer *> *)iceServers
iceTransportPolicy:(RTCIceTransportPolicy)iceTransportPolicy
bundlePolicy:(RTCBundlePolicy)bundlePolicy
rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy
tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy
audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets
iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout
iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval {
if (self = [self init]) {
if (iceServers) {
_iceServers = [iceServers copy];
}
_iceTransportPolicy = iceTransportPolicy;
_bundlePolicy = bundlePolicy;
_rtcpMuxPolicy = rtcpMuxPolicy;
_tcpCandidatePolicy = tcpCandidatePolicy;
_audioJitterBufferMaxPackets = audioJitterBufferMaxPackets;
_iceConnectionReceivingTimeout = iceConnectionReceivingTimeout;
_iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval;
}
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:
@"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n",
_iceServers,
[[self class] stringForTransportPolicy:_iceTransportPolicy],
[[self class] stringForBundlePolicy:_bundlePolicy],
[[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
[[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
_audioJitterBufferMaxPackets,
_iceConnectionReceivingTimeout,
_iceBackupCandidatePairPingInterval];
}
#pragma mark - Private
- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration {
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
for (RTCIceServer *iceServer in _iceServers) {
nativeConfig.servers.push_back(iceServer.iceServer);
}
nativeConfig.type =
[[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
nativeConfig.bundle_policy =
[[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
nativeConfig.rtcp_mux_policy =
[[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
nativeConfig.tcp_candidate_policy =
[[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
nativeConfig.ice_connection_receiving_timeout =
_iceConnectionReceivingTimeout;
nativeConfig.ice_backup_candidate_pair_ping_interval =
_iceBackupCandidatePairPingInterval;
return nativeConfig;
}
- (instancetype)initWithNativeConfiguration:
(webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfig {
NSMutableArray *iceServers =
[NSMutableArray arrayWithCapacity:nativeConfig.servers.size()];
for (auto const &server : nativeConfig.servers) {
RTCIceServer *iceServer =
[[RTCIceServer alloc] initWithNativeServer:server];
[iceServers addObject:iceServer];
}
if (self = [self init]) {
if (iceServers) {
_iceServers = [iceServers copy];
}
_iceTransportPolicy =
[[self class] transportPolicyForTransportsType:nativeConfig.type];
_bundlePolicy =
[[self class] bundlePolicyForNativePolicy:nativeConfig.bundle_policy];
_rtcpMuxPolicy = [[self class] rtcpMuxPolicyForNativePolicy:
nativeConfig.rtcp_mux_policy];
_tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
nativeConfig.tcp_candidate_policy];
_audioJitterBufferMaxPackets = nativeConfig.audio_jitter_buffer_max_packets;
_iceConnectionReceivingTimeout =
nativeConfig.ice_connection_receiving_timeout;
_iceBackupCandidatePairPingInterval =
nativeConfig.ice_backup_candidate_pair_ping_interval;
}
return self;
}
+ (webrtc::PeerConnectionInterface::IceTransportsType)
nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
switch (policy) {
case RTCIceTransportPolicyNone:
return webrtc::PeerConnectionInterface::kNone;
case RTCIceTransportPolicyRelay:
return webrtc::PeerConnectionInterface::kRelay;
case RTCIceTransportPolicyNoHost:
return webrtc::PeerConnectionInterface::kNoHost;
case RTCIceTransportPolicyAll:
return webrtc::PeerConnectionInterface::kAll;
}
}
+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
(webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
switch (nativeType) {
case webrtc::PeerConnectionInterface::kNone:
return RTCIceTransportPolicyNone;
case webrtc::PeerConnectionInterface::kRelay:
return RTCIceTransportPolicyRelay;
case webrtc::PeerConnectionInterface::kNoHost:
return RTCIceTransportPolicyNoHost;
case webrtc::PeerConnectionInterface::kAll:
return RTCIceTransportPolicyAll;
}
}
+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
switch (policy) {
case RTCIceTransportPolicyNone:
return @"NONE";
case RTCIceTransportPolicyRelay:
return @"RELAY";
case RTCIceTransportPolicyNoHost:
return @"NO_HOST";
case RTCIceTransportPolicyAll:
return @"ALL";
}
}
+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
(RTCBundlePolicy)policy {
switch (policy) {
case RTCBundlePolicyBalanced:
return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
case RTCBundlePolicyMaxCompat:
return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
case RTCBundlePolicyMaxBundle:
return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
}
}
+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
switch (nativePolicy) {
case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
return RTCBundlePolicyBalanced;
case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
return RTCBundlePolicyMaxCompat;
case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
return RTCBundlePolicyMaxBundle;
}
}
+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
switch (policy) {
case RTCBundlePolicyBalanced:
return @"BALANCED";
case RTCBundlePolicyMaxCompat:
return @"MAX_COMPAT";
case RTCBundlePolicyMaxBundle:
return @"MAX_BUNDLE";
}
}
+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
(RTCRtcpMuxPolicy)policy {
switch (policy) {
case RTCRtcpMuxPolicyNegotiate:
return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
case RTCRtcpMuxPolicyRequire:
return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
}
}
+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
(webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
switch (nativePolicy) {
case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
return RTCRtcpMuxPolicyNegotiate;
case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
return RTCRtcpMuxPolicyRequire;
}
}
+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
switch (policy) {
case RTCRtcpMuxPolicyNegotiate:
return @"NEGOTIATE";
case RTCRtcpMuxPolicyRequire:
return @"REQUIRE";
}
}
+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
switch (policy) {
case RTCTcpCandidatePolicyEnabled:
return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
case RTCTcpCandidatePolicyDisabled:
return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
}
}
+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
switch (nativePolicy) {
case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
return RTCTcpCandidatePolicyEnabled;
case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
return RTCTcpCandidatePolicyDisabled;
}
}
+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
switch (policy) {
case RTCTcpCandidatePolicyEnabled:
return @"TCP_ENABLED";
case RTCTcpCandidatePolicyDisabled:
return @"TCP_DISABLED";
}
}
@end

View File

@ -23,6 +23,10 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly)
webrtc::PeerConnectionInterface::IceServer iceServer;
/** Initialize an RTCIceServer from a native IceServer. */
- (instancetype)initWithNativeServer:
(webrtc::PeerConnectionInterface::IceServer)nativeServer;
@end
NS_ASSUME_NONNULL_END

View File

@ -61,4 +61,19 @@
return iceServer;
}
- (instancetype)initWithNativeServer:
(webrtc::PeerConnectionInterface::IceServer)nativeServer {
NSMutableArray *urls =
[NSMutableArray arrayWithCapacity:nativeServer.urls.size()];
for (auto const &url : nativeServer.urls) {
[urls addObject:[NSString stringForStdString:url]];
}
NSString *username = [NSString stringForStdString:nativeServer.username];
NSString *credential = [NSString stringForStdString:nativeServer.password];
self = [self initWithURLStrings:urls
username:username
credential:credential];
return self;
}
@end

View File

@ -0,0 +1,118 @@
/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import <Foundation/Foundation.h>
#include <vector>
#include "webrtc/base/gunit.h"
#import "webrtc/api/objc/RTCConfiguration.h"
#import "webrtc/api/objc/RTCConfiguration+Private.h"
#import "webrtc/api/objc/RTCIceServer.h"
#import "webrtc/base/objc/NSString+StdString.h"
@interface RTCConfigurationTest : NSObject
- (void)testConversionToNativeConfiguration;
- (void)testInitFromNativeConfiguration;
@end
@implementation RTCConfigurationTest
- (void)testConversionToNativeConfiguration {
NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
RTCConfiguration *config =
[[RTCConfiguration alloc] initWithIceServers:@[ server ]
iceTransportPolicy:RTCIceTransportPolicyRelay
bundlePolicy:RTCBundlePolicyMaxBundle
rtcpMuxPolicy:RTCRtcpMuxPolicyNegotiate
tcpCandidatePolicy:RTCTcpCandidatePolicyDisabled
audioJitterBufferMaxPackets:60
iceConnectionReceivingTimeout:1
iceBackupCandidatePairPingInterval:2];
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig =
config.nativeConfiguration;
EXPECT_EQ(1u, nativeConfig.servers.size());
webrtc::PeerConnectionInterface::IceServer nativeServer =
nativeConfig.servers.front();
EXPECT_EQ(1u, nativeServer.urls.size());
EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front());
EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig.type);
EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle,
nativeConfig.bundle_policy);
EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
nativeConfig.rtcp_mux_policy);
EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled,
nativeConfig.tcp_candidate_policy);
EXPECT_EQ(60, nativeConfig.audio_jitter_buffer_max_packets);
EXPECT_EQ(1, nativeConfig.ice_connection_receiving_timeout);
EXPECT_EQ(2, nativeConfig.ice_backup_candidate_pair_ping_interval);
}
- (void)testInitFromNativeConfiguration {
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
webrtc::PeerConnectionInterface::IceServer nativeServer;
nativeServer.username = "username";
nativeServer.password = "password";
nativeServer.urls.push_back("stun:stun.example.net");
webrtc::PeerConnectionInterface::IceServers servers { nativeServer };
nativeConfig.servers = servers;
nativeConfig.type = webrtc::PeerConnectionInterface::kNoHost;
nativeConfig.bundle_policy =
webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
nativeConfig.rtcp_mux_policy =
webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
nativeConfig.tcp_candidate_policy =
webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
nativeConfig.audio_jitter_buffer_max_packets = 40;
nativeConfig.ice_connection_receiving_timeout =
webrtc::PeerConnectionInterface::RTCConfiguration::kUndefined;
nativeConfig.ice_backup_candidate_pair_ping_interval =
webrtc::PeerConnectionInterface::RTCConfiguration::kUndefined;
RTCConfiguration *config =
[[RTCConfiguration alloc] initWithNativeConfiguration:nativeConfig];
EXPECT_EQ(1u, config.iceServers.count);
RTCIceServer *server = config.iceServers.firstObject;
EXPECT_EQ(1u, server.urlStrings.count);
EXPECT_TRUE([@"stun:stun.example.net" isEqualToString:
server.urlStrings.firstObject]);
EXPECT_EQ(RTCIceTransportPolicyNoHost, config.iceTransportPolicy);
EXPECT_EQ(RTCBundlePolicyMaxCompat, config.bundlePolicy);
EXPECT_EQ(RTCRtcpMuxPolicyRequire, config.rtcpMuxPolicy);
EXPECT_EQ(RTCTcpCandidatePolicyEnabled, config.tcpCandidatePolicy);
EXPECT_EQ(40, config.audioJitterBufferMaxPackets);
EXPECT_EQ(-1, config.iceConnectionReceivingTimeout);
EXPECT_EQ(-1, config.iceBackupCandidatePairPingInterval);
}
@end
TEST(RTCConfigurationTest, NativeConfigurationConversionTest) {
@autoreleasepool {
RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
[test testConversionToNativeConfiguration];
}
}
TEST(RTCConfigurationTest, InitFromConfigurationTest) {
@autoreleasepool {
RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
[test testInitFromNativeConfiguration];
}
}

View File

@ -16,11 +16,13 @@
#import "webrtc/api/objc/RTCIceServer.h"
#import "webrtc/api/objc/RTCIceServer+Private.h"
#import "webrtc/base/objc/NSString+StdString.h"
@interface RTCIceServerTest : NSObject
- (void)testOneURLServer;
- (void)testTwoURLServer;
- (void)testPasswordCredential;
- (void)testInitFromNativeServer;
@end
@implementation RTCIceServerTest
@ -30,7 +32,7 @@
@"stun:stun1.example.net" ]];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
EXPECT_EQ((size_t)1, iceStruct.urls.size());
EXPECT_EQ(1u, iceStruct.urls.size());
EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front());
EXPECT_EQ("", iceStruct.username);
EXPECT_EQ("", iceStruct.password);
@ -41,7 +43,7 @@
@"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
EXPECT_EQ((size_t)2, iceStruct.urls.size());
EXPECT_EQ(2u, iceStruct.urls.size());
EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back());
EXPECT_EQ("", iceStruct.username);
@ -54,12 +56,27 @@
username:@"username"
credential:@"credential"];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
EXPECT_EQ((size_t)1, iceStruct.urls.size());
EXPECT_EQ(1u, iceStruct.urls.size());
EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
EXPECT_EQ("username", iceStruct.username);
EXPECT_EQ("credential", iceStruct.password);
}
- (void)testInitFromNativeServer {
webrtc::PeerConnectionInterface::IceServer nativeServer;
nativeServer.username = "username";
nativeServer.password = "password";
nativeServer.urls.push_back("stun:stun.example.net");
RTCIceServer *iceServer =
[[RTCIceServer alloc] initWithNativeServer:nativeServer];
EXPECT_EQ(1u, iceServer.urlStrings.count);
EXPECT_EQ("stun:stun.example.net",
[NSString stdStringForString:iceServer.urlStrings.firstObject]);
EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
}
@end
TEST(RTCIceServerTest, OneURLTest) {
@ -82,3 +99,10 @@ TEST(RTCIceServerTest, PasswordCredentialTest) {
[test testPasswordCredential];
}
}
TEST(RTCIceServerTest, InitFromNativeServerTest) {
@autoreleasepool {
RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
[test testInitFromNativeServer];
}
}