Commit cea436ce authored by Geovanny Vera's avatar Geovanny Vera

Added functionality to transition to meeting

parent 8bb192d2
......@@ -6,9 +6,21 @@ const router = new Router();
router.post('/', (ctx, next) => {
const body = ctx.request.body;
console.log(`Server ${body.name}`);
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `TestServer?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
});
sub.unref();
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `${body.name}?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
ctx.response.status = 204;
});
router.post('/classroom', (ctx, next) => {
const body = ctx.request.body;
console.log(`Classroom ${body.name}`);
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `TestClassroom?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
});
......
......@@ -17,7 +17,19 @@ UHttpService::UHttpService(const class FObjectInitializer& ObjectInitializer) :
Http = &FHttpModule::Get();
}
UHttpService* UHttpService::GetHttp() {
Http = &FHttpModule::Get();
return this;
}
void UHttpService::SetTimeout(float Timeout) {
if (this == NULL) {
UE_LOG(LogTemp, Log, TEXT("TU PUTA MADRE"));
}
else if(this->Http == NULL) {
UE_LOG(LogTemp, Log, TEXT("LA TUYA"));
}
Http->SetHttpTimeout(Timeout);
}
......@@ -40,11 +52,12 @@ void UHttpService::SetRequestHeaders(TSharedRef<IHttpRequest>& Request) {
TSharedRef<IHttpRequest> UHttpService::RequestWithRoute(FString Subroute) {
// I have to set it here because for some reason if I set it on the constructor it becomes empty when it reaches here
// TODO: Figure out why that happens and fix it to remove this line
VRCAPIPath = FString(TEXT("https://api.ev3.me/"));
FString VRCAPIPath1 = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
FString url = FString(VRCAPIPath + Subroute);
FString url = FString(VRCAPIPath1);
url.Append(Subroute);
Request->SetURL(url);
SetRequestHeaders(Request);
......
......@@ -9,5 +9,5 @@ UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitial
}
UHttpService* UVRCGameInstance::GetHttpService() {
return Http;
return Http->GetHttp();
}
......@@ -3,6 +3,7 @@
#include "VRCPlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "VRCGameInstance.h"
AVRCPlayerController::AVRCPlayerController() {
......@@ -15,10 +16,13 @@ void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTr
}
void AVRCPlayerController::ConnectToCampus() {
Http = &FHttpModule::Get();
Http->SetHttpTimeout(TravelTimeout);
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(TravelTimeout);
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
TSharedRef<IHttpRequest> Request = Http->PostRequest("dsa", "asd");
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToCampusResponseRecieved);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
......@@ -62,3 +66,51 @@ void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Req
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Error accessing server!"));
}
}
void AVRCPlayerController::ConnectToMeeting(FString MeetingId) {
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(20.0f);
MeetingId.TrimStartAndEndInline();
FString PostParameters = FString(TEXT("{\"meetingId\":\"123\"}"));
TSharedRef<IHttpRequest> Request = Http->GetRequest("meeting/connect");
Request->SetURL(FString("http://localhost:1337/instances/join-classroom/123"));
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToMeetingResponseRecieved);
Request->ProcessRequest();
}
void AVRCPlayerController::OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
FString content = *Response->GetContentAsString();
UE_LOG(LogTemp, Log, TEXT("asdsad"));
if(Http->ResponseIsValid(Response, bWasSuccessful)){
UE_LOG(LogTemp, Log, TEXT("Connecting to meeting"));
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
FString IP = JsonObject->GetStringField("ip");
FString PORT = JsonObject->GetStringField("port");
FString URL = IP + FString(TEXT(":")) + PORT.Left(4);
UE_LOG(LogTemp, Log, TEXT("OnConnectToMeeting IP is %s Port %s, Both"), *IP, *PORT, *URL);
TravelToMap(URL, false);
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Server returned no data!"));
}
}else{
UE_LOG(LogTemp, Error, TEXT("Connect to meeting failed"));
}
}
......@@ -23,6 +23,8 @@ public:
FString VRCAPIPath = "";
UHttpService* GetHttp();
void SetTimeout(float Timeout);
bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful);
......
......@@ -4,7 +4,7 @@
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HttpService.h"
#include "VRCPlayerController.generated.h"
USTRUCT(BlueprintType, Blueprintable)
......@@ -29,7 +29,7 @@ class VRCLASSROOM_API AVRCPlayerController : public APlayerController
{
GENERATED_BODY()
FHttpModule* Http;
UHttpService* Http;
public:
......@@ -41,12 +41,17 @@ public:
UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "http://localhost:1337/";
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToCampus();
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToMeeting(FString MeetingId);
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
void OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment