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