Skip to content

Commit

Permalink
Added the ability for connections to pre-buffer messages that are sen…
Browse files Browse the repository at this point in the history
…t to them and then replay them.

#1889
  • Loading branch information
NTaylorMullen committed May 1, 2013
1 parent 1e028b3 commit 0d71a80
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Microsoft.AspNet.SignalR.Client.JS/jquery.signalR.core.js
Expand Up @@ -219,7 +219,9 @@
init: function (url, qs, logging) {
this.url = url;
this.qs = qs;
this._ = {};
this._ = {
incomingMessageBuffer: []
};
if (typeof (logging) === "boolean") {
this.logging = logging;
}
Expand Down Expand Up @@ -407,7 +409,11 @@

$(connection).triggerHandler(events.onStart);

_pageWindow.unload(function () { // failure
// Drain any incoming buffered messages (messages that came in prior to connect)
signalR.transports._logic.drainIncomingMessageBuffer(connection);

// wire the stop handler for when the user leaves the page
_pageWindow.unload(function () {
connection.stop(false /* async */);
});

Expand Down
Expand Up @@ -223,6 +223,31 @@
connection.log("Fired ajax abort async = " + async);
},

drainIncomingMessageBuffer: function (connection) {
var incomingMessageBuffer = connection._.incomingMessageBuffer;

while (incomingMessageBuffer.length > 0) {
// Check isDisconnecting for each message, a message can cause the connection to stop
if (!isDisconnecting(connection)) {
signalR.transports._logic.processMessages(connection, incomingMessageBuffer.shift());
}
else {
// If we're disconnecting, reset the message buffer and stop drain
connection._.incomingMessageBuffer = [];
return;
}
}
},

tryPreConnectBuffer: function (connection, message) {
// Check if we need to buffer message
if (connection.state === signalR.connectionState.connecting) {
connection._.incomingMessageBuffer.push(message);
return true;
}

return false;
},
processMessages: function (connection, minData) {
var data;
// Transport can be null if we've just closed the connection
Expand Down

0 comments on commit 0d71a80

Please sign in to comment.