From d98fd8f179a207cc588981b18d71ac7c6d047e10 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Wed, 7 May 2025 14:31:19 -0700 Subject: [PATCH] Suppress hide/show_self until after fully connected. --- src/reporting/FreeDVReporter.cpp | 24 ++++++++++++++++++++++-- src/reporting/FreeDVReporter.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/reporting/FreeDVReporter.cpp b/src/reporting/FreeDVReporter.cpp index 66c635c5..ca2cdbcb 100644 --- a/src/reporting/FreeDVReporter.cpp +++ b/src/reporting/FreeDVReporter.cpp @@ -37,6 +37,7 @@ FreeDVReporter::FreeDVReporter(std::string hostname, std::string callsign, std:: , tx_(false) , rxOnly_(rxOnly) , hidden_(false) + , fullyConnected_(false) { if (hostname_ == "") { @@ -257,10 +258,12 @@ void FreeDVReporter::connect_() sioClient_->setOnConnectFn([&]() { isConnecting_ = false; + fullyConnected_ = false; }); sioClient_->setOnDisconnectFn([&]() { isConnecting_ = false; + fullyConnected_ = false; if (onReporterDisconnectFn_) { @@ -322,6 +325,8 @@ void FreeDVReporter::connect_() }); sioClient_->on("connection_successful", [&](nlohmann::json) { + fullyConnected_ = true; + if (onConnectionSuccessfulFn_) { onConnectionSuccessfulFn_(); @@ -590,7 +595,14 @@ void FreeDVReporter::sendMessageImpl_(std::string message) void FreeDVReporter::hideFromViewImpl_() { - sioClient_->emit("hide_self"); + // The FreeDV Reporter connection isn't actually valid until we get + // the "connection successful" message. Thus, we defer sending hide_self + // until we get that message, but we record what state we should be + // in the meantime. + if (fullyConnected_) + { + sioClient_->emit("hide_self"); + } hidden_ = true; } @@ -601,6 +613,14 @@ void FreeDVReporter::showOurselvesImpl_() onAboutToShowSelfFn_(); } - sioClient_->emit("show_self"); + // The FreeDV Reporter connection isn't actually valid until we get + // the "connection successful" message. Thus, we defer sending show_self + // until we get that message, but we record what state we should be + // in the meantime. + if (fullyConnected_) + { + sioClient_->emit("show_self"); + } + hidden_ = false; } diff --git a/src/reporting/FreeDVReporter.h b/src/reporting/FreeDVReporter.h index 32672bd9..9520bd6e 100644 --- a/src/reporting/FreeDVReporter.h +++ b/src/reporting/FreeDVReporter.h @@ -122,6 +122,7 @@ private: bool rxOnly_; bool hidden_; std::string message_; + bool fullyConnected_; ReporterConnectionFn onReporterConnectFn_; ReporterConnectionFn onReporterDisconnectFn_;