OLD | NEW |
| (Empty) |
1 /* | |
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 #import "webrtc/base/objc/RTCMacros.h" | |
14 | |
15 @class RTCConfiguration; | |
16 @class RTCDataChannel; | |
17 @class RTCDataChannelConfiguration; | |
18 @class RTCIceCandidate; | |
19 @class RTCMediaConstraints; | |
20 @class RTCMediaStream; | |
21 @class RTCMediaStreamTrack; | |
22 @class RTCPeerConnectionFactory; | |
23 @class RTCRtpSender; | |
24 @class RTCSessionDescription; | |
25 @class RTCStatsReport; | |
26 | |
27 NS_ASSUME_NONNULL_BEGIN | |
28 | |
29 extern NSString * const kRTCPeerConnectionErrorDomain; | |
30 extern int const kRTCSessionDescriptionErrorCode; | |
31 | |
32 /** Represents the signaling state of the peer connection. */ | |
33 typedef NS_ENUM(NSInteger, RTCSignalingState) { | |
34 RTCSignalingStateStable, | |
35 RTCSignalingStateHaveLocalOffer, | |
36 RTCSignalingStateHaveLocalPrAnswer, | |
37 RTCSignalingStateHaveRemoteOffer, | |
38 RTCSignalingStateHaveRemotePrAnswer, | |
39 // Not an actual state, represents the total number of states. | |
40 RTCSignalingStateClosed, | |
41 }; | |
42 | |
43 /** Represents the ice connection state of the peer connection. */ | |
44 typedef NS_ENUM(NSInteger, RTCIceConnectionState) { | |
45 RTCIceConnectionStateNew, | |
46 RTCIceConnectionStateChecking, | |
47 RTCIceConnectionStateConnected, | |
48 RTCIceConnectionStateCompleted, | |
49 RTCIceConnectionStateFailed, | |
50 RTCIceConnectionStateDisconnected, | |
51 RTCIceConnectionStateClosed, | |
52 RTCIceConnectionStateCount, | |
53 }; | |
54 | |
55 /** Represents the ice gathering state of the peer connection. */ | |
56 typedef NS_ENUM(NSInteger, RTCIceGatheringState) { | |
57 RTCIceGatheringStateNew, | |
58 RTCIceGatheringStateGathering, | |
59 RTCIceGatheringStateComplete, | |
60 }; | |
61 | |
62 /** Represents the stats output level. */ | |
63 typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) { | |
64 RTCStatsOutputLevelStandard, | |
65 RTCStatsOutputLevelDebug, | |
66 }; | |
67 | |
68 @class RTCPeerConnection; | |
69 | |
70 RTC_EXPORT | |
71 @protocol RTCPeerConnectionDelegate <NSObject> | |
72 | |
73 /** Called when the SignalingState changed. */ | |
74 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
75 didChangeSignalingState:(RTCSignalingState)stateChanged; | |
76 | |
77 /** Called when media is received on a new stream from remote peer. */ | |
78 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
79 didAddStream:(RTCMediaStream *)stream; | |
80 | |
81 /** Called when a remote peer closes a stream. */ | |
82 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
83 didRemoveStream:(RTCMediaStream *)stream; | |
84 | |
85 /** Called when negotiation is needed, for example ICE has restarted. */ | |
86 - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; | |
87 | |
88 /** Called any time the IceConnectionState changes. */ | |
89 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
90 didChangeIceConnectionState:(RTCIceConnectionState)newState; | |
91 | |
92 /** Called any time the IceGatheringState changes. */ | |
93 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
94 didChangeIceGatheringState:(RTCIceGatheringState)newState; | |
95 | |
96 /** New ice candidate has been found. */ | |
97 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
98 didGenerateIceCandidate:(RTCIceCandidate *)candidate; | |
99 | |
100 /** New data channel has been opened. */ | |
101 - (void)peerConnection:(RTCPeerConnection *)peerConnection | |
102 didOpenDataChannel:(RTCDataChannel *)dataChannel; | |
103 | |
104 @end | |
105 | |
106 RTC_EXPORT | |
107 @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 */ | |
112 @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; | |
113 @property(nonatomic, readonly) NSArray *localStreams; | |
114 @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 | |
122 /** 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 | |
128 - (instancetype)init NS_UNAVAILABLE; | |
129 | |
130 /** 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 | |
138 /** Terminate all media and close the transport. */ | |
139 - (void)close; | |
140 | |
141 /** Provide a remote candidate to the ICE Agent. */ | |
142 - (void)addIceCandidate:(RTCIceCandidate *)candidate; | |
143 | |
144 /** Add a new media stream to be sent on this peer connection. */ | |
145 - (void)addStream:(RTCMediaStream *)stream; | |
146 | |
147 /** Remove the given media stream from this peer connection. */ | |
148 - (void)removeStream:(RTCMediaStream *)stream; | |
149 | |
150 /** Generate an SDP offer. */ | |
151 - (void)offerForConstraints:(RTCMediaConstraints *)constraints | |
152 completionHandler:(nullable void (^) | |
153 (RTCSessionDescription * _Nullable sdp, | |
154 NSError * _Nullable error))completionHandler; | |
155 | |
156 /** Generate an SDP answer. */ | |
157 - (void)answerForConstraints:(RTCMediaConstraints *)constraints | |
158 completionHandler:(nullable void (^) | |
159 (RTCSessionDescription * _Nullable sdp, | |
160 NSError * _Nullable error))completionHandler; | |
161 | |
162 /** Apply the supplied RTCSessionDescription as the local description. */ | |
163 - (void)setLocalDescription:(RTCSessionDescription *)sdp | |
164 completionHandler: | |
165 (nullable void (^)(NSError * _Nullable error))completionHandler; | |
166 | |
167 /** Apply the supplied RTCSessionDescription as the remote description. */ | |
168 - (void)setRemoteDescription:(RTCSessionDescription *)sdp | |
169 completionHandler: | |
170 (nullable void (^)(NSError * _Nullable error))completionHandler; | |
171 | |
172 @end | |
173 | |
174 @interface RTCPeerConnection (DataChannel) | |
175 | |
176 /** Create a new data channel with the given label and configuration. */ | |
177 - (RTCDataChannel *)dataChannelForLabel:(NSString *)label | |
178 configuration:(RTCDataChannelConfiguration *)configuration; | |
179 | |
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: | |
188 (nullable RTCMediaStreamTrack *)mediaStreamTrack | |
189 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel | |
190 completionHandler: | |
191 (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; | |
192 | |
193 @end | |
194 | |
195 NS_ASSUME_NONNULL_END | |
OLD | NEW |