RTCDataChannel.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #import <AvailabilityMacros.h>
  11. #import <Foundation/Foundation.h>
  12. #import "RTCMacros.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. RTC_OBJC_EXPORT
  15. @interface RTCDataBuffer : NSObject
  16. /** NSData representation of the underlying buffer. */
  17. @property(nonatomic, readonly) NSData *data;
  18. /** Indicates whether |data| contains UTF-8 or binary data. */
  19. @property(nonatomic, readonly) BOOL isBinary;
  20. - (instancetype)init NS_UNAVAILABLE;
  21. /**
  22. * Initialize an RTCDataBuffer from NSData. |isBinary| indicates whether |data|
  23. * contains UTF-8 or binary data.
  24. */
  25. - (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary;
  26. @end
  27. @class RTCDataChannel;
  28. RTC_OBJC_EXPORT
  29. @protocol RTCDataChannelDelegate <NSObject>
  30. /** The data channel state changed. */
  31. - (void)dataChannelDidChangeState:(RTCDataChannel *)dataChannel;
  32. /** The data channel successfully received a data buffer. */
  33. - (void)dataChannel:(RTCDataChannel *)dataChannel
  34. didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer;
  35. @optional
  36. /** The data channel's |bufferedAmount| changed. */
  37. - (void)dataChannel:(RTCDataChannel *)dataChannel didChangeBufferedAmount:(uint64_t)amount;
  38. @end
  39. /** Represents the state of the data channel. */
  40. typedef NS_ENUM(NSInteger, RTCDataChannelState) {
  41. RTCDataChannelStateConnecting,
  42. RTCDataChannelStateOpen,
  43. RTCDataChannelStateClosing,
  44. RTCDataChannelStateClosed,
  45. };
  46. RTC_OBJC_EXPORT
  47. @interface RTCDataChannel : NSObject
  48. /**
  49. * A label that can be used to distinguish this data channel from other data
  50. * channel objects.
  51. */
  52. @property(nonatomic, readonly) NSString *label;
  53. /** Whether the data channel can send messages in unreliable mode. */
  54. @property(nonatomic, readonly) BOOL isReliable DEPRECATED_ATTRIBUTE;
  55. /** Returns whether this data channel is ordered or not. */
  56. @property(nonatomic, readonly) BOOL isOrdered;
  57. /** Deprecated. Use maxPacketLifeTime. */
  58. @property(nonatomic, readonly) NSUInteger maxRetransmitTime DEPRECATED_ATTRIBUTE;
  59. /**
  60. * The length of the time window (in milliseconds) during which transmissions
  61. * and retransmissions may occur in unreliable mode.
  62. */
  63. @property(nonatomic, readonly) uint16_t maxPacketLifeTime;
  64. /**
  65. * The maximum number of retransmissions that are attempted in unreliable mode.
  66. */
  67. @property(nonatomic, readonly) uint16_t maxRetransmits;
  68. /**
  69. * The name of the sub-protocol used with this data channel, if any. Otherwise
  70. * this returns an empty string.
  71. */
  72. @property(nonatomic, readonly) NSString *protocol;
  73. /**
  74. * Returns whether this data channel was negotiated by the application or not.
  75. */
  76. @property(nonatomic, readonly) BOOL isNegotiated;
  77. /** Deprecated. Use channelId. */
  78. @property(nonatomic, readonly) NSInteger streamId DEPRECATED_ATTRIBUTE;
  79. /** The identifier for this data channel. */
  80. @property(nonatomic, readonly) int channelId;
  81. /** The state of the data channel. */
  82. @property(nonatomic, readonly) RTCDataChannelState readyState;
  83. /**
  84. * The number of bytes of application data that have been queued using
  85. * |sendData:| but that have not yet been transmitted to the network.
  86. */
  87. @property(nonatomic, readonly) uint64_t bufferedAmount;
  88. /** The delegate for this data channel. */
  89. @property(nonatomic, weak) id<RTCDataChannelDelegate> delegate;
  90. - (instancetype)init NS_UNAVAILABLE;
  91. /** Closes the data channel. */
  92. - (void)close;
  93. /** Attempt to send |data| on this data channel's underlying data transport. */
  94. - (BOOL)sendData:(RTCDataBuffer *)data;
  95. @end
  96. NS_ASSUME_NONNULL_END