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, |
| 36 | RTCSignalingStateClosed, |
| 37 | }; |
| 38 | |
| 39 | /** Represents the ice connection state of the peer connection. */ |
| 40 | typedef NS_ENUM(NSInteger, RTCIceConnectionState) { |
| 41 | RTCIceConnectionStateNew, |
| 42 | RTCIceConnectionStateChecking, |
| 43 | RTCIceConnectionStateConnected, |
| 44 | RTCIceConnectionStateCompleted, |
| 45 | RTCIceConnectionStateFailed, |
| 46 | RTCIceConnectionStateDisconnected, |
| 47 | RTCIceConnectionStateClosed, |
| 48 | RTCIceConnectionStateMax, |
| 49 | }; |
| 50 | |
| 51 | /** Represents the ice gathering state of the peer connection. */ |
| 52 | typedef NS_ENUM(NSInteger, RTCIceGatheringState) { |
| 53 | RTCIceGatheringStateNew, |
| 54 | RTCIceGatheringStateGathering, |
| 55 | RTCIceGatheringStateComplete, |
| 56 | }; |
| 57 | |
| 58 | /** Represents the stats output level. */ |
| 59 | typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) { |
| 60 | RTCStatsOutputLevelStandard, |
| 61 | RTCStatsOutputLevelDebug, |
| 62 | }; |
| 63 | |
| 64 | @class RTCPeerConnection; |
| 65 | |
| 66 | @protocol RTCPeerConnectionDelegate <NSObject> |
| 67 | |
| 68 | /** Called when the SignalingState changed. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 69 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 70 | didChangeSignalingState:(RTCSignalingState)stateChanged; |
| 71 | |
| 72 | /** Called when media is received on a new stream from remote peer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 73 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 74 | didAddStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 75 | |
| 76 | /** Called when a remote peer closes a stream. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 77 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 78 | didRemoveStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 79 | |
| 80 | /** Called when negotiation is needed, for example ICE has restarted. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 81 | - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 82 | |
| 83 | /** Called any time the IceConnectionState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 84 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 85 | didChangeIceConnectionState:(RTCIceConnectionState)newState; |
| 86 | |
| 87 | /** Called any time the IceGatheringState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 88 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 89 | didChangeIceGatheringState:(RTCIceGatheringState)newState; |
| 90 | |
| 91 | /** New ice candidate has been found. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 92 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 93 | didGenerateIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 94 | |
| 95 | /** New data channel has been opened. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 96 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 97 | didOpenDataChannel:(RTCDataChannel *)dataChannel; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 98 | |
| 99 | @end |
| 100 | |
| 101 | |
| 102 | @interface RTCPeerConnection : NSObject |
| 103 | |
| 104 | /** The object that will be notifed about events such as state changes and |
| 105 | * streams being added or removed. |
| 106 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 107 | @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 108 | @property(nonatomic, readonly) NSArray *localStreams; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 109 | @property(nonatomic, readonly, nullable) |
| 110 | RTCSessionDescription *localDescription; |
| 111 | @property(nonatomic, readonly, nullable) |
| 112 | RTCSessionDescription *remoteDescription; |
| 113 | @property(nonatomic, readonly) RTCSignalingState signalingState; |
| 114 | @property(nonatomic, readonly) RTCIceConnectionState iceConnectionState; |
| 115 | @property(nonatomic, readonly) RTCIceGatheringState iceGatheringState; |
| 116 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 117 | - (instancetype)init NS_UNAVAILABLE; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 118 | |
| 119 | /** Initialize an RTCPeerConnection with a configuration, constraints, and |
| 120 | * delegate. |
| 121 | */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 122 | - (instancetype)initWithFactory: |
| 123 | (RTCPeerConnectionFactory *)factory |
| 124 | configuration: |
| 125 | (RTCConfiguration *)configuration |
| 126 | constraints: |
| 127 | (RTCMediaConstraints *)constraints |
| 128 | delegate: |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 129 | (nullable id<RTCPeerConnectionDelegate>)delegate |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 130 | NS_DESIGNATED_INITIALIZER; |
| 131 | |
| 132 | /** Terminate all media and close the transport. */ |
| 133 | - (void)close; |
| 134 | |
| 135 | /** Provide a remote candidate to the ICE Agent. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 136 | - (void)addIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 137 | |
| 138 | /** Add a new media stream to be sent on this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 139 | - (void)addStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 140 | |
| 141 | /** Remove the given media stream from this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 142 | - (void)removeStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 143 | |
| 144 | /** Generate an SDP offer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 145 | - (void)offerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 146 | completionHandler:(nullable void (^) |
| 147 | (RTCSessionDescription * _Nullable sdp, |
| 148 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 149 | |
| 150 | /** Generate an SDP answer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 151 | - (void)answerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 152 | completionHandler:(nullable void (^) |
| 153 | (RTCSessionDescription * _Nullable sdp, |
| 154 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 155 | |
| 156 | /** Apply the supplied RTCSessionDescription as the local description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 157 | - (void)setLocalDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 158 | completionHandler: |
| 159 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 160 | |
| 161 | /** Apply the supplied RTCSessionDescription as the remote description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 162 | - (void)setRemoteDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 163 | completionHandler: |
| 164 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 165 | |
| 166 | @end |
| 167 | |
| 168 | @interface RTCPeerConnection (DataChannel) |
| 169 | |
| 170 | /** Create a new data channel with the given label and configuration. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 171 | - (RTCDataChannel *)dataChannelForLabel:(NSString *)label |
| 172 | configuration:(RTCDataChannelConfiguration *)configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 173 | |
| 174 | @end |
| 175 | |
| 176 | @interface RTCPeerConnection (Stats) |
| 177 | |
| 178 | /** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil |
| 179 | * statistics are gathered for all tracks. |
| 180 | */ |
| 181 | - (void)statsForTrack: |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 182 | (nullable RTCMediaStreamTrack *)mediaStreamTrack |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 183 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel |
| 184 | completionHandler: |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame^] | 185 | (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 186 | |
| 187 | @end |
| 188 | |
| 189 | NS_ASSUME_NONNULL_END |