loleaflet/src/layer/tile/TileLayer.js | 4 ++-- loolwsd/ChildSession.cpp | 27 ++++++++++++++------------- loolwsd/ChildSession.hpp | 5 +++++ loolwsd/LOOLKit.cpp | 32 ++++++++++++++++++++++++++++++++ loolwsd/protocol.txt | 7 +++++-- 5 files changed, 58 insertions(+), 17 deletions(-)
New commits: commit 5e4af6165881795f24fa4a5f6b831349e5390360 Author: Pranav Kant <[email protected]> Date: Tue Aug 30 11:16:58 2016 +0530 loleaflet: Use names echoed from loolwsd for cursors Change-Id: Ibcb513889c41aa9ec34903fbe68e3dc28d2d1802 Reviewed-on: https://gerrit.libreoffice.org/28483 Reviewed-by: pranavk <[email protected]> Tested-by: pranavk <[email protected]> diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index ee32550..db783db 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -656,7 +656,7 @@ L.TileLayer = L.GridLayer.extend({ _onAddViewMsg: function(textMsg) { textMsg = textMsg.substring('addview:'.length + 1); var obj = JSON.parse(textMsg); - var viewId = parseInt(obj.viewId); + var viewId = parseInt(obj.id); var username = obj.username; // Ignore if viewid is same as ours @@ -1135,7 +1135,7 @@ L.TileLayer = L.GridLayer.extend({ blink: false, header: true, // we want a 'hat' to our view cursors (which will contain view user names) headerTimeout: 1500, // hide after some interval - headerName: 'Anonymous LOOL User' + headerName: this._map.getViewName(viewId) }; viewCursorMarker = L.cursor(viewCursorPos, viewCursorOptions); this._map.addLayer(viewCursorMarker); commit 7d48cd6f175e57ce701be307bfbf782b308ddee9 Author: Pranav Kant <[email protected]> Date: Tue Aug 30 10:49:49 2016 +0530 loolwsd: Echo back view information to clients View information as of now includes viewid and username associated with the view. Change-Id: If0c4957eb56962eb4b1b1d0c1189dc300fa6b857 Reviewed-on: https://gerrit.libreoffice.org/28482 Reviewed-by: pranavk <[email protected]> Tested-by: pranavk <[email protected]> diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp index 67aae9c..93a2312 100644 --- a/loolwsd/ChildSession.cpp +++ b/loolwsd/ChildSession.cpp @@ -10,6 +10,8 @@ #include "ChildSession.hpp" #include "config.h" +#include <sstream> + #include <Poco/JSON/Object.h> #include <Poco/JSON/Parser.h> #include <Poco/Net/WebSocket.h> @@ -97,10 +99,7 @@ bool ChildSession::_handleInput(const char *buffer, int length) // Refresh the viewIds. sendTextFrame("remallviews:"); - for (const auto viewId : _docManager.getViewIds()) - { - sendTextFrame("addview: " + std::to_string(viewId)); - } + _docManager.notifyCurrentViewOfOtherViews(getId()); const int curPart = _loKitDocument->getPart(); sendTextFrame("curpart: part=" + std::to_string(curPart)); @@ -326,10 +325,18 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT if (_multiView) { + std::ostringstream ossViewInfo; _viewId = _loKitDocument->getView(); const auto viewId = std::to_string(_viewId); - Log::info("Created new view: " + viewId); - _docManager.notifyOtherSessions(getId(), "addview: " + viewId); + + // Create a message object + Object::Ptr viewInfoObj = new Object(); + viewInfoObj->set("id", viewId); + viewInfoObj->set("username", _userName); + viewInfoObj->stringify(ossViewInfo); + + Log::info("Created new view with viewid: [" + viewId + "] for username: [" + _userName + "]."); + _docManager.notifyOtherSessions(getId(), "addview: " + ossViewInfo.str()); } _docType = LOKitHelper::getDocumentTypeAsString(_loKitDocument->get()); @@ -348,13 +355,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT } // Inform this view of other views - for (const auto viewId: _docManager.getViewIds()) - { - if (viewId != _viewId) - { - sendTextFrame("addview: " + std::to_string(viewId)); - } - } + _docManager.notifyCurrentViewOfOtherViews(getId()); Log::info("Loaded session " + getId()); return true; diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp index 649a7d3..3295ab4 100644 --- a/loolwsd/ChildSession.hpp +++ b/loolwsd/ChildSession.hpp @@ -47,6 +47,10 @@ public: /// Send message to all other sessions except 'sessionId' virtual void notifyOtherSessions(const std::string& sessionId, const std::string& message) const = 0; + + /// Send other view's information to current view (one with sessionId) + virtual + void notifyCurrentViewOfOtherViews(const std::string& sessionId) const = 0; }; /// Represents a client session, with the socket end-point, @@ -70,6 +74,7 @@ public: bool getStatus(const char *buffer, int length); bool getPartPageRectangles(const char *buffer, int length); int getViewId() const { return _viewId; } + const std::string getViewUserName() const { return _userName; } void loKitCallback(const int nType, const std::string& rPayload); diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 6f4898d..781610f 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -965,6 +965,38 @@ private: } } + void notifyCurrentViewOfOtherViews(const std::string& sessionId) const override + { + std::unique_lock<std::mutex> lock(_mutex); + + const auto& it = _connections.find(Util::decodeId(sessionId)); + if (it == _connections.end() || !it->second) + { + Log::error("Cannot find current session [" + sessionId + "]."); + return; + } + + auto currentSession = it->second->getSession(); + for (auto& connectionIt: _connections) + { + if (connectionIt.second->isRunning() && connectionIt.second->getSessionId() != sessionId) + { + auto session = connectionIt.second->getSession(); + const auto viewId = session->getViewId(); + const auto viewUserName = session->getViewUserName(); + + // Create a message object + Object::Ptr viewInfoObj = new Object(); + viewInfoObj->set("id", viewId); + viewInfoObj->set("username", viewUserName); + std::ostringstream ossViewInfo; + viewInfoObj->stringify(ossViewInfo); + + currentSession->sendTextFrame("addview: " + ossViewInfo.str()); + } + } + } + private: std::shared_ptr<lok::Document> load(const std::string& sessionId, diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt index 396a359..332d088 100644 --- a/loolwsd/protocol.txt +++ b/loolwsd/protocol.txt @@ -332,9 +332,12 @@ viewlock: Per-view lock rectangle. JSON payload. -addview: <viewId> +addview: <JSON string> - New view with the given viewId is created. + Eg: {"id": "<viewid>", + "username": "<name of the user>"} + + New view with the given view information is created. remview: <viewId> _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
