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 を SoraSignalingObserver に追加する #130

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
- @melpon
- [ADD] VERSION と examples/VERSION のバージョンをチェックする仕組みを追加
- @melpon
- [ADD] WebSocket の Close を取得できるよう SendOnWsClose を SoraSignalingObserver に追加する
- @tnoho
- [FIX] HTTP Proxy 利用時の Websocket 初期化で insecure_ メンバ変数が初期化されていなかったのを修正
- @melpon

Expand Down
2 changes: 2 additions & 0 deletions include/sora/sora_signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<webrtc::RtpTransceiverInterface> transceiver) = 0;
Expand Down Expand Up @@ -226,6 +227,7 @@ class SoraSignaling : public std::enable_shared_from_this<SoraSignaling>,
void SendOnSignalingMessage(SoraSignalingType type,
SoraSignalingDirection direction,
std::string message);
void SendOnWsClose(boost::beast::websocket::close_reason& reason);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

パラメータに const あった方が良さそう


webrtc::DataBuffer ConvertToDataBuffer(const std::string& label,
const std::string& input);
Expand Down
11 changes: 11 additions & 0 deletions src/sora_signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここだと非エラーの時に SendOnWsClose が呼ばれなさそうな気がします

on_close(false, SoraSignalingErrorCode::CLOSE_FAILED,
"Failed to close WebSocket: ec=" + ec.message() +
" wscode=" + std::to_string(reason.code) +
Expand Down Expand Up @@ -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=" +
Expand Down Expand Up @@ -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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string で囲む必要は無さそう

}
}

webrtc::DataBuffer SoraSignaling::ConvertToDataBuffer(
const std::string& label,
const std::string& input) {
Expand Down