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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 11 | #import "RTCPeerConnection.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "api/peer_connection_interface.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 14 | |
| 15 | NS_ASSUME_NONNULL_BEGIN |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | /** |
| 20 | * These objects are created by RTCPeerConnectionFactory to wrap an |
| 21 | * id<RTCPeerConnectionDelegate> and call methods on that interface. |
| 22 | */ |
| 23 | class PeerConnectionDelegateAdapter : public PeerConnectionObserver { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 24 | public: |
| 25 | PeerConnectionDelegateAdapter(RTCPeerConnection *peerConnection); |
Mirko Bonadei | 17aff35 | 2018-07-26 12:20:40 +0200 | [diff] [blame] | 26 | ~PeerConnectionDelegateAdapter() override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 27 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 28 | void OnSignalingChange(PeerConnectionInterface::SignalingState new_state) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 29 | |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 30 | void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 31 | |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 32 | void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 33 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 34 | void OnTrack(rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override; |
| 35 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 36 | void OnDataChannel(rtc::scoped_refptr<DataChannelInterface> data_channel) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 37 | |
| 38 | void OnRenegotiationNeeded() override; |
| 39 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 40 | void OnIceConnectionChange(PeerConnectionInterface::IceConnectionState new_state) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 41 | |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 42 | void OnStandardizedIceConnectionChange( |
| 43 | PeerConnectionInterface::IceConnectionState new_state) override; |
| 44 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 45 | void OnConnectionChange(PeerConnectionInterface::PeerConnectionState new_state) override; |
| 46 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 47 | void OnIceGatheringChange(PeerConnectionInterface::IceGatheringState new_state) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 48 | |
| 49 | void OnIceCandidate(const IceCandidateInterface *candidate) override; |
| 50 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | void OnIceCandidatesRemoved(const std::vector<cricket::Candidate> &candidates) override; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 52 | |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 53 | void OnIceSelectedCandidatePairChanged(const cricket::CandidatePairChangeEvent &event) override; |
| 54 | |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 55 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 56 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) override; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 57 | |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 58 | void OnRemoveTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver) override; |
| 59 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 60 | private: |
magjed | 63bafd6 | 2017-02-27 07:04:25 -0800 | [diff] [blame] | 61 | __weak RTCPeerConnection *peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 64 | } // namespace webrtc |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 65 | |
| 66 | @interface RTCPeerConnection () |
| 67 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 68 | /** The factory used to create this RTCPeerConnection */ |
| 69 | @property(nonatomic, readonly) RTCPeerConnectionFactory *factory; |
| 70 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 71 | /** The native PeerConnectionInterface created during construction. */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 72 | @property(nonatomic, readonly) rtc::scoped_refptr<webrtc::PeerConnectionInterface> |
| 73 | nativePeerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 74 | |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame] | 75 | /** Initialize an RTCPeerConnection with a configuration, constraints, and |
| 76 | * delegate. |
| 77 | */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 78 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 79 | configuration:(RTCConfiguration *)configuration |
| 80 | constraints:(RTCMediaConstraints *)constraints |
| 81 | delegate:(nullable id<RTCPeerConnectionDelegate>)delegate |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame] | 82 | NS_DESIGNATED_INITIALIZER; |
| 83 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 84 | + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 85 | (RTCSignalingState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 86 | |
| 87 | + (RTCSignalingState)signalingStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 88 | (webrtc::PeerConnectionInterface::SignalingState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 89 | |
| 90 | + (NSString *)stringForSignalingState:(RTCSignalingState)state; |
| 91 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 92 | + (webrtc::PeerConnectionInterface::IceConnectionState)nativeIceConnectionStateForState: |
| 93 | (RTCIceConnectionState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 94 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 95 | + (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: |
| 96 | (RTCPeerConnectionState)state; |
| 97 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 98 | + (RTCIceConnectionState)iceConnectionStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | (webrtc::PeerConnectionInterface::IceConnectionState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 100 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 101 | + (RTCPeerConnectionState)connectionStateForNativeState: |
| 102 | (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState; |
| 103 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 104 | + (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state; |
| 105 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 106 | + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state; |
| 107 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 108 | + (webrtc::PeerConnectionInterface::IceGatheringState)nativeIceGatheringStateForState: |
| 109 | (RTCIceGatheringState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 110 | |
| 111 | + (RTCIceGatheringState)iceGatheringStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 112 | (webrtc::PeerConnectionInterface::IceGatheringState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 113 | |
| 114 | + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state; |
| 115 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 116 | + (webrtc::PeerConnectionInterface::StatsOutputLevel)nativeStatsOutputLevelForLevel: |
| 117 | (RTCStatsOutputLevel)level; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 118 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 119 | @end |
| 120 | |
| 121 | NS_ASSUME_NONNULL_END |