blob: 471a8deef02616d1278e53e3a30285bc12aada8b [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
13@class RTCConfiguration;
14@class RTCDataChannel;
15@class RTCDataChannelConfiguration;
16@class RTCIceCandidate;
17@class RTCMediaConstraints;
18@class RTCMediaStream;
19@class RTCMediaStreamTrack;
20@class RTCPeerConnectionFactory;
skvlad79b4b872016-04-08 17:28:55 -070021@class RTCRtpSender;
hjonf396f602016-02-11 16:19:06 -080022@class RTCSessionDescription;
23@class RTCStatsReport;
24
25NS_ASSUME_NONNULL_BEGIN
26
Jon Hjelle32e0c012016-03-08 16:04:46 -080027extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080028extern int const kRTCSessionDescriptionErrorCode;
29
30/** Represents the signaling state of the peer connection. */
31typedef NS_ENUM(NSInteger, RTCSignalingState) {
32 RTCSignalingStateStable,
33 RTCSignalingStateHaveLocalOffer,
34 RTCSignalingStateHaveLocalPrAnswer,
35 RTCSignalingStateHaveRemoteOffer,
36 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070037 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080038 RTCSignalingStateClosed,
39};
40
41/** Represents the ice connection state of the peer connection. */
42typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
43 RTCIceConnectionStateNew,
44 RTCIceConnectionStateChecking,
45 RTCIceConnectionStateConnected,
46 RTCIceConnectionStateCompleted,
47 RTCIceConnectionStateFailed,
48 RTCIceConnectionStateDisconnected,
49 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070050 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080051};
52
53/** Represents the ice gathering state of the peer connection. */
54typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
55 RTCIceGatheringStateNew,
56 RTCIceGatheringStateGathering,
57 RTCIceGatheringStateComplete,
58};
59
60/** Represents the stats output level. */
61typedef 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 Hjelle32e0c012016-03-08 16:04:46 -080071- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080072 didChangeSignalingState:(RTCSignalingState)stateChanged;
73
74/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080075- (void)peerConnection:(RTCPeerConnection *)peerConnection
76 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080077
78/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080079- (void)peerConnection:(RTCPeerConnection *)peerConnection
80 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080081
82/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080083- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080084
85/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080086- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080087 didChangeIceConnectionState:(RTCIceConnectionState)newState;
88
89/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080090- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080091 didChangeIceGatheringState:(RTCIceGatheringState)newState;
92
93/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080094- (void)peerConnection:(RTCPeerConnection *)peerConnection
95 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -080096
97/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080098- (void)peerConnection:(RTCPeerConnection *)peerConnection
99 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -0800100
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 */
hjon6b039952016-02-25 12:32:58 -0800109@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Jon Hjelle32e0c012016-03-08 16:04:46 -0800110@property(nonatomic, readonly) NSArray *localStreams;
hjonf396f602016-02-11 16:19:06 -0800111@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
skvlad79b4b872016-04-08 17:28:55 -0700119/** 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 Hjelle32e0c012016-03-08 16:04:46 -0800125- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800126
tkchinaac3eb22016-03-09 21:49:40 -0800127/** 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
hjonf396f602016-02-11 16:19:06 -0800135/** Terminate all media and close the transport. */
136- (void)close;
137
138/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800139- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800140
141/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800142- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800143
144/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800145- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800146
147/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800148- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800149 completionHandler:(nullable void (^)
150 (RTCSessionDescription * _Nullable sdp,
151 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800152
153/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800154- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800155 completionHandler:(nullable void (^)
156 (RTCSessionDescription * _Nullable sdp,
157 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800158
159/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800160- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800161 completionHandler:
162 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800163
164/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800165- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800166 completionHandler:
167 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800168
169@end
170
171@interface RTCPeerConnection (DataChannel)
172
173/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800174- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
175 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800176
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:
hjona2f77982016-03-04 07:09:09 -0800185 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800186 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
187 completionHandler:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800188 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800189
190@end
191
192NS_ASSUME_NONNULL_END