Only retry messages on startup, not every sockect reconnect (#1510)

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-09-28 14:58:45 -07:00 committed by GitHub
parent 2d650bd627
commit 95c85010c4
3 changed files with 29 additions and 11 deletions

View file

@ -157,6 +157,7 @@
}
});
var connectCount = 0;
function connect(firstRun) {
window.removeEventListener('online', connect);
window.addEventListener('offline', disconnect);
@ -173,9 +174,14 @@
var PASSWORD = storage.get('password');
var mySignalingKey = storage.get('signaling_key');
connectCount += 1;
var options = {
retryCached: connectCount === 1,
};
// initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(
SERVER_URL, USERNAME, PASSWORD, mySignalingKey
SERVER_URL, USERNAME, PASSWORD, mySignalingKey, options
);
messageReceiver.addEventListener('message', onMessageReceived);
messageReceiver.addEventListener('receipt', onDeliveryReceipt);

View file

@ -38356,7 +38356,9 @@ var TextSecureServer = (function() {
* vim: ts=4:sw=4:expandtab
*/
function MessageReceiver(url, username, password, signalingKey) {
function MessageReceiver(url, username, password, signalingKey, options) {
options = options || {};
this.count = 0;
this.url = url;
@ -38368,6 +38370,12 @@ function MessageReceiver(url, username, password, signalingKey) {
var address = libsignal.SignalProtocolAddress.fromString(username);
this.number = address.getName();
this.deviceId = address.getDeviceId();
this.pending = Promise.resolve();
if (options.retryCached) {
this.pending = this.queueAllCached();
}
}
MessageReceiver.prototype = new textsecure.EventTarget();
@ -38387,8 +38395,6 @@ MessageReceiver.prototype.extend({
keepalive: { path: '/v1/keepalive', disconnect: true }
});
this.pending = this.queueAllCached();
// Ensures that an immediate 'empty' event from the websocket will fire only after
// all cached envelopes are processed.
this.incoming = [this.pending];
@ -39211,8 +39217,8 @@ MessageReceiver.prototype.extend({
window.textsecure = window.textsecure || {};
textsecure.MessageReceiver = function(url, username, password, signalingKey) {
var messageReceiver = new MessageReceiver(url, username, password, signalingKey);
textsecure.MessageReceiver = function(url, username, password, signalingKey, options) {
var messageReceiver = new MessageReceiver(url, username, password, signalingKey, options);
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);

View file

@ -2,7 +2,9 @@
* vim: ts=4:sw=4:expandtab
*/
function MessageReceiver(url, username, password, signalingKey) {
function MessageReceiver(url, username, password, signalingKey, options) {
options = options || {};
this.count = 0;
this.url = url;
@ -14,6 +16,12 @@ function MessageReceiver(url, username, password, signalingKey) {
var address = libsignal.SignalProtocolAddress.fromString(username);
this.number = address.getName();
this.deviceId = address.getDeviceId();
this.pending = Promise.resolve();
if (options.retryCached) {
this.pending = this.queueAllCached();
}
}
MessageReceiver.prototype = new textsecure.EventTarget();
@ -33,8 +41,6 @@ MessageReceiver.prototype.extend({
keepalive: { path: '/v1/keepalive', disconnect: true }
});
this.pending = this.queueAllCached();
// Ensures that an immediate 'empty' event from the websocket will fire only after
// all cached envelopes are processed.
this.incoming = [this.pending];
@ -857,8 +863,8 @@ MessageReceiver.prototype.extend({
window.textsecure = window.textsecure || {};
textsecure.MessageReceiver = function(url, username, password, signalingKey) {
var messageReceiver = new MessageReceiver(url, username, password, signalingKey);
textsecure.MessageReceiver = function(url, username, password, signalingKey, options) {
var messageReceiver = new MessageReceiver(url, username, password, signalingKey, options);
this.addEventListener = messageReceiver.addEventListener.bind(messageReceiver);
this.removeEventListener = messageReceiver.removeEventListener.bind(messageReceiver);
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);