Messagepack (#43)
* add messagepack to client * add resolvers * fixes on client --------- Co-authored-by: Stanley Dimant <stanley.dimant@varian.com> Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: f604e6d27e...24faa352e7
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Authors></Authors>
|
||||
<Company></Company>
|
||||
<Version>0.7.22</Version>
|
||||
<Version>0.7.23</Version>
|
||||
<Description></Description>
|
||||
<Copyright></Copyright>
|
||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||
@@ -33,6 +33,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="7.0.2" />
|
||||
<PackageReference Include="Penumbra.Api" Version="1.0.7" />
|
||||
<PackageReference Include="Penumbra.String" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -13,6 +13,9 @@ using MareSynchronos.Managers;
|
||||
using Dalamud.Utility;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Mediator;
|
||||
using MessagePack;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MessagePack.Resolvers;
|
||||
|
||||
namespace MareSynchronos.WebAPI;
|
||||
public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareHubClient
|
||||
@@ -183,12 +186,12 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
|
||||
await _mareHub.StartAsync(token).ConfigureAwait(false);
|
||||
|
||||
await InitializeData().ConfigureAwait(false);
|
||||
|
||||
_connectionDto = await GetConnectionDto().ConfigureAwait(false);
|
||||
|
||||
ServerState = ServerState.Connected;
|
||||
|
||||
await InitializeData().ConfigureAwait(false);
|
||||
|
||||
if (_connectionDto.ServerVersion != IMareHub.ApiVersion)
|
||||
{
|
||||
await StopConnection(token, ServerState.VersionMisMatch).ConfigureAwait(false);
|
||||
@@ -315,6 +318,25 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
options.Headers.Add("Authorization", "Bearer " + _serverManager.GetToken());
|
||||
options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
|
||||
})
|
||||
.AddMessagePackProtocol(opt =>
|
||||
{
|
||||
var resolver = CompositeResolver.Create(StandardResolverAllowPrivate.Instance,
|
||||
BuiltinResolver.Instance,
|
||||
AttributeFormatterResolver.Instance,
|
||||
// replace enum resolver
|
||||
DynamicEnumAsStringResolver.Instance,
|
||||
DynamicGenericResolver.Instance,
|
||||
DynamicUnionResolver.Instance,
|
||||
DynamicObjectResolver.Instance,
|
||||
PrimitiveObjectResolver.Instance,
|
||||
// final fallback(last priority)
|
||||
StandardResolver.Instance);
|
||||
|
||||
opt.SerializerOptions =
|
||||
MessagePackSerializerOptions.Standard
|
||||
.WithCompression(MessagePackCompression.Lz4Block)
|
||||
.WithResolver(resolver);
|
||||
})
|
||||
.WithAutomaticReconnect(new ForeverRetryPolicy(Mediator))
|
||||
.ConfigureLogging(a =>
|
||||
{
|
||||
@@ -352,6 +374,12 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
ServerState = ServerState.Connecting;
|
||||
await InitializeData().ConfigureAwait(false);
|
||||
_connectionDto = await GetConnectionDto().ConfigureAwait(false);
|
||||
if (_connectionDto.ServerVersion != IMareHub.ApiVersion)
|
||||
{
|
||||
CancellationTokenSource cts = new();
|
||||
await StopConnection(cts.Token, ServerState.VersionMisMatch).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
ServerState = ServerState.Connected;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user