loleaflet/src/core/Socket.js | 12 ++++++++++++ wsd/ClientSession.cpp | 5 ++++- wsd/DocumentBroker.cpp | 18 +++++++++++++----- wsd/DocumentBroker.hpp | 3 +++ wsd/protocol.txt | 14 +++++++++----- 5 files changed, 41 insertions(+), 11 deletions(-)
New commits: commit 2491146606b92db70529e2f6255c767d4daa8b32 Author: Pranav Kant <pran...@collabora.co.uk> Date: Thu Jun 1 21:41:11 2017 +0530 Broadcast command result back to clients This is required to tell the clients if the command they issued was successfull or not. In this case 'savetostorage' is the command that we are interested in knowing the success status of. With this, now if the user commands to overwrite the document, dialog boxes of all other users are automatically closed. Can easily more commands in future for this kind of thing. Its similar to unocommandresult, except its not a uno command, but our internal command. Change-Id: I2e7e1fd5edbd55c13ee4bf9bce24284483d6507f (cherry picked from commit f4b22bbb3c82c1e841934f98280f5deb2256f326) Reviewed-on: https://gerrit.libreoffice.org/38533 Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 8abb1898..fa03820a 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -223,6 +223,18 @@ L.Socket = L.Class.extend({ this._map.fire('wopiprops', wopiInfo); return; } + else if (textMsg.startsWith('commandresult: ')) { + var commandresult = JSON.parse(textMsg.substring(textMsg.indexOf('{'))); + if (commandresult['command'] === 'savetostorage' && commandresult['success']) { + // Close any open confirmation dialogs + if (vex.dialogID > 0) { + var id = vex.dialogID; + vex.dialogID = -1; + vex.close(id); + } + } + return; + } else if (textMsg.startsWith('close: ')) { textMsg = textMsg.substring('close: '.length); msg = ''; diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 5dd4c278..64e7ea94 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -224,7 +224,10 @@ bool ClientSession::_handleInput(const char *buffer, int length) { int force = 0; getTokenInteger(tokens[1], "force", force); - docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true); + if (docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true)) + { + docBroker->broadcastMessage("commandresult: { \"command\": \"savetostorage\", \"success\": true }"); + } } else { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index d1ad267b..850baf66 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -626,6 +626,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId, // So set _documentLastModifiedTime then _documentLastModifiedTime = _storage->getFileInfo()._modifiedTime; + // After a successful save, we are sure that document in the storage is same as ours _documentChangedInStorage = false; @@ -661,11 +662,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId, { LOG_ERR("PutFile says that Document changed in storage"); _documentChangedInStorage = true; - // Inform all clients - for (const auto& sessionIt : _sessions) - { - sessionIt.second->sendTextFrame("error: cmd=storage kind=documentconflict"); - } + broadcastMessage("error: cmd=storage kind=documentconflict"); } return false; @@ -1416,6 +1413,17 @@ void DocumentBroker::closeDocument(const std::string& reason) terminateChild(reason, false); } +void DocumentBroker::broadcastMessage(const std::string& message) +{ + assertCorrectThread(); + + LOG_DBG("Broadcasting message [" << message << "] to all sessions."); + for (const auto& sessionIt : _sessions) + { + sessionIt.second->sendTextFrame(message); + } +} + void DocumentBroker::updateLastActivityTime() { _lastActivityTime = std::chrono::steady_clock::now(); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 92de36c2..03bca722 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -340,6 +340,9 @@ public: /// Sends the .uno:Save command to LoKit. bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = true, bool dontSaveIfUnmodified = true); + /// Sends a message to all sessions + void broadcastMessage(const std::string& message); + private: /// Shutdown all client connections with the given reason. diff --git a/wsd/protocol.txt b/wsd/protocol.txt index 021dfc35..e775a605 100644 --- a/wsd/protocol.txt +++ b/wsd/protocol.txt @@ -334,6 +334,10 @@ tile: part=<partNumber> width=<width> height=<height> tileposx=<xpos> tileposy=< a hash of the tile contents, and can be included by the client in the next 'tile' message requesting the same tile. +commandresult: <payload> + This is used to acknowledge the commands from the client. + <payload> is { command: <command name>, success: 'true' } + Each LOK_CALLBACK_FOO_BAR callback except LOK_CALLBACK_INVALIDATE_TILES causes a corresponding message to the client, consisting of the FOO_BAR part in lowercase, without @@ -343,12 +347,12 @@ message as documented above.) For instance: invalidatecursor: <payload> -The payload contains a rectangle describing the cursor position. + The payload contains a rectangle describing the cursor position. -The communication between the parent process (the one keeping open the -Websocket connections to the clients) and a child process (handling -one document through LibreOfficeKit) uses the same protocol, with -the following additions and changes: + The communication between the parent process (the one keeping open the + Websocket connections to the clients) and a child process (handling + one document through LibreOfficeKit) uses the same protocol, with + the following additions and changes: unocommandresult: <payload> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits