loleaflet: new event, docloaded, to sync. various things
First, use the docloaded event to see whether we should be dimming the document (make it inactive) or not. There is no point in inactivating a document before document has completely loaded; so don't start the timer until after the document is completely loaded. It turns out that we were only emitting the WOPI's App_LoadingStatus with DocumentLoaded for the first document load, but not for subsequent reconnections. The problem here was that doclayerinit event is only emitted during first document load (when TileLayer is -actually- initialized), which was responsible for emitting this event. By bifurcating the document load from document layer initialization, we solve this problem. Change-Id: I0b7b97fc6244ba9ebd6318d68d78d3abef2c0c08
This commit is contained in:
parent
a75b780b8a
commit
d0be89bffa
3 changed files with 85 additions and 57 deletions
|
@ -62,6 +62,9 @@ L.Socket = L.Class.extend({
|
|||
this.socket.onmessage = function () {};
|
||||
this.socket.close();
|
||||
|
||||
// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization
|
||||
this._map['wopi'].resetAppLoaded();
|
||||
this._map.fire('docloaded', {status: false});
|
||||
clearTimeout(this._accessTokenExpireTimeout);
|
||||
},
|
||||
|
||||
|
@ -574,59 +577,64 @@ L.Socket = L.Class.extend({
|
|||
var img = 'data:image/png;base64,' + window.btoa(strBytes);
|
||||
}
|
||||
|
||||
if (textMsg.startsWith('status:') && !this._map._docLayer) {
|
||||
// first status message, we need to create the document layer
|
||||
var tileWidthTwips = this._map.options.tileWidthTwips;
|
||||
var tileHeightTwips = this._map.options.tileHeightTwips;
|
||||
if (this._map.options.zoom !== this._map.options.defaultZoom) {
|
||||
var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom);
|
||||
tileWidthTwips = Math.round(tileWidthTwips * scale);
|
||||
tileHeightTwips = Math.round(tileHeightTwips * scale);
|
||||
}
|
||||
|
||||
var docLayer = null;
|
||||
if (command.type === 'text') {
|
||||
docLayer = new L.WriterTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
}
|
||||
else if (command.type === 'spreadsheet') {
|
||||
docLayer = new L.CalcTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (command.type === 'presentation' &&
|
||||
this._map.options.defaultZoom === this._map.options.zoom) {
|
||||
// If we have a presentation document and the zoom level has not been set
|
||||
// in the options, resize the document so that it fits the viewing area
|
||||
var verticalTiles = this._map.getSize().y / 256;
|
||||
tileWidthTwips = Math.round(command.height / verticalTiles);
|
||||
tileHeightTwips = Math.round(command.height / verticalTiles);
|
||||
if (textMsg.startsWith('status:')) {
|
||||
if (!this._map._docLayer) {
|
||||
// first status message, we need to create the document layer
|
||||
var tileWidthTwips = this._map.options.tileWidthTwips;
|
||||
var tileHeightTwips = this._map.options.tileHeightTwips;
|
||||
if (this._map.options.zoom !== this._map.options.defaultZoom) {
|
||||
var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom);
|
||||
tileWidthTwips = Math.round(tileWidthTwips * scale);
|
||||
tileHeightTwips = Math.round(tileHeightTwips * scale);
|
||||
}
|
||||
docLayer = new L.ImpressTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
|
||||
var docLayer = null;
|
||||
if (command.type === 'text') {
|
||||
docLayer = new L.WriterTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
}
|
||||
else if (command.type === 'spreadsheet') {
|
||||
docLayer = new L.CalcTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (command.type === 'presentation' &&
|
||||
this._map.options.defaultZoom === this._map.options.zoom) {
|
||||
// If we have a presentation document and the zoom level has not been set
|
||||
// in the options, resize the document so that it fits the viewing area
|
||||
var verticalTiles = this._map.getSize().y / 256;
|
||||
tileWidthTwips = Math.round(command.height / verticalTiles);
|
||||
tileHeightTwips = Math.round(command.height / verticalTiles);
|
||||
}
|
||||
docLayer = new L.ImpressTileLayer('', {
|
||||
permission: this._map.options.permission,
|
||||
tileWidthTwips: tileWidthTwips,
|
||||
tileHeightTwips: tileHeightTwips,
|
||||
docType: command.type
|
||||
});
|
||||
}
|
||||
|
||||
this._map._docLayer = docLayer;
|
||||
this._map.addLayer(docLayer);
|
||||
this._map.fire('doclayerinit');
|
||||
}
|
||||
else if (this._reconnecting) {
|
||||
// we are reconnecting ...
|
||||
this._reconnecting = false;
|
||||
this._map._docLayer._onMessage('invalidatetiles: EMPTY', null);
|
||||
this._map.fire('statusindicator', {statusType: 'reconnected'});
|
||||
this._map.setPermission(this._map.options.permission);
|
||||
}
|
||||
|
||||
this._map._docLayer = docLayer;
|
||||
this._map.addLayer(docLayer);
|
||||
this._map.fire('doclayerinit');
|
||||
} else if (textMsg.startsWith('status:') && this._reconnecting) {
|
||||
// we are reconnecting ...
|
||||
this._reconnecting = false;
|
||||
this._map._docLayer._onMessage('invalidatetiles: EMPTY', null);
|
||||
this._map.fire('statusindicator', {statusType: 'reconnected'});
|
||||
this._map.setPermission(this._map.options.permission);
|
||||
this._map.fire('docloaded', {status: true});
|
||||
}
|
||||
|
||||
// these can arrive very early during the startup
|
||||
|
@ -671,8 +679,9 @@ L.Socket = L.Class.extend({
|
|||
this._map.fire('error', {msg: _('Well, this is embarrassing, we cannot connect to your document. Please try again.'), cmd: 'socket', kind: 'closed', id: 4});
|
||||
}
|
||||
|
||||
// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization again
|
||||
// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization
|
||||
this._map['wopi'].resetAppLoaded();
|
||||
this._map.fire('docloaded', {status: false});
|
||||
|
||||
if (!this._reconnecting) {
|
||||
this._reconnecting = true;
|
||||
|
|
|
@ -143,10 +143,24 @@ L.Map = L.Evented.extend({
|
|||
// This becomes true if document was ever modified by the user
|
||||
this._everModified = false;
|
||||
|
||||
// Document is completely loaded or not
|
||||
this._docLoaded = false;
|
||||
|
||||
this.on('commandstatechanged', function(e) {
|
||||
if (e.commandName === '.uno:ModifiedStatus')
|
||||
this._everModified = this._everModified || (e.state === 'true');
|
||||
}, this);
|
||||
|
||||
this.on('docloaded', function(e) {
|
||||
if (e.status) {
|
||||
// so that dim timer starts from now()
|
||||
this.lastActiveTime = Date.now();
|
||||
if (!document.hasFocus()) {
|
||||
this._deactivate();
|
||||
}
|
||||
}
|
||||
this._docLoaded = e.status;
|
||||
}, this);
|
||||
},
|
||||
|
||||
// public methods that modify map state
|
||||
|
@ -883,7 +897,8 @@ L.Map = L.Evented.extend({
|
|||
|
||||
_dimIfInactive: function () {
|
||||
console.debug('_dimIfInactive: diff=' + (Date.now() - this.lastActiveTime));
|
||||
if ((Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) {
|
||||
if (this._docLoaded && // don't dim if document hasn't been loaded yet
|
||||
(Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) {
|
||||
this._dim();
|
||||
} else {
|
||||
this._startInactiveTimer();
|
||||
|
@ -904,7 +919,7 @@ L.Map = L.Evented.extend({
|
|||
},
|
||||
|
||||
_deactivate: function () {
|
||||
if (this._serverRecycling || this._documentIdle) {
|
||||
if (this._serverRecycling || this._documentIdle || !this._docLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ L.Map.WOPI = L.Handler.extend({
|
|||
DisableCopy: false,
|
||||
|
||||
_appLoadedConditions: {
|
||||
doclayerinit: false,
|
||||
docloaded: false,
|
||||
updatepermission: false,
|
||||
viewinfo: false /* Whether view information has already arrived */
|
||||
},
|
||||
|
@ -32,7 +32,7 @@ L.Map.WOPI = L.Handler.extend({
|
|||
this._map.on('postMessage', this._postMessage, this);
|
||||
|
||||
// init messages
|
||||
this._map.on('doclayerinit', this._postLoaded, this);
|
||||
this._map.on('docloaded', this._postLoaded, this);
|
||||
this._map.on('updatepermission', this._postLoaded, this);
|
||||
// This indicates that 'viewinfo' message has already arrived
|
||||
this._map.on('viewinfo', this._postLoaded, this);
|
||||
|
@ -45,7 +45,7 @@ L.Map.WOPI = L.Handler.extend({
|
|||
this._map.off('postMessage', this._postMessage, this);
|
||||
|
||||
// init messages
|
||||
this._map.off('doclayerinit', this._postLoaded, this);
|
||||
this._map.off('docloaded', this._postLoaded, this);
|
||||
this._map.off('updatepermission', this._postLoaded, this);
|
||||
this._map.off('viewinfo', this._postLoaded, this);
|
||||
|
||||
|
@ -81,7 +81,11 @@ L.Map.WOPI = L.Handler.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
if (e.type === 'doclayerinit') {
|
||||
if (e.type === 'docloaded') {
|
||||
// doc unloaded
|
||||
if (!e.status)
|
||||
return;
|
||||
|
||||
this.DocumentLoadedTime = Date.now();
|
||||
}
|
||||
this._appLoadedConditions[e.type] = true;
|
||||
|
|
Loading…
Reference in a new issue