OpenTera WebRTC API (C++) 1.2.6
DataChannelPeerConnectionHandler.h
1 #ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_FUNCTIONAL_DATA_CHANNEL_OBSERVER_H
2 #define OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_FUNCTIONAL_DATA_CHANNEL_OBSERVER_H
3 
4 #include <OpenteraWebrtcNativeClient/Handlers/PeerConnectionHandler.h>
5 #include <OpenteraWebrtcNativeClient/Configurations/DataChannelConfiguration.h>
6 
7 #include <api/data_channel_interface.h>
8 
9 #include <functional>
10 
11 namespace opentera
12 {
13  class DataChannelPeerConnectionHandler : public PeerConnectionHandler, public webrtc::DataChannelObserver
14  {
15  DataChannelConfiguration m_dataChannelConfiguration;
16 
17  std::function<void(const Client&)> m_onDataChannelOpen;
18  std::function<void(const Client&)> m_onDataChannelClosed;
19  std::function<void(const Client&, const std::string&)> m_onDataChannelError;
20  std::function<void(const Client&, const webrtc::DataBuffer& buffer)> m_onDataChannelMessageBinary;
21  std::function<void(const Client&, const std::string&)> m_onDataChannelMessageString;
22 
23  rtc::scoped_refptr<webrtc::DataChannelInterface> m_dataChannel;
24 
25  bool m_onDataChannelClosedCalled;
26 
27  public:
29  std::string id,
30  Client peerClient,
31  bool isCaller,
32  SignalingClient& m_signalingClient,
33  std::function<void(const std::string&)> onError,
34  std::function<void(const Client&)> onClientConnected,
35  std::function<void(const Client&)> onClientDisconnected,
36  std::function<void(const Client&)> onClientConnectionFailed,
37  DataChannelConfiguration dataChannelConfiguration,
38  std::function<void(const Client&)> onDataChannelOpen,
39  std::function<void(const Client&)> onDataChannelClosed,
40  std::function<void(const Client&, const std::string&)> onDataChannelError,
41  std::function<void(const Client&, const webrtc::DataBuffer& buffer)> onDataChannelMessageBinary,
42  std::function<void(const Client&, const std::string&)> onDataChannelMessageString);
43 
45 
46  void setPeerConnection(const rtc::scoped_refptr<webrtc::PeerConnectionInterface>& peerConnection) override;
47 
48  bool send(const webrtc::DataBuffer& buffer);
49 
50  // Observer methods
51  void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel) override;
52 
53  void OnStateChange() override;
54  void OnMessage(const webrtc::DataBuffer& buffer) override;
55 
56  protected:
57  void createAnswer() override;
58  };
59 }
60 
61 #endif
Represents a peer client.
Definition: Client.h:14
Represents a data channel configuration.
Definition: DataChannelConfiguration.h:14
Definition: DataChannelPeerConnectionHandler.h:14
Definition: PeerConnectionHandler.h:36
Definition: SignalingClient.h:16