Skip to content

Commit

Permalink
Merge pull request #289 from SuperPat45/patch-1
Browse files Browse the repository at this point in the history
Avoid errors when sending message during websocket reconnection
  • Loading branch information
jfarcand authored Jun 4, 2024
2 parents 9c369e1 + c31a21e commit bd95a51
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/javascript/src/main/webapp/javascript/atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,17 @@
_pushJsonp(message);
} else if (_websocket != null) {
_pushWebSocket(message);
// Avoid errors when sending message during websocket reconnection
} else if (_request && _request.isOpen && _request.reconnect && _request.isReopen && _request.transport === "websocket") {
_debug("Waiting for the websocket reconnection to send the message...");
var reopenHandler = _request.onReopen;
_request.onReopen = function() {
_request.onReopen = reopenHandler;
if (typeof (reopenHandler) !== 'undefined') {
reopenHandler.apply(this, arguments);
}
_push(message, _request);
}
} else {
_onError(0, "No suspended connection available");
atmosphere.util.error("No suspended connection available. Make sure atmosphere.subscribe has been called and request.onOpen invoked before trying to push data");
Expand Down

0 comments on commit bd95a51

Please sign in to comment.