Allow DDP client to register onDisconnect callback.

accounts-base uses this to handle disconnects due to users being intentionally
logged out.
This commit is contained in:
Emily Stark
2013-09-02 19:04:01 -07:00
parent e84f0adb78
commit 21dd57c95d
2 changed files with 9 additions and 5 deletions

View File

@@ -112,6 +112,13 @@ Accounts.callLoginMethod = function (options) {
}});
}
};
Meteor.connection._onDisconnect = function (reason) {
var loggedOutReasons = ["logged_out", "token_expired",
"user_deleted", "token_deleted"];
if (_.indexOf(loggedOutReasons, reason) !== -1)
makeClientLoggedOut();
};
}
};
@@ -162,6 +169,7 @@ makeClientLoggedOut = function() {
unstoreLoginToken();
Meteor.connection.setUserId(null);
Meteor.connection.onReconnect = null;
Meteor.connection._onDisconnect = null;
};
makeClientLoggedIn = function(userId, token, tokenExpires) {
@@ -189,7 +197,6 @@ Meteor._logoutAllOthers = function (opts, callback) {
}
Meteor.apply('_logoutAllOthers', [opts], { wait: true },
function (error, result) {
console.log("logged out others");
if (error) {
callback && callback(error);
} else {

View File

@@ -1324,10 +1324,7 @@ _.extend(Connection.prototype, {
_livedata_disconnected: function (msg) {
var self = this;
var reason = msg.reason;
if (reason === "logged_out" || reason === "token_expired") {
self.setUserId(null);
self.onReconnect = null;
}
self._onDisconnect && self._onDisconnect(reason);
},
_livedata_error: function (msg) {