blob: 6f4ef37f8f2e3ab7ddc16963546d3f541b6a0169 [file] [log] [blame]
Anders Carlsson7bca8ca2018-08-30 09:30:29 +02001/*
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 <AvailabilityMacros.h>
12#import <Foundation/Foundation.h>
13
14#import "RTCMacros.h"
15
16NS_ASSUME_NONNULL_BEGIN
17
Mirko Bonadeie8d57242018-09-17 10:22:56 +020018RTC_OBJC_EXPORT
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020019@interface RTC_OBJC_TYPE (RTCDataBuffer) : NSObject
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020020
21/** NSData representation of the underlying buffer. */
22@property(nonatomic, readonly) NSData *data;
23
Artem Titovd7ac5812021-07-27 12:23:39 +020024/** Indicates whether `data` contains UTF-8 or binary data. */
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020025@property(nonatomic, readonly) BOOL isBinary;
26
27- (instancetype)init NS_UNAVAILABLE;
28
29/**
Artem Titovd7ac5812021-07-27 12:23:39 +020030 * Initialize an RTCDataBuffer from NSData. `isBinary` indicates whether `data`
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020031 * contains UTF-8 or binary data.
32 */
33- (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary;
34
35@end
36
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020037@class RTC_OBJC_TYPE(RTCDataChannel);
Mirko Bonadeie8d57242018-09-17 10:22:56 +020038RTC_OBJC_EXPORT
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020039@protocol RTC_OBJC_TYPE
40(RTCDataChannelDelegate)<NSObject>
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020041
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020042 /** The data channel state changed. */
43 - (void)dataChannelDidChangeState : (RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020044
45/** The data channel successfully received a data buffer. */
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020046- (void)dataChannel:(RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel
47 didReceiveMessageWithBuffer:(RTC_OBJC_TYPE(RTCDataBuffer) *)buffer;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020048
49@optional
Artem Titovd7ac5812021-07-27 12:23:39 +020050/** The data channel's `bufferedAmount` changed. */
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020051- (void)dataChannel:(RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel
52 didChangeBufferedAmount:(uint64_t)amount;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020053
54@end
55
56/** Represents the state of the data channel. */
57typedef NS_ENUM(NSInteger, RTCDataChannelState) {
58 RTCDataChannelStateConnecting,
59 RTCDataChannelStateOpen,
60 RTCDataChannelStateClosing,
61 RTCDataChannelStateClosed,
62};
63
Mirko Bonadeie8d57242018-09-17 10:22:56 +020064RTC_OBJC_EXPORT
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020065@interface RTC_OBJC_TYPE (RTCDataChannel) : NSObject
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020066
67/**
68 * A label that can be used to distinguish this data channel from other data
69 * channel objects.
70 */
71@property(nonatomic, readonly) NSString *label;
72
73/** Whether the data channel can send messages in unreliable mode. */
74@property(nonatomic, readonly) BOOL isReliable DEPRECATED_ATTRIBUTE;
75
76/** Returns whether this data channel is ordered or not. */
77@property(nonatomic, readonly) BOOL isOrdered;
78
79/** Deprecated. Use maxPacketLifeTime. */
80@property(nonatomic, readonly) NSUInteger maxRetransmitTime DEPRECATED_ATTRIBUTE;
81
82/**
83 * The length of the time window (in milliseconds) during which transmissions
84 * and retransmissions may occur in unreliable mode.
85 */
86@property(nonatomic, readonly) uint16_t maxPacketLifeTime;
87
88/**
89 * The maximum number of retransmissions that are attempted in unreliable mode.
90 */
91@property(nonatomic, readonly) uint16_t maxRetransmits;
92
93/**
94 * The name of the sub-protocol used with this data channel, if any. Otherwise
95 * this returns an empty string.
96 */
97@property(nonatomic, readonly) NSString *protocol;
98
99/**
100 * Returns whether this data channel was negotiated by the application or not.
101 */
102@property(nonatomic, readonly) BOOL isNegotiated;
103
104/** Deprecated. Use channelId. */
105@property(nonatomic, readonly) NSInteger streamId DEPRECATED_ATTRIBUTE;
106
107/** The identifier for this data channel. */
108@property(nonatomic, readonly) int channelId;
109
110/** The state of the data channel. */
111@property(nonatomic, readonly) RTCDataChannelState readyState;
112
113/**
114 * The number of bytes of application data that have been queued using
115 * |sendData:| but that have not yet been transmitted to the network.
116 */
117@property(nonatomic, readonly) uint64_t bufferedAmount;
118
119/** The delegate for this data channel. */
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200120@property(nonatomic, weak) id<RTC_OBJC_TYPE(RTCDataChannelDelegate)> delegate;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +0200121
122- (instancetype)init NS_UNAVAILABLE;
123
124/** Closes the data channel. */
125- (void)close;
126
Artem Titovd7ac5812021-07-27 12:23:39 +0200127/** Attempt to send `data` on this data channel's underlying data transport. */
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200128- (BOOL)sendData:(RTC_OBJC_TYPE(RTCDataBuffer) *)data;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +0200129
130@end
131
132NS_ASSUME_NONNULL_END