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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "api/peerconnectioninterface.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 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 42 | void OnConnectionChange(PeerConnectionInterface::PeerConnectionState new_state) override; |
| 43 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 44 | void OnIceGatheringChange(PeerConnectionInterface::IceGatheringState new_state) override; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 45 | |
| 46 | void OnIceCandidate(const IceCandidateInterface *candidate) override; |
| 47 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 48 | void OnIceCandidatesRemoved(const std::vector<cricket::Candidate> &candidates) override; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 49 | |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 50 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) override; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 52 | |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 53 | void OnRemoveTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver) override; |
| 54 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 55 | private: |
magjed | 63bafd6 | 2017-02-27 07:04:25 -0800 | [diff] [blame] | 56 | __weak RTCPeerConnection *peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 59 | } // namespace webrtc |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 60 | |
| 61 | @interface RTCPeerConnection () |
| 62 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 63 | /** The factory used to create this RTCPeerConnection */ |
| 64 | @property(nonatomic, readonly) RTCPeerConnectionFactory *factory; |
| 65 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 66 | /** The native PeerConnectionInterface created during construction. */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 67 | @property(nonatomic, readonly) rtc::scoped_refptr<webrtc::PeerConnectionInterface> |
| 68 | nativePeerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 69 | |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame] | 70 | /** Initialize an RTCPeerConnection with a configuration, constraints, and |
| 71 | * delegate. |
| 72 | */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 73 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 74 | configuration:(RTCConfiguration *)configuration |
| 75 | constraints:(RTCMediaConstraints *)constraints |
| 76 | delegate:(nullable id<RTCPeerConnectionDelegate>)delegate |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame] | 77 | NS_DESIGNATED_INITIALIZER; |
| 78 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 79 | + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 80 | (RTCSignalingState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 81 | |
| 82 | + (RTCSignalingState)signalingStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 83 | (webrtc::PeerConnectionInterface::SignalingState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 84 | |
| 85 | + (NSString *)stringForSignalingState:(RTCSignalingState)state; |
| 86 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 87 | + (webrtc::PeerConnectionInterface::IceConnectionState)nativeIceConnectionStateForState: |
| 88 | (RTCIceConnectionState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 89 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 90 | + (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: |
| 91 | (RTCPeerConnectionState)state; |
| 92 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 93 | + (RTCIceConnectionState)iceConnectionStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 94 | (webrtc::PeerConnectionInterface::IceConnectionState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 95 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 96 | + (RTCPeerConnectionState)connectionStateForNativeState: |
| 97 | (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState; |
| 98 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 99 | + (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state; |
| 100 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 101 | + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state; |
| 102 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 103 | + (webrtc::PeerConnectionInterface::IceGatheringState)nativeIceGatheringStateForState: |
| 104 | (RTCIceGatheringState)state; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 105 | |
| 106 | + (RTCIceGatheringState)iceGatheringStateForNativeState: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 107 | (webrtc::PeerConnectionInterface::IceGatheringState)nativeState; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 108 | |
| 109 | + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state; |
| 110 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 111 | + (webrtc::PeerConnectionInterface::StatsOutputLevel)nativeStatsOutputLevelForLevel: |
| 112 | (RTCStatsOutputLevel)level; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 113 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 114 | @end |
| 115 | |
| 116 | NS_ASSUME_NONNULL_END |