Ensure that all event handling in background.js is queued

This commit is contained in:
Scott Nonnenberg 2019-06-14 15:17:37 -07:00 committed by Ken Powers
parent 649544dfac
commit cc7b9da0cf
2 changed files with 25 additions and 15 deletions

View file

@ -16,6 +16,8 @@
(async function() {
'use strict';
const eventHandlerQueue = new window.PQueue({ concurrency: 1 });
// Globally disable drag and drop
document.body.addEventListener(
'dragover',
@ -806,21 +808,28 @@
mySignalingKey,
options
);
messageReceiver.addEventListener('message', onMessageReceived);
messageReceiver.addEventListener('delivery', onDeliveryReceipt);
messageReceiver.addEventListener('contact', onContactReceived);
messageReceiver.addEventListener('group', onGroupReceived);
messageReceiver.addEventListener('sent', onSentMessage);
messageReceiver.addEventListener('readSync', onReadSync);
messageReceiver.addEventListener('read', onReadReceipt);
messageReceiver.addEventListener('verified', onVerified);
messageReceiver.addEventListener('error', onError);
messageReceiver.addEventListener('empty', onEmpty);
messageReceiver.addEventListener('reconnect', onReconnect);
messageReceiver.addEventListener('progress', onProgress);
messageReceiver.addEventListener('configuration', onConfiguration);
messageReceiver.addEventListener('typing', onTyping);
messageReceiver.addEventListener('sticker-pack', onStickerPack);
function addQueuedEventListener(name, handler) {
messageReceiver.addEventListener(name, (...args) =>
eventHandlerQueue.add(() => handler(...args))
);
}
addQueuedEventListener('message', onMessageReceived);
addQueuedEventListener('delivery', onDeliveryReceipt);
addQueuedEventListener('contact', onContactReceived);
addQueuedEventListener('group', onGroupReceived);
addQueuedEventListener('sent', onSentMessage);
addQueuedEventListener('readSync', onReadSync);
addQueuedEventListener('read', onReadReceipt);
addQueuedEventListener('verified', onVerified);
addQueuedEventListener('error', onError);
addQueuedEventListener('empty', onEmpty);
addQueuedEventListener('reconnect', onReconnect);
addQueuedEventListener('progress', onProgress);
addQueuedEventListener('configuration', onConfiguration);
addQueuedEventListener('typing', onTyping);
addQueuedEventListener('sticker-pack', onStickerPack);
window.Signal.AttachmentDownloads.start({
getMessageReceiver: () => messageReceiver,

View file

@ -287,6 +287,7 @@ window.getGuid = require('uuid/v4');
window.React = require('react');
window.ReactDOM = require('react-dom');
window.moment = require('moment');
window.PQueue = require('p-queue');
const Signal = require('./js/modules/signal');
const i18n = require('./js/modules/i18n');