Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCIceCandidate+Private.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 12 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 15 | #import "NSString+StdString.h" |
| 16 | #import "WebRTC/RTCLogging.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 17 | |
| 18 | @implementation RTCIceCandidate |
| 19 | |
| 20 | @synthesize sdpMid = _sdpMid; |
| 21 | @synthesize sdpMLineIndex = _sdpMLineIndex; |
| 22 | @synthesize sdp = _sdp; |
zhihuang | d7e771d | 2017-02-16 11:29:39 -0800 | [diff] [blame^] | 23 | @synthesize serverUrl = _serverUrl; |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 24 | |
| 25 | - (instancetype)initWithSdp:(NSString *)sdp |
tkchin | 121ac12 | 2016-03-21 09:08:40 -0700 | [diff] [blame] | 26 | sdpMLineIndex:(int)sdpMLineIndex |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 27 | sdpMid:(NSString *)sdpMid { |
| 28 | NSParameterAssert(sdp.length); |
| 29 | if (self = [super init]) { |
| 30 | _sdpMid = [sdpMid copy]; |
| 31 | _sdpMLineIndex = sdpMLineIndex; |
| 32 | _sdp = [sdp copy]; |
| 33 | } |
| 34 | return self; |
| 35 | } |
| 36 | |
| 37 | - (NSString *)description { |
zhihuang | d7e771d | 2017-02-16 11:29:39 -0800 | [diff] [blame^] | 38 | return [NSString stringWithFormat:@"RTCIceCandidate:\n%@\n%d\n%@\n%@", |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 39 | _sdpMid, |
tkchin | 121ac12 | 2016-03-21 09:08:40 -0700 | [diff] [blame] | 40 | _sdpMLineIndex, |
zhihuang | d7e771d | 2017-02-16 11:29:39 -0800 | [diff] [blame^] | 41 | _sdp, |
| 42 | _serverUrl]; |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #pragma mark - Private |
| 46 | |
| 47 | - (instancetype)initWithNativeCandidate: |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 48 | (const webrtc::IceCandidateInterface *)candidate { |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 49 | NSParameterAssert(candidate); |
| 50 | std::string sdp; |
| 51 | candidate->ToString(&sdp); |
| 52 | |
zhihuang | d7e771d | 2017-02-16 11:29:39 -0800 | [diff] [blame^] | 53 | RTCIceCandidate *rtcCandidate = |
| 54 | [self initWithSdp:[NSString stringForStdString:sdp] |
| 55 | sdpMLineIndex:candidate->sdp_mline_index() |
| 56 | sdpMid:[NSString stringForStdString:candidate->sdp_mid()]]; |
| 57 | rtcCandidate->_serverUrl = [NSString stringForStdString:candidate->server_url()]; |
| 58 | return rtcCandidate; |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 59 | } |
| 60 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 61 | - (std::unique_ptr<webrtc::IceCandidateInterface>)nativeCandidate { |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 62 | webrtc::SdpParseError error; |
| 63 | |
| 64 | webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate( |
| 65 | _sdpMid.stdString, _sdpMLineIndex, _sdp.stdString, &error); |
| 66 | |
| 67 | if (!candidate) { |
| 68 | RTCLog(@"Failed to create ICE candidate: %s\nline: %s", |
| 69 | error.description.c_str(), |
| 70 | error.line.c_str()); |
| 71 | } |
| 72 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 73 | return std::unique_ptr<webrtc::IceCandidateInterface>(candidate); |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @end |