blob: 8b69804a1610d53b68d90c37b5e2b552bee997fc [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
hjonf396f602016-02-11 16:19:06 -0800123@end
124
tkchin8b577ed2016-04-19 10:04:41 -0700125RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -0800126@interface RTCPeerConnection : NSObject
127
128/** The object that will be notifed about events such as state changes and
129 * streams being added or removed.
130 */
hjon6b039952016-02-25 12:32:58 -0800131@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Steve Anton8cb344a2018-02-27 15:34:53 -0800132/** This property is not available with RTCSdpSemanticsUnifiedPlan. Please use
133 * |senders| instead.
134 */
vopatop.skam96b6b832016-08-18 14:21:20 -0700135@property(nonatomic, readonly) NSArray<RTCMediaStream *> *localStreams;
hjonf396f602016-02-11 16:19:06 -0800136@property(nonatomic, readonly, nullable)
137 RTCSessionDescription *localDescription;
138@property(nonatomic, readonly, nullable)
139 RTCSessionDescription *remoteDescription;
140@property(nonatomic, readonly) RTCSignalingState signalingState;
141@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
142@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
jtteh4eeb5372017-04-03 15:06:37 -0700143@property(nonatomic, readonly, copy) RTCConfiguration *configuration;
hjonf396f602016-02-11 16:19:06 -0800144
skvlad79b4b872016-04-08 17:28:55 -0700145/** Gets all RTCRtpSenders associated with this peer connection.
146 * Note: reading this property returns different instances of RTCRtpSender.
147 * Use isEqual: instead of == to compare RTCRtpSender instances.
148 */
149@property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders;
150
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700151/** Gets all RTCRtpReceivers associated with this peer connection.
152 * Note: reading this property returns different instances of RTCRtpReceiver.
153 * Use isEqual: instead of == to compare RTCRtpReceiver instances.
154 */
155@property(nonatomic, readonly) NSArray<RTCRtpReceiver *> *receivers;
156
Steve Anton8cb344a2018-02-27 15:34:53 -0800157/** Gets all RTCRtpTransceivers associated with this peer connection.
158 * Note: reading this property returns different instances of
159 * RTCRtpTransceiver. Use isEqual: instead of == to compare RTCRtpTransceiver
160 * instances.
161 * This is only available with RTCSdpSemanticsUnifiedPlan specified.
162 */
163@property(nonatomic, readonly) NSArray<RTCRtpTransceiver *> *transceivers;
164
Jon Hjelle32e0c012016-03-08 16:04:46 -0800165- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800166
tkchinaac3eb22016-03-09 21:49:40 -0800167/** Sets the PeerConnection's global configuration to |configuration|.
168 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
169 * next gathering phase, and cause the next call to createOffer to generate
170 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
171 * cannot be changed with this method.
172 */
173- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
174
hjonf396f602016-02-11 16:19:06 -0800175/** Terminate all media and close the transport. */
176- (void)close;
177
178/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800179- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800180
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700181/** Remove a group of remote candidates from the ICE Agent. */
182- (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
183
Steve Anton8cb344a2018-02-27 15:34:53 -0800184/** Add a new media stream to be sent on this peer connection.
185 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
186 * addTrack instead.
187 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800188- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800189
Steve Anton8cb344a2018-02-27 15:34:53 -0800190/** Remove the given media stream from this peer connection.
191 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
192 * removeTrack instead.
193 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800194- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800195
Steve Anton8cb344a2018-02-27 15:34:53 -0800196/** Add a new media stream track to be sent on this peer connection, and return
197 * the newly created RTCRtpSender. The RTCRtpSender will be associated with
198 * the streams specified in the |streamLabels| list.
199 *
200 * Errors: If an error occurs, returns nil. An error can occur if:
201 * - A sender already exists for the track.
202 * - The peer connection is closed.
203 */
204- (RTCRtpSender *)addTrack:(RTCMediaStreamTrack *)track
205 streamLabels:(NSArray<NSString *> *)streamLabels;
206
207/** With PlanB semantics, removes an RTCRtpSender from this peer connection.
208 *
209 * With UnifiedPlan semantics, sets sender's track to null and removes the
210 * send component from the associated RTCRtpTransceiver's direction.
211 *
212 * Returns YES on success.
213 */
214- (BOOL)removeTrack:(RTCRtpSender *)sender;
215
216/** addTransceiver creates a new RTCRtpTransceiver and adds it to the set of
217 * transceivers. Adding a transceiver will cause future calls to CreateOffer
218 * to add a media description for the corresponding transceiver.
219 *
220 * The initial value of |mid| in the returned transceiver is nil. Setting a
221 * new session description may change it to a non-nil value.
222 *
223 * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
224 *
225 * Optionally, an RtpTransceiverInit structure can be specified to configure
226 * the transceiver from construction. If not specified, the transceiver will
227 * default to having a direction of kSendRecv and not be part of any streams.
228 *
229 * These methods are only available when Unified Plan is enabled (see
230 * RTCConfiguration).
231 */
232
233/** Adds a transceiver with a sender set to transmit the given track. The kind
234 * of the transceiver (and sender/receiver) will be derived from the kind of
235 * the track.
236 */
237- (RTCRtpTransceiver *)addTransceiverWithTrack:(RTCMediaStreamTrack *)track;
238- (RTCRtpTransceiver *)addTransceiverWithTrack:(RTCMediaStreamTrack *)track
239 init:(RTCRtpTransceiverInit *)init;
240
241/** Adds a transceiver with the given kind. Can either be RTCRtpMediaTypeAudio
242 * or RTCRtpMediaTypeVideo.
243 */
244- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType;
245- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType
246 init:(RTCRtpTransceiverInit *)init;
247
hjonf396f602016-02-11 16:19:06 -0800248/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800249- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800250 completionHandler:(nullable void (^)
251 (RTCSessionDescription * _Nullable sdp,
252 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800253
254/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800255- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800256 completionHandler:(nullable void (^)
257 (RTCSessionDescription * _Nullable sdp,
258 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800259
260/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800261- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800262 completionHandler:
263 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800264
265/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800266- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800267 completionHandler:
268 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800269
zstein8b476172017-09-05 14:43:03 -0700270/** Limits the bandwidth allocated for all RTP streams sent by this
271 * PeerConnection. Nil parameters will be unchanged. Setting
272 * |currentBitrateBps| will force the available bitrate estimate to the given
273 * value. Returns YES if the parameters were successfully updated.
zstein03adb7c2017-08-09 14:29:42 -0700274 */
zstein8b476172017-09-05 14:43:03 -0700275- (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps
276 currentBitrateBps:(nullable NSNumber *)currentBitrateBps
277 maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
zstein03adb7c2017-08-09 14:29:42 -0700278
ivoc14d5dbe2016-07-04 07:06:55 -0700279/** Start or stop recording an Rtc EventLog. */
280- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
281 maxSizeInBytes:(int64_t)maxSizeInBytes;
282- (void)stopRtcEventLog;
283
hjonf396f602016-02-11 16:19:06 -0800284@end
285
skvladf3569c82016-04-29 15:30:16 -0700286@interface RTCPeerConnection (Media)
287
zstein8b476172017-09-05 14:43:03 -0700288/** Create an RTCRtpSender with the specified kind and media stream ID.
289 * See RTCMediaStreamTrack.h for available kinds.
Steve Anton8cb344a2018-02-27 15:34:53 -0800290 * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
291 * addTransceiver instead.
skvladf3569c82016-04-29 15:30:16 -0700292 */
293- (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId;
294
295@end
296
hjonf396f602016-02-11 16:19:06 -0800297@interface RTCPeerConnection (DataChannel)
298
299/** Create a new data channel with the given label and configuration. */
Peter Hanspersd9b64cd2018-01-12 16:16:18 +0100300- (nullable RTCDataChannel *)dataChannelForLabel:(NSString *)label
301 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800302
303@end
304
305@interface RTCPeerConnection (Stats)
306
307/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
308 * statistics are gathered for all tracks.
309 */
310- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800311 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800312 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
313 completionHandler:
hbosbd3dda62016-09-09 01:36:28 -0700314 (nullable void (^)(NSArray<RTCLegacyStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800315
316@end
317
318NS_ASSUME_NONNULL_END