| #include "api/turn_customizer.h" |
| 6 | #include "api/data_channel_interface.h" |
| 7 | #include "pc/sctp_data_channel.h" |
| 8 | #include "media/sctp/sctp_transport_factory.h" |
| 9 |
| 10 | #include "StaticThreads.h" |
| 11 |
| 12 | namespace cricket { |
| 13 | class DtlsTransport; |
| 14 | } // namespace cricket |
| 15 |
| 16 | namespace tgcalls { |
| 17 |
| 18 | class SctpDataChannelProviderInterfaceImpl : public sigslot::has_slots<>, public webrtc::SctpDataChannelControllerInterface, public webrtc::DataChannelObserver, public webrtc::DataChannelSink { |
| 19 | public: |
| 20 | SctpDataChannelProviderInterfaceImpl( |
| 21 | rtc::PacketTransportInternal *transportChannel, |
| 22 | bool isOutgoing, |
| 23 | std::function<void(bool)> onStateChanged, |
| 24 | std::function<void()> onTerminated, |
| 25 | std::function<void(std::string const &)> onMessageReceived, |
| 26 | std::shared_ptr<Threads> threads |
| 27 | ); |
| 28 | virtual ~SctpDataChannelProviderInterfaceImpl(); |
| 29 |
| 30 | virtual bool IsOkToCallOnTheNetworkThread() override; |
| 31 |
| 32 | void updateIsConnected(bool isConnected); |
| 33 | void sendDataChannelMessage(std::string const &message); |
| 34 |
| 35 | virtual void OnStateChange() override; |
| 36 | virtual void OnMessage(const webrtc::DataBuffer& buffer) override; |
| 37 | virtual webrtc::RTCError SendData( |
| 38 | webrtc::StreamId sid, |
| 39 | const webrtc::SendDataParams& params, |
| 40 | const rtc::CopyOnWriteBuffer& payload) override; |
| 41 |
| 42 | virtual void AddSctpDataStream(webrtc::StreamId sid) override; |
| 43 | virtual void RemoveSctpDataStream(webrtc::StreamId sid) override; |
| 44 | virtual void OnChannelStateChanged(webrtc::SctpDataChannel *data_channel, webrtc::DataChannelInterface::DataState state) override; |
| 45 |
| 46 | virtual void OnDataReceived(int channel_id, |
| 47 | webrtc::DataMessageType type, |
| 48 | const rtc::CopyOnWriteBuffer& buffer) override; |
| 49 | virtual void OnReadyToSend() override; |
| 50 | virtual void OnTransportClosed(webrtc::RTCError error) override; |
| 51 |
| 52 | // Unused |
| 53 | virtual void OnChannelClosing(int channel_id) override{} |
| 54 | virtual void OnChannelClosed(int channel_id) override{} |
| 55 |
| 56 | private: |
| 57 | rtc::WeakPtrFactory<SctpDataChannelProviderInterfaceImpl> _weakFactory; |
| 58 | std::shared_ptr<Threads> _threads; |
| 59 | std::function<void(bool)> _onStateChanged; |
| 60 | std::function<void()> _onTerminated; |
| 61 | std::function<void(std::string const &)> _onMessageReceived; |
| 62 |
| 63 | std::unique_ptr<cricket::SctpTransportFactory> _sctpTransportFactory; |
| 64 | std::unique_ptr<cricket::SctpTransportInternal> _sctpTransport; |
| 65 | webrtc::scoped_refptr<webrtc::SctpDataChannel> _dataChannel; |
| 66 |
| 67 | bool _isSctpTransportStarted = false; |
| 68 | bool _isDataChannelOpen = false; |
| 69 |
| 70 | }; |
| 71 |
| 72 | } // namespace tgcalls |
| 73 |
| 74 | #endif |
| 75 |