Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions PubNubUnity/Assets/PubNub/Editor/PNConfigAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PNConfigAssetEditor : Editor {
"MaintainPresenceState",
"EnableEventEngine",
"EnableWebGLBuildMode",
"EnableHttp2",
"LogToUnityConsole",
"LogVerbosity",
"LogLevel"
Expand Down
Binary file modified PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll
Binary file not shown.
55 changes: 55 additions & 0 deletions PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions PubNubUnity/Assets/PubNub/Runtime/Util/PNConfigAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PNConfigAsset : ScriptableObject {
public bool MaintainPresenceState = true;
public bool EnableEventEngine = true;
public bool EnableWebGLBuildMode;
public bool EnabbleHttp2 = true;
public bool LogToUnityConsole = true;
[Tooltip("Obsolete and used in legacy logging, if you can please use LogLevel instead")]
public PNLogVerbosity LogVerbosity;
Expand All @@ -37,6 +38,7 @@ public static implicit operator PNConfiguration(PNConfigAsset asset) {
config.PublishKey = asset.PublishKey;
config.SecretKey = asset.SecretKey;
config.AuthKey = asset.AuthKey;
config.EnableHttp2 = asset.EnabbleHttp2;
config.CipherKey = asset.CipherKey;
config.NonSubscribeRequestTimeout = asset.NonSubscribeRequestTimeout;
config.SubscribeTimeout = asset.SubscribeTimeout;
Expand Down
64 changes: 51 additions & 13 deletions PubNubUnity/Assets/PubNub/Runtime/Util/PubnubUnityUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PubnubApi.PNSDK;
using UnityEngine;

namespace PubnubApi.Unity {
public static class PubnubUnityUtils {
Expand All @@ -8,18 +9,53 @@ public static class PubnubUnityUtils {
/// <param name="configuration">Pubnub configuration object</param>
/// <param name="webGLBuildMode">Flag for enabling WebGL mode - sets httpTransportService to UnityWebGLHttpClientService</param>
/// <param name="unityLogging">Flag to set Unity specific logger (UnityPubNubLogger)</param>
/// <param name="ipnsdkSource">Optional: PNSDK source, used for analytics and debugging.</param>
/// <returns></returns>
public static Pubnub NewUnityPubnub(PNConfiguration configuration, bool webGLBuildMode = false, bool unityLogging = false, IPNSDKSource ipnsdkSource = null) {
ipnsdkSource ??= new UnityPNSDKSource();
var pubnub = webGLBuildMode
? new Pubnub(configuration, httpTransportService: new UnityWebGLHttpClientService(),
ipnsdkSource: ipnsdkSource)
: new Pubnub(configuration, ipnsdkSource: ipnsdkSource);
/// <param name="customIpnsdkSource">Custom PNSDK source, used for analytics and debugging.</param>
/// <param name="customIHttpClientService">Custom IHttpClientService internal transport layer to be used by the Pubnub instance.</param>
/// <returns>A new initialized Pubnub instance optimized for Unity usage.</returns>
public static Pubnub NewUnityPubnub(PNConfiguration configuration, bool webGLBuildMode = false,
bool unityLogging = false, IPNSDKSource customIpnsdkSource = null,
IHttpClientService customIHttpClientService = null)
{
Pubnub pubnub;
var ipnsdkSource = customIpnsdkSource ?? new UnityPNSDKSource();
//With a custom transport layer
if (customIHttpClientService != null) {
pubnub = new Pubnub(configuration, httpTransportService: customIHttpClientService,
ipnsdkSource: ipnsdkSource);
}
//With the WebGL transport layer
else if (webGLBuildMode) {
pubnub = new Pubnub(configuration, httpTransportService: new UnityWebGLHttpClientService(),
ipnsdkSource: ipnsdkSource);
}
//With the Unity Http/2 supported transport layer
else if (configuration.EnableHttp2) {
#if UNITY_6000_5_OR_NEWER
var handler = new UnityEngine.Networking.UnityHttpMessageHandler()
{
HttpForcedVersion = UnityEngine.Networking.HttpForcedVersion.NotForced
};
var transport = new HttpClientService(handler, enableHttp2: true);
pubnub = new Pubnub(configuration, httpTransportService: transport, ipnsdkSource: new UnityPNSDKSource());
pubnub.SetJsonPluggableLibrary(new NewtonsoftJsonUnity(configuration));
#else
Debug.LogWarning(
"Project version is below Unity 6.5 so HTTP/2 support can only be enabled via a third-party HTTP handler, " +
"see documentation for more information. This created Pubnub instance will have the default non-HTTP/2 supporting transport. " +
"If you don't require HTTP/2 and don't want to see this warning set \"EnableHttp2\" to false in the Pubnub config.");
pubnub = new Pubnub(configuration, ipnsdkSource: ipnsdkSource);
#endif
}
//Default
else {
pubnub = new Pubnub(configuration, ipnsdkSource: ipnsdkSource);
}

pubnub.SetJsonPluggableLibrary(new NewtonsoftJsonUnity(configuration));
if (unityLogging) {
pubnub.SetLogger(new UnityPubNubLogger(pubnub.InstanceId));
}
pubnub.SetJsonPluggableLibrary(new NewtonsoftJsonUnity(configuration));

return pubnub;
}

Expand All @@ -29,11 +65,13 @@ public static Pubnub NewUnityPubnub(PNConfiguration configuration, bool webGLBui
/// <param name="configurationAsset">Pubnub configuration Scriptable Object asset</param>
/// <param name="userId">Client user ID for this instance</param>
/// <param name="ipnsdkSource">Optional: PNSDK source, used for analytics and debugging.</param>
/// <returns></returns>
public static Pubnub NewUnityPubnub(PNConfigAsset configurationAsset, string userId, IPNSDKSource ipnsdkSource = null) {
configurationAsset.UserId = userId;
/// <returns>A new initialized Pubnub instance.</returns>
public static Pubnub NewUnityPubnub(PNConfigAsset configurationAsset, string userId,
IPNSDKSource ipnsdkSource = null) {
var pnConfig = ((PNConfiguration)configurationAsset);
return NewUnityPubnub(pnConfig, configurationAsset.EnableWebGLBuildMode, configurationAsset.LogToUnityConsole, ipnsdkSource: ipnsdkSource);
pnConfig.UserId = userId;
return NewUnityPubnub(pnConfig, configurationAsset.EnableWebGLBuildMode,
configurationAsset.LogToUnityConsole, customIpnsdkSource: ipnsdkSource);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,28 @@ static void InitReadOnly()
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
// snippet.end
}

static void Http2UsingYAHH() {
//Not compiling to avoid having to import YAHH into the project
#if false
// snippet.http2_yahh
var config = new PNConfiguration(new UserId("h2-user"))
{
PublishKey = "your-key-here",
SubscribeKey = "your-key-here",
//HTTP/2 supporting origin, default one only supports HTTP/1.1
Origin = "h2.pubnubapi.com",
//Have to be true (and are by default)
Secure = true,
EnableHttp2 = true
};
//The YAHH handler
var handler = new YetAnotherHttpHandler();
//Creating a HttpClientService instance
var customTransport = new HttpClientService(handler, true);
//Creating a Pubnub instance with the custom transport layer
var pubnub = PubnubUnityUtils.NewUnityPubnub(config, customIHttpClientService: customTransport);
// snippet.end
#endif
}
}
35 changes: 17 additions & 18 deletions PubNubUnity/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ads": "3.7.5",
"com.unity.analytics": "3.6.12",
"com.unity.asset-store-tools": "https://github.com/Unity-Technologies/com.unity.asset-store-tools.git/?path=/com.unity.asset-store-tools/",
"com.unity.collab-proxy": "1.17.1",
"com.unity.ext.nunit": "1.0.6",
"com.unity.ide.rider": "3.0.15",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.nuget.newtonsoft-json": "3.0.2",
"com.unity.purchasing": "4.3.0",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.4",
"com.unity.toolchain.linux-x86_64": "2.0.2",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4",
"com.unity.ugui": "1.0.0",
"com.unity.xr.legacyinputhelpers": "2.1.9",
"com.unity.ai.navigation": "2.0.12",
"com.unity.analytics": "3.8.2",
"com.unity.collab-proxy": "2.12.4",
"com.unity.ext.nunit": "2.1.0",
"com.unity.ide.rider": "3.0.40",
"com.unity.ide.visualstudio": "2.0.26",
"com.unity.multiplayer.center": "1.0.1",
"com.unity.nuget.newtonsoft-json": "3.2.2",
"com.unity.purchasing": "4.15.0",
"com.unity.test-framework": "1.7.0",
"com.unity.timeline": "1.8.12",
"com.unity.ugui": "2.5.0",
"com.unity.xr.legacyinputhelpers": "3.0.1",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.adaptiveperformance": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand All @@ -32,6 +30,7 @@
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.physicscore2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
Expand All @@ -45,9 +44,9 @@
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vectorgraphics": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
Expand Down
Loading
Loading