5#ifndef SKYWAY_CORE_CONTEXT_HPP_
6#define SKYWAY_CORE_CONTEXT_HPP_
8#include "skyway/core/config.hpp"
9#include "skyway/core/context_options.hpp"
10#include "skyway/core/interface/remote_member_plugin.hpp"
11#include "skyway/global/error.hpp"
12#include "skyway/global/interface/logger.hpp"
13#include "skyway/network/interface/http_client.hpp"
14#include "skyway/network/interface/websocket_client.hpp"
15#include "skyway/platform/interface/platform_info_delegator.hpp"
16#include "skyway/rtc_api/interface/client.hpp"
17#include "skyway/token/interface/auth_token_manager.hpp"
27class CoreIceManagerTest;
32namespace remote_person {
34class RemotePersonPluginReceiverTest;
35class RemotePersonPluginSenderTest;
41class SfuBotPluginConnectionStateObserverTest;
42class SfuBotPluginSenderTest;
52using RemoteMemberPluginInterface = interface::RemoteMemberPlugin;
53using HttpClientInterface = network::interface::HttpClient;
54using WebSocketClientFactoryInterface = network::interface::WebSocketClientFactory;
55using PlatformInfoDelegatorInterface = platform::interface::PlatformInfoDelegator;
56using LoggerInterface = global::interface::Logger;
57using SkyWayError = global::Error;
65 virtual ~EventListener() =
default;
68 virtual void OnReconnectStart() = 0;
71 virtual void OnReconnectSuccess() = 0;
76 virtual void OnFatalError(
const SkyWayError& error) = 0;
88 static bool Setup(
const std::string& token,
89 std::unique_ptr<HttpClientInterface> http,
90 std::unique_ptr<WebSocketClientFactoryInterface> ws_factory,
91 std::unique_ptr<PlatformInfoDelegatorInterface> platform_info,
92 std::unique_ptr<LoggerInterface> logger,
93 EventListener* listener,
94 const ContextOptions& options);
98 static bool UpdateAuthToken(
const std::string& token);
103 static void _UpdateRtcConfig(ContextOptions::RtcConfig rtc_config);
108 static void RegisterPlugin(std::unique_ptr<RemoteMemberPluginInterface> plugin);
112 static void Dispose();
117 static std::weak_ptr<token::interface::AuthTokenManager> AuthTokenManager();
121 static std::weak_ptr<rtc_api::interface::Client> RtcApi();
126 static std::weak_ptr<analytics::interface::AnalyticsClient> AnalyticsClient();
130 static ContextOptions Options();
134 static std::vector<RemoteMemberPluginInterface*> GetRemoteMemberPlugins();
140 static RemoteMemberPluginInterface* FindRemoteMemberPluginBySubtype(
const std::string& subtype);
144 static void OnReconnectStart();
148 static void OnReconnectSuccess();
153 static void OnFatalError(
const SkyWayError& error);
158 static std::string GetContextId();
161 static std::mutex listener_mtx_;
162 static EventListener* listener_;
163 static bool is_setup_;
164 static std::mutex setup_mtx_;
165 static std::shared_ptr<rtc_api::interface::Client> rtc_api_;
166 static std::shared_ptr<token::interface::AuthTokenManager> token_manager_;
167 static std::string context_id_;
168 static std::shared_ptr<analytics::interface::AnalyticsClient> analytics_client_;
169 static ContextOptions options_;
170 static std::vector<std::unique_ptr<RemoteMemberPluginInterface>> plugins_;
174 friend class CoreContextTest;
175 friend class channel::CoreChannelTest;
176 friend class ice::CoreIceManagerTest;
177 friend class plugin::sfu_bot::connection::
178 SfuBotPluginConnectionStateObserverTest;
179 friend class plugin::sfu_bot::connection::SfuBotPluginSenderTest;
180 friend class plugin::remote_person::connection::
181 RemotePersonPluginReceiverTest;
182 friend class plugin::remote_person::connection::RemotePersonPluginSenderTest;