@@ -25,6 +25,7 @@ uint32_t autoConfig::sleepIntervalMS = 33;
2525Napi::ThreadSafeFunction autoConfig::js_thread;
2626std::thread *autoConfig::worker_thread = nullptr ;
2727std::vector<std::thread *> autoConfig::ac_queue_task_workers;
28+ std::string bind_ip = " default" ;
2829
2930#ifdef WIN32
3031const char *ac_sem_name = nullptr ; // Not used on Windows
@@ -106,6 +107,7 @@ Napi::Value autoConfig::InitializeAutoConfig(const Napi::CallbackInfo &info)
106107 Napi::Object serverInfo = info[1 ].ToObject ();
107108 std::string continent = serverInfo.Get (" continent" ).ToString ().Utf8Value ();
108109 std::string service = serverInfo.Get (" service_name" ).ToString ().Utf8Value ();
110+ bind_ip = serverInfo.Get (" bind_ip" ).ToString ().Utf8Value ();
109111
110112 auto conn = GetConnection (info);
111113 if (!conn)
@@ -130,7 +132,7 @@ Napi::Value autoConfig::StartBandwidthTest(const Napi::CallbackInfo &info)
130132 if (!conn)
131133 return info.Env ().Undefined ();
132134
133- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartBandwidthTest" , {});
135+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartBandwidthTest" , {ipc::value (bind_ip) });
134136 if (!ValidateResponse (info, response))
135137 return info.Env ().Undefined ();
136138
@@ -225,43 +227,74 @@ Napi::Value autoConfig::StartCheckSettings(const Napi::CallbackInfo &info)
225227 return info.Env ().Undefined ();
226228}
227229
228- Napi::Value autoConfig::StartSetDefaultSettings (const Napi::CallbackInfo &info)
230+ Napi::Value autoConfig::UseAutoConfigDefaultSettings (const Napi::CallbackInfo &info)
229231{
230232 auto conn = GetConnection (info);
231233 if (!conn)
232234 return info.Env ().Undefined ();
233235
234- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSetDefaultSettings " , {});
236+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " UseAutoConfigDefaultSettings " , {});
235237 if (!ValidateResponse (info, response))
236238 return info.Env ().Undefined ();
237239
238240 return info.Env ().Undefined ();
239241}
240242
241- Napi::Value autoConfig::StartSaveStreamSettings (const Napi::CallbackInfo &info)
242- {
243- auto conn = GetConnection (info);
244- if (!conn)
245- return info.Env ().Undefined ();
243+ namespace {
246244
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 ();
245+ Napi::Value napiValueFromIpcValue (const Napi::Env &env, const ipc::value &v)
246+ {
247+ switch (v.type ) {
248+ case ipc::type::Null:
249+ return env.Null ();
250+ case ipc::type::Float:
251+ return Napi::Number::New (env, v.value_union .fp32 );
252+ case ipc::type::Double:
253+ return Napi::Number::New (env, v.value_union .fp64 );
254+ case ipc::type::Int32:
255+ return Napi::Number::New (env, v.value_union .i32 );
256+ case ipc::type::Int64:
257+ return Napi::Number::New (env, v.value_union .i64 );
258+ case ipc::type::UInt32:
259+ return Napi::Number::New (env, v.value_union .ui32 );
260+ case ipc::type::UInt64:
261+ return Napi::Number::New (env, v.value_union .ui64 );
262+ case ipc::type::String:
263+ return Napi::String::New (env, v.value_str );
264+ case ipc::type::Binary: {
265+ auto res = Napi::ArrayBuffer::New (env, v.value_bin .size ());
266+ for (std::size_t i = 0 ; i < v.value_bin .size (); ++i) {
267+ res.Set (i, v.value_bin [i]);
268+ }
269+ return res;
270+ }
271+ }
252272}
253273
254- Napi::Value autoConfig::StartSaveSettings (const Napi::CallbackInfo &info)
274+ } // namespace
275+
276+ Napi::Value autoConfig::GetNewSettings (const Napi::CallbackInfo &info)
255277{
256278 auto conn = GetConnection (info);
257279 if (!conn)
258280 return info.Env ().Undefined ();
259281
260- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSaveSettings " , {});
282+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " GetNewSettings " , {});
261283 if (!ValidateResponse (info, response))
262284 return info.Env ().Undefined ();
263285
264- return info.Env ().Undefined ();
286+ std::size_t counter = 0 ;
287+ auto result = Napi::Array::New (info.Env ());
288+ for (std::size_t i = 1 ; i < response.size (); i += 3 , counter++) {
289+ auto settingsTuple = Napi::Array::New (info.Env ());
290+ settingsTuple.Set (uint32_t (0 ), Napi::String::New (info.Env (), response[i].value_str ));
291+ settingsTuple.Set (uint32_t (1 ), Napi::String::New (info.Env (), response[i + 1 ].value_str ));
292+ settingsTuple.Set (uint32_t (2 ), napiValueFromIpcValue (info.Env (), response[i + 2 ]));
293+
294+ result.Set (counter, settingsTuple);
295+ }
296+
297+ return result;
265298}
266299
267300Napi::Value autoConfig::TerminateAutoConfig (const Napi::CallbackInfo &info)
@@ -288,8 +321,7 @@ void autoConfig::Init(Napi::Env env, Napi::Object exports)
288321 exports.Set (Napi::String::New (env, " StartStreamEncoderTest" ), Napi::Function::New (env, autoConfig::StartStreamEncoderTest));
289322 exports.Set (Napi::String::New (env, " StartRecordingEncoderTest" ), Napi::Function::New (env, autoConfig::StartRecordingEncoderTest));
290323 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));
324+ exports.Set (Napi::String::New (env, " UseAutoConfigDefaultSettings" ), Napi::Function::New (env, autoConfig::UseAutoConfigDefaultSettings));
325+ exports.Set (Napi::String::New (env, " GetNewSettings" ), Napi::Function::New (env, autoConfig::GetNewSettings));
294326 exports.Set (Napi::String::New (env, " TerminateAutoConfig" ), Napi::Function::New (env, autoConfig::TerminateAutoConfig));
295327}
0 commit comments