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