Merge pull request #23 from rerdavies/rerdavies/issue20

Crash on initial load.
This commit is contained in:
Robin Davies
2022-03-10 11:34:30 -05:00
committed by GitHub
7 changed files with 97 additions and 22 deletions
+5 -18
View File
@@ -836,7 +836,11 @@ class PiPedalModelImpl implements PiPedalModel {
})
.then((data) => {
this.banks.set(new BankIndex().deserialize(data));
if (this.webSocket)
{
// MUST not allow reconnect until at least one complete load has finished.
this.webSocket.canReconnect = true;
}
return true;
})
.catch((error) => {
@@ -848,23 +852,6 @@ class PiPedalModelImpl implements PiPedalModel {
;
}
// requestPlugins(): Promise<boolean> {
// const myRequest = new Request(this.varRequest('uiplugins.json'));
// return fetch(myRequest)
// .then(
// response => response.json()
// )
// .then(data => {
// let plugins = UiPlugin.deserialize_array(data);
// this.ui_plugins.set(plugins);
// return true;
// })
// .catch((error) => {
// this.setError("Can't contact server.\n\n" + error);
// return false;
// });
// }
requestCurrentPedalBoard(): Promise<void> {
const myRequest = new Request(this.varRequest('current_pedalboard.json'));
return fetch(myRequest)
+7 -1
View File
@@ -178,6 +178,9 @@ class PiPedalSocket {
throw new PiPedalStateError("Server connection lost.");
}
}
canReconnect: boolean = false;
handleClose(_event: any): any {
if (this.retrying) {
// treat this as a fatal error.
@@ -189,7 +192,10 @@ class PiPedalSocket {
return;
}
this._reconnect();
if (this.canReconnect)
{
this._reconnect();
}
}
_reconnect() {
this._discardReplyReservations();
+6 -1
View File
@@ -547,7 +547,10 @@ const SettingsDialog = withStyles(styles, { withTheme: true })(
</div>
</ButtonBase>
<ButtonBase className={classes.setting} disabled={!this.state.wifiConfigSettings.valid}
<ButtonBase
style={{display: "none"}}
className={classes.setting} disabled={!this.state.wifiConfigSettings.valid}
onClick={() => this.handleShowGovernorSettingsDialogDialog()} >
<SelectHoverBackground selected={false} showHover={true} />
<div style={{ width: "100%" }}>
@@ -559,6 +562,8 @@ const SettingsDialog = withStyles(styles, { withTheme: true })(
</div>
</ButtonBase>
<ButtonBase className={classes.setting} disabled={!isConfigValid || disableShutdown}
onClick={() => this.handleRestart()} >
<SelectHoverBackground selected={false} showHover={true} />
+9 -2
View File
@@ -385,11 +385,18 @@ namespace pipedal
}
std::shared_ptr<websocketpp::uri> connectionUri = con->get_uri();
uri requestUri(con->get_uri()->str().c_str());
HttpRequestImpl req(con->get_request());
HttpResponseImpl res((*con));
uri requestUri;
try {
requestUri.set(con->get_uri()->str().c_str());
} catch (const std::exception &e)
{
ServerError(*con, SS("Unexpected error. " << e.what()));
return;
}
if (req.method() == HttpVerb::options)
{
res.set(HttpField::access_control_allow_origin, origin);
+61
View File
@@ -85,6 +85,67 @@ static bool IsIpv4OnLocalSubnet(uint32_t ipv4Addres)
return result;
}
bool pipedal::ParseHttpAddress(const std::string address,
std::string *pUser,
std::string *pServer,
int *pPort,
int defaultPort)
{
// strip user.
auto start = address.find_first_of('@');
if (start != std::string::npos)
{
if (pUser)
{
*pUser = address.substr(0,start);
}
start = start+1;
} else {
start = 0;
if (pUser)
{
*pUser = "";
}
}
// find the port address.
int port = address.length();
while (port > 0 && address[port-1] != ':')
{
if (address[port-1] != ']')
{
port = address.length();
break;
}
--port;
}
int portNumber = defaultPort;
if (port < address.length() && address[port] == ':')
{
const char*p = address.c_str()+port+1;
if (*p)
{
portNumber = 0;
while (*p)
{
if (*p >= '0' && *p <= '9')
{
portNumber = portNumber*10 + *p -'0';
} else {
return false;
}
}
}
}
if (pPort)
{
*pPort = portNumber;
}
if (pServer)
{
*pServer = address.substr(start,port-start);
}
return true;
}
static std::string StripPortNumber(const std::string &fromAddress)
{
std::string address = fromAddress;
+6
View File
@@ -27,5 +27,11 @@ namespace pipedal {
bool IsOnLocalSubnet(const std::string&fromAddress);
bool ParseHttpAddress(const std::string address,
std::string *pUser,
std::string *pServer,
int *pPort,
int defaultPort);
}
+3
View File
@@ -140,6 +140,9 @@ void uri::set_()
{
authority_end = p;
port_start = p+1;
} else if (c == ']') // ignore colon inside ipv6 address.
{
port_start = nullptr;
}
if (c == '/' || c == '?' || c == '#')
{