hjon | e373dc2 | 2016-01-22 14:04:27 -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 | |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 11 | #import <AvailabilityMacros.h> |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 12 | #import <Foundation/Foundation.h> |
| 13 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 14 | #import <WebRTC/RTCMacros.h> |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 15 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 16 | NS_ASSUME_NONNULL_BEGIN |
| 17 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 18 | RTC_EXPORT |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 19 | @interface RTCDataBuffer : NSObject |
| 20 | |
| 21 | /** NSData representation of the underlying buffer. */ |
| 22 | @property(nonatomic, readonly) NSData *data; |
| 23 | |
| 24 | /** Indicates whether |data| contains UTF-8 or binary data. */ |
| 25 | @property(nonatomic, readonly) BOOL isBinary; |
| 26 | |
| 27 | - (instancetype)init NS_UNAVAILABLE; |
| 28 | |
| 29 | /** |
| 30 | * Initialize an RTCDataBuffer from NSData. |isBinary| indicates whether |data| |
| 31 | * contains UTF-8 or binary data. |
| 32 | */ |
| 33 | - (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary; |
| 34 | |
| 35 | @end |
| 36 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 37 | @class RTCDataChannel; |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 38 | RTC_EXPORT |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 39 | @protocol RTCDataChannelDelegate <NSObject> |
| 40 | |
| 41 | /** The data channel state changed. */ |
| 42 | - (void)dataChannelDidChangeState:(RTCDataChannel *)dataChannel; |
| 43 | |
| 44 | /** The data channel successfully received a data buffer. */ |
| 45 | - (void)dataChannel:(RTCDataChannel *)dataChannel |
| 46 | didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer; |
| 47 | |
| 48 | @optional |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 49 | /** The data channel's |bufferedAmount| changed. */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 50 | - (void)dataChannel:(RTCDataChannel *)dataChannel didChangeBufferedAmount:(uint64_t)amount; |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 51 | |
| 52 | @end |
| 53 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 54 | /** Represents the state of the data channel. */ |
| 55 | typedef NS_ENUM(NSInteger, RTCDataChannelState) { |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 56 | RTCDataChannelStateConnecting, |
| 57 | RTCDataChannelStateOpen, |
| 58 | RTCDataChannelStateClosing, |
| 59 | RTCDataChannelStateClosed, |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 62 | RTC_EXPORT |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 63 | @interface RTCDataChannel : NSObject |
| 64 | |
| 65 | /** |
| 66 | * A label that can be used to distinguish this data channel from other data |
| 67 | * channel objects. |
| 68 | */ |
| 69 | @property(nonatomic, readonly) NSString *label; |
| 70 | |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 71 | /** Whether the data channel can send messages in unreliable mode. */ |
| 72 | @property(nonatomic, readonly) BOOL isReliable DEPRECATED_ATTRIBUTE; |
| 73 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 74 | /** Returns whether this data channel is ordered or not. */ |
| 75 | @property(nonatomic, readonly) BOOL isOrdered; |
| 76 | |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 77 | /** Deprecated. Use maxPacketLifeTime. */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 78 | @property(nonatomic, readonly) NSUInteger maxRetransmitTime DEPRECATED_ATTRIBUTE; |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 79 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 80 | /** |
| 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 | |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 102 | /** Deprecated. Use channelId. */ |
| 103 | @property(nonatomic, readonly) NSInteger streamId DEPRECATED_ATTRIBUTE; |
| 104 | |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 105 | /** The identifier for this data channel. */ |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 106 | @property(nonatomic, readonly) int channelId; |
hjon | e373dc2 | 2016-01-22 14:04:27 -0800 | [diff] [blame] | 107 | |
| 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 | |
| 130 | NS_ASSUME_NONNULL_END |