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

OnWsClose を自分自身の時にも発火するようにする #133

Merged
merged 2 commits into from
Oct 3, 2024
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/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
17 changes: 15 additions & 2 deletions src/sora_signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ void SoraSignaling::Redirect(std::string url) {
return;
}

// Disconnect と重複しないように Redirecting の場合のみ発火させる
self->SendSelfOnWsClose(ec);

// close 処理に成功してても失敗してても処理は続ける
if (ec) {
RTC_LOG(LS_WARNING) << "Redirect error: ec=" << ec.message();
Expand Down Expand Up @@ -1143,8 +1146,11 @@ void SoraSignaling::OnRead(boost::system::error_code ec,
auto it = m.as_object().find("ignore_disconnect_websocket");
if (it != m.as_object().end() && it->value().as_bool() && ws_connected_) {
RTC_LOG(LS_INFO) << "Close WebSocket for DataChannel";
ws_->Close([self = shared_from_this()](boost::system::error_code) {},
config_.websocket_close_timeout);
ws_->Close(
[self = shared_from_this()](boost::system::error_code ec) {
self->SendSelfOnWsClose(ec);
},
config_.websocket_close_timeout);
ws_connected_ = false;

return;
Expand Down Expand Up @@ -1366,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