From 1b9412e6b49b07c0636cff80384f67421c9f2ed2 Mon Sep 17 00:00:00 2001 From: tnoho Date: Thu, 26 Sep 2024 00:41:01 +0900 Subject: [PATCH] =?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) {