hjon | f396f60 | 2016-02-11 16:19:06 -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 "RTCPeerConnection+Private.h" |
| 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import "RTCConfiguration+Private.h" |
| 14 | #import "RTCDataChannel+Private.h" |
| 15 | #import "RTCIceCandidate+Private.h" |
hbos | bd3dda6 | 2016-09-09 01:36:28 -0700 | [diff] [blame] | 16 | #import "RTCLegacyStatsReport+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "RTCMediaConstraints+Private.h" |
| 18 | #import "RTCMediaStream+Private.h" |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 19 | #import "RTCMediaStreamTrack+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 20 | #import "RTCPeerConnectionFactory+Private.h" |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 21 | #import "RTCRtpReceiver+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 22 | #import "RTCRtpSender+Private.h" |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 23 | #import "RTCRtpTransceiver+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 24 | #import "RTCSessionDescription+Private.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 25 | #import "base/RTCLogging.h" |
| 26 | #import "helpers/NSString+StdString.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 27 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 28 | #include <memory> |
| 29 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "api/jsep_ice_candidate.h" |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 31 | #include "api/rtc_event_log_output_file.h" |
Yura Yaroshevich | d672535 | 2021-03-05 18:21:16 +0300 | [diff] [blame] | 32 | #include "api/set_local_description_observer_interface.h" |
| 33 | #include "api/set_remote_description_observer_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "rtc_base/checks.h" |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 35 | #include "rtc_base/numerics/safe_conversions.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 36 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 37 | NSString *const kRTCPeerConnectionErrorDomain = @"org.webrtc.RTC_OBJC_TYPE(RTCPeerConnection)"; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 38 | int const kRTCPeerConnnectionSessionDescriptionError = -1; |
| 39 | |
Yura Yaroshevich | d672535 | 2021-03-05 18:21:16 +0300 | [diff] [blame] | 40 | typedef void (^RTCSetSessionDescriptionCompletionHandler)(NSError *_Nullable error); |
| 41 | |
| 42 | namespace { |
| 43 | |
| 44 | class SetSessionDescriptionObserver : public webrtc::SetLocalDescriptionObserverInterface, |
| 45 | public webrtc::SetRemoteDescriptionObserverInterface { |
| 46 | public: |
| 47 | SetSessionDescriptionObserver( |
| 48 | RTCSetSessionDescriptionCompletionHandler _Nullable completionHandler) { |
| 49 | completion_handler_ = completionHandler; |
| 50 | } |
| 51 | |
| 52 | virtual void OnSetLocalDescriptionComplete(webrtc::RTCError error) override { |
| 53 | if (completion_handler_ != nil) { |
| 54 | OnCompelete(error); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | virtual void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override { |
| 59 | if (completion_handler_ != nil) { |
| 60 | OnCompelete(error); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | void OnCompelete(webrtc::RTCError error) { |
| 66 | RTC_DCHECK(completion_handler_); |
| 67 | if (error.ok()) { |
| 68 | completion_handler_(nil); |
| 69 | } else { |
| 70 | // TODO(hta): Add handling of error.type() |
| 71 | NSString *str = [NSString stringForStdString:error.message()]; |
| 72 | NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain |
| 73 | code:kRTCPeerConnnectionSessionDescriptionError |
| 74 | userInfo:@{NSLocalizedDescriptionKey : str}]; |
| 75 | completion_handler_(err); |
| 76 | } |
| 77 | completion_handler_ = nil; |
| 78 | } |
| 79 | RTCSetSessionDescriptionCompletionHandler completion_handler_; |
| 80 | }; |
| 81 | |
| 82 | } // anonymous namespace |
| 83 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 84 | namespace webrtc { |
| 85 | |
| 86 | class CreateSessionDescriptionObserverAdapter |
| 87 | : public CreateSessionDescriptionObserver { |
| 88 | public: |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 89 | CreateSessionDescriptionObserverAdapter(void (^completionHandler)( |
| 90 | RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, NSError *error)) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 91 | completion_handler_ = completionHandler; |
| 92 | } |
| 93 | |
Mirko Bonadei | 17aff35 | 2018-07-26 12:20:40 +0200 | [diff] [blame] | 94 | ~CreateSessionDescriptionObserverAdapter() override { completion_handler_ = nil; } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 95 | |
| 96 | void OnSuccess(SessionDescriptionInterface *desc) override { |
| 97 | RTC_DCHECK(completion_handler_); |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 98 | std::unique_ptr<webrtc::SessionDescriptionInterface> description = |
| 99 | std::unique_ptr<webrtc::SessionDescriptionInterface>(desc); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 100 | RTC_OBJC_TYPE(RTCSessionDescription) *session = |
| 101 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description.get()]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 102 | completion_handler_(session, nil); |
| 103 | completion_handler_ = nil; |
| 104 | } |
| 105 | |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 106 | void OnFailure(RTCError error) override { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 107 | RTC_DCHECK(completion_handler_); |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 108 | // TODO(hta): Add handling of error.type() |
| 109 | NSString *str = [NSString stringForStdString:error.message()]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 110 | NSError* err = |
| 111 | [NSError errorWithDomain:kRTCPeerConnectionErrorDomain |
| 112 | code:kRTCPeerConnnectionSessionDescriptionError |
| 113 | userInfo:@{ NSLocalizedDescriptionKey : str }]; |
| 114 | completion_handler_(nil, err); |
| 115 | completion_handler_ = nil; |
| 116 | } |
| 117 | |
| 118 | private: |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 119 | void (^completion_handler_)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 120 | NSError *error); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 123 | PeerConnectionDelegateAdapter::PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) * |
| 124 | peerConnection) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 125 | peer_connection_ = peerConnection; |
| 126 | } |
| 127 | |
| 128 | PeerConnectionDelegateAdapter::~PeerConnectionDelegateAdapter() { |
| 129 | peer_connection_ = nil; |
| 130 | } |
| 131 | |
| 132 | void PeerConnectionDelegateAdapter::OnSignalingChange( |
| 133 | PeerConnectionInterface::SignalingState new_state) { |
| 134 | RTCSignalingState state = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 135 | [[RTC_OBJC_TYPE(RTCPeerConnection) class] signalingStateForNativeState:new_state]; |
| 136 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 137 | [peer_connection.delegate peerConnection:peer_connection |
| 138 | didChangeSignalingState:state]; |
| 139 | } |
| 140 | |
| 141 | void PeerConnectionDelegateAdapter::OnAddStream( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 142 | rtc::scoped_refptr<MediaStreamInterface> stream) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 143 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 144 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 145 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 146 | nativeMediaStream:stream]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 147 | [peer_connection.delegate peerConnection:peer_connection |
| 148 | didAddStream:mediaStream]; |
| 149 | } |
| 150 | |
| 151 | void PeerConnectionDelegateAdapter::OnRemoveStream( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 152 | rtc::scoped_refptr<MediaStreamInterface> stream) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 153 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 154 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 155 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 156 | nativeMediaStream:stream]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 157 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 158 | [peer_connection.delegate peerConnection:peer_connection |
| 159 | didRemoveStream:mediaStream]; |
| 160 | } |
| 161 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 162 | void PeerConnectionDelegateAdapter::OnTrack( |
| 163 | rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 164 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 165 | RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = |
| 166 | [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:peer_connection.factory |
| 167 | nativeRtpTransceiver:nativeTransceiver]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 168 | if ([peer_connection.delegate |
| 169 | respondsToSelector:@selector(peerConnection:didStartReceivingOnTransceiver:)]) { |
| 170 | [peer_connection.delegate peerConnection:peer_connection |
| 171 | didStartReceivingOnTransceiver:transceiver]; |
| 172 | } |
| 173 | } |
| 174 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 175 | void PeerConnectionDelegateAdapter::OnDataChannel( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 176 | rtc::scoped_refptr<DataChannelInterface> data_channel) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 177 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 178 | RTC_OBJC_TYPE(RTCDataChannel) *dataChannel = |
| 179 | [[RTC_OBJC_TYPE(RTCDataChannel) alloc] initWithFactory:peer_connection.factory |
| 180 | nativeDataChannel:data_channel]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 181 | [peer_connection.delegate peerConnection:peer_connection |
| 182 | didOpenDataChannel:dataChannel]; |
| 183 | } |
| 184 | |
| 185 | void PeerConnectionDelegateAdapter::OnRenegotiationNeeded() { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 186 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 187 | [peer_connection.delegate peerConnectionShouldNegotiate:peer_connection]; |
| 188 | } |
| 189 | |
| 190 | void PeerConnectionDelegateAdapter::OnIceConnectionChange( |
| 191 | PeerConnectionInterface::IceConnectionState new_state) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 192 | RTCIceConnectionState state = |
| 193 | [RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 194 | [peer_connection_.delegate peerConnection:peer_connection_ didChangeIceConnectionState:state]; |
| 195 | } |
| 196 | |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 197 | void PeerConnectionDelegateAdapter::OnStandardizedIceConnectionChange( |
| 198 | PeerConnectionInterface::IceConnectionState new_state) { |
| 199 | if ([peer_connection_.delegate |
| 200 | respondsToSelector:@selector(peerConnection:didChangeStandardizedIceConnectionState:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 201 | RTCIceConnectionState state = |
| 202 | [RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 203 | [peer_connection_.delegate peerConnection:peer_connection_ |
| 204 | didChangeStandardizedIceConnectionState:state]; |
| 205 | } |
| 206 | } |
| 207 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 208 | void PeerConnectionDelegateAdapter::OnConnectionChange( |
| 209 | PeerConnectionInterface::PeerConnectionState new_state) { |
| 210 | if ([peer_connection_.delegate |
| 211 | respondsToSelector:@selector(peerConnection:didChangeConnectionState:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 212 | RTCPeerConnectionState state = |
| 213 | [RTC_OBJC_TYPE(RTCPeerConnection) connectionStateForNativeState:new_state]; |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 214 | [peer_connection_.delegate peerConnection:peer_connection_ didChangeConnectionState:state]; |
| 215 | } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void PeerConnectionDelegateAdapter::OnIceGatheringChange( |
| 219 | PeerConnectionInterface::IceGatheringState new_state) { |
| 220 | RTCIceGatheringState state = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 221 | [[RTC_OBJC_TYPE(RTCPeerConnection) class] iceGatheringStateForNativeState:new_state]; |
| 222 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 223 | [peer_connection.delegate peerConnection:peer_connection |
| 224 | didChangeIceGatheringState:state]; |
| 225 | } |
| 226 | |
| 227 | void PeerConnectionDelegateAdapter::OnIceCandidate( |
| 228 | const IceCandidateInterface *candidate) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 229 | RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = |
| 230 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:candidate]; |
| 231 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 232 | [peer_connection.delegate peerConnection:peer_connection |
| 233 | didGenerateIceCandidate:iceCandidate]; |
| 234 | } |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 235 | |
| 236 | void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( |
| 237 | const std::vector<cricket::Candidate>& candidates) { |
| 238 | NSMutableArray* ice_candidates = |
| 239 | [NSMutableArray arrayWithCapacity:candidates.size()]; |
| 240 | for (const auto& candidate : candidates) { |
| 241 | std::unique_ptr<JsepIceCandidate> candidate_wrapper( |
| 242 | new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 243 | RTC_OBJC_TYPE(RTCIceCandidate) *ice_candidate = |
| 244 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:candidate_wrapper.get()]; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 245 | [ice_candidates addObject:ice_candidate]; |
| 246 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 247 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 248 | [peer_connection.delegate peerConnection:peer_connection |
| 249 | didRemoveIceCandidates:ice_candidates]; |
| 250 | } |
| 251 | |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 252 | void PeerConnectionDelegateAdapter::OnIceSelectedCandidatePairChanged( |
| 253 | const cricket::CandidatePairChangeEvent &event) { |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 254 | const auto &selected_pair = event.selected_candidate_pair; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 255 | auto local_candidate_wrapper = std::make_unique<JsepIceCandidate>( |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 256 | selected_pair.local_candidate().transport_name(), -1, selected_pair.local_candidate()); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 257 | RTC_OBJC_TYPE(RTCIceCandidate) *local_candidate = [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] |
| 258 | initWithNativeCandidate:local_candidate_wrapper.release()]; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 259 | auto remote_candidate_wrapper = std::make_unique<JsepIceCandidate>( |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 260 | selected_pair.remote_candidate().transport_name(), -1, selected_pair.remote_candidate()); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 261 | RTC_OBJC_TYPE(RTCIceCandidate) *remote_candidate = [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] |
| 262 | initWithNativeCandidate:remote_candidate_wrapper.release()]; |
| 263 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 264 | NSString *nsstr_reason = [NSString stringForStdString:event.reason]; |
| 265 | if ([peer_connection.delegate |
| 266 | respondsToSelector:@selector |
| 267 | (peerConnection:didChangeLocalCandidate:remoteCandidate:lastReceivedMs:changeReason:)]) { |
| 268 | [peer_connection.delegate peerConnection:peer_connection |
| 269 | didChangeLocalCandidate:local_candidate |
| 270 | remoteCandidate:remote_candidate |
| 271 | lastReceivedMs:event.last_data_received_ms |
| 272 | changeReason:nsstr_reason]; |
| 273 | } |
| 274 | } |
| 275 | |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 276 | void PeerConnectionDelegateAdapter::OnAddTrack( |
| 277 | rtc::scoped_refptr<RtpReceiverInterface> receiver, |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 278 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 279 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 280 | if ([peer_connection.delegate respondsToSelector:@selector(peerConnection: |
| 281 | didAddReceiver:streams:)]) { |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 282 | NSMutableArray *mediaStreams = [NSMutableArray arrayWithCapacity:streams.size()]; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 283 | for (const auto &nativeStream : streams) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 284 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 285 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 286 | nativeMediaStream:nativeStream]; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 287 | [mediaStreams addObject:mediaStream]; |
| 288 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 289 | RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = |
| 290 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory |
| 291 | nativeRtpReceiver:receiver]; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 292 | |
| 293 | [peer_connection.delegate peerConnection:peer_connection |
| 294 | didAddReceiver:rtpReceiver |
| 295 | streams:mediaStreams]; |
| 296 | } |
| 297 | } |
| 298 | |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 299 | void PeerConnectionDelegateAdapter::OnRemoveTrack( |
| 300 | rtc::scoped_refptr<RtpReceiverInterface> receiver) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 301 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 302 | if ([peer_connection.delegate respondsToSelector:@selector(peerConnection:didRemoveReceiver:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 303 | RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = |
| 304 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory |
| 305 | nativeRtpReceiver:receiver]; |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 306 | [peer_connection.delegate peerConnection:peer_connection didRemoveReceiver:rtpReceiver]; |
| 307 | } |
| 308 | } |
| 309 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 310 | } // namespace webrtc |
| 311 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 312 | @implementation RTC_OBJC_TYPE (RTCPeerConnection) { |
| 313 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * _factory; |
| 314 | NSMutableArray<RTC_OBJC_TYPE(RTCMediaStream) *> *_localStreams; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 315 | std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 316 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 317 | std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 318 | BOOL _hasStartedRtcEventLog; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @synthesize delegate = _delegate; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 322 | @synthesize factory = _factory; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 323 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 324 | - (nullable instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
| 325 | configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration |
| 326 | constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 327 | delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 328 | NSParameterAssert(factory); |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 329 | std::unique_ptr<webrtc::PeerConnectionDependencies> dependencies = |
| 330 | std::make_unique<webrtc::PeerConnectionDependencies>(nullptr); |
| 331 | return [self initWithDependencies:factory |
| 332 | configuration:configuration |
| 333 | constraints:constraints |
| 334 | dependencies:std::move(dependencies) |
| 335 | delegate:delegate]; |
| 336 | } |
| 337 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 338 | - (nullable instancetype) |
| 339 | initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
| 340 | configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration |
| 341 | constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 342 | dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies |
| 343 | delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 344 | NSParameterAssert(factory); |
| 345 | NSParameterAssert(dependencies.get()); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 346 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 347 | [configuration createNativeConfiguration]); |
| 348 | if (!config) { |
| 349 | return nil; |
| 350 | } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 351 | if (self = [super init]) { |
| 352 | _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 353 | _nativeConstraints = constraints.nativeConstraints; |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 354 | CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), config.get()); |
| 355 | |
| 356 | webrtc::PeerConnectionDependencies deps = std::move(*dependencies.release()); |
| 357 | deps.observer = _observer.get(); |
| 358 | _peerConnection = factory.nativeFactory->CreatePeerConnection(*config, std::move(deps)); |
| 359 | |
skvlad | 588783a | 2016-08-11 14:29:25 -0700 | [diff] [blame] | 360 | if (!_peerConnection) { |
| 361 | return nil; |
| 362 | } |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 363 | _factory = factory; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 364 | _localStreams = [[NSMutableArray alloc] init]; |
| 365 | _delegate = delegate; |
| 366 | } |
| 367 | return self; |
| 368 | } |
| 369 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 370 | - (NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *)localStreams { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 371 | return [_localStreams copy]; |
| 372 | } |
| 373 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 374 | - (RTC_OBJC_TYPE(RTCSessionDescription) *)localDescription { |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame] | 375 | // It's only safe to operate on SessionDescriptionInterface on the signaling thread. |
| 376 | return _peerConnection->signaling_thread()->Invoke<RTC_OBJC_TYPE(RTCSessionDescription) *>( |
| 377 | RTC_FROM_HERE, [self] { |
| 378 | const webrtc::SessionDescriptionInterface *description = |
| 379 | _peerConnection->local_description(); |
| 380 | return description ? |
| 381 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 382 | nil; |
| 383 | }); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 386 | - (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription { |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame] | 387 | // It's only safe to operate on SessionDescriptionInterface on the signaling thread. |
| 388 | return _peerConnection->signaling_thread()->Invoke<RTC_OBJC_TYPE(RTCSessionDescription) *>( |
| 389 | RTC_FROM_HERE, [self] { |
| 390 | const webrtc::SessionDescriptionInterface *description = |
| 391 | _peerConnection->remote_description(); |
| 392 | return description ? |
| 393 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 394 | nil; |
| 395 | }); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | - (RTCSignalingState)signalingState { |
| 399 | return [[self class] |
| 400 | signalingStateForNativeState:_peerConnection->signaling_state()]; |
| 401 | } |
| 402 | |
| 403 | - (RTCIceConnectionState)iceConnectionState { |
| 404 | return [[self class] iceConnectionStateForNativeState: |
| 405 | _peerConnection->ice_connection_state()]; |
| 406 | } |
| 407 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 408 | - (RTCPeerConnectionState)connectionState { |
| 409 | return [[self class] connectionStateForNativeState:_peerConnection->peer_connection_state()]; |
| 410 | } |
| 411 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 412 | - (RTCIceGatheringState)iceGatheringState { |
| 413 | return [[self class] iceGatheringStateForNativeState: |
| 414 | _peerConnection->ice_gathering_state()]; |
| 415 | } |
| 416 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 417 | - (BOOL)setConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 418 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 419 | [configuration createNativeConfiguration]); |
| 420 | if (!config) { |
| 421 | return NO; |
| 422 | } |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 423 | CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), |
| 424 | config.get()); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 425 | return _peerConnection->SetConfiguration(*config).ok(); |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 428 | - (RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 429 | webrtc::PeerConnectionInterface::RTCConfiguration config = |
| 430 | _peerConnection->GetConfiguration(); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 431 | return [[RTC_OBJC_TYPE(RTCConfiguration) alloc] initWithNativeConfiguration:config]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 432 | } |
| 433 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 434 | - (void)close { |
| 435 | _peerConnection->Close(); |
| 436 | } |
| 437 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 438 | - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate { |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 439 | std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 440 | candidate.nativeCandidate); |
| 441 | _peerConnection->AddIceCandidate(iceCandidate.get()); |
| 442 | } |
| 443 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 444 | - (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 445 | std::vector<cricket::Candidate> candidates; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 446 | for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 447 | std::unique_ptr<const webrtc::IceCandidateInterface> candidate( |
| 448 | iceCandidate.nativeCandidate); |
| 449 | if (candidate) { |
| 450 | candidates.push_back(candidate->candidate()); |
| 451 | // Need to fill the transport name from the sdp_mid. |
| 452 | candidates.back().set_transport_name(candidate->sdp_mid()); |
| 453 | } |
| 454 | } |
| 455 | if (!candidates.empty()) { |
| 456 | _peerConnection->RemoveIceCandidates(candidates); |
| 457 | } |
| 458 | } |
| 459 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 460 | - (void)addStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 461 | if (!_peerConnection->AddStream(stream.nativeMediaStream)) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 462 | RTCLogError(@"Failed to add stream: %@", stream); |
| 463 | return; |
| 464 | } |
| 465 | [_localStreams addObject:stream]; |
| 466 | } |
| 467 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 468 | - (void)removeStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 469 | _peerConnection->RemoveStream(stream.nativeMediaStream); |
| 470 | [_localStreams removeObject:stream]; |
| 471 | } |
| 472 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 473 | - (nullable RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 474 | streamIds:(NSArray<NSString *> *)streamIds { |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 475 | std::vector<std::string> nativeStreamIds; |
| 476 | for (NSString *streamId in streamIds) { |
| 477 | nativeStreamIds.push_back([streamId UTF8String]); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 478 | } |
| 479 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenderOrError = |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 480 | _peerConnection->AddTrack(track.nativeTrack, nativeStreamIds); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 481 | if (!nativeSenderOrError.ok()) { |
| 482 | RTCLogError(@"Failed to add track %@: %s", track, nativeSenderOrError.error().message()); |
| 483 | return nil; |
| 484 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 485 | return [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 486 | nativeRtpSender:nativeSenderOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 489 | - (BOOL)removeTrack:(RTC_OBJC_TYPE(RTCRtpSender) *)sender { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 490 | bool result = _peerConnection->RemoveTrack(sender.nativeRtpSender); |
| 491 | if (!result) { |
| 492 | RTCLogError(@"Failed to remote track %@", sender); |
| 493 | } |
| 494 | return result; |
| 495 | } |
| 496 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 497 | - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverWithTrack: |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 498 | (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { |
| 499 | return [self addTransceiverWithTrack:track |
| 500 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 503 | - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *) |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 504 | addTransceiverWithTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 505 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 506 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
| 507 | _peerConnection->AddTransceiver(track.nativeTrack, init.nativeInit); |
| 508 | if (!nativeTransceiverOrError.ok()) { |
| 509 | RTCLogError( |
| 510 | @"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message()); |
| 511 | return nil; |
| 512 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 513 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 514 | initWithFactory:self.factory |
| 515 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 518 | - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 519 | return [self addTransceiverOfType:mediaType |
| 520 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Yura Yaroshevich | d140c8f | 2021-03-02 23:25:10 +0300 | [diff] [blame] | 523 | - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *) |
| 524 | addTransceiverOfType:(RTCRtpMediaType)mediaType |
| 525 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 526 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 527 | _peerConnection->AddTransceiver( |
| 528 | [RTC_OBJC_TYPE(RTCRtpReceiver) nativeMediaTypeForMediaType:mediaType], init.nativeInit); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 529 | if (!nativeTransceiverOrError.ok()) { |
| 530 | RTCLogError(@"Failed to add transceiver %@: %s", |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 531 | [RTC_OBJC_TYPE(RTCRtpReceiver) stringForMediaType:mediaType], |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 532 | nativeTransceiverOrError.error().message()); |
| 533 | return nil; |
| 534 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 535 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 536 | initWithFactory:self.factory |
| 537 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Yura Yaroshevich | 92d1270 | 2021-03-06 23:55:17 +0300 | [diff] [blame^] | 540 | - (void)restartIce { |
| 541 | _peerConnection->RestartIce(); |
| 542 | } |
| 543 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 544 | - (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 545 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 546 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 547 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 548 | observer(new rtc::RefCountedObject |
| 549 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 550 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 551 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 552 | |
| 553 | _peerConnection->CreateOffer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 556 | - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 557 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 558 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 559 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 560 | observer(new rtc::RefCountedObject |
| 561 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 562 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 563 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 564 | |
| 565 | _peerConnection->CreateAnswer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 566 | } |
| 567 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 568 | - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp |
Yura Yaroshevich | d672535 | 2021-03-05 18:21:16 +0300 | [diff] [blame] | 569 | completionHandler:(nullable void (^)(NSError *error))completionHandler { |
| 570 | rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer( |
| 571 | new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler)); |
| 572 | _peerConnection->SetLocalDescription(sdp.nativeDescription->Clone(), observer); |
| 573 | } |
| 574 | |
| 575 | - (void)setLocalDescriptionWithCompletionHandler: |
| 576 | (nullable void (^)(NSError *error))completionHandler { |
| 577 | rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer( |
| 578 | new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler)); |
| 579 | _peerConnection->SetLocalDescription(observer); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 582 | - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp |
Yura Yaroshevich | d672535 | 2021-03-05 18:21:16 +0300 | [diff] [blame] | 583 | completionHandler:(nullable void (^)(NSError *error))completionHandler { |
| 584 | rtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface> observer( |
| 585 | new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler)); |
| 586 | _peerConnection->SetRemoteDescription(sdp.nativeDescription->Clone(), observer); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 587 | } |
| 588 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 589 | - (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps |
| 590 | currentBitrateBps:(nullable NSNumber *)currentBitrateBps |
| 591 | maxBitrateBps:(nullable NSNumber *)maxBitrateBps { |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 592 | webrtc::BitrateSettings params; |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 593 | if (minBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 594 | params.min_bitrate_bps = absl::optional<int>(minBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 595 | } |
| 596 | if (currentBitrateBps != nil) { |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 597 | params.start_bitrate_bps = absl::optional<int>(currentBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 598 | } |
| 599 | if (maxBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 600 | params.max_bitrate_bps = absl::optional<int>(maxBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 601 | } |
| 602 | return _peerConnection->SetBitrate(params).ok(); |
| 603 | } |
| 604 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 605 | - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath |
| 606 | maxSizeInBytes:(int64_t)maxSizeInBytes { |
| 607 | RTC_DCHECK(filePath.length); |
| 608 | RTC_DCHECK_GT(maxSizeInBytes, 0); |
| 609 | RTC_DCHECK(!_hasStartedRtcEventLog); |
| 610 | if (_hasStartedRtcEventLog) { |
| 611 | RTCLogError(@"Event logging already started."); |
| 612 | return NO; |
| 613 | } |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 614 | FILE *f = fopen(filePath.UTF8String, "wb"); |
| 615 | if (!f) { |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 616 | RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
| 617 | return NO; |
| 618 | } |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 619 | // TODO(eladalon): It would be better to not allow negative values into PC. |
| 620 | const size_t max_size = (maxSizeInBytes < 0) ? webrtc::RtcEventLog::kUnlimitedOutput : |
| 621 | rtc::saturated_cast<size_t>(maxSizeInBytes); |
| 622 | |
| 623 | _hasStartedRtcEventLog = _peerConnection->StartRtcEventLog( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 624 | std::make_unique<webrtc::RtcEventLogOutputFile>(f, max_size)); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 625 | return _hasStartedRtcEventLog; |
| 626 | } |
| 627 | |
| 628 | - (void)stopRtcEventLog { |
| 629 | _peerConnection->StopRtcEventLog(); |
| 630 | _hasStartedRtcEventLog = NO; |
| 631 | } |
| 632 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 633 | - (RTC_OBJC_TYPE(RTCRtpSender) *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId { |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 634 | std::string nativeKind = [NSString stdStringForString:kind]; |
| 635 | std::string nativeStreamId = [NSString stdStringForString:streamId]; |
| 636 | rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender( |
| 637 | _peerConnection->CreateSender(nativeKind, nativeStreamId)); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 638 | return nativeSender ? [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 639 | nativeRtpSender:nativeSender] : |
| 640 | nil; |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 643 | - (NSArray<RTC_OBJC_TYPE(RTCRtpSender) *> *)senders { |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 644 | std::vector<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenders( |
| 645 | _peerConnection->GetSenders()); |
| 646 | NSMutableArray *senders = [[NSMutableArray alloc] init]; |
| 647 | for (const auto &nativeSender : nativeSenders) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 648 | RTC_OBJC_TYPE(RTCRtpSender) *sender = |
| 649 | [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 650 | nativeRtpSender:nativeSender]; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 651 | [senders addObject:sender]; |
| 652 | } |
| 653 | return senders; |
| 654 | } |
| 655 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 656 | - (NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *)receivers { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 657 | std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> nativeReceivers( |
| 658 | _peerConnection->GetReceivers()); |
| 659 | NSMutableArray *receivers = [[NSMutableArray alloc] init]; |
| 660 | for (const auto &nativeReceiver : nativeReceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 661 | RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = |
| 662 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:self.factory |
| 663 | nativeRtpReceiver:nativeReceiver]; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 664 | [receivers addObject:receiver]; |
| 665 | } |
| 666 | return receivers; |
| 667 | } |
| 668 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 669 | - (NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *)transceivers { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 670 | std::vector<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceivers( |
| 671 | _peerConnection->GetTransceivers()); |
| 672 | NSMutableArray *transceivers = [[NSMutableArray alloc] init]; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 673 | for (const auto &nativeTransceiver : nativeTransceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 674 | RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = |
| 675 | [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:self.factory |
| 676 | nativeRtpTransceiver:nativeTransceiver]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 677 | [transceivers addObject:transceiver]; |
| 678 | } |
| 679 | return transceivers; |
| 680 | } |
| 681 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 682 | #pragma mark - Private |
| 683 | |
| 684 | + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: |
| 685 | (RTCSignalingState)state { |
| 686 | switch (state) { |
| 687 | case RTCSignalingStateStable: |
| 688 | return webrtc::PeerConnectionInterface::kStable; |
| 689 | case RTCSignalingStateHaveLocalOffer: |
| 690 | return webrtc::PeerConnectionInterface::kHaveLocalOffer; |
| 691 | case RTCSignalingStateHaveLocalPrAnswer: |
| 692 | return webrtc::PeerConnectionInterface::kHaveLocalPrAnswer; |
| 693 | case RTCSignalingStateHaveRemoteOffer: |
| 694 | return webrtc::PeerConnectionInterface::kHaveRemoteOffer; |
| 695 | case RTCSignalingStateHaveRemotePrAnswer: |
| 696 | return webrtc::PeerConnectionInterface::kHaveRemotePrAnswer; |
| 697 | case RTCSignalingStateClosed: |
| 698 | return webrtc::PeerConnectionInterface::kClosed; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | + (RTCSignalingState)signalingStateForNativeState: |
| 703 | (webrtc::PeerConnectionInterface::SignalingState)nativeState { |
| 704 | switch (nativeState) { |
| 705 | case webrtc::PeerConnectionInterface::kStable: |
| 706 | return RTCSignalingStateStable; |
| 707 | case webrtc::PeerConnectionInterface::kHaveLocalOffer: |
| 708 | return RTCSignalingStateHaveLocalOffer; |
| 709 | case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: |
| 710 | return RTCSignalingStateHaveLocalPrAnswer; |
| 711 | case webrtc::PeerConnectionInterface::kHaveRemoteOffer: |
| 712 | return RTCSignalingStateHaveRemoteOffer; |
| 713 | case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: |
| 714 | return RTCSignalingStateHaveRemotePrAnswer; |
| 715 | case webrtc::PeerConnectionInterface::kClosed: |
| 716 | return RTCSignalingStateClosed; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | + (NSString *)stringForSignalingState:(RTCSignalingState)state { |
| 721 | switch (state) { |
| 722 | case RTCSignalingStateStable: |
| 723 | return @"STABLE"; |
| 724 | case RTCSignalingStateHaveLocalOffer: |
| 725 | return @"HAVE_LOCAL_OFFER"; |
| 726 | case RTCSignalingStateHaveLocalPrAnswer: |
| 727 | return @"HAVE_LOCAL_PRANSWER"; |
| 728 | case RTCSignalingStateHaveRemoteOffer: |
| 729 | return @"HAVE_REMOTE_OFFER"; |
| 730 | case RTCSignalingStateHaveRemotePrAnswer: |
| 731 | return @"HAVE_REMOTE_PRANSWER"; |
| 732 | case RTCSignalingStateClosed: |
| 733 | return @"CLOSED"; |
| 734 | } |
| 735 | } |
| 736 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 737 | + (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: |
| 738 | (RTCPeerConnectionState)state { |
| 739 | switch (state) { |
| 740 | case RTCPeerConnectionStateNew: |
| 741 | return webrtc::PeerConnectionInterface::PeerConnectionState::kNew; |
| 742 | case RTCPeerConnectionStateConnecting: |
| 743 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting; |
| 744 | case RTCPeerConnectionStateConnected: |
| 745 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnected; |
| 746 | case RTCPeerConnectionStateFailed: |
| 747 | return webrtc::PeerConnectionInterface::PeerConnectionState::kFailed; |
| 748 | case RTCPeerConnectionStateDisconnected: |
| 749 | return webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected; |
| 750 | case RTCPeerConnectionStateClosed: |
| 751 | return webrtc::PeerConnectionInterface::PeerConnectionState::kClosed; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | + (RTCPeerConnectionState)connectionStateForNativeState: |
| 756 | (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState { |
| 757 | switch (nativeState) { |
| 758 | case webrtc::PeerConnectionInterface::PeerConnectionState::kNew: |
| 759 | return RTCPeerConnectionStateNew; |
| 760 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting: |
| 761 | return RTCPeerConnectionStateConnecting; |
| 762 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected: |
| 763 | return RTCPeerConnectionStateConnected; |
| 764 | case webrtc::PeerConnectionInterface::PeerConnectionState::kFailed: |
| 765 | return RTCPeerConnectionStateFailed; |
| 766 | case webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected: |
| 767 | return RTCPeerConnectionStateDisconnected; |
| 768 | case webrtc::PeerConnectionInterface::PeerConnectionState::kClosed: |
| 769 | return RTCPeerConnectionStateClosed; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state { |
| 774 | switch (state) { |
| 775 | case RTCPeerConnectionStateNew: |
| 776 | return @"NEW"; |
| 777 | case RTCPeerConnectionStateConnecting: |
| 778 | return @"CONNECTING"; |
| 779 | case RTCPeerConnectionStateConnected: |
| 780 | return @"CONNECTED"; |
| 781 | case RTCPeerConnectionStateFailed: |
| 782 | return @"FAILED"; |
| 783 | case RTCPeerConnectionStateDisconnected: |
| 784 | return @"DISCONNECTED"; |
| 785 | case RTCPeerConnectionStateClosed: |
| 786 | return @"CLOSED"; |
| 787 | } |
| 788 | } |
| 789 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 790 | + (webrtc::PeerConnectionInterface::IceConnectionState) |
| 791 | nativeIceConnectionStateForState:(RTCIceConnectionState)state { |
| 792 | switch (state) { |
| 793 | case RTCIceConnectionStateNew: |
| 794 | return webrtc::PeerConnectionInterface::kIceConnectionNew; |
| 795 | case RTCIceConnectionStateChecking: |
| 796 | return webrtc::PeerConnectionInterface::kIceConnectionChecking; |
| 797 | case RTCIceConnectionStateConnected: |
| 798 | return webrtc::PeerConnectionInterface::kIceConnectionConnected; |
| 799 | case RTCIceConnectionStateCompleted: |
| 800 | return webrtc::PeerConnectionInterface::kIceConnectionCompleted; |
| 801 | case RTCIceConnectionStateFailed: |
| 802 | return webrtc::PeerConnectionInterface::kIceConnectionFailed; |
| 803 | case RTCIceConnectionStateDisconnected: |
| 804 | return webrtc::PeerConnectionInterface::kIceConnectionDisconnected; |
| 805 | case RTCIceConnectionStateClosed: |
| 806 | return webrtc::PeerConnectionInterface::kIceConnectionClosed; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 807 | case RTCIceConnectionStateCount: |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 808 | return webrtc::PeerConnectionInterface::kIceConnectionMax; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | + (RTCIceConnectionState)iceConnectionStateForNativeState: |
| 813 | (webrtc::PeerConnectionInterface::IceConnectionState)nativeState { |
| 814 | switch (nativeState) { |
| 815 | case webrtc::PeerConnectionInterface::kIceConnectionNew: |
| 816 | return RTCIceConnectionStateNew; |
| 817 | case webrtc::PeerConnectionInterface::kIceConnectionChecking: |
| 818 | return RTCIceConnectionStateChecking; |
| 819 | case webrtc::PeerConnectionInterface::kIceConnectionConnected: |
| 820 | return RTCIceConnectionStateConnected; |
| 821 | case webrtc::PeerConnectionInterface::kIceConnectionCompleted: |
| 822 | return RTCIceConnectionStateCompleted; |
| 823 | case webrtc::PeerConnectionInterface::kIceConnectionFailed: |
| 824 | return RTCIceConnectionStateFailed; |
| 825 | case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: |
| 826 | return RTCIceConnectionStateDisconnected; |
| 827 | case webrtc::PeerConnectionInterface::kIceConnectionClosed: |
| 828 | return RTCIceConnectionStateClosed; |
| 829 | case webrtc::PeerConnectionInterface::kIceConnectionMax: |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 830 | return RTCIceConnectionStateCount; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | |
| 834 | + (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state { |
| 835 | switch (state) { |
| 836 | case RTCIceConnectionStateNew: |
| 837 | return @"NEW"; |
| 838 | case RTCIceConnectionStateChecking: |
| 839 | return @"CHECKING"; |
| 840 | case RTCIceConnectionStateConnected: |
| 841 | return @"CONNECTED"; |
| 842 | case RTCIceConnectionStateCompleted: |
| 843 | return @"COMPLETED"; |
| 844 | case RTCIceConnectionStateFailed: |
| 845 | return @"FAILED"; |
| 846 | case RTCIceConnectionStateDisconnected: |
| 847 | return @"DISCONNECTED"; |
| 848 | case RTCIceConnectionStateClosed: |
| 849 | return @"CLOSED"; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 850 | case RTCIceConnectionStateCount: |
| 851 | return @"COUNT"; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
| 855 | + (webrtc::PeerConnectionInterface::IceGatheringState) |
| 856 | nativeIceGatheringStateForState:(RTCIceGatheringState)state { |
| 857 | switch (state) { |
| 858 | case RTCIceGatheringStateNew: |
| 859 | return webrtc::PeerConnectionInterface::kIceGatheringNew; |
| 860 | case RTCIceGatheringStateGathering: |
| 861 | return webrtc::PeerConnectionInterface::kIceGatheringGathering; |
| 862 | case RTCIceGatheringStateComplete: |
| 863 | return webrtc::PeerConnectionInterface::kIceGatheringComplete; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | + (RTCIceGatheringState)iceGatheringStateForNativeState: |
| 868 | (webrtc::PeerConnectionInterface::IceGatheringState)nativeState { |
| 869 | switch (nativeState) { |
| 870 | case webrtc::PeerConnectionInterface::kIceGatheringNew: |
| 871 | return RTCIceGatheringStateNew; |
| 872 | case webrtc::PeerConnectionInterface::kIceGatheringGathering: |
| 873 | return RTCIceGatheringStateGathering; |
| 874 | case webrtc::PeerConnectionInterface::kIceGatheringComplete: |
| 875 | return RTCIceGatheringStateComplete; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state { |
| 880 | switch (state) { |
| 881 | case RTCIceGatheringStateNew: |
| 882 | return @"NEW"; |
| 883 | case RTCIceGatheringStateGathering: |
| 884 | return @"GATHERING"; |
| 885 | case RTCIceGatheringStateComplete: |
| 886 | return @"COMPLETE"; |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
| 891 | nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
| 892 | switch (level) { |
| 893 | case RTCStatsOutputLevelStandard: |
| 894 | return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
| 895 | case RTCStatsOutputLevelDebug: |
| 896 | return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
| 897 | } |
| 898 | } |
| 899 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 900 | - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
| 901 | return _peerConnection; |
| 902 | } |
| 903 | |
| 904 | @end |