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 |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 25 | // TODO(hjon): Update nullability types. See http://crbug/webrtc/5592 |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 26 | |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 27 | extern NSString * _Nonnull const kRTCPeerConnectionErrorDomain; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 28 | extern int const kRTCSessionDescriptionErrorCode; |
| 29 | |
| 30 | /** Represents the signaling state of the peer connection. */ |
| 31 | typedef 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. */ |
| 41 | typedef 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. */ |
| 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. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 70 | - (void)peerConnection:(nonnull 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. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 74 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
| 75 | didAddStream:(nonnull RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 76 | |
| 77 | /** Called when a remote peer closes a stream. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 78 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
| 79 | didRemoveStream:(nonnull 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. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 82 | - (void)peerConnectionShouldNegotiate: |
| 83 | (nonnull RTCPeerConnection *)peerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 84 | |
| 85 | /** Called any time the IceConnectionState changes. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 86 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 87 | didChangeIceConnectionState:(RTCIceConnectionState)newState; |
| 88 | |
| 89 | /** Called any time the IceGatheringState changes. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 90 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 91 | didChangeIceGatheringState:(RTCIceGatheringState)newState; |
| 92 | |
| 93 | /** New ice candidate has been found. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 94 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
| 95 | didGenerateIceCandidate:(nonnull RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 96 | |
| 97 | /** New data channel has been opened. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 98 | - (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection |
| 99 | didOpenDataChannel:(nonnull RTCDataChannel *)dataChannel; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 100 | |
| 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 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 109 | @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; |
| 110 | @property(nonatomic, readonly, nonnull) NSArray *localStreams; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 111 | @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 | |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 119 | - (nonnull instancetype)init NS_UNAVAILABLE; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 120 | |
| 121 | /** Initialize an RTCPeerConnection with a configuration, constraints, and |
| 122 | * delegate. |
| 123 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 124 | - (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 |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 132 | 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. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 138 | - (void)addIceCandidate:(nonnull RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 139 | |
| 140 | /** Add a new media stream to be sent on this peer connection. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 141 | - (void)addStream:(nonnull RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 142 | |
| 143 | /** Remove the given media stream from this peer connection. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 144 | - (void)removeStream:(nonnull RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 145 | |
| 146 | /** Generate an SDP offer. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 147 | - (void)offerForConstraints:(nonnull RTCMediaConstraints *)constraints |
| 148 | completionHandler:(nullable void (^) |
| 149 | (RTCSessionDescription * _Nullable sdp, |
| 150 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 151 | |
| 152 | /** Generate an SDP answer. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 153 | - (void)answerForConstraints:(nonnull RTCMediaConstraints *)constraints |
| 154 | completionHandler:(nullable void (^) |
| 155 | (RTCSessionDescription * _Nullable sdp, |
| 156 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 157 | |
| 158 | /** Apply the supplied RTCSessionDescription as the local description. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 159 | - (void)setLocalDescription:(nonnull RTCSessionDescription *)sdp |
| 160 | completionHandler: |
| 161 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 162 | |
| 163 | /** Apply the supplied RTCSessionDescription as the remote description. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 164 | - (void)setRemoteDescription:(nonnull RTCSessionDescription *)sdp |
| 165 | completionHandler: |
| 166 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 167 | |
| 168 | @end |
| 169 | |
| 170 | @interface RTCPeerConnection (DataChannel) |
| 171 | |
| 172 | /** Create a new data channel with the given label and configuration. */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 173 | - (nonnull RTCDataChannel *)dataChannelForLabel:(nonnull NSString *)label |
| 174 | configuration:(nonnull RTCDataChannelConfiguration *)configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 175 | |
| 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: |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame^] | 184 | (nullable RTCMediaStreamTrack *)mediaStreamTrack |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 185 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel |
| 186 | completionHandler: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 187 | (nullable void (^)(NSArray * _Nonnull stats))completionHandler; |
| 188 | // (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 189 | |
| 190 | @end |
| 191 | |
| 192 | NS_ASSUME_NONNULL_END |