conductor.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2012 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
  11. #define EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
  12. #include <deque>
  13. #include <map>
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #include "api/media_stream_interface.h"
  18. #include "api/peer_connection_interface.h"
  19. #include "examples/peerconnection/client/main_wnd.h"
  20. #include "examples/peerconnection/client/peer_connection_client.h"
  21. namespace webrtc {
  22. class VideoCaptureModule;
  23. } // namespace webrtc
  24. namespace cricket {
  25. class VideoRenderer;
  26. } // namespace cricket
  27. class Conductor : public webrtc::PeerConnectionObserver,
  28. public webrtc::CreateSessionDescriptionObserver,
  29. public PeerConnectionClientObserver,
  30. public MainWndCallback {
  31. public:
  32. enum CallbackID {
  33. MEDIA_CHANNELS_INITIALIZED = 1,
  34. PEER_CONNECTION_CLOSED,
  35. SEND_MESSAGE_TO_PEER,
  36. NEW_TRACK_ADDED,
  37. TRACK_REMOVED,
  38. };
  39. Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
  40. bool connection_active() const;
  41. void Close() override;
  42. protected:
  43. ~Conductor();
  44. bool InitializePeerConnection();
  45. bool ReinitializePeerConnectionForLoopback();
  46. bool CreatePeerConnection(bool dtls);
  47. void DeletePeerConnection();
  48. void EnsureStreamingUI();
  49. void AddTracks();
  50. //
  51. // PeerConnectionObserver implementation.
  52. //
  53. void OnSignalingChange(
  54. webrtc::PeerConnectionInterface::SignalingState new_state) override {}
  55. void OnAddTrack(
  56. rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
  57. const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
  58. streams) override;
  59. void OnRemoveTrack(
  60. rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override;
  61. void OnDataChannel(
  62. rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {}
  63. void OnRenegotiationNeeded() override {}
  64. void OnIceConnectionChange(
  65. webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
  66. void OnIceGatheringChange(
  67. webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
  68. void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
  69. void OnIceConnectionReceivingChange(bool receiving) override {}
  70. //
  71. // PeerConnectionClientObserver implementation.
  72. //
  73. void OnSignedIn() override;
  74. void OnDisconnected() override;
  75. void OnPeerConnected(int id, const std::string& name) override;
  76. void OnPeerDisconnected(int id) override;
  77. void OnMessageFromPeer(int peer_id, const std::string& message) override;
  78. void OnMessageSent(int err) override;
  79. void OnServerConnectionFailure() override;
  80. //
  81. // MainWndCallback implementation.
  82. //
  83. void StartLogin(const std::string& server, int port) override;
  84. void DisconnectFromServer() override;
  85. void ConnectToPeer(int peer_id) override;
  86. void DisconnectFromCurrentPeer() override;
  87. void UIThreadCallback(int msg_id, void* data) override;
  88. // CreateSessionDescriptionObserver implementation.
  89. void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
  90. void OnFailure(webrtc::RTCError error) override;
  91. protected:
  92. // Send a message to the remote peer.
  93. void SendMessage(const std::string& json_object);
  94. int peer_id_;
  95. bool loopback_;
  96. rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
  97. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
  98. peer_connection_factory_;
  99. PeerConnectionClient* client_;
  100. MainWindow* main_wnd_;
  101. std::deque<std::string*> pending_messages_;
  102. std::string server_;
  103. };
  104. #endif // EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_