1919#include " nodeobs_autoconfig.hpp"
2020#include " shared.hpp"
2121
22+ #include < unordered_set>
23+
2224bool autoConfig::isWorkerRunning = false ;
2325bool autoConfig::worker_stop = true ;
2426uint32_t autoConfig::sleepIntervalMS = 33 ;
2527Napi::ThreadSafeFunction autoConfig::js_thread;
2628std::thread *autoConfig::worker_thread = nullptr ;
2729std::vector<std::thread *> autoConfig::ac_queue_task_workers;
30+ std::string bind_ip = " default" ;
2831
2932#ifdef WIN32
3033const char *ac_sem_name = nullptr ; // Not used on Windows
@@ -106,6 +109,7 @@ Napi::Value autoConfig::InitializeAutoConfig(const Napi::CallbackInfo &info)
106109 Napi::Object serverInfo = info[1 ].ToObject ();
107110 std::string continent = serverInfo.Get (" continent" ).ToString ().Utf8Value ();
108111 std::string service = serverInfo.Get (" service_name" ).ToString ().Utf8Value ();
112+ bind_ip = serverInfo.Get (" bind_ip" ).ToString ().Utf8Value ();
109113
110114 auto conn = GetConnection (info);
111115 if (!conn)
@@ -130,7 +134,7 @@ Napi::Value autoConfig::StartBandwidthTest(const Napi::CallbackInfo &info)
130134 if (!conn)
131135 return info.Env ().Undefined ();
132136
133- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartBandwidthTest" , {});
137+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartBandwidthTest" , {ipc::value (bind_ip) });
134138 if (!ValidateResponse (info, response))
135139 return info.Env ().Undefined ();
136140
@@ -225,43 +229,74 @@ Napi::Value autoConfig::StartCheckSettings(const Napi::CallbackInfo &info)
225229 return info.Env ().Undefined ();
226230}
227231
228- Napi::Value autoConfig::StartSetDefaultSettings (const Napi::CallbackInfo &info)
232+ Napi::Value autoConfig::UseAutoConfigDefaultSettings (const Napi::CallbackInfo &info)
229233{
230234 auto conn = GetConnection (info);
231235 if (!conn)
232236 return info.Env ().Undefined ();
233237
234- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSetDefaultSettings " , {});
238+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " UseAutoConfigDefaultSettings " , {});
235239 if (!ValidateResponse (info, response))
236240 return info.Env ().Undefined ();
237241
238242 return info.Env ().Undefined ();
239243}
240244
241- Napi::Value autoConfig::StartSaveStreamSettings (const Napi::CallbackInfo &info)
242- {
243- auto conn = GetConnection (info);
244- if (!conn)
245- return info.Env ().Undefined ();
245+ namespace {
246246
247- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSaveStreamSettings" , {});
248- if (!ValidateResponse (info, response))
249- return info.Env ().Undefined ();
250-
251- return info.Env ().Undefined ();
247+ Napi::Value napiValueFromIpcValue (const Napi::Env &env, const ipc::value &v)
248+ {
249+ switch (v.type ) {
250+ case ipc::type::Null:
251+ return env.Null ();
252+ case ipc::type::Float:
253+ return Napi::Number::New (env, v.value_union .fp32 );
254+ case ipc::type::Double:
255+ return Napi::Number::New (env, v.value_union .fp64 );
256+ case ipc::type::Int32:
257+ return Napi::Number::New (env, v.value_union .i32 );
258+ case ipc::type::Int64:
259+ return Napi::Number::New (env, v.value_union .i64 );
260+ case ipc::type::UInt32:
261+ return Napi::Number::New (env, v.value_union .ui32 );
262+ case ipc::type::UInt64:
263+ return Napi::Number::New (env, v.value_union .ui64 );
264+ case ipc::type::String:
265+ return Napi::String::New (env, v.value_str );
266+ case ipc::type::Binary: {
267+ auto res = Napi::ArrayBuffer::New (env, v.value_bin .size ());
268+ for (std::size_t i = 0 ; i < v.value_bin .size (); ++i) {
269+ res.Set (i, v.value_bin [i]);
270+ }
271+ return res;
272+ }
273+ }
252274}
253275
254- Napi::Value autoConfig::StartSaveSettings (const Napi::CallbackInfo &info)
276+ } // namespace
277+
278+ Napi::Value autoConfig::GetNewSettings (const Napi::CallbackInfo &info)
255279{
256280 auto conn = GetConnection (info);
257281 if (!conn)
258282 return info.Env ().Undefined ();
259283
260- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSaveSettings " , {});
284+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " GetNewSettings " , {});
261285 if (!ValidateResponse (info, response))
262286 return info.Env ().Undefined ();
263287
264- return info.Env ().Undefined ();
288+ std::size_t counter = 0 ;
289+ auto result = Napi::Array::New (info.Env ());
290+ for (std::size_t i = 1 ; i < response.size (); i += 3 , counter++) {
291+ auto settingsTuple = Napi::Array::New (info.Env ());
292+ settingsTuple.Set (uint32_t (0 ), Napi::String::New (info.Env (), response[i].value_str ));
293+ settingsTuple.Set (uint32_t (1 ), Napi::String::New (info.Env (), response[i + 1 ].value_str ));
294+ settingsTuple.Set (uint32_t (2 ), napiValueFromIpcValue (info.Env (), response[i + 2 ]));
295+
296+ result.Set (counter, settingsTuple);
297+ }
298+
299+ return result;
265300}
266301
267302Napi::Value autoConfig::TerminateAutoConfig (const Napi::CallbackInfo &info)
@@ -288,8 +323,7 @@ void autoConfig::Init(Napi::Env env, Napi::Object exports)
288323 exports.Set (Napi::String::New (env, " StartStreamEncoderTest" ), Napi::Function::New (env, autoConfig::StartStreamEncoderTest));
289324 exports.Set (Napi::String::New (env, " StartRecordingEncoderTest" ), Napi::Function::New (env, autoConfig::StartRecordingEncoderTest));
290325 exports.Set (Napi::String::New (env, " StartCheckSettings" ), Napi::Function::New (env, autoConfig::StartCheckSettings));
291- exports.Set (Napi::String::New (env, " StartSetDefaultSettings" ), Napi::Function::New (env, autoConfig::StartSetDefaultSettings));
292- exports.Set (Napi::String::New (env, " StartSaveStreamSettings" ), Napi::Function::New (env, autoConfig::StartSaveStreamSettings));
293- exports.Set (Napi::String::New (env, " StartSaveSettings" ), Napi::Function::New (env, autoConfig::StartSaveSettings));
326+ exports.Set (Napi::String::New (env, " UseAutoConfigDefaultSettings" ), Napi::Function::New (env, autoConfig::UseAutoConfigDefaultSettings));
327+ exports.Set (Napi::String::New (env, " GetNewSettings" ), Napi::Function::New (env, autoConfig::GetNewSettings));
294328 exports.Set (Napi::String::New (env, " TerminateAutoConfig" ), Napi::Function::New (env, autoConfig::TerminateAutoConfig));
295329}
0 commit comments