From 1b9412e6b49b07c0636cff80384f67421c9f2ed2 Mon Sep 17 00:00:00 2001 From: tnoho Date: Thu, 26 Sep 2024 00:41:01 +0900 Subject: [PATCH 1/3] =?UTF-8?q?OnWSClose=20=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sora/sora_signaling.h | 2 ++ src/sora_signaling.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/sora/sora_signaling.h b/include/sora/sora_signaling.h index 514a6996..192a395f 100644 --- a/include/sora/sora_signaling.h +++ b/include/sora/sora_signaling.h @@ -62,6 +62,7 @@ class SoraSignalingObserver { virtual void OnSignalingMessage(SoraSignalingType type, SoraSignalingDirection direction, std::string message) {} + virtual void OnWsClose(uint16_t code, std::string message) {} virtual void OnTrack( rtc::scoped_refptr transceiver) = 0; @@ -226,6 +227,7 @@ class SoraSignaling : public std::enable_shared_from_this, void SendOnSignalingMessage(SoraSignalingType type, SoraSignalingDirection direction, std::string message); + void SendOnWsClose(boost::beast::websocket::close_reason& reason); webrtc::DataBuffer ConvertToDataBuffer(const std::string& label, const std::string& input); diff --git a/src/sora_signaling.cpp b/src/sora_signaling.cpp index 2a4335ef..ca0cd4c9 100644 --- a/src/sora_signaling.cpp +++ b/src/sora_signaling.cpp @@ -591,6 +591,7 @@ void SoraSignaling::DoInternalDisconnect( boost::system::error_code tec; self->closing_timeout_timer_.cancel(tec); auto ws_reason = self->ws_->reason(); + self->SendOnWsClose(ws_reason); std::string message = "Unintended disconnect WebSocket during Disconnect process: ec=" + ec.message() + " wscode=" + std::to_string(ws_reason.code) + @@ -624,6 +625,7 @@ void SoraSignaling::DoInternalDisconnect( boost::system::error_code tec; self->closing_timeout_timer_.cancel(tec); auto ws_reason = self->ws_->reason(); + self->SendOnWsClose(ws_reason); std::string ws_reason_str = " wscode=" + std::to_string(ws_reason.code) + " wsreason=" + ws_reason.reason.c_str(); @@ -705,6 +707,7 @@ void SoraSignaling::DoInternalDisconnect( bool ec_error = ec != boost::beast::websocket::error::closed; if (ec_error) { auto reason = self->ws_->reason(); + self->SendOnWsClose(reason); on_close(false, SoraSignalingErrorCode::CLOSE_FAILED, "Failed to close WebSocket: ec=" + ec.message() + " wscode=" + std::to_string(reason.code) + @@ -816,6 +819,7 @@ void SoraSignaling::OnRead(boost::system::error_code ec, ? SoraSignalingErrorCode::WEBSOCKET_ONCLOSE : SoraSignalingErrorCode::WEBSOCKET_ONERROR; auto reason = ws_->reason(); + SendOnWsClose(reason); std::string reason_str = " wscode=" + std::to_string(reason.code) + " wsreason=" + reason.reason.c_str(); SendOnDisconnect(error_code, "Failed to read WebSocket: ec=" + @@ -1355,6 +1359,13 @@ void SoraSignaling::SendOnSignalingMessage(SoraSignalingType type, } } +void SoraSignaling::SendOnWsClose( + boost::beast::websocket::close_reason& reason) { + if (auto ob = config_.observer.lock(); ob) { + ob->OnWsClose(reason.code, std::string(reason.reason.c_str())); + } +} + webrtc::DataBuffer SoraSignaling::ConvertToDataBuffer( const std::string& label, const std::string& input) { From cbbd0d86ded65dd338f1731ceced9701c9b732f4 Mon Sep 17 00:00:00 2001 From: tnoho Date: Thu, 26 Sep 2024 00:43:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?CHANGES=20=E3=82=92=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c7dec0e4..89dca97e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,6 +34,8 @@ - @melpon - [ADD] VERSION と examples/VERSION のバージョンをチェックする仕組みを追加 - @melpon +- [ADD] WebSocket の Close を取得できるよう SendOnWsClose を SoraSignalingObserver に追加する + - @tnoho - [FIX] HTTP Proxy 利用時の Websocket 初期化で insecure_ メンバ変数が初期化されていなかったのを修正 - @melpon From 081cece704081e314127f964c8f01338cc098db3 Mon Sep 17 00:00:00 2001 From: tnoho Date: Fri, 27 Sep 2024 18:59:59 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sora/sora_signaling.h | 2 +- src/sora_signaling.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sora/sora_signaling.h b/include/sora/sora_signaling.h index 192a395f..0afc7506 100644 --- a/include/sora/sora_signaling.h +++ b/include/sora/sora_signaling.h @@ -227,7 +227,7 @@ class SoraSignaling : public std::enable_shared_from_this, void SendOnSignalingMessage(SoraSignalingType type, SoraSignalingDirection direction, std::string message); - void SendOnWsClose(boost::beast::websocket::close_reason& reason); + void SendOnWsClose(const boost::beast::websocket::close_reason& reason); webrtc::DataBuffer ConvertToDataBuffer(const std::string& label, const std::string& input); diff --git a/src/sora_signaling.cpp b/src/sora_signaling.cpp index ca0cd4c9..398fa0fd 100644 --- a/src/sora_signaling.cpp +++ b/src/sora_signaling.cpp @@ -704,10 +704,10 @@ void SoraSignaling::DoInternalDisconnect( self->on_ws_close_ = [self, on_close](boost::system::error_code ec) { boost::system::error_code tec; self->closing_timeout_timer_.cancel(tec); + auto reason = self->ws_->reason(); + self->SendOnWsClose(reason); bool ec_error = ec != boost::beast::websocket::error::closed; if (ec_error) { - auto reason = self->ws_->reason(); - self->SendOnWsClose(reason); on_close(false, SoraSignalingErrorCode::CLOSE_FAILED, "Failed to close WebSocket: ec=" + ec.message() + " wscode=" + std::to_string(reason.code) + @@ -1360,9 +1360,9 @@ void SoraSignaling::SendOnSignalingMessage(SoraSignalingType type, } void SoraSignaling::SendOnWsClose( - boost::beast::websocket::close_reason& reason) { + const boost::beast::websocket::close_reason& reason) { if (auto ob = config_.observer.lock(); ob) { - ob->OnWsClose(reason.code, std::string(reason.reason.c_str())); + ob->OnWsClose(reason.code, reason.reason.c_str()); } }