1/*
2 * libjingle
3 * Copyright 2014, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 *  1. Redistributions of source code must retain the above copyright notice,
9 *     this list of conditions and the following disclaimer.
10 *  2. Redistributions in binary form must reproduce the above copyright notice,
11 *     this list of conditions and the following disclaimer in the documentation
12 *     and/or other materials provided with the distribution.
13 *  3. The name of the author may not be used to endorse or promote products
14 *     derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#import <Foundation/Foundation.h>
29
30// ObjectiveC wrapper for a DataChannelInit object.
31@interface RTCDataChannelInit : NSObject
32
33// Set to YES if ordered delivery is required
34@property(nonatomic) BOOL isOrdered;
35// Max period in milliseconds in which retransmissions will be sent. After this
36// time, no more retransmissions will be sent. -1 if unset.
37@property(nonatomic) NSInteger maxRetransmitTimeMs;
38// The max number of retransmissions. -1 if unset.
39@property(nonatomic) NSInteger maxRetransmits;
40// Set to YES if the channel has been externally negotiated and we do not send
41// an in-band signalling in the form of an "open" message
42@property(nonatomic) BOOL isNegotiated;
43// The stream id, or SID, for SCTP data channels. -1 if unset.
44@property(nonatomic) NSInteger streamId;
45// Set by the application and opaque to the WebRTC implementation.
46@property(nonatomic) NSString* protocol;
47
48@end
49
50// ObjectiveC wrapper for a DataBuffer object.
51@interface RTCDataBuffer : NSObject
52
53@property(nonatomic, readonly) NSData* data;
54@property(nonatomic, readonly) BOOL isBinary;
55
56- (instancetype)initWithData:(NSData*)data isBinary:(BOOL)isBinary;
57
58#ifndef DOXYGEN_SHOULD_SKIP_THIS
59// Disallow init and don't add to documentation
60- (id)init __attribute__((
61    unavailable("init is not a supported initializer for this class.")));
62#endif /* DOXYGEN_SHOULD_SKIP_THIS */
63
64@end
65
66// Keep in sync with webrtc::DataChannelInterface::DataState
67typedef enum {
68  kRTCDataChannelStateConnecting,
69  kRTCDataChannelStateOpen,
70  kRTCDataChannelStateClosing,
71  kRTCDataChannelStateClosed
72} RTCDataChannelState;
73
74@class RTCDataChannel;
75// Protocol for receving data channel state and message events.
76@protocol RTCDataChannelDelegate<NSObject>
77
78// Called when the data channel state has changed.
79- (void)channelDidChangeState:(RTCDataChannel*)channel;
80
81// Called when a data buffer was successfully received.
82- (void)channel:(RTCDataChannel*)channel
83    didReceiveMessageWithBuffer:(RTCDataBuffer*)buffer;
84
85@end
86
87// ObjectiveC wrapper for a DataChannel object.
88// See talk/app/webrtc/datachannelinterface.h
89@interface RTCDataChannel : NSObject
90
91@property(nonatomic, readonly) NSString* label;
92@property(nonatomic, readonly) BOOL isReliable;
93@property(nonatomic, readonly) BOOL isOrdered;
94@property(nonatomic, readonly) NSUInteger maxRetransmitTime;
95@property(nonatomic, readonly) NSUInteger maxRetransmits;
96@property(nonatomic, readonly) NSString* protocol;
97@property(nonatomic, readonly) BOOL isNegotiated;
98@property(nonatomic, readonly) NSInteger streamId;
99@property(nonatomic, readonly) RTCDataChannelState state;
100@property(nonatomic, readonly) NSUInteger bufferedAmount;
101@property(nonatomic, weak) id<RTCDataChannelDelegate> delegate;
102
103- (void)close;
104- (BOOL)sendData:(RTCDataBuffer*)data;
105
106#ifndef DOXYGEN_SHOULD_SKIP_THIS
107// Disallow init and don't add to documentation
108- (id)init __attribute__((
109    unavailable("init is not a supported initializer for this class.")));
110#endif /* DOXYGEN_SHOULD_SKIP_THIS */
111
112@end
113