RemoteSubsystem update
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "IHttpRouter.h"
|
||||
#include "Rundown/AvaRundown.h"
|
||||
#include "Json.h"
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "Misc/DateTime.h"
|
||||
|
||||
@ -129,6 +130,16 @@ bool UDTFluxRemoteSubsystem::IsHTTPServerRunning() const
|
||||
return bServerRunning;
|
||||
}
|
||||
|
||||
void UDTFluxRemoteSubsystem::ResetPendingTitleData()
|
||||
{
|
||||
bHasPendingTitleRequest = false;
|
||||
}
|
||||
|
||||
void UDTFluxRemoteSubsystem::ResetPendingBibData()
|
||||
{
|
||||
bHasPendingTitleBibRequest = false;
|
||||
}
|
||||
|
||||
void UDTFluxRemoteSubsystem::SetupRoutes()
|
||||
{
|
||||
if (!HttpRouter.IsValid())
|
||||
@ -184,9 +195,19 @@ bool UDTFluxRemoteSubsystem::HandleTitleRequest(const FHttpServerRequest& Reques
|
||||
AsyncTask(ENamedThreads::GameThread, [this, TitleData]()
|
||||
{
|
||||
OnTitleReceived.Broadcast(TitleData);
|
||||
if (RemotedRundown && RemotedRundown->IsValidLowLevel())
|
||||
{
|
||||
PendingTitleData = TitleData;
|
||||
bHasPendingTitleRequest = true;
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Playing page %i"), TitleData.RundownPageId);
|
||||
RemotedRundown->PlayPage(TitleData.RundownPageId, EAvaRundownPagePlayType::PlayFromStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Warning, TEXT("No rundown loaded"));
|
||||
}
|
||||
});
|
||||
|
||||
// Send success response
|
||||
OnComplete(FHttpServerResponse::Create(CreateSuccessResponse(TEXT("Title data received")), TEXT("application/json")));
|
||||
return true;
|
||||
}
|
||||
@ -239,9 +260,18 @@ bool UDTFluxRemoteSubsystem::HandleCommandsRequest(const FHttpServerRequest& Req
|
||||
AsyncTask(ENamedThreads::GameThread, [this, CommandData]()
|
||||
{
|
||||
OnCommandReceived.Broadcast(CommandData);
|
||||
if (RemotedRundown && RemotedRundown->IsValidLowLevel())
|
||||
{
|
||||
RemotedRundown->StopPage(CommandData.RundownPageId, EAvaRundownPageStopOptions::None, false);
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Stoping page %i"), CommandData.RundownPageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Warning, TEXT("No rundown loaded"));
|
||||
}
|
||||
});
|
||||
|
||||
OnComplete(FHttpServerResponse::Create(CreateSuccessResponse(TEXT("Command data received")), TEXT("application/json")));
|
||||
OnComplete(FHttpServerResponse::Create(CreateErrorResponse(TEXT("OK")), TEXT("application/json")));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -249,7 +279,17 @@ TSharedPtr<FJsonObject> UDTFluxRemoteSubsystem::ParseJsonFromRequest(const FHttp
|
||||
{
|
||||
// Get request body
|
||||
TArray<uint8> Body = Request.Body;
|
||||
FString JsonString = FString(UTF8_TO_TCHAR(reinterpret_cast<const char*>(Body.GetData())));
|
||||
FString JsonString;
|
||||
if (Body.Num() > 0)
|
||||
{
|
||||
// Ajouter un null terminator si nécessaire
|
||||
if (Body.Last() != 0)
|
||||
{
|
||||
Body.Add(0);
|
||||
}
|
||||
|
||||
JsonString = FString(UTF8_TO_TCHAR(reinterpret_cast<const char*>(Body.GetData())));
|
||||
}
|
||||
|
||||
UE_LOG(logDTFluxRemote, Verbose, TEXT("Received JSON: %s"), *JsonString);
|
||||
|
||||
@ -299,53 +339,65 @@ bool UDTFluxRemoteSubsystem::ParseTitleData(const TSharedPtr<FJsonObject>& JsonO
|
||||
{
|
||||
if (!JsonObject.IsValid())
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Invalid JSON object for %s"), TEXT("FDTFluxRemoteTitleData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse title fields
|
||||
JsonObject->TryGetStringField(TEXT("LastName"), OutData.LastName);
|
||||
JsonObject->TryGetStringField(TEXT("FirsName"), OutData.FirstName);
|
||||
JsonObject->TryGetStringField(TEXT("Function1"), OutData.Function1);
|
||||
JsonObject->TryGetStringField(TEXT("Function2"), OutData.Function2);
|
||||
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Parsed Title Data - LastName: %s, FirstName: %s"), *OutData.LastName, *OutData.FirstName);
|
||||
return true;
|
||||
if (FJsonObjectConverter::JsonObjectToUStruct<FDTFluxRemoteTitleData>(JsonObject.ToSharedRef(), &OutData))
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Successfully parsed %s"), TEXT("FDTFluxRemoteTitleData"));
|
||||
return true;
|
||||
}
|
||||
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Failed to convert JSON to %s struct"),TEXT("FDTFluxRemoteTitleData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UDTFluxRemoteSubsystem::ParseTitleBibData(const TSharedPtr<FJsonObject>& JsonObject, FDTFluxRemoteBibData& OutData)
|
||||
{
|
||||
if (!JsonObject.IsValid())
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Invalid JSON object for %s"), TEXT("FDTFluxRemoteBibData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
JsonObject->TryGetNumberField(TEXT("Bib"), OutData.Bib);
|
||||
|
||||
|
||||
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Parsed Title-Bib Data - Bib: %i"), OutData.Bib);
|
||||
if (FJsonObjectConverter::JsonObjectToUStruct<FDTFluxRemoteBibData>(JsonObject.ToSharedRef(), &OutData))
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Successfully parsed %s"), TEXT("FDTFluxRemoteBibData"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Failed to convert JSON to %s struct"),TEXT("FDTFluxRemoteBibData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UDTFluxRemoteSubsystem::ParseCommandData(const TSharedPtr<FJsonObject>& JsonObject, FDTFluxRemoteCommandData& OutData)
|
||||
{
|
||||
if (!JsonObject.IsValid())
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Invalid JSON object for %s"), TEXT("FDTFluxRemoteCommandData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
JsonObject->TryGetNumberField(TEXT("type"), OutData.Type);
|
||||
JsonObject->TryGetStringField(TEXT("Data"), OutData.Data);
|
||||
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Parsed Command Data - Command Type: %i, Data: %s"),
|
||||
OutData.Type, *OutData.Data);
|
||||
if (FJsonObjectConverter::JsonObjectToUStruct<FDTFluxRemoteCommandData>(JsonObject.ToSharedRef(), &OutData))
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Successfully parsed %s"), TEXT("FDTFluxRemoteCommandData"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Failed to convert JSON to %s struct"),TEXT("FDTFluxRemoteCommandData"));
|
||||
return false;
|
||||
}
|
||||
|
||||
void UDTFluxRemoteSubsystem::UnloadCurrentRundown()
|
||||
{
|
||||
if (RemotedRundown)
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Unloading current rundown"));
|
||||
// Ici vous pouvez ajouter une logique de nettoyage si nécessaire
|
||||
// Par exemple : RemotedRundown->StopAllPages();
|
||||
RemotedRundown = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxRemoteSubsystem::LoadRundownFromSettings()
|
||||
@ -366,7 +418,6 @@ void UDTFluxRemoteSubsystem::LoadRundownFromSettings()
|
||||
return;
|
||||
}
|
||||
|
||||
// Si c'est le même rundown, pas besoin de recharger
|
||||
if (RemotedRundown && RemotedRundown == RundownAsset.LoadSynchronous())
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Rundown already loaded: %s"), *RundownAsset.ToString());
|
||||
@ -385,6 +436,47 @@ void UDTFluxRemoteSubsystem::LoadRundownFromSettings()
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Failed to load rundown from settings: %s"), *RundownAsset.ToString());
|
||||
}
|
||||
LoadRundown(RundownAsset);
|
||||
}
|
||||
|
||||
bool UDTFluxRemoteSubsystem::LoadRundown(const TSoftObjectPtr<UAvaRundown>& RundownAsset)
|
||||
{
|
||||
if (RundownAsset.IsNull())
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Warning, TEXT("Cannot load rundown: asset is null"));
|
||||
UnloadCurrentRundown();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Charger le rundown de manière synchrone
|
||||
UAvaRundown* LoadedRundown = RundownAsset.LoadSynchronous();
|
||||
|
||||
// Vérifier si le rundown est déjà chargé
|
||||
if (RemotedRundown && RemotedRundown == LoadedRundown)
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Rundown already loaded: %s"), *RundownAsset.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Décharger l'ancien rundown d'abord
|
||||
UnloadCurrentRundown();
|
||||
|
||||
// Assigner le nouveau rundown
|
||||
RemotedRundown = LoadedRundown;
|
||||
|
||||
// Vérifier que le chargement a réussi
|
||||
if (RemotedRundown && RemotedRundown->IsValidLowLevel())
|
||||
{
|
||||
RemotedRundown->InitializePlaybackContext();
|
||||
UE_LOG(logDTFluxRemote, Log, TEXT("Successfully loaded rundown: %s"), *RundownAsset.ToString());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxRemote, Error, TEXT("Failed to load rundown: %s"), *RundownAsset.ToString());
|
||||
RemotedRundown = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
Reference in New Issue
Block a user