blob: 2c5c19e00f40336829342583e9c1cdbb975e8a3a [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
120/** Initialize an RTCPeerConnection with a configuration, constraints, and
121 * delegate.
122 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800123- (instancetype)initWithFactory:
124 (RTCPeerConnectionFactory *)factory
125 configuration:
126 (RTCConfiguration *)configuration
127 constraints:
128 (RTCMediaConstraints *)constraints
129 delegate:
hjon6b039952016-02-25 12:32:58 -0800130 (nullable id<RTCPeerConnectionDelegate>)delegate
hjonf396f602016-02-11 16:19:06 -0800131 NS_DESIGNATED_INITIALIZER;
132
tkchinaac3eb22016-03-09 21:49:40 -0800133/** Sets the PeerConnection's global configuration to |configuration|.
134 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
135 * next gathering phase, and cause the next call to createOffer to generate
136 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
137 * cannot be changed with this method.
138 */
139- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
140
hjonf396f602016-02-11 16:19:06 -0800141/** Terminate all media and close the transport. */
142- (void)close;
143
144/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800145- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800146
147/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800148- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800149
150/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800151- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800152
153/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800154- (void)offerForConstraints:(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/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800160- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800161 completionHandler:(nullable void (^)
162 (RTCSessionDescription * _Nullable sdp,
163 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800164
165/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800166- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800167 completionHandler:
168 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800169
170/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800171- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800172 completionHandler:
173 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800174
175@end
176
177@interface RTCPeerConnection (DataChannel)
178
179/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800180- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
181 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800182
183@end
184
185@interface RTCPeerConnection (Stats)
186
187/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
188 * statistics are gathered for all tracks.
189 */
190- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800191 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800192 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
193 completionHandler:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800194 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800195
196@end
197
198NS_ASSUME_NONNULL_END