From 7cf0647049a03e2cfe22f138eaad943e1a880bba Mon Sep 17 00:00:00 2001 From: tnoho Date: Sun, 29 Sep 2024 12:09:09 +0900 Subject: [PATCH] =?UTF-8?q?reason=20=E3=81=AE=E6=89=B1=E3=81=84=E3=82=92?= =?UTF-8?q?=E5=A4=89=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sora/sora_signaling.h | 1 + src/sora_signaling.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/sora/sora_signaling.h b/include/sora/sora_signaling.h index 2ef1226..970859b 100644 --- a/include/sora/sora_signaling.h +++ b/include/sora/sora_signaling.h @@ -228,6 +228,7 @@ class SoraSignaling : public std::enable_shared_from_this, SoraSignalingDirection direction, std::string message); void SendOnWsClose(const boost::beast::websocket::close_reason& reason); + void SendSelfOnWsClose(boost::system::error_code ec); webrtc::DataBuffer ConvertToDataBuffer(const std::string& label, const std::string& input); diff --git a/src/sora_signaling.cpp b/src/sora_signaling.cpp index 796df98..df82ed4 100644 --- a/src/sora_signaling.cpp +++ b/src/sora_signaling.cpp @@ -134,15 +134,13 @@ void SoraSignaling::Redirect(std::string url) { } auto on_close = [self, url](boost::system::error_code ec) { - if (!ec) { - self->SendOnWsClose(boost::beast::websocket::close_reason( - boost::beast::websocket::close_code::normal)); - } - if (self->state_ != State::Redirecting) { return; } + // Disconnect と重複しないように Redirecting の場合のみ発火させる + self->SendSelfOnWsClose(ec); + // close 処理に成功してても失敗してても処理は続ける if (ec) { RTC_LOG(LS_WARNING) << "Redirect error: ec=" << ec.message(); @@ -1150,10 +1148,7 @@ void SoraSignaling::OnRead(boost::system::error_code ec, RTC_LOG(LS_INFO) << "Close WebSocket for DataChannel"; ws_->Close( [self = shared_from_this()](boost::system::error_code ec) { - if (!ec) { - self->SendOnWsClose(boost::beast::websocket::close_reason( - boost::beast::websocket::close_code::normal)); - } + self->SendSelfOnWsClose(ec); }, config_.websocket_close_timeout); ws_connected_ = false; @@ -1377,6 +1372,13 @@ void SoraSignaling::SendOnWsClose( } } +void SoraSignaling::SendSelfOnWsClose(boost::system::error_code ec) { + auto close_reason = boost::beast::websocket::close_reason( + ec ? 4999 : boost::beast::websocket::close_code::normal); + close_reason.reason = "SELF-CLOSED"; + SendOnWsClose(close_reason); +} + webrtc::DataBuffer SoraSignaling::ConvertToDataBuffer( const std::string& label, const std::string& input) {