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