Add a way to fetch our current profile ID.

This commit is contained in:
Ian Gulliver
2014-05-16 19:03:33 +03:00
parent 5e63eb9ae6
commit 64e16e7ec1
2 changed files with 26 additions and 0 deletions

View File

@@ -56,6 +56,11 @@ Cosmopolite = function(callbacks, urlPrefix, namespace) {
}, this);
};
/**
* Shutdown this instance.
*
* No callbacks will fire after this returns.
*/
Cosmopolite.prototype.shutdown = function() {
console.log(this.loggingPrefix_(), 'shutdown');
this.shutdown_ = true;
@@ -164,6 +169,22 @@ Cosmopolite.prototype.getKeyMessage = function(subject, key) {
return this.subscriptions_[subject].keys[key];
};
/**
* Return our current profile ID, if known.
*
* @return {?string} Profile ID.
* @const
*/
Cosmopolite.prototype.profile = function() {
return this.profile_ || null;
};
/**
* Generate a string identifying us to be included in log messages.
*
* @return {string} Log line prefix.
* @const
*/
Cosmopolite.prototype.loggingPrefix_ = function() {
return 'cosmopolite (' + this.namespace_ + '):';
};
@@ -417,6 +438,9 @@ Cosmopolite.prototype.onServerEvent_ = function(e) {
if (this.shutdown_) {
return;
}
if (e['profile']) {
this.profile_ = e['profile'];
}
switch (e['event_type']) {
case 'login':
if ('onLogin' in this.callbacks_) {