Skip to content

Commit

Permalink
reason の扱いを変える
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoho committed Sep 29, 2024
1 parent cfb0be7 commit 7cf0647
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/sora/sora_signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class SoraSignaling : public std::enable_shared_from_this<SoraSignaling>,
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);
Expand Down
20 changes: 11 additions & 9 deletions src/sora_signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7cf0647

Please sign in to comment.