Use HTTP with Player SDK #
By default the SDK is configured to establish websocket connections. You can configure the Player Unreal SDK to use HTTP for all requests to the Connect backend.
Configure client #
Update the PragmaSdkConfig
and set the Protocol
property.
Config\DefaultGame.ini
[/Script/PragmaSDK.PragmaSdkConfig]
ProtocolType="Http"
Notifications poll #
Upon login, the backend queues player notifications. Stored notifications are returned from any client request. The SDK issues a heartbeat to the backend every 30 seconds; for higher-frequency delivery of notifications, use the GetNotifications
API to poll.
This guide is based on an example Unreal project using the Third Person Unreal C++ project template. The example project is named ‘Narwhal’, update references accordingly.
Source\Narwhal\NarwhalPlayerController.h
UCLASS()
class NARWHAL_API ANarwhalPlayerController : public APlayerController
{
GENERATED_BODY()
public:
// ...
UFUNCTION(Exec)
void LogIn(const FString& Username);
// ...
private:
Pragma::FPlayerPtr Player;
FTimerHandle NotificationTimerHandle;
void GetNotifications();
// ...
Source\Narwhal\NarwhalPlayerController.cpp
void ANarwhalPlayerController::LogIn(const FString &Username) {
Player->LogIn(
EPragma_Account_IdProvider::UNSAFE, Username,
Pragma::FPlayer::FLoggedInDelegate::CreateWeakLambda(
this, [this, Username = Username](const TPragmaResult<> &Result) {
if (Result.IsSuccessful()) {
UE_LOG(LogTemp, Display, TEXT("-- Logged in as user %s."),
*Username);
// start a poll to fetch notifications every 10 seconds;
GetWorld()->GetTimerManager().SetTimer(
NotificationTimerHandle, this,
&ANarwhalPlayerController::GetNotifications, 10.0f, true);
} else {
UE_LOG(LogTemp, Error, TEXT("-- Login failed: %s"),
*Result.GetErrorAsString());
}
}));
}
void ANarwhalPlayerController::GetNotifications() {
Player->PragmaSessionService().GetNotifications(
UPragmaSessionService::FOnGetNotificationsCompleteDelegate::CreateLambda(
[](TPragmaResult<FPragma_Session_GetNotificationsV1Response> Result) {
if (Result.IsSuccessful()) {
UE_LOG(LogTemp, Display,
TEXT("=== Notifications are sent down on response and "
"processed by handlers ==="));
} else {
UE_LOG(LogTemp, Display, TEXT("=== Call failed ==="));
}
}));
}