[Libreoffice-commits] online.git: loolwsd/ChildSession.cpp loolwsd/ChildSession.hpp loolwsd/LOOLKit.cpp

Pranav Kant pranavk at collabora.co.uk
Thu Aug 25 18:26:49 UTC 2016


 loolwsd/ChildSession.cpp |    2 +-
 loolwsd/ChildSession.hpp |    4 ++++
 loolwsd/LOOLKit.cpp      |   17 +++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 178808f9893ce51d1906bfd1ff7e19da8920c823
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Aug 25 23:28:42 2016 +0530

    loolwsd: Notify other views when new view is added
    
    ... but no need to notify the one which is just added.
    
    Earlier behavior was notifying only the one which is just added,
    which is redundant as same is accomplished by 'status' message.
    
    Change-Id: Ib09424d186c49527b7b9c36fdabf90c31518ee04
    Reviewed-on: https://gerrit.libreoffice.org/28395
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp
index a0bb227..4f0d91e 100644
--- a/loolwsd/ChildSession.cpp
+++ b/loolwsd/ChildSession.cpp
@@ -327,7 +327,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT
         _viewId = _loKitDocument->getView();
         const auto viewId = std::to_string(_viewId);
         Log::info("Created new view: " + viewId);
-        sendTextFrame("addview: " + viewId);
+        _docManager.notifyOtherSessions(getId(), "addview: " + viewId);
     }
 
     _docType = LOKitHelper::getDocumentTypeAsString(_loKitDocument->get());
diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp
index ddb804f..7bd5122 100644
--- a/loolwsd/ChildSession.hpp
+++ b/loolwsd/ChildSession.hpp
@@ -42,6 +42,10 @@ public:
     /// Get a list of all current view IDs.
     virtual
     std::vector<unsigned> getViewIds() const = 0;
+
+    /// Send message to all other sessions except 'sessionId'
+    virtual
+    void notifyOtherSessions(const std::string& sessionId, const std::string& message) const = 0;
 };
 
 /// Represents a client session, with the socket end-point,
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index b73779e..0316835 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -942,6 +942,23 @@ private:
         return v;
     }
 
+    void notifyOtherSessions(const std::string& sessionId, const std::string& message) const override
+    {
+        std::unique_lock<std::mutex> lock(_mutex);
+
+        for (auto& it: _connections)
+        {
+            if (it.second->isRunning() && it.second->getSessionId() != sessionId)
+            {
+                auto session = it.second->getSession();
+                if (session)
+                {
+                    session->sendTextFrame(message);
+                }
+            }
+        }
+    }
+
 private:
 
     std::shared_ptr<lok::Document> load(const std::string& sessionId,


More information about the Libreoffice-commits mailing list