Add performance to demo page

pull/1260/head
Rick Carlino 2019-07-04 15:49:51 -05:00
parent ed26a3ecb9
commit 8c1a13804a
2 changed files with 23 additions and 28 deletions

View File

@ -47,10 +47,6 @@ module Api
before_action :always_allow_admin, except: [:user_action]
def user_action # Session entrypoint - Part I
if username_param == FARMBOT_DEMO_USER
deny
return
end
# Example JSON:
# "username" => "foo@bar.com",
# "password" => "******",
@ -70,10 +66,6 @@ module Api
end
def vhost_action # Session entrypoint - Part II
if username_param == FARMBOT_DEMO_USER
deny
return
end
# Example JSON:
# "username" => "admin",
# "vhost" => "/",
@ -82,10 +74,6 @@ module Api
end
def resource_action
if username_param == FARMBOT_DEMO_USER
deny
return
end
# Example JSON:
# "username" => "admin",
# "vhost" => "/",
@ -97,10 +85,6 @@ module Api
end
def topic_action # Called during subscribe
if username_param == FARMBOT_DEMO_USER
deny
return
end
# Example JSON:
# "name" => "amq.topic",
# "permission" => "read",

View File

@ -35,12 +35,28 @@ export class DemoIframe extends React.Component<{}, State> {
setError = (error?: Error) => this.setState({ error });
componentWillMount() {
const client =
connect(globalConfig.MQTT_WS, WS_CONFIG);
this.setState({ client });
client.on("message", this.handleMessage);
client.subscribe(MQTT_CHAN, this.setError);
connectMqtt = (): Promise<MqttClient> => {
const client = connect(globalConfig.MQTT_WS, WS_CONFIG);
this.setState({ stage: WAITING_ON_API });
return new Promise(resolve => {
this.setState({ stage: "Promise executor called" });
client.on("connect", () => {
this.setState({ stage: "Connected" });
this.setState({ client });
client.on("message", this.handleMessage);
client.subscribe(MQTT_CHAN, this.setError);
resolve(client);
});
});
}
connectApi = () => {
const is51 = (Math.round(Math.random() * 100) == 51);
is51 && this.setState({ stage: EASTER_EGG });
return axios
.post<string>(HTTP_URL, { secret: SECRET })
.then(() => this.setState({ stage: WAITING_ON_API }))
.catch(this.setError);
}
handleMessage =
@ -50,12 +66,7 @@ export class DemoIframe extends React.Component<{}, State> {
}
requestAccount = () => {
const is51 = (Math.round(Math.random() * 100) == 51);
is51 && this.setState({ stage: EASTER_EGG });
return axios
.post<string>(HTTP_URL, { secret: SECRET })
.then(() => this.setState({ stage: WAITING_ON_API }))
.catch(this.setError);
return this.connectMqtt().then(this.connectApi);
};
ok = () => {