| // Compiler errors in conflicting Windows headers if not included here. |
| 6 | #include <winsock2.h> |
| 7 | #endif // WEBRTC_WIN |
| 8 |
| 9 | #include "rtc_base/copy_on_write_buffer.h" |
| 10 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 11 | #include "rtc_base/network_monitor_factory.h" |
| 12 | #include "api/candidate.h" |
| 13 | #include "media/base/media_channel.h" |
| 14 | #include "pc/sctp_transport.h" |
| 15 | #include "rtc_base/ssl_fingerprint.h" |
| 16 | #include "pc/sctp_data_channel.h" |
| 17 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
| 18 |
| 19 | #include <functional> |
| 20 | #include <memory> |
| 21 |
| 22 | #include "Message.h" |
| 23 | #include "ThreadLocalObject.h" |
| 24 |
| 25 | namespace rtc { |
| 26 | class BasicPacketSocketFactory; |
| 27 | class BasicNetworkManager; |
| 28 | class PacketTransportInternal; |
| 29 | struct NetworkRoute; |
| 30 | } // namespace rtc |
| 31 |
| 32 | namespace cricket { |
| 33 | class BasicPortAllocator; |
| 34 | class P2PTransportChannel; |
| 35 | class IceTransportInternal; |
| 36 | class DtlsTransport; |
| 37 | } // namespace cricket |
| 38 |
| 39 | namespace webrtc { |
| 40 | class BasicAsyncResolverFactory; |
| 41 | class TurnCustomizer; |
| 42 | class DtlsSrtpTransport; |
| 43 | class RtpTransport; |
| 44 | } // namespace webrtc |
| 45 |
| 46 | namespace tgcalls { |
| 47 |
| 48 | struct Message; |
| 49 | class SctpDataChannelProviderInterfaceImpl; |
| 50 | class Threads; |
| 51 |
| 52 | class GroupNetworkManager : public sigslot::has_slots<>, public std::enable_shared_from_this<GroupNetworkManager> { |
| 53 | public: |
| 54 | struct State { |
| 55 | bool isReadyToSendData = false; |
| 56 | bool isFailed = false; |
| 57 | }; |
| 58 |
| 59 | static webrtc::CryptoOptions getDefaulCryptoOptions(); |
| 60 |
| 61 | GroupNetworkManager( |
| 62 | const webrtc::WebRtcKeyValueConfig& fieldTrials, |
| 63 | std::function<void(const State &)> stateUpdated, |
| 64 | std::function<void(uint32_t, int)> unknownSsrcPacketReceived, |
| 65 | std::function<void(bool)> dataChannelStateUpdated, |
| 66 | std::function<void(std::string const &)> dataChannelMessageReceived, |
| 67 | std::function<void(uint32_t, uint8_t, bool)> audioActivityUpdated, |
| 68 | std::shared_ptr<Threads> threads); |
| 69 | ~GroupNetworkManager(); |
| 70 |
| 71 | void start(); |
| 72 | void stop(); |
| 73 |
| 74 | PeerIceParameters getLocalIceParameters(); |
| 75 | std::unique_ptr<rtc::SSLFingerprint> getLocalFingerprint(); |
| 76 | void setRemoteParams(PeerIceParameters const &remoteIceParameters, std::vector<cricket::Candidate> const &iceCandidates, rtc::SSLFingerprint *fingerprint); |
| 77 |
| 78 | void sendDataChannelMessage(std::string const &message); |
| 79 |
| 80 | void setOutgoingVoiceActivity(bool isSpeech); |
| 81 |
| 82 | webrtc::RtpTransport *getRtpTransport(); |
| 83 |
| 84 | private: |
| 85 | void resetDtlsSrtpTransport(); |
| 86 | void restartDataChannel(); |
| 87 | void checkConnectionTimeout(); |
| 88 | void candidateGathered(cricket::IceTransportInternal *transport, const cricket::Candidate &candidate); |
| 89 | void candidateGatheringState(cricket::IceTransportInternal *transport); |
| 90 | void OnTransportWritableState_n(rtc::PacketTransportInternal *transport); |
| 91 | void OnTransportReceivingState_n(rtc::PacketTransportInternal *transport); |
| 92 | void transportStateChanged(cricket::IceTransportInternal *transport); |
| 93 | void transportReadyToSend(cricket::IceTransportInternal *transport); |
| 94 | void transportPacketReceived(rtc::PacketTransportInternal *transport, const char *bytes, size_t size, const int64_t ×tamp, int unused); |
| 95 | void DtlsReadyToSend(bool DtlsReadyToSend); |
| 96 | void UpdateAggregateStates_n(); |
| 97 | void RtpPacketReceived_n(webrtc::RtpPacketReceived const &packet, bool isUnresolved); |
| 98 | void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *packet, int64_t packet_time_us); |
| 99 |
| 100 | void sctpReadyToSendData(); |
| 101 | void sctpDataReceived(const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer); |
| 102 |
| 103 | std::shared_ptr<Threads> _threads; |
| 104 | std::function<void(const GroupNetworkManager::State &)> _stateUpdated; |
| 105 | std::function<void(uint32_t, int)> _unknownSsrcPacketReceived; |
| 106 | std::function<void(bool)> _dataChannelStateUpdated; |
| 107 | std::function<void(std::string const &)> _dataChannelMessageReceived; |
| 108 | std::function<void(uint32_t, uint8_t, bool)> _audioActivityUpdated; |
| 109 |
| 110 | std::unique_ptr<rtc::NetworkMonitorFactory> _networkMonitorFactory; |
| 111 | std::unique_ptr<rtc::BasicPacketSocketFactory> _socketFactory; |
| 112 | std::unique_ptr<rtc::BasicNetworkManager> _networkManager; |
| 113 | std::unique_ptr<webrtc::TurnCustomizer> _turnCustomizer; |
| 114 | std::unique_ptr<cricket::BasicPortAllocator> _portAllocator; |
| 115 | std::unique_ptr<webrtc::BasicAsyncResolverFactory> _asyncResolverFactory; |
| 116 | std::unique_ptr<cricket::P2PTransportChannel> _transportChannel; |
| 117 | std::unique_ptr<cricket::DtlsTransport> _dtlsTransport; |
| 118 | std::unique_ptr<webrtc::DtlsSrtpTransport> _dtlsSrtpTransport; |
| 119 |
| 120 | std::unique_ptr<SctpDataChannelProviderInterfaceImpl> _dataChannelInterface; |
| 121 |
| 122 | rtc::scoped_refptr<rtc::RTCCertificate> _localCertificate; |
| 123 | PeerIceParameters _localIceParameters; |
| 124 | absl::optional<PeerIceParameters> _remoteIceParameters; |
| 125 |
| 126 | bool _isConnected = false; |
| 127 | int64_t _lastNetworkActivityMs = 0; |
| 128 | }; |
| 129 |
| 130 | } // namespace tgcalls |
| 131 |
| 132 | #endif |
| 133 |