blob: 7b0c4492f4792be56f6fa315d197b91f232cef6c [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;
hjonf396f602016-02-11 16:19:06 -080025@class RTCSessionDescription;
hbosbd3dda62016-09-09 01:36:28 -070026@class RTCLegacyStatsReport;
hjonf396f602016-02-11 16:19:06 -080027
28NS_ASSUME_NONNULL_BEGIN
29
Jon Hjelle32e0c012016-03-08 16:04:46 -080030extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080031extern int const kRTCSessionDescriptionErrorCode;
32
33/** Represents the signaling state of the peer connection. */
34typedef NS_ENUM(NSInteger, RTCSignalingState) {
35 RTCSignalingStateStable,
36 RTCSignalingStateHaveLocalOffer,
37 RTCSignalingStateHaveLocalPrAnswer,
38 RTCSignalingStateHaveRemoteOffer,
39 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070040 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080041 RTCSignalingStateClosed,
42};
43
44/** Represents the ice connection state of the peer connection. */
45typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
46 RTCIceConnectionStateNew,
47 RTCIceConnectionStateChecking,
48 RTCIceConnectionStateConnected,
49 RTCIceConnectionStateCompleted,
50 RTCIceConnectionStateFailed,
51 RTCIceConnectionStateDisconnected,
52 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070053 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080054};
55
56/** Represents the ice gathering state of the peer connection. */
57typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
58 RTCIceGatheringStateNew,
59 RTCIceGatheringStateGathering,
60 RTCIceGatheringStateComplete,
61};
62
63/** Represents the stats output level. */
64typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
65 RTCStatsOutputLevelStandard,
66 RTCStatsOutputLevelDebug,
67};
68
69@class RTCPeerConnection;
70
tkchin8b577ed2016-04-19 10:04:41 -070071RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -080072@protocol RTCPeerConnectionDelegate <NSObject>
73
74/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080075- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080076 didChangeSignalingState:(RTCSignalingState)stateChanged;
77
78/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080079- (void)peerConnection:(RTCPeerConnection *)peerConnection
80 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080081
82/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080083- (void)peerConnection:(RTCPeerConnection *)peerConnection
84 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080085
86/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080087- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080088
89/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080090- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080091 didChangeIceConnectionState:(RTCIceConnectionState)newState;
92
93/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080094- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080095 didChangeIceGatheringState:(RTCIceGatheringState)newState;
96
97/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080098- (void)peerConnection:(RTCPeerConnection *)peerConnection
99 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800100
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700101/** Called when a group of local Ice candidates have been removed. */
102- (void)peerConnection:(RTCPeerConnection *)peerConnection
103 didRemoveIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
104
hjonf396f602016-02-11 16:19:06 -0800105/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800106- (void)peerConnection:(RTCPeerConnection *)peerConnection
107 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -0800108
109@end
110
tkchin8b577ed2016-04-19 10:04:41 -0700111RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -0800112@interface RTCPeerConnection : NSObject
113
114/** The object that will be notifed about events such as state changes and
115 * streams being added or removed.
116 */
hjon6b039952016-02-25 12:32:58 -0800117@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
vopatop.skam96b6b832016-08-18 14:21:20 -0700118@property(nonatomic, readonly) NSArray<RTCMediaStream *> *localStreams;
hjonf396f602016-02-11 16:19:06 -0800119@property(nonatomic, readonly, nullable)
120 RTCSessionDescription *localDescription;
121@property(nonatomic, readonly, nullable)
122 RTCSessionDescription *remoteDescription;
123@property(nonatomic, readonly) RTCSignalingState signalingState;
124@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
125@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
jtteh4eeb5372017-04-03 15:06:37 -0700126@property(nonatomic, readonly, copy) RTCConfiguration *configuration;
hjonf396f602016-02-11 16:19:06 -0800127
skvlad79b4b872016-04-08 17:28:55 -0700128/** Gets all RTCRtpSenders associated with this peer connection.
129 * Note: reading this property returns different instances of RTCRtpSender.
130 * Use isEqual: instead of == to compare RTCRtpSender instances.
131 */
132@property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders;
133
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700134/** Gets all RTCRtpReceivers associated with this peer connection.
135 * Note: reading this property returns different instances of RTCRtpReceiver.
136 * Use isEqual: instead of == to compare RTCRtpReceiver instances.
137 */
138@property(nonatomic, readonly) NSArray<RTCRtpReceiver *> *receivers;
139
Jon Hjelle32e0c012016-03-08 16:04:46 -0800140- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800141
tkchinaac3eb22016-03-09 21:49:40 -0800142/** Sets the PeerConnection's global configuration to |configuration|.
143 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
144 * next gathering phase, and cause the next call to createOffer to generate
145 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
146 * cannot be changed with this method.
147 */
148- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
149
hjonf396f602016-02-11 16:19:06 -0800150/** Terminate all media and close the transport. */
151- (void)close;
152
153/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800154- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800155
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700156/** Remove a group of remote candidates from the ICE Agent. */
157- (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
158
hjonf396f602016-02-11 16:19:06 -0800159/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800160- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800161
162/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800163- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800164
165/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800166- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800167 completionHandler:(nullable void (^)
168 (RTCSessionDescription * _Nullable sdp,
169 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800170
171/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800172- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800173 completionHandler:(nullable void (^)
174 (RTCSessionDescription * _Nullable sdp,
175 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800176
177/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800178- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800179 completionHandler:
180 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800181
182/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800183- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800184 completionHandler:
185 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800186
zstein8b476172017-09-05 14:43:03 -0700187/** Limits the bandwidth allocated for all RTP streams sent by this
188 * PeerConnection. Nil parameters will be unchanged. Setting
189 * |currentBitrateBps| will force the available bitrate estimate to the given
190 * value. Returns YES if the parameters were successfully updated.
zstein03adb7c2017-08-09 14:29:42 -0700191 */
zstein8b476172017-09-05 14:43:03 -0700192- (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps
193 currentBitrateBps:(nullable NSNumber *)currentBitrateBps
194 maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
zstein03adb7c2017-08-09 14:29:42 -0700195
ivoc14d5dbe2016-07-04 07:06:55 -0700196/** Start or stop recording an Rtc EventLog. */
197- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
198 maxSizeInBytes:(int64_t)maxSizeInBytes;
199- (void)stopRtcEventLog;
200
hjonf396f602016-02-11 16:19:06 -0800201@end
202
skvladf3569c82016-04-29 15:30:16 -0700203@interface RTCPeerConnection (Media)
204
zstein8b476172017-09-05 14:43:03 -0700205/** Create an RTCRtpSender with the specified kind and media stream ID.
206 * See RTCMediaStreamTrack.h for available kinds.
skvladf3569c82016-04-29 15:30:16 -0700207 */
208- (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId;
209
210@end
211
hjonf396f602016-02-11 16:19:06 -0800212@interface RTCPeerConnection (DataChannel)
213
214/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800215- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
216 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800217
218@end
219
220@interface RTCPeerConnection (Stats)
221
222/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
223 * statistics are gathered for all tracks.
224 */
225- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800226 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800227 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
228 completionHandler:
hbosbd3dda62016-09-09 01:36:28 -0700229 (nullable void (^)(NSArray<RTCLegacyStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800230
231@end
232
233NS_ASSUME_NONNULL_END