Offline drive (or team) detection

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

@ -1835,7 +1835,8 @@ define([
//var data = cmdData.data;
var s = getStore(cmdData.teamId);
if (s.offline) {
broadcast([], 'NETWORK_DISCONNECT');
var send = s.id ? s.sendEvent : sendDriveEvent;
send('NETWORK_DISCONNECT');
return void cb({ error: 'OFFLINE' });
}
var cb2 = function (data2) {
@ -2291,17 +2292,18 @@ define([
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
rt.network.disconnect();
rt.realtime.abort();
broadcast([], 'NETWORK_DISCONNECT');
sendDriveEvent('NETWORK_DISCONNECT');
}
});
// Proxy handlers (reconnect only called when the proxy is ready)
rt.proxy.on('disconnect', function () {
store.offline = true;
broadcast([], 'NETWORK_DISCONNECT');
sendDriveEvent('NETWORK_DISCONNECT');
});
rt.proxy.on('reconnect', function (info) {
rt.proxy.on('reconnect', function () {
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()

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

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

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

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

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

Loading…
Cancel
Save