| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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+Private.h" | |
| 12 | |
| 13 #import "NSString+StdString.h" | |
| 14 | |
| 15 @implementation RTCIceServer | |
| 16 | |
| 17 @synthesize urlStrings = _urlStrings; | |
| 18 @synthesize username = _username; | |
| 19 @synthesize credential = _credential; | |
| 20 @synthesize tlsCertPolicy = _tlsCertPolicy; | |
| 21 | |
| 22 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { | |
| 23 return [self initWithURLStrings:urlStrings | |
| 24 username:nil | |
| 25 credential:nil]; | |
| 26 } | |
| 27 | |
| 28 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | |
| 29 username:(NSString *)username | |
| 30 credential:(NSString *)credential { | |
| 31 return [self initWithURLStrings:urlStrings | |
| 32 username:username | |
| 33 credential:credential | |
| 34 tlsCertPolicy:RTCTlsCertPolicySecure]; | |
| 35 } | |
| 36 | |
| 37 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | |
| 38 username:(NSString *)username | |
| 39 credential:(NSString *)credential | |
| 40 tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | |
| 41 NSParameterAssert(urlStrings.count); | |
| 42 if (self = [super init]) { | |
| 43 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; | |
| 44 _username = [username copy]; | |
| 45 _credential = [credential copy]; | |
| 46 _tlsCertPolicy = tlsCertPolicy; | |
| 47 } | |
| 48 return self; | |
| 49 } | |
| 50 | |
| 51 - (NSString *)description { | |
| 52 return | |
| 53 [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@\n%@", _urlStrings, | |
| 54 _username, _credential, | |
| 55 [self stringForTlsCertPolicy:_tlsCertPolicy]]; | |
| 56 } | |
| 57 | |
| 58 #pragma mark - Private | |
| 59 | |
| 60 - (NSString *)stringForTlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | |
| 61 switch (tlsCertPolicy) { | |
| 62 case RTCTlsCertPolicySecure: | |
| 63 return @"RTCTlsCertPolicySecure"; | |
| 64 case RTCTlsCertPolicyInsecureNoCheck: | |
| 65 return @"RTCTlsCertPolicyInsecureNoCheck"; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 - (webrtc::PeerConnectionInterface::IceServer)nativeServer { | |
| 70 __block webrtc::PeerConnectionInterface::IceServer iceServer; | |
| 71 | |
| 72 iceServer.username = [NSString stdStringForString:_username]; | |
| 73 iceServer.password = [NSString stdStringForString:_credential]; | |
| 74 | |
| 75 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, | |
| 76 NSUInteger idx, | |
| 77 BOOL *stop) { | |
| 78 iceServer.urls.push_back(url.stdString); | |
| 79 }]; | |
| 80 | |
| 81 switch (_tlsCertPolicy) { | |
| 82 case RTCTlsCertPolicySecure: | |
| 83 iceServer.tls_cert_policy = | |
| 84 webrtc::PeerConnectionInterface::kTlsCertPolicySecure; | |
| 85 break; | |
| 86 case RTCTlsCertPolicyInsecureNoCheck: | |
| 87 iceServer.tls_cert_policy = | |
| 88 webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck; | |
| 89 break; | |
| 90 } | |
| 91 return iceServer; | |
| 92 } | |
| 93 | |
| 94 - (instancetype)initWithNativeServer: | |
| 95 (webrtc::PeerConnectionInterface::IceServer)nativeServer { | |
| 96 NSMutableArray *urls = | |
| 97 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; | |
| 98 for (auto const &url : nativeServer.urls) { | |
| 99 [urls addObject:[NSString stringForStdString:url]]; | |
| 100 } | |
| 101 NSString *username = [NSString stringForStdString:nativeServer.username]; | |
| 102 NSString *credential = [NSString stringForStdString:nativeServer.password]; | |
| 103 RTCTlsCertPolicy tlsCertPolicy; | |
| 104 | |
| 105 switch (nativeServer.tls_cert_policy) { | |
| 106 case webrtc::PeerConnectionInterface::kTlsCertPolicySecure: | |
| 107 tlsCertPolicy = RTCTlsCertPolicySecure; | |
| 108 break; | |
| 109 case webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck: | |
| 110 tlsCertPolicy = RTCTlsCertPolicyInsecureNoCheck; | |
| 111 break; | |
| 112 } | |
| 113 | |
| 114 self = [self initWithURLStrings:urls | |
| 115 username:username | |
| 116 credential:credential | |
| 117 tlsCertPolicy:tlsCertPolicy]; | |
| 118 return self; | |
| 119 } | |
| 120 | |
| 121 @end | |
| OLD | NEW |