diff --git a/SDK.CSharp.Hub/SDK.CSharp.Hub.csproj b/SDK.CSharp.Hub/SDK.CSharp.Hub.csproj
index 9ea0c98..88886df 100644
--- a/SDK.CSharp.Hub/SDK.CSharp.Hub.csproj
+++ b/SDK.CSharp.Hub/SDK.CSharp.Hub.csproj
@@ -9,8 +9,8 @@
OpenShock.SDK.CSharp.Hub
OpenShock.SDK.CSharp.Hub
OpenShock
- 0.0.16
- 0.0.16
+ 0.0.19
+ 0.0.19
SDK.DotNet.Hub
OpenShock
Extension for OpenShock.SDK.CSharp
@@ -35,7 +35,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/SDK.CSharp.Live/IOpenShockLiveControlClient.cs b/SDK.CSharp.Live/IOpenShockLiveControlClient.cs
index 1387479..3f39cbe 100644
--- a/SDK.CSharp.Live/IOpenShockLiveControlClient.cs
+++ b/SDK.CSharp.Live/IOpenShockLiveControlClient.cs
@@ -1,18 +1,16 @@
-using OneOf;
-using OneOf.Types;
-using OpenShock.SDK.CSharp.Live.LiveControlModels;
+using OpenShock.SDK.CSharp.Live.LiveControlModels;
+using OpenShock.SDK.CSharp.Updatables;
namespace OpenShock.SDK.CSharp.Live;
public interface IOpenShockLiveControlClient
{
- public ulong Latency { get; }
- public WebsocketConnectionState State { get; }
+ public IAsyncUpdatable Latency { get; }
+ public IAsyncUpdatable State { get; }
# region Events
public event Func? OnDispose;
- public event Func? OnStateUpdate;
public event Func? OnDeviceNotConnected;
public event Func? OnDeviceConnected;
diff --git a/SDK.CSharp.Live/OpenShockLiveControlClient.cs b/SDK.CSharp.Live/OpenShockLiveControlClient.cs
index 715e51a..4505bc9 100644
--- a/SDK.CSharp.Live/OpenShockLiveControlClient.cs
+++ b/SDK.CSharp.Live/OpenShockLiveControlClient.cs
@@ -10,6 +10,7 @@
using OpenShock.SDK.CSharp.Live.LiveControlModels;
using OpenShock.SDK.CSharp.Live.Utils;
using OpenShock.SDK.CSharp.Serialization;
+using OpenShock.SDK.CSharp.Updatables;
using OpenShock.SDK.CSharp.Utils;
namespace OpenShock.SDK.CSharp.Live;
@@ -27,12 +28,9 @@ public sealed class OpenShockLiveControlClient : IOpenShockLiveControlClient, IA
private readonly string _authToken;
private readonly ILogger _logger;
private ClientWebSocket? _clientWebSocket = null;
-
- public event Func? OnStateUpdate;
+
public event Func? OnDeviceNotConnected;
public event Func? OnDeviceConnected;
- private WebsocketConnectionState _state = WebsocketConnectionState.Disconnected;
-
public event Func? OnDispose;
private readonly CancellationTokenSource _dispose;
@@ -59,16 +57,8 @@ public OpenShockLiveControlClient(string gateway, Guid deviceId, string authToke
private ValueTask QueueMessage(BaseRequest data) =>
_channel.Writer.WriteAsync(data, _dispose.Token);
- public WebsocketConnectionState State
- {
- get => _state;
- private set
- {
- _state = value;
- OnStateUpdate?.Raise(value);
- }
- }
-
+ private readonly AsyncUpdatableVariable _state = new(WebsocketConnectionState.Disconnected);
+ public IAsyncUpdatable State => _state;
private async Task MessageLoop()
{
@@ -98,7 +88,7 @@ private async Task> ConnectAsyn
return new Shutdown();
}
- State = WebsocketConnectionState.Connecting;
+ _state.Value = WebsocketConnectionState.Connecting;
#if NETSTANDARD2_1
_currentConnectionClose?.Cancel();
#else
@@ -121,7 +111,7 @@ private async Task> ConnectAsyn
await _clientWebSocket.ConnectAsync(new Uri($"wss://{_gateway}/1/ws/live/{_deviceId}"), _linked.Token);
_logger.LogInformation("Connected to websocket");
- State = WebsocketConnectionState.Connected;
+ _state.Value = WebsocketConnectionState.Connected;
Run(ReceiveLoop, _linked.Token);
Run(MessageLoop, _linked.Token);
@@ -145,7 +135,7 @@ private async Task> ConnectAsyn
_logger.LogError(e, "Error while connecting, retrying in 3 seconds");
}
- State = WebsocketConnectionState.Reconnecting;
+ _state.Value = WebsocketConnectionState.Reconnecting;
_clientWebSocket.Abort();
_clientWebSocket.Dispose();
await Task.Delay(3000, _dispose.Token);
@@ -248,7 +238,7 @@ await _clientWebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal cl
}
_logger.LogWarning("Lost websocket connection, trying to reconnect in 3 seconds");
- State = WebsocketConnectionState.Reconnecting;
+ _state.Value = WebsocketConnectionState.Reconnecting;
_clientWebSocket?.Abort();
_clientWebSocket?.Dispose();
@@ -298,7 +288,7 @@ await QueueMessage(new BaseRequest
return;
}
- Latency = latencyAnnounceResponse.OwnLatency;
+ _latency.Value = latencyAnnounceResponse.OwnLatency;
break;
case LiveResponseType.DeviceNotConnected:
@@ -353,7 +343,8 @@ public Task Run(Task? function, CancellationToken cancellationToken = default, [
file.Substring(index + 1, file.Length - index - 1), member, line, t.Exception?.StackTrace);
}, TaskContinuationOptions.OnlyOnFaulted);
- public ulong Latency { get; private set; } = 0;
+ private readonly AsyncUpdatableVariable _latency = new(0);
+ public IAsyncUpdatable Latency => _latency;
public async Task SendFrame(ClientLiveFrame frame)
{
diff --git a/SDK.CSharp.Live/SDK.CSharp.Live.csproj b/SDK.CSharp.Live/SDK.CSharp.Live.csproj
index 41a2411..97f1761 100644
--- a/SDK.CSharp.Live/SDK.CSharp.Live.csproj
+++ b/SDK.CSharp.Live/SDK.CSharp.Live.csproj
@@ -8,8 +8,8 @@
OpenShock.SDK.CSharp.Live
OpenShock.SDK.CSharp.Live
OpenShock
- 0.0.17
- 0.0.17
+ 0.0.19
+ 0.0.19
SDK.DotNet.Live
OpenShock
Extension for OpenShock.SDK.CSharp
@@ -31,7 +31,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/SDK.CSharp/SDK.CSharp.csproj b/SDK.CSharp/SDK.CSharp.csproj
index 11cc1f5..71deba4 100644
--- a/SDK.CSharp/SDK.CSharp.csproj
+++ b/SDK.CSharp/SDK.CSharp.csproj
@@ -8,8 +8,8 @@
OpenShock.SDK.CSharp
OpenShock.SDK.CSharp
OpenShock
- 0.0.16
- 0.0.16
+ 0.0.19
+ 0.0.19
SDK.DotNet
OpenShock
.NET / C# SDK for developing OpenShock applications. Used to interact with a OpenShock backend.
diff --git a/SDK.CSharp/Updatables/AsyncUpdatableVariable.cs b/SDK.CSharp/Updatables/AsyncUpdatableVariable.cs
new file mode 100644
index 0000000..a091429
--- /dev/null
+++ b/SDK.CSharp/Updatables/AsyncUpdatableVariable.cs
@@ -0,0 +1,24 @@
+using OpenShock.SDK.CSharp.Utils;
+
+namespace OpenShock.SDK.CSharp.Updatables;
+
+public sealed class AsyncUpdatableVariable(T internalValue) : IAsyncUpdatable
+{
+ public T Value
+ {
+ get => internalValue;
+ set
+ {
+ if (internalValue!.Equals(value)) return;
+ internalValue = value;
+ Task.Run(() => OnValueChanged?.Raise(value));
+ }
+ }
+
+ public event Func? OnValueChanged;
+
+ public void UpdateWithoutNotify(T newValue)
+ {
+ internalValue = newValue;
+ }
+}
\ No newline at end of file
diff --git a/SDK.CSharp/Updatables/IAsyncUpdatable.cs b/SDK.CSharp/Updatables/IAsyncUpdatable.cs
new file mode 100644
index 0000000..5e5d148
--- /dev/null
+++ b/SDK.CSharp/Updatables/IAsyncUpdatable.cs
@@ -0,0 +1,6 @@
+namespace OpenShock.SDK.CSharp.Updatables;
+
+public interface IAsyncUpdatable : IUpdatableBase
+{
+ public event Func? OnValueChanged;
+}
\ No newline at end of file
diff --git a/SDK.CSharp/Updatables/IUpdatable.cs b/SDK.CSharp/Updatables/IUpdatable.cs
new file mode 100644
index 0000000..5834bbc
--- /dev/null
+++ b/SDK.CSharp/Updatables/IUpdatable.cs
@@ -0,0 +1,6 @@
+namespace OpenShock.SDK.CSharp.Updatables;
+
+public interface IUpdatable : IUpdatableBase
+{
+ public event Action? OnValueChanged;
+}
\ No newline at end of file
diff --git a/SDK.CSharp/Updatables/IUpdatableBase.cs b/SDK.CSharp/Updatables/IUpdatableBase.cs
new file mode 100644
index 0000000..f49d182
--- /dev/null
+++ b/SDK.CSharp/Updatables/IUpdatableBase.cs
@@ -0,0 +1,6 @@
+namespace OpenShock.SDK.CSharp.Updatables;
+
+public interface IUpdatableBase
+{
+ public T Value { get; }
+}
\ No newline at end of file
diff --git a/SDK.CSharp/Updatables/UpdatableVariable.cs b/SDK.CSharp/Updatables/UpdatableVariable.cs
new file mode 100644
index 0000000..5209992
--- /dev/null
+++ b/SDK.CSharp/Updatables/UpdatableVariable.cs
@@ -0,0 +1,22 @@
+namespace OpenShock.SDK.CSharp.Updatables;
+
+public sealed class UpdatableVariable(T internalValue) : IUpdatable
+{
+ public T Value
+ {
+ get => internalValue;
+ set
+ {
+ if (internalValue!.Equals(value)) return;
+ internalValue = value;
+ OnValueChanged?.Invoke(value);
+ }
+ }
+
+ public event Action? OnValueChanged;
+
+ public void UpdateWithoutNotify(T newValue)
+ {
+ internalValue = newValue;
+ }
+}
\ No newline at end of file