#ifndef MS_RTC_DATA_PRODUCER_HPP
#define MS_RTC_DATA_PRODUCER_HPP
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "RTC/SCTP/public/Message.hpp"
#include "RTC/SctpDictionaries.hpp"
#include "SharedInterface.hpp"
#include <string>
#include <vector>
namespace RTC
{
class DataProducer : public Channel::ChannelSocket::RequestHandler,
public Channel::ChannelSocket::NotificationHandler
{
public:
class Listener
{
public:
virtual ~Listener() = default;
public:
virtual void OnDataProducerReceiveData(RTC::DataProducer* producer, size_t len) = 0;
virtual void OnDataProducerMessageReceived(
RTC::DataProducer* dataProducer,
RTC::SCTP::Message message,
std::vector<uint16_t>& subchannels,
std::optional<uint16_t> requiredSubchannel) = 0;
virtual void OnDataProducerPaused(RTC::DataProducer* dataProducer) = 0;
virtual void OnDataProducerResumed(RTC::DataProducer* dataProducer) = 0;
};
public:
enum class Type : uint8_t
{
SCTP = 0,
DIRECT
};
public:
DataProducer(
SharedInterface* shared,
const std::string& id,
size_t maxMessageSize,
RTC::DataProducer::Listener* listener,
const FBS::Transport::ProduceDataRequest* data);
~DataProducer() override;
public:
flatbuffers::Offset<FBS::DataProducer::DumpResponse> FillBuffer(
flatbuffers::FlatBufferBuilder& builder) const;
flatbuffers::Offset<FBS::DataProducer::GetStatsResponse> FillBufferStats(
flatbuffers::FlatBufferBuilder& builder) const;
Type GetType() const
{
return this->type;
}
const RTC::SctpStreamParameters& GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
bool IsPaused() const
{
return this->paused;
}
void ReceiveMessage(
RTC::SCTP::Message message,
std::vector<uint16_t>& subchannels,
std::optional<uint16_t> requiredSubchannel);
public:
void HandleRequest(Channel::ChannelRequest* request) override;
public:
void HandleNotification(Channel::ChannelNotification* notification) override;
public:
std::string id;
private:
SharedInterface* shared{ nullptr };
size_t maxMessageSize{ 0u };
RTC::DataProducer::Listener* listener{ nullptr };
Type type;
RTC::SctpStreamParameters sctpStreamParameters;
std::string label;
std::string protocol;
bool paused{ false };
size_t messagesReceived{ 0u };
size_t bytesReceived{ 0u };
};
}
#endif