socket set up properly
This commit is contained in:
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ClipTrimDotNet.Client
|
||||
{
|
||||
@ -18,27 +19,35 @@ namespace ClipTrimDotNet.Client
|
||||
public class ClipMetadata
|
||||
{
|
||||
[JsonProperty(PropertyName = "filename")]
|
||||
[JsonPropertyName("filename")]
|
||||
|
||||
public string Filename { get; set; }
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "volume")]
|
||||
[JsonPropertyName("volume")]
|
||||
public double Volume { get; set; } = 1.0;
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "startTime")]
|
||||
[JsonPropertyName("startTime")]
|
||||
public double StartTime { get; set; } = 0.0;
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "endTime")]
|
||||
[JsonPropertyName("endTime")]
|
||||
public double EndTime { get; set; } = 0.0;
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "playbackType")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
[JsonPropertyName("playbackType")]
|
||||
public PlaybackType PlaybackType { get; set; } = PlaybackType.playStop;
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ namespace ClipTrimDotNet.Client
|
||||
// BaseAddress = new Uri("http://localhost:5010/"),
|
||||
// Timeout = TimeSpan.FromSeconds(10)
|
||||
//};
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, $"Starting ClipTrimClient on port {PortNumber}");
|
||||
socket = new SocketIO(new Uri($"http://localhost:5010/"));
|
||||
socket.Options.AutoUpgrade = false;
|
||||
socket.Options.ConnectionTimeout = TimeSpan.FromSeconds(10);
|
||||
@ -46,11 +47,14 @@ namespace ClipTrimDotNet.Client
|
||||
{
|
||||
try
|
||||
{
|
||||
Collections = JsonConvert.DeserializeObject<List<CollectionMetaData>>(ctx.RawText);
|
||||
var response = ctx.GetValue<List<CollectionMetaData>>(0);
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, $"full_data event {JsonConvert.SerializeObject(response)}");
|
||||
Collections = response!;
|
||||
//Logger.Instance.LogMessage(TracingLevel.INFO, $"Collections {JsonConvert.SerializeObject(Collections)}");
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, $"full_data error {ex.ToString()}");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
@ -58,18 +62,19 @@ namespace ClipTrimDotNet.Client
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = JsonConvert.DeserializeObject<CollectionMetaData>(ctx.RawText);
|
||||
int index = Collections.FindIndex(x => x.Id == collection.Id);
|
||||
if(index != -1)
|
||||
var response = ctx.GetValue<CollectionMetaData>(0)!;
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, $"collection_updated event {JsonConvert.SerializeObject(response)}");
|
||||
int index = Collections.FindIndex(x => x.Id == response.Id);
|
||||
if (index != -1)
|
||||
{
|
||||
Collections[index] = collection;
|
||||
Collections[index] = response;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
@ -89,7 +94,7 @@ namespace ClipTrimDotNet.Client
|
||||
//}
|
||||
|
||||
public List<CollectionMetaData> Collections { get; private set; } = new List<CollectionMetaData>();
|
||||
public CollectionMetaData? SelectedCollection { get; private set; }
|
||||
public int SelectedCollection { get; private set; } = -1;
|
||||
public int PageIndex { get; private set; } = 0;
|
||||
//private async Task GetMetadata()
|
||||
//{
|
||||
@ -120,21 +125,21 @@ namespace ClipTrimDotNet.Client
|
||||
|
||||
public void SetSelectedCollectionByName(string name)
|
||||
{
|
||||
var collection = Collections.FirstOrDefault(x => x.Name == name);
|
||||
if (collection != null)
|
||||
SelectedCollection = Collections.FindIndex(x => x.Name == name);
|
||||
if (SelectedCollection != -1)
|
||||
{
|
||||
SelectedCollection = collection;
|
||||
PageIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public ClipMetadata? GetClipByPagedIndex(int index)
|
||||
{
|
||||
if (SelectedCollection == null) return null;
|
||||
if (SelectedCollection == -1) return null;
|
||||
int clipIndex = PageIndex * 10 + index;
|
||||
if (clipIndex >= 0 && clipIndex < SelectedCollection.Clips.Count)
|
||||
var collection = Collections[SelectedCollection];
|
||||
if (clipIndex >= 0 && clipIndex < collection.Clips.Count)
|
||||
{
|
||||
return SelectedCollection.Clips[clipIndex];
|
||||
return collection.Clips[clipIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClipTrimDotNet.Client
|
||||
@ -10,14 +11,17 @@ namespace ClipTrimDotNet.Client
|
||||
public class CollectionMetaData
|
||||
{
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "clips")]
|
||||
[JsonPropertyName("clips")]
|
||||
public List<ClipMetadata> Clips { get; set; } = new List<ClipMetadata>();
|
||||
|
||||
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user