Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing peer connection threads #121

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/Handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace mediasoupclient

/* Methods inherited from PeerConnectionListener. */
public:
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState newState) override;
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState) override;

protected:
Expand Down
7 changes: 4 additions & 3 deletions include/PeerConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace mediasoupclient
~PeerConnection() = default;

void Close();
void CloseThreads();
webrtc::PeerConnectionInterface::RTCConfiguration GetConfiguration() const;
bool SetConfiguration(const webrtc::PeerConnectionInterface::RTCConfiguration& config);
std::string CreateOffer(const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
Expand All @@ -135,9 +136,9 @@ namespace mediasoupclient

private:
// Signaling and worker threads.
std::unique_ptr<rtc::Thread> networkThread;
std::unique_ptr<rtc::Thread> signalingThread;
std::unique_ptr<rtc::Thread> workerThread;
std::unique_ptr<rtc::Thread> networkThread{ nullptr };
std::unique_ptr<rtc::Thread> signalingThread{ nullptr };
std::unique_ptr<rtc::Thread> workerThread{ nullptr };

// PeerConnection factory.
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peerConnectionFactory;
Expand Down
8 changes: 8 additions & 0 deletions src/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ namespace mediasoupclient
MSC_THROW_ERROR("failed to update ICE servers");
};

void Handler::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState newState)
{
MSC_TRACE();

if (newState == webrtc::PeerConnectionInterface::SignalingState::kClosed)
this->pc->CloseThreads();
}

void Handler::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState)
{
MSC_TRACE();
Expand Down
14 changes: 14 additions & 0 deletions src/PeerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ namespace mediasoupclient
this->pc->Close();
}

void PeerConnection::CloseThreads()
{
MSC_TRACE();

if (this->networkThread != nullptr)
this->networkThread->Quit();

if (this->signalingThread != nullptr)
this->signalingThread->Quit();

if (this->workerThread != nullptr)
this->workerThread->Quit();
}

webrtc::PeerConnectionInterface::RTCConfiguration PeerConnection::GetConfiguration() const
{
MSC_TRACE();
Expand Down