#ifndef TGCALLS_SCTP_DATA_CHANNEL_PROVIDER_IMPL_H #define TGCALLS_SCTP_DATA_CHANNEL_PROVIDER_IMPL_H #include "media/sctp/sctp_transport_factory.h" #include "api/turn_customizer.h" #include "api/data_channel_interface.h" #include "pc/sctp_data_channel.h" #include "media/sctp/sctp_transport_factory.h" #include "pc/sctp_transport.h" #include "StaticThreads.h" namespace cricket { class DtlsTransport; } // namespace cricket namespace tgcalls { class SctpDataChannelProviderInterfaceImpl : public sigslot::has_slots<>, public webrtc::SctpDataChannelProviderInterface, public webrtc::DataChannelObserver { public: SctpDataChannelProviderInterfaceImpl( cricket::DtlsTransport *transportChannel, bool isOutgoing, std::function onStateChanged, std::function onTerminated, std::function onMessageReceived, std::shared_ptr threads ); virtual ~SctpDataChannelProviderInterfaceImpl(); void updateIsConnected(bool isConnected); void sendDataChannelMessage(std::string const &message); virtual void OnStateChange() override; virtual void OnMessage(const webrtc::DataBuffer& buffer) override; virtual bool SendData( int sid, const webrtc::SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result) override; virtual bool ConnectDataChannel(webrtc::SctpDataChannel *data_channel) override; virtual void DisconnectDataChannel(webrtc::SctpDataChannel* data_channel) override; virtual void AddSctpDataStream(int sid) override; virtual void RemoveSctpDataStream(int sid) override; virtual bool ReadyToSendData() const override; private: void sctpReadyToSendData(); void sctpClosedAbruptly(webrtc::RTCError error); void sctpDataReceived(const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer); private: std::shared_ptr _threads; std::function _onStateChanged; std::function _onTerminated; std::function _onMessageReceived; std::unique_ptr _sctpTransportFactory; std::unique_ptr _sctpTransport; rtc::scoped_refptr _dataChannel; bool _isSctpTransportStarted = false; bool _isDataChannelOpen = false; }; } // namespace tgcalls #endif