Fix duplicate text bug on reconnect or ACK timeout

This commit is contained in:
yflory
2020-03-16 11:19:04 +01:00
parent a2b6501adb
commit 27c1291182
3 changed files with 11 additions and 6 deletions

View File

@@ -879,7 +879,8 @@ define([
postMessage("LEAVE_PAD", data, cb); postMessage("LEAVE_PAD", data, cb);
}; };
pad.sendPadMsg = function (data, cb) { pad.sendPadMsg = function (data, cb) {
postMessage("SEND_PAD_MSG", data, cb); // -1 ==> no timeout, we may receive the callback only when we reconnect
postMessage("SEND_PAD_MSG", data, cb, { timeout: -1 });
}; };
pad.onReadyEvent = Util.mkEvent(); pad.onReadyEvent = Util.mkEvent();
pad.onMessageEvent = Util.mkEvent(); pad.onMessageEvent = Util.mkEvent();

View File

@@ -45,10 +45,13 @@ define([
var txid = mkTxid(); var txid = mkTxid();
opts = opts || {}; opts = opts || {};
var to = opts.timeout || 30000; var to = opts.timeout || 30000;
var timeout = setTimeout(function () { var timeout;
if (to > 0) {
timeout = setTimeout(function () {
delete queries[txid]; delete queries[txid];
cb('TIMEOUT'); cb('TIMEOUT');
}, to); }, to);
}
acks[txid] = function (err) { acks[txid] = function (err) {
clearTimeout(timeout); clearTimeout(timeout);
delete acks[txid]; delete acks[txid];

View File

@@ -59,10 +59,11 @@ define([
logLevel: logLevel logLevel: logLevel
}); });
chainpad.onMessage(function(message, cb) { chainpad.onMessage(function(message, cb) {
// -1 ==> no timeout, we may receive the callback only when we reconnect
sframeChan.query('Q_RT_MESSAGE', message, function (err) { sframeChan.query('Q_RT_MESSAGE', message, function (err) {
if (!err) { evPatchSent.fire(); } if (!err) { evPatchSent.fire(); }
cb(err); cb(err);
}); }, { timeout: -1 });
}); });
chainpad.onPatch(function () { chainpad.onPatch(function () {
onRemote({ realtime: chainpad }); onRemote({ realtime: chainpad });