You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
  28. #define PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
  29. #pragma once
  30. #include <deque>
  31. #include <map>
  32. #include <set>
  33. #include <string>
  34. #include "talk/examples/peerconnection/client/main_wnd.h"
  35. #include "talk/examples/peerconnection/client/peer_connection_client.h"
  36. #include "talk/app/webrtc/mediastreaminterface.h"
  37. #include "talk/app/webrtc/peerconnectioninterface.h"
  38. #include "talk/base/scoped_ptr.h"
  39. namespace webrtc {
  40. class VideoCaptureModule;
  41. } // namespace webrtc
  42. namespace cricket {
  43. class VideoRenderer;
  44. } // namespace cricket
  45. class Conductor
  46. : public webrtc::PeerConnectionObserver,
  47. public webrtc::CreateSessionDescriptionObserver,
  48. public PeerConnectionClientObserver,
  49. public MainWndCallback {
  50. public:
  51. enum CallbackID {
  52. MEDIA_CHANNELS_INITIALIZED = 1,
  53. PEER_CONNECTION_CLOSED,
  54. SEND_MESSAGE_TO_PEER,
  55. PEER_CONNECTION_ERROR,
  56. NEW_STREAM_ADDED,
  57. STREAM_REMOVED,
  58. };
  59. Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
  60. bool connection_active() const;
  61. virtual void Close();
  62. protected:
  63. ~Conductor();
  64. bool InitializePeerConnection();
  65. void DeletePeerConnection();
  66. void EnsureStreamingUI();
  67. void AddStreams();
  68. cricket::VideoCapturer* OpenVideoCaptureDevice();
  69. //
  70. // PeerConnectionObserver implementation.
  71. //
  72. virtual void OnError();
  73. virtual void OnStateChange(
  74. webrtc::PeerConnectionObserver::StateType state_changed) {}
  75. virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
  76. virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream);
  77. virtual void OnRenegotiationNeeded() {}
  78. virtual void OnIceChange() {}
  79. virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
  80. //
  81. // PeerConnectionClientObserver implementation.
  82. //
  83. virtual void OnSignedIn();
  84. virtual void OnDisconnected();
  85. virtual void OnPeerConnected(int id, const std::string& name);
  86. virtual void OnPeerDisconnected(int id);
  87. virtual void OnMessageFromPeer(int peer_id, const std::string& message);
  88. virtual void OnMessageSent(int err);
  89. virtual void OnServerConnectionFailure();
  90. //
  91. // MainWndCallback implementation.
  92. //
  93. virtual void StartLogin(const std::string& server, int port);
  94. virtual void DisconnectFromServer();
  95. virtual void ConnectToPeer(int peer_id);
  96. virtual void DisconnectFromCurrentPeer();
  97. virtual void UIThreadCallback(int msg_id, void* data);
  98. // CreateSessionDescriptionObserver implementation.
  99. virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
  100. virtual void OnFailure(const std::string& error);
  101. protected:
  102. // Send a message to the remote peer.
  103. void SendMessage(const std::string& json_object);
  104. int peer_id_;
  105. talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
  106. talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
  107. peer_connection_factory_;
  108. PeerConnectionClient* client_;
  109. MainWindow* main_wnd_;
  110. std::deque<std::string*> pending_messages_;
  111. std::map<std::string, talk_base::scoped_refptr<webrtc::MediaStreamInterface> >
  112. active_streams_;
  113. std::string server_;
  114. };
  115. #endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_