blob: d9ddffbe1eced714e6095d6cfe18f9fd6202b0b4 [file] [log] [blame]
hjonf396f602016-02-11 16:19:06 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070013#import <WebRTC/RTCMacros.h>
tkchin8b577ed2016-04-19 10:04:41 -070014
hjonf396f602016-02-11 16:19:06 -080015@class RTCConfiguration;
16@class RTCDataChannel;
17@class RTCDataChannelConfiguration;
18@class RTCIceCandidate;
19@class RTCMediaConstraints;
20@class RTCMediaStream;
21@class RTCMediaStreamTrack;
22@class RTCPeerConnectionFactory;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070023@class RTCRtpReceiver;
skvlad79b4b872016-04-08 17:28:55 -070024@class RTCRtpSender;
Steve Anton8cb344a2018-02-27 15:34:53 -080025@class RTCRtpTransceiver;
26@class RTCRtpTransceiverInit;
hjonf396f602016-02-11 16:19:06 -080027@class RTCSessionDescription;
hbosbd3dda62016-09-09 01:36:28 -070028@class RTCLegacyStatsReport;
hjonf396f602016-02-11 16:19:06 -080029
Steve Anton8cb344a2018-02-27 15:34:53 -080030typedef NS_ENUM(NSInteger, RTCRtpMediaType);
31
hjonf396f602016-02-11 16:19:06 -080032NS_ASSUME_NONNULL_BEGIN
33
Jon Hjelle32e0c012016-03-08 16:04:46 -080034extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080035extern int const kRTCSessionDescriptionErrorCode;
36
37/** Represents the signaling state of the peer connection. */
38typedef NS_ENUM(NSInteger, RTCSignalingState) {
39 RTCSignalingStateStable,
40 RTCSignalingStateHaveLocalOffer,
41 RTCSignalingStateHaveLocalPrAnswer,
42 RTCSignalingStateHaveRemoteOffer,
43 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070044 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080045 RTCSignalingStateClosed,
46};
47
48/** Represents the ice connection state of the peer connection. */
49typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
50 RTCIceConnectionStateNew,
51 RTCIceConnectionStateChecking,
52 RTCIceConnectionStateConnected,
53 RTCIceConnectionStateCompleted,
54 RTCIceConnectionStateFailed,
55 RTCIceConnectionStateDisconnected,
56 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070057 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080058};
59
60/** Represents the ice gathering state of the peer connection. */
61typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
62 RTCIceGatheringStateNew,
63 RTCIceGatheringStateGathering,
64 RTCIceGatheringStateComplete,
65};
66
67/** Represents the stats output level. */
68typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
69 RTCStatsOutputLevelStandard,
70 RTCStatsOutputLevelDebug,
71};
72
73@class RTCPeerConnection;
74
tkchin8b577ed2016-04-19 10:04:41 -070075RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -080076@protocol RTCPeerConnectionDelegate <NSObject>
77
78/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080079- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080080 didChangeSignalingState:(RTCSignalingState)stateChanged;
81
82/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080083- (void)peerConnection:(RTCPeerConnection *)peerConnection
84 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080085
Steve Anton8cb344a2018-02-27 15:34:53 -080086/** Called when a remote peer closes a stream.
87 * This is not called when RTCSdpSemanticsUnifiedPlan is specified.
88 */
Jon Hjelle32e0c012016-03-08 16:04:46 -080089- (void)peerConnection:(RTCPeerConnection *)peerConnection
90 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080091
92/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080093- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080094
95/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080096- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080097 didChangeIceConnectionState:(RTCIceConnectionState)newState;
98
99/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800100- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -0800101 didChangeIceGatheringState:(RTCIceGatheringState)newState;
102
103/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800104- (void)peerConnection:(RTCPeerConnection *)peerConnection
105 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800106
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700107/** Called when a group of local Ice candidates have been removed. */
108- (void)peerConnection:(RTCPeerConnection *)peerConnection
109 didRemoveIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
110
hjonf396f602016-02-11 16:19:06 -0800111/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800112- (void)peerConnection:(RTCPeerConnection *)peerConnection
113 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -0800114
Steve Anton8cb344a2018-02-27 15:34:53 -0800115/** Called when signaling indicates a transceiver will be receiving media from
116 * the remote endpoint.
117 * This is only called with RTCSdpSemanticsUnifiedPlan specified.
118 */
119@optional
120- (void)peerConnection:(RTCPeerConnection *)peerConnection
121 didStartReceivingOnTransceiver:(RTCRtpTransceiver *)transceiver;
122
Yura Yaroshevich546d7f92018-02-28 21:06:34 +0300123/** Called when a receiver and its track are created. */
124@optional
125- (void)peerConnection:(RTCPeerConnection *)peerConnection
126 didAddReceiver:(RTCRtpReceiver *)rtpReceiver
127 streams:(NSArray<RTCMediaStream *> *)mediaStreams;
128
hjonf396f602016-02-11 16:19:06 -0800129@end
130
tkchin8b577ed2016-04-19 10:04:41 -0700131RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -0800132@interface RTCPeerConnection : NSObject
133
134/** The object that will be notifed about events such as state changes and
135 * streams being added or removed.
136 */
hjon6b039952016-02-25 12:32:58 -0800137@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Steve Anton8cb344a2018-02-27 15:34:53 -0800138/** This property is not available with RTCSdpSemanticsUnifiedPlan. Please use
139 * |senders| instead.
140 */
vopatop.skam96b6b832016-08-18 14:21:20 -0700141@property(nonatomic, readonly) NSArray<RTCMediaStream *> *localStreams;
hjonf396f602016-02-11 16:19:06 -0800142@property(nonatomic, readonly, nullable)
143 RTCSessionDescription *localDescription;
144@property(nonatomic, readonly, nullable)
145 RTCSessionDescription *remoteDescription;
146@property(nonatomic, readonly) RTCSignalingState signalingState;
147@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
148@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
jtteh4eeb5372017-04-03 15:06:37 -0700149@property(nonatomic, readonly, copy) RTCConfiguration *configuration;
hjonf396f602016-02-11 16:19:06 -0800150
skvlad79b4b872016-04-08 17:28:55 -0700151/** Gets all RTCRtpSenders associated with this peer connection.
152 * Note: reading this property returns different instances of RTCRtpSender.
153 * Use isEqual: instead of == to compare RTCRtpSender instances.
154 */
155@property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders;
156
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700157/** Gets all RTCRtpReceivers associated with this peer connection.
158 * Note: reading this property returns different instances of RTCRtpReceiver.
159 * Use isEqual: instead of == to compare RTCRtpReceiver instances.
160 */
161@property(nonatomic, readonly) NSArray<RTCRtpReceiver *> *receivers;
162
Steve Anton8cb344a2018-02-27 15:34:53 -0800163/** Gets all RTCRtpTransceivers associated with this peer connection.
164 * Note: reading this property returns different instances of
165 * RTCRtpTransceiver. Use isEqual: instead of == to compare RTCRtpTransceiver
166 * instances.
167 * This is only available with RTCSdpSemanticsUnifiedPlan specified.
168 */
169@property(nonatomic, readonly) NSArray<RTCRtpTransceiver *> *transceivers;
170
Jon Hjelle32e0c012016-03-08 16:04:46 -0800171- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800172
tkchinaac3eb22016-03-09 21:49:40 -0800173/** Sets the PeerConnection's global configuration to |configuration|.
174 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
175 * next gathering phase, and cause the next call to createOffer to generate
176 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
177 * cannot be changed with this method.
178 */
179- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
180
hjonf396f602016-02-11 16:19:06 -0800181/** Terminate all media and close the transport. */
182- (void)close;
183
184/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800185- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800186
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700187/** Remove a group of remote candidates from the ICE Agent. */
188- (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
189
Steve Anton8cb344a2018-02-27 15:34:53 -0800190/** Add a new media stream to be sent on this peer connection.
191 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
192 * addTrack instead.
193 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800194- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800195
Steve Anton8cb344a2018-02-27 15:34:53 -0800196/** Remove the given media stream from this peer connection.
197 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
198 * removeTrack instead.
199 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800200- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800201
Steve Anton8cb344a2018-02-27 15:34:53 -0800202/** Add a new media stream track to be sent on this peer connection, and return
203 * the newly created RTCRtpSender. The RTCRtpSender will be associated with
Seth Hampson513449e2018-03-06 09:35:56 -0800204 * the streams specified in the |streamIds| list.
Steve Anton8cb344a2018-02-27 15:34:53 -0800205 *
206 * Errors: If an error occurs, returns nil. An error can occur if:
207 * - A sender already exists for the track.
208 * - The peer connection is closed.
209 */
Seth Hampson513449e2018-03-06 09:35:56 -0800210- (RTCRtpSender *)addTrack:(RTCMediaStreamTrack *)track streamIds:(NSArray<NSString *> *)streamIds;
Steve Anton8cb344a2018-02-27 15:34:53 -0800211
212/** With PlanB semantics, removes an RTCRtpSender from this peer connection.
213 *
214 * With UnifiedPlan semantics, sets sender's track to null and removes the
215 * send component from the associated RTCRtpTransceiver's direction.
216 *
217 * Returns YES on success.
218 */
219- (BOOL)removeTrack:(RTCRtpSender *)sender;
220
221/** addTransceiver creates a new RTCRtpTransceiver and adds it to the set of
222 * transceivers. Adding a transceiver will cause future calls to CreateOffer
223 * to add a media description for the corresponding transceiver.
224 *
225 * The initial value of |mid| in the returned transceiver is nil. Setting a
226 * new session description may change it to a non-nil value.
227 *
228 * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
229 *
230 * Optionally, an RtpTransceiverInit structure can be specified to configure
231 * the transceiver from construction. If not specified, the transceiver will
232 * default to having a direction of kSendRecv and not be part of any streams.
233 *
234 * These methods are only available when Unified Plan is enabled (see
235 * RTCConfiguration).
236 */
237
238/** Adds a transceiver with a sender set to transmit the given track. The kind
239 * of the transceiver (and sender/receiver) will be derived from the kind of
240 * the track.
241 */
242- (RTCRtpTransceiver *)addTransceiverWithTrack:(RTCMediaStreamTrack *)track;
243- (RTCRtpTransceiver *)addTransceiverWithTrack:(RTCMediaStreamTrack *)track
244 init:(RTCRtpTransceiverInit *)init;
245
246/** Adds a transceiver with the given kind. Can either be RTCRtpMediaTypeAudio
247 * or RTCRtpMediaTypeVideo.
248 */
249- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType;
250- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType
251 init:(RTCRtpTransceiverInit *)init;
252
hjonf396f602016-02-11 16:19:06 -0800253/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800254- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800255 completionHandler:(nullable void (^)
256 (RTCSessionDescription * _Nullable sdp,
257 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800258
259/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800260- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800261 completionHandler:(nullable void (^)
262 (RTCSessionDescription * _Nullable sdp,
263 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800264
265/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800266- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800267 completionHandler:
268 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800269
270/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800271- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800272 completionHandler:
273 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800274
zstein8b476172017-09-05 14:43:03 -0700275/** Limits the bandwidth allocated for all RTP streams sent by this
276 * PeerConnection. Nil parameters will be unchanged. Setting
277 * |currentBitrateBps| will force the available bitrate estimate to the given
278 * value. Returns YES if the parameters were successfully updated.
zstein03adb7c2017-08-09 14:29:42 -0700279 */
zstein8b476172017-09-05 14:43:03 -0700280- (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps
281 currentBitrateBps:(nullable NSNumber *)currentBitrateBps
282 maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
zstein03adb7c2017-08-09 14:29:42 -0700283
ivoc14d5dbe2016-07-04 07:06:55 -0700284/** Start or stop recording an Rtc EventLog. */
285- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
286 maxSizeInBytes:(int64_t)maxSizeInBytes;
287- (void)stopRtcEventLog;
288
hjonf396f602016-02-11 16:19:06 -0800289@end
290
skvladf3569c82016-04-29 15:30:16 -0700291@interface RTCPeerConnection (Media)
292
zstein8b476172017-09-05 14:43:03 -0700293/** Create an RTCRtpSender with the specified kind and media stream ID.
294 * See RTCMediaStreamTrack.h for available kinds.
Steve Anton8cb344a2018-02-27 15:34:53 -0800295 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
296 * addTransceiver instead.
skvladf3569c82016-04-29 15:30:16 -0700297 */
298- (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId;
299
300@end
301
hjonf396f602016-02-11 16:19:06 -0800302@interface RTCPeerConnection (DataChannel)
303
304/** Create a new data channel with the given label and configuration. */
Peter Hanspersd9b64cd2018-01-12 16:16:18 +0100305- (nullable RTCDataChannel *)dataChannelForLabel:(NSString *)label
306 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800307
308@end
309
310@interface RTCPeerConnection (Stats)
311
312/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
313 * statistics are gathered for all tracks.
314 */
315- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800316 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800317 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
318 completionHandler:
hbosbd3dda62016-09-09 01:36:28 -0700319 (nullable void (^)(NSArray<RTCLegacyStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800320
321@end
322
323NS_ASSUME_NONNULL_END