blob: 9fc215429f45f00b148c0822b2b6b3aa3c17cf70 [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
11#import "RTCIceServer.h"
12
13#import "webrtc/api/objc/RTCIceServer+Private.h"
14#import "webrtc/base/objc/NSString+StdString.h"
15
16@implementation RTCIceServer
hjon6b039952016-02-25 12:32:58 -080017// TODO(hjon): Update nullability types. See http://crbug/webrtc/5592
hjonaa32c3e2015-12-13 19:58:11 -080018
19@synthesize urlStrings = _urlStrings;
20@synthesize username = _username;
21@synthesize credential = _credential;
22
hjon6b039952016-02-25 12:32:58 -080023- (instancetype)initWithURLStrings:(NSArray *)urlStrings {
24// - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings {
hjonaa32c3e2015-12-13 19:58:11 -080025 NSParameterAssert(urlStrings.count);
26 return [self initWithURLStrings:urlStrings
27 username:nil
28 credential:nil];
29}
30
hjon6b039952016-02-25 12:32:58 -080031- (instancetype)initWithURLStrings:(NSArray *)urlStrings
32// - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings
hjonaa32c3e2015-12-13 19:58:11 -080033 username:(NSString *)username
34 credential:(NSString *)credential {
35 NSParameterAssert(urlStrings.count);
36 if (self = [super init]) {
37 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES];
38 _username = [username copy];
39 _credential = [credential copy];
40 }
41 return self;
42}
43
44- (NSString *)description {
45 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@",
46 _urlStrings,
47 _username,
48 _credential];
49}
50
51#pragma mark - Private
52
hjona2f77982016-03-04 07:09:09 -080053- (webrtc::PeerConnectionInterface::IceServer)nativeServer {
hjonaa32c3e2015-12-13 19:58:11 -080054 __block webrtc::PeerConnectionInterface::IceServer iceServer;
55
56 iceServer.username = [NSString stdStringForString:_username];
57 iceServer.password = [NSString stdStringForString:_credential];
58
59 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url,
60 NSUInteger idx,
61 BOOL *stop) {
62 iceServer.urls.push_back(url.stdString);
63 }];
64 return iceServer;
65}
66
hjon6d49a8e2016-01-26 13:06:42 -080067- (instancetype)initWithNativeServer:
68 (webrtc::PeerConnectionInterface::IceServer)nativeServer {
69 NSMutableArray *urls =
70 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()];
71 for (auto const &url : nativeServer.urls) {
72 [urls addObject:[NSString stringForStdString:url]];
73 }
74 NSString *username = [NSString stringForStdString:nativeServer.username];
75 NSString *credential = [NSString stringForStdString:nativeServer.password];
76 self = [self initWithURLStrings:urls
77 username:username
78 credential:credential];
79 return self;
80}
81
hjonaa32c3e2015-12-13 19:58:11 -080082@end