From 7d45f4426567e51431f1d50d08b9cd9b83ba2f62 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 13 Jun 2014 21:33:19 -0700 Subject: [PATCH] Survive clearing of localStorage while we're running by caching client ID. --- static/cosmopolite.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 6e3fac0..711564d 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -99,6 +99,11 @@ var Cosmopolite = function( if (!localStorage[this.namespace_ + ':client_id']) { localStorage[this.namespace_ + ':client_id'] = this.uuid_(); } + /** + * @type {string} + * @private + */ + this.clientID_ = localStorage[this.namespace_ + ':client_id']; /** * @type {string} @@ -710,7 +715,8 @@ Cosmopolite.prototype.onReceiveMessage_ = function(data) { } break; case 'logout_complete': - localStorage[this.namespace_ + ':client_id'] = this.uuid_(); + this.clientID_ = localStorage[this.namespace_ + ':client_id'] = + this.uuid_(); localStorage.removeItem(this.namespace_ + ':google_user_id'); if (this.socket_) { this.socket_.close(); @@ -820,7 +826,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, opt_delay) { } var request = { 'instance_id': this.instanceID_, - 'client_id': localStorage[this.namespace_ + ':client_id'], + 'client_id': this.clientID_, 'commands': [] }; commands.forEach(function(command) {