socket set up properly
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user