4#include "WebSocketsModule.h"
10#define LogAPEX(pmt, ...) UE_LOG(LogApexWebSocket, Log, TEXT(pmt), ##__VA_ARGS__)
11#define WarnAPEX(pmt, ...) UE_LOG(LogApexWebSocket, Warning, TEXT(pmt), ##__VA_ARGS__)
12#define ErrorAPEX(pmt, ...) UE_LOG(LogApexWebSocket, Error, TEXT(pmt), ##__VA_ARGS__)
13#define FatalAPEX(pmt, ...) UE_LOG(LogApexWebSocket, Fatal, TEXT(pmt), ##__VA_ARGS__)
67 Socket = FWebSocketsModule::Get().CreateWebSocket(Uri, Protocol);
69 Socket->OnConnected().AddLambda([&]() ->
void {
70 LogAPEX(
"Apex websocket connected.");
75 Socket->OnConnectionError().AddLambda([&](
const FString&
Error) ->
void {
81 Socket->OnClosed().AddLambda([&](int32 StatusCode,
const FString& Reason,
bool bWasClean) ->
void {
82 LogAPEX(
"Socket closed with status %d, for reason %s", StatusCode, *Reason);
87 Socket->OnMessage().AddLambda([&](
const FString& Message) ->
void {
89 LogAPEX(
"Message received: %s", *Message);
98 if (MessageJsonObject->
HasField(
"auth_code"))
103 if (MessageJsonObject->
HasField(
"token"))
109 Socket->OnRawMessage().AddLambda([&](
const void* Data, SIZE_T Size, SIZE_T BytesRemaining) ->
void {
111 LogAPEX(
"A raw message was received.");
114 Socket->OnMessageSent().AddLambda([&](
const FString& MessageString) ->
void {
126 switch (NextRequestType)
130 SendData(
"{\"action\": \"authcode\" }");
134 ErrorAPEX(
"Invalid request type submitted of type %d", NextRequestType);
#define ErrorAPEX(pmt,...)
DEFINE_LOG_CATEGORY_STATIC(LogApexWebSocket, Log, All)
bool IsWebsocketConnected()
void SetupSocket(TSharedPtr< IWebSocket > &Socket, FString Uri, FString Protocol)
void SendData(FString Data)
void RequestAuthorizationCode()
FApexSocketConnectFailed ApexConnectFailedEvent
void HandleAuthenticateComplete(UVaRestJsonObject *JsonObject)
bool AttemptConnect(FString Uri, FString Protocol="wss")
void HandleAuthCodeReceived(UVaRestJsonObject *JsonObject)
FApexSocketAuthCodeRetrieved ApexAuthCodeRetrievedEvent
TSharedPtr< IWebSocket > WebSocket
FApexSocketConnected ApexConnectedEvent
FApexSocketDisconnected ApexDisconnectedEvent
FApexSocketAuthenticateComplete ApexAuthenticateCompleteEvent
TArray< ApexWebSocketRequestType > PendingWebsocketRequests
void ProcessNextRequest()
static UVaRestSubsystem * GetRestSubsystem()
UCLASS(BlueprintType, Blueprintable)
TSharedRef< FJsonObject > & GetRootObject()
bool HasField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
UVaRestJsonObject * DecodeJsonObject(const FString &JsonString)
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
virtual void FromJsonObject(const TSharedPtr< FJsonObject > &JObject) override
FString AuthCode
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Authentication Code")