add api to check whether the realtime has synced with the server

This commit is contained in:
ansuz
2017-02-13 10:42:17 +01:00
parent 3b1bd2f720
commit f723585758
2 changed files with 14 additions and 14 deletions

View File

@@ -44,6 +44,18 @@ define([
return; return;
}; };
var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) {
realtime.sync();
var interval = 300;
var check = function () {
if (realtime.getAuthDoc() !== realtime.getUserDoc()) {
return window.setTimeout(check, interval);
}
cb();
};
window.setTimeout(check, interval);
};
var getWebsocketURL = common.getWebsocketURL = function () { var getWebsocketURL = common.getWebsocketURL = function () {
if (!Config.websocketPath) { return Config.websocketURL; } if (!Config.websocketPath) { return Config.websocketURL; }
var path = Config.websocketPath; var path = Config.websocketPath;

View File

@@ -51,7 +51,7 @@ define([
} }
[ $uname, $passwd, $confirm] [ $uname, $passwd, $confirm]
.some(function ($el) { if (!$el.val()) { return ($el.focus(), true); } }); .some(function ($el) { if (!$el.val()) { $el.focus(); return true; } });
// checkboxes // checkboxes
var $checkImport = $('#import-recent'); var $checkImport = $('#import-recent');
@@ -60,18 +60,6 @@ define([
var $register = $('button#register'); var $register = $('button#register');
var proxyIsSynced = function (realtime, cb) {
realtime.sync();
var interval = 300;
var check = function () {
if (realtime.getAuthDoc() !== realtime.getUserDoc()) {
return window.setTimeout(check, interval);
}
cb();
};
window.setTimeout(check, interval);
};
$register.click(function () { $register.click(function () {
var uname = $uname.val(); var uname = $uname.val();
var passwd = $passwd.val(); var passwd = $passwd.val();
@@ -108,7 +96,7 @@ define([
proxy.login_name = uname; proxy.login_name = uname;
proxyIsSynced(result.realtime, function () { Cryptpad.whenRealtimeSyncs(result.realtime, function () {
document.location.href = '/drive/'; document.location.href = '/drive/';
}); });
}); });