Suppress hide/show_self until after fully connected.

ms-reporter-startup-crash
Mooneer Salem 2025-05-07 14:31:19 -07:00
parent 099a010a6e
commit d98fd8f179
2 changed files with 23 additions and 2 deletions

View File

@ -37,6 +37,7 @@ FreeDVReporter::FreeDVReporter(std::string hostname, std::string callsign, std::
, tx_(false) , tx_(false)
, rxOnly_(rxOnly) , rxOnly_(rxOnly)
, hidden_(false) , hidden_(false)
, fullyConnected_(false)
{ {
if (hostname_ == "") if (hostname_ == "")
{ {
@ -257,10 +258,12 @@ void FreeDVReporter::connect_()
sioClient_->setOnConnectFn([&]() sioClient_->setOnConnectFn([&]()
{ {
isConnecting_ = false; isConnecting_ = false;
fullyConnected_ = false;
}); });
sioClient_->setOnDisconnectFn([&]() { sioClient_->setOnDisconnectFn([&]() {
isConnecting_ = false; isConnecting_ = false;
fullyConnected_ = false;
if (onReporterDisconnectFn_) if (onReporterDisconnectFn_)
{ {
@ -322,6 +325,8 @@ void FreeDVReporter::connect_()
}); });
sioClient_->on("connection_successful", [&](nlohmann::json) { sioClient_->on("connection_successful", [&](nlohmann::json) {
fullyConnected_ = true;
if (onConnectionSuccessfulFn_) if (onConnectionSuccessfulFn_)
{ {
onConnectionSuccessfulFn_(); onConnectionSuccessfulFn_();
@ -590,7 +595,14 @@ void FreeDVReporter::sendMessageImpl_(std::string message)
void FreeDVReporter::hideFromViewImpl_() void FreeDVReporter::hideFromViewImpl_()
{ {
// 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"); sioClient_->emit("hide_self");
}
hidden_ = true; hidden_ = true;
} }
@ -601,6 +613,14 @@ void FreeDVReporter::showOurselvesImpl_()
onAboutToShowSelfFn_(); onAboutToShowSelfFn_();
} }
// 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"); sioClient_->emit("show_self");
}
hidden_ = false; hidden_ = false;
} }

View File

@ -122,6 +122,7 @@ private:
bool rxOnly_; bool rxOnly_;
bool hidden_; bool hidden_;
std::string message_; std::string message_;
bool fullyConnected_;
ReporterConnectionFn onReporterConnectFn_; ReporterConnectionFn onReporterConnectFn_;
ReporterConnectionFn onReporterDisconnectFn_; ReporterConnectionFn onReporterDisconnectFn_;