diff --git a/browser/src/core/Socket.js b/browser/src/core/Socket.js index 24a99f2a4e8d1..f1a0fdafbb4de 100644 --- a/browser/src/core/Socket.js +++ b/browser/src/core/Socket.js @@ -31,7 +31,6 @@ app.definitions.Socket = L.Class.extend({ this._map = map; this._msgQueue = []; this._delayedMessages = []; - this._handlingDelayedMessages = false; }, getWebSocketBaseURI: function(map) { @@ -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 { @@ -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); @@ -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) { @@ -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');