diff --git a/.pubnub.yml b/.pubnub.yml index b5e61e36..ca3a094f 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,6 +1,11 @@ --- -version: v9.3.0 +version: v9.4.0 changelog: + - date: 2026-06-15 + version: v9.4.0 + changes: + - type: feature + text: "Added HTTP/2 option to config (enabled by default) and updated the Unity specific Pubnub instance creation flow to use the native UnityHttpMessageHandler for Unity 6.5+ and allow injecting custom HTTP/2 enabled handlers earlier versions." - date: 2025-11-04 version: v9.3.0 changes: @@ -802,7 +807,7 @@ sdks: distribution-type: package distribution-repository: git release package-name: PubNub.unitypackage - location: https://github.com/pubnub/unity/releases/download/v9.3.0/PubNub.unitypackage + location: https://github.com/pubnub/unity/releases/download/v9.4.0/PubNub.unitypackage requires: - name: "UnityEditor" @@ -934,7 +939,7 @@ sdks: distribution-type: package distribution-repository: git release package-name: PubNub.unitypackage - location: https://github.com/pubnub/unity/releases/download/v9.3.0/PubNub.unitypackage + location: https://github.com/pubnub/unity/releases/download/v9.4.0/PubNub.unitypackage requires: - name: "UnityEditor" diff --git a/PubNubUnity/Assets/PubNub/Editor/PNConfigAssetEditor.cs b/PubNubUnity/Assets/PubNub/Editor/PNConfigAssetEditor.cs index bb7d9c0e..5861c9f3 100644 --- a/PubNubUnity/Assets/PubNub/Editor/PNConfigAssetEditor.cs +++ b/PubNubUnity/Assets/PubNub/Editor/PNConfigAssetEditor.cs @@ -22,6 +22,7 @@ public class PNConfigAssetEditor : Editor { "MaintainPresenceState", "EnableEventEngine", "EnableWebGLBuildMode", + "EnableHttp2", "LogToUnityConsole", "LogVerbosity", "LogLevel" diff --git a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll index f480b594..271dbf53 100644 Binary files a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll and b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll differ diff --git a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.xml b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.xml index 8b59eadb..e2e43008 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.xml +++ b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.xml @@ -49,6 +49,10 @@ + + Estimates final URL size for regular publish GET using the same middleware path + and query construction used for actual requests. + The publish timetoken of a parent message @@ -160,6 +164,17 @@ Hexadecimal CBOR string Thrown when unsupported type is passed + + + Safely invokes a listener callback with exception handling to prevent listener exceptions from affecting SDK operations. + + The listener callback action to invoke. + The type of event being processed (for logging purposes). + + This method ensures that exceptions thrown by user-provided listener callbacks do not crash the SDK + or prevent other listeners from receiving events. All exceptions are logged at Warning level. + + Dispatch an invocation i.e. call a registered effect handler. @@ -410,6 +425,17 @@ region + + + When enabled single multi-channel subscriptions will internally be changed into multiple single-channel ones. + Enable this option if your keyset has channel-based sharding enabled. + This option requires Event Engine to be enabled (it's on by default). + WARNING: Enabling this option will also: +
  • Disable subscribing to channel groups
  • +
  • Disable subscribing with WithPresence() (you can still explicitly subscribe to *-pnpres channels directly)
  • +
  • Generate more server requests, potentially increasing costs
  • +
    +
    This property is obsolete. Use instead. @@ -428,6 +454,18 @@ PubnubLog is deprecated. Implement IPubnubLogger and Use SetLogger method to configure custom logger for improved flexibility and control. + + + When enabled (default), each outbound request negotiates HTTP/2 using + / VersionPolicy, with + automatic fallback to HTTP/1.1. HTTP/2 only takes effect against an HTTP/2-capable + (customer-enabled) PubNub origin; otherwise requests transparently use HTTP/1.1. + The negotiated protocol is re-evaluated on new connections (natural reconnect or + Pubnub client recreation); the SDK does not pin or proactively probe for HTTP/2. + On target frameworks without VersionPolicy support (netstandard2.0/.NET Framework), + only the request version is set as a best-effort hint. + + Call this function to globally clean up all background threads running in the SDK. Note that this will unsubscribe all channels. @@ -462,6 +500,23 @@ The identifier **must** be 4 bytes long. + + + Creates a transport backed by a caller-supplied . + Intended for testing and advanced transport scenarios (e.g. observing outgoing + requests or stubbing responses). The supplied handler is fully responsible for + TLS/certificate validation and proxy behavior; the SDK does not weaken or override + them here. Do not pass a handler that disables certificate validation in production. + + The message handler used to send requests. + Whether outbound requests should request HTTP/2 with HTTP/1.1 fallback. + + + + The negotiated HTTP protocol version of the response (e.g. 2.0 or 1.1), + taken from HttpResponseMessage.Version. Null when no response was received. + + MD5 Service provider diff --git a/PubNubUnity/Assets/PubNub/Runtime/Util/PNConfigAsset.cs b/PubNubUnity/Assets/PubNub/Runtime/Util/PNConfigAsset.cs index 4cb97d9a..cfde0bac 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Util/PNConfigAsset.cs +++ b/PubNubUnity/Assets/PubNub/Runtime/Util/PNConfigAsset.cs @@ -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; @@ -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; diff --git a/PubNubUnity/Assets/PubNub/Runtime/Util/PubnubUnityUtils.cs b/PubNubUnity/Assets/PubNub/Runtime/Util/PubnubUnityUtils.cs index 12e583e5..369f95d6 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Util/PubnubUnityUtils.cs +++ b/PubNubUnity/Assets/PubNub/Runtime/Util/PubnubUnityUtils.cs @@ -1,4 +1,5 @@ using PubnubApi.PNSDK; +using UnityEngine; namespace PubnubApi.Unity { public static class PubnubUnityUtils { @@ -8,18 +9,53 @@ public static class PubnubUnityUtils { /// Pubnub configuration object /// Flag for enabling WebGL mode - sets httpTransportService to UnityWebGLHttpClientService /// Flag to set Unity specific logger (UnityPubNubLogger) - /// Optional: PNSDK source, used for analytics and debugging. - /// - 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); + /// Custom PNSDK source, used for analytics and debugging. + /// Custom IHttpClientService internal transport layer to be used by the Pubnub instance. + /// A new initialized Pubnub instance optimized for Unity usage. + 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; } @@ -29,11 +65,13 @@ public static Pubnub NewUnityPubnub(PNConfiguration configuration, bool webGLBui /// Pubnub configuration Scriptable Object asset /// Client user ID for this instance /// Optional: PNSDK source, used for analytics and debugging. - /// - public static Pubnub NewUnityPubnub(PNConfigAsset configurationAsset, string userId, IPNSDKSource ipnsdkSource = null) { - configurationAsset.UserId = userId; + /// A new initialized Pubnub instance. + 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); } } } \ No newline at end of file diff --git a/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs b/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs index e3a45425..c33a1ec5 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs +++ b/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs @@ -5,7 +5,7 @@ namespace PubnubApi.Unity { public class UnityPNSDKSource : IPNSDKSource { - private const string build = "9.3.0"; + private const string build = "9.4.0"; public string Build => build; public string GetPNSDK() { diff --git a/PubNubUnity/Assets/PubNub/package.json b/PubNubUnity/Assets/PubNub/package.json index 410644e5..45c31f9a 100644 --- a/PubNubUnity/Assets/PubNub/package.json +++ b/PubNubUnity/Assets/PubNub/package.json @@ -1,6 +1,6 @@ { "name": "com.pubnub.sdk", - "version": "9.3.0", + "version": "9.4.0", "displayName": "PubNub SDK", "description": "PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks", "unity": "2018.2", diff --git a/PubNubUnity/Assets/Snippets/Configuration/ConfigurationSample.cs b/PubNubUnity/Assets/Snippets/Configuration/ConfigurationSample.cs index 116ba97e..2c775a48 100644 --- a/PubNubUnity/Assets/Snippets/Configuration/ConfigurationSample.cs +++ b/PubNubUnity/Assets/Snippets/Configuration/ConfigurationSample.cs @@ -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 + } } \ No newline at end of file diff --git a/VERSION b/VERSION index b13d146a..8148c559 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.3.0 +9.4.0