Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ Below, you can learn how to setup and install UniScan for your platform.

| Name | Version | Description |
|:-----------------------------------------------------------------------------------------------:|:-------:|------------------------------------------------|
| [UniScan.Server.Core](src/Server/UniScan.Server.Core) | 0.3.0 | Shared server code |
| [UniScan.Server.Host](src/Server/UniScan.Server.Host) | 0.1.1 | Bootstraps UniScan.Server.Core |
| [UniScan.Server.Core](src/Server/UniScan.Server.Core) | 0.4.0 | Shared server code |
| [UniScan.Server.Host](src/Server/UniScan.Server.Host) | 0.2.0 | Bootstraps UniScan.Server.Core |
| [UniScan.Server.Authentication](src/Server/UniScan.Server.Authentication) | 0.0.1 | Common auth code and storage |
| [UniScan.Platform](src/Platform/UniScan.Platform) | 0.1.0 | Shared platform abstractions |
| [UniScan.Platform.DependencyInjection](src/Platform/UniScan.Platform.DependencyInjection) | 0.0.1 | Adds some DI extensions to UniScan.Platform |
Expand All @@ -173,7 +173,7 @@ Below, you can learn how to setup and install UniScan for your platform.
| [UniScan.Device](src/Core/UniScan.Device) | 0.3.0 | Device abstractions and transport methods |
| [UniScan.UserInterface](src/Core/UniScan.UserInterface) | 0.0.1 | Serverside UI definitions |
| [UniScan.Client.Core](src/Client/UniScan.Client.Core) | 0.3.0 | Holds shared client code, no dep on Avalonia |
| [UniScan.Client.App](src/Client/UniScan.Client.App) | 0.1.1 | UniScan client |
| [UniScan.Client.App](src/Client/UniScan.Client.App) | 0.2.0 | UniScan client |
| [UniScan.Client.App.Platform.Android](src/Client/UniScan.Client.App.Platform.Android) | 0.0.6 | UniScan client for Android |
| [UniScan.Client.App.Platform.Browser](src/Client/UniScan.Client.App.Platform.Browser) | 0.1.4 | UniScan client for web browsers (https://uniscan.dexrn.me) |
| [UniScan.Client.App.Platform.Desktop](src/Client/UniScan.Client.App.Platform.Desktop) | 0.0.3 | UniScan client for desktop |
Expand Down
4 changes: 2 additions & 2 deletions src/Client/UniScan.Client.App/UniScan.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<LangVersion>14</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<Company>UniScanProject</Company>
<AssemblyVersion>0.1.1</AssemblyVersion>
<FileVersion>0.1.1</FileVersion>
<AssemblyVersion>0.2.0</AssemblyVersion>
<FileVersion>0.2.0</FileVersion>
<Description>UniScan client</Description>
<Configurations>Release App;Debug App</Configurations>
<Platforms>AnyCPU</Platforms>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public DeviceInfoControlViewModel(DeviceViewModel deviceViewModel, IRemoteRootPa
else
{
_logger.Information("No longer subscribed to device '{Identifier}'", deviceViewModel.Device.Identifier);

_navigator.Navigate(null);
}
}).AddTo(_subscriptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void Dispose()

void IRemoteRootPageDeviceNavigatorProxy.Navigate(RemoteDevice? device)
{
if (device == null)
if (device == null)//TODO THIS IS SHIT BECAUSE THIS WILL SWITCH THE USER OUT OF WHATEVER PAGE REGARDLESS WHEN THE DEVICE IS UNSUBSCRIBED BY THE SERVER!!!!! WE DONT WANT SUCH SPECIFIC SHIT LIKE THIS BUT RUSHING THIS
{
Dispatcher.UIThread.Post(() => { CurrentSubpage = (ObservableObject?)_mainPage ?? _notConnectedPage; });
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using DotNetty.Transport.Channels;
using ObservableCollections;
using Serilog;
using Shiki.Common.Identity;
using UniScan.Client.Core.Remote;
using UniScan.Client.Core.Remote.Device;
using UniScan.Core.State;
using UniScan.Core.State.Node;
using UniScan.Network.Protocol.Packets.Clientbound.Device;

namespace UniScan.Client.Core.Module.Modules.Internal.Handler;

public class DeviceInfoPacketHandler : SimpleChannelInboundHandler<DeviceInfoPacket>
{
protected override void ChannelRead0(IChannelHandlerContext ctx, DeviceInfoPacket msg)
{
RemoteServer serv = ctx.Channel.GetAttribute(ServerAttributes.ServerAttribute).Get();

Log.Information("Received device info for {Identifier}: {Device}", msg.Device.DeviceIdentifier, msg.Device);
if (!serv.Devices.TryGetValue(msg.DeviceIdentifier, out RemoteDevice? device))
{
serv.Devices[msg.DeviceIdentifier] = RemoteDevice.FromDto(msg.Device, serv);
return;
}

//TODO better way than this to apply diffs?
if (!msg.Device.Connected && device.Subscribed.Value)
{
_ = device.UnsubscribeAsync(true);
}

device.UpdateFrom(msg.Device);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ protected override void ChannelRead0(IChannelHandlerContext ctx, StatePacket msg

foreach (var state in msg.States)
{
if (state.Value is null)
{
device.States.Remove(state.Key);
continue;
}

device.States[state.Key] = state.Value;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using DotNetty.Transport.Channels;
using ObservableCollections;
using Serilog;
using Shiki.Common.Identity;
using UniScan.Client.Core.Remote;
using UniScan.Client.Core.Remote.Device;
using UniScan.Core.State;
using UniScan.Core.State.Node;
using UniScan.Network.Protocol.Packets.Clientbound.Device;

namespace UniScan.Client.Core.Module.Modules.Internal.Handler;

public class UnsubscribeFromDevicePacketHandler : SimpleChannelInboundHandler<UnsubscribeFromDevicePacket>
{
protected override void ChannelRead0(IChannelHandlerContext ctx, UnsubscribeFromDevicePacket msg)
{
RemoteServer serv = ctx.Channel.GetAttribute(ServerAttributes.ServerAttribute).Get();

if (!serv.Devices.TryGetValue(msg.DeviceIdentifier, out RemoteDevice? device))
{
Log.Warning("Received device unsubscribe packet for nonexistent device '{Identifier}'", msg.DeviceIdentifier);
return;
}

Log.Information("Received device unsubscribe packet for device '{Identifier}'", msg.DeviceIdentifier);
_ = device.UnsubscribeAsync(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public void ConfigureDi(IServiceCollection services)
services.AddTransient<RemoteInfoPacketHandler>();
services.AddTransient<DeviceStatePacketHandler>();

services.AddTransient<DeviceInfoPacketHandler>();
services.AddTransient<UnsubscribeFromDevicePacketHandler>();

services.AddSingleton<IPipelineConfigurator, InternalUniScanClientPipelineConfigurator>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public void ConfigureHandlers(IChannelPipeline pipeline)
pipeline.AddLast(nameof(DisconnectPacketHandler), serviceProvider.GetRequiredService<DisconnectPacketHandler>());
pipeline.AddLast(nameof(RemoteInfoPacketHandler), serviceProvider.GetRequiredService<RemoteInfoPacketHandler>());
pipeline.AddLast(nameof(DeviceStatePacketHandler), serviceProvider.GetRequiredService<DeviceStatePacketHandler>());
pipeline.AddLast(nameof(DeviceInfoPacketHandler), serviceProvider.GetRequiredService<DeviceInfoPacketHandler>());
pipeline.AddLast(nameof(UnsubscribeFromDevicePacketHandler), serviceProvider.GetRequiredService<UnsubscribeFromDevicePacketHandler>());
}
}
25 changes: 22 additions & 3 deletions src/Client/UniScan.Client.Core/Remote/Device/RemoteDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UniScan.Network.Data;
using UniScan.Network.Data.Device;
using UniScan.Network.Protocol.Packets.Bidirectional.Status;
using UniScan.Network.Protocol.Packets.Serverbound.Device;
using UniScan.Network.Protocol.Packets.Serverbound.Subscription;

namespace UniScan.Client.Core.Remote.Device;
Expand All @@ -16,17 +17,17 @@ public class RemoteDevice(Slug<SnakeSlugFormatter> id, string? name, bool connec
{
public Slug<SnakeSlugFormatter> Identifier { get; } = id;

public string? DisplayName { get; } = name;
public string? DisplayName { get; private set; } = name;
public string Name => DisplayName ?? Identifier.Value;

public bool Connected { get; } = connected;
public bool Connected { get; private set; } = connected;

public RemoteServer Parent { get; } = parent;

private readonly BindableReactiveProperty<bool> _subscribed = new(false);
public IReadOnlyBindableReactiveProperty<bool> Subscribed => _subscribed;

public DeviceSpecifications? Specs { get; } = specs;
public DeviceSpecifications? Specs { get; private set; } = specs;

public ObservableDictionary<Identifier, IStateNode> States { get; set; } = [];

Expand All @@ -40,8 +41,26 @@ public async ValueTask<BooleanResult<Exception>> Subscribe()
return !res.Value.Result.IsSuccessful ? new BooleanResult<Exception>(res.Value.Result.Error) : BooleanResult<Exception>.Successful;
}

public async Task UnsubscribeAsync(bool notify)//todo this is just shit
{
if (notify)
{
await parent.Socket.SendRequestAsync(DeviceUnsubscribePacket.CreateRequest(Identifier));
}

_subscribed.Value = false;
}

public void Dispose()
{
_subscribed.Dispose();
}

//TODO there has to be better way than this but rushing...
public void UpdateFrom(DeviceDto dto)
{
DisplayName = dto.DisplayName;
Connected = dto.Connected;
Specs = dto.Specs;
}
}
2 changes: 1 addition & 1 deletion src/Network/UniScan.Network/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace UniScan.Network;

public class Constants
{
public const int ProtocolVersion = 10;
public const int ProtocolVersion = 11;
public const ushort DefaultPort = 'U' | ('S' << 2) | ('C' << 4) | ('N' << 6);//This packing really means nothing other than being an attempt at getting a nice port number
}
18 changes: 16 additions & 2 deletions src/Network/UniScan.Network/Data/Device/DeviceDto.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using MessagePack;
using Semver;
using Shiki.Common.Identity;
using Shiki.Common.Identity.Slug;
using Shiki.Common.Identity.Slug.Formatting.Formatters;
using UniScan.Network.Formatter.Semver;
Expand All @@ -17,6 +18,19 @@ public record DeviceSpecifications(
public record DeviceDto(
[property: Key(0)] Slug<SnakeSlugFormatter> DeviceIdentifier,
[property: Key(1)] string? DisplayName,
[property: Key(2), MemberNotNullWhen(true, nameof(DeviceDto.Specs))] bool Connected,
[property: Key(2), MemberNotNullWhen(true, nameof(DeviceDto.Specs))]
bool Connected,
[property: Key(3)] DeviceSpecifications? Specs
);
)
{
public static DeviceDto FromDevice(Slug<SnakeSlugFormatter> deviceId, UniScan.Device.Device.Device device, string? displayName)
{
DeviceSpecifications? info = null;
if (device.DeviceInfo != null)
{
info = new DeviceSpecifications(device.DeviceInfo.Model, device.DeviceInfo.Version);
}

return new DeviceDto(deviceId, displayName, device.Active.Value, info);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MessagePack;
using Shiki.Common.Identity.Slug;
using Shiki.Common.Identity.Slug.Formatting.Formatters;
using UniScan.Network.Data.Device;
Expand All @@ -7,8 +8,9 @@
namespace UniScan.Network.Protocol.Packets.Clientbound.Device;

[RegistryPacket("UniScan", "packet", "clientbound", "device", "info")]
public readonly record struct InfoPacket(
Slug<SnakeSlugFormatter> DeviceIdentifier,
DeviceDto Device,
Guid? RequestId
[MessagePackObject]
public readonly record struct DeviceInfoPacket(
[property: Key(0)] Slug<SnakeSlugFormatter> DeviceIdentifier,
[property: Key(1)] DeviceDto Device,
[property: Key(2)] Guid? RequestId
) : IClientboundPacket, IResponsePayloadPart, ISelectedDevicePayloadPart;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MessagePack;
using Shiki.Common.Identity.Slug;
using Shiki.Common.Identity.Slug.Formatting.Formatters;
using UniScan.Network.Protocol.Packets.Bidirectional.Status;
using UniScan.Network.Protocol.PayloadPart;
using UniScan.Network.Registry;
using UniScan.Network.Request;

namespace UniScan.Network.Protocol.Packets.Serverbound.Device;

[RegistryPacket("UniScan", "packet", "serverbound", "device", "client_unsubscribed")]
[MessagePackObject]
[method: RequestConstructor]
public partial record DeviceUnsubscribePacket(
[property: Key(0)] Slug<SnakeSlugFormatter> DeviceIdentifier,
[property: Key(1)] Guid? RequestId
) : IServerboundPacket, IRequestPayloadPart<AcknowledgePacket>;

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/Server/UniScan.Server.Core/Host/DeviceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DeviceHost(Slug<SnakeSlugFormatter> identifier, string? displayName, Devi

this.Logger = Log.ForContext("SourceContext", ToString());

NetworkClients = new HostClientsHandler(Identifier, Device);
NetworkClients = new HostClientsHandler(Identifier, Device, this);
}

public async Task StartAsync(CancellationToken ct = default)
Expand Down
Loading
Loading