diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 8d29353c9..5900601e8 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1835,8 +1835,9 @@ define([ //var data = cmdData.data; var s = getStore(cmdData.teamId); if (s.offline) { - broadcast([], 'NETWORK_DISCONNECT'); - return void cb({ error: 'OFFLINE' }); + var send = s.id ? s.sendEvent : sendDriveEvent; + send('NETWORK_DISCONNECT'); + return void cb({ error: 'OFFLINE' }); } var cb2 = function (data2) { // 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) { 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() diff --git a/www/common/outer/team.js b/www/common/outer/team.js index b1be2baea..9c33a722a 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -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') { diff --git a/www/drive/inner.js b/www/drive/inner.js index e2415d2d0..03bf73697 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -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); }); }); diff --git a/www/drive/main.js b/www/drive/main.js index 0cda8a9cc..bd2e506d4 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -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); diff --git a/www/teams/inner.js b/www/teams/inner.js index 974f75d28..4ba4cf2f4 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -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); }); }); diff --git a/www/teams/main.js b/www/teams/main.js index d37de141c..f12308207 100644 --- a/www/teams/main.js +++ b/www/teams/main.js @@ -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; } - sframeChan.event('EV_'+obj.data.ev, obj.data.data); + 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({