diff --git a/src/impl/peerconnection.cpp b/src/impl/peerconnection.cpp index 6b017d5e5..0cd81a828 100644 --- a/src/impl/peerconnection.cpp +++ b/src/impl/peerconnection.cpp @@ -1126,12 +1126,13 @@ bool PeerConnection::changeState(State newState) { s << newState; PLOG_INFO << "Changed state to " << s.str(); - if (newState == State::Closed) - stateChangeCallback(State::Closed); // synchronous - else + if (newState == State::Closed) { + auto callback = std::move(stateChangeCallback); // steal the callback + callback(State::Closed); // call it synchronously + } else { mProcessor.enqueue(&PeerConnection::trigger, shared_from_this(), stateChangeCallback, newState); - + } return true; }