Skip to content

Commit

Permalink
delayed message can be applied when _map._docLayer becomes available
Browse files Browse the repository at this point in the history
without a need for an additional timer to poll when that is possible.

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: Ia019d8d8516f8c9156f3e96be262138a16343983
  • Loading branch information
caolanm committed Oct 9, 2023
1 parent f96622b commit 6eead7b
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions browser/src/core/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ app.definitions.Socket = L.Class.extend({
this._map = map;
this._msgQueue = [];
this._delayedMessages = [];
this._handlingDelayedMessages = false;
},

getWebSocketBaseURI: function(map) {
Expand Down Expand Up @@ -348,8 +347,8 @@ app.definitions.Socket = L.Class.extend({
}
catch (e)
{
// unpleasant - but stops this one problem
// event stopping an unknown number of others.
// unpleasant - but stops this one problem event
// stopping an unknown number of others.
window.app.console.error('Exception ' + e + ' emitting event ' + evt.data);
}
finally {
Expand Down Expand Up @@ -1198,7 +1197,7 @@ app.definitions.Socket = L.Class.extend({
this._onHyperlinkClickedMsg(textMsg);
}

if (!this._isReady() || !this._map._docLayer || this._delayedMessages.length || this._handlingDelayedMessages) {
if (!this._map._docLayer) {
this._delayMessage(textMsg);
} else {
this._map._docLayer._onMessage(textMsg, e.image);
Expand Down Expand Up @@ -1318,42 +1317,24 @@ app.definitions.Socket = L.Class.extend({
_delayMessage: function(textMsg) {
var message = {msg: textMsg};
this._delayedMessages.push(message);

if (!this._delayedMsgHandlerTimeoutId) {
this._handleDelayedMessages();
}
},

_handleDelayedMessages: function() {
if (!this._isReady() || !this._map._docLayer || this._handlingDelayedMessages) {
var that = this;
// Retry in a bit.
this._delayedMsgHandlerTimeoutId = setTimeout(function() {
that._handleDelayedMessages();
}, 100);
return;
}
_handleDelayedMessages: function(docLayer) {
var messages = [];
for (var i = 0; i < this._delayedMessages.length; ++i) {
var message = this._delayedMessages[i];
if (message)
messages.push(message.msg);
messages.push(message.msg);
}
this._delayedMessages = [];
this._delayedMsgHandlerTimeoutId = null;
this._handlingDelayedMessages = true;
if (this._map._docLayer) {
for (var k = 0; k < messages.length; ++k) {
try {
this._map._docLayer._onMessage(messages[k]);
} catch (e) {
// unpleasant - but stops this one problem
// event stopping an unknown number of others.
window.app.console.log('Exception ' + e + ' emitting event ' + messages[k]);
}
for (var k = 0; k < messages.length; ++k) {
try {
docLayer._onMessage(messages[k]);
} catch (e) {
// unpleasant - but stops this one problem
// event stopping an unknown number of others.
window.app.console.log('Exception ' + e + ' emitting event ' + messages[k]);
}
}
this._handlingDelayedMessages = false;
},

_onStatusMsg: function(textMsg, command) {
Expand Down Expand Up @@ -1403,6 +1384,9 @@ app.definitions.Socket = L.Class.extend({
});
}

if (docLayer !== null) {
this._handleDelayedMessages(docLayer);
}
this._map._docLayer = docLayer;
this._map.addLayer(docLayer);
this._map.fire('doclayerinit');
Expand Down

0 comments on commit 6eead7b

Please sign in to comment.