loleaflet/README | 7 +++++-- loleaflet/reference.html | 15 ++++++++++----- loleaflet/src/control/Parts.js | 9 ++++++--- loleaflet/src/layer/tile/TileLayer.js | 2 +- loolwsd/DocumentBroker.cpp | 12 +++++++++++- loolwsd/TileDesc.hpp | 18 ++++++++++++++---- loolwsd/protocol.txt | 13 +++++++------ loolwsd/test/TileCacheTests.cpp | 2 +- 8 files changed, 55 insertions(+), 23 deletions(-)
New commits: commit 8fe58df7594dad926eefaa22dbdb300e9bfa3de9 Author: Tor Lillqvist <t...@collabora.com> Date: Fri Oct 7 16:07:50 2016 +0300 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 <pran...@collabora.co.uk> Tested-by: pranavk <pran...@collabora.co.uk> diff --git a/loleaflet/README b/loleaflet/README index 9a01968..bfbadf5 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 0b67eb0..839d072 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 1542b1c..cbca779 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 7d6aa7a..8eca6a8 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 52f60c7..39702cc 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 8ba44bd..5c39e48 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 9de1606..c316b32 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 5343092..da115cc 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); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits