4 #ifndef OWT_P2P_P2PCLIENT_H_ 5 #define OWT_P2P_P2PCLIENT_H_ 9 #include <unordered_map> 12 #include "owt/base/commontypes.h" 13 #include "owt/base/connectionstats.h" 14 #include "owt/base/stream.h" 15 #include "owt/p2p/p2ppublication.h" 16 #include "owt/p2p/p2psignalingchannelinterface.h" 17 #include "owt/p2p/p2psignalingsenderinterface.h" 18 #include "owt/base/clientconfiguration.h" 19 #include "owt/base/globalconfiguration.h" 25 struct PeerConnectionChannelConfiguration;
34 std::vector<AudioEncodingParameters> audio_encodings;
35 std::vector<VideoEncodingParameters> video_encodings;
37 class P2PPeerConnectionChannelObserverCppImpl;
38 class P2PPeerConnectionChannel;
48 const std::string message){}
54 std::shared_ptr<owt::base::RemoteStream> stream){}
63 :
protected P2PSignalingSenderInterface,
65 public std::enable_shared_from_this<P2PClient> {
67 friend class P2PPeerConnectionChannelObserverCppImpl;
75 std::shared_ptr<P2PSignalingChannelInterface> signaling_channel);
96 void Connect(
const std::string& host,
97 const std::string& token,
98 std::function<
void(
const std::string&)> on_success,
99 std::function<
void(std::unique_ptr<Exception>)> on_failure);
109 void Disconnect(std::function<
void()> on_success,
110 std::function<
void(std::unique_ptr<Exception>)> on_failure);
127 std::function<
void()> on_success,
128 std::function<
void(std::unique_ptr<Exception>)> on_failure);
141 void Stop(
const std::string& target_id,
142 std::function<
void()> on_success,
143 std::function<
void(std::unique_ptr<Exception>)> on_failure);
156 void Publish(
const std::string& target_id,
157 std::shared_ptr<owt::base::LocalStream> stream,
158 std::function<
void(std::shared_ptr<P2PPublication>)> on_success,
159 std::function<
void(std::unique_ptr<Exception>)> on_failure);
171 void Send(
const std::string& target_id,
172 const std::string& message,
173 std::function<
void()> on_success,
174 std::function<
void(std::unique_ptr<Exception>)> on_failure);
187 const std::string& target_id,
188 std::function<
void(std::shared_ptr<owt::base::ConnectionStats>)> on_success,
189 std::function<
void(std::unique_ptr<Exception>)> on_failure);
191 void SetLocalId(
const std::string& local_id);
195 virtual void SendSignalingMessage(
const std::string& message,
196 const std::string& remote_id,
197 std::function<
void()> on_success,
198 std::function<
void(std::unique_ptr<Exception>)> on_failure);
200 virtual void OnSignalingMessage(
const std::string& message,
const std::string& sender);
201 virtual void OnServerDisconnected();
204 virtual void OnStopped(
const std::string& remote_id);
207 virtual void OnMessageReceived(
const std::string& remote_id,
208 const std::string& message);
210 virtual void OnStreamAdded(
211 std::shared_ptr<owt::base::RemoteStream> stream);
213 void Unpublish(
const std::string& target_id,
214 std::shared_ptr<LocalStream> stream,
215 std::function<
void()> on_success,
216 std::function<
void(std::unique_ptr<Exception>)> on_failure);
217 std::shared_ptr<P2PPeerConnectionChannel> GetPeerConnectionChannel(
218 const std::string& target_id);
219 bool IsPeerConnectionChannelCreated(
const std::string& target_id);
220 owt::base::PeerConnectionChannelConfiguration GetPeerConnectionChannelConfiguration();
223 std::shared_ptr<rtc::TaskQueue> event_queue_;
224 std::shared_ptr<P2PSignalingChannelInterface> signaling_channel_;
225 std::unordered_map<std::string, std::shared_ptr<P2PPeerConnectionChannel>>
227 std::mutex pc_channels_mutex_;
228 std::vector<std::shared_ptr<P2PPeerConnectionChannel>> removed_pc_channels_;
229 std::mutex removed_pc_channels_mutex_;
230 std::string local_id_;
231 std::vector<std::reference_wrapper<P2PClientObserver>> observers_;
233 mutable std::mutex remote_ids_mutex_;
234 std::vector<std::string> allowed_remote_ids_;
238 #endif // OWT_P2P_P2PCLIENT_H_ Definition: conferencepublication.h:12
virtual void OnServerDisconnected()
This function will be invoked when client is disconnected from signaling server.
Definition: p2pclient.h:59
void RemoveObserver(P2PClientObserver &observer)
void Stop(const std::string &target_id, std::function< void()> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Stop a WebRTC session.
Observer for P2PClient.
Definition: p2pclient.h:40
void Publish(const std::string &target_id, std::shared_ptr< owt::base::LocalStream > stream, std::function< void(std::shared_ptr< P2PPublication >)> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Publish a stream to the remote client.
Definition: audioplayerinterface.h:8
virtual void OnMessageReceived(const std::string &remote_user_id, const std::string message)
This function will be invoked when received data from a remote user.
Definition: p2pclient.h:47
Client configurations.
Definition: clientconfiguration.h:13
void AddObserver(P2PClientObserver &observer)
void RemoveAllowedRemoteId(const std::string &target_id, std::function< void()> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Remove a remote user from the allowed list to stop a WebRTC session.
void AddAllowedRemoteId(const std::string &target_id)
Add a remote user to the allowed list to start a WebRTC session.
Definition: p2ppublication.h:18
Signaling channel will notify observer when event triggers.
Definition: p2psignalingchannelinterface.h:17
virtual void OnStreamAdded(std::shared_ptr< owt::base::RemoteStream > stream)
This function will be invoked when a remote stream is available.
Definition: p2pclient.h:53
Configuration for P2PClient This configuration is used while creating P2PClient. Changing this config...
Definition: p2pclient.h:33
void Connect(const std::string &host, const std::string &token, std::function< void(const std::string &)> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Connect to the signaling server.
An async client for P2P WebRTC sessions.
Definition: p2pclient.h:62
void Send(const std::string &target_id, const std::string &message, std::function< void()> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Send a message to remote client.
void Disconnect(std::function< void()> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Disconnect from the signaling server. It will stop all active WebRTC sessions.
P2PClient(P2PClientConfiguration &configuration, std::shared_ptr< P2PSignalingChannelInterface > signaling_channel)
Init a P2PClient instance with speficied signaling channel.
void GetConnectionStats(const std::string &target_id, std::function< void(std::shared_ptr< owt::base::ConnectionStats >)> on_success, std::function< void(std::unique_ptr< Exception >)> on_failure)
Get the connection statistowt with target client.