4 #ifndef OWT_CONFERENCE_CONFERENCECLIENT_H_ 5 #define OWT_CONFERENCE_CONFERENCECLIENT_H_ 9 #include <unordered_map> 12 #include "owt/base/commontypes.h" 13 #include "owt/base/clientconfiguration.h" 14 #include "owt/base/connectionstats.h" 15 #include "owt/base/options.h" 16 #include "owt/base/stream.h" 17 #include "owt/base/exception.h" 18 #include "owt/conference/conferencepublication.h" 19 #include "owt/conference/conferencesubscription.h" 20 #include "owt/conference/streamupdateobserver.h" 21 #include "owt/conference/subscribeoptions.h" 30 struct PeerConnectionChannelConfiguration;
34 namespace conference {
45 class ConferencePeerConnectionChannel;
46 class ConferenceSocketSignalingChannel;
63 Participant(std::string
id, std::string role, std::string user_id)
66 , user_id_(user_id) {}
73 std::string
Id()
const {
return id_; }
75 std::string
Role()
const {
return role_; }
77 std::string
UserId()
const {
return user_id_; }
80 void Id(std::string
id) { id_ = id; }
82 void Role(std::string role) { role_ = role; }
84 void UserId(std::string user_id) { user_id_ = user_id; }
86 void TriggerOnParticipantLeft();
91 mutable std::mutex observer_mutex_;
92 std::vector<std::reference_wrapper<ParticipantObserver>> observers_;
105 return remote_streams_;
109 return participants_;
112 std::string
Id()
const {
return id_; }
114 std::shared_ptr<Participant>
Self()
const {
119 void AddParticipant(std::shared_ptr<Participant> participant);
121 void RemoveParticipantById(
const std::string&
id);
123 void AddOrUpdateStream(std::shared_ptr<RemoteStream> remote_stream,
bool &updated);
125 void RemoveStreamById(
const std::string& stream_id);
127 void TriggerOnParticipantLeft(
const std::string& participant_id);
129 void TriggerOnStreamEnded(
const std::string& stream_id);
131 void TriggerOnStreamUpdated(
const std::string& stream_id);
133 void TriggerOnStreamMuteOrUnmute(
const std::string& stream_id, owt::base::TrackKind track_kind,
bool muted);
135 bool ParticipantPresent(
const std::string& participant_id);
136 bool RemoteStreamPresent(
const std::string& stream_id);
138 mutable std::mutex participants_mutex_;
139 std::vector<std::shared_ptr<Participant>> participants_;
140 mutable std::mutex remote_streams_mutex_;
141 std::vector<std::shared_ptr<RemoteStream>> remote_streams_;
142 std::shared_ptr<Participant> self_;
145 class ConferenceSocketSignalingChannelObserver {
147 virtual ~ConferenceSocketSignalingChannelObserver(){}
148 virtual void OnUserJoined(std::shared_ptr<sio::message> user) = 0;
149 virtual void OnUserLeft(std::shared_ptr<sio::message> user) = 0;
150 virtual void OnStreamAdded(std::shared_ptr<sio::message> stream) = 0;
151 virtual void OnStreamRemoved(std::shared_ptr<sio::message> stream) = 0;
152 virtual void OnStreamUpdated(std::shared_ptr<sio::message> stream) = 0;
153 virtual void OnServerDisconnected() = 0;
154 virtual void OnCustomMessage(std::string& from, std::string& message, std::string& to) = 0;
155 virtual void OnSignalingMessage(std::shared_ptr<sio::message> message) = 0;
156 virtual void OnStreamError(std::shared_ptr<sio::message> stream) = 0;
158 virtual void OnStreamId(
const std::string&
id,
const std::string& label) = 0;
159 virtual void OnSubscriptionId(
const std::string& subscription_id,
160 const std::string& stream_id) = 0;
165 class ConferencePeerConnectionChannelObserver {
167 virtual ~ConferencePeerConnectionChannelObserver(){}
170 virtual void OnStreamError(
171 std::shared_ptr<Stream> stream,
172 std::shared_ptr<const Exception> exception) = 0;
175 class ConferenceClientObserver {
183 std::shared_ptr<RemoteStream> stream){}
189 std::shared_ptr<RemoteMixedStream> stream){}
198 std::string& sender_id,
213 : ConferenceSocketSignalingChannelObserver,
214 ConferencePeerConnectionChannelObserver,
215 public std::enable_shared_from_this<ConferenceClient> {
223 static std::shared_ptr<ConferenceClient> Create(
237 const std::string& token,
238 std::function<
void(std::shared_ptr<ConferenceInfo>)> on_success,
239 std::function<
void(std::unique_ptr<Exception>)> on_failure);
244 std::function<
void()> on_success,
245 std::function<
void(std::unique_ptr<Exception>)> on_failure);
251 std::shared_ptr<LocalStream> stream,
252 std::function<
void(std::shared_ptr<ConferencePublication>)> on_success,
253 std::function<
void(std::unique_ptr<Exception>)> on_failure);
260 std::shared_ptr<LocalStream> stream,
262 std::function<
void(std::shared_ptr<ConferencePublication>)> on_success,
263 std::function<
void(std::unique_ptr<Exception>)> on_failure);
270 std::shared_ptr<RemoteStream> stream,
271 std::function<
void(std::shared_ptr<ConferenceSubscription>)> on_success,
272 std::function<
void(std::unique_ptr<Exception>)> on_failure);
280 std::shared_ptr<RemoteStream> stream,
282 std::function<
void(std::shared_ptr<ConferenceSubscription>)> on_success,
283 std::function<
void(std::unique_ptr<Exception>)> on_failure);
289 const std::string& message,
290 std::function<
void()> on_success,
291 std::function<
void(std::unique_ptr<Exception>)> on_failure);
298 const std::string& message,
299 const std::string& receiver,
300 std::function<
void()> on_success,
301 std::function<
void(std::unique_ptr<Exception>)> on_failure);
305 virtual void OnStreamAdded(std::shared_ptr<sio::message> stream)
override;
306 virtual void OnCustomMessage(std::string& from,
307 std::string& message,
308 std::string& to)
override;
309 virtual void OnSignalingMessage(
310 std::shared_ptr<sio::message> stream)
override;
311 virtual void OnUserJoined(std::shared_ptr<sio::message> user)
override;
312 virtual void OnUserLeft(std::shared_ptr<sio::message> user)
override;
313 virtual void OnStreamRemoved(std::shared_ptr<sio::message> stream)
override;
314 virtual void OnStreamUpdated(std::shared_ptr<sio::message> stream)
override;
315 virtual void OnStreamError(std::shared_ptr<sio::message> stream)
override;
316 virtual void OnServerDisconnected()
override;
317 virtual void OnStreamId(
const std::string&
id,
318 const std::string& publish_stream_label)
override;
319 virtual void OnSubscriptionId(
const std::string& subscription_id,
320 const std::string& stream_id)
override;
322 virtual void OnStreamError(
323 std::shared_ptr<Stream> stream,
324 std::shared_ptr<const Exception> exception)
override;
331 const std::string& session_id,
332 std::function<
void()> on_success,
333 std::function<
void(std::unique_ptr<Exception>)> on_failure);
339 const std::string& session_id,
340 std::function<
void()> on_success,
341 std::function<
void(std::unique_ptr<Exception>)> on_failure);
345 void UpdateSubscription(
346 const std::string& session_id,
347 const std::string& stream_id,
349 std::function<
void()> on_success,
350 std::function<
void(std::unique_ptr<Exception>)> on_failure);
354 void GetConnectionStats(
355 const std::string& session_id,
356 std::function<
void(std::shared_ptr<ConnectionStats>)> on_success,
357 std::function<
void(std::unique_ptr<Exception>)> on_failure);
359 const std::string& session_id,
361 const std::vector<const webrtc::StatsReport*>& reports)> on_success,
362 std::function<
void(std::unique_ptr<Exception>)> on_failure);
367 const std::string& session_id,
368 TrackKind track_kind,
369 std::function<
void()> on_success,
370 std::function<
void(std::unique_ptr<Exception>)> on_failure);
375 const std::string& session_id,
376 TrackKind track_kind,
377 std::function<
void()> on_success,
378 std::function<
void(std::unique_ptr<Exception>)> on_failure);
382 bool CheckNullPointer(
384 std::function<
void(std::unique_ptr<Exception>)> on_failure);
385 bool CheckNullPointer(
387 const std::string& failure_message,
388 std::function<
void(std::unique_ptr<Exception>)> on_failure);
391 bool CheckSignalingChannelOnline(
392 std::function<
void(std::unique_ptr<Exception>)> on_failure);
393 PeerConnectionChannelConfiguration GetPeerConnectionChannelConfiguration()
397 std::shared_ptr<ConferencePeerConnectionChannel>
398 GetConferencePeerConnectionChannel(
const std::string& session_id)
const;
399 void TriggerOnUserJoined(std::shared_ptr<sio::message> user_info,
bool joining =
false);
400 void TriggerOnUserLeft(std::shared_ptr<sio::message> user_info);
401 void TriggerOnStreamAdded(std::shared_ptr<sio::message> stream_info,
bool joining =
false);
402 void TriggerOnStreamRemoved(std::shared_ptr<sio::message> stream_info);
403 void TriggerOnStreamUpdated(std::shared_ptr<sio::message> stream_info);
404 void TriggerOnStreamError(std::shared_ptr<Stream> stream,
405 std::shared_ptr<const Exception> exception);
408 bool ParseUser(std::shared_ptr<sio::message> user_info,
Participant** participant)
const;
409 void ParseStreamInfo(std::shared_ptr<sio::message> stream_info,
bool joining =
false);
410 std::unordered_map<std::string, std::string> AttributesFromStreamInfo(
411 std::shared_ptr<sio::message> stream_info);
412 std::function<void()> RunInEventQueue(std::function<
void()> func);
414 bool IsBase64EncodedString(
const std::string str)
const;
416 void AddStreamUpdateObserver(ConferenceStreamUpdateObserver& observer);
418 void RemoveStreamUpdateObserver(ConferenceStreamUpdateObserver& observer);
419 enum StreamType: int;
423 std::shared_ptr<rtc::TaskQueue> event_queue_;
424 std::shared_ptr<ConferenceSocketSignalingChannel> signaling_channel_;
425 std::mutex observer_mutex_;
426 bool signaling_channel_connected_;
428 std::unordered_map<std::string, std::string> publish_id_label_map_;
430 std::vector<std::shared_ptr<ConferencePeerConnectionChannel>>
432 mutable std::mutex publish_pcs_mutex_;
434 std::vector<std::shared_ptr<ConferencePeerConnectionChannel>>
437 std::unordered_map<std::string, std::string> subscribe_id_label_map_;
438 mutable std::mutex subscribe_pcs_mutex_;
440 std::unordered_map<std::string, std::shared_ptr<RemoteStream>>
442 std::unordered_map<std::string, StreamType> added_stream_type_;
443 mutable std::mutex conference_info_mutex_;
445 std::shared_ptr<ConferenceInfo> current_conference_info_;
448 std::vector<std::reference_wrapper<ConferenceClientObserver>> observers_;
449 mutable std::mutex stream_update_observer_mutex_;
450 std::vector <std::reference_wrapper<ConferenceStreamUpdateObserver>> stream_update_observers_;
454 #endif // OWT_CONFERENCE_CONFERENCECLIENT_H_ std::vector< std::shared_ptr< RemoteStream > > RemoteStreams() const
Current remote streams in the conference.
Definition: conferenceclient.h:104
Information about the conference.
Definition: conferenceclient.h:98
std::string UserId() const
Get the participant's user id.
Definition: conferenceclient.h:77
An asynchronous class for app to communicate with a conference in MCU.
Definition: conferenceclient.h:212
std::string Id() const
Get the participant's ID.
Definition: conferenceclient.h:73
std::vector< std::shared_ptr< Participant > > Participants() const
Current participant list in the conference.
Definition: conferenceclient.h:108
Observer for OWTConferenceClient.
Definition: conferenceclient.h:176
Definition: conferenceclient.h:22
This class represent a mixed remote stream.
Definition: remotemixedstream.h:17
Participant represents one conference client in a conference room.
Definition: conferenceclient.h:60
Observer interface for participant.
Definition: conferenceclient.h:52
std::string Id() const
Conference ID.
Definition: conferenceclient.h:112
Definition: audioplayerinterface.h:8
Client configurations.
Definition: clientconfiguration.h:13
virtual void OnMessageReceived(std::string &message, std::string &sender_id, std::string &to)
Triggers when a message is received.
Definition: conferenceclient.h:197
Definition: audioplayerinterface.h:9
Configuration for creating a ConferenceClient.
Definition: conferenceclient.h:43
virtual void OnStreamAdded(std::shared_ptr< RemoteStream > stream)
Triggers when a stream is added.
Definition: conferenceclient.h:182
virtual void OnParticipantJoined(std::shared_ptr< Participant >)
Triggers when a participant joined conference.
Definition: conferenceclient.h:204
Definition: conferencepublication.h:25
Publish options describing encoding settings.
Definition: options.h:51
virtual void OnLeft()
Participant leave event callback.
Definition: conferenceclient.h:57
std::string Role() const
Get the participant's role.
Definition: conferenceclient.h:75
std::shared_ptr< Participant > Self() const
The participant info of current conference client.
Definition: conferenceclient.h:114
Subscribe options.
Definition: subscribeoptions.h:44
virtual void OnStreamAdded(std::shared_ptr< RemoteMixedStream > stream)
Triggers when a mixed stream is added.
Definition: conferenceclient.h:188
Subscription update option used by subscription's ApplyOptions API.
Definition: subscribeoptions.h:65
virtual void OnServerDisconnected()
Triggers when server is disconnected.
Definition: conferenceclient.h:208
Definition: conferencesubscription.h:25