hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 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 | @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 | |
| 24 | NS_ASSUME_NONNULL_BEGIN |
| 25 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 26 | extern NSString * const kRTCPeerConnectionErrorDomain; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 27 | extern int const kRTCSessionDescriptionErrorCode; |
| 28 | |
| 29 | /** Represents the signaling state of the peer connection. */ |
| 30 | typedef NS_ENUM(NSInteger, RTCSignalingState) { |
| 31 | RTCSignalingStateStable, |
| 32 | RTCSignalingStateHaveLocalOffer, |
| 33 | RTCSignalingStateHaveLocalPrAnswer, |
| 34 | RTCSignalingStateHaveRemoteOffer, |
| 35 | RTCSignalingStateHaveRemotePrAnswer, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame^] | 36 | // Not an actual state, represents the total number of states. |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 37 | RTCSignalingStateClosed, |
| 38 | }; |
| 39 | |
| 40 | /** Represents the ice connection state of the peer connection. */ |
| 41 | typedef NS_ENUM(NSInteger, RTCIceConnectionState) { |
| 42 | RTCIceConnectionStateNew, |
| 43 | RTCIceConnectionStateChecking, |
| 44 | RTCIceConnectionStateConnected, |
| 45 | RTCIceConnectionStateCompleted, |
| 46 | RTCIceConnectionStateFailed, |
| 47 | RTCIceConnectionStateDisconnected, |
| 48 | RTCIceConnectionStateClosed, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame^] | 49 | RTCIceConnectionStateCount, |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** Represents the ice gathering state of the peer connection. */ |
| 53 | typedef NS_ENUM(NSInteger, RTCIceGatheringState) { |
| 54 | RTCIceGatheringStateNew, |
| 55 | RTCIceGatheringStateGathering, |
| 56 | RTCIceGatheringStateComplete, |
| 57 | }; |
| 58 | |
| 59 | /** Represents the stats output level. */ |
| 60 | typedef 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 Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 70 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 71 | didChangeSignalingState:(RTCSignalingState)stateChanged; |
| 72 | |
| 73 | /** Called when media is received on a new stream from remote peer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 74 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 75 | didAddStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 76 | |
| 77 | /** Called when a remote peer closes a stream. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 78 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 79 | didRemoveStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 80 | |
| 81 | /** Called when negotiation is needed, for example ICE has restarted. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 82 | - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 83 | |
| 84 | /** Called any time the IceConnectionState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 85 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 86 | didChangeIceConnectionState:(RTCIceConnectionState)newState; |
| 87 | |
| 88 | /** Called any time the IceGatheringState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 89 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 90 | didChangeIceGatheringState:(RTCIceGatheringState)newState; |
| 91 | |
| 92 | /** New ice candidate has been found. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 93 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 94 | didGenerateIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 95 | |
| 96 | /** New data channel has been opened. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 97 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 98 | didOpenDataChannel:(RTCDataChannel *)dataChannel; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 99 | |
| 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 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 108 | @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 109 | @property(nonatomic, readonly) NSArray *localStreams; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 110 | @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 Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 118 | - (instancetype)init NS_UNAVAILABLE; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 119 | |
| 120 | /** Initialize an RTCPeerConnection with a configuration, constraints, and |
| 121 | * delegate. |
| 122 | */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 123 | - (instancetype)initWithFactory: |
| 124 | (RTCPeerConnectionFactory *)factory |
| 125 | configuration: |
| 126 | (RTCConfiguration *)configuration |
| 127 | constraints: |
| 128 | (RTCMediaConstraints *)constraints |
| 129 | delegate: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 130 | (nullable id<RTCPeerConnectionDelegate>)delegate |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 131 | NS_DESIGNATED_INITIALIZER; |
| 132 | |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 133 | /** 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 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 141 | /** Terminate all media and close the transport. */ |
| 142 | - (void)close; |
| 143 | |
| 144 | /** Provide a remote candidate to the ICE Agent. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 145 | - (void)addIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 146 | |
| 147 | /** Add a new media stream to be sent on this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 148 | - (void)addStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 149 | |
| 150 | /** Remove the given media stream from this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 151 | - (void)removeStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 152 | |
| 153 | /** Generate an SDP offer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 154 | - (void)offerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 155 | completionHandler:(nullable void (^) |
| 156 | (RTCSessionDescription * _Nullable sdp, |
| 157 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 158 | |
| 159 | /** Generate an SDP answer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 160 | - (void)answerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 161 | completionHandler:(nullable void (^) |
| 162 | (RTCSessionDescription * _Nullable sdp, |
| 163 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 164 | |
| 165 | /** Apply the supplied RTCSessionDescription as the local description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 166 | - (void)setLocalDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 167 | completionHandler: |
| 168 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 169 | |
| 170 | /** Apply the supplied RTCSessionDescription as the remote description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 171 | - (void)setRemoteDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 172 | completionHandler: |
| 173 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 174 | |
| 175 | @end |
| 176 | |
| 177 | @interface RTCPeerConnection (DataChannel) |
| 178 | |
| 179 | /** Create a new data channel with the given label and configuration. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 180 | - (RTCDataChannel *)dataChannelForLabel:(NSString *)label |
| 181 | configuration:(RTCDataChannelConfiguration *)configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 182 | |
| 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: |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 191 | (nullable RTCMediaStreamTrack *)mediaStreamTrack |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 192 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel |
| 193 | completionHandler: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 194 | (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 195 | |
| 196 | @end |
| 197 | |
| 198 | NS_ASSUME_NONNULL_END |