PubNub UUIDs JavaScript/Web SDK


For JavaScript, here is the code we recommend for generating, persisting and retrieving a UUID. This could be wrapped in a function can called directly from the PUBNUB.init function rather than the two step inline solution below.

// get/create/store UUID
var UUID = PUBNUB.db.get('session') || (function(){ 
    var uuid = PUBNUB.uuid(); 
    PUBNUB.db.set('session', uuid); 
    return uuid; 

// init PUBNUB object with UUID value
var pubnub = PUBNUB.init({
    publish_key: pubKey,
    subscribe_key: subKey,
    uuid: UUID