Skip to content

Commit

Permalink
OnWSClose を追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoho committed Sep 25, 2024
1 parent 20204cd commit 1b9412e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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);

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);
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()));
}
}

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

0 comments on commit 1b9412e

Please sign in to comment.