OpenTera WebRTC API (C++) 1.2.5
PeerConnectionHandler.h
1 #ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_FUNCTIONAL_PEER_CONNECTION_OBSERVER_H
2 #define OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_FUNCTIONAL_PEER_CONNECTION_OBSERVER_H
3 
4 #include <OpenteraWebrtcNativeClient/Signaling/SignalingClient.h>
5 #include <OpenteraWebrtcNativeClient/Utils/Client.h>
6 
7 #include <api/peer_connection_interface.h>
8 
9 #include <functional>
10 
11 namespace opentera
12 {
13  class CreateSessionDescriptionObserverHelper : public webrtc::CreateSessionDescriptionObserver
14  {
15  public:
16  void OnSuccess(webrtc::SessionDescriptionInterface* desc) final;
17  void OnFailure(webrtc::RTCError error) final;
18 
19  virtual void OnCreateSessionDescriptionObserverSuccess(webrtc::SessionDescriptionInterface* desc) = 0;
20  virtual void OnCreateSessionDescriptionObserverFailure(webrtc::RTCError error) = 0;
21  };
22 
23  class SetSessionDescriptionObserverHelper : public webrtc::SetSessionDescriptionObserver
24  {
25  public:
26  void OnSuccess() final;
27  void OnFailure(webrtc::RTCError error) final;
28 
29  virtual void OnSetSessionDescriptionObserverSuccess() = 0;
30  virtual void OnSetSessionDescriptionObserverFailure(webrtc::RTCError error) = 0;
31  };
32 
33  class PeerConnectionHandler : public webrtc::PeerConnectionObserver,
36  {
37  protected:
38  std::string m_id;
39  Client m_peerClient;
40  bool m_isCaller;
41  SignalingClient& m_signalingClient;
42  std::function<void(const std::string&)> m_onError;
43  std::function<void(const Client&)> m_onClientConnected;
44  std::function<void(const Client&)> m_onClientDisconnected;
45  std::function<void(const Client&)> m_onClientConnectionFailed;
46 
47  rtc::scoped_refptr<webrtc::PeerConnectionInterface> m_peerConnection;
48 
49  bool m_onClientDisconnectedCalled;
50 
51  public:
53  std::string&& id,
54  Client&& peerClient,
55  bool isCaller,
56  SignalingClient& m_signalingClient,
57  std::function<void(const std::string&)>&& onError,
58  std::function<void(const Client&)>&& onClientConnected,
59  std::function<void(const Client&)>&& onClientDisconnected,
60  std::function<void(const Client&)>&& onClientConnectionFailed);
61  ~PeerConnectionHandler() override;
62 
63  virtual void setPeerConnection(const rtc::scoped_refptr<webrtc::PeerConnectionInterface>& peerConnection);
64 
65  void makePeerCall();
66  void receivePeerCall(const std::string& sdp);
67  void receivePeerCallAnswer(const std::string& sdp);
68  void receiveIceCandidate(const std::string& sdpMid, int sdpMLineIndex, const std::string& sdp);
69 
70  // Observer methods
71  void OnConnectionChange(webrtc::PeerConnectionInterface::PeerConnectionState newState) override;
72  void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
73 
74  void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel) override;
75 
76  void OnTrack(rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) override;
77  void OnRemoveTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override;
78 
79  void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState newState) override;
80  void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState newState) override;
81 
82  void OnCreateSessionDescriptionObserverSuccess(webrtc::SessionDescriptionInterface* desc) override;
83  void OnCreateSessionDescriptionObserverFailure(webrtc::RTCError error) override;
84 
85  void OnSetSessionDescriptionObserverSuccess() override;
86  void OnSetSessionDescriptionObserverFailure(webrtc::RTCError error) override;
87 
88  void AddRef() const override;
89  [[nodiscard]] rtc::RefCountReleaseStatus Release() const override;
90 
91  protected:
92  virtual void createAnswer();
93  };
94 
95  void setTransceiverDirection(
96  const rtc::scoped_refptr<webrtc::RtpTransceiverInterface>& transceiver,
97  webrtc::RtpTransceiverDirection direction);
98 }
99 
100 #endif
Represents a peer client.
Definition: Client.h:14
Definition: PeerConnectionHandler.h:14
Definition: PeerConnectionHandler.h:36
Definition: PeerConnectionHandler.h:24
Definition: SignalingClient.h:16