Offline drive (or team) detection

pull/1/head
yflory 5 years ago
parent 63ea882545
commit c9c19b8395

@ -1835,8 +1835,9 @@ define([
//var data = cmdData.data; //var data = cmdData.data;
var s = getStore(cmdData.teamId); var s = getStore(cmdData.teamId);
if (s.offline) { if (s.offline) {
broadcast([], 'NETWORK_DISCONNECT'); var send = s.id ? s.sendEvent : sendDriveEvent;
return void cb({ error: 'OFFLINE' }); send('NETWORK_DISCONNECT');
return void cb({ error: 'OFFLINE' });
} }
var cb2 = function (data2) { var cb2 = function (data2) {
// Send the CHANGE event to all the stores because the command may have // Send the CHANGE event to all the stores because the command may have
@ -2291,17 +2292,18 @@ define([
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) { if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
rt.network.disconnect(); rt.network.disconnect();
rt.realtime.abort(); rt.realtime.abort();
broadcast([], 'NETWORK_DISCONNECT'); sendDriveEvent('NETWORK_DISCONNECT');
} }
}); });
// Proxy handlers (reconnect only called when the proxy is ready)
rt.proxy.on('disconnect', function () { rt.proxy.on('disconnect', function () {
store.offline = true; store.offline = true;
broadcast([], 'NETWORK_DISCONNECT'); sendDriveEvent('NETWORK_DISCONNECT');
}); });
rt.proxy.on('reconnect', function (info) { rt.proxy.on('reconnect', function () {
store.offline = false; store.offline = false;
broadcast([], 'NETWORK_RECONNECT', {myId: info.myId}); sendDriveEvent('NETWORK_RECONNECT');
}); });
// Ping clients regularly to make sure one tab was not closed without sending a removeClient() // Ping clients regularly to make sure one tab was not closed without sending a removeClient()

@ -57,6 +57,14 @@ define([
return false; return false;
} }
}); });
proxy.on('disconnect', function () {
team.offline = true;
team.sendEvent('NETWORK_DISCONNECT');
});
proxy.on('reconnect', function () {
team.offline = false;
team.sendEvent('NETWORK_RECONNECT');
});
} }
proxy.on('change', [], function (o, n, p) { proxy.on('change', [], function (o, n, p) {
if (fId) { if (fId) {
@ -101,12 +109,6 @@ define([
path: p path: p
}); });
}); });
proxy.on('disconnect', function () {
team.offline = true;
});
proxy.on('reconnect', function (/* info */) {
team.offline = false;
});
}; };
var closeTeam = function (ctx, teamId) { var closeTeam = function (ctx, teamId) {
@ -1363,6 +1365,10 @@ define([
removeClient(ctx, clientId); removeClient(ctx, clientId);
}; };
team.execCommand = function (clientId, obj, cb) { team.execCommand = function (clientId, obj, cb) {
if (ctx.store.offline) {
return void cb({ error: 'OFFLINE' });
}
var cmd = obj.cmd; var cmd = obj.cmd;
var data = obj.data; var data = obj.data;
if (cmd === 'SUBSCRIBE') { if (cmd === 'SUBSCRIBE') {

@ -274,10 +274,10 @@ define([
APP.toolbar.failed(); APP.toolbar.failed();
if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); } if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); }
}; };
var onReconnect = function (info) { var onReconnect = function () {
setEditable(true); setEditable(true);
if (drive.refresh) { drive.refresh(); } if (drive.refresh) { drive.refresh(); }
APP.toolbar.reconnecting(info.myId); APP.toolbar.reconnecting();
UI.findOKButton().click(); UI.findOKButton().click();
}; };
@ -287,9 +287,8 @@ define([
sframeChan.on('EV_NETWORK_DISCONNECT', function () { sframeChan.on('EV_NETWORK_DISCONNECT', function () {
onDisconnect(); onDisconnect();
}); });
sframeChan.on('EV_NETWORK_RECONNECT', function (data) { sframeChan.on('EV_NETWORK_RECONNECT', function () {
// data.myId; onReconnect();
onReconnect(data);
}); });
common.onLogout(function () { setEditable(false); }); common.onLogout(function () { setEditable(false); });
}); });

@ -94,8 +94,8 @@ define([
Cryptpad.onNetworkDisconnect.reg(function () { Cryptpad.onNetworkDisconnect.reg(function () {
sframeChan.event('EV_NETWORK_DISCONNECT'); sframeChan.event('EV_NETWORK_DISCONNECT');
}); });
Cryptpad.onNetworkReconnect.reg(function (data) { Cryptpad.onNetworkReconnect.reg(function () {
sframeChan.event('EV_NETWORK_RECONNECT', data); sframeChan.event('EV_NETWORK_RECONNECT');
}); });
Cryptpad.drive.onLog.reg(function (msg) { Cryptpad.drive.onLog.reg(function (msg) {
sframeChan.event('EV_DRIVE_LOG', msg); sframeChan.event('EV_DRIVE_LOG', msg);

@ -368,6 +368,7 @@ define([
var content = []; var content = [];
APP.module.execCommand('LIST_TEAMS', null, function (obj) { APP.module.execCommand('LIST_TEAMS', null, function (obj) {
if (!obj) { return; } if (!obj) { return; }
if (obj.error === "OFFLINE") { return UI.alert(Messages.driveOfflineError); }
if (obj.error) { return void console.error(obj.error); } if (obj.error) { return void console.error(obj.error); }
var list = []; var list = [];
var keys = Object.keys(obj).slice(0,3); var keys = Object.keys(obj).slice(0,3);
@ -453,6 +454,7 @@ define([
name: name name: name
}, function (obj) { }, function (obj) {
if (obj && obj.error) { if (obj && obj.error) {
if (obj.error === "OFFLINE") { return UI.alert(Messages.driveOfflineError); }
console.error(obj.error); console.error(obj.error);
$spinner.hide(); $spinner.hide();
return void UI.warn(Messages.error); return void UI.warn(Messages.error);
@ -1125,10 +1127,10 @@ define([
toolbar.failed(); toolbar.failed();
if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); } if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); }
}; };
var onReconnect = function (info) { var onReconnect = function () {
setEditable(true); setEditable(true);
if (APP.team && driveAPP.refresh) { driveAPP.refresh(); } if (APP.team && driveAPP.refresh) { driveAPP.refresh(); }
toolbar.reconnecting(info.myId); toolbar.reconnecting();
UI.findOKButton().click(); UI.findOKButton().click();
}; };
@ -1138,9 +1140,8 @@ define([
sframeChan.on('EV_NETWORK_DISCONNECT', function () { sframeChan.on('EV_NETWORK_DISCONNECT', function () {
onDisconnect(); onDisconnect();
}); });
sframeChan.on('EV_NETWORK_RECONNECT', function (data) { sframeChan.on('EV_NETWORK_RECONNECT', function () {
// data.myId; onReconnect();
onReconnect(data);
}); });
common.onLogout(function () { setEditable(false); }); common.onLogout(function () { setEditable(false); });
}); });

@ -69,14 +69,21 @@ define([
Cryptpad.onNetworkDisconnect.reg(function () { Cryptpad.onNetworkDisconnect.reg(function () {
sframeChan.event('EV_NETWORK_DISCONNECT'); sframeChan.event('EV_NETWORK_DISCONNECT');
}); });
Cryptpad.onNetworkReconnect.reg(function (data) { Cryptpad.onNetworkReconnect.reg(function () {
sframeChan.event('EV_NETWORK_RECONNECT', data); sframeChan.event('EV_NETWORK_RECONNECT');
}); });
Cryptpad.universal.onEvent.reg(function (obj) { Cryptpad.universal.onEvent.reg(function (obj) {
// Intercept events for the team drive and send them the required way // Intercept events for the team drive and send them the required way
if (obj.type !== 'team' || if (obj.type !== 'team') { return; }
['DRIVE_CHANGE', 'DRIVE_LOG', 'DRIVE_REMOVE'].indexOf(obj.data.ev) === -1) { return; } if (['DRIVE_CHANGE', 'DRIVE_LOG', 'DRIVE_REMOVE'].indexOf(obj.data.ev) !== -1) {
sframeChan.event('EV_'+obj.data.ev, obj.data.data); sframeChan.event('EV_'+obj.data.ev, obj.data.data);
}
if (obj.data.ev === 'NETWORK_RECONNECT') {
sframeChan.event('EV_NETWORK_RECONNECT');
}
if (obj.data.ev === 'NETWORK_DISCONNECT') {
sframeChan.event('EV_NETWORK_DISCONNECT');
}
}); });
}; };
SFCommonO.start({ SFCommonO.start({

Loading…
Cancel
Save