Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID changes #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions PubNubUnity/Assets/PubNub/Editor/EditorCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class EditorCommon
public bool DeliveryStatus { get; set; }

public static PubNub InitPN(PNConfiguration pnConfig){
pnConfig.UUID = PubNub.GenerateUUID();
return new PubNub(pnConfig);
}

Expand All @@ -62,6 +63,7 @@ public static PNConfiguration CreatePNConfig(){
pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;
pnConfiguration.PresenceTimeout = 60;
pnConfiguration.PresenceInterval= 30;
pnConfiguration.UUID = PubNub.GenerateUUID();
return pnConfiguration;
}

Expand Down
1 change: 1 addition & 0 deletions PubNubUnity/Assets/PubNub/Editor/PNConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PNConfigurationTests
public void TestPNinGenerateGuid ()
{
PNConfiguration pnConfig = new PNConfiguration();
pnConfig.UUID = PubNub.GenerateUUID();
Assert.IsTrue(pnConfig.UUID.Contains("pn-"));
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion PubNubUnity/Assets/PubNub/Examples/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void Init(){
pnConfiguration.HeartbeatNotificationOption = PNHeartbeatNotificationOption.All;

//TODO: remove
pnConfiguration.UUID = "PubNubUnityExample";
pnConfiguration.UUID = PubNub.GenerateUUID();
Debug.Log ("PNConfiguration");
pubnub = new PubNub (pnConfiguration);

Expand Down
1 change: 1 addition & 0 deletions PubNubUnity/Assets/PubNub/Helpers/CommonText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ internal static class CommonText
{
internal static readonly string DuplicateChannelsOrChannelGroups = "Duplicate Channels or Channel Groups";
internal static readonly string APNS2TopicEmpty = "Topic cannot be empty when APNS2 is selected";
internal static readonly string UUIDMissing = "UUID misisng, please set it in the PNConfig.";
}
}
6 changes: 6 additions & 0 deletions PubNubUnity/Assets/PubNub/Helpers/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public static int CheckTimeoutValue(int value){
}
}
#endif

public static void CheckUUID(string uuid){
if (string.IsNullOrEmpty (uuid) || string.IsNullOrEmpty (uuid.Trim ())) {
throw new PubNubException(CommonText.UUIDMissing);
}
}

public static bool CheckDictionaryForError(Dictionary<string, object> dictionary, string keyName){
if(dictionary.ContainsKey(keyName) && dictionary[keyName].Equals(true)){
Expand Down
1 change: 1 addition & 0 deletions PubNubUnity/Assets/PubNub/Models/Server/BuildRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ private static string TokenOrAuthKey(PubNubUnity pnInstance){
private static Uri BuildRestApiRequest<T> (List<string> urlComponents, PNOperationType type, string parameters, PubNubUnity pnInstance, Dictionary<string, string> queryParams)
{
string uuid = pnInstance.PNConfig.UUID;
Utility.CheckUUID(pnInstance.PNConfig.UUID);
bool ssl = pnInstance.PNConfig.Secure;
string origin = pnInstance.PNConfig.Origin;
int pubnubPresenceHeartbeatInSeconds = pnInstance.PNConfig.PresenceTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static PNConfiguration SetPNConfig(bool useCipher, bool withPAM){
pnConfiguration.Origin = Origin;
pnConfiguration.SubscribeKey = SubscribeKey;
pnConfiguration.PublishKey = PublishKey;
pnConfiguration.UUID = PubNub.GenerateUUID();
pnConfiguration.NonSubscribeTimeout = 30;
if(withPAM){
pnConfiguration.SubscribeKey = SubscribeKeyPAM;
Expand Down
5 changes: 5 additions & 0 deletions PubNubUnity/Assets/PubNub/PubNub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private PubNub (PNConfiguration pnConfiguration, GameObject gameObjectRef, IJson
this.jsonLibrary = jsonLibrary;
this.gameObj = gameObjectRef;
this.PNConfig = pnConfiguration;
Utility.CheckUUID(this.PNConfig.UUID);
PubNubUnityInitializationAfterCleanup();
}

Expand Down Expand Up @@ -102,6 +103,10 @@ public IJsonLibrary JsonLibrary{
}
}

public static string GenerateUUID(){
return string.Format("pn-{0}", Guid.NewGuid ().ToString ());
}

public void Reconnect(){
PubNubUnityInitializationAfterCleanup();
pnUnity.Reconnect();
Expand Down
5 changes: 1 addition & 4 deletions PubNubUnity/Assets/PubNub/PubNubUnity/PNConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ public ushort ConcurrentNonSubscribeWorkers {
private string uuid;
public string UUID {
get{
if (string.IsNullOrEmpty (uuid) || string.IsNullOrEmpty (uuid.Trim ())) {
uuid = string.Format("pn-{0}", Guid.NewGuid ().ToString ());
}

return uuid;
}
set{
uuid = value;
Utility.CheckUUID(uuid);
if(UUIDChanged!=null){
UUIDChanged.Invoke(this, null);
}
Expand Down