Skip to content

Commit

Permalink
Stop persisting on connect; unpersist on recover
Browse files Browse the repository at this point in the history
We can minimise interference between tabs by only persisting the
connection when the page refreshes, and then unpersisting it once we
connect with the recovered key/serial. (At the cost of losing the
fallback recover-from-key-only if the onPageRefresh callback fails)
  • Loading branch information
SimonWoolf committed May 2, 2016
1 parent 326e78d commit c62fc42
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions common/lib/transport/connectionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ var ConnectionManager = (function() {
} else {
self.activateTransport(transport, connectionKey, connectionSerial, connectionId, clientId);
}
if(mode === 'recover' && self.options.onPageRefresh === 'persist') {
/* After a successful recovery, we remove the recover cookie we used to
* connect, so other browser tabs don't try to reuse the same connection params */
self.unpersistConnection();
}
});

var eventHandler = function(event) {
Expand Down Expand Up @@ -577,9 +582,6 @@ var ConnectionManager = (function() {
this.realtime.connection.serial = this.connectionSerial = (connectionSerial === undefined) ? -1 : connectionSerial;
this.realtime.connection.recoveryKey = connectionKey + ':' + this.connectionSerial;
this.msgSerial = 0;
if(this.options.recover === true)
this.persistConnection();

};

ConnectionManager.prototype.clearConnection = function() {
Expand All @@ -588,7 +590,6 @@ var ConnectionManager = (function() {
this.realtime.connection.serial = this.connectionSerial = undefined;
this.realtime.connection.recoveryKey = null;
this.msgSerial = 0;
this.unpersistConnection();
};

/**
Expand Down

0 comments on commit c62fc42

Please sign in to comment.