From 64e16e7ec1f9bfaaafd88e2c18c0db64adbf7880 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 16 May 2014 19:03:33 +0300 Subject: [PATCH] Add a way to fetch our current profile ID. --- api.py | 2 ++ static/cosmopolite.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/api.py b/api.py index 52a5b6a..0f6e4a3 100644 --- a/api.py +++ b/api.py @@ -35,11 +35,13 @@ def CreateChannel(google_user, client, args): if google_user: events.append({ 'event_type': 'login', + 'profile': str(client.parent_key()), 'google_user': google_user.email(), }) else: events.append({ 'event_type': 'logout', + 'profile': str(client.parent_key()), }) return { diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 0b811e5..1598229 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -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_) {