Skip to content

Commit aae965f

Browse files
committed
intermediate commit
1 parent f2b2029 commit aae965f

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

SDK.CSharp.Live/IOpenShockLiveControlClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace OpenShock.SDK.CSharp.Live;
77

88
public interface IOpenShockLiveControlClient
99
{
10-
public string Gateway { get; }
11-
public Guid DeviceId { get; }
10+
public string? Gateway { get; }
11+
public Guid HubId { get; }
1212
public byte Tps { get; }
1313

1414
public IAsyncUpdatable<ulong> Latency { get; }

SDK.CSharp.Live/OpenShockLiveControlClient.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ namespace OpenShock.SDK.CSharp.Live;
2020

2121
public sealed class OpenShockLiveControlClient : IOpenShockLiveControlClient, IAsyncDisposable
2222
{
23+
24+
private readonly OpenShockApiClient? _apiClient = null;
25+
2326
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
2427
{
2528
PropertyNameCaseInsensitive = true,
2629
Converters = { new CustomJsonStringEnumConverter() }
2730
};
28-
29-
public string Gateway { get; }
30-
public Guid DeviceId { get; }
31+
32+
public string? Gateway { get; } = null;
33+
public Guid HubId { get; }
3134

3235
private readonly string _authToken;
3336
private readonly ILogger<OpenShockLiveControlClient> _logger;
@@ -87,18 +90,43 @@ private set
8790
private Channel<BaseRequest<LiveRequestType>>
8891
_channel = Channel.CreateUnbounded<BaseRequest<LiveRequestType>>();
8992

90-
public OpenShockLiveControlClient(string gateway, Guid deviceId, string authToken,
91-
ILogger<OpenShockLiveControlClient> logger, ApiClientOptions.ProgramInfo? programInfo = null)
93+
/// <summary>
94+
/// Provide a gateway to connect to
95+
/// </summary>
96+
/// <param name="gateway"></param>
97+
/// <param name="hubId"></param>
98+
/// <param name="authToken"></param>
99+
/// <param name="logger"></param>
100+
/// <param name="programInfo"></param>
101+
public OpenShockLiveControlClient(string gateway, Guid hubId, string authToken,
102+
ILogger<OpenShockLiveControlClient> logger, ApiClientOptions.ProgramInfo? programInfo = null) : this(hubId, authToken, logger, programInfo)
92103
{
93104
Gateway = gateway;
94-
DeviceId = deviceId;
95-
_authToken = authToken;
105+
}
106+
107+
/// <summary>
108+
/// Just provide the hub ID and a pre-configured api client to get the gateway automatically on every connection attempt.
109+
/// </summary>
110+
/// <param name="hubId"></param>
111+
/// <param name="authToken"></param>
112+
/// <param name="apiClient"></param>
113+
/// <param name="logger"></param>
114+
/// <param name="programInfo"></param>
115+
public OpenShockLiveControlClient(Guid hubId, string authToken, OpenShockApiClient apiClient, ILogger<OpenShockLiveControlClient> logger, ApiClientOptions.ProgramInfo? programInfo = null) : this(hubId, authToken, logger, programInfo)
116+
{
117+
_apiClient = apiClient;
118+
}
119+
120+
private OpenShockLiveControlClient(Guid hubId, string authToken, ILogger<OpenShockLiveControlClient> logger,
121+
ApiClientOptions.ProgramInfo? programInfo = null)
122+
{
96123
_logger = logger;
97124
_programInfo = programInfo;
98-
125+
HubId = hubId;
99126
_dispose = new CancellationTokenSource();
100127
_linked = _dispose;
101-
128+
_authToken = authToken;
129+
102130
_managedFrameTimer = new Timer(FrameTimerTick);
103131
}
104132

@@ -168,7 +196,7 @@ private async Task<OneOf<Success, Shutdown, Reconnecting>> ConnectAsync()
168196
_logger.LogInformation("Connecting to websocket....");
169197
try
170198
{
171-
await _clientWebSocket.ConnectAsync(new Uri($"wss://{Gateway}/1/ws/live/{DeviceId}"), cancellationToken);
199+
await _clientWebSocket.ConnectAsync(new Uri($"wss://{Gateway}/1/ws/live/{HubId}"), cancellationToken);
172200

173201
_logger.LogInformation("Connected to websocket");
174202
_state.Value = WebsocketConnectionState.Connected;

0 commit comments

Comments
 (0)