Start all the receivers only after the secondary registration is finished

pull/537/head
sachaaaaa 6 years ago
parent b63d8ec84f
commit cc04bee38a

@ -875,14 +875,14 @@
); );
} }
function disconnect() { async function disconnect() {
window.log.info('disconnect'); window.log.info('disconnect');
// Clear timer, since we're only called when the timer is expired // Clear timer, since we're only called when the timer is expired
disconnectTimer = null; disconnectTimer = null;
if (messageReceiver) { if (messageReceiver) {
messageReceiver.close(); await messageReceiver.close();
} }
window.Signal.AttachmentDownloads.stop(); window.Signal.AttachmentDownloads.stop();
} }
@ -912,7 +912,7 @@
} }
if (messageReceiver) { if (messageReceiver) {
messageReceiver.close(); await messageReceiver.close();
} }
const USERNAME = storage.get('number_id'); const USERNAME = storage.get('number_id');
@ -927,6 +927,26 @@
Whisper.Notifications.disable(); // avoid notification flood until empty Whisper.Notifications.disable(); // avoid notification flood until empty
if (Whisper.Registration.ongoingSecondaryDeviceRegistration()) {
const ourKey = textsecure.storage.user.getNumber();
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
window.localLokiServer = null;
window.lokiPublicChatAPI = null;
window.feeds = [];
messageReceiver = new textsecure.MessageReceiver(
USERNAME,
PASSWORD,
mySignalingKey,
options
);
messageReceiver.addEventListener('message', onMessageReceived);
window.textsecure.messaging = new textsecure.MessageSender(
USERNAME,
PASSWORD
);
return;
}
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
startLocalLokiServer(); startLocalLokiServer();
await initAPIs(); await initAPIs();

@ -19,6 +19,10 @@ class LokiAppDotNetAPI extends EventEmitter {
this.myPrivateKey = false; this.myPrivateKey = false;
} }
async close() {
await Promise.all(this.servers.map(server => server.close()));
}
async getPrivateKey() { async getPrivateKey() {
if (!this.myPrivateKey) { if (!this.myPrivateKey) {
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
@ -89,6 +93,13 @@ class LokiAppDotNetServerAPI {
})(); })();
} }
async close() {
this.channels.forEach(channel => channel.stop());
if (this.tokenPromise) {
await this.tokenPromise;
}
}
// channel getter/factory // channel getter/factory
findOrCreateChannel(channelId, conversationId) { findOrCreateChannel(channelId, conversationId) {
let thisChannel = this.channels.find( let thisChannel = this.channels.find(

@ -141,6 +141,8 @@
clearInterval(this.pairingInterval); clearInterval(this.pairingInterval);
// Ensure the left menu is updated // Ensure the left menu is updated
Whisper.events.trigger('userChanged', { isSecondaryDevice: true }); Whisper.events.trigger('userChanged', { isSecondaryDevice: true });
// will re-run the background initialisation
Whisper.events.trigger('registration_done');
this.$el.trigger('openInbox'); this.$el.trigger('openInbox');
}, },
async resetRegistration() { async resetRegistration() {

@ -77,11 +77,15 @@ MessageReceiver.prototype.extend({
handleRequest: this.handleRequest.bind(this), handleRequest: this.handleRequest.bind(this),
}); });
this.httpPollingResource.pollServer(); this.httpPollingResource.pollServer();
localLokiServer.on('message', this.handleP2pMessage.bind(this)); if (localLokiServer) {
lokiPublicChatAPI.on( localLokiServer.on('message', this.handleP2pMessage.bind(this));
'publicMessage', }
this.handleUnencryptedMessage.bind(this) if (lokiPublicChatAPI) {
); lokiPublicChatAPI.on(
'publicMessage',
this.handleUnencryptedMessage.bind(this)
);
}
// set up pollers for any RSS feeds // set up pollers for any RSS feeds
feeds.forEach(feed => { feeds.forEach(feed => {
feed.on('rssMessage', this.handleUnencryptedMessage.bind(this)); feed.on('rssMessage', this.handleUnencryptedMessage.bind(this));
@ -118,6 +122,9 @@ MessageReceiver.prototype.extend({
this.incoming = [this.pending]; this.incoming = [this.pending];
}, },
async startLocalServer() { async startLocalServer() {
if (!localLokiServer) {
return;
}
try { try {
// clearnet change: getMyLokiIp -> getMyClearIp // clearnet change: getMyLokiIp -> getMyClearIp
// const myLokiIp = await window.lokiSnodeAPI.getMyLokiIp(); // const myLokiIp = await window.lokiSnodeAPI.getMyLokiIp();
@ -184,7 +191,7 @@ MessageReceiver.prototype.extend({
); );
} }
}, },
close() { async close() {
window.log.info('MessageReceiver.close()'); window.log.info('MessageReceiver.close()');
this.calledClose = true; this.calledClose = true;
@ -198,6 +205,10 @@ MessageReceiver.prototype.extend({
localLokiServer.close(); localLokiServer.close();
} }
if (lokiPublicChatAPI) {
await lokiPublicChatAPI.close();
}
if (this.httpPollingResource) { if (this.httpPollingResource) {
this.httpPollingResource.close(); this.httpPollingResource.close();
} }

Loading…
Cancel
Save