[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/MasterProcessSession.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Apr 21 05:31:36 UTC 2016


 loolwsd/ChildProcessSession.cpp  |   23 ++++++++++++++++++++---
 loolwsd/LOOLSession.cpp          |    1 +
 loolwsd/LOOLSession.hpp          |    5 ++++-
 loolwsd/MasterProcessSession.cpp |    7 +++++--
 4 files changed, 30 insertions(+), 6 deletions(-)

New commits:
commit 5fbaa8f3d21e89d1b5a11bb33a4812fe88add890
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Apr 21 01:14:27 2016 -0400

    loolwsd: useractive and userinactive command support
    
    loleaflet can now send userinactive when the user
    has switched tabs or the browser window loses
    focus. Similarly, it can send useractive when
    focus is regained.
    
    Change-Id: Id3186949b10a8263e29ada1a790d3123a79e8f08
    Reviewed-on: https://gerrit.libreoffice.org/24272
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 7fbebcf..a5529d7 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -88,7 +88,7 @@ public:
             Log::trace("Skipping callback on disconnected session " + _session.getName());
             return;
         }
-        else if (_session.isInactive())
+        else if (!_session.isActive())
         {
             Log::trace("Skipping callback on inactive session " + _session.getName());
             return;
@@ -307,7 +307,7 @@ void ChildProcessSession::disconnect()
 
 bool ChildProcessSession::_handleInput(const char *buffer, int length)
 {
-    if (isInactive() && _loKitDocument != nullptr)
+    if (!isActive() && _loKitDocument != nullptr)
     {
         Log::debug("Handling message after inactivity of " + std::to_string(getInactivityMS()) + "ms.");
 
@@ -375,6 +375,13 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length)
     }
     else if (!_isDocLoaded)
     {
+        // Be forgiving to these messages while we load.
+        if (tokens[0] == "useractive" ||
+            tokens[0] == "userinactive")
+        {
+            return true;
+        }
+
         sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
         return false;
     }
@@ -420,7 +427,9 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length)
                tokens[0] == "selecttext" ||
                tokens[0] == "selectgraphic" ||
                tokens[0] == "resetselection" ||
-               tokens[0] == "saveas");
+               tokens[0] == "saveas" ||
+               tokens[0] == "useractive" ||
+               tokens[0] == "userinactive");
 
         {
             std::unique_lock<std::recursive_mutex> lock(Mutex);
@@ -490,6 +499,14 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length)
         {
             return saveAs(buffer, length, tokens);
         }
+        else if (tokens[0] == "useractive")
+        {
+            setIsActive(true);
+        }
+        else if (tokens[0] == "userinactive")
+        {
+            setIsActive(false);
+        }
         else
         {
             assert(false);
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 090f2ed..d755ef8 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -58,6 +58,7 @@ LOOLSession::LOOLSession(const std::string& id, const Kind kind,
     _isDocPasswordProtected(false),
     _isCloseFrame(false),
     _disconnected(false),
+    _isActive(true),
     _lastActivityTime(std::chrono::steady_clock::now())
 {
     // Only a post request can have a null ws.
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 617b159..926895b 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -55,7 +55,8 @@ public:
     /// Called to handle disconnection command from socket.
     virtual bool handleDisconnect();
 
-    bool isInactive() const { return getInactivityMS() >= InactivityThresholdMS; }
+    bool isActive() const { return _isActive; }
+    void setIsActive(bool isActive) { _isActive = isActive; }
 
     /// Returns the inactivity time of the client in milliseconds.
     double getInactivityMS() const
@@ -143,6 +144,8 @@ private:
     std::string _name;
     /// True if we have been disconnected.
     bool _disconnected;
+    /// True if the user is active, otherwise false (switched tabs).
+    bool _isActive;
 
     std::chrono::steady_clock::time_point _lastActivityTime;
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 0dee495..b7ae049 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -319,7 +319,9 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
              tokens[0] != "status" &&
              tokens[0] != "tile" &&
              tokens[0] != "tilecombine" &&
-             tokens[0] != "uno")
+             tokens[0] != "uno" &&
+             tokens[0] != "useractive" &&
+             tokens[0] != "userinactive")
     {
         sendTextFrame("error: cmd=" + tokens[0] + " kind=unknown");
         return false;
@@ -380,7 +382,8 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
         }
 
         // Allow 'downloadas' for all kinds of views irrespective of editlock
-        if (_kind == Kind::ToClient && !isEditLocked() && tokens[0] != "downloadas")
+        if (_kind == Kind::ToClient && !isEditLocked() && tokens[0] != "downloadas" &&
+            tokens[0] != "userinactive" && tokens[0] != "useractive")
         {
             std::string dummyFrame = "dummymsg";
             forwardToPeer(dummyFrame.c_str(), dummyFrame.size());


More information about the Libreoffice-commits mailing list