Skip to content

Commit

Permalink
fix: Improve mapeo core start-up after reload during development
Browse files Browse the repository at this point in the history
When the app is reloaded in dev, the node server does not reload.
This requests the server status when the RN app starts, in case it is
already running. Also reduces the interval between heartbeats from the server
  • Loading branch information
gmaclennan committed Jun 5, 2019
1 parent a51539d commit 266a7de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ const constants = require("./constants");
class ServerStatus {
constructor() {
this.setState(constants.STARTING);
rnBridge.channel.on("request-status", () => {
log("status request");
rnBridge.channel.post("status", this.state);
});
}
startHeartbeat() {
if (this.intervalId) return; // Don't have two heartbeats
this.intervalId = setInterval(() => {
rnBridge.channel.post("status", this.state);
}, 1000);
}, 4000);
}
pauseHeartbeat() {
clearInterval(this.intervalId);
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export function Api({
// Start server, returns a promise that resolves when the server is ready
// or rejects if there is an error starting the server
startServer: function startServer(): Promise<void> {
// The server might already be started - request current status
nodejs.channel.post("request-status");
// The server requires read & write permissions for external storage
const serverStartPromise = PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
Expand Down

0 comments on commit 266a7de

Please sign in to comment.