Ensure API objects are inited only once

pull/497/head
sachaaaaa 6 years ago
parent cf3ddf0b03
commit 025ad10fc5

@ -205,7 +205,11 @@
window.log.info('Storage fetch'); window.log.info('Storage fetch');
storage.fetch(); storage.fetch();
let initialisedAPI = false;
const initAPIs = () => { const initAPIs = () => {
if (initialisedAPI) {
return;
}
const ourKey = textsecure.storage.user.getNumber(); const ourKey = textsecure.storage.user.getNumber();
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
window.lokiP2pAPI = new window.LokiP2pAPI(ourKey); window.lokiP2pAPI = new window.LokiP2pAPI(ourKey);
@ -215,6 +219,7 @@
}); });
window.lokiP2pAPI.on('online', ConversationController._handleOnline); window.lokiP2pAPI.on('online', ConversationController._handleOnline);
window.lokiP2pAPI.on('offline', ConversationController._handleOffline); window.lokiP2pAPI.on('offline', ConversationController._handleOffline);
initialisedAPI = true;
}; };
function mapOldThemeToNew(theme) { function mapOldThemeToNew(theme) {
@ -232,6 +237,9 @@
} }
function startLocalLokiServer() { function startLocalLokiServer() {
if (window.localLokiServer) {
return;
}
const pems = window.getSelfSignedCert(); const pems = window.getSelfSignedCert();
window.localLokiServer = new window.LocalLokiServer(pems); window.localLokiServer = new window.LocalLokiServer(pems);
} }

Loading…
Cancel
Save