Make uuid() public
This commit is contained in:
@@ -97,7 +97,7 @@ var Cosmopolite = function(
|
|||||||
this.profilePromises_ = [];
|
this.profilePromises_ = [];
|
||||||
|
|
||||||
if (!localStorage[this.namespace_ + ':client_id']) {
|
if (!localStorage[this.namespace_ + ':client_id']) {
|
||||||
localStorage[this.namespace_ + ':client_id'] = this.uuid_();
|
localStorage[this.namespace_ + ':client_id'] = this.uuid();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
@@ -109,7 +109,7 @@ var Cosmopolite = function(
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.instanceID_ = this.uuid_();
|
this.instanceID_ = this.uuid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
@@ -376,7 +376,7 @@ Cosmopolite.prototype.sendMessage = function(subject, message) {
|
|||||||
var args = {
|
var args = {
|
||||||
'subject': this.canonicalSubject_(subject),
|
'subject': this.canonicalSubject_(subject),
|
||||||
'message': JSON.stringify(message),
|
'message': JSON.stringify(message),
|
||||||
'sender_message_id': this.uuid_()
|
'sender_message_id': this.uuid()
|
||||||
};
|
};
|
||||||
|
|
||||||
// No message left behind.
|
// No message left behind.
|
||||||
@@ -483,7 +483,7 @@ Cosmopolite.prototype.currentProfile = function() {
|
|||||||
Cosmopolite.prototype.pin = function(subject, message) {
|
Cosmopolite.prototype.pin = function(subject, message) {
|
||||||
return this.newPromise_(function(resolve, reject) {
|
return this.newPromise_(function(resolve, reject) {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
var id = this.uuid_();
|
var id = this.uuid();
|
||||||
var args = {
|
var args = {
|
||||||
'subject': this.canonicalSubject_(subject),
|
'subject': this.canonicalSubject_(subject),
|
||||||
'message': JSON.stringify(message),
|
'message': JSON.stringify(message),
|
||||||
@@ -561,7 +561,7 @@ Cosmopolite.prototype.init_ = function() {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.analyticsObjName_ = this.uuid_();
|
this.analyticsObjName_ = this.uuid();
|
||||||
window['GoogleAnalyticsObject'] = this.analyticsObjName_;
|
window['GoogleAnalyticsObject'] = this.analyticsObjName_;
|
||||||
|
|
||||||
var completeCallback = (function() {
|
var completeCallback = (function() {
|
||||||
@@ -600,6 +600,25 @@ Cosmopolite.prototype.init_ = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a v4 UUID.
|
||||||
|
*
|
||||||
|
* @return {string} A universally-unique random value.
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
|
Cosmopolite.prototype.uuid = function() {
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||||
|
/** @type {number} */
|
||||||
|
var r = (Math.random() * 16) | 0;
|
||||||
|
if (c == 'x') {
|
||||||
|
return r.toString(16);
|
||||||
|
} else {
|
||||||
|
return (r & (0x03 | 0x08)).toString(16);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a new Promise object with exception handling.
|
* Build a new Promise object with exception handling.
|
||||||
*
|
*
|
||||||
@@ -636,26 +655,6 @@ Cosmopolite.prototype.loggingPrefix_ = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a v4 UUID.
|
|
||||||
*
|
|
||||||
* @return {string} A universally-unique random value.
|
|
||||||
* @const
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
Cosmopolite.prototype.uuid_ = function() {
|
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
||||||
/** @type {number} */
|
|
||||||
var r = (Math.random() * 16) | 0;
|
|
||||||
if (c == 'x') {
|
|
||||||
return r.toString(16);
|
|
||||||
} else {
|
|
||||||
return (r & (0x03 | 0x08)).toString(16);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Canonicalize a subject name or object
|
* Canonicalize a subject name or object
|
||||||
*
|
*
|
||||||
@@ -716,7 +715,7 @@ Cosmopolite.prototype.onReceiveMessage_ = function(data) {
|
|||||||
break;
|
break;
|
||||||
case 'logout_complete':
|
case 'logout_complete':
|
||||||
this.clientID_ = localStorage[this.namespace_ + ':client_id'] =
|
this.clientID_ = localStorage[this.namespace_ + ':client_id'] =
|
||||||
this.uuid_();
|
this.uuid();
|
||||||
localStorage.removeItem(this.namespace_ + ':google_user_id');
|
localStorage.removeItem(this.namespace_ + ':google_user_id');
|
||||||
if (this.socket_) {
|
if (this.socket_) {
|
||||||
this.socket_.close();
|
this.socket_.close();
|
||||||
@@ -1072,7 +1071,7 @@ Cosmopolite.prototype.onSocketClose_ = function() {
|
|||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instanceID_ = this.uuid_();
|
this.instanceID_ = this.uuid();
|
||||||
|
|
||||||
this.createChannel_();
|
this.createChannel_();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user