Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New settings API for autoconfig #1348

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 51 additions & 19 deletions obs-studio-client/source/nodeobs_autoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uint32_t autoConfig::sleepIntervalMS = 33;
Napi::ThreadSafeFunction autoConfig::js_thread;
std::thread *autoConfig::worker_thread = nullptr;
std::vector<std::thread *> autoConfig::ac_queue_task_workers;
std::string bind_ip = "default";

#ifdef WIN32
const char *ac_sem_name = nullptr; // Not used on Windows
Expand Down Expand Up @@ -106,6 +107,7 @@ Napi::Value autoConfig::InitializeAutoConfig(const Napi::CallbackInfo &info)
Napi::Object serverInfo = info[1].ToObject();
std::string continent = serverInfo.Get("continent").ToString().Utf8Value();
std::string service = serverInfo.Get("service_name").ToString().Utf8Value();
bind_ip = serverInfo.Get("bind_ip").ToString().Utf8Value();

auto conn = GetConnection(info);
if (!conn)
Expand All @@ -130,7 +132,7 @@ Napi::Value autoConfig::StartBandwidthTest(const Napi::CallbackInfo &info)
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartBandwidthTest", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartBandwidthTest", {ipc::value(bind_ip)});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

Expand Down Expand Up @@ -225,43 +227,74 @@ Napi::Value autoConfig::StartCheckSettings(const Napi::CallbackInfo &info)
return info.Env().Undefined();
}

Napi::Value autoConfig::StartSetDefaultSettings(const Napi::CallbackInfo &info)
Napi::Value autoConfig::UseAutoConfigDefaultSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSetDefaultSettings", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "UseAutoConfigDefaultSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
}

Napi::Value autoConfig::StartSaveStreamSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();
namespace {

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSaveStreamSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
Napi::Value napiValueFromIpcValue(const Napi::Env &env, const ipc::value &v)
{
switch (v.type) {
case ipc::type::Null:
return env.Null();
case ipc::type::Float:
return Napi::Number::New(env, v.value_union.fp32);
case ipc::type::Double:
return Napi::Number::New(env, v.value_union.fp64);
case ipc::type::Int32:
return Napi::Number::New(env, v.value_union.i32);
case ipc::type::Int64:
return Napi::Number::New(env, v.value_union.i64);
case ipc::type::UInt32:
return Napi::Number::New(env, v.value_union.ui32);
case ipc::type::UInt64:
return Napi::Number::New(env, v.value_union.ui64);
case ipc::type::String:
return Napi::String::New(env, v.value_str);
case ipc::type::Binary: {
auto res = Napi::ArrayBuffer::New(env, v.value_bin.size());
for (std::size_t i = 0; i < v.value_bin.size(); ++i) {
res.Set(i, v.value_bin[i]);
}
return res;
}
}
}

Napi::Value autoConfig::StartSaveSettings(const Napi::CallbackInfo &info)
} // namespace

Napi::Value autoConfig::GetNewSettings(const Napi::CallbackInfo &info)
{
auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "StartSaveSettings", {});
std::vector<ipc::value> response = conn->call_synchronous_helper("AutoConfig", "GetNewSettings", {});
if (!ValidateResponse(info, response))
return info.Env().Undefined();

return info.Env().Undefined();
std::size_t counter = 0;
auto result = Napi::Array::New(info.Env());
for (std::size_t i = 1; i < response.size(); i += 3, counter++) {
auto settingsTuple = Napi::Array::New(info.Env());
settingsTuple.Set(uint32_t(0), Napi::String::New(info.Env(), response[i].value_str));
settingsTuple.Set(uint32_t(1), Napi::String::New(info.Env(), response[i + 1].value_str));
settingsTuple.Set(uint32_t(2), napiValueFromIpcValue(info.Env(), response[i + 2]));

result.Set(counter, settingsTuple);
}

return result;
}

Napi::Value autoConfig::TerminateAutoConfig(const Napi::CallbackInfo &info)
Expand All @@ -288,8 +321,7 @@ void autoConfig::Init(Napi::Env env, Napi::Object exports)
exports.Set(Napi::String::New(env, "StartStreamEncoderTest"), Napi::Function::New(env, autoConfig::StartStreamEncoderTest));
exports.Set(Napi::String::New(env, "StartRecordingEncoderTest"), Napi::Function::New(env, autoConfig::StartRecordingEncoderTest));
exports.Set(Napi::String::New(env, "StartCheckSettings"), Napi::Function::New(env, autoConfig::StartCheckSettings));
exports.Set(Napi::String::New(env, "StartSetDefaultSettings"), Napi::Function::New(env, autoConfig::StartSetDefaultSettings));
exports.Set(Napi::String::New(env, "StartSaveStreamSettings"), Napi::Function::New(env, autoConfig::StartSaveStreamSettings));
exports.Set(Napi::String::New(env, "StartSaveSettings"), Napi::Function::New(env, autoConfig::StartSaveSettings));
exports.Set(Napi::String::New(env, "UseAutoConfigDefaultSettings"), Napi::Function::New(env, autoConfig::UseAutoConfigDefaultSettings));
exports.Set(Napi::String::New(env, "GetNewSettings"), Napi::Function::New(env, autoConfig::GetNewSettings));
exports.Set(Napi::String::New(env, "TerminateAutoConfig"), Napi::Function::New(env, autoConfig::TerminateAutoConfig));
}
5 changes: 2 additions & 3 deletions obs-studio-client/source/nodeobs_autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Napi::Value StartBandwidthTest(const Napi::CallbackInfo &info);
Napi::Value StartStreamEncoderTest(const Napi::CallbackInfo &info);
Napi::Value StartRecordingEncoderTest(const Napi::CallbackInfo &info);
Napi::Value StartCheckSettings(const Napi::CallbackInfo &info);
Napi::Value StartSetDefaultSettings(const Napi::CallbackInfo &info);
Napi::Value StartSaveStreamSettings(const Napi::CallbackInfo &info);
Napi::Value StartSaveSettings(const Napi::CallbackInfo &info);
Napi::Value UseAutoConfigDefaultSettings(const Napi::CallbackInfo &info);
Napi::Value GetNewSettings(const Napi::CallbackInfo &info);
Napi::Value TerminateAutoConfig(const Napi::CallbackInfo &info);
}
Loading
Loading