mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Utils: Refactor into dedicated components
This commit is contained in:
parent
306844e42d
commit
43a889c1d4
@ -97,10 +97,10 @@ set(obs-websocket_SOURCES
|
||||
src/forms/SettingsDialog.cpp
|
||||
src/forms/ConnectInfo.cpp
|
||||
src/forms/resources.qrc
|
||||
src/utils/Crypto.cpp
|
||||
src/utils/Json.cpp
|
||||
src/utils/Crypto.cpp
|
||||
src/utils/Platform.cpp
|
||||
src/utils/Obs.cpp
|
||||
src/utils/Platform.cpp
|
||||
deps/qr/cpp/QrCode.cpp)
|
||||
|
||||
set(obs-websocket_HEADERS
|
||||
@ -117,6 +117,10 @@ set(obs-websocket_HEADERS
|
||||
src/requesthandler/rpc/RequestStatus.h
|
||||
src/forms/SettingsDialog.h
|
||||
src/forms/ConnectInfo.h
|
||||
src/utils/Crypto.h
|
||||
src/utils/Json.h
|
||||
src/utils/Obs.h
|
||||
src/utils/Platform.h
|
||||
src/utils/Utils.h
|
||||
deps/qr/cpp/QrCode.hpp)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Crypto.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
std::string Utils::Crypto::GenerateSalt()
|
||||
|
13
src/utils/Crypto.h
Normal file
13
src/utils/Crypto.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
|
||||
namespace Utils {
|
||||
namespace Crypto {
|
||||
std::string GenerateSalt();
|
||||
std::string GenerateSecret(std::string password, std::string salt);
|
||||
bool CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString);
|
||||
QString GeneratePassword(size_t length = 16);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "Utils.h"
|
||||
#include "Json.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
bool Utils::Json::JsonArrayIsValidObsArray(json j)
|
||||
|
14
src/utils/Json.h
Normal file
14
src/utils/Json.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Utils {
|
||||
namespace Json {
|
||||
bool JsonArrayIsValidObsArray(json j);
|
||||
obs_data_t *JsonToObsData(json j);
|
||||
json ObsDataToJson(obs_data_t *d, bool includeDefault = false);
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include <inttypes.h>
|
||||
#include <QString>
|
||||
#include <obs-frontend-api.h>
|
||||
#include <util/util_uint64.h>
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Obs.h"
|
||||
#include "../obs-websocket.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
|
47
src/utils/Obs.h
Normal file
47
src/utils/Obs.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <obs.hpp>
|
||||
|
||||
#include "Json.h"
|
||||
|
||||
namespace Utils {
|
||||
namespace Obs {
|
||||
namespace StringHelper {
|
||||
std::string GetObsVersionString();
|
||||
std::string GetCurrentSceneCollection();
|
||||
std::string GetCurrentProfile();
|
||||
std::string GetCurrentProfilePath();
|
||||
std::string GetSourceTypeString(obs_source_t *source);
|
||||
std::string GetInputMonitorTypeString(obs_source_t *input);
|
||||
std::string GetMediaInputStateString(obs_source_t *input);
|
||||
std::string GetLastReplayBufferFilePath();
|
||||
std::string GetOutputTimecodeString(obs_output_t *output);
|
||||
}
|
||||
|
||||
namespace NumberHelper {
|
||||
uint64_t GetOutputDuration(obs_output_t *output);
|
||||
}
|
||||
|
||||
namespace ListHelper {
|
||||
std::vector<std::string> GetSceneCollectionList();
|
||||
std::vector<std::string> GetProfileList();
|
||||
std::vector<obs_hotkey_t *> GetHotkeyList();
|
||||
std::vector<std::string> GetHotkeyNameList();
|
||||
std::vector<json> GetSceneList();
|
||||
std::vector<json> GetSceneItemList(obs_scene_t *scene, bool basic = false);
|
||||
std::vector<json> GetTransitionList();
|
||||
std::vector<json> GetInputList(std::string inputKind = "");
|
||||
std::vector<std::string> GetInputKindList(bool unversioned = false, bool includeDisabled = false);
|
||||
}
|
||||
|
||||
namespace SearchHelper {
|
||||
obs_hotkey_t *GetHotkeyByName(std::string name);
|
||||
}
|
||||
|
||||
namespace ActionHelper {
|
||||
obs_sceneitem_t *CreateSceneItem(obs_source_t *input, obs_scene_t *scene, bool sceneItemEnabled = true);
|
||||
obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
#include <QHostAddress>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Platform.h"
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
std::string Utils::Platform::GetLocalAddress()
|
||||
|
14
src/utils/Platform.h
Normal file
14
src/utils/Platform.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
namespace Utils {
|
||||
namespace Platform {
|
||||
std::string GetLocalAddress();
|
||||
QString GetCommandLineArgument(QString arg);
|
||||
bool GetCommandLineFlagSet(QString arg);
|
||||
void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body);
|
||||
}
|
||||
}
|
@ -1,70 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <obs.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Utils {
|
||||
namespace Json {
|
||||
bool JsonArrayIsValidObsArray(json j);
|
||||
obs_data_t *JsonToObsData(json j);
|
||||
json ObsDataToJson(obs_data_t *d, bool includeDefault = false);
|
||||
}
|
||||
|
||||
namespace Crypto {
|
||||
std::string GenerateSalt();
|
||||
std::string GenerateSecret(std::string password, std::string salt);
|
||||
bool CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString);
|
||||
QString GeneratePassword(size_t length = 16);
|
||||
}
|
||||
|
||||
namespace Platform {
|
||||
std::string GetLocalAddress();
|
||||
QString GetCommandLineArgument(QString arg);
|
||||
bool GetCommandLineFlagSet(QString arg);
|
||||
void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body);
|
||||
}
|
||||
|
||||
namespace Obs {
|
||||
namespace StringHelper {
|
||||
std::string GetObsVersionString();
|
||||
std::string GetCurrentSceneCollection();
|
||||
std::string GetCurrentProfile();
|
||||
std::string GetCurrentProfilePath();
|
||||
std::string GetSourceTypeString(obs_source_t *source);
|
||||
std::string GetInputMonitorTypeString(obs_source_t *input);
|
||||
std::string GetMediaInputStateString(obs_source_t *input);
|
||||
std::string GetLastReplayBufferFilePath();
|
||||
std::string GetOutputTimecodeString(obs_output_t *output);
|
||||
}
|
||||
|
||||
namespace NumberHelper {
|
||||
uint64_t GetOutputDuration(obs_output_t *output);
|
||||
}
|
||||
|
||||
namespace ListHelper {
|
||||
std::vector<std::string> GetSceneCollectionList();
|
||||
std::vector<std::string> GetProfileList();
|
||||
std::vector<obs_hotkey_t *> GetHotkeyList();
|
||||
std::vector<std::string> GetHotkeyNameList();
|
||||
std::vector<json> GetSceneList();
|
||||
std::vector<json> GetSceneItemList(obs_scene_t *scene, bool basic = false);
|
||||
std::vector<json> GetTransitionList();
|
||||
std::vector<json> GetInputList(std::string inputKind = "");
|
||||
std::vector<std::string> GetInputKindList(bool unversioned = false, bool includeDisabled = false);
|
||||
}
|
||||
|
||||
namespace SearchHelper {
|
||||
obs_hotkey_t *GetHotkeyByName(std::string name);
|
||||
}
|
||||
|
||||
namespace ActionHelper {
|
||||
obs_sceneitem_t *CreateSceneItem(obs_source_t *input, obs_scene_t *scene, bool sceneItemEnabled = true);
|
||||
obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "Crypto.h"
|
||||
#include "Json.h"
|
||||
#include "Obs.h"
|
||||
#include "Platform.h"
|
||||
|
Loading…
Reference in New Issue
Block a user