RTCDataChannel.h 3.9 KB

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