@@ -20,12 +20,12 @@ void PeerConnectionWrapper::CloseAll()
20
20
inst->doClose ();
21
21
}
22
22
23
- void PeerConnectionWrapper::ResetCallbacksAll ()
23
+ void PeerConnectionWrapper::CleanupAll ()
24
24
{
25
- PLOG_DEBUG << " ResetCallbacksAll () called" ;
25
+ PLOG_DEBUG << " CleanupAll () called" ;
26
26
auto copy (instances);
27
27
for (auto inst : copy)
28
- inst->doResetCallbacks ();
28
+ inst->doCleanup ();
29
29
}
30
30
31
31
Napi::Object PeerConnectionWrapper::Init (Napi::Env env, Napi::Object exports)
@@ -37,7 +37,6 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
37
37
" PeerConnection" ,
38
38
{
39
39
InstanceMethod (" close" , &PeerConnectionWrapper::close ),
40
- InstanceMethod (" destroy" , &PeerConnectionWrapper::destroy),
41
40
InstanceMethod (" setLocalDescription" , &PeerConnectionWrapper::setLocalDescription),
42
41
InstanceMethod (" setRemoteDescription" , &PeerConnectionWrapper::setRemoteDescription),
43
42
InstanceMethod (" localDescription" , &PeerConnectionWrapper::localDescription),
@@ -253,7 +252,8 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
253
252
PeerConnectionWrapper::~PeerConnectionWrapper ()
254
253
{
255
254
PLOG_DEBUG << " Destructor called" ;
256
- doDestroy ();
255
+ doCleanup ();
256
+ doClose ();
257
257
}
258
258
259
259
void PeerConnectionWrapper::doClose ()
@@ -273,40 +273,27 @@ void PeerConnectionWrapper::doClose()
273
273
return ;
274
274
}
275
275
}
276
- }
277
-
278
- void PeerConnectionWrapper::close (const Napi::CallbackInfo &info)
279
- {
280
- PLOG_DEBUG << " close() called" ;
281
- doClose ();
282
- }
283
-
284
- void PeerConnectionWrapper::doDestroy ()
285
- {
286
- PLOG_DEBUG << " doDestroy() called" ;
287
- doClose ();
288
- doResetCallbacks ();
289
- }
290
276
291
- void PeerConnectionWrapper::doResetCallbacks ()
292
- {
293
- PLOG_DEBUG << " doResetCallbacks() called" ;
294
277
mOnLocalDescriptionCallback .reset ();
295
278
mOnLocalCandidateCallback .reset ();
296
- mOnStateChangeCallback .reset ();
297
279
mOnIceStateChangeCallback .reset ();
298
280
mOnSignalingStateChangeCallback .reset ();
299
281
mOnGatheringStateChangeCallback .reset ();
300
282
mOnDataChannelCallback .reset ();
301
283
mOnTrackCallback .reset ();
284
+ }
302
285
303
- instances.erase (this );
286
+ void PeerConnectionWrapper::close (const Napi::CallbackInfo &info)
287
+ {
288
+ PLOG_DEBUG << " close() called" ;
289
+ doClose ();
304
290
}
305
291
306
- void PeerConnectionWrapper::destroy ( const Napi::CallbackInfo &info )
292
+ void PeerConnectionWrapper::doCleanup ( )
307
293
{
308
- PLOG_DEBUG << " destroy() called" ;
309
- doDestroy ();
294
+ PLOG_DEBUG << " doCleanup() called" ;
295
+ mOnStateChangeCallback .reset ();
296
+ instances.erase (this );
310
297
}
311
298
312
299
void PeerConnectionWrapper::setLocalDescription (const Napi::CallbackInfo &info)
@@ -738,6 +725,13 @@ void PeerConnectionWrapper::onStateChange(const Napi::CallbackInfo &info)
738
725
stream << state;
739
726
args = {Napi::String::New (env, stream.str ())};
740
727
PLOG_DEBUG << " mOnStateChangeCallback call(2)" ;
728
+ },[this ,state](){
729
+ PLOG_DEBUG << " mOnStateChangeCallback cleanup" ;
730
+ // Special case for closed state, we need to reset all callbacks
731
+ if (state == rtc::PeerConnection::State::Closed)
732
+ {
733
+ doCleanup ();
734
+ }
741
735
}); });
742
736
}
743
737
0 commit comments