@@ -25,6 +25,7 @@ uint32_t autoConfig::sleepIntervalMS = 33;
25
25
Napi::ThreadSafeFunction autoConfig::js_thread;
26
26
std::thread *autoConfig::worker_thread = nullptr ;
27
27
std::vector<std::thread *> autoConfig::ac_queue_task_workers;
28
+ std::string bind_ip = " default" ;
28
29
29
30
#ifdef WIN32
30
31
const char *ac_sem_name = nullptr ; // Not used on Windows
@@ -106,6 +107,7 @@ Napi::Value autoConfig::InitializeAutoConfig(const Napi::CallbackInfo &info)
106
107
Napi::Object serverInfo = info[1 ].ToObject ();
107
108
std::string continent = serverInfo.Get (" continent" ).ToString ().Utf8Value ();
108
109
std::string service = serverInfo.Get (" service_name" ).ToString ().Utf8Value ();
110
+ bind_ip = serverInfo.Get (" bind_ip" ).ToString ().Utf8Value ();
109
111
110
112
auto conn = GetConnection (info);
111
113
if (!conn)
@@ -130,7 +132,7 @@ Napi::Value autoConfig::StartBandwidthTest(const Napi::CallbackInfo &info)
130
132
if (!conn)
131
133
return info.Env ().Undefined ();
132
134
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) });
134
136
if (!ValidateResponse (info, response))
135
137
return info.Env ().Undefined ();
136
138
@@ -225,43 +227,74 @@ Napi::Value autoConfig::StartCheckSettings(const Napi::CallbackInfo &info)
225
227
return info.Env ().Undefined ();
226
228
}
227
229
228
- Napi::Value autoConfig::StartSetDefaultSettings (const Napi::CallbackInfo &info)
230
+ Napi::Value autoConfig::UseAutoConfigDefaultSettings (const Napi::CallbackInfo &info)
229
231
{
230
232
auto conn = GetConnection (info);
231
233
if (!conn)
232
234
return info.Env ().Undefined ();
233
235
234
- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSetDefaultSettings " , {});
236
+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " UseAutoConfigDefaultSettings " , {});
235
237
if (!ValidateResponse (info, response))
236
238
return info.Env ().Undefined ();
237
239
238
240
return info.Env ().Undefined ();
239
241
}
240
242
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 {
246
244
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
+ }
252
272
}
253
273
254
- Napi::Value autoConfig::StartSaveSettings (const Napi::CallbackInfo &info)
274
+ } // namespace
275
+
276
+ Napi::Value autoConfig::GetNewSettings (const Napi::CallbackInfo &info)
255
277
{
256
278
auto conn = GetConnection (info);
257
279
if (!conn)
258
280
return info.Env ().Undefined ();
259
281
260
- std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " StartSaveSettings " , {});
282
+ std::vector<ipc::value> response = conn->call_synchronous_helper (" AutoConfig" , " GetNewSettings " , {});
261
283
if (!ValidateResponse (info, response))
262
284
return info.Env ().Undefined ();
263
285
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;
265
298
}
266
299
267
300
Napi::Value autoConfig::TerminateAutoConfig (const Napi::CallbackInfo &info)
@@ -288,8 +321,7 @@ void autoConfig::Init(Napi::Env env, Napi::Object exports)
288
321
exports.Set (Napi::String::New (env, " StartStreamEncoderTest" ), Napi::Function::New (env, autoConfig::StartStreamEncoderTest));
289
322
exports.Set (Napi::String::New (env, " StartRecordingEncoderTest" ), Napi::Function::New (env, autoConfig::StartRecordingEncoderTest));
290
323
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));
294
326
exports.Set (Napi::String::New (env, " TerminateAutoConfig" ), Napi::Function::New (env, autoConfig::TerminateAutoConfig));
295
327
}
0 commit comments