The community forums are in BETA and closed to the public.

Unknown UUID in presence timeout callback

Hello PubNub, My name is Trent Miller and I am from Motorola Solutions. We are evaluating PubNub now for world-wide applications. I have a test driver I am using on your platform and ran into an unusual situation I'm hoping you can help with. I'm using a Javascript client to test the Presence "timeout" callback. I have several Chrome browser tab instances connected to the same channel. I use PUBNUB.uuid to generate a unique uuid for each browser tab and I pass that into the PUBNUB.init call. In my pubnub.subscribe, I've set my hearbeat to 10 seconds. When I close one Chrome browser tab, I do get a presence callback after about 10 seconds, but the UUID I receive in the presence callback (i.e. message.uuid) doesn't match any of the uuids I generated with each tab. In short, the presence callback receives a different UUID than any of the UUIDs I set using PUBNUB.init. Please help. Can you please contact me through corporate email?

Thank you, Trent

Trent, Can you try either using different browsers (Firefox, Chrome and Safari or IE) instead of using multiple tabs? Or use Chrome's private browsing in separate browser windows? Let me know if that helps.

We have a new dev console coming soon that will allow you to test multiple clients (up to three within the same browser tab) properly.

Cheers Craig

Hi Craig, Wow! Thank you kindly for your quick response. From a single machine, I now run 1 instance of the latest Chrome and 1 instance of the latest Firefox. Javascript from both browsers is communicating with the same channel. When I close either browser, I am still getting an unknown UUID in the other browser's Presence "timeout" callback. Thanks for your help, Trent

Hmmm - I will investigate further and get back to you about this.

Hello, Craig. My name is Tolya Agulnik and I am also from Motorola Solutions. I think I found another problem. I ran 3 clients (on different browsers and two machines) subscribed to the same group channel (but not the demo channel). They were printing out the presence events received on the channel (someone joins/leaves etc.). When one of the client left the channel (or got disconnected), two others received “client 1: leave” event and the number of participants became 2. So far so good. But after 4-5 seconds they also received “client 1: join” event and the number of participants became 3 again. Client 1 was shown as a participant until the system timed out on it. Then other clients received “client 1: leave” again and the number of participants became 2 and stayed 2. Is this problem known?

I've seen that before. I think you might be on older version of our JavaScript SDK.

Hi Craig,

Thanks for looking at this.

Tolya and I work pretty closely. We were using 3.7.1.min and have now changed to 3.7.8.min. I haven't tested Tolya's specific issue, but I can say the original incorrect UUID in presence timeout callbacks is still an issue with 3.7.8.min.

Best regards, Trent

Hi Craig, Just letting you know that I think I've figured out my issue (said carefully). I was calling pubnub.uuid() after PUBNUB.init() and that was resetting my UUID to a new value. I was trying to use the uuid() call to read the set uuid from pubnub, but ended up resetting the value assigned in init.

Can one call pubnub.uuid() after init() to read the UUID without changing it? I was just doing var my_uuid = pubnub.uuid();

Thank you, Trent

Trent, yes that it can be a bit confusing. A uuid is generated for you so you do not have to create or set it. However uuid() generates a new uuid but does not set it automatically. You would have to use set_uuid(String) to do that or just provide the uuid in the init call by providing a value for the uuid parameter.

While we are on the subject, once you set the uuid, it is a good idea to persist that so that you can reuse it again later. You might store the uuid in the user's profile in your database or just in local storage. For more details, see How do I set the UUID?.

Trent, if you can call pubnub.get_uuid() to get the current UUID that is set for that pubnub instance.

pubnub.uuid() just generates a new UUID but id does not set the UUID nor does it get the current UUID.

See how do i set the uuid for more details.

Thanks Craig. I noticed one interesting side effect. If you let PubNub choose a UUID in pubnub.init(), all of the tabs in the same browser instance will get the same UUID. If your application requires a unique UUID per browser tab (i.e. per user, per tab), then you can't let PubNub choose a UUID. You will need to have the Javascript with each browser tab assign a unique UUID and pass that into the pubnub.init() call.

I found this algorithm online to generate your own UUID: pubNubUUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); });

Comments to this discussion are now closed!