@@ -53,15 +53,15 @@ Napi::Value osn::Streaming::GetService(const Napi::CallbackInfo &info)
5353
5454void osn::Streaming::SetService (const Napi::CallbackInfo &info, const Napi::Value &value)
5555{
56- if (!serviceRef.IsEmpty ())
57- serviceRef.Reset ();
58-
5956 auto conn = GetConnection (info);
6057 if (!conn)
6158 return ;
6259
6360 if (value.IsNull () || value.IsUndefined ()) {
64- conn->call (className, " SetService" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
61+ if (!serviceRef.IsEmpty ())
62+ serviceRef.Reset ();
63+ auto response = conn->call_synchronous_helper (className, " SetService" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
64+ ValidateResponse (info, response);
6565 return ;
6666 }
6767
@@ -79,6 +79,8 @@ void osn::Streaming::SetService(const Napi::CallbackInfo &info, const Napi::Valu
7979 if (!ValidateResponse (info, response))
8080 return ;
8181
82+ if (!serviceRef.IsEmpty ())
83+ serviceRef.Reset ();
8284 serviceRef = Napi::Persistent (obj);
8385}
8486
@@ -122,14 +124,13 @@ Napi::Value osn::Streaming::GetVideoEncoder(const Napi::CallbackInfo &info)
122124
123125void osn::Streaming::SetVideoEncoder (const Napi::CallbackInfo &info, const Napi::Value &value)
124126{
125- if (!videoEncoderRef.IsEmpty ())
126- videoEncoderRef.Reset ();
127-
128127 auto conn = GetConnection (info);
129128 if (!conn)
130129 return ;
131130
132131 if (value.IsNull () || value.IsUndefined ()) {
132+ if (!videoEncoderRef.IsEmpty ())
133+ videoEncoderRef.Reset ();
133134 auto response = conn->call_synchronous_helper (className, " SetVideoEncoder" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
134135 ValidateResponse (info, response);
135136 return ;
@@ -150,6 +151,8 @@ void osn::Streaming::SetVideoEncoder(const Napi::CallbackInfo &info, const Napi:
150151 if (!ValidateResponse (info, response))
151152 return ;
152153
154+ if (!videoEncoderRef.IsEmpty ())
155+ videoEncoderRef.Reset ();
153156 videoEncoderRef = Napi::Persistent (obj);
154157}
155158
@@ -208,14 +211,13 @@ Napi::Value osn::Streaming::GetDelay(const Napi::CallbackInfo &info)
208211
209212void osn::Streaming::SetDelay (const Napi::CallbackInfo &info, const Napi::Value &value)
210213{
211- if (!delayRef.IsEmpty ())
212- delayRef.Reset ();
213-
214214 auto conn = GetConnection (info);
215215 if (!conn)
216216 return ;
217217
218218 if (value.IsNull () || value.IsUndefined ()) {
219+ if (!delayRef.IsEmpty ())
220+ delayRef.Reset ();
219221 auto response = conn->call_synchronous_helper (className, " SetDelay" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
220222 ValidateResponse (info, response);
221223 return ;
@@ -235,6 +237,8 @@ void osn::Streaming::SetDelay(const Napi::CallbackInfo &info, const Napi::Value
235237 if (!ValidateResponse (info, response))
236238 return ;
237239
240+ if (!delayRef.IsEmpty ())
241+ delayRef.Reset ();
238242 delayRef = Napi::Persistent (obj);
239243}
240244
@@ -245,14 +249,13 @@ Napi::Value osn::Streaming::GetReconnect(const Napi::CallbackInfo &info)
245249
246250void osn::Streaming::SetReconnect (const Napi::CallbackInfo &info, const Napi::Value &value)
247251{
248- if (!reconnectRef.IsEmpty ())
249- reconnectRef.Reset ();
250-
251252 auto conn = GetConnection (info);
252253 if (!conn)
253254 return ;
254255
255256 if (value.IsNull () || value.IsUndefined ()) {
257+ if (!reconnectRef.IsEmpty ())
258+ reconnectRef.Reset ();
256259 auto response = conn->call_synchronous_helper (className, " SetReconnect" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
257260 ValidateResponse (info, response);
258261 return ;
@@ -272,6 +275,8 @@ void osn::Streaming::SetReconnect(const Napi::CallbackInfo &info, const Napi::Va
272275 if (!ValidateResponse (info, response))
273276 return ;
274277
278+ if (!reconnectRef.IsEmpty ())
279+ reconnectRef.Reset ();
275280 reconnectRef = Napi::Persistent (obj);
276281}
277282
@@ -282,14 +287,13 @@ Napi::Value osn::Streaming::GetNetwork(const Napi::CallbackInfo &info)
282287
283288void osn::Streaming::SetNetwork (const Napi::CallbackInfo &info, const Napi::Value &value)
284289{
285- if (!networkRef.IsEmpty ())
286- networkRef.Reset ();
287-
288290 auto conn = GetConnection (info);
289291 if (!conn)
290292 return ;
291293
292294 if (value.IsNull () || value.IsUndefined ()) {
295+ if (!networkRef.IsEmpty ())
296+ networkRef.Reset ();
293297 auto response = conn->call_synchronous_helper (className, " SetNetwork" , {ipc::value (this ->uid ), ipc::value (UINT64_MAX)});
294298 ValidateResponse (info, response);
295299 return ;
@@ -309,6 +313,8 @@ void osn::Streaming::SetNetwork(const Napi::CallbackInfo &info, const Napi::Valu
309313 if (!ValidateResponse (info, response))
310314 return ;
311315
316+ if (!networkRef.IsEmpty ())
317+ networkRef.Reset ();
312318 networkRef = Napi::Persistent (obj);
313319}
314320
0 commit comments