blob: 59ab2b8b26fddf9706e85d46dfddf5ab4b8daa3b [file] [log] [blame]
hjone373dc22016-01-22 14:04:27 -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
tkchin8b9ca952016-03-31 12:08:03 -070011#import <AvailabilityMacros.h>
hjone373dc22016-01-22 14:04:27 -080012#import <Foundation/Foundation.h>
13
14NS_ASSUME_NONNULL_BEGIN
15
16@interface RTCDataBuffer : NSObject
17
18/** NSData representation of the underlying buffer. */
19@property(nonatomic, readonly) NSData *data;
20
21/** Indicates whether |data| contains UTF-8 or binary data. */
22@property(nonatomic, readonly) BOOL isBinary;
23
24- (instancetype)init NS_UNAVAILABLE;
25
26/**
27 * Initialize an RTCDataBuffer from NSData. |isBinary| indicates whether |data|
28 * contains UTF-8 or binary data.
29 */
30- (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary;
31
32@end
33
34
35@class RTCDataChannel;
hjone373dc22016-01-22 14:04:27 -080036@protocol RTCDataChannelDelegate <NSObject>
37
38/** The data channel state changed. */
39- (void)dataChannelDidChangeState:(RTCDataChannel *)dataChannel;
40
41/** The data channel successfully received a data buffer. */
42- (void)dataChannel:(RTCDataChannel *)dataChannel
43 didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer;
44
45@optional
hjone373dc22016-01-22 14:04:27 -080046/** The data channel's |bufferedAmount| changed. */
47- (void)dataChannel:(RTCDataChannel *)dataChannel
tkchin121ac122016-03-21 09:08:40 -070048 didChangeBufferedAmount:(uint64_t)amount;
hjone373dc22016-01-22 14:04:27 -080049
50@end
51
52
53/** Represents the state of the data channel. */
54typedef NS_ENUM(NSInteger, RTCDataChannelState) {
tkchin8b9ca952016-03-31 12:08:03 -070055 RTCDataChannelStateConnecting,
56 RTCDataChannelStateOpen,
57 RTCDataChannelStateClosing,
58 RTCDataChannelStateClosed,
hjone373dc22016-01-22 14:04:27 -080059};
60
tkchin8b9ca952016-03-31 12:08:03 -070061
hjone373dc22016-01-22 14:04:27 -080062@interface RTCDataChannel : NSObject
63
64/**
65 * A label that can be used to distinguish this data channel from other data
66 * channel objects.
67 */
68@property(nonatomic, readonly) NSString *label;
69
tkchin8b9ca952016-03-31 12:08:03 -070070/** Whether the data channel can send messages in unreliable mode. */
71@property(nonatomic, readonly) BOOL isReliable DEPRECATED_ATTRIBUTE;
72
hjone373dc22016-01-22 14:04:27 -080073/** Returns whether this data channel is ordered or not. */
74@property(nonatomic, readonly) BOOL isOrdered;
75
tkchin8b9ca952016-03-31 12:08:03 -070076/** Deprecated. Use maxPacketLifeTime. */
77@property(nonatomic, readonly) NSUInteger maxRetransmitTime
78 DEPRECATED_ATTRIBUTE;
79
hjone373dc22016-01-22 14:04:27 -080080/**
81 * The length of the time window (in milliseconds) during which transmissions
82 * and retransmissions may occur in unreliable mode.
83 */
84@property(nonatomic, readonly) uint16_t maxPacketLifeTime;
85
86/**
87 * The maximum number of retransmissions that are attempted in unreliable mode.
88 */
89@property(nonatomic, readonly) uint16_t maxRetransmits;
90
91/**
92 * The name of the sub-protocol used with this data channel, if any. Otherwise
93 * this returns an empty string.
94 */
95@property(nonatomic, readonly) NSString *protocol;
96
97/**
98 * Returns whether this data channel was negotiated by the application or not.
99 */
100@property(nonatomic, readonly) BOOL isNegotiated;
101
tkchin8b9ca952016-03-31 12:08:03 -0700102/** Deprecated. Use channelId. */
103@property(nonatomic, readonly) NSInteger streamId DEPRECATED_ATTRIBUTE;
104
hjone373dc22016-01-22 14:04:27 -0800105/** The identifier for this data channel. */
hjona2f77982016-03-04 07:09:09 -0800106@property(nonatomic, readonly) int channelId;
hjone373dc22016-01-22 14:04:27 -0800107
108/** The state of the data channel. */
109@property(nonatomic, readonly) RTCDataChannelState readyState;
110
111/**
112 * The number of bytes of application data that have been queued using
113 * |sendData:| but that have not yet been transmitted to the network.
114 */
115@property(nonatomic, readonly) uint64_t bufferedAmount;
116
117/** The delegate for this data channel. */
118@property(nonatomic, weak) id<RTCDataChannelDelegate> delegate;
119
120- (instancetype)init NS_UNAVAILABLE;
121
122/** Closes the data channel. */
123- (void)close;
124
125/** Attempt to send |data| on this data channel's underlying data transport. */
126- (BOOL)sendData:(RTCDataBuffer *)data;
127
128@end
129
130NS_ASSUME_NONNULL_END