SkyWay Linux SDK
読み取り中…
検索中…
一致する文字列を見つけられません
channel.hpp
1//
2// © NTT DOCOMO BUSINESS, Inc. All Rights Reserved.
3//
4
5#ifndef SKYWAY_CORE_CHANNEL_CHANNEL_HPP_
6#define SKYWAY_CORE_CHANNEL_CHANNEL_HPP_
7
8#include <string>
9
10#include "skyway/core/channel/member/local_person.hpp"
11#include "skyway/core/interface/channel.hpp"
12#include "skyway/core/interface/chunk_messenger_factory.hpp"
13#include "skyway/core/interface/member.hpp"
14#include "skyway/core/interface/publication.hpp"
15#include "skyway/core/interface/remote_member.hpp"
16#include "skyway/core/interface/subscription.hpp"
17#include "skyway/rtc_api/client.hpp"
18#include "skyway/rtc_api/interface/channel_state.hpp"
19
20namespace skyway {
21namespace core {
22namespace channel {
23
24using ChannelState = interface::ChannelState;
25using ChannelInit = model::Channel::Init;
26using ChannelQuery = model::Channel::Query;
27
28using SignalingClientDelegator = signaling::interface::SignalingClient::Delegator;
29
31class Channel : public interface::Channel, public rtc_api::ChannelState::EventListener {
32public:
34 Channel(std::unique_ptr<rtc_api::interface::ChannelState> rtc_api_channel_state,
35 std::unique_ptr<interface::ChunkMessengerFactory> chunk_messenger_factory);
36 Channel(std::unique_ptr<rtc_api::interface::ChannelState> rtc_api_channel_state);
37 ~Channel();
38 void SetupDomains();
40
44 static std::shared_ptr<Channel> Create(const ChannelInit& init);
46 static std::shared_ptr<Channel> Create();
50 static std::shared_ptr<Channel> Find(const ChannelQuery& query);
53 static std::shared_ptr<Channel> FindOrCreate(const ChannelInit& init);
56 static void DisposeAllChannels();
58
61
62 std::string Id() const override;
63 std::optional<std::string> Name() const override;
64 std::optional<std::string> Metadata() const override;
65 std::shared_ptr<interface::LocalPerson> LocalPerson() override;
66 std::vector<std::shared_ptr<interface::RemoteMember>> Bots(bool active_only = true) override;
67 std::vector<std::shared_ptr<interface::Member>> Members(bool active_only = true) override;
68 std::vector<std::shared_ptr<interface::Publication>> Publications(bool active_only = true) override;
69 std::vector<std::shared_ptr<interface::Subscription>> Subscriptions(bool active_only = true) override;
70 ChannelState State() const override;
71
72 std::shared_ptr<interface::LocalPerson> Join(const model::Member::Init& init) override;
73 bool UpdateMetadata(const std::string& metadata) override;
74 bool Leave(std::shared_ptr<interface::Member> member) override;
75 bool Close() override;
76 void Dispose(bool remove_myself_if_needed = true) override;
77
79 std::shared_ptr<interface::Member> FindMember(const std::string& member_id, bool active_only = true) override;
80 std::shared_ptr<interface::RemoteMember> FindRemoteMember(const std::string& member_id, bool active_only = true) override;
81 std::shared_ptr<interface::Publication> FindPublication(const std::string& publication_id,
82 bool active_only = true) override;
83 std::shared_ptr<interface::Subscription> FindSubscription(const std::string& subscription_id,
84 bool active_only = true) override;
85 std::vector<std::shared_ptr<interface::Subscription>> GetSubscriptionsByPublicationId(
86 const std::string& publication_id, bool active_only = true) override;
87 std::vector<std::shared_ptr<interface::Subscription>> GetSubscriptionsBySubscriberId(
88 const std::string& subscriber_id, bool active_only = true) override;
89 std::vector<std::shared_ptr<interface::Publication>> GetPublicationsByPublisherId(
90 const std::string& publisher_id, bool active_only = true) override;
91
92 std::optional<model::Member> GetMemberDto(const std::string& member_id) const override;
93 std::optional<model::Publication> GetPublicationDto(
94 const std::string& publication_id) const override;
95 std::optional<model::Subscription> GetSubscriptionDto(
96 const std::string& subscription_id) const override;
97
98 // ChannelState::EventListener
99 void OnChannelDeleted(const std::string& channel_id) override;
100 void OnChannelMetadataUpdated(model::Channel* channel) override;
101 void OnMemberAdded(const model::Member& member) override;
102 void OnMemberRemoved(const std::string& member_id) override;
103 void OnMemberMetadataUpdated(const model::Member& member) override;
104 void OnStreamPublished(const model::Publication& publication) override;
105 void OnStreamUnpublished(const std::string& publication_id) override;
106 void OnPublicationEnabled(const model::Publication& publication) override;
107 void OnPublicationDisabled(const model::Publication& publication) override;
108 void OnPublicationMetadataUpdated(const model::Publication& publication) override;
109 void OnPublicationSubscribed(const model::Subscription& subscription) override;
110 void OnPublicationUnsubscribed(const std::string& subscription_id) override;
112
113private:
114 std::vector<std::shared_ptr<interface::LocalPerson>> LocalPersons(bool active_only = true);
115 std::vector<std::shared_ptr<interface::RemoteMember>> RemoteMembers(bool active_only = true);
116 std::shared_ptr<member::LocalPerson> CreateLocalPerson(const model::Member& member);
117 std::shared_ptr<interface::RemoteMember> CreateRemoteMember(const model::Member& member);
118
119 std::unique_ptr<rtc_api::interface::ChannelState> rtc_api_channel_state_;
120 ChannelState state_;
121 std::atomic<bool> is_disposed_;
122
123 std::vector<std::shared_ptr<member::LocalPerson>> persons_;
124 std::vector<std::shared_ptr<interface::RemoteMember>> remote_members_;
125 std::vector<std::shared_ptr<interface::Publication>> publications_;
126 std::vector<std::shared_ptr<interface::Subscription>> subscriptions_;
127
128 std::unordered_set<interface::Channel::EventListener*> listeners_;
129
130 std::optional<std::string> tmp_local_person_id_;
131 std::optional<int> tmp_keepalive_interval_sec_;
132 std::optional<int> tmp_keepalive_interval_gap_sec_;
133 bool waiting_for_local_person_creation_;
134
135 std::mutex listeners_mtx_;
136 // These mutexes are required because it's possible that a domain is read on one thread while it
137 // is written on another thread(rtc-api)
138 std::mutex persons_mtx_;
139 std::mutex remote_members_mtx_;
140 std::mutex publications_mtx_;
141 std::mutex subscriptions_mtx_;
142 std::mutex dispose_mtx_;
143
144 std::unique_ptr<interface::ChunkMessengerFactory> chunk_messenger_factory_;
145
146 static std::unordered_set<std::shared_ptr<Channel>> channels_;
147
148public:
150 friend class CoreChannelTest;
152};
153
154} // namespace channel
155} // namespace core
156} // namespace skyway
157
158#endif /* SKYWAY_CORE_CHANNEL_CHANNEL_HPP_ */
Channelの実装クラス
Definition channel.hpp:31
void AddEventListener(interface::Channel::EventListener *listener) override
イベントを購読します。
std::vector< std::shared_ptr< interface::Publication > > Publications(bool active_only=true) override
Publicationの一覧を取得します。
static std::shared_ptr< Channel > Find(const ChannelQuery &query)
既に存在するChannelを検索します。
std::vector< std::shared_ptr< interface::Subscription > > Subscriptions(bool active_only=true) override
Subscriptionの一覧を取得します。
std::optional< std::string > Metadata() const override
Metadataを取得します。
static std::shared_ptr< Channel > Create()
Channelを作成します。
bool Close() override
Channelを閉じます。
void Dispose(bool remove_myself_if_needed=true) override
Channelを閉じずにChannelインスタンスを無効にし、リソースを解放します。
static std::shared_ptr< Channel > Create(const ChannelInit &init)
Channelを作成します。
void RemoveEventListener(interface::Channel::EventListener *listener) override
イベントの購読を中止します。
std::shared_ptr< interface::LocalPerson > LocalPerson() override
ChannelにJoinしているLocalPersonを取得します。
bool UpdateMetadata(const std::string &metadata) override
Metadataを更新します。
std::shared_ptr< interface::LocalPerson > Join(const model::Member::Init &init) override
ChannelにLocalPersonを追加します。
ChannelState State() const override
Channelの状態を取得します。
std::vector< std::shared_ptr< interface::RemoteMember > > Bots(bool active_only=true) override
ChannelにJoinしているBotを取得します。
std::vector< std::shared_ptr< interface::Member > > Members(bool active_only=true) override
ChannelにJoinしているすべてのMemberを取得します。
std::optional< std::string > Name() const override
Nameを取得します。
static std::shared_ptr< Channel > FindOrCreate(const ChannelInit &init)
既に存在するChannelを検索し、存在しない場合はChannelを作成します。
std::string Id() const override
Idを取得します。
イベントリスナ
Definition channel.hpp:30
Channelのインターフェース
Definition channel.hpp:27
CreateもしくはFindOrCreateで指定する情報
Definition domain.hpp:162
FindもしくはFindOrCreateで指定する情報
Definition domain.hpp:169
Channel情報
Definition domain.hpp:160
Join時に使用するメンバー情報
Definition domain.hpp:55
メンバー情報
Definition domain.hpp:53
Publication情報
Definition domain.hpp:91
Subscription情報
Definition domain.hpp:135