blob: 5acaa8093fbfbc608edd39de6817ec25ecc38bd6 [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
tkchin8b577ed2016-04-19 10:04:41 -070013#import "webrtc/base/objc/RTCMacros.h"
14
hjonf396f602016-02-11 16:19:06 -080015@class RTCConfiguration;
16@class RTCDataChannel;
17@class RTCDataChannelConfiguration;
18@class RTCIceCandidate;
19@class RTCMediaConstraints;
20@class RTCMediaStream;
21@class RTCMediaStreamTrack;
22@class RTCPeerConnectionFactory;
skvlad79b4b872016-04-08 17:28:55 -070023@class RTCRtpSender;
hjonf396f602016-02-11 16:19:06 -080024@class RTCSessionDescription;
25@class RTCStatsReport;
26
27NS_ASSUME_NONNULL_BEGIN
28
Jon Hjelle32e0c012016-03-08 16:04:46 -080029extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080030extern int const kRTCSessionDescriptionErrorCode;
31
32/** Represents the signaling state of the peer connection. */
33typedef NS_ENUM(NSInteger, RTCSignalingState) {
34 RTCSignalingStateStable,
35 RTCSignalingStateHaveLocalOffer,
36 RTCSignalingStateHaveLocalPrAnswer,
37 RTCSignalingStateHaveRemoteOffer,
38 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070039 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080040 RTCSignalingStateClosed,
41};
42
43/** Represents the ice connection state of the peer connection. */
44typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
45 RTCIceConnectionStateNew,
46 RTCIceConnectionStateChecking,
47 RTCIceConnectionStateConnected,
48 RTCIceConnectionStateCompleted,
49 RTCIceConnectionStateFailed,
50 RTCIceConnectionStateDisconnected,
51 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070052 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080053};
54
55/** Represents the ice gathering state of the peer connection. */
56typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
57 RTCIceGatheringStateNew,
58 RTCIceGatheringStateGathering,
59 RTCIceGatheringStateComplete,
60};
61
62/** Represents the stats output level. */
63typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
64 RTCStatsOutputLevelStandard,
65 RTCStatsOutputLevelDebug,
66};
67
68@class RTCPeerConnection;
69
tkchin8b577ed2016-04-19 10:04:41 -070070RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -080071@protocol RTCPeerConnectionDelegate <NSObject>
72
73/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080074- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080075 didChangeSignalingState:(RTCSignalingState)stateChanged;
76
77/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080078- (void)peerConnection:(RTCPeerConnection *)peerConnection
79 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080080
81/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080082- (void)peerConnection:(RTCPeerConnection *)peerConnection
83 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080084
85/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080086- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080087
88/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080089- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080090 didChangeIceConnectionState:(RTCIceConnectionState)newState;
91
92/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080093- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080094 didChangeIceGatheringState:(RTCIceGatheringState)newState;
95
96/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080097- (void)peerConnection:(RTCPeerConnection *)peerConnection
98 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -080099
100/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800101- (void)peerConnection:(RTCPeerConnection *)peerConnection
102 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -0800103
104@end
105
tkchin8b577ed2016-04-19 10:04:41 -0700106RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -0800107@interface RTCPeerConnection : NSObject
108
109/** The object that will be notifed about events such as state changes and
110 * streams being added or removed.
111 */
hjon6b039952016-02-25 12:32:58 -0800112@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
Jon Hjelle32e0c012016-03-08 16:04:46 -0800113@property(nonatomic, readonly) NSArray *localStreams;
hjonf396f602016-02-11 16:19:06 -0800114@property(nonatomic, readonly, nullable)
115 RTCSessionDescription *localDescription;
116@property(nonatomic, readonly, nullable)
117 RTCSessionDescription *remoteDescription;
118@property(nonatomic, readonly) RTCSignalingState signalingState;
119@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
120@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
121
skvlad79b4b872016-04-08 17:28:55 -0700122/** Gets all RTCRtpSenders associated with this peer connection.
123 * Note: reading this property returns different instances of RTCRtpSender.
124 * Use isEqual: instead of == to compare RTCRtpSender instances.
125 */
126@property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders;
127
Jon Hjelle32e0c012016-03-08 16:04:46 -0800128- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800129
tkchinaac3eb22016-03-09 21:49:40 -0800130/** Sets the PeerConnection's global configuration to |configuration|.
131 * Any changes to STUN/TURN servers or ICE candidate policy will affect the
132 * next gathering phase, and cause the next call to createOffer to generate
133 * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies
134 * cannot be changed with this method.
135 */
136- (BOOL)setConfiguration:(RTCConfiguration *)configuration;
137
hjonf396f602016-02-11 16:19:06 -0800138/** Terminate all media and close the transport. */
139- (void)close;
140
141/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800142- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800143
144/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800145- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800146
147/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800148- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800149
150/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800151- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800152 completionHandler:(nullable void (^)
153 (RTCSessionDescription * _Nullable sdp,
154 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800155
156/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800157- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800158 completionHandler:(nullable void (^)
159 (RTCSessionDescription * _Nullable sdp,
160 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800161
162/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800163- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800164 completionHandler:
165 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800166
167/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800168- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800169 completionHandler:
170 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800171
172@end
173
174@interface RTCPeerConnection (DataChannel)
175
176/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800177- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
178 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800179
180@end
181
182@interface RTCPeerConnection (Stats)
183
184/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil
185 * statistics are gathered for all tracks.
186 */
187- (void)statsForTrack:
hjona2f77982016-03-04 07:09:09 -0800188 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800189 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
190 completionHandler:
Jon Hjelle32e0c012016-03-08 16:04:46 -0800191 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800192
193@end
194
195NS_ASSUME_NONNULL_END