Commit 54ec0503 authored by Geovanny Vera's avatar Geovanny Vera

Demo flow connection done

parent 94e9b334
......@@ -361,3 +361,6 @@ net.MaxRepArraySize=65535
+CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")
[/Script/OculusHMD.OculusHMDRuntimeSettings]
bRequiresSystemKeyboard=True
const config = {
UE4_PATH: "C:\\UnrealEngine-4.25.3-release\\Engine\\Binaries\\Win64\\UE4Editor.exe",
UE4_PATH: "C:\\UE4-oculus-4.25.4\\Engine\\Binaries\\Win64\\UE4Editor.exe",
PROJECT_PATH: "C:\\Users\\geova\\OneDrive\\Documents\\Unreal Projects\\VRClassroom 4.25\\src\\VRClassroom.uproject",
}
......
......@@ -11,3 +11,11 @@ UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitial
UHttpService* UVRCGameInstance::GetHttpService() {
return Http->GetHttp();
}
void UVRCGameInstance::SetUserToken(FString token) {
User.Token = token;
}
FString UVRCGameInstance::GetUserToken() {
return User.Token;
}
......@@ -16,16 +16,21 @@ void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTr
}
void AVRCPlayerController::ConnectToCampus() {
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
FString token = GameInstance->GetUserToken();
Http->SetTimeout(TravelTimeout);
TSharedRef<IHttpRequest> Request = Http->GetRequest("instances/join-server");
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToCampusResponseRecieved);
Request->SetHeader("Accepts", TEXT("application/json"));
FString auth = "Bearer ";
auth.Append(token);
Request->SetHeader("Authorization", auth);
FString url = FString(VRCAPIPath + "instances/join-server");
Request->SetURL(url);
......@@ -59,19 +64,23 @@ void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Req
}
void AVRCPlayerController::ConnectToMeeting(FString MeetingId) {
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(20.0f);
void AVRCPlayerController::ConnectToMeeting(int32 MeetingId) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
FString token = GameInstance->GetUserToken();
MeetingId.TrimStartAndEndInline();
Http->SetTimeout(20.0f);
TSharedRef<IHttpRequest> Request = Http->GetRequest("instances/join-classroom/123");
Request->SetURL(FString("http://localhost:1337/instances/join-classroom/123"));
FString url = "http://localhost:1337/instances/join-classroom/";
url.AppendInt(MeetingId);
Request->SetURL(url);
Request->SetHeader("Accepts", TEXT("application/json"));
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToMeetingResponseRecieved);
FString auth = "Bearer ";
auth.Append(token);
Request->SetHeader("Authorization", auth);
Request->ProcessRequest();
}
......
// Copyright 2020 Testy
#include "VRCScheduleWidget.h"
#include "HttpService.h"
#include "VRCGameInstance.h"
#include "JsonObjectConverter.h"
void UVRCScheduleWidget::GetMeetings() {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
FString token = GameInstance->GetUserToken();
Http->SetTimeout(20.0f);
TSharedRef<IHttpRequest> Request = Http->GetRequest("instances/join-classroom/123");
Request->SetURL(FString("http://localhost:1337/users/meetings"));
Request->SetHeader("Accepts", TEXT("application/json"));
Request->OnProcessRequestComplete().BindUObject(this, &UVRCScheduleWidget::OnGetMeetingsResponseRecieved);
FString auth = "Bearer ";
auth.Append(token);
Request->SetHeader("Authorization", auth);
//Request->ProcessRequest();
Testy();
}
void UVRCScheduleWidget::Testy() {
FString asd = "[{\"id\":34,\"map_id\":1,\"name\":\"CSC123\",\"password\":\"angry\",\"repeating\":0,\"active\":0,\"creator_id\":1}]";
TArray<FMeetingInfo> responseMeetings;
if (FJsonObjectConverter::JsonArrayStringToUStruct(asd, &responseMeetings, 0, 0)) {
meetings = responseMeetings;
FMeetingInfo temp = meetings[0];
UE_LOG(LogTemp, Log, TEXT("Good shit id: %d, name: %s"), temp.id, *temp.name);
NotifyGetMeetings();
}
else {
UE_LOG(LogTemp, Log, TEXT("Bad shit"));
}
}
void UVRCScheduleWidget::OnGetMeetingsResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
FString asd = "[{\"id\":34,\"map_id\":1,\"name\":\"CSC123\",\"password\":\"angry\",\"repeating\":0,\"active\":0,\"creator_id\":1}]";
if (Http->ResponseIsValid(Response, bWasSuccessful)) {
TSharedPtr<FJsonObject> JsonObject;
TArray<FMeetingInfo> responseMeetings;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
FString dsa = Response->GetContentAsString();
//UE_LOG(LogTemp, Log, TEXT("Response: %s"), &dsa);
//if (FJsonSerializer::Deserialize(Reader, JsonObject))
//{
if(FJsonObjectConverter::JsonArrayStringToUStruct(asd, &responseMeetings, 0, 0)){
/*FString IP = JsonObject->GetStringField("ip");
FString PORT = JsonObject->GetStringField("port");
FString URL = IP + FString(TEXT(":")) + PORT.Left(4);
UE_LOG(LogTemp, Log, TEXT("OnConnectToCampus IP is %s Port %s, Both"), *IP, *PORT, *URL);*/
//NotifyGetMeetings();
//UE_LOG(LogTemp, Log, TEXT("Response: %s"), Response->GetContentAsString());
}
else {
UE_LOG(LogTemp, Error, TEXT("GetMeetings returned no data!"));
}
}
else {
UE_LOG(LogTemp, Error, TEXT("GetMeetings Error accessing server!"));
}
}
\ No newline at end of file
......@@ -7,6 +7,17 @@
#include "HttpService.h"
#include "VRCGameInstance.generated.h"
USTRUCT(BlueprintType, Blueprintable)
struct FUserData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "API")
FString Token;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "User")
FString DisplayName;
};
/**
*
*/
......@@ -19,7 +30,15 @@ class VRCLASSROOM_API UVRCGameInstance : public UGameInstance
public:
UVRCGameInstance(const class FObjectInitializer& ObjectInitializer);
FUserData User;
UFUNCTION(BlueprintCallable, Category = "Http")
UHttpService* GetHttpService();
UFUNCTION(BlueprintCallable, Category = "Http")
void SetUserToken(FString token);
UFUNCTION(BlueprintCallable, Category = "Http")
FString GetUserToken();
};
......@@ -50,7 +50,7 @@ public:
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToMeeting(FString MeetingId);
void ConnectToMeeting(int32 MeetingId);
void OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
......
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "HttpService.h"
#include "VRCGameInstance.h"
#include "VRCScheduleWidget.generated.h"
USTRUCT(BlueprintType)
struct FMeetingInfo {
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadOnly)
int32 id;
UPROPERTY(BlueprintReadOnly)
int32 map_id;
UPROPERTY(BlueprintReadOnly)
FString name;
UPROPERTY(BlueprintReadOnly)
FString password;
UPROPERTY(BlueprintReadOnly)
int32 repeating;
UPROPERTY(BlueprintReadOnly)
int32 active;
UPROPERTY(BlueprintReadOnly)
int32 creator_id;
};
/**
*
*/
UCLASS()
class VRCLASSROOM_API UVRCScheduleWidget : public UUserWidget
{
GENERATED_BODY()
UHttpService* Http;
public:
UPROPERTY(BlueprintReadWrite, Category = "Meetings")
TArray<FMeetingInfo> meetings;
UFUNCTION(BlueprintCallable, Category = "Meetings")
void GetMeetings();
void Testy();
void OnGetMeetingsResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintImplementableEvent, Category = "Meetings")
void NotifyGetMeetings();
};
{
"FileVersion": 3,
"EngineAssociation": "{4EDE54B2-41A6-5679-C2F5-D48179AF5635}",
"EngineAssociation": "{0506F437-410D-A1AD-0DE5-36A1D1C0C5F7}",
"Category": "",
"Description": "",
"Modules": [
......
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