Merge pull request #537 from sachaaaaa/secondary_device_minimum_receiver

[multi-device] Start all the receivers only after the secondary registration is fini…
pull/542/head
sachaaaaa 6 years ago committed by GitHub
commit 73d90a5277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -877,14 +877,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();
} }
@ -914,7 +914,7 @@
} }
if (messageReceiver) { if (messageReceiver) {
messageReceiver.close(); await messageReceiver.close();
} }
const USERNAME = storage.get('number_id'); const USERNAME = storage.get('number_id');
@ -929,6 +929,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(

@ -149,6 +149,8 @@
await lokiFileServerAPI.updateOurDeviceMapping(); await lokiFileServerAPI.updateOurDeviceMapping();
// 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() {

@ -78,11 +78,15 @@ MessageReceiver.prototype.extend({
handleRequest: this.handleRequest.bind(this), handleRequest: this.handleRequest.bind(this),
}); });
this.httpPollingResource.pollServer(); this.httpPollingResource.pollServer();
if (localLokiServer) {
localLokiServer.on('message', this.handleP2pMessage.bind(this)); localLokiServer.on('message', this.handleP2pMessage.bind(this));
}
if (lokiPublicChatAPI) {
lokiPublicChatAPI.on( lokiPublicChatAPI.on(
'publicMessage', 'publicMessage',
this.handleUnencryptedMessage.bind(this) 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));
@ -119,6 +123,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();
@ -185,7 +192,7 @@ MessageReceiver.prototype.extend({
); );
} }
}, },
close() { async close() {
window.log.info('MessageReceiver.close()'); window.log.info('MessageReceiver.close()');
this.calledClose = true; this.calledClose = true;
@ -199,6 +206,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