Reconnect provisioning socket

If the provisioning socket closes, reconnect and generate a new qr code.
Fixes #371

// FREEBIE
This commit is contained in:
lilia 2015-10-23 18:33:07 -07:00
parent 47befdbf61
commit 9b12d8a978
3 changed files with 36 additions and 28 deletions

View file

@ -39073,10 +39073,11 @@ var TextSecureServer = (function() {
var registerKeys = this.server.registerKeys.bind(this.server);
var getSocket = this.server.getProvisioningSocket.bind(this.server);
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
return new Promise(function(resolve) {
return new Promise(function(resolve, reject) {
var socket = getSocket();
socket.onclose = function(e) {
console.log('websocket closed', e.code);
reject(new Error('websocket closed'));
};
var wsr = new WebSocketResource(socket, {
keepalive: { path: '/v1/keepalive/provisioning' },

View file

@ -61,10 +61,13 @@
});
$(function() {
var accountManager = new bg.getAccountManager();
var init = function() {
$('#init-setup').show().addClass('in');
$('#qr').html('');
$('#status').text("Connecting...");
var accountManager = new bg.getAccountManager();
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
var launch = function() {
bg.openInbox();
@ -76,9 +79,10 @@
bg.addEventListener('textsecure:contactsync', launch);
$('.progress-dialog .status').text('Syncing groups and contacts');
$('.progress-dialog .bar').addClass('progress-bar-striped active');
}).catch(function(e) {
if (e.name === 'HTTPError' && e.code == 411) {
if (e.message === 'websocket closed') {
init();
} else if (e.name === 'HTTPError' && e.code == 411) {
$('.progress-dialog').hide();
$('.error-dialog').show();
$('.error-dialog .ok').click(function(e) {
@ -89,6 +93,8 @@
throw e;
}
});
};
init();
});
});
})();

View file

@ -36,10 +36,11 @@
var registerKeys = this.server.registerKeys.bind(this.server);
var getSocket = this.server.getProvisioningSocket.bind(this.server);
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
return new Promise(function(resolve) {
return new Promise(function(resolve, reject) {
var socket = getSocket();
socket.onclose = function(e) {
console.log('websocket closed', e.code);
reject(new Error('websocket closed'));
};
var wsr = new WebSocketResource(socket, {
keepalive: { path: '/v1/keepalive/provisioning' },