Skip to content

Commit

Permalink
auto udp & proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
cybercop23 committed Jan 14, 2025
1 parent 5ff110b commit 892cda3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
39 changes: 33 additions & 6 deletions xLights/controllers/FPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3830,13 +3830,27 @@ inline void setIfEmpty(uint32_t &val, uint32_t nv) {
}
}

void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, OutputManager* outputManager) {
void FPP::MapToFPPInstances(Discovery& discovery, std::list<FPP*>& instances, OutputManager* outputManager) {
static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
std::unordered_set<std::string> configuredIPs;
bool foundActiveController = false;
uint16_t activePlayerCount = 0;
std::unordered_set<std::string> allProxyList;
std::map<std::string, std::string> configuredIPs;
if (discovery.GetOutputManager()->GetGlobalFPPProxy() != "") {
auto ip = ip_utils::ResolveIP(discovery.GetOutputManager()->GetGlobalFPPProxy());
allProxyList.insert(ip);
};
for (auto& it : discovery.GetOutputManager()->GetControllers()) {
auto c = dynamic_cast<ControllerEthernet*>(it);
configuredIPs.insert(c->GetResolvedIP());
}
auto c = dynamic_cast<ControllerEthernet*>(it);
configuredIPs[c->GetResolvedIP()] = c->GetIP();
if (!c->GetFPPProxy().empty()) {
auto ip = ip_utils::ResolveIP(c->GetFPPProxy());
allProxyList.insert(ip);
}
if (Controller::DecodeActiveState(c->GetActive()) == "Active") {
foundActiveController = true;
}
}
for (auto res : discovery.GetResults()) {
if (::supportedForFPPConnect(res, outputManager)) {
logger_base.info("FPP Discovery - Found Supported FPP Instance: %s (u: %s)(h: %s)(p: %s)(r: %s)", res->ip.c_str(), res->uuid.c_str(), res->hostname.c_str(), res->proxy.c_str(), res->ranges.c_str());
Expand Down Expand Up @@ -3887,6 +3901,15 @@ void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, Ou
if (res->extraData.HasMember("cape")) {
fpp->capeInfo = res->extraData["cape"];
}
auto it = configuredIPs.find(res->ip);
if (it != configuredIPs.end()) {
if (allProxyList.count(it->first) > 0 || allProxyList.count(it->second) > 0) {
fpp->isaProxy = true;
}
}
if (StartsWith(res->mode, "player")) {
activePlayerCount++;
};
instances.push_back(fpp);
} else if (!skipit) {
fpp->ipAddress = res->ip;
Expand All @@ -3906,7 +3929,6 @@ void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, Ou
setIfEmpty(fpp->controllerVendor, res->vendor);
setIfEmpty(fpp->controllerModel, res->model);
setIfEmpty(fpp->controllerVariant, res->variant);

setIfEmpty(fpp->minorVersion, res->minorVersion);
setIfEmpty(fpp->patchVersion, res->patchVersion);
setIfEmpty(fpp->majorVersion, res->majorVersion);
Expand All @@ -3924,6 +3946,11 @@ void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, Ou
logger_base.info("FPP Discovery - %s is not a supported FPP Instance", res->ip.c_str());
}
}
for (auto f : instances) {
if (activePlayerCount == 1 && StartsWith(f->mode, "player")) {
f->solePlayer = true;
}
}
}

void FPP::TypeIDtoControllerType(int typeId, FPP* inst) {
Expand Down
2 changes: 2 additions & 0 deletions xLights/controllers/FPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class FPP : public BaseController

std::string proxy;
std::set<std::string> proxies;
bool isaProxy = false;
bool solePlayer = false;

std::string username;
std::string password;
Expand Down
44 changes: 36 additions & 8 deletions xLights/controllers/FPPConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,14 @@ void FPPConnectDialog::PopulateFPPInstanceList(wxProgressDialog *prgs) {
Choice1->Append(_("Proxied"));
Choice1->SetSelection(0);
FPPInstanceSizer->Add(Choice1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 1);

if (inst->solePlayer) {
SetChoiceValueIndex(UDP_COL + rowStr, 1);
} else if (inst->isaProxy) {
SetChoiceValueIndex(UDP_COL + rowStr, 2);
}
wxCheckBox* CheckBoxProxy = new wxCheckBox(FPPInstanceList, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, PROXY_COL + rowStr);
FPPInstanceSizer->Add(CheckBoxProxy, 1, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 1);
CheckBoxProxy->SetValue(inst->isaProxy);

//playlist combo box
if (StartsWith(inst->mode, "player")) {
Expand Down Expand Up @@ -1553,13 +1558,36 @@ void FPPConnectDialog::SaveSettings(bool onlyInsts)
std::string rowStr = std::to_string(row);
wxString keyPostfx = (inst->uuid.empty() ? inst->ipAddress : inst->uuid);
keyPostfx = Fixitup(keyPostfx);
config->Write("FPPConnectUpload_" + keyPostfx, GetCheckValue(CHECK_COL + rowStr));
config->Write("FPPConnectUploadMedia_" + keyPostfx, GetCheckValue(MEDIA_COL + rowStr));
config->Write("FPPConnectUploadFSEQType_" + keyPostfx, GetChoiceValueIndex(FSEQ_COL + rowStr));
config->Write("FPPConnectUploadModels_" + keyPostfx, GetChoiceValueIndex(MODELS_COL + rowStr));
config->Write("FPPConnectUploadUDPOut_" + keyPostfx, GetChoiceValueIndex(UDP_COL + rowStr));
config->Write("FPPConnectUploadPixelOut_" + keyPostfx, GetCheckValue(UPLOAD_CONTROLLER_COL + rowStr));
config->Write("FPPConnectUploadProxy_" + keyPostfx, GetCheckValue(PROXY_COL + rowStr));
bool bval;
int lval;
// only save the settings if they are different from defaults, or if previously changed and saved - this will help new users with auto setting up UPD & proxy
if (GetCheckValue(CHECK_COL + rowStr) != false || config->Read("FPPConnectUpload_" + Fixitup(inst->uuid), &bval)) {
config->Write("FPPConnectUpload_" + keyPostfx, GetCheckValue(CHECK_COL + rowStr));
}
if (GetCheckValue(MEDIA_COL + rowStr) != false || config->Read("FPPConnectUploadMedia_" + Fixitup(inst->uuid), &bval)) {
config->Write("FPPConnectUploadMedia_" + keyPostfx, GetCheckValue(MEDIA_COL + rowStr));
}
if (inst->fppType == FPP_TYPE::FPP && inst->supportedForFPPConnect()) {
if (GetChoiceValueIndex(FSEQ_COL + rowStr) != 2 || config->Read("FPPConnectUploadFSEQType_" + Fixitup(inst->uuid), &lval)) {
config->Write("FPPConnectUploadFSEQType_" + keyPostfx, GetChoiceValueIndex(FSEQ_COL + rowStr));
}
} else if (inst->fppType == FPP_TYPE::FALCONV4V5) {
if (GetChoiceValueIndex(FSEQ_COL + rowStr) != 2 || config->Read("FPPConnectUploadFSEQType_" + Fixitup(inst->uuid), &lval)) {
config->Write("FPPConnectUploadFSEQType_" + keyPostfx, GetChoiceValueIndex(FSEQ_COL + rowStr));
}
}
if (GetChoiceValueIndex(MODELS_COL + rowStr) != 0 || config->Read("FPPConnectUploadModels_" + Fixitup(inst->uuid), &lval)) {
config->Write("FPPConnectUploadModels_" + keyPostfx, GetChoiceValueIndex(MODELS_COL + rowStr));
}
if (GetChoiceValueIndex(UDP_COL + rowStr) > 0 || config->Read("FPPConnectUploadUDPOut_" + Fixitup(inst->uuid), &lval)) {
config->Write("FPPConnectUploadUDPOut_" + keyPostfx, GetChoiceValueIndex(UDP_COL + rowStr));
}
if (GetCheckValue(UPLOAD_CONTROLLER_COL + rowStr) != false || config->Read("FPPConnectUploadPixelOut_" + Fixitup(inst->uuid), &bval)) {
config->Write("FPPConnectUploadPixelOut_" + keyPostfx, GetCheckValue(UPLOAD_CONTROLLER_COL + rowStr));
}
if (GetCheckValue(PROXY_COL + rowStr) != false || config->Read("FPPConnectUploadProxy_" + Fixitup(inst->uuid), &bval)) {
config->Write("FPPConnectUploadProxy_" + keyPostfx, GetCheckValue(PROXY_COL + rowStr));
}
row++;
}
config->Flush();
Expand Down

0 comments on commit 892cda3

Please sign in to comment.