blob: 41084b9357129f126f6683047f4ea748124b8216 [file] [log] [blame]
hjonaa32c3e2015-12-13 19:58:11 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCIceServer+Private.h"
hjonaa32c3e2015-12-13 19:58:11 -080012
tkchin9eeb6242016-04-27 01:54:20 -070013#import "NSString+StdString.h"
hjonaa32c3e2015-12-13 19:58:11 -080014
15@implementation RTCIceServer
16
17@synthesize urlStrings = _urlStrings;
18@synthesize username = _username;
19@synthesize credential = _credential;
20
Jon Hjelle32e0c012016-03-08 16:04:46 -080021- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings {
hjonaa32c3e2015-12-13 19:58:11 -080022 NSParameterAssert(urlStrings.count);
23 return [self initWithURLStrings:urlStrings
24 username:nil
25 credential:nil];
26}
27
Jon Hjelle32e0c012016-03-08 16:04:46 -080028- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings
hjonaa32c3e2015-12-13 19:58:11 -080029 username:(NSString *)username
30 credential:(NSString *)credential {
31 NSParameterAssert(urlStrings.count);
32 if (self = [super init]) {
33 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES];
34 _username = [username copy];
35 _credential = [credential copy];
36 }
37 return self;
38}
39
40- (NSString *)description {
41 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@",
42 _urlStrings,
43 _username,
44 _credential];
45}
46
47#pragma mark - Private
48
hjona2f77982016-03-04 07:09:09 -080049- (webrtc::PeerConnectionInterface::IceServer)nativeServer {
hjonaa32c3e2015-12-13 19:58:11 -080050 __block webrtc::PeerConnectionInterface::IceServer iceServer;
51
52 iceServer.username = [NSString stdStringForString:_username];
53 iceServer.password = [NSString stdStringForString:_credential];
54
55 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url,
56 NSUInteger idx,
57 BOOL *stop) {
58 iceServer.urls.push_back(url.stdString);
59 }];
60 return iceServer;
61}
62
hjon6d49a8e2016-01-26 13:06:42 -080063- (instancetype)initWithNativeServer:
64 (webrtc::PeerConnectionInterface::IceServer)nativeServer {
65 NSMutableArray *urls =
66 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()];
67 for (auto const &url : nativeServer.urls) {
68 [urls addObject:[NSString stringForStdString:url]];
69 }
70 NSString *username = [NSString stringForStdString:nativeServer.username];
71 NSString *credential = [NSString stringForStdString:nativeServer.password];
72 self = [self initWithURLStrings:urls
73 username:username
74 credential:credential];
75 return self;
76}
77
hjonaa32c3e2015-12-13 19:58:11 -080078@end