Skip to content

Commit

Permalink
Fix sending empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Aug 17, 2024
1 parent b1bbabc commit cd9c884
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 23 additions & 8 deletions SDK.CSharp.Live/OpenShockLiveControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,38 @@ private async void FrameTimerTick(object state)
{
try
{
if(_shockerStates.IsEmpty) return;

if (_clientWebSocket is not { State: WebSocketState.Open })
{
_logger.LogWarning("Frame timer ticked, but websocket is not open");
_managedFrameTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
return;
}

await QueueMessage(new BaseRequest<LiveRequestType>()
IList<ClientLiveFrame>? data = null;

var cur = DateTimeOffset.UtcNow;

foreach (var pair in _shockerStates)
{
if (pair.Value.ActiveUntil < cur ) continue;
data ??= new List<ClientLiveFrame>();

data.Add(new ClientLiveFrame
{
Shocker = pair.Key,
Type = pair.Value.LastType,
Intensity = pair.Value.LastIntensity
});
}

if (data == null) return;

await QueueMessage(new BaseRequest<LiveRequestType>
{
RequestType = LiveRequestType.BulkFrame,
Data = _shockerStates.Where(x => x.Value.ActiveUntil > DateTimeOffset.UtcNow)
.Select(x => new ClientLiveFrame
{
Shocker = x.Key,
Type = x.Value.LastType,
Intensity = x.Value.LastIntensity
})
Data = data
});
}
catch (Exception e)
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.26</AssemblyVersion>
<Version>0.0.26</Version>
<AssemblyVersion>0.0.27</AssemblyVersion>
<Version>0.0.27</Version>
<Title>SDK.DotNet.Live</Title>
<Authors>OpenShock</Authors>
<Description>Extension for OpenShock.SDK.CSharp</Description>
Expand Down

0 comments on commit cd9c884

Please sign in to comment.