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