You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "RTCIceCandidate+Private.h"
  11. #include <memory>
  12. #import "base/RTCLogging.h"
  13. #import "helpers/NSString+StdString.h"
  14. @implementation RTCIceCandidate
  15. @synthesize sdpMid = _sdpMid;
  16. @synthesize sdpMLineIndex = _sdpMLineIndex;
  17. @synthesize sdp = _sdp;
  18. @synthesize serverUrl = _serverUrl;
  19. - (instancetype)initWithSdp:(NSString *)sdp
  20. sdpMLineIndex:(int)sdpMLineIndex
  21. sdpMid:(NSString *)sdpMid {
  22. NSParameterAssert(sdp.length);
  23. if (self = [super init]) {
  24. _sdpMid = [sdpMid copy];
  25. _sdpMLineIndex = sdpMLineIndex;
  26. _sdp = [sdp copy];
  27. }
  28. return self;
  29. }
  30. - (NSString *)description {
  31. return [NSString stringWithFormat:@"RTCIceCandidate:\n%@\n%d\n%@\n%@",
  32. _sdpMid,
  33. _sdpMLineIndex,
  34. _sdp,
  35. _serverUrl];
  36. }
  37. #pragma mark - Private
  38. - (instancetype)initWithNativeCandidate:
  39. (const webrtc::IceCandidateInterface *)candidate {
  40. NSParameterAssert(candidate);
  41. std::string sdp;
  42. candidate->ToString(&sdp);
  43. RTCIceCandidate *rtcCandidate =
  44. [self initWithSdp:[NSString stringForStdString:sdp]
  45. sdpMLineIndex:candidate->sdp_mline_index()
  46. sdpMid:[NSString stringForStdString:candidate->sdp_mid()]];
  47. rtcCandidate->_serverUrl = [NSString stringForStdString:candidate->server_url()];
  48. return rtcCandidate;
  49. }
  50. - (std::unique_ptr<webrtc::IceCandidateInterface>)nativeCandidate {
  51. webrtc::SdpParseError error;
  52. webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
  53. _sdpMid.stdString, _sdpMLineIndex, _sdp.stdString, &error);
  54. if (!candidate) {
  55. RTCLog(@"Failed to create ICE candidate: %s\nline: %s",
  56. error.description.c_str(),
  57. error.line.c_str());
  58. }
  59. return std::unique_ptr<webrtc::IceCandidateInterface>(candidate);
  60. }
  61. @end