blob: e0f9b78e8ebb0ac1b41234e8501595ffe1f201cd [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;
21@class RTCSessionDescription;
22@class RTCStatsReport;
23
24NS_ASSUME_NONNULL_BEGIN
25
Jon Hjelle32e0c012016-03-08 16:04:46 -080026extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080027extern int const kRTCSessionDescriptionErrorCode;
28
29/** Represents the signaling state of the peer connection. */
30typedef NS_ENUM(NSInteger, RTCSignalingState) {
31 RTCSignalingStateStable,
32 RTCSignalingStateHaveLocalOffer,
33 RTCSignalingStateHaveLocalPrAnswer,
34 RTCSignalingStateHaveRemoteOffer,
35 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070036 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080037 RTCSignalingStateClosed,
38};
39
40/** Represents the ice connection state of the peer connection. */
41typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
42 RTCIceConnectionStateNew,
43 RTCIceConnectionStateChecking,
44 RTCIceConnectionStateConnected,
45 RTCIceConnectionStateCompleted,
46 RTCIceConnectionStateFailed,
47 RTCIceConnectionStateDisconnected,
48 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070049 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080050};
51
52/** Represents the ice gathering state of the peer connection. */
53typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
54 RTCIceGatheringStateNew,
55 RTCIceGatheringStateGathering,
56 RTCIceGatheringStateComplete,
57};
58
59/** Represents the stats output level. */
60typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
61 RTCStatsOutputLevelStandard,
62 RTCStatsOutputLevelDebug,
63};
64
65@class RTCPeerConnection;
66
67@protocol RTCPeerConnectionDelegate <NSObject>
68
69/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080070- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080071 didChangeSignalingState:(RTCSignalingState)stateChanged;
72
73/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080074- (void)peerConnection:(RTCPeerConnection *)peerConnection
75 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080076
77/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080078- (void)peerConnection:(RTCPeerConnection *)peerConnection
79 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080080
81/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080082- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080083
84/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080085- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080086 didChangeIceConnectionState:(RTCIceConnectionState)newState;
87
88/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080089- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080090 didChangeIceGatheringState:(RTCIceGatheringState)newState;
91
92/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080093- (void)peerConnection:(RTCPeerConnection *)peerConnection
94 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -080095
96/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080097- (void)peerConnection:(RTCPeerConnection *)peerConnection
98 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -080099
100@end
101
102
103@interface RTCPeerConnection : NSObject
104
105/** The object that will be notifed about events such as state changes and
106 * streams being added or removed.
107 */
hjon6b039952016-02-25 12:32:58 -0800108@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Jon Hjelle32e0c012016-03-08 16:04:46 -0800109@property(nonatomic, readonly) NSArray *localStreams;
hjonf396f602016-02-11 16:19:06 -0800110@property(nonatomic, readonly, nullable)
111 RTCSessionDescription *localDescription;
112@property(nonatomic, readonly, nullable)
113 RTCSessionDescription *remoteDescription;
114@property(nonatomic, readonly) RTCSignalingState signalingState;
115@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
116@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
117
Jon Hjelle32e0c012016-03-08 16:04:46 -0800118- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800119
tkchinaac3eb22016-03-09 21:49:40 -0800120/** Sets the PeerConnection's global configuration to |configuration|.
121 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
122 * next gathering phase, and cause the next call to createOffer to generate
123 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
124 * cannot be changed with this method.
125 */
126- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
127
hjonf396f602016-02-11 16:19:06 -0800128/** Terminate all media and close the transport. */
129- (void)close;
130
131/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800132- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800133
134/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800135- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800136
137/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800138- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800139
140/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800141- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800142 completionHandler:(nullable void (^)
143 (RTCSessionDescription * _Nullable sdp,
144 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800145
146/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800147- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800148 completionHandler:(nullable void (^)
149 (RTCSessionDescription * _Nullable sdp,
150 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800151
152/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800153- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800154 completionHandler:
155 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800156
157/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800158- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800159 completionHandler:
160 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800161
162@end
163
164@interface RTCPeerConnection (DataChannel)
165
166/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800167- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
168 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800169
170@end
171
172@interface RTCPeerConnection (Stats)
173
174/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
175 * statistics are gathered for all tracks.
176 */
177- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800178 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800179 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
180 completionHandler:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800181 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800182
183@end
184
185NS_ASSUME_NONNULL_END