You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012, 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. // This file contains interfaces for DataChannels
  28. // http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcdatachannel
  29. #ifndef TALK_APP_WEBRTC_DATACHANNELINTERFACE_H_
  30. #define TALK_APP_WEBRTC_DATACHANNELINTERFACE_H_
  31. #include <string>
  32. #include "talk/base/basictypes.h"
  33. #include "talk/base/buffer.h"
  34. #include "talk/base/refcount.h"
  35. namespace webrtc {
  36. struct DataChannelInit {
  37. bool reliable;
  38. };
  39. struct DataBuffer {
  40. DataBuffer() : binary(false) {
  41. }
  42. explicit DataBuffer(const std::string& string_to_send)
  43. : data(string_to_send.c_str(), string_to_send.length()),
  44. binary(false) {
  45. }
  46. talk_base::Buffer data;
  47. // Indicates if the receivied data contains UTF-8 or binary data.
  48. // Note that the upper layers are left to verify the UTF-8 encoding.
  49. bool binary;
  50. };
  51. class DataChannelObserver {
  52. public:
  53. // The data channel state have changed.
  54. virtual void OnStateChange() = 0;
  55. // A data buffer was successfully received.
  56. virtual void OnMessage(const DataBuffer& buffer) = 0;
  57. protected:
  58. virtual ~DataChannelObserver() {}
  59. };
  60. class DataChannelInterface : public talk_base::RefCountInterface {
  61. public:
  62. enum DataState {
  63. kConnecting,
  64. kOpen, // The DataChannel is ready to send data.
  65. kClosing,
  66. kClosed
  67. };
  68. virtual void RegisterObserver(DataChannelObserver* observer) = 0;
  69. virtual void UnregisterObserver() = 0;
  70. // The label attribute represents a label that can be used to distinguish this
  71. // DataChannel object from other DataChannel objects.
  72. virtual std::string label() const = 0;
  73. virtual bool reliable() const = 0;
  74. virtual DataState state() const = 0;
  75. // The buffered_amount returns the number of bytes of application data
  76. // (UTF-8 text and binary data) that have been queued using SendBuffer but
  77. // have not yet been transmitted to the network.
  78. virtual uint64 buffered_amount() const = 0;
  79. virtual void Close() = 0;
  80. // Sends |data| to the remote peer.
  81. virtual bool Send(const DataBuffer& buffer) = 0;
  82. protected:
  83. virtual ~DataChannelInterface() {}
  84. };
  85. } // namespace webrtc
  86. #endif // TALK_APP_WEBRTC_DATACHANNELINTERFACE_H_