diff --git a/.gitignore b/.gitignore index 4b13570..f94daeb 100644 --- a/.gitignore +++ b/.gitignore @@ -57,12 +57,8 @@ BenchmarkDotNet.Artifacts/ # .NET Core project.lock.json -RelayTestServer/ project.fragment.lock.json artifacts/ -publish_ms_out/ -publish_out/ -*.zip # StyleCop StyleCopReport.xml diff --git a/plugin_Relay/Models/Contract.cs b/plugin_Relay/Models/Contract.cs index a097fbd..475ea84 100644 --- a/plugin_Relay/Models/Contract.cs +++ b/plugin_Relay/Models/Contract.cs @@ -6,7 +6,7 @@ using Amethyst.Plugins.Contract; using MemoryPack; using Microsoft.Extensions.Logging; -using ActualLab.Rpc; +using Stl.Rpc; namespace plugin_Relay.Models; diff --git a/plugin_Relay/RelayDevice.cs b/plugin_Relay/RelayDevice.cs index b38d048..5f34574 100644 --- a/plugin_Relay/RelayDevice.cs +++ b/plugin_Relay/RelayDevice.cs @@ -16,7 +16,7 @@ using plugin_Relay.Models; using plugin_Relay.Pages; using Microsoft.Extensions.Logging; -using ActualLab.Rpc; +using Stl.Rpc; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -169,29 +169,39 @@ public void Initialize() // Mark as initialized IsInitialized = true; - MemoryPackFormatterProvider.Register(new TrackingDeviceFormatter()); - MemoryPackFormatterProvider.Register(new TrackedJointFormatter()); - - if (RelayService.Instance?.IsBackfeed ?? false) + try { - Status = RelayDeviceStatus.BackFeedDetected; - SettingsPage.DeviceStatusAppendix = string.Empty; - InitException = null; - return; // Don't proceed further - } + MemoryPackFormatterProvider.Register(new TrackingDeviceFormatter()); + MemoryPackFormatterProvider.Register(new TrackedJointFormatter()); - var services = new ServiceCollection() - .AddLogging(); + if (RelayService.Instance?.IsBackfeed ?? false) + { + Status = RelayDeviceStatus.BackFeedDetected; + SettingsPage.DeviceStatusAppendix = string.Empty; + InitException = null; + return; // Don't proceed further + } - services.AddRpc() - .AddWebSocketClient($"http://{ServerIp}:{ServerPort}/") - .AddClient(); + var services = new ServiceCollection() + .AddLogging(logging => logging.AddConsole()); - ServiceChannel = services.BuildServiceProvider(); - Service = ServiceChannel.GetRequiredService(); + services.AddRpc() + .AddWebSocketClient($"http://{ServerIp}:{ServerPort}/") + .AddClient() + .AddServer(); - SettingsPage.DeviceStatusAppendix = string.Empty; - SettingsPage.StartConnectionTest(); + ServiceChannel = services.BuildServiceProvider(); + Service = ServiceChannel.GetRequiredService(); + + SettingsPage.DeviceStatusAppendix = string.Empty; + SettingsPage.StartConnectionTest(); + } + catch (Exception ex) + { + InitException = ex; + Status = RelayDeviceStatus.ServiceError; + return; + } Host.Log($"Tried to initialize with status: {DeviceStatusString}"); InitException = null; diff --git a/plugin_Relay/RelayService.cs b/plugin_Relay/RelayService.cs index a2084d3..37a8fa1 100644 --- a/plugin_Relay/RelayService.cs +++ b/plugin_Relay/RelayService.cs @@ -15,10 +15,10 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using plugin_Relay.Models; -using ActualLab.Rpc; +using Stl.Rpc; using IServiceEndpoint = Amethyst.Plugins.Contract.IServiceEndpoint; using Microsoft.AspNetCore.Builder; -using ActualLab.Rpc.Server; +using Stl.Rpc.Server; using MemoryPack; using Microsoft.Extensions.Logging; @@ -209,6 +209,18 @@ public int Initialize() rpc.AddServer() .AddClient(); + builder.Services.AddSingleton(c => + { + RpcHub rpcHub = null; // Necessary because of IRelayClient, which requires call routing + return (methodDef, args) => + { + rpcHub ??= c.RpcHub(); // We can't resolve it earlier, coz otherwise it will trigger recursion + if (methodDef.Service.Type != typeof(IRelayClient)) return rpcHub.GetClientPeer(RpcPeerRef.Default); + var peerRef = new RpcPeerRef(args.Get(0), true); + return rpcHub.GetServerPeer(peerRef); + }; + }); + var app = builder.Build(); app.Urls.Add($"http://0.0.0.0:{ServerPort}/"); app.UseWebSockets(); diff --git a/plugin_Relay/plugin_Relay.csproj b/plugin_Relay/plugin_Relay.csproj index 04b85cf..f4d6e2b 100644 --- a/plugin_Relay/plugin_Relay.csproj +++ b/plugin_Relay/plugin_Relay.csproj @@ -24,17 +24,13 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - + + +