Skip to content

Commit

Permalink
fix: Unity target (#190)
Browse files Browse the repository at this point in the history
* fix: unity target and global cleanup method

* fix: doc comment

* fix: added missing project files
  • Loading branch information
MikeDobrzan authored Oct 12, 2023
1 parent 82bee35 commit eed021d
Show file tree
Hide file tree
Showing 5 changed files with 1,003 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/release/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@
"clearedPrefix": true,
"clearedSuffix": false
}
]
],
"src/Api/PubnubApiUnity/PubnubApiUnity.csproj": [
{
"pattern": "^\\s{2,}<PackageVersion>(v?(\\d+\\.?){2,}([a-zA-Z0-9-]+(\\.?\\d+)?)?)<\/PackageVersion>$",
"clearedPrefix": true,
"clearedSuffix": false
}
],
}
28 changes: 27 additions & 1 deletion src/Api/PubnubApi/Pubnub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using PubnubApi.EndPoint;
#if !NET35 && !NET40
using System.Collections.Concurrent;
#endif
Expand All @@ -18,6 +19,10 @@ public class Pubnub
private readonly EndPoint.TokenManager tokenManager;
private object savedSubscribeOperation;
private readonly string savedSdkVerion;

#if UNITY
private static System.Func<UnsubscribeAllOperation<object>> OnCleanupCall;
#endif

static Pubnub()
{
Expand All @@ -30,6 +35,16 @@ static Pubnub()
#endif
Version = string.Format(CultureInfo.InvariantCulture, "{0}CSharp{1}", PNPlatform.Get(), assemblyVersion);
}

#if UNITY
/// <summary>
/// Call this function to globally clean up all background threads running in the SDK. Note that this will unsubscribe all channels.
/// </summary>
public static void CleanUp()
{
OnCleanupCall?.Invoke();
}
#endif

#region "PubNub API Channel Methods"

Expand Down Expand Up @@ -860,6 +875,10 @@ public void SetJsonPluggableLibrary(IJsonPluggableLibrary customJson)

public Pubnub(PNConfiguration config)
{
#if UNITY
OnCleanupCall += this.UnsubscribeAll<object>;
#endif

savedSdkVerion = Version;
InstanceId = Guid.NewGuid().ToString();
pubnubConfig.AddOrUpdate(InstanceId, config, (k, o) => config);
Expand Down Expand Up @@ -905,6 +924,13 @@ public Pubnub(PNConfiguration config)

}

#if UNITY
~Pubnub()
{
OnCleanupCall -= this.UnsubscribeAll<object>;
}
#endif

private void CheckRequiredConfigValues()
{
if (pubnubConfig != null && pubnubConfig.ContainsKey(InstanceId))
Expand Down Expand Up @@ -932,5 +958,5 @@ private void CheckRequiredConfigValues()
}

#endregion
}
}
}
Loading

0 comments on commit eed021d

Please sign in to comment.