tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

data_channel_event_observer_interface.h (2553B)


      1 /*
      2 *  Copyright (c) 2025 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 
     11 #ifndef API_DATA_CHANNEL_EVENT_OBSERVER_INTERFACE_H_
     12 #define API_DATA_CHANNEL_EVENT_OBSERVER_INTERFACE_H_
     13 
     14 #include <cstdint>
     15 #include <string>
     16 #include <vector>
     17 
     18 #include "absl/strings/string_view.h"
     19 #include "api/array_view.h"
     20 
     21 namespace webrtc {
     22 
     23 // TODO: issues.chromium.org/407785197 - Maybe update the observer to also
     24 // notify on controll messages as well.
     25 // TODO: issues.chromium.org/407785197 - Remove comment below when DataChannel
     26 // logging has been launched.
     27 // NOTE: This class is still under development and may change without notice.
     28 class DataChannelEventObserverInterface {
     29 public:
     30  virtual ~DataChannelEventObserverInterface() = default;
     31 
     32  class Message {
     33   public:
     34    enum class Direction { kSend, kReceive };
     35    enum class DataType { kString, kBinary };
     36 
     37    // When `direction` is `kSend` the timestamp represent when the message was
     38    // handed over to the transport, if `direction` is `kReceive` then it
     39    // represent when the message was received from the transport.
     40    int64_t unix_timestamp_ms() const { return unix_timestamp_; }
     41    void set_unix_timestamp_ms(int64_t timestamp) {
     42      unix_timestamp_ = timestamp;
     43    }
     44 
     45    int datachannel_id() const { return datachannel_id_; }
     46    void set_datachannel_id(int id) { datachannel_id_ = id; }
     47 
     48    absl::string_view label() const { return label_; }
     49    void set_label(absl::string_view label) { label_ = std::string(label); }
     50 
     51    Direction direction() const { return direction_; }
     52    void set_direction(Direction direction) { direction_ = direction; }
     53 
     54    DataType data_type() const { return data_type_; }
     55    void set_data_type(DataType type) { data_type_ = type; }
     56 
     57    const std::vector<uint8_t>& data() const { return data_; }
     58    void set_data(ArrayView<const uint8_t> d) {
     59      data_.assign(d.begin(), d.end());
     60    }
     61 
     62   private:
     63    int64_t unix_timestamp_;
     64    int datachannel_id_;
     65    std::string label_;
     66    Direction direction_;
     67    DataType data_type_;
     68    std::vector<uint8_t> data_;
     69  };
     70 
     71  virtual void OnMessage(const Message& message) = 0;
     72 };
     73 
     74 }  // namespace webrtc
     75 
     76 #endif  // API_DATA_CHANNEL_EVENT_OBSERVER_INTERFACE_H_