Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating the UUID of a client in PubNub

I am writing a simple chat application using PubNub to demo realtime data. When the application starts it shows a list of connected users down the side. Each user has a default UUID that is generated by PubNub when initialised. I want to be able to change this UUID to something more human friendly. I am aware that I can do this when I initialise the PubNub library

PubNub.init({
  ... keys ...
  uuid: 'The username'
});

But I wish to also do this 'on the fly' so users can update their username during the runtime of the application. I have not been able to find any documentation to support this functionality which suggests to me it is not possible. However I also see nothing stating it cannot be done. Is there such a feature and how do I do it?

like image 825
tomasbasham Avatar asked Nov 29 '25 14:11

tomasbasham


1 Answers

Changing the UUID in PubNub

You can change the UUID of a connected client anytime. Use the set_uuid method to update the UUID and have the SDK re-initialize the Connection State with a new UUID.

Set initial UUID

var pubnub = PUBNUB({ ..., uuid : "CLIENT_UUID" });

Change the UUID

pubnub.set_uuid("NEW_UUID");

The only reference currently posted on PubNub Documentation is here: https://www.pubnub.com/docs/posix-cpp/api-reference#init_example_3 in the PubNub POSIX C API Reference.

like image 194
Stephen Blum Avatar answered Dec 01 '25 02:12

Stephen Blum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!