OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 // This file contains interfaces for DataChannels | 11 // This file contains interfaces for DataChannels |
12 // http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcdatachannel | 12 // http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcdatachannel |
13 | 13 |
14 #ifndef WEBRTC_API_DATACHANNELINTERFACE_H_ | 14 #ifndef WEBRTC_API_DATACHANNELINTERFACE_H_ |
15 #define WEBRTC_API_DATACHANNELINTERFACE_H_ | 15 #define WEBRTC_API_DATACHANNELINTERFACE_H_ |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "webrtc/base/basictypes.h" | 19 #include "webrtc/base/basictypes.h" |
20 #include "webrtc/base/buffer.h" | |
21 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/copyonwritebuffer.h" |
22 #include "webrtc/base/refcount.h" | 22 #include "webrtc/base/refcount.h" |
23 | 23 |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 struct DataChannelInit { | 27 struct DataChannelInit { |
28 DataChannelInit() | 28 DataChannelInit() |
29 : reliable(false), | 29 : reliable(false), |
30 ordered(true), | 30 ordered(true), |
31 maxRetransmitTime(-1), | 31 maxRetransmitTime(-1), |
(...skipping 11 matching lines...) Expand all Loading... |
43 std::string protocol; // This is set by the application and opaque to the | 43 std::string protocol; // This is set by the application and opaque to the |
44 // WebRTC implementation. | 44 // WebRTC implementation. |
45 bool negotiated; // True if the channel has been externally negotiated | 45 bool negotiated; // True if the channel has been externally negotiated |
46 // and we do not send an in-band signalling in the | 46 // and we do not send an in-band signalling in the |
47 // form of an "open" message. | 47 // form of an "open" message. |
48 int id; // The stream id, or SID, for SCTP data channels. -1 | 48 int id; // The stream id, or SID, for SCTP data channels. -1 |
49 // if unset. | 49 // if unset. |
50 }; | 50 }; |
51 | 51 |
52 struct DataBuffer { | 52 struct DataBuffer { |
53 DataBuffer(const rtc::Buffer& data, bool binary) | 53 DataBuffer(const rtc::CopyOnWriteBuffer& data, bool binary) |
54 : data(data), | 54 : data(data), |
55 binary(binary) { | 55 binary(binary) { |
56 } | 56 } |
57 // For convenience for unit tests. | 57 // For convenience for unit tests. |
58 explicit DataBuffer(const std::string& text) | 58 explicit DataBuffer(const std::string& text) |
59 : data(text.data(), text.length()), | 59 : data(text.data(), text.length()), |
60 binary(false) { | 60 binary(false) { |
61 } | 61 } |
62 size_t size() const { return data.size(); } | 62 size_t size() const { return data.size(); } |
63 | 63 |
64 rtc::Buffer data; | 64 rtc::CopyOnWriteBuffer data; |
65 // Indicates if the received data contains UTF-8 or binary data. | 65 // Indicates if the received data contains UTF-8 or binary data. |
66 // Note that the upper layers are left to verify the UTF-8 encoding. | 66 // Note that the upper layers are left to verify the UTF-8 encoding. |
67 // TODO(jiayl): prefer to use an enum instead of a bool. | 67 // TODO(jiayl): prefer to use an enum instead of a bool. |
68 bool binary; | 68 bool binary; |
69 }; | 69 }; |
70 | 70 |
71 class DataChannelObserver { | 71 class DataChannelObserver { |
72 public: | 72 public: |
73 // The data channel state have changed. | 73 // The data channel state have changed. |
74 virtual void OnStateChange() = 0; | 74 virtual void OnStateChange() = 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Sends |data| to the remote peer. | 133 // Sends |data| to the remote peer. |
134 virtual bool Send(const DataBuffer& buffer) = 0; | 134 virtual bool Send(const DataBuffer& buffer) = 0; |
135 | 135 |
136 protected: | 136 protected: |
137 virtual ~DataChannelInterface() {} | 137 virtual ~DataChannelInterface() {} |
138 }; | 138 }; |
139 | 139 |
140 } // namespace webrtc | 140 } // namespace webrtc |
141 | 141 |
142 #endif // WEBRTC_API_DATACHANNELINTERFACE_H_ | 142 #endif // WEBRTC_API_DATACHANNELINTERFACE_H_ |
OLD | NEW |