diff options
author | Tor Lillqvist <tml@collabora.com> | 2016-10-07 16:07:50 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2016-11-23 00:11:56 +0100 |
commit | b85cb42727bdbb619184a5a3c5ed7b63fe0a47a6 (patch) | |
tree | f105cc8b81294a9e3c65e69338338a75516c2c7b | |
parent | Refactor this unit test, indentation + fix some silliness (diff) | |
download | online-b85cb42727bdbb619184a5a3c5ed7b63fe0a47a6.tar.gz online-b85cb42727bdbb619184a5a3c5ed7b63fe0a47a6.zip |
An updated preview of a slide should be broadcast to all document clients
Amazingly, this (my third attempt) seems to work.
Add a boolean 'forAllClients' parameter to the loleafget getPreview()
function, and pass it as true in the location where a new preview of
an edited slide is requested.
Add a parameter 'broadcast' to the 'tile' (request) message. Set to
'yes' in the above case. When subscribing to a such tile rendering,
subscribe all sessions of the document.
While at it, drop the default values for the parameters of the
TileDesc constructor. I dislike default values...
Change-Id: Idb438f11c953d791fafe4c890e0497d8dfbaa733
Reviewed-on: https://gerrit.libreoffice.org/29591
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
(cherry picked from commit 8fe58df7594dad926eefaa22dbdb300e9bfa3de9)
-rw-r--r-- | loleaflet/README | 7 | ||||
-rw-r--r-- | loleaflet/reference.html | 15 | ||||
-rw-r--r-- | loleaflet/src/control/Parts.js | 9 | ||||
-rw-r--r-- | loleaflet/src/layer/tile/TileLayer.js | 2 | ||||
-rw-r--r-- | loolwsd/DocumentBroker.cpp | 12 | ||||
-rw-r--r-- | loolwsd/TileDesc.hpp | 18 | ||||
-rw-r--r-- | loolwsd/protocol.txt | 13 | ||||
-rw-r--r-- | loolwsd/test/TileCacheTests.cpp | 2 |
8 files changed, 55 insertions, 23 deletions
diff --git a/loleaflet/README b/loleaflet/README index 9a01968127..bfbadf51cd 100644 --- a/loleaflet/README +++ b/loleaflet/README @@ -178,11 +178,14 @@ Parts (like slides in presentation, or sheets in spreadsheets): map.setPart('next' | 'prev' | partNumber) map.getNumberOfParts() map.getCurrentPartNumber() - map.getPreview(id, index, maxWidth, maxHeight, [options]) + map.getPreview(id, index, maxWidth, maxHeight, [options], forAllClients) + id = the ID of the request so that the response can be identified + index = the part / page 's number + maxWidth / maxHeight = max dimensions so that the ratio is preserved - + options = {autoUpdate: true} - automatically updates the previews + + options = {autoUpdate: <boolean>, broadcast: <boolean>} - + + autoUpdate - boolean, automatically updates the previews + + broadcast - boolean, whether the response (a preview of a slide) should be sent to all clients + viewing the same presentation map.getCustomPreview(id, part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, [options]) + id = the ID of the request so that the response can be identified + part = the part containing the desired preview diff --git a/loleaflet/reference.html b/loleaflet/reference.html index 0b67eb02bc..839d072ac5 100644 --- a/loleaflet/reference.html +++ b/loleaflet/reference.html @@ -1648,8 +1648,7 @@ unexpected behaviour.</h4> </code></td> <td><code>undefined</code></td> <td>Triggers the creation of a preview with the given id, of maximum maxWidth X maxHeight size, of the - page / part with number 'index', keeping the original ration. By passing an - optional parameter {autoUpdate: true}, the preview will be automatically invalidated.</td> + page / part with number 'index', keeping the original ration.</td> </tr> <tr> <td><code><b>getCustomPreview</b>( @@ -1665,8 +1664,7 @@ unexpected behaviour.</h4> </code></td> <td><code>undefined</code></td> <td>Triggers the creation of a preview with the given id, of width X height size, of the - [(tilePosX,tilePosY), (tilePosX + tileWidth, tilePosY + tileHeight)] section of the document. By passing an - optional parameter {autoUpdate: true}, the preview will be automatically invalidated.</td> + [(tilePosX,tilePosY), (tilePosX + tileWidth, tilePosY + tileHeight)] section of the document.</td> </tr> <tr> <td><code><b>removePreviewUpdate</b>( @@ -1711,7 +1709,14 @@ unexpected behaviour.</h4> <tr> <td><code><b>autoUpdate</b></code></td> <td><code>Boolean</code></td> - <td>Whether a new preview is generated automatically when it becomes invalid.</td> + <td>Whether a new preview is generated automatically when it becomes + invalid.</td> + </tr> + <tr> + <td><code><b>broadcast</b></code></td> + <td><code>Boolean</code></td> + <td>Whether new preview should be broadcasted to other clients of same + document.</td> </tr> </table> diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js index 1542b1cee8..cbca779602 100644 --- a/loleaflet/src/control/Parts.js +++ b/loleaflet/src/control/Parts.js @@ -53,7 +53,8 @@ L.Map.include({ if (!this._docPreviews) { this._docPreviews = {}; } - var autoUpdate = options ? options.autoUpdate : false; + var autoUpdate = options ? !!options.autoUpdate : false; + var forAllClients = options ? !!options.broadcast : false; this._docPreviews[id] = {id: id, index: index, maxWidth: maxWidth, maxHeight: maxHeight, autoUpdate: autoUpdate}; var docLayer = this._docLayer; @@ -91,7 +92,8 @@ L.Map.include({ 'tileposy=' + tilePosY + ' ' + 'tilewidth=' + tileWidth + ' ' + 'tileheight=' + tileHeight + ' ' + - 'id=' + id); + 'id=' + id + ' ' + + 'broadcast=' + (forAllClients ? 'yes' : 'no')); }, getCustomPreview: function (id, part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, options) { @@ -109,7 +111,8 @@ L.Map.include({ 'tileposy=' + tilePosY + ' ' + 'tilewidth=' + tileWidth + ' ' + 'tileheight=' + tileHeight + ' ' + - 'id=' + id); + 'id=' + id + ' ' + + 'broadcast=no'); }, removePreviewUpdate: function (id) { diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 7d6aa7a0ff..8eca6a840c 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1878,7 +1878,7 @@ L.TileLayer = L.GridLayer.extend({ preview = this._map._docPreviews[key]; if (preview.autoUpdate) { if (preview.index >= 0) { - this._map.getPreview(preview.id, preview.index, preview.maxWidth, preview.maxHeight, {autoUpdate: true}); + this._map.getPreview(preview.id, preview.index, preview.maxWidth, preview.maxHeight, {autoUpdate: true, broadcast: true}); } else { this._map.getCustomPreview(preview.id, preview.part, preview.width, preview.height, preview.tilePosX, diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index 52f60c78ba..39702cc159 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -680,7 +680,17 @@ void DocumentBroker::handleTileRequest(TileDesc& tile, return; } - tileCache().subscribeToTileRendering(tile, session); + if (tile.getBroadcast()) + { + for (auto& it: _sessions) + { + tileCache().subscribeToTileRendering(tile, it.second); + } + } + else + { + tileCache().subscribeToTileRendering(tile, session); + } // Forward to child to render. LOG_DBG("Sending render request for tile (" << tile.getPart() << ',' << diff --git a/loolwsd/TileDesc.hpp b/loolwsd/TileDesc.hpp index 8ba44bdf6d..5c39e48023 100644 --- a/loolwsd/TileDesc.hpp +++ b/loolwsd/TileDesc.hpp @@ -25,7 +25,7 @@ class TileDesc { public: - TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int ver = -1, int imgSize = 0, int id = -1) : + TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int ver, int imgSize, int id, bool broadcast) : _part(part), _width(width), _height(height), @@ -35,7 +35,8 @@ public: _tileHeight(tileHeight), _ver(ver), _imgSize(imgSize), - _id(id) + _id(id), + _broadcast(broadcast) { if (_part < 0 || _width <= 0 || @@ -62,6 +63,7 @@ public: int getImgSize() const { return _imgSize; } void setImgSize(const int imgSize) { _imgSize = imgSize; } int getId() const { return _id; } + bool getBroadcast() const { return _broadcast; } bool intersectsWithRect(int x, int y, int w, int h) const { @@ -131,6 +133,11 @@ public: oss << " id=" << _id; } + if (_broadcast) + { + oss << " broadcast=yes"; + } + return oss.str(); } @@ -155,12 +162,14 @@ public: pairs[name] = value; } } + std::string s; + bool broadcast = (LOOLProtocol::getTokenString(tokens, "broadcast", s) && s == "yes"); return TileDesc(pairs["part"], pairs["width"], pairs["height"], pairs["tileposx"], pairs["tileposy"], pairs["tilewidth"], pairs["tileheight"], pairs["ver"], - pairs["imgsize"], pairs["id"]); + pairs["imgsize"], pairs["id"], broadcast); } /// Deserialize a TileDesc from a string format. @@ -182,6 +191,7 @@ private: int _ver; //< Versioning support. int _imgSize; //< Used for responses. int _id; + bool _broadcast; }; /// One or more tile header. @@ -243,7 +253,7 @@ private: throw BadArgumentException("Invalid tilecombine descriptor."); } - _tiles.emplace_back(_part, _width, _height, x, y, _tileWidth, _tileHeight, ver, size, id); + _tiles.emplace_back(_part, _width, _height, x, y, _tileWidth, _tileHeight, ver, size, id, false); } } diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt index 9de16062e7..c316b32d1f 100644 --- a/loolwsd/protocol.txt +++ b/loolwsd/protocol.txt @@ -123,14 +123,15 @@ status styles tile part=<partNumber> width=<width> height=<height> tileposx=<xpos> tileposy=<ypos> tilewidth=<tileWidth> -tileheight=<tileHeight> [timestamp=<time>] [id=<id>] +tileheight=<tileHeight> [timestamp=<time>] [id=<id> broadcast=<yesOrNo>] - All parameters are numbers. + Parameters are numbers except broadcast which is 'yes' or 'no'. - Note: id must be echoed back in the response verbatim. It is used - when rendering slide thumbnails of presentation documents, and not - for anything else. It is only useful to loleaflet and will break - it if not returned in the response. + Note: id must be echoed back in the response verbatim. It and the + following parameter, broadcast, are used when rendering slide + previews of presentation documents, and not for anything else. It + is only useful to loleaflet and will break it if not returned in + the response. tilecombine <parameters> diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp index 53430924b0..da115cc69a 100644 --- a/loolwsd/test/TileCacheTests.cpp +++ b/loolwsd/test/TileCacheTests.cpp @@ -152,7 +152,7 @@ void TileCacheTests::testSimple() int tilePosY = 0; int tileWidth = 3840; int tileHeight = 3840; - TileDesc tile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight); + TileDesc tile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, -1, 0, -1, false); // No Cache auto file = tc.lookupTile(tile); |