ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::visualization::webrtc_server::PeerConnectionManager Class Reference

#include <PeerConnectionManager.h>

Collaboration diagram for cloudViewer::visualization::webrtc_server::PeerConnectionManager:

Public Member Functions

 PeerConnectionManager (const std::list< std::string > &ice_server_list, const Json::Value &config, const std::string &publish_filter, const std::string &webrtc_udp_port_range)
 
virtual ~PeerConnectionManager ()
 
bool InitializePeerConnection ()
 
const std::map< std::string, HttpServerRequestHandler::HttpFunctionGetHttpApi ()
 
const Json::Value GetIceCandidateList (const std::string &peerid)
 
const Json::Value AddIceCandidate (const std::string &peerid, const Json::Value &json_message)
 
const Json::Value GetMediaList ()
 
const Json::Value HangUp (const std::string &peerid)
 
const Json::Value Call (const std::string &peerid, const std::string &window_uid, const std::string &options, const Json::Value &json_message)
 
const Json::Value GetIceServers ()
 
void SendInitFramesToPeer (const std::string &peerid)
 
void CloseWindowConnections (const std::string &window_uid)
 
void OnFrame (const std::string &window_uid, const std::shared_ptr< core::Tensor > &im)
 

Protected Member Functions

rtc::scoped_refptr< BitmapTrackSourceInterfaceGetVideoTrackSource (const std::string &window_uid)
 
PeerConnectionObserver * CreatePeerConnection (const std::string &peerid)
 
bool AddStreams (webrtc::PeerConnectionInterface *peer_connection, const std::string &window_uid, const std::string &options)
 
rtc::scoped_refptr< BitmapTrackSourceInterfaceCreateVideoSource (const std::string &window_uid, const std::map< std::string, std::string > &opts)
 
bool WindowStillUsed (const std::string &window_uid)
 
rtc::scoped_refptr< webrtc::PeerConnectionInterface > GetPeerConnection (const std::string &peerid)
 

Protected Attributes

std::unique_ptr< webrtc::TaskQueueFactory > task_queue_factory_
 
rtc::scoped_refptr< webrtc::PeerConnectionFactoryInterface > peer_connection_factory_
 
std::unordered_map< std::string, PeerConnectionObserver * > peerid_to_connection_
 
std::mutex peerid_to_connection_mutex_
 
std::unordered_set< std::string > peerid_data_channel_ready_
 
std::mutex peerid_data_channel_mutex_
 
std::unordered_map< std::string, rtc::scoped_refptr< BitmapTrackSourceInterface > > window_uid_to_track_source_
 
std::mutex window_uid_to_track_source_mutex_
 
std::unordered_map< std::string, std::set< std::string > > window_uid_to_peerids_
 
std::unordered_map< std::string, std::string > peerid_to_window_uid_
 
std::mutex window_uid_to_peerids_mutex_
 
std::list< std::string > ice_server_list_
 
const Json::Value config_
 
const std::regex publish_filter_
 
std::map< std::string, HttpServerRequestHandler::HttpFunctionfunc_
 
std::string webrtc_port_range_
 

Detailed Description

PeerConnectionManager manages WebRTC signaling (i.e. handshake), data channel and video streams.

[Stage 1: Signaling] Signaling is the handshake process to establish a WebRTC connection. See https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Connectivity#signaling for more information. In PeerConnectionManager, a WebRTC client (e.g. JavaScript video player) calls the following HTTP APIs:

  • /api/getMediaList: Returns a list of active CloudViewer visualizer windows.
  • /api/getIceServers: Returns a list of ICE (STUN/TURN) servers. The ICE server is used to forward requests through the remote peer's NAT layer. We use publicly available STUN servers. In certain network configurations (e.g. if the peers are behind certain type of firewalls), STUN server may fail to resolve and in this case, we'll need to implement and host a separate TURN server.
  • /api/call: Connect to a specific media (CloudViewer visualizer window).
  • /api/addIceCandidate (multiple calls): Client sends ICE candidate proposals.
  • /api/getIceCandidate: the client gets a list of ICE candidate associated with a PeerConnection.

[Stage 2: Sending video streams and send/recv with data channel]

  • PeerConnectionManager::OnFrame() shall be called when a frame is ready. This will send a video frame to all peers connected to the target window.
  • DataChannelObserver::OnMessage() will be called when the server receives a message from the data channel. The PeerConnectionManager then forwards the message to the correct event handler and eventually events (such as mouse click)can be triggered.

[Stage 3: Hangup] The client calls /api/hangup to close the WebRTC connection. This does not close the CloudViewer Window as a Window can be connected to 0 or more peers.

TODO (yixing): Use PImpl.

Definition at line 75 of file PeerConnectionManager.h.

Constructor & Destructor Documentation

◆ PeerConnectionManager()

cloudViewer::visualization::webrtc_server::PeerConnectionManager::PeerConnectionManager ( const std::list< std::string > &  ice_server_list,
const Json::Value &  config,
const std::string &  publish_filter,
const std::string &  webrtc_udp_port_range 
)

Definition at line 126 of file PeerConnectionManager.cpp.

References func_, and webrtc_port_range_.

◆ ~PeerConnectionManager()

cloudViewer::visualization::webrtc_server::PeerConnectionManager::~PeerConnectionManager ( )
virtual

Definition at line 200 of file PeerConnectionManager.cpp.

Member Function Documentation

◆ AddIceCandidate()

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::AddIceCandidate ( const std::string &  peerid,
const Json::Value &  json_message 
)

◆ AddStreams()

bool cloudViewer::visualization::webrtc_server::PeerConnectionManager::AddStreams ( webrtc::PeerConnectionInterface *  peer_connection,
const std::string &  window_uid,
const std::string &  options 
)
protected

◆ Call()

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::Call ( const std::string &  peerid,
const std::string &  window_uid,
const std::string &  options,
const Json::Value &  json_message 
)

◆ CloseWindowConnections()

void cloudViewer::visualization::webrtc_server::PeerConnectionManager::CloseWindowConnections ( const std::string &  window_uid)

◆ CreatePeerConnection()

PeerConnectionManager::PeerConnectionObserver * cloudViewer::visualization::webrtc_server::PeerConnectionManager::CreatePeerConnection ( const std::string &  peerid)
protected

◆ CreateVideoSource()

rtc::scoped_refptr< BitmapTrackSourceInterface > cloudViewer::visualization::webrtc_server::PeerConnectionManager::CreateVideoSource ( const std::string &  window_uid,
const std::map< std::string, std::string > &  opts 
)
protected

◆ GetHttpApi()

const std::map< std::string, HttpServerRequestHandler::HttpFunction > cloudViewer::visualization::webrtc_server::PeerConnectionManager::GetHttpApi ( )

Definition at line 494 of file PeerConnectionManager.cpp.

References func_.

◆ GetIceCandidateList()

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::GetIceCandidateList ( const std::string &  peerid)

◆ GetIceServers()

◆ GetMediaList()

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::GetMediaList ( )

◆ GetPeerConnection()

rtc::scoped_refptr< webrtc::PeerConnectionInterface > cloudViewer::visualization::webrtc_server::PeerConnectionManager::GetPeerConnection ( const std::string &  peerid)
protected

Definition at line 241 of file PeerConnectionManager.cpp.

References peerid_to_connection_.

Referenced by AddIceCandidate().

◆ GetVideoTrackSource()

rtc::scoped_refptr< BitmapTrackSourceInterface > cloudViewer::visualization::webrtc_server::PeerConnectionManager::GetVideoTrackSource ( const std::string &  window_uid)
protected

Definition at line 696 of file PeerConnectionManager.cpp.

References window_uid_to_track_source_, and window_uid_to_track_source_mutex_.

Referenced by OnFrame().

◆ HangUp()

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::HangUp ( const std::string &  peerid)

◆ InitializePeerConnection()

bool cloudViewer::visualization::webrtc_server::PeerConnectionManager::InitializePeerConnection ( )

Definition at line 516 of file PeerConnectionManager.cpp.

References peer_connection_factory_.

◆ OnFrame()

void cloudViewer::visualization::webrtc_server::PeerConnectionManager::OnFrame ( const std::string &  window_uid,
const std::shared_ptr< core::Tensor > &  im 
)

Definition at line 732 of file PeerConnectionManager.cpp.

References GetVideoTrackSource().

◆ SendInitFramesToPeer()

void cloudViewer::visualization::webrtc_server::PeerConnectionManager::SendInitFramesToPeer ( const std::string &  peerid)

◆ WindowStillUsed()

bool cloudViewer::visualization::webrtc_server::PeerConnectionManager::WindowStillUsed ( const std::string &  window_uid)
protected

Definition at line 417 of file PeerConnectionManager.cpp.

References peerid_to_connection_.

Referenced by HangUp().

Member Data Documentation

◆ config_

const Json::Value cloudViewer::visualization::webrtc_server::PeerConnectionManager::config_
protected

Definition at line 453 of file PeerConnectionManager.h.

Referenced by AddStreams(), and CreateVideoSource().

◆ func_

std::map<std::string, HttpServerRequestHandler::HttpFunction> cloudViewer::visualization::webrtc_server::PeerConnectionManager::func_
protected

Definition at line 455 of file PeerConnectionManager.h.

Referenced by GetHttpApi(), and PeerConnectionManager().

◆ ice_server_list_

std::list<std::string> cloudViewer::visualization::webrtc_server::PeerConnectionManager::ice_server_list_
protected

Definition at line 452 of file PeerConnectionManager.h.

Referenced by CreatePeerConnection(), and GetIceServers().

◆ peer_connection_factory_

rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> cloudViewer::visualization::webrtc_server::PeerConnectionManager::peer_connection_factory_
protected

Definition at line 429 of file PeerConnectionManager.h.

Referenced by AddStreams(), and InitializePeerConnection().

◆ peerid_data_channel_mutex_

std::mutex cloudViewer::visualization::webrtc_server::PeerConnectionManager::peerid_data_channel_mutex_
protected

Definition at line 437 of file PeerConnectionManager.h.

Referenced by AddIceCandidate().

◆ peerid_data_channel_ready_

std::unordered_set<std::string> cloudViewer::visualization::webrtc_server::PeerConnectionManager::peerid_data_channel_ready_
protected

Definition at line 436 of file PeerConnectionManager.h.

Referenced by AddIceCandidate().

◆ peerid_to_connection_

std::unordered_map<std::string, PeerConnectionObserver*> cloudViewer::visualization::webrtc_server::PeerConnectionManager::peerid_to_connection_
protected

◆ peerid_to_connection_mutex_

std::mutex cloudViewer::visualization::webrtc_server::PeerConnectionManager::peerid_to_connection_mutex_
protected

Definition at line 434 of file PeerConnectionManager.h.

Referenced by AddIceCandidate(), Call(), GetIceCandidateList(), and HangUp().

◆ peerid_to_window_uid_

std::unordered_map<std::string, std::string> cloudViewer::visualization::webrtc_server::PeerConnectionManager::peerid_to_window_uid_
protected

Definition at line 448 of file PeerConnectionManager.h.

Referenced by Call(), HangUp(), and SendInitFramesToPeer().

◆ publish_filter_

const std::regex cloudViewer::visualization::webrtc_server::PeerConnectionManager::publish_filter_
protected

Definition at line 454 of file PeerConnectionManager.h.

◆ task_queue_factory_

std::unique_ptr<webrtc::TaskQueueFactory> cloudViewer::visualization::webrtc_server::PeerConnectionManager::task_queue_factory_
protected

Definition at line 427 of file PeerConnectionManager.h.

◆ webrtc_port_range_

std::string cloudViewer::visualization::webrtc_server::PeerConnectionManager::webrtc_port_range_
protected

Definition at line 456 of file PeerConnectionManager.h.

Referenced by CreatePeerConnection(), and PeerConnectionManager().

◆ window_uid_to_peerids_

std::unordered_map<std::string, std::set<std::string> > cloudViewer::visualization::webrtc_server::PeerConnectionManager::window_uid_to_peerids_
protected

Definition at line 447 of file PeerConnectionManager.h.

Referenced by Call(), CloseWindowConnections(), and HangUp().

◆ window_uid_to_peerids_mutex_

std::mutex cloudViewer::visualization::webrtc_server::PeerConnectionManager::window_uid_to_peerids_mutex_
protected

◆ window_uid_to_track_source_

std::unordered_map<std::string, rtc::scoped_refptr<BitmapTrackSourceInterface> > cloudViewer::visualization::webrtc_server::PeerConnectionManager::window_uid_to_track_source_
protected

◆ window_uid_to_track_source_mutex_

std::mutex cloudViewer::visualization::webrtc_server::PeerConnectionManager::window_uid_to_track_source_mutex_
protected

Definition at line 443 of file PeerConnectionManager.h.

Referenced by AddStreams(), GetVideoTrackSource(), and HangUp().


The documentation for this class was generated from the following files: