some tests
This commit is contained in:
@ -5,6 +5,9 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using SocketIOClient;
|
||||
using BarRaider.SdTools;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ClipTrimDotNet.Client
|
||||
{
|
||||
@ -23,51 +26,91 @@ namespace ClipTrimDotNet.Client
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient httpClient;
|
||||
//private HttpClient httpClient;
|
||||
private SocketIO socket;
|
||||
|
||||
public int PortNumber { get; set; } = 5010;
|
||||
|
||||
public ClipTrimClient()
|
||||
{
|
||||
httpClient = new HttpClient()
|
||||
//httpClient = new HttpClient()
|
||||
//{
|
||||
// BaseAddress = new Uri("http://localhost:5010/"),
|
||||
// Timeout = TimeSpan.FromSeconds(10)
|
||||
//};
|
||||
socket = new SocketIO(new Uri($"http://localhost:5010/"));
|
||||
socket.Options.AutoUpgrade = false;
|
||||
socket.Options.ConnectionTimeout = TimeSpan.FromSeconds(10);
|
||||
socket.Options.Reconnection = true;
|
||||
socket.On("full_data", ctx =>
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost:5010/"),
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
Task.Run(ShortPoll);
|
||||
try
|
||||
{
|
||||
Collections = JsonConvert.DeserializeObject<List<CollectionMetaData>>(ctx.RawText);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
socket.On("collection_updated", ctx =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = JsonConvert.DeserializeObject<CollectionMetaData>(ctx.RawText);
|
||||
int index = Collections.FindIndex(x => x.Id == collection.Id);
|
||||
if(index != -1)
|
||||
{
|
||||
Collections[index] = collection;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
Task.Run(async () => await socket.ConnectAsync());
|
||||
//Task.Run(ShortPoll);
|
||||
}
|
||||
|
||||
public async Task ShortPoll()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await GetMetadata();
|
||||
await Task.Delay(TimeSpan.FromSeconds(5)); await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
|
||||
}
|
||||
}
|
||||
//public async Task ShortPoll()
|
||||
//{
|
||||
// while (true)
|
||||
// {
|
||||
// await GetMetadata();
|
||||
// await Task.Delay(TimeSpan.FromSeconds(5)); await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
public List<CollectionMetaData> Collections { get; private set; } = new List<CollectionMetaData>();
|
||||
public CollectionMetaData? SelectedCollection { get; private set; }
|
||||
public int PageIndex { get; private set; } = 0;
|
||||
private async Task GetMetadata()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetAsync("meta");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
dynamic collections = JsonConvert.DeserializeObject(json);
|
||||
collections = collections.collections;
|
||||
Collections = JsonConvert.DeserializeObject<List<CollectionMetaData>>(collections.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Logger.Instance.LogMessage(TracingLevel.INFO, $"Error pinging ClipTrim API: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
//private async Task GetMetadata()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// var response = await httpClient.GetAsync("meta");
|
||||
// if (response.IsSuccessStatusCode)
|
||||
// {
|
||||
// var json = await response.Content.ReadAsStringAsync();
|
||||
// dynamic collections = JsonConvert.DeserializeObject(json);
|
||||
// collections = collections.collections;
|
||||
// Collections = JsonConvert.DeserializeObject<List<CollectionMetaData>>(collections.ToString());
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Error pinging ClipTrim API: {ex.Message}");
|
||||
// return;
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
public List<string> GetCollectionNames()
|
||||
{
|
||||
@ -98,13 +141,13 @@ namespace ClipTrimDotNet.Client
|
||||
|
||||
public async void PlayClip(ClipMetadata? metadata)
|
||||
{
|
||||
if (metadata == null) return;
|
||||
if (metadata == null) return;
|
||||
|
||||
var response = await httpClient.PostAsync("playback/start", new StringContent(JsonConvert.SerializeObject(metadata), Encoding.UTF8, "application/json"));
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
//Logger.Instance.LogMessage(TracingLevel.INFO, $"Error playing clip: {response.ReasonPhrase}");
|
||||
}
|
||||
//var response = await httpClient.PostAsync("playback/start", new StringContent(JsonConvert.SerializeObject(metadata), Encoding.UTF8, "application/json"));
|
||||
//if (!response.IsSuccessStatusCode)
|
||||
//{
|
||||
// //Logger.Instance.LogMessage(TracingLevel.INFO, $"Error playing clip: {response.ReasonPhrase}");
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user