Catch errors when starting local server and retry every 30 seconds

pull/233/head
Beaudan 6 years ago
parent 55e0ff1a88
commit eaea7d9b7d

@ -83,13 +83,7 @@ MessageReceiver.prototype.extend({
this.onEmpty();
}
});
window.lokiSnodeAPI.getMyLokiIp().then(myLokiIp => {
localLokiServer.start(localServerPort, myLokiIp).then(port => {
window.log.info(`Local Server started at ${myLokiIp}:${port}`);
libloki.api.broadcastOnlineStatus();
localLokiServer.on('message', this.handleP2pMessage.bind(this));
});
});
this.startLocalServer();
// TODO: Rework this socket stuff to work with online messaging
const useWebSocket = false;
@ -120,6 +114,28 @@ MessageReceiver.prototype.extend({
// all cached envelopes are processed.
this.incoming = [this.pending];
},
async startLocalServer() {
let myLokiIp;
let myServerPort;
try {
myLokiIp = await window.lokiSnodeAPI.getMyLokiIp();
} catch (e) {
window.log.warn(
'Failed to get my loki address to bind server to, will retry in 30 seconds'
);
setTimeout(this.startLocalServer.bind(this), 30 * 1000);
}
try {
myServerPort = await localLokiServer.start(localServerPort, myLokiIp);
} catch (e) {
window.log.warn('Failed to start local loki server, will retry in 30 seconds');
setTimeout(this.startLocalServer.bind(this), 30 * 1000);
}
window.log.info(`Local Server started at ${myLokiIp}:${myServerPort}`);
libloki.api.broadcastOnlineStatus();
localLokiServer.on('message', this.handleP2pMessage.bind(this));
},
handleP2pMessage(message) {
this.httpPollingResource.handleMessage(message, true);
},

Loading…
Cancel
Save