Skip to content

Commit

Permalink
public gateway and device id in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Apr 26, 2024
1 parent 33d4532 commit 7e5c40d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions SDK.CSharp.Live/IOpenShockLiveControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace OpenShock.SDK.CSharp.Live;

public interface IOpenShockLiveControlClient
{
public string Gateway { get; }
public Guid DeviceId { get; }

public IAsyncUpdatable<ulong> Latency { get; }
public IAsyncUpdatable<WebsocketConnectionState> State { get; }

Expand Down
18 changes: 11 additions & 7 deletions SDK.CSharp.Live/OpenShockLiveControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public sealed class OpenShockLiveControlClient : IOpenShockLiveControlClient, IA
Converters = { new CustomJsonStringEnumConverter() }
};

private readonly string _gateway;
private readonly Guid _deviceId;
public string Gateway { get; }
public Guid DeviceId { get; }

private readonly string _authToken;
private readonly ILogger<OpenShockLiveControlClient> _logger;
private ClientWebSocket? _clientWebSocket = null;

public event Func<Task>? OnDeviceNotConnected;
public event Func<Task>? OnDeviceConnected;
public event Func<Task>? OnDispose;
Expand All @@ -43,8 +44,8 @@ private Channel<BaseRequest<LiveRequestType>>
public OpenShockLiveControlClient(string gateway, Guid deviceId, string authToken,
ILogger<OpenShockLiveControlClient> logger)
{
_gateway = gateway;
_deviceId = deviceId;
Gateway = gateway;
DeviceId = deviceId;
_authToken = authToken;
_logger = logger;

Expand All @@ -57,7 +58,9 @@ public OpenShockLiveControlClient(string gateway, Guid deviceId, string authToke
private ValueTask QueueMessage(BaseRequest<LiveRequestType> data) =>
_channel.Writer.WriteAsync(data, _dispose.Token);

private readonly AsyncUpdatableVariable<WebsocketConnectionState> _state = new(WebsocketConnectionState.Disconnected);
private readonly AsyncUpdatableVariable<WebsocketConnectionState> _state =
new(WebsocketConnectionState.Disconnected);

public IAsyncUpdatable<WebsocketConnectionState> State => _state;

private async Task MessageLoop()
Expand Down Expand Up @@ -108,7 +111,7 @@ private async Task<OneOf<Success, NotFound, Shutdown, Reconnecting>> ConnectAsyn
_logger.LogInformation("Connecting to websocket....");
try
{
await _clientWebSocket.ConnectAsync(new Uri($"wss://{_gateway}/1/ws/live/{_deviceId}"), _linked.Token);
await _clientWebSocket.ConnectAsync(new Uri($"wss://{Gateway}/1/ws/live/{DeviceId}"), _linked.Token);

_logger.LogInformation("Connected to websocket");
_state.Value = WebsocketConnectionState.Connected;
Expand Down Expand Up @@ -344,6 +347,7 @@ public Task Run(Task? function, CancellationToken cancellationToken = default, [
}, TaskContinuationOptions.OnlyOnFaulted);

private readonly AsyncUpdatableVariable<ulong> _latency = new(0);

public IAsyncUpdatable<ulong> Latency => _latency;

public async Task SendFrame(ClientLiveFrame frame)
Expand Down
4 changes: 2 additions & 2 deletions SDK.CSharp.Live/SDK.CSharp.Live.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<AssemblyName>OpenShock.SDK.CSharp.Live</AssemblyName>
<RootNamespace>OpenShock.SDK.CSharp.Live</RootNamespace>
<Company>OpenShock</Company>
<AssemblyVersion>0.0.19</AssemblyVersion>
<Version>0.0.19</Version>
<AssemblyVersion>0.0.20</AssemblyVersion>
<Version>0.0.20</Version>
<Title>SDK.DotNet.Live</Title>
<Authors>OpenShock</Authors>
<Description>Extension for OpenShock.SDK.CSharp</Description>
Expand Down

0 comments on commit 7e5c40d

Please sign in to comment.