mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
appears to connect to websocket, but there's a python error
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
DEFINE_LOG_CATEGORY(EventSourceLog);
|
DEFINE_LOG_CATEGORY(EventSourceLog);
|
||||||
|
|
||||||
AEventSourceActor::AEventSourceActor() :
|
AEventSourceActor::AEventSourceActor() :
|
||||||
redis(nullptr)
|
redis(nullptr),
|
||||||
|
WebSocket(nullptr)
|
||||||
{
|
{
|
||||||
UE_LOG(EventSourceLog, Log, TEXT("CTOR()"));
|
UE_LOG(EventSourceLog, Log, TEXT("CTOR()"));
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ AEventSourceActor::AEventSourceActor() :
|
|||||||
//redis = CreateDefaultSubobject<URedisObject>(TEXT("RedisObject"));
|
//redis = CreateDefaultSubobject<URedisObject>(TEXT("RedisObject"));
|
||||||
|
|
||||||
//RootComponent = redis;
|
//RootComponent = redis;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AEventSourceActor::~AEventSourceActor()
|
AEventSourceActor::~AEventSourceActor()
|
||||||
@@ -134,3 +136,63 @@ void AEventSourceActor::InternalSubscribeCallback(FString Channel, FString Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======================================= web sockets =============================================
|
||||||
|
|
||||||
|
void AEventSourceActor::OnConnected()
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnConnected");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnConnected"));
|
||||||
|
|
||||||
|
WebSocket->SendMessage(TEXT("Hello Server!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::OnConnectionError(const FString& Error)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnConnectionError");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnConnectionError"));
|
||||||
|
|
||||||
|
// Connection failed.
|
||||||
|
UE_LOG(EventSourceLog, Error, TEXT("Failed to connect: %s."), *Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::OnClosed(int64 StatusCode, const FString& Reason, bool bWasClean)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnClosed");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnClosed"));
|
||||||
|
|
||||||
|
UE_LOG(EventSourceLog, Warning, TEXT("Connection closed: %d:%s. Clean: %d"), StatusCode, *Reason, bWasClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::OnMessage(const FString& Message)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnMessage");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnMessage"));
|
||||||
|
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("New message: %s"), *Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::OnRawMessage(const TArray<uint8>& Data, int32 BytesRemaining)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnRawMessage");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnRawMessage"));
|
||||||
|
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("New binary message: %d bytes and %d bytes remaining."), Data.Num(), BytesRemaining);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::OnMessageSent(const FString& Message)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OnMessageSent");
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("OnMessageSent"));
|
||||||
|
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("We just sent %s to the server."), *Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AEventSourceActor::SetupWebSockets()
|
||||||
|
{
|
||||||
|
if (WebSocket == nullptr) {
|
||||||
|
WebSocket = UBlueprintWebSocket::CreateWebSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
WebSocket->Connect(TEXT("ws://localhost:8765/"), TEXT("ws"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "RedisObject.h"
|
#include "RedisObject.h"
|
||||||
|
|
||||||
// BlueprintWebSocketPlugin
|
// BlueprintWebSocketPlugin
|
||||||
|
// Docs: https://github.com/Pandoa/BlueprintWebSocket
|
||||||
#include "BlueprintWebSocketWrapper.h"
|
#include "BlueprintWebSocketWrapper.h"
|
||||||
|
|
||||||
// EventCenterPlugin
|
// EventCenterPlugin
|
||||||
@@ -66,15 +67,30 @@ public:
|
|||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FMySubscriberDelegate MyDelegate;
|
FMySubscriberDelegate MyDelegate;
|
||||||
|
|
||||||
|
/** Set up websockets.*/
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "EventCenter")
|
||||||
|
void SetupWebSockets();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
virtual void BeginDestroy() override;
|
virtual void BeginDestroy() override;
|
||||||
|
|
||||||
|
// websocket callbacks
|
||||||
|
UFUNCTION() void OnConnected();
|
||||||
|
UFUNCTION() void OnConnectionError(const FString& Error);
|
||||||
|
UFUNCTION() void OnClosed(int64 StatusCode, const FString& Reason, bool bWasClean);
|
||||||
|
UFUNCTION() void OnMessage(const FString& Message);
|
||||||
|
UFUNCTION() void OnRawMessage(const TArray<uint8>& Data, int32 BytesRemaining);
|
||||||
|
UFUNCTION() void OnMessageSent(const FString& Message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
URedisObject* redis;
|
URedisObject* redis;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UBlueprintWebSocket* WebSocket;
|
||||||
|
|
||||||
// Handle callbacks.
|
// Handle callbacks.
|
||||||
// NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback.
|
// NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback.
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
|||||||
Reference in New Issue
Block a user