From 3c07d99a895d125e553bbf06477ba1c60967cb6d Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 31 Jan 2019 11:14:35 +1100 Subject: [PATCH] Fix variable names. Fix module export to be more consistent. --- js/modules/loki_message_api.js | 4 +--- js/modules/loki_p2p_api.js | 4 +--- js/modules/loki_snode_api.js | 4 +--- js/modules/util_worker_interface.js | 5 +---- libloki/local_loki_server.js | 2 +- libloki/test/node/local_loki_server_test.js | 2 +- libtextsecure/message_receiver.js | 24 ++++++++++----------- libtextsecure/outgoing_message.js | 4 +--- preload.js | 16 +++++++------- 9 files changed, 27 insertions(+), 38 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 3203e67f6..90a1920ca 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -257,6 +257,4 @@ class LokiMessageAPI { } } -module.exports = { - LokiMessageAPI, -}; +module.exports = LokiMessageAPI; diff --git a/js/modules/loki_p2p_api.js b/js/modules/loki_p2p_api.js index fff8e30d1..09978299b 100644 --- a/js/modules/loki_p2p_api.js +++ b/js/modules/loki_p2p_api.js @@ -19,6 +19,4 @@ class LokiP2pAPI { } } -module.exports = { - LokiP2pAPI, -}; +module.exports = LokiP2pAPI; diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index 8d1dc501b..50efbdd4b 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -212,6 +212,4 @@ function HTTPError(message, providedCode, response, stack) { return e; } -module.exports = { - LokiSnodeAPI, -}; +module.exports = LokiSnodeAPI; diff --git a/js/modules/util_worker_interface.js b/js/modules/util_worker_interface.js index 82fafcc74..5f89c756a 100644 --- a/js/modules/util_worker_interface.js +++ b/js/modules/util_worker_interface.js @@ -122,7 +122,4 @@ class WorkerInterface { } } -module.exports = { - WorkerInterface, - TimedOutError, -}; +module.exports = WorkerInterface; diff --git a/libloki/local_loki_server.js b/libloki/local_loki_server.js index ed9bf6c03..979c30852 100644 --- a/libloki/local_loki_server.js +++ b/libloki/local_loki_server.js @@ -87,4 +87,4 @@ class LocalLokiServer extends EventEmitter { } } -exports.LocalLokiServer = LocalLokiServer; +module.exports = LocalLokiServer; diff --git a/libloki/test/node/local_loki_server_test.js b/libloki/test/node/local_loki_server_test.js index ec75a72f0..be0ea2930 100644 --- a/libloki/test/node/local_loki_server_test.js +++ b/libloki/test/node/local_loki_server_test.js @@ -1,6 +1,6 @@ const axios = require('axios'); const { assert } = require('chai'); -const { LocalLokiServer } = require('../../local_loki_server'); +const LocalLokiServer = require('../../local_loki_server'); describe('LocalLokiServer', () => { before(async () => { diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 5d66d9435..66298084b 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -12,6 +12,9 @@ /* global ContactBuffer: false */ /* global GroupBuffer: false */ /* global WebSocketResource: false */ +/* global localLokiServer: false */ +/* global localServerPort: false */ +/* global lokiMessageAPI: false */ /* eslint-disable more/no-then */ /* eslint-disable no-unreachable */ @@ -22,8 +25,6 @@ function MessageReceiver(username, password, signalingKey, options = {}) { this.signalingKey = signalingKey; this.username = username; this.password = password; - this.lokiMessageAPI = window.LokiMessageAPI; - this.localServer = window.LocalLokiServer; if (!options.serverTrustRoot) { throw new Error('Server trust root is required!'); @@ -68,7 +69,7 @@ MessageReceiver.prototype.extend({ } this.hasConnected = true; - this.httpPollingResource = new HttpResource(this.lokiMessageAPI, { + this.httpPollingResource = new HttpResource(lokiMessageAPI, { handleRequest: this.handleRequest.bind(this), }); this.httpPollingResource.startPolling(connected => { @@ -82,10 +83,10 @@ MessageReceiver.prototype.extend({ } }); - this.localServer.start(window.localServerPort).then(port => { + localLokiServer.start(localServerPort).then(port => { window.log.info(`Local Server started at localhost:${port}`); - window.libloki.api.broadcastOnlineStatus(); - this.localServer.on('message', this.httpPollingResource.handleMessage); + libloki.api.broadcastOnlineStatus(); + localLokiServer.on('message', this.httpPollingResource.handleMessage); }); // TODO: Rework this socket stuff to work with online messaging @@ -130,12 +131,11 @@ MessageReceiver.prototype.extend({ this.wsr = null; } - if (this.localServer) { - this.localServer.removeListener( + if (localLokiServer) { + localLokiServer.removeListener( 'message', this.httpPollingResource.handleMessage ); - this.localServer = null; } }, close() { @@ -148,8 +148,8 @@ MessageReceiver.prototype.extend({ this.wsr.close(3000, 'called close'); } - if (this.localServer) { - this.localServer.close(); + if (localLokiServer) { + localLokiServer.close(); } return this.drain(); @@ -900,7 +900,7 @@ MessageReceiver.prototype.extend({ }, async handleLokiAddressMessage(envelope, lokiAddressMessage) { const { p2pAddress, p2pPort } = lokiAddressMessage; - window.LokiP2pAPI.addContactP2pDetails( + window.lokiP2pAPI.addContactP2pDetails( envelope.source, p2pAddress, p2pPort diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 885de9250..1e3b0f080 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -34,8 +34,6 @@ function OutgoingMessage( this.callback = callback; this.silent = silent; - this.lokiMessageAPI = window.LokiMessageAPI; - this.numbersCompleted = 0; this.errors = []; this.successfulNumbers = []; @@ -186,7 +184,7 @@ OutgoingMessage.prototype = { async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60) { const pubKey = number; try { - await this.lokiMessageAPI.sendMessage(pubKey, data, timestamp, ttl); + await window.lokiMessageAPI.sendMessage(pubKey, data, timestamp, ttl); } catch (e) { if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) { // 409 and 410 should bubble and be handled by doSendMessage diff --git a/preload.js b/preload.js index 67affe39b..fb3dc298a 100644 --- a/preload.js +++ b/preload.js @@ -269,31 +269,31 @@ window.WebAPI = initializeWebAPI({ proxyUrl: config.proxyUrl, }); -const { LokiSnodeAPI } = require('./js/modules/loki_snode_api'); +const LokiSnodeAPI = require('./js/modules/loki_snode_api'); window.LokiSnodeAPI = new LokiSnodeAPI({ url: config.serverUrl, swarmServerPort: config.swarmServerPort, }); -const { LokiP2pAPI } = require('./js/modules/loki_p2p_api'); +const LokiP2pAPI = require('./js/modules/loki_p2p_api'); -window.LokiP2pAPI = new LokiP2pAPI(); +window.lokiP2pAPI = new LokiP2pAPI(); -const { LokiMessageAPI } = require('./js/modules/loki_message_api'); +const LokiMessageAPI = require('./js/modules/loki_message_api'); -window.LokiMessageAPI = new LokiMessageAPI({ +window.lokiMessageAPI = new LokiMessageAPI({ url: config.serverUrl, messageServerPort: config.messageServerPort, }); -const { LocalLokiServer } = require('./libloki/local_loki_server'); +const LocalLokiServer = require('./libloki/local_loki_server'); window.localServerPort = config.localServerPort; -window.LocalLokiServer = new LocalLokiServer(); +window.localLokiServer = new LocalLokiServer(); window.mnemonic = require('./libloki/mnemonic'); -const { WorkerInterface } = require('./js/modules/util_worker_interface'); +const WorkerInterface = require('./js/modules/util_worker_interface'); // A Worker with a 3 minute timeout const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js');