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 | |
| 11 | #import <Foundation/Foundation.h> |
| 12 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame^] | 13 | #import "webrtc/base/objc/RTCMacros.h" |
| 14 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 15 | @class RTCConfiguration; |
| 16 | @class RTCDataChannel; |
| 17 | @class RTCDataChannelConfiguration; |
| 18 | @class RTCIceCandidate; |
| 19 | @class RTCMediaConstraints; |
| 20 | @class RTCMediaStream; |
| 21 | @class RTCMediaStreamTrack; |
| 22 | @class RTCPeerConnectionFactory; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 23 | @class RTCRtpSender; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 24 | @class RTCSessionDescription; |
| 25 | @class RTCStatsReport; |
| 26 | |
| 27 | NS_ASSUME_NONNULL_BEGIN |
| 28 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 29 | extern NSString * const kRTCPeerConnectionErrorDomain; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 30 | extern int const kRTCSessionDescriptionErrorCode; |
| 31 | |
| 32 | /** Represents the signaling state of the peer connection. */ |
| 33 | typedef NS_ENUM(NSInteger, RTCSignalingState) { |
| 34 | RTCSignalingStateStable, |
| 35 | RTCSignalingStateHaveLocalOffer, |
| 36 | RTCSignalingStateHaveLocalPrAnswer, |
| 37 | RTCSignalingStateHaveRemoteOffer, |
| 38 | RTCSignalingStateHaveRemotePrAnswer, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 39 | // Not an actual state, represents the total number of states. |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 40 | RTCSignalingStateClosed, |
| 41 | }; |
| 42 | |
| 43 | /** Represents the ice connection state of the peer connection. */ |
| 44 | typedef NS_ENUM(NSInteger, RTCIceConnectionState) { |
| 45 | RTCIceConnectionStateNew, |
| 46 | RTCIceConnectionStateChecking, |
| 47 | RTCIceConnectionStateConnected, |
| 48 | RTCIceConnectionStateCompleted, |
| 49 | RTCIceConnectionStateFailed, |
| 50 | RTCIceConnectionStateDisconnected, |
| 51 | RTCIceConnectionStateClosed, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 52 | RTCIceConnectionStateCount, |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /** Represents the ice gathering state of the peer connection. */ |
| 56 | typedef NS_ENUM(NSInteger, RTCIceGatheringState) { |
| 57 | RTCIceGatheringStateNew, |
| 58 | RTCIceGatheringStateGathering, |
| 59 | RTCIceGatheringStateComplete, |
| 60 | }; |
| 61 | |
| 62 | /** Represents the stats output level. */ |
| 63 | typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) { |
| 64 | RTCStatsOutputLevelStandard, |
| 65 | RTCStatsOutputLevelDebug, |
| 66 | }; |
| 67 | |
| 68 | @class RTCPeerConnection; |
| 69 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame^] | 70 | RTC_EXPORT |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 71 | @protocol RTCPeerConnectionDelegate <NSObject> |
| 72 | |
| 73 | /** Called when the SignalingState changed. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 74 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 75 | didChangeSignalingState:(RTCSignalingState)stateChanged; |
| 76 | |
| 77 | /** Called when media is received on a new stream from remote peer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 78 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 79 | didAddStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 80 | |
| 81 | /** Called when a remote peer closes a stream. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 82 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 83 | didRemoveStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 84 | |
| 85 | /** Called when negotiation is needed, for example ICE has restarted. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 86 | - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 87 | |
| 88 | /** Called any time the IceConnectionState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 89 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 90 | didChangeIceConnectionState:(RTCIceConnectionState)newState; |
| 91 | |
| 92 | /** Called any time the IceGatheringState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 93 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 94 | didChangeIceGatheringState:(RTCIceGatheringState)newState; |
| 95 | |
| 96 | /** New ice candidate has been found. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 97 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 98 | didGenerateIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 99 | |
| 100 | /** New data channel has been opened. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 101 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 102 | didOpenDataChannel:(RTCDataChannel *)dataChannel; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 103 | |
| 104 | @end |
| 105 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame^] | 106 | RTC_EXPORT |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 107 | @interface RTCPeerConnection : NSObject |
| 108 | |
| 109 | /** The object that will be notifed about events such as state changes and |
| 110 | * streams being added or removed. |
| 111 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 112 | @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 113 | @property(nonatomic, readonly) NSArray *localStreams; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 114 | @property(nonatomic, readonly, nullable) |
| 115 | RTCSessionDescription *localDescription; |
| 116 | @property(nonatomic, readonly, nullable) |
| 117 | RTCSessionDescription *remoteDescription; |
| 118 | @property(nonatomic, readonly) RTCSignalingState signalingState; |
| 119 | @property(nonatomic, readonly) RTCIceConnectionState iceConnectionState; |
| 120 | @property(nonatomic, readonly) RTCIceGatheringState iceGatheringState; |
| 121 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 122 | /** Gets all RTCRtpSenders associated with this peer connection. |
| 123 | * Note: reading this property returns different instances of RTCRtpSender. |
| 124 | * Use isEqual: instead of == to compare RTCRtpSender instances. |
| 125 | */ |
| 126 | @property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders; |
| 127 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 128 | - (instancetype)init NS_UNAVAILABLE; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 129 | |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 130 | /** Sets the PeerConnection's global configuration to |configuration|. |
| 131 | * Any changes to STUN/TURN servers or ICE candidate policy will affect the |
| 132 | * next gathering phase, and cause the next call to createOffer to generate |
| 133 | * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies |
| 134 | * cannot be changed with this method. |
| 135 | */ |
| 136 | - (BOOL)setConfiguration:(RTCConfiguration *)configuration; |
| 137 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 138 | /** Terminate all media and close the transport. */ |
| 139 | - (void)close; |
| 140 | |
| 141 | /** Provide a remote candidate to the ICE Agent. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 142 | - (void)addIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 143 | |
| 144 | /** Add a new media stream to be sent on this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 145 | - (void)addStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 146 | |
| 147 | /** Remove the given media stream from this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 148 | - (void)removeStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 149 | |
| 150 | /** Generate an SDP offer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 151 | - (void)offerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 152 | completionHandler:(nullable void (^) |
| 153 | (RTCSessionDescription * _Nullable sdp, |
| 154 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 155 | |
| 156 | /** Generate an SDP answer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 157 | - (void)answerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 158 | completionHandler:(nullable void (^) |
| 159 | (RTCSessionDescription * _Nullable sdp, |
| 160 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 161 | |
| 162 | /** Apply the supplied RTCSessionDescription as the local description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 163 | - (void)setLocalDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 164 | completionHandler: |
| 165 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 166 | |
| 167 | /** Apply the supplied RTCSessionDescription as the remote description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 168 | - (void)setRemoteDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 169 | completionHandler: |
| 170 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 171 | |
| 172 | @end |
| 173 | |
| 174 | @interface RTCPeerConnection (DataChannel) |
| 175 | |
| 176 | /** Create a new data channel with the given label and configuration. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 177 | - (RTCDataChannel *)dataChannelForLabel:(NSString *)label |
| 178 | configuration:(RTCDataChannelConfiguration *)configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 179 | |
| 180 | @end |
| 181 | |
| 182 | @interface RTCPeerConnection (Stats) |
| 183 | |
| 184 | /** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil |
| 185 | * statistics are gathered for all tracks. |
| 186 | */ |
| 187 | - (void)statsForTrack: |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 188 | (nullable RTCMediaStreamTrack *)mediaStreamTrack |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 189 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel |
| 190 | completionHandler: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 191 | (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 192 | |
| 193 | @end |
| 194 | |
| 195 | NS_ASSUME_NONNULL_END |