#ifndef TGCALLS_NATIVE_NETWORKING_IMPL_H #define TGCALLS_NATIVE_NETWORKING_IMPL_H #ifdef WEBRTC_WIN // Compiler errors in conflicting Windows headers if not included here. #include #endif // WEBRTC_WIN #include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "api/candidate.h" #include "media/base/media_channel.h" #include "media/sctp/sctp_transport.h" #include "pc/sctp_data_channel.h" #include #include #include "Message.h" #include "ThreadLocalObject.h" #include "Instance.h" namespace rtc { class BasicPacketSocketFactory; class BasicNetworkManager; class PacketTransportInternal; struct NetworkRoute; } // namespace rtc namespace cricket { class BasicPortAllocator; class P2PTransportChannel; class IceTransportInternal; class DtlsTransport; } // namespace cricket namespace webrtc { class BasicAsyncResolverFactory; class TurnCustomizer; class DtlsSrtpTransport; class RtpTransport; } // namespace webrtc namespace tgcalls { struct Message; class SctpDataChannelProviderInterfaceImpl; class Threads; class NativeNetworkingImpl : public sigslot::has_slots<>, public std::enable_shared_from_this { public: struct State { bool isReadyToSendData = false; bool isFailed = false; }; struct Configuration { bool isOutgoing = false; bool enableStunMarking = false; bool enableTCP = false; bool enableP2P = false; std::vector rtcServers; std::function stateUpdated; std::function candidateGathered; std::function transportMessageReceived; std::function rtcpPacketReceived; std::function dataChannelStateUpdated; std::function dataChannelMessageReceived; std::shared_ptr threads; }; static webrtc::CryptoOptions getDefaulCryptoOptions(); NativeNetworkingImpl(Configuration &&configuration); ~NativeNetworkingImpl(); void start(); void stop(); PeerIceParameters getLocalIceParameters(); std::unique_ptr getLocalFingerprint(); void setRemoteParams(PeerIceParameters const &remoteIceParameters, rtc::SSLFingerprint *fingerprint, std::string const &sslSetup); void addCandidates(std::vector const &candidates); void sendDataChannelMessage(std::string const &message); webrtc::RtpTransport *getRtpTransport(); private: void resetDtlsSrtpTransport(); void checkConnectionTimeout(); void candidateGathered(cricket::IceTransportInternal *transport, const cricket::Candidate &candidate); void candidateGatheringState(cricket::IceTransportInternal *transport); void OnTransportWritableState_n(rtc::PacketTransportInternal *transport); void OnTransportReceivingState_n(rtc::PacketTransportInternal *transport); void transportStateChanged(cricket::IceTransportInternal *transport); void transportReadyToSend(cricket::IceTransportInternal *transport); void transportPacketReceived(rtc::PacketTransportInternal *transport, const char *bytes, size_t size, const int64_t ×tamp, int unused); void DtlsReadyToSend(bool DtlsReadyToSend); void UpdateAggregateStates_n(); void RtpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us, bool isUnresolved); void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us); void sctpReadyToSendData(); void sctpDataReceived(const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer); std::shared_ptr _threads; bool _isOutgoing = false; bool _enableStunMarking = false; bool _enableTCP = false; bool _enableP2P = false; std::vector _rtcServers; std::function _stateUpdated; std::function _candidateGathered; std::function _transportMessageReceived; std::function _rtcpPacketReceived; std::function _dataChannelStateUpdated; std::function _dataChannelMessageReceived; std::unique_ptr _socketFactory; std::unique_ptr _networkManager; std::unique_ptr _turnCustomizer; std::unique_ptr _portAllocator; std::unique_ptr _asyncResolverFactory; std::unique_ptr _transportChannel; std::unique_ptr _dtlsTransport; std::unique_ptr _dtlsSrtpTransport; std::unique_ptr _dataChannelInterface; rtc::scoped_refptr _localCertificate; PeerIceParameters _localIceParameters; absl::optional _remoteIceParameters; bool _isConnected = false; int64_t _lastNetworkActivityMs = 0; }; } // namespace tgcalls #endif