blob: 72645b523f44560c7b5bf11d74066f58842ebaf3 [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
hjon6b039952016-02-25 12:32:58 -080025// TODO(hjon): Update nullability types. See http://crbug/webrtc/5592
hjonf396f602016-02-11 16:19:06 -080026
hjon6b039952016-02-25 12:32:58 -080027extern NSString * _Nonnull 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,
37 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,
49 RTCIceConnectionStateMax,
50};
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. */
hjon6b039952016-02-25 12:32:58 -080070- (void)peerConnection:(nonnull 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. */
hjon6b039952016-02-25 12:32:58 -080074- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
75 didAddStream:(nonnull RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080076
77/** Called when a remote peer closes a stream. */
hjon6b039952016-02-25 12:32:58 -080078- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
79 didRemoveStream:(nonnull RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080080
81/** Called when negotiation is needed, for example ICE has restarted. */
hjon6b039952016-02-25 12:32:58 -080082- (void)peerConnectionShouldNegotiate:
83 (nonnull RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080084
85/** Called any time the IceConnectionState changes. */
hjon6b039952016-02-25 12:32:58 -080086- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080087 didChangeIceConnectionState:(RTCIceConnectionState)newState;
88
89/** Called any time the IceGatheringState changes. */
hjon6b039952016-02-25 12:32:58 -080090- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080091 didChangeIceGatheringState:(RTCIceGatheringState)newState;
92
93/** New ice candidate has been found. */
hjon6b039952016-02-25 12:32:58 -080094- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
95 didGenerateIceCandidate:(nonnull RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -080096
97/** New data channel has been opened. */
hjon6b039952016-02-25 12:32:58 -080098- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
99 didOpenDataChannel:(nonnull 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;
110@property(nonatomic, readonly, nonnull) 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
hjon6b039952016-02-25 12:32:58 -0800119- (nonnull instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800120
121/** Initialize an RTCPeerConnection with a configuration, constraints, and
122 * delegate.
123 */
hjon6b039952016-02-25 12:32:58 -0800124- (nonnull instancetype)initWithFactory:
125 (nonnull RTCPeerConnectionFactory *)factory
126 configuration:
127 (nonnull RTCConfiguration *)configuration
128 constraints:
129 (nonnull RTCMediaConstraints *)constraints
130 delegate:
131 (nullable id<RTCPeerConnectionDelegate>)delegate
hjonf396f602016-02-11 16:19:06 -0800132 NS_DESIGNATED_INITIALIZER;
133
134/** Terminate all media and close the transport. */
135- (void)close;
136
137/** Provide a remote candidate to the ICE Agent. */
hjon6b039952016-02-25 12:32:58 -0800138- (void)addIceCandidate:(nonnull RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800139
140/** Add a new media stream to be sent on this peer connection. */
hjon6b039952016-02-25 12:32:58 -0800141- (void)addStream:(nonnull RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800142
143/** Remove the given media stream from this peer connection. */
hjon6b039952016-02-25 12:32:58 -0800144- (void)removeStream:(nonnull RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800145
146/** Generate an SDP offer. */
hjon6b039952016-02-25 12:32:58 -0800147- (void)offerForConstraints:(nonnull RTCMediaConstraints *)constraints
148 completionHandler:(nullable void (^)
149 (RTCSessionDescription * _Nullable sdp,
150 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800151
152/** Generate an SDP answer. */
hjon6b039952016-02-25 12:32:58 -0800153- (void)answerForConstraints:(nonnull RTCMediaConstraints *)constraints
154 completionHandler:(nullable void (^)
155 (RTCSessionDescription * _Nullable sdp,
156 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800157
158/** Apply the supplied RTCSessionDescription as the local description. */
hjon6b039952016-02-25 12:32:58 -0800159- (void)setLocalDescription:(nonnull RTCSessionDescription *)sdp
160 completionHandler:
161 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800162
163/** Apply the supplied RTCSessionDescription as the remote description. */
hjon6b039952016-02-25 12:32:58 -0800164- (void)setRemoteDescription:(nonnull RTCSessionDescription *)sdp
165 completionHandler:
166 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800167
168@end
169
170@interface RTCPeerConnection (DataChannel)
171
172/** Create a new data channel with the given label and configuration. */
hjon6b039952016-02-25 12:32:58 -0800173- (nonnull RTCDataChannel *)dataChannelForLabel:(nonnull NSString *)label
174 configuration:(nonnull RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800175
176@end
177
178@interface RTCPeerConnection (Stats)
179
180/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
181 * statistics are gathered for all tracks.
182 */
183- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800184 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800185 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
186 completionHandler:
hjon6b039952016-02-25 12:32:58 -0800187 (nullable void (^)(NSArray * _Nonnull stats))completionHandler;
188 // (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800189
190@end
191
192NS_ASSUME_NONNULL_END