#ifndef TGCALLS_DIRECT_NETWORKING_IMPL_H #define TGCALLS_DIRECT_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 "rtc_base/ssl_fingerprint.h" #include "pc/sctp_data_channel.h" #include "p2p/base/port.h" #include "api/transport/field_trial_based_config.h" #include #include #include "InstanceNetworking.h" #include "Message.h" #include "ThreadLocalObject.h" #include "Instance.h" #include "EncryptedConnection.h" namespace rtc { class BasicPacketSocketFactory; class BasicNetworkManager; class PacketTransportInternal; struct NetworkRoute; } // namespace rtc namespace cricket { class BasicPortAllocator; class P2PTransportChannel; class IceTransportInternal; class DtlsTransport; class RelayPortFactoryInterface; } // namespace cricket namespace webrtc { class TurnCustomizer; class DtlsSrtpTransport; class RtpTransport; class AsyncDnsResolverFactoryInterface; } // namespace webrtc namespace tgcalls { struct Message; class SctpDataChannelProviderInterfaceImpl; class Threads; class DirectPacketTransport; class DirectRtpTransport; class DirectNetworkingImpl : public InstanceNetworking, public sigslot::has_slots<>, public std::enable_shared_from_this { public: static webrtc::CryptoOptions getDefaulCryptoOptions(); DirectNetworkingImpl(Configuration &&configuration); ~DirectNetworkingImpl(); 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 checkConnectionTimeout(); void notifyStateUpdated(); void resetDtlsSrtpTransport(); void DtlsReadyToSend(bool DtlsReadyToSend); void UpdateAggregateStates_n(); void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us); void OnTransportWritableState_n(rtc::PacketTransportInternal *transport); void OnTransportReceivingState_n(rtc::PacketTransportInternal *transport); private: std::shared_ptr _threads; bool _isOutgoing = false; rtc::scoped_refptr _localCertificate; std::vector _rtcServers; PeerIceParameters _localIceParameters; std::unique_ptr _channel; std::shared_ptr _directConnectionChannel; std::shared_ptr _packetTransport; std::unique_ptr _rtpTransport; std::unique_ptr _dataChannelInterface; std::function _stateUpdated; std::function _transportMessageReceived; std::function _rtcpPacketReceived; std::function _dataChannelStateUpdated; std::function _dataChannelMessageReceived; bool _transportIsConnected = false; bool _isConnected = false; bool _isFailed = false; int64_t _lastDisconnectedTimestamp = 0; absl::optional _currentRouteDescription; absl::optional _currentConnectionDescription; }; } // namespace tgcalls #endif