diff --git a/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/DFrameWorkerApp.cs b/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/DFrameWorkerApp.cs index 23c9734..b5c49f0 100644 --- a/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/DFrameWorkerApp.cs +++ b/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/DFrameWorkerApp.cs @@ -14,6 +14,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using MagicOnion.Client.DynamicClient; using MagicOnion.Serialization.MessagePack; namespace DFrame @@ -243,13 +244,18 @@ async Task ConnectAsync(CancellationToken applicationLifeTime) var callInvoker = channel.CreateCallInvoker(); var callOption = new CallOptions(new Metadata { { "worker-id", workerId.ToString() } }); - var connectTask = StreamingHubClient.ConnectAsync(callInvoker, this, option: callOption, serializerProvider: MessagePackMagicOnionSerializerProvider.Default.WithOptions( #if UNITY_2020_1_OR_NEWER - DFrameResolver.Options + var factoryProvider = MagicOnionDFrameGeneratedClientInitializer.StreamingHubClientFactoryProvider; + var serializerOptions = DFrameResolver.Options; #else - MessagePackSerializerOptions.Standard + var factoryProvider = DynamicStreamingHubClientFactoryProvider.Instance; + var serializerOptions = MessagePackSerializerOptions.Standard; #endif - ), factoryProvider: MagicOnionDFrameGeneratedClientInitializer.StreamingHubClientFactoryProvider); + var connectTask = StreamingHubClient.ConnectAsync(callInvoker, this, + option: callOption, + serializerProvider: MessagePackMagicOnionSerializerProvider.Default.WithOptions(serializerOptions), + factoryProvider: factoryProvider + ); client = await connectTask.WaitAsync(connectTimeout); this.connectionLifeTime = CancellationTokenSource.CreateLinkedTokenSource(client!.WaitForDisconnect().ToCancellationToken(), applicationLifeTime); diff --git a/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/Internal/MagicOnionDFrameGeneratedClientInitializer.cs b/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/Internal/MagicOnionDFrameGeneratedClientInitializer.cs index 8e98dc5..e4942aa 100644 --- a/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/Internal/MagicOnionDFrameGeneratedClientInitializer.cs +++ b/src/DFrame.Unity/Assets/Plugins/DFrame/Runtime/Internal/MagicOnionDFrameGeneratedClientInitializer.cs @@ -1,7 +1,9 @@ -using MagicOnion.Client; +#if UNITY_2020_1_OR_NEWER +using MagicOnion.Client; namespace DFrame.Internal { [MagicOnionClientGeneration(typeof(DFrame.IControllerHub), DisableAutoRegistration = true)] internal partial class MagicOnionDFrameGeneratedClientInitializer { } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/DFrame.Worker/DFrameWorkerApp.cs b/src/DFrame.Worker/DFrameWorkerApp.cs index 49d9c57..b5c49f0 100644 --- a/src/DFrame.Worker/DFrameWorkerApp.cs +++ b/src/DFrame.Worker/DFrameWorkerApp.cs @@ -14,6 +14,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using MagicOnion.Client.DynamicClient; using MagicOnion.Serialization.MessagePack; namespace DFrame @@ -225,6 +226,7 @@ async Task ConnectAsync(CancellationToken applicationLifeTime) #if UNITY_2020_1_OR_NEWER HttpHandler = new Cysharp.Net.Http.YetAnotherHttpHandler() { + Http2Only = true, Http2KeepAliveInterval = options.HttpHandlerOptions.KeepAlivePingDelay, Http2KeepAliveTimeout = options.HttpHandlerOptions.KeepAlivePingTimeout, }, @@ -242,13 +244,18 @@ async Task ConnectAsync(CancellationToken applicationLifeTime) var callInvoker = channel.CreateCallInvoker(); var callOption = new CallOptions(new Metadata { { "worker-id", workerId.ToString() } }); - var connectTask = StreamingHubClient.ConnectAsync(callInvoker, this, option: callOption, serializerProvider: MessagePackMagicOnionSerializerProvider.Default.WithOptions( #if UNITY_2020_1_OR_NEWER - DFrameResolver.Options + var factoryProvider = MagicOnionDFrameGeneratedClientInitializer.StreamingHubClientFactoryProvider; + var serializerOptions = DFrameResolver.Options; #else - MessagePackSerializerOptions.Standard + var factoryProvider = DynamicStreamingHubClientFactoryProvider.Instance; + var serializerOptions = MessagePackSerializerOptions.Standard; #endif - ), factoryProvider: MagicOnionDFrameGeneratedClientInitializer.StreamingHubClientFactoryProvider); + var connectTask = StreamingHubClient.ConnectAsync(callInvoker, this, + option: callOption, + serializerProvider: MessagePackMagicOnionSerializerProvider.Default.WithOptions(serializerOptions), + factoryProvider: factoryProvider + ); client = await connectTask.WaitAsync(connectTimeout); this.connectionLifeTime = CancellationTokenSource.CreateLinkedTokenSource(client!.WaitForDisconnect().ToCancellationToken(), applicationLifeTime); diff --git a/src/DFrame.Worker/Internal/MagicOnionDFrameGeneratedClientInitializer.cs b/src/DFrame.Worker/Internal/MagicOnionDFrameGeneratedClientInitializer.cs index 8e98dc5..e4942aa 100644 --- a/src/DFrame.Worker/Internal/MagicOnionDFrameGeneratedClientInitializer.cs +++ b/src/DFrame.Worker/Internal/MagicOnionDFrameGeneratedClientInitializer.cs @@ -1,7 +1,9 @@ -using MagicOnion.Client; +#if UNITY_2020_1_OR_NEWER +using MagicOnion.Client; namespace DFrame.Internal { [MagicOnionClientGeneration(typeof(DFrame.IControllerHub), DisableAutoRegistration = true)] internal partial class MagicOnionDFrameGeneratedClientInitializer { } -} \ No newline at end of file +} +#endif \ No newline at end of file