mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-10-01 13:59:31 -05:00
Compare commits
4 Commits
mac-proc-f
...
twitch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8f4e524ba | ||
|
|
b104f98d02 | ||
|
|
abc8c3708f | ||
|
|
3b63db2bde |
@@ -383,8 +383,18 @@ target_precompile_headers(${LIB_NAME} PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/lib/pch.hpp")
|
||||
|
||||
target_include_directories(
|
||||
${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk")
|
||||
${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib")
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk/exprtk.hpp")
|
||||
target_include_directories(${LIB_NAME}
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk")
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE EXPRTK_SUPPORT=1)
|
||||
else()
|
||||
message(
|
||||
STATUS
|
||||
"${PROJECT_NAME}: deps/exprtk not found - math expression support disabled"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT nlohmann_json_DIR
|
||||
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/json/CMakeLists.txt")
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
#include "obs-module-helper.hpp"
|
||||
|
||||
#include <climits>
|
||||
#ifdef EXPRTK_SUPPORT
|
||||
#include <exprtk.hpp>
|
||||
#include <random>
|
||||
#endif
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::variant<double, std::string> EvalMathExpression(const std::string &expr)
|
||||
{
|
||||
#ifdef EXPRTK_SUPPORT
|
||||
static auto randomFunc = []() {
|
||||
thread_local std::mt19937 gen(std::random_device{}());
|
||||
thread_local std::uniform_real_distribution<double> dis(0.0,
|
||||
@@ -26,6 +29,7 @@ std::variant<double, std::string> EvalMathExpression(const std::string &expr)
|
||||
if (parser.compile(expr, expression)) {
|
||||
return expression.value();
|
||||
}
|
||||
#endif
|
||||
return std::string(obs_module_text(
|
||||
"AdvSceneSwitcher.math.expressionFail")) +
|
||||
" \"" + expr + "\"";
|
||||
|
||||
@@ -127,9 +127,10 @@ void RegisterWebsocketRequest(
|
||||
|
||||
void SendWebsocketVendorEvent(const std::string &eventName, obs_data_t *data)
|
||||
{
|
||||
if (OBSIsShuttingDown()) {
|
||||
if (OBSIsShuttingDown() || !obs_get_module("obs-websocket")) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs_websocket_vendor_emit_event(vendor, eventName.c_str(), data);
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,12 @@ void TwitchToken::Load(obs_data_t *obj)
|
||||
{
|
||||
Item::Load(obj);
|
||||
_token = obs_data_get_string(obj, "token");
|
||||
_userID = obs_data_get_string(obj, "userID");
|
||||
if (obs_data_has_user_value(obj, "userID") &&
|
||||
*obs_data_get_string(obj, "userID") != '\0') {
|
||||
_userID = obs_data_get_string(obj, "userID");
|
||||
} else {
|
||||
_userID = {};
|
||||
}
|
||||
obs_data_set_default_bool(obj, "validateEventSubTimestamps", true);
|
||||
_validateEventSubTimestamps =
|
||||
obs_data_get_bool(obj, "validateEventSubTimestamps");
|
||||
@@ -255,7 +260,7 @@ void TwitchToken::Save(obs_data_t *obj) const
|
||||
{
|
||||
Item::Save(obj);
|
||||
obs_data_set_string(obj, "token", _token.c_str());
|
||||
if (_userID) {
|
||||
if (_userID && !_userID->empty()) {
|
||||
obs_data_set_string(obj, "userID", _userID->c_str());
|
||||
}
|
||||
obs_data_set_bool(obj, "validateEventSubTimestamps",
|
||||
@@ -310,7 +315,7 @@ bool TwitchToken::AnyOptionIsEnabled(
|
||||
return false;
|
||||
}
|
||||
|
||||
void TwitchToken::SetToken(const std::string &value)
|
||||
bool TwitchToken::SetToken(const std::string &value)
|
||||
{
|
||||
_token = value;
|
||||
auto res =
|
||||
@@ -318,21 +323,34 @@ void TwitchToken::SetToken(const std::string &value)
|
||||
if (res.status != 200) {
|
||||
blog(LOG_WARNING, "failed to get Twitch user id from token!");
|
||||
_userID = {};
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool gotUserID = false;
|
||||
OBSDataArrayAutoRelease array = obs_data_get_array(res.data, "data");
|
||||
size_t count = obs_data_array_count(array);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
OBSDataAutoRelease arrayObj = obs_data_array_item(array, i);
|
||||
_userID = obs_data_get_string(arrayObj, "id");
|
||||
std::string id = obs_data_get_string(arrayObj, "id");
|
||||
if (id.empty()) {
|
||||
blog(LOG_WARNING,
|
||||
"Twitch /helix/users response did not contain a user id!");
|
||||
continue;
|
||||
}
|
||||
_userID = id;
|
||||
_name = obs_data_get_string(arrayObj, "display_name");
|
||||
gotUserID = true;
|
||||
}
|
||||
|
||||
if (!gotUserID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Trigger resubscribes with new token
|
||||
if (_eventSub) {
|
||||
_eventSub->ClearActiveSubscriptions();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<std::string> TwitchToken::GetToken() const
|
||||
@@ -388,7 +406,7 @@ bool TwitchToken::IsValid(bool forceUpdate) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_userID && _userID != id) {
|
||||
if (_userID && !_userID->empty() && _userID != id) {
|
||||
blog(LOG_INFO,
|
||||
"Twitch token %s does not match expected user (got %s, expected %s)!",
|
||||
_name.c_str(), id, _userID->c_str());
|
||||
@@ -396,6 +414,10 @@ bool TwitchToken::IsValid(bool forceUpdate) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_userID || _userID->empty()) {
|
||||
_userID = id;
|
||||
}
|
||||
|
||||
_lastValidityCheckResult = true;
|
||||
return true;
|
||||
};
|
||||
@@ -819,9 +841,9 @@ void TwitchTokenSettingsDialog::GotToken(const std::optional<QString> &value)
|
||||
return;
|
||||
}
|
||||
|
||||
_currentToken.SetToken(value.value().toStdString());
|
||||
bool success = _currentToken.SetToken(value.value().toStdString());
|
||||
auto name = QString::fromStdString(_currentToken._name);
|
||||
if (name.isEmpty()) {
|
||||
if (!success || name.isEmpty()) {
|
||||
_tokenStatus->setText(obs_module_text(
|
||||
"AdvSceneSwitcher.twitchToken.request.fail"));
|
||||
_name->setText("");
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
bool OptionIsActive(const TokenOption &option) const;
|
||||
bool OptionIsEnabled(const TokenOption &option) const;
|
||||
bool AnyOptionIsEnabled(const std::vector<TokenOption> &options) const;
|
||||
void SetToken(const std::string &);
|
||||
bool SetToken(const std::string &);
|
||||
bool IsEmpty() const { return _token.empty(); }
|
||||
std::optional<std::string> GetToken() const;
|
||||
std::optional<std::string> GetUserID() const { return _userID; }
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
mutable std::string _lastValidityCheckValue;
|
||||
mutable bool _lastValidityCheckResult = false;
|
||||
mutable std::chrono::system_clock::time_point _lastValidityCheckTime;
|
||||
std::optional<std::string> _userID;
|
||||
mutable std::optional<std::string> _userID;
|
||||
std::set<TokenOption> _tokenOptions = TokenOption::GetAllTokenOptions();
|
||||
std::shared_ptr<EventSub> _eventSub;
|
||||
bool _validateEventSubTimestamps = false;
|
||||
|
||||
@@ -85,8 +85,11 @@ target_sources(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE test-math.cpp ${ADVSS_SOURCE_DIR}/lib/utils/math-helpers.cpp
|
||||
${ADVSS_SOURCE_DIR}/lib/utils/obs-module-helper.cpp)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk)
|
||||
if(EXISTS "${ADVSS_SOURCE_DIR}/deps/exprtk/exprtk.hpp")
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE EXPRTK_SUPPORT=1)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC /MP /d2FH4- /wd4267 /bigobj)
|
||||
|
||||
Reference in New Issue
Block a user