#ifndef TGCALLS_SIGNALING_SCTP_CONNECTION_H_ #define TGCALLS_SIGNALING_SCTP_CONNECTION_H_ #ifdef WEBRTC_WIN #include #endif // WEBRTC_WIN #include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/socket_address.h" #include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/byte_buffer.h" #include "media/base/media_channel.h" #include #include #include "StaticThreads.h" #include "SignalingConnection.h" namespace rtc { class Socket; } namespace cricket { class SctpTransportFactory; class SctpTransportInternal; }; namespace tgcalls { class SignalingPacketTransport; class SignalingSctpConnection : public sigslot::has_slots<>, public SignalingConnection, public webrtc::DataChannelSink { private: struct PacketReadState { rtc::CopyOnWriteBuffer headerData; int remainingHeaderSize = 0; bool isHeaderCompleted = false; rtc::CopyOnWriteBuffer data; int remainingDataSize = 0; bool isDataCompleted = false; }; public: SignalingSctpConnection(std::shared_ptr threads, std::function &)> onIncomingData, std::function &)> emitData); virtual ~SignalingSctpConnection(); virtual void receiveExternal(const std::vector &data) override; virtual void start() override; virtual void send(const std::vector &data) override; virtual void OnDataReceived(int channel_id, webrtc::DataMessageType type, const rtc::CopyOnWriteBuffer& buffer) override; virtual void OnReadyToSend() override; virtual void OnTransportClosed(webrtc::RTCError error) override; // Unused virtual void OnChannelClosing(int channel_id) override{} virtual void OnChannelClosed(int channel_id) override{} private: std::shared_ptr _threads; std::function &)> _emitData; std::function &)> _onIncomingData; std::unique_ptr _packetTransport; std::unique_ptr _sctpTransportFactory; std::unique_ptr _sctpTransport; bool _isReadyToSend = false; std::vector> _pendingData; }; } // namespace tgcalls #endif // TGCALLS_SIGNALING_SCTP_CONNECTION_H_