Fix fast reconnect, and add support for reconnecting ws in polls

This commit is contained in:
yflory 2017-03-15 16:01:00 +01:00
parent 66ff6ae1b0
commit a286599f93
5 changed files with 49 additions and 30 deletions

View File

@ -141,17 +141,19 @@ const getHistory = function (ctx, channelName, lastKnownHash, handler, cb) {
for (var x = msgBuff2.pop(); x; x = msgBuff2.pop()) { handler(x); } for (var x = msgBuff2.pop(); x; x = msgBuff2.pop()) { handler(x); }
}; };
var hash = function (msg) { var hash = function (msg) {
return Crypto.createHash('md5').update(msg).digest('hex'); return msg.slice(0,64); //Crypto.createHash('md5').update(msg).digest('hex');
}; };
var isSent = false; var isSent = false;
for (startPoint = messageBuf.length - 1; startPoint >= 0; startPoint--) { for (startPoint = messageBuf.length - 1; startPoint >= 0; startPoint--) {
var msg = messageBuf[startPoint]; var msg = messageBuf[startPoint];
msgBuff2.push(msg); msgBuff2.push(msg);
if (msg[2] === 'MSG' && hash(msg[4]) === lastKnownHash) { if (lastKnownHash) {
msgBuff2.pop(); if (msg[2] === 'MSG' && hash(msg[4]) === lastKnownHash) {
sendBuff2(); msgBuff2.pop();
isSent = true; sendBuff2();
break; isSent = true;
break;
}
} else if (msg[2] === 'MSG' && msg[4].indexOf('cp|') === 0) { } else if (msg[2] === 'MSG' && msg[4].indexOf('cp|') === 0) {
cpCount++; cpCount++;
if (cpCount >= 2) { if (cpCount >= 2) {

View File

@ -2,7 +2,7 @@ require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/J
define([ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar.js', '/common/toolbar.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
@ -521,12 +521,14 @@ define([
}; };
var onReady = config.onReady = function (info) { var onReady = config.onReady = function (info) {
var realtime = module.realtime = info.realtime;
module.users = info.userList.users; module.users = info.userList.users;
module.patchText = TextPatcher.create({ if (module.realtime !== info.realtime) {
realtime: realtime, var realtime = module.realtime = info.realtime;
//logging: true module.patchText = TextPatcher.create({
}); realtime: realtime,
//logging: true
});
}
var userDoc = module.realtime.getUserDoc(); var userDoc = module.realtime.getUserDoc();

View File

@ -8,7 +8,7 @@ define([
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/TypingTests.js', '/common/TypingTests.js',
'json.sortify', 'json.sortify',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/visible.js', '/common/visible.js',
'/common/notify.js', '/common/notify.js',
@ -656,10 +656,12 @@ define([
} }
} }
module.patchText = TextPatcher.create({ if (module.realtime !== info.realtime) {
realtime: info.realtime, module.patchText = TextPatcher.create({
//logging: true, realtime: info.realtime,
}); //logging: true,
});
}
module.users = info.userList.users; module.users = info.userList.users;
module.realtime = info.realtime; module.realtime = info.realtime;

View File

@ -589,7 +589,7 @@ define([
$description.val(proxy.info.description); $description.val(proxy.info.description);
} }
$('#tableScroll').prepend($table); $('#tableScroll').html('').prepend($table);
updateDisplayedTable(); updateDisplayedTable();
$table $table
@ -662,11 +662,17 @@ define([
var disconnect = function (info) { var disconnect = function (info) {
//setEditable(false); // TODO //setEditable(false); // TODO
APP.realtime.toolbar.failed();
Cryptpad.alert(Messages.common_connectionLost, undefined, true); Cryptpad.alert(Messages.common_connectionLost, undefined, true);
}; };
var reconnect = function (info) {
//setEditable(true); // TODO
APP.realtime.toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
};
var create = function (info) { var create = function (info) {
var realtime = APP.realtime = info.realtime;
var myID = APP.myID = info.myID; var myID = APP.myID = info.myID;
var editHash; var editHash;
@ -676,10 +682,13 @@ define([
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
} }
APP.patchText = TextPatcher.create({ if (APP.realtime !== info.realtime) {
realtime: realtime, APP.realtime = info.realtime;
logging: true, APP.patchText = TextPatcher.create({
}); realtime: info.realtime,
logging: true,
});
}
userList = APP.userList = info.userList; userList = APP.userList = info.userList;
@ -766,7 +775,8 @@ define([
}); });
}); });
}) })
.on('disconnect', disconnect); .on('disconnect', disconnect)
.on('reconnect', reconnect);
Cryptpad.getAttribute(HIDE_INTRODUCTION_TEXT, function (e, value) { Cryptpad.getAttribute(HIDE_INTRODUCTION_TEXT, function (e, value) {
if (e) { console.error(e); } if (e) { console.error(e); }

View File

@ -2,7 +2,7 @@ require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/J
define([ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar.js', '/common/toolbar.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
@ -678,12 +678,15 @@ define([
}; };
var onReady = config.onReady = function (info) { var onReady = config.onReady = function (info) {
var realtime = module.realtime = info.realtime;
module.users = info.userList.users; module.users = info.userList.users;
module.patchText = TextPatcher.create({
realtime: realtime, if (module.realtime !== info.realtime) {
//logging: true var realtime = module.realtime = info.realtime;
}); module.patchText = TextPatcher.create({
realtime: realtime,
//logging: true
});
}
var userDoc = module.realtime.getUserDoc(); var userDoc = module.realtime.getUserDoc();