blob: 68db191bff40db6649e7f71f7167b35fc784a97f [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,
36 RTCSignalingStateClosed,
37};
38
39/** Represents the ice connection state of the peer connection. */
40typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
41 RTCIceConnectionStateNew,
42 RTCIceConnectionStateChecking,
43 RTCIceConnectionStateConnected,
44 RTCIceConnectionStateCompleted,
45 RTCIceConnectionStateFailed,
46 RTCIceConnectionStateDisconnected,
47 RTCIceConnectionStateClosed,
48 RTCIceConnectionStateMax,
49};
50
51/** Represents the ice gathering state of the peer connection. */
52typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
53 RTCIceGatheringStateNew,
54 RTCIceGatheringStateGathering,
55 RTCIceGatheringStateComplete,
56};
57
58/** Represents the stats output level. */
59typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
60 RTCStatsOutputLevelStandard,
61 RTCStatsOutputLevelDebug,
62};
63
64@class RTCPeerConnection;
65
66@protocol RTCPeerConnectionDelegate <NSObject>
67
68/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080069- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080070 didChangeSignalingState:(RTCSignalingState)stateChanged;
71
72/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080073- (void)peerConnection:(RTCPeerConnection *)peerConnection
74 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080075
76/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080077- (void)peerConnection:(RTCPeerConnection *)peerConnection
78 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080079
80/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080081- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080082
83/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080084- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080085 didChangeIceConnectionState:(RTCIceConnectionState)newState;
86
87/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080088- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080089 didChangeIceGatheringState:(RTCIceGatheringState)newState;
90
91/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080092- (void)peerConnection:(RTCPeerConnection *)peerConnection
93 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -080094
95/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080096- (void)peerConnection:(RTCPeerConnection *)peerConnection
97 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -080098
99@end
100
101
102@interface RTCPeerConnection : NSObject
103
104/** The object that will be notifed about events such as state changes and
105 * streams being added or removed.
106 */
hjon6b039952016-02-25 12:32:58 -0800107@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Jon Hjelle32e0c012016-03-08 16:04:46 -0800108@property(nonatomic, readonly) NSArray *localStreams;
hjonf396f602016-02-11 16:19:06 -0800109@property(nonatomic, readonly, nullable)
110 RTCSessionDescription *localDescription;
111@property(nonatomic, readonly, nullable)
112 RTCSessionDescription *remoteDescription;
113@property(nonatomic, readonly) RTCSignalingState signalingState;
114@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
115@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
116
Jon Hjelle32e0c012016-03-08 16:04:46 -0800117- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800118
119/** Initialize an RTCPeerConnection with a configuration, constraints, and
120 * delegate.
121 */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800122- (instancetype)initWithFactory:
123 (RTCPeerConnectionFactory *)factory
124 configuration:
125 (RTCConfiguration *)configuration
126 constraints:
127 (RTCMediaConstraints *)constraints
128 delegate:
hjon6b039952016-02-25 12:32:58 -0800129 (nullable id<RTCPeerConnectionDelegate>)delegate
hjonf396f602016-02-11 16:19:06 -0800130 NS_DESIGNATED_INITIALIZER;
131
tkchinaac3eb22016-03-09 21:49:40 -0800132/** Sets the PeerConnection's global configuration to |configuration|.
133 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
134 * next gathering phase, and cause the next call to createOffer to generate
135 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
136 * cannot be changed with this method.
137 */
138- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
139
hjonf396f602016-02-11 16:19:06 -0800140/** Terminate all media and close the transport. */
141- (void)close;
142
143/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800144- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800145
146/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800147- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800148
149/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800150- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800151
152/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800153- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800154 completionHandler:(nullable void (^)
155 (RTCSessionDescription * _Nullable sdp,
156 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800157
158/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800159- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800160 completionHandler:(nullable void (^)
161 (RTCSessionDescription * _Nullable sdp,
162 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800163
164/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800165- (void)setLocalDescription:(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/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800170- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800171 completionHandler:
172 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800173
174@end
175
176@interface RTCPeerConnection (DataChannel)
177
178/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800179- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
180 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800181
182@end
183
184@interface RTCPeerConnection (Stats)
185
186/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
187 * statistics are gathered for all tracks.
188 */
189- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800190 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800191 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
192 completionHandler:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800193 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800194
195@end
196
197NS_ASSUME_NONNULL_END